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