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