1 /*
   2  * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package jdk.vm.ci.hotspot;
  25 
  26 import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime;
  27 import static jdk.vm.ci.inittimer.InitTimer.timer;
  28 
  29 import java.lang.reflect.Constructor;
  30 import java.lang.reflect.Method;
  31 
  32 import jdk.vm.ci.code.BytecodeFrame;
  33 import jdk.vm.ci.code.InstalledCode;
  34 import jdk.vm.ci.code.InvalidInstalledCodeException;
  35 import jdk.vm.ci.code.TargetDescription;
  36 import jdk.vm.ci.common.JVMCIError;
  37 import jdk.vm.ci.hotspotvmconfig.HotSpotVMField;
  38 import jdk.vm.ci.inittimer.InitTimer;
  39 import jdk.vm.ci.meta.JavaType;
  40 import jdk.vm.ci.meta.ResolvedJavaMethod;
  41 import jdk.vm.ci.meta.ResolvedJavaType;
  42 import jdk.internal.misc.Unsafe;
  43 
  44 /**
  45  * Calls from Java into HotSpot. The behavior of all the methods in this class that take a native
  46  * pointer as an argument (e.g., {@link #getSymbol(long)}) is undefined if the argument does not
  47  * denote a valid native object.
  48  */
  49 final class CompilerToVM {
  50     /**
  51      * Initializes the native part of the JVMCI runtime.
  52      */
  53     private static native void registerNatives();
  54 
  55     static {
  56         initialize();
  57     }
  58 
  59     @SuppressWarnings("try")
  60     private static void initialize() {
  61         try (InitTimer t = timer("CompilerToVM.registerNatives")) {
  62             registerNatives();
  63         }
  64     }
  65 
  66     /**
  67      * Gets the {@link CompilerToVM} instance associated with the singleton
  68      * {@link HotSpotJVMCIRuntime} instance.
  69      */
  70     public static CompilerToVM compilerToVM() {
  71         return runtime().getCompilerToVM();
  72     }
  73 
  74     /**
  75      * Copies the original bytecode of {@code method} into a new byte array and returns it.
  76      *
  77      * @return a new byte array containing the original bytecode of {@code method}
  78      */
  79     native byte[] getBytecode(HotSpotResolvedJavaMethodImpl method);
  80 
  81     /**
  82      * Gets the number of entries in {@code method}'s exception handler table or 0 if it has not
  83      * exception handler table.
  84      */
  85     native int getExceptionTableLength(HotSpotResolvedJavaMethodImpl method);
  86 
  87     /**
  88      * Gets the address of the first entry in {@code method}'s exception handler table.
  89      *
  90      * Each entry is a native object described by these fields:
  91      *
  92      * <ul>
  93      * <li>{@link HotSpotVMConfig#exceptionTableElementSize}</li>
  94      * <li>{@link HotSpotVMConfig#exceptionTableElementStartPcOffset}</li>
  95      * <li>{@link HotSpotVMConfig#exceptionTableElementEndPcOffset}</li>
  96      * <li>{@link HotSpotVMConfig#exceptionTableElementHandlerPcOffset}</li>
  97      * <li>{@link HotSpotVMConfig#exceptionTableElementCatchTypeIndexOffset}
  98      * </ul>
  99      *
 100      * @return 0 if {@code method} has no exception handlers (i.e.
 101      *         {@code getExceptionTableLength(method) == 0})
 102      */
 103     native long getExceptionTableStart(HotSpotResolvedJavaMethodImpl method);
 104 
 105     /**
 106      * Determines if {@code method} can be inlined. A method may not be inlinable for a number of
 107      * reasons such as:
 108      * <ul>
 109      * <li>a CompileOracle directive may prevent inlining or compilation of methods</li>
 110      * <li>the method may have a bytecode breakpoint set</li>
 111      * <li>the method may have other bytecode features that require special handling by the VM</li>
 112      * </ul>
 113      */
 114     native boolean canInlineMethod(HotSpotResolvedJavaMethodImpl method);
 115 
 116     /**
 117      * Determines if {@code method} should be inlined at any cost. This could be because:
 118      * <ul>
 119      * <li>a CompileOracle directive may forces inlining of this methods</li>
 120      * <li>an annotation forces inlining of this method</li>
 121      * </ul>
 122      */
 123     native boolean shouldInlineMethod(HotSpotResolvedJavaMethodImpl method);
 124 
 125     /**
 126      * Used to implement {@link ResolvedJavaType#findUniqueConcreteMethod(ResolvedJavaMethod)}.
 127      *
 128      * @param method the method on which to base the search
 129      * @param actualHolderType the best known type of receiver
 130      * @return the method result or 0 is there is no unique concrete method for {@code method}
 131      */
 132     native HotSpotResolvedJavaMethodImpl findUniqueConcreteMethod(HotSpotResolvedObjectTypeImpl actualHolderType, HotSpotResolvedJavaMethodImpl method);
 133 
 134     /**
 135      * Gets the implementor for the interface class {@code type}.
 136      *
 137      * @return the implementor if there is a single implementor, 0 if there is no implementor, or
 138      *         {@code type} itself if there is more than one implementor
 139      */
 140     native HotSpotResolvedObjectTypeImpl getImplementor(HotSpotResolvedObjectTypeImpl type);
 141 
 142     /**
 143      * Determines if {@code method} is ignored by security stack walks.
 144      */
 145     native boolean methodIsIgnoredBySecurityStackWalk(HotSpotResolvedJavaMethodImpl method);
 146 
 147     /**
 148      * Converts a name to a type.
 149      *
 150      * @param name a well formed Java type in {@linkplain JavaType#getName() internal} format
 151      * @param accessingClass the context of resolution (must not be null)
 152      * @param resolve force resolution to a {@link ResolvedJavaType}. If true, this method will
 153      *            either return a {@link ResolvedJavaType} or throw an exception
 154      * @return the type for {@code name} or 0 if resolution failed and {@code resolve == false}
 155      * @throws LinkageError if {@code resolve == true} and the resolution failed
 156      */
 157     native HotSpotResolvedObjectTypeImpl lookupType(String name, Class<?> accessingClass, boolean resolve);
 158 
 159     /**
 160      * Resolves the entry at index {@code cpi} in {@code constantPool} to an object.
 161      *
 162      * The behavior of this method is undefined if {@code cpi} does not denote one of the following
 163      * entry types: {@code JVM_CONSTANT_MethodHandle}, {@code JVM_CONSTANT_MethodHandleInError},
 164      * {@code JVM_CONSTANT_MethodType} and {@code JVM_CONSTANT_MethodTypeInError}.
 165      */
 166     native Object resolveConstantInPool(HotSpotConstantPool constantPool, int cpi);
 167 
 168     /**
 169      * Resolves the entry at index {@code cpi} in {@code constantPool} to an object, looking in the
 170      * constant pool cache first.
 171      *
 172      * The behavior of this method is undefined if {@code cpi} does not denote a
 173      * {@code JVM_CONSTANT_String} entry.
 174      */
 175     native Object resolvePossiblyCachedConstantInPool(HotSpotConstantPool constantPool, int cpi);
 176 
 177     /**
 178      * Gets the {@code JVM_CONSTANT_NameAndType} index from the entry at index {@code cpi} in
 179      * {@code constantPool}.
 180      *
 181      * The behavior of this method is undefined if {@code cpi} does not denote an entry containing a
 182      * {@code JVM_CONSTANT_NameAndType} index.
 183      */
 184     native int lookupNameAndTypeRefIndexInPool(HotSpotConstantPool constantPool, int cpi);
 185 
 186     /**
 187      * Gets the name of the {@code JVM_CONSTANT_NameAndType} entry referenced by another entry
 188      * denoted by {@code which} in {@code constantPool}.
 189      *
 190      * The behavior of this method is undefined if {@code which} does not denote a entry that
 191      * references a {@code JVM_CONSTANT_NameAndType} entry.
 192      */
 193     native String lookupNameInPool(HotSpotConstantPool constantPool, int which);
 194 
 195     /**
 196      * Gets the signature of the {@code JVM_CONSTANT_NameAndType} entry referenced by another entry
 197      * denoted by {@code which} in {@code constantPool}.
 198      *
 199      * The behavior of this method is undefined if {@code which} does not denote a entry that
 200      * references a {@code JVM_CONSTANT_NameAndType} entry.
 201      */
 202     native String lookupSignatureInPool(HotSpotConstantPool constantPool, int which);
 203 
 204     /**
 205      * Gets the {@code JVM_CONSTANT_Class} index from the entry at index {@code cpi} in
 206      * {@code constantPool}.
 207      *
 208      * The behavior of this method is undefined if {@code cpi} does not denote an entry containing a
 209      * {@code JVM_CONSTANT_Class} index.
 210      */
 211     native int lookupKlassRefIndexInPool(HotSpotConstantPool constantPool, int cpi);
 212 
 213     /**
 214      * Looks up a class denoted by the {@code JVM_CONSTANT_Class} entry at index {@code cpi} in
 215      * {@code constantPool}. This method does not perform any resolution.
 216      *
 217      * The behavior of this method is undefined if {@code cpi} does not denote a
 218      * {@code JVM_CONSTANT_Class} entry.
 219      *
 220      * @return the resolved class entry or a String otherwise
 221      */
 222     native Object lookupKlassInPool(HotSpotConstantPool constantPool, int cpi);
 223 
 224     /**
 225      * Looks up a method denoted by the entry at index {@code cpi} in {@code constantPool}. This
 226      * method does not perform any resolution.
 227      *
 228      * The behavior of this method is undefined if {@code cpi} does not denote an entry representing
 229      * a method.
 230      *
 231      * @param opcode the opcode of the instruction for which the lookup is being performed or
 232      *            {@code -1}. If non-negative, then resolution checks specific to the bytecode it
 233      *            denotes are performed if the method is already resolved. Should any of these
 234      *            checks fail, 0 is returned.
 235      * @return the resolved method entry, 0 otherwise
 236      */
 237     native HotSpotResolvedJavaMethodImpl lookupMethodInPool(HotSpotConstantPool constantPool, int cpi, byte opcode);
 238 
 239     /**
 240      * Ensures that the type referenced by the specified {@code JVM_CONSTANT_InvokeDynamic} entry at
 241      * index {@code cpi} in {@code constantPool} is loaded and initialized.
 242      *
 243      * The behavior of this method is undefined if {@code cpi} does not denote a
 244      * {@code JVM_CONSTANT_InvokeDynamic} entry.
 245      */
 246     native void resolveInvokeDynamicInPool(HotSpotConstantPool constantPool, int cpi);
 247 
 248     /**
 249      * Ensures that the type referenced by the entry for a
 250      * <a href="https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-2.html#jvms-2.9">signature
 251      * polymorphic</a> method at index {@code cpi} in {@code constantPool} is loaded and
 252      * initialized.
 253      *
 254      * The behavior of this method is undefined if {@code cpi} does not denote an entry representing
 255      * a signature polymorphic method.
 256      */
 257     native void resolveInvokeHandleInPool(HotSpotConstantPool constantPool, int cpi);
 258 
 259     /**
 260      * Gets the resolved type denoted by the entry at index {@code cpi} in {@code constantPool}.
 261      *
 262      * The behavior of this method is undefined if {@code cpi} does not denote an entry representing
 263      * a class.
 264      *
 265      * @throws LinkageError if resolution failed
 266      */
 267     native HotSpotResolvedObjectTypeImpl resolveTypeInPool(HotSpotConstantPool constantPool, int cpi) throws LinkageError;
 268 
 269     /**
 270      * Looks up and attempts to resolve the {@code JVM_CONSTANT_Field} entry at index {@code cpi} in
 271      * {@code constantPool}. The values returned in {@code info} are:

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