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 for at index {@code cpi} in
 271      * {@code constantPool}. For some opcodes, checks are performed that require the {@code method}
 272      * that contains {@code opcode} to be specified. The values returned in {@code info} are:
 273      *
 274      * <pre>
 275      *     [(int) flags,   // only valid if field is resolved
 276      *      (int) offset]  // only valid if field is resolved
 277      * </pre>
 278      *
 279      * The behavior of this method is undefined if {@code cpi} does not denote a
 280      * {@code JVM_CONSTANT_Field} entry.
 281      *
 282      * @param info an array in which the details of the field are returned
 283      * @return the type defining the field if resolution is successful, 0 otherwise
 284      */
 285     native HotSpotResolvedObjectTypeImpl resolveFieldInPool(HotSpotConstantPool constantPool, int cpi, HotSpotResolvedJavaMethodImpl method, byte opcode, long[] info);
 286 
 287     /**
 288      * Converts {@code cpci} from an index into the cache for {@code constantPool} to an index
 289      * directly into {@code constantPool}.
 290      *
 291      * The behavior of this method is undefined if {@code ccpi} is an invalid constant pool cache
 292      * index.
 293      */
 294     native int constantPoolRemapInstructionOperandFromCache(HotSpotConstantPool constantPool, int cpci);
 295 
 296     /**
 297      * Gets the appendix object (if any) associated with the entry at index {@code cpi} in
 298      * {@code constantPool}.
 299      */
 300     native Object lookupAppendixInPool(HotSpotConstantPool constantPool, int cpi);
 301 
 302     /**
 303      * Installs the result of a compilation into the code cache.
 304      *
 305      * @param target the target where this code should be installed
 306      * @param compiledCode the result of a compilation
 307      * @param code the details of the installed CodeBlob are written to this object
 308      * @return the outcome of the installation which will be one of
 309      *         {@link HotSpotVMConfig#codeInstallResultOk},
 310      *         {@link HotSpotVMConfig#codeInstallResultCacheFull},
 311      *         {@link HotSpotVMConfig#codeInstallResultCodeTooLarge},
 312      *         {@link HotSpotVMConfig#codeInstallResultDependenciesFailed} or
 313      *         {@link HotSpotVMConfig#codeInstallResultDependenciesInvalid}.
 314      * @throws JVMCIError if there is something wrong with the compiled code or the associated
 315      *             metadata.
 316      */
 317     native int installCode(TargetDescription target, HotSpotCompiledCode compiledCode, InstalledCode code, HotSpotSpeculationLog speculationLog);
 318 
 319     /**
 320      * Generates the VM metadata for some compiled code and copies them into {@code metaData}. This
 321      * method does not install anything into the code cache.
 322      *
 323      * @param target the target where this code would be installed
 324      * @param compiledCode the result of a compilation
 325      * @param metaData the metadata is written to this object
 326      * @return the outcome of the installation which will be one of
 327      *         {@link HotSpotVMConfig#codeInstallResultOk},
 328      *         {@link HotSpotVMConfig#codeInstallResultCacheFull},
 329      *         {@link HotSpotVMConfig#codeInstallResultCodeTooLarge},
 330      *         {@link HotSpotVMConfig#codeInstallResultDependenciesFailed} or
 331      *         {@link HotSpotVMConfig#codeInstallResultDependenciesInvalid}.
 332      * @throws JVMCIError if there is something wrong with the compiled code or the metadata
 333      */
 334     public native int getMetadata(TargetDescription target, HotSpotCompiledCode compiledCode, HotSpotMetaData metaData);
 335 
 336     /**
 337      * Resets all compilation statistics.
 338      */
 339     native void resetCompilationStatistics();
 340 
 341     /**
 342      * Initializes the fields of {@code config}.
 343      */
 344     native long initializeConfiguration(HotSpotVMConfig config);
 345 
 346     /**
 347      * Resolves the implementation of {@code method} for virtual dispatches on objects of dynamic
 348      * type {@code exactReceiver}. This resolution process only searches "up" the class hierarchy of
 349      * {@code exactReceiver}.
 350      *
 351      * @param caller the caller or context type used to perform access checks
 352      * @return the link-time resolved method (might be abstract) or {@code 0} if it can not be
 353      *         linked
 354      */
 355     native HotSpotResolvedJavaMethodImpl resolveMethod(HotSpotResolvedObjectTypeImpl exactReceiver, HotSpotResolvedJavaMethodImpl method, HotSpotResolvedObjectTypeImpl caller);
 356 
 357     /**
 358      * Gets the static initializer of {@code type}.
 359      *
 360      * @return 0 if {@code type} has no static initializer
 361      */
 362     native HotSpotResolvedJavaMethodImpl getClassInitializer(HotSpotResolvedObjectTypeImpl type);
 363 
 364     /**
 365      * Determines if {@code type} or any of its currently loaded subclasses overrides
 366      * {@code Object.finalize()}.
 367      */
 368     native boolean hasFinalizableSubclass(HotSpotResolvedObjectTypeImpl type);
 369 
 370     /**
 371      * Gets the method corresponding to {@code holder} and slot number {@code slot} (i.e.
 372      * {@link Method#slot} or {@link Constructor#slot}).
 373      */
 374     native HotSpotResolvedJavaMethodImpl getResolvedJavaMethodAtSlot(Class<?> holder, int slot);
 375 
 376     /**
 377      * Gets the maximum absolute offset of a PC relative call to {@code address} from any position
 378      * in the code cache.
 379      *
 380      * @param address an address that may be called from any code in the code cache
 381      * @return -1 if {@code address == 0}
 382      */
 383     native long getMaxCallTargetOffset(long address);
 384 
 385     /**
 386      * Gets a textual disassembly of {@code codeBlob}.
 387      *
 388      * @return a non-zero length string containing a disassembly of {@code codeBlob} or null if
 389      *         {@code codeBlob} could not be disassembled for some reason
 390      */
 391     // The HotSpot disassembler seems not to be thread safe so it's better to synchronize its usage
 392     synchronized native String disassembleCodeBlob(InstalledCode installedCode);
 393 
 394     /**
 395      * Gets a stack trace element for {@code method} at bytecode index {@code bci}.
 396      */
 397     native StackTraceElement getStackTraceElement(HotSpotResolvedJavaMethodImpl method, int bci);
 398 
 399     /**
 400      * Executes some {@code installedCode} with arguments {@code args}.
 401      *
 402      * @return the result of executing {@code installedCode}
 403      * @throws InvalidInstalledCodeException if {@code installedCode} has been invalidated
 404      */
 405     native Object executeInstalledCode(Object[] args, InstalledCode installedCode) throws InvalidInstalledCodeException;
 406 
 407     /**
 408      * Gets the line number table for {@code method}. The line number table is encoded as (bci,
 409      * source line number) pairs.
 410      *
 411      * @return the line number table for {@code method} or null if it doesn't have one
 412      */
 413     native long[] getLineNumberTable(HotSpotResolvedJavaMethodImpl method);
 414 
 415     /**
 416      * Gets the number of entries in the local variable table for {@code method}.
 417      *
 418      * @return the number of entries in the local variable table for {@code method}
 419      */
 420     native int getLocalVariableTableLength(HotSpotResolvedJavaMethodImpl method);
 421 
 422     /**
 423      * Gets the address of the first entry in the local variable table for {@code method}.
 424      *
 425      * Each entry is a native object described by these fields:
 426      *
 427      * <ul>
 428      * <li>{@link HotSpotVMConfig#localVariableTableElementSize}</li>
 429      * <li>{@link HotSpotVMConfig#localVariableTableElementLengthOffset}</li>
 430      * <li>{@link HotSpotVMConfig#localVariableTableElementNameCpIndexOffset}</li>
 431      * <li>{@link HotSpotVMConfig#localVariableTableElementDescriptorCpIndexOffset}</li>
 432      * <li>{@link HotSpotVMConfig#localVariableTableElementSignatureCpIndexOffset}
 433      * <li>{@link HotSpotVMConfig#localVariableTableElementSlotOffset}
 434      * <li>{@link HotSpotVMConfig#localVariableTableElementStartBciOffset}
 435      * </ul>
 436      *
 437      * @return 0 if {@code method} does not have a local variable table
 438      */
 439     native long getLocalVariableTableStart(HotSpotResolvedJavaMethodImpl method);
 440 
 441     /**
 442      * Determines if {@code method} should not be inlined or compiled.
 443      */
 444     native void doNotInlineOrCompile(HotSpotResolvedJavaMethodImpl method);
 445 
 446     /**
 447      * Invalidates the profiling information for {@code method} and (re)initializes it such that
 448      * profiling restarts upon its next invocation.
 449      */
 450     native void reprofile(HotSpotResolvedJavaMethodImpl method);
 451 
 452     /**
 453      * Invalidates {@code installedCode} such that {@link InvalidInstalledCodeException} will be
 454      * raised the next time {@code installedCode} is executed.
 455      */
 456     native void invalidateInstalledCode(InstalledCode installedCode);
 457 
 458     /**
 459      * Collects the current values of all JVMCI benchmark counters, summed up over all threads.
 460      */
 461     native long[] collectCounters();
 462 
 463     /**
 464      * Determines if {@code metaspaceMethodData} is mature.
 465      */
 466     native boolean isMature(long metaspaceMethodData);
 467 
 468     /**
 469      * Generate a unique id to identify the result of the compile.
 470      */
 471     native int allocateCompileId(HotSpotResolvedJavaMethodImpl method, int entryBCI);
 472 
 473     /**
 474      * Determines if {@code method} has OSR compiled code identified by {@code entryBCI} for
 475      * compilation level {@code level}.
 476      */
 477     native boolean hasCompiledCodeForOSR(HotSpotResolvedJavaMethodImpl method, int entryBCI, int level);
 478 
 479     /**
 480      * Gets the value of {@code metaspaceSymbol} as a String.
 481      */
 482     native String getSymbol(long metaspaceSymbol);
 483 
 484     /**
 485      * Looks for the next Java stack frame matching an entry in {@code methods}.
 486      *
 487      * @param frame the starting point of the search, where {@code null} refers to the topmost frame
 488      * @param methods the methods to look for, where {@code null} means that any frame is returned
 489      * @return the frame, or {@code null} if the end of the stack was reached during the search
 490      */
 491     native HotSpotStackFrameReference getNextStackFrame(HotSpotStackFrameReference frame, ResolvedJavaMethod[] methods, int initialSkip);
 492 
 493     /**
 494      * Materializes all virtual objects within {@code stackFrame} and updates its locals.
 495      *
 496      * @param invalidate if {@code true}, the compiled method for the stack frame will be
 497      *            invalidated
 498      */
 499     native void materializeVirtualObjects(HotSpotStackFrameReference stackFrame, boolean invalidate);
 500 
 501     /**
 502      * Gets the v-table index for interface method {@code method} in the receiver {@code type} or
 503      * {@link HotSpotVMConfig#invalidVtableIndex} if {@code method} is not in {@code type}'s
 504      * v-table.
 505      *
 506      * @throws InternalError if {@code type} is an interface or {@code method} is not held by an
 507      *             interface or class represented by {@code type} is not initialized
 508      */
 509     native int getVtableIndexForInterfaceMethod(HotSpotResolvedObjectTypeImpl type, HotSpotResolvedJavaMethodImpl method);
 510 
 511     /**
 512      * Determines if debug info should also be emitted at non-safepoint locations.
 513      */
 514     native boolean shouldDebugNonSafepoints();
 515 
 516     /**
 517      * Writes {@code length} bytes from {@code bytes} starting at offset {@code offset} to the
 518      * HotSpot's log stream.
 519      *
 520      * @exception NullPointerException if {@code bytes == null}
 521      * @exception IndexOutOfBoundsException if copying would cause access of data outside array
 522      *                bounds
 523      */
 524     native void writeDebugOutput(byte[] bytes, int offset, int length);
 525 
 526     /**
 527      * Flush HotSpot's log stream.
 528      */
 529     native void flushDebugOutput();
 530 
 531     /**
 532      * Read a HotSpot Method* value from the memory location described by {@code base} plus
 533      * {@code displacement} and return the {@link HotSpotResolvedJavaMethodImpl} wrapping it. This
 534      * method does no checking that the memory location actually contains a valid pointer and may
 535      * crash the VM if an invalid location is provided. If the {@code base} is null then
 536      * {@code displacement} is used by itself. If {@code base} is a
 537      * {@link HotSpotResolvedJavaMethodImpl}, {@link HotSpotConstantPool} or
 538      * {@link HotSpotResolvedObjectTypeImpl} then the metaspace pointer is fetched from that object
 539      * and added to {@code displacement}. Any other non-null object type causes an
 540      * {@link IllegalArgumentException} to be thrown.
 541      *
 542      * @param base an object to read from or null
 543      * @param displacement
 544      * @return null or the resolved method for this location
 545      */
 546     native HotSpotResolvedJavaMethodImpl getResolvedJavaMethod(Object base, long displacement);
 547 
 548     /**
 549      * Read a HotSpot ConstantPool* value from the memory location described by {@code base} plus
 550      * {@code displacement} and return the {@link HotSpotConstantPool} wrapping it. This method does
 551      * no checking that the memory location actually contains a valid pointer and may crash the VM
 552      * if an invalid location is provided. If the {@code base} is null then {@code displacement} is
 553      * used by itself. If {@code base} is a {@link HotSpotResolvedJavaMethodImpl},
 554      * {@link HotSpotConstantPool} or {@link HotSpotResolvedObjectTypeImpl} then the metaspace
 555      * pointer is fetched from that object and added to {@code displacement}. Any other non-null
 556      * object type causes an {@link IllegalArgumentException} to be thrown.
 557      *
 558      * @param base an object to read from or null
 559      * @param displacement
 560      * @return null or the resolved method for this location
 561      */
 562     native HotSpotConstantPool getConstantPool(Object base, long displacement);
 563 
 564     /**
 565      * Read a HotSpot Klass* value from the memory location described by {@code base} plus
 566      * {@code displacement} and return the {@link HotSpotResolvedObjectTypeImpl} wrapping it. This
 567      * method does no checking that the memory location actually contains a valid pointer and may
 568      * crash the VM if an invalid location is provided. If the {@code base} is null then
 569      * {@code displacement} is used by itself. If {@code base} is a
 570      * {@link HotSpotResolvedJavaMethodImpl}, {@link HotSpotConstantPool} or
 571      * {@link HotSpotResolvedObjectTypeImpl} then the metaspace pointer is fetched from that object
 572      * and added to {@code displacement}. Any other non-null object type causes an
 573      * {@link IllegalArgumentException} to be thrown.
 574      *
 575      * @param base an object to read from or null
 576      * @param displacement
 577      * @param compressed true if the location contains a compressed Klass*
 578      * @return null or the resolved method for this location
 579      */
 580     native HotSpotResolvedObjectTypeImpl getResolvedJavaType(Object base, long displacement, boolean compressed);
 581 
 582     /**
 583      * Return the size of the HotSpot ProfileData* pointed at by {@code position}. If
 584      * {@code position} is outside the space of the MethodData then an
 585      * {@link IllegalArgumentException} is thrown. A {@code position} inside the MethodData but that
 586      * isn't pointing at a valid ProfileData will crash the VM.
 587      *
 588      * @param metaspaceMethodData
 589      * @param position
 590      * @return the size of the ProfileData item pointed at by {@code position}
 591      * @throws IllegalArgumentException if an out of range position is given
 592      */
 593     native int methodDataProfileDataSize(long metaspaceMethodData, int position);
 594 
 595     /**
 596      * Return the amount of native stack required for the interpreter frames represented by
 597      * {@code frame}. This is used when emitting the stack banging code to ensure that there is
 598      * enough space for the frames during deoptimization.
 599      *
 600      * @param frame
 601      * @return the number of bytes required for deoptimization of this frame state
 602      */
 603     native int interpreterFrameSize(BytecodeFrame frame);
 604 }