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