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