1 /*
   2  * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package jdk.vm.ci.hotspot;
  25 
  26 import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime;
  27 import static jdk.vm.ci.inittimer.InitTimer.timer;
  28 
  29 import java.lang.reflect.Constructor;
  30 import java.lang.reflect.Method;
  31 
  32 import jdk.vm.ci.code.InstalledCode;
  33 import jdk.vm.ci.code.InvalidInstalledCodeException;
  34 import jdk.vm.ci.code.TargetDescription;
  35 import jdk.vm.ci.hotspotvmconfig.HotSpotVMField;
  36 import jdk.vm.ci.inittimer.InitTimer;
  37 import jdk.vm.ci.meta.JavaType;
  38 import jdk.vm.ci.meta.ResolvedJavaMethod;
  39 import jdk.vm.ci.meta.ResolvedJavaType;
  40 import sun.misc.Unsafe;
  41 
  42 /**
  43  * Calls from Java into HotSpot. The behavior of all the methods in this class that take a native
  44  * pointer as an argument (e.g., {@link #getSymbol(long)}) is undefined if the argument does not
  45  * denote a valid native object.
  46  */
  47 final class CompilerToVM {
  48     /**
  49      * Initializes the native part of the JVMCI runtime.
  50      */
  51     private static native void registerNatives();
  52 
  53     static {
  54         initialize();
  55     }
  56 
  57     @SuppressWarnings("try")
  58     private static void initialize() {
  59         try (InitTimer t = timer("CompilerToVM.registerNatives")) {
  60             registerNatives();
  61         }
  62     }
  63 
  64     /**
  65      * Gets the {@link CompilerToVM} instance associated with the singleton
  66      * {@link HotSpotJVMCIRuntime} instance.
  67      */
  68     public static CompilerToVM compilerToVM() {
  69         return runtime().getCompilerToVM();
  70     }
  71 
  72     /**
  73      * Copies the original bytecode of {@code method} into a new byte array and returns it.
  74      *
  75      * @return a new byte array containing the original bytecode of {@code method}
  76      */
  77     native byte[] getBytecode(HotSpotResolvedJavaMethodImpl method);
  78 
  79     /**
  80      * Gets the number of entries in {@code method}'s exception handler table or 0 if it has not
  81      * exception handler table.
  82      */
  83     native int getExceptionTableLength(HotSpotResolvedJavaMethodImpl method);
  84 
  85     /**
  86      * Gets the address of the first entry in {@code method}'s exception handler table.
  87      *
  88      * Each entry is a native object described by these fields:
  89      *
  90      * <ul>
  91      * <li>{@link HotSpotVMConfig#exceptionTableElementSize}</li>
  92      * <li>{@link HotSpotVMConfig#exceptionTableElementStartPcOffset}</li>
  93      * <li>{@link HotSpotVMConfig#exceptionTableElementEndPcOffset}</li>
  94      * <li>{@link HotSpotVMConfig#exceptionTableElementHandlerPcOffset}</li>
  95      * <li>{@link HotSpotVMConfig#exceptionTableElementCatchTypeIndexOffset}
  96      * </ul>
  97      *
  98      * @return 0 if {@code method} has no exception handlers (i.e.
  99      *         {@code getExceptionTableLength(method) == 0})
 100      */
 101     native long getExceptionTableStart(HotSpotResolvedJavaMethodImpl method);
 102 
 103     /**
 104      * Determines if {@code method} can be inlined. A method may not be inlinable for a number of
 105      * reasons such as:
 106      * <ul>
 107      * <li>a CompileOracle directive may prevent inlining or compilation of methods</li>
 108      * <li>the method may have a bytecode breakpoint set</li>
 109      * <li>the method may have other bytecode features that require special handling by the VM</li>
 110      * </ul>
 111      */
 112     native boolean canInlineMethod(HotSpotResolvedJavaMethodImpl method);
 113 
 114     /**
 115      * Determines if {@code method} should be inlined at any cost. This could be because:
 116      * <ul>
 117      * <li>a CompileOracle directive may forces inlining of this methods</li>
 118      * <li>an annotation forces inlining of this method</li>
 119      * </ul>
 120      */
 121     native boolean shouldInlineMethod(HotSpotResolvedJavaMethodImpl method);
 122 
 123     /**
 124      * Used to implement {@link ResolvedJavaType#findUniqueConcreteMethod(ResolvedJavaMethod)}.
 125      *
 126      * @param method the method on which to base the search
 127      * @param actualHolderType the best known type of receiver
 128      * @return the method result or 0 is there is no unique concrete method for {@code method}
 129      */
 130     native HotSpotResolvedJavaMethodImpl findUniqueConcreteMethod(HotSpotResolvedObjectTypeImpl actualHolderType, HotSpotResolvedJavaMethodImpl method);
 131 
 132     /**
 133      * Gets the implementor for the interface class {@code type}.
 134      *
 135      * @return the implementor if there is a single implementor, 0 if there is no implementor, or
 136      *         {@code type} itself if there is more than one implementor
 137      */
 138     native HotSpotResolvedObjectTypeImpl getImplementor(HotSpotResolvedObjectTypeImpl type);
 139 
 140     /**
 141      * Determines if {@code method} is ignored by security stack walks.
 142      */
 143     native boolean methodIsIgnoredBySecurityStackWalk(HotSpotResolvedJavaMethodImpl method);
 144 
 145     /**
 146      * Converts a name to a type.
 147      *
 148      * @param name a well formed Java type in {@linkplain JavaType#getName() internal} format
 149      * @param accessingClass the context of resolution (must not be null)
 150      * @param resolve force resolution to a {@link ResolvedJavaType}. If true, this method will
 151      *            either return a {@link ResolvedJavaType} or throw an exception
 152      * @return the type for {@code name} or 0 if resolution failed and {@code resolve == false}
 153      * @throws LinkageError if {@code resolve == true} and the resolution failed
 154      */
 155     native HotSpotResolvedObjectTypeImpl lookupType(String name, Class<?> accessingClass, boolean resolve);
 156 
 157     /**
 158      * Resolves the entry at index {@code cpi} in {@code constantPool} to an object.
 159      *
 160      * The behavior of this method is undefined if {@code cpi} does not denote one of the following
 161      * entry types: {@code JVM_CONSTANT_MethodHandle}, {@code JVM_CONSTANT_MethodHandleInError},
 162      * {@code JVM_CONSTANT_MethodType} and {@code JVM_CONSTANT_MethodTypeInError}.
 163      */
 164     native Object resolveConstantInPool(HotSpotConstantPool constantPool, int cpi);
 165 
 166     /**
 167      * Resolves the entry at index {@code cpi} in {@code constantPool} to an object, looking in the
 168      * constant pool cache first.
 169      *
 170      * The behavior of this method is undefined if {@code cpi} does not denote a
 171      * {@code JVM_CONSTANT_String} entry.
 172      */
 173     native Object resolvePossiblyCachedConstantInPool(HotSpotConstantPool constantPool, int cpi);
 174 
 175     /**
 176      * Gets the {@code JVM_CONSTANT_NameAndType} index from the entry at index {@code cpi} in
 177      * {@code constantPool}.
 178      *
 179      * The behavior of this method is undefined if {@code cpi} does not denote an entry containing a
 180      * {@code JVM_CONSTANT_NameAndType} index.
 181      */
 182     native int lookupNameAndTypeRefIndexInPool(HotSpotConstantPool constantPool, int cpi);
 183 
 184     /**
 185      * Gets the name of the {@code JVM_CONSTANT_NameAndType} entry referenced by another entry
 186      * denoted by {@code which} in {@code constantPool}.
 187      *
 188      * The behavior of this method is undefined if {@code which} does not denote a entry that
 189      * references a {@code JVM_CONSTANT_NameAndType} entry.
 190      */
 191     native String lookupNameInPool(HotSpotConstantPool constantPool, int which);
 192 
 193     /**
 194      * Gets the signature of the {@code JVM_CONSTANT_NameAndType} entry referenced by another entry
 195      * denoted by {@code which} in {@code constantPool}.
 196      *
 197      * The behavior of this method is undefined if {@code which} does not denote a entry that
 198      * references a {@code JVM_CONSTANT_NameAndType} entry.
 199      */
 200     native String lookupSignatureInPool(HotSpotConstantPool constantPool, int which);
 201 
 202     /**
 203      * Gets the {@code JVM_CONSTANT_Class} index from the entry at index {@code cpi} in
 204      * {@code constantPool}.
 205      *
 206      * The behavior of this method is undefined if {@code cpi} does not denote an entry containing a
 207      * {@code JVM_CONSTANT_Class} index.
 208      */
 209     native int lookupKlassRefIndexInPool(HotSpotConstantPool constantPool, int cpi);
 210 
 211     /**
 212      * Looks up a class denoted by the {@code JVM_CONSTANT_Class} entry at index {@code cpi} in
 213      * {@code constantPool}. This method does not perform any resolution.
 214      *
 215      * The behavior of this method is undefined if {@code cpi} does not denote a
 216      * {@code JVM_CONSTANT_Class} entry.
 217      *
 218      * @return the resolved class entry or a String otherwise
 219      */
 220     native Object lookupKlassInPool(HotSpotConstantPool constantPool, int cpi);
 221 
 222     /**
 223      * Looks up a method denoted by the entry at index {@code cpi} in {@code constantPool}. This
 224      * method does not perform any resolution.
 225      *
 226      * The behavior of this method is undefined if {@code cpi} does not denote an entry representing
 227      * a method.
 228      *
 229      * @param opcode the opcode of the instruction for which the lookup is being performed or
 230      *            {@code -1}. If non-negative, then resolution checks specific to the bytecode it
 231      *            denotes are performed if the method is already resolved. Should any of these
 232      *            checks fail, 0 is returned.
 233      * @return the resolved method entry, 0 otherwise
 234      */
 235     native HotSpotResolvedJavaMethodImpl lookupMethodInPool(HotSpotConstantPool constantPool, int cpi, byte opcode);
 236 
 237     /**
 238      * Ensures that the type referenced by the specified {@code JVM_CONSTANT_InvokeDynamic} entry at
 239      * index {@code cpi} in {@code constantPool} is loaded and initialized.
 240      *
 241      * The behavior of this method is undefined if {@code cpi} does not denote a
 242      * {@code JVM_CONSTANT_InvokeDynamic} entry.
 243      */
 244     native void resolveInvokeDynamicInPool(HotSpotConstantPool constantPool, int cpi);
 245 
 246     /**
 247      * Ensures that the type referenced by the entry for a <a
 248      * href="https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-2.html#jvms-2.9">signature
 249      * polymorphic</a> method at index {@code cpi} in {@code constantPool} is loaded and
 250      * initialized.
 251      *
 252      * The behavior of this method is undefined if {@code cpi} does not denote an entry representing
 253      * a signature polymorphic method.
 254      */
 255     native void resolveInvokeHandleInPool(HotSpotConstantPool constantPool, int cpi);
 256 
 257     /**
 258      * Gets the resolved type denoted by the entry at index {@code cpi} in {@code constantPool}.
 259      *
 260      * The behavior of this method is undefined if {@code cpi} does not denote an entry representing
 261      * a class.
 262      *
 263      * @throws LinkageError if resolution failed
 264      */
 265     native HotSpotResolvedObjectTypeImpl resolveTypeInPool(HotSpotConstantPool constantPool, int cpi) throws LinkageError;
 266 
 267     /**
 268      * Looks up and attempts to resolve the {@code JVM_CONSTANT_Field} entry at index {@code cpi} in
 269      * {@code constantPool}. The values returned in {@code info} are:
 270      *
 271      * <pre>
 272      *     [(int) flags,   // only valid if field is resolved
 273      *      (int) offset]  // only valid if field is resolved
 274      * </pre>
 275      *
 276      * The behavior of this method is undefined if {@code cpi} does not denote a
 277      * {@code JVM_CONSTANT_Field} entry.
 278      *
 279      * @param info an array in which the details of the field are returned
 280      * @return the type defining the field if resolution is successful, 0 otherwise
 281      */
 282     native HotSpotResolvedObjectTypeImpl resolveFieldInPool(HotSpotConstantPool constantPool, int cpi, byte opcode, long[] info);
 283 
 284     /**
 285      * Converts {@code cpci} from an index into the cache for {@code constantPool} to an index
 286      * directly into {@code constantPool}.
 287      *
 288      * The behavior of this method is undefined if {@code ccpi} is an invalid constant pool cache
 289      * index.
 290      */
 291     native int constantPoolRemapInstructionOperandFromCache(HotSpotConstantPool constantPool, int cpci);
 292 
 293     /**
 294      * Gets the appendix object (if any) associated with the entry at index {@code cpi} in
 295      * {@code constantPool}.
 296      */
 297     native Object lookupAppendixInPool(HotSpotConstantPool constantPool, int cpi);
 298 
 299     /**
 300      * Installs the result of a compilation into the code cache.
 301      *
 302      * @param target the target where this code should be installed
 303      * @param compiledCode the result of a compilation
 304      * @param code the details of the installed CodeBlob are written to this object
 305      * @return the outcome of the installation which will be one of
 306      *         {@link HotSpotVMConfig#codeInstallResultOk},
 307      *         {@link HotSpotVMConfig#codeInstallResultCacheFull},
 308      *         {@link HotSpotVMConfig#codeInstallResultCodeTooLarge},
 309      *         {@link HotSpotVMConfig#codeInstallResultDependenciesFailed} or
 310      *         {@link HotSpotVMConfig#codeInstallResultDependenciesInvalid}.
 311      */
 312     native int installCode(TargetDescription target, HotSpotCompiledCode compiledCode, InstalledCode code, HotSpotSpeculationLog speculationLog);
 313 
 314     public native int getMetadata(TargetDescription target, HotSpotCompiledCode compiledCode, HotSpotMetaData metaData);
 315 
 316     /**
 317      * Notifies the VM of statistics for a completed compilation.
 318      *
 319      * @param id the identifier of the compilation
 320      * @param method the method compiled
 321      * @param osr specifies if the compilation was for on-stack-replacement
 322      * @param processedBytecodes the number of bytecodes processed during the compilation, including
 323      *            the bytecodes of all inlined methods
 324      * @param time the amount time spent compiling {@code method}
 325      * @param timeUnitsPerSecond the granularity of the units for the {@code time} value
 326      * @param installedCode the nmethod installed as a result of the compilation
 327      */
 328     synchronized native void notifyCompilationStatistics(int id, HotSpotResolvedJavaMethodImpl method, boolean osr, int processedBytecodes, long time, long timeUnitsPerSecond,
 329                     InstalledCode installedCode);
 330 
 331     /**
 332      * Resets all compilation statistics.
 333      */
 334     native void resetCompilationStatistics();
 335 
 336     /**
 337      * Initializes the fields of {@code config}.
 338      */
 339     native long initializeConfiguration(HotSpotVMConfig config);
 340 
 341     /**
 342      * Resolves the implementation of {@code method} for virtual dispatches on objects of dynamic
 343      * type {@code exactReceiver}. This resolution process only searches "up" the class hierarchy of
 344      * {@code exactReceiver}.
 345      *
 346      * @param caller the caller or context type used to perform access checks
 347      * @return the link-time resolved method (might be abstract) or {@code 0} if it can not be
 348      *         linked
 349      */
 350     native HotSpotResolvedJavaMethodImpl resolveMethod(HotSpotResolvedObjectTypeImpl exactReceiver, HotSpotResolvedJavaMethodImpl method, HotSpotResolvedObjectTypeImpl caller);
 351 
 352     /**
 353      * Gets the static initializer of {@code type}.
 354      *
 355      * @return 0 if {@code type} has no static initializer
 356      */
 357     native HotSpotResolvedJavaMethodImpl getClassInitializer(HotSpotResolvedObjectTypeImpl type);
 358 
 359     /**
 360      * Determines if {@code type} or any of its currently loaded subclasses overrides
 361      * {@code Object.finalize()}.
 362      */
 363     native boolean hasFinalizableSubclass(HotSpotResolvedObjectTypeImpl type);
 364 
 365     /**
 366      * Gets the method corresponding to {@code holder} and slot number {@code slot} (i.e.
 367      * {@link Method#slot} or {@link Constructor#slot}).
 368      */
 369     native HotSpotResolvedJavaMethodImpl getResolvedJavaMethodAtSlot(Class<?> holder, int slot);
 370 
 371     /**
 372      * Gets the maximum absolute offset of a PC relative call to {@code address} from any position
 373      * in the code cache.
 374      *
 375      * @param address an address that may be called from any code in the code cache
 376      * @return -1 if {@code address == 0}
 377      */
 378     native long getMaxCallTargetOffset(long address);
 379 
 380     /**
 381      * Gets a textual disassembly of {@code codeBlob}.
 382      *
 383      * @return a non-zero length string containing a disassembly of {@code codeBlob} or null if
 384      *         {@code codeBlob} could not be disassembled for some reason
 385      */
 386     // The HotSpot disassembler seems not to be thread safe so it's better to synchronize its usage
 387     synchronized native String disassembleCodeBlob(InstalledCode installedCode);
 388 
 389     /**
 390      * Gets a stack trace element for {@code method} at bytecode index {@code bci}.
 391      */
 392     native StackTraceElement getStackTraceElement(HotSpotResolvedJavaMethodImpl method, int bci);
 393 
 394     /**
 395      * Executes some {@code installedCode} with arguments {@code args}.
 396      *
 397      * @return the result of executing {@code installedCode}
 398      * @throws InvalidInstalledCodeException if {@code installedCode} has been invalidated
 399      */
 400     native Object executeInstalledCode(Object[] args, InstalledCode installedCode) throws InvalidInstalledCodeException;
 401 
 402     /**
 403      * Gets the line number table for {@code method}. The line number table is encoded as (bci,
 404      * source line number) pairs.
 405      *
 406      * @return the line number table for {@code method} or null if it doesn't have one
 407      */
 408     native long[] getLineNumberTable(HotSpotResolvedJavaMethodImpl method);
 409 
 410     /**
 411      * Gets the number of entries in the local variable table for {@code method}.
 412      *
 413      * @return the number of entries in the local variable table for {@code method}
 414      */
 415     native int getLocalVariableTableLength(HotSpotResolvedJavaMethodImpl method);
 416 
 417     /**
 418      * Gets the address of the first entry in the local variable table for {@code method}.
 419      *
 420      * Each entry is a native object described by these fields:
 421      *
 422      * <ul>
 423      * <li>{@link HotSpotVMConfig#localVariableTableElementSize}</li>
 424      * <li>{@link HotSpotVMConfig#localVariableTableElementLengthOffset}</li>
 425      * <li>{@link HotSpotVMConfig#localVariableTableElementNameCpIndexOffset}</li>
 426      * <li>{@link HotSpotVMConfig#localVariableTableElementDescriptorCpIndexOffset}</li>
 427      * <li>{@link HotSpotVMConfig#localVariableTableElementSignatureCpIndexOffset}
 428      * <li>{@link HotSpotVMConfig#localVariableTableElementSlotOffset}
 429      * <li>{@link HotSpotVMConfig#localVariableTableElementStartBciOffset}
 430      * </ul>
 431      *
 432      * @return 0 if {@code method} does not have a local variable table
 433      */
 434     native long getLocalVariableTableStart(HotSpotResolvedJavaMethodImpl method);
 435 
 436     /**
 437      * Reads an object pointer within a VM data structure. That is, any {@link HotSpotVMField} whose
 438      * {@link HotSpotVMField#type() type} is {@code "oop"} (e.g.,
 439      * {@code ArrayKlass::_component_mirror}, {@code Klass::_java_mirror},
 440      * {@code JavaThread::_threadObj}).
 441      *
 442      * Note that {@link Unsafe#getObject(Object, long)} cannot be used for this since it does a
 443      * {@code narrowOop} read if the VM is using compressed oops whereas oops within VM data
 444      * structures are (currently) always uncompressed.
 445      *
 446      * @param address address of an oop field within a VM data structure
 447      */
 448     native Object readUncompressedOop(long address);
 449 
 450     /**
 451      * Determines if {@code method} should not be inlined or compiled.
 452      */
 453     native void doNotInlineOrCompile(HotSpotResolvedJavaMethodImpl method);
 454 
 455     /**
 456      * Invalidates the profiling information for {@code method} and (re)initializes it such that
 457      * profiling restarts upon its next invocation.
 458      */
 459     native void reprofile(HotSpotResolvedJavaMethodImpl method);
 460 
 461     /**
 462      * Invalidates {@code installedCode} such that {@link InvalidInstalledCodeException} will be
 463      * raised the next time {@code installedCode} is executed.
 464      */
 465     native void invalidateInstalledCode(InstalledCode installedCode);
 466 
 467     /**
 468      * Collects the current values of all JVMCI benchmark counters, summed up over all threads.
 469      */
 470     native long[] collectCounters();
 471 
 472     /**
 473      * Determines if {@code metaspaceMethodData} is mature.
 474      */
 475     native boolean isMature(long metaspaceMethodData);
 476 
 477     /**
 478      * Generate a unique id to identify the result of the compile.
 479      */
 480     native int allocateCompileId(HotSpotResolvedJavaMethodImpl method, int entryBCI);
 481 
 482     /**
 483      * Determines if {@code method} has OSR compiled code identified by {@code entryBCI} for
 484      * compilation level {@code level}.
 485      */
 486     native boolean hasCompiledCodeForOSR(HotSpotResolvedJavaMethodImpl method, int entryBCI, int level);
 487 
 488     /**
 489      * Gets the value of {@code metaspaceSymbol} as a String.
 490      */
 491     native String getSymbol(long metaspaceSymbol);
 492 
 493     /**
 494      * Looks for the next Java stack frame matching an entry in {@code methods}.
 495      *
 496      * @param frame the starting point of the search, where {@code null} refers to the topmost frame
 497      * @param methods the methods to look for, where {@code null} means that any frame is returned
 498      * @return the frame, or {@code null} if the end of the stack was reached during the search
 499      */
 500     native HotSpotStackFrameReference getNextStackFrame(HotSpotStackFrameReference frame, ResolvedJavaMethod[] methods, int initialSkip);
 501 
 502     /**
 503      * Materializes all virtual objects within {@code stackFrame} updates its locals.
 504      *
 505      * @param invalidate if {@code true}, the compiled method for the stack frame will be
 506      *            invalidated.
 507      */
 508     native void materializeVirtualObjects(HotSpotStackFrameReference stackFrame, boolean invalidate);
 509 
 510     /**
 511      * Gets the v-table index for interface method {@code method} in the receiver {@code type} or
 512      * {@link HotSpotVMConfig#invalidVtableIndex} if {@code method} is not in {@code type}'s
 513      * v-table.
 514      *
 515      * @throws InternalError if {@code type} is an interface or {@code method} is not held by an
 516      *             interface or class represented by {@code type} is not initialized
 517      */
 518     native int getVtableIndexForInterfaceMethod(HotSpotResolvedObjectTypeImpl type, HotSpotResolvedJavaMethodImpl method);
 519 
 520     /**
 521      * Determines if debug info should also be emitted at non-safepoint locations.
 522      */
 523 
 524     native boolean shouldDebugNonSafepoints();
 525 
 526     /**
 527      * Writes {@code length} bytes from {@code bytes} starting at offset {@code offset} to the
 528      * HotSpot's log stream.
 529      *
 530      * @exception NullPointerException if {@code bytes == null}
 531      * @exception IndexOutOfBoundsException if copying would cause access of data outside array
 532      *                bounds
 533      */
 534     native void writeDebugOutput(byte[] bytes, int offset, int length);
 535 
 536     /**
 537      * Flush HotSpot's log stream.
 538      */
 539     native void flushDebugOutput();
 540 
 541     /**
 542      * Read a HotSpot Method* value from the memory location described by {@code base} plus
 543      * {@code displacement} and return the {@link HotSpotResolvedJavaMethodImpl} wrapping it. This
 544      * method does no checking that the memory location actually contains a valid pointer and may
 545      * crash the VM if an invalid location is provided. If the {@code base} is null then
 546      * {@code displacement} is used by itself. If {@code base} is a
 547      * {@link HotSpotResolvedJavaMethodImpl}, {@link HotSpotConstantPool} or
 548      * {@link HotSpotResolvedObjectTypeImpl} then the metaspace pointer is fetched from that object
 549      * and added to {@code displacement}. Any other non-null object type causes an
 550      * {@link IllegalArgumentException} to be thrown.
 551      *
 552      * @param base an object to read from or null
 553      * @param displacement
 554      * @return null or the resolved method for this location
 555      */
 556     native HotSpotResolvedJavaMethodImpl getResolvedJavaMethod(Object base, long displacement);
 557 
 558     /**
 559      * Read a HotSpot ConstantPool* value from the memory location described by {@code base} plus
 560      * {@code displacement} and return the {@link HotSpotConstantPool} wrapping it. This method does
 561      * no checking that the memory location actually contains a valid pointer and may crash the VM
 562      * if an invalid location is provided. If the {@code base} is null then {@code displacement} is
 563      * used by itself. If {@code base} is a {@link HotSpotResolvedJavaMethodImpl},
 564      * {@link HotSpotConstantPool} or {@link HotSpotResolvedObjectTypeImpl} then the metaspace
 565      * pointer is fetched from that object and added to {@code displacement}. Any other non-null
 566      * object type causes an {@link IllegalArgumentException} to be thrown.
 567      *
 568      * @param base an object to read from or null
 569      * @param displacement
 570      * @return null or the resolved method for this location
 571      */
 572     native HotSpotConstantPool getConstantPool(Object base, long displacement);
 573 
 574     /**
 575      * Read a HotSpot Klass* value from the memory location described by {@code base} plus
 576      * {@code displacement} and return the {@link HotSpotResolvedObjectTypeImpl} wrapping it. This
 577      * method does no checking that the memory location actually contains a valid pointer and may
 578      * crash the VM if an invalid location is provided. If the {@code base} is null then
 579      * {@code displacement} is used by itself. If {@code base} is a
 580      * {@link HotSpotResolvedJavaMethodImpl}, {@link HotSpotConstantPool} or
 581      * {@link HotSpotResolvedObjectTypeImpl} then the metaspace pointer is fetched from that object
 582      * and added to {@code displacement}. Any other non-null object type causes an
 583      * {@link IllegalArgumentException} to be thrown.
 584      *
 585      * @param base an object to read from or null
 586      * @param displacement
 587      * @param compressed true if the location contains a compressed Klass*
 588      * @return null or the resolved method for this location
 589      */
 590     native HotSpotResolvedObjectTypeImpl getResolvedJavaType(Object base, long displacement, boolean compressed);
 591 
 592     /**
 593      * Return the size of the HotSpot ProfileData* pointed at by {@code position}. If
 594      * {@code position} is outside the space of the MethodData then an
 595      * {@link IllegalArgumentException} is thrown. A {@code position} inside the MethodData but that
 596      * isn't pointing at a valid ProfileData will crash the VM.
 597      *
 598      * @param metaspaceMethodData
 599      * @param position
 600      * @return the size of the ProfileData item pointed at by {@code position}
 601      * @throws IllegalArgumentException if an out of range position is given
 602      */
 603     native int methodDataProfileDataSize(long metaspaceMethodData, int position);
 604 }