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