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