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