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