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