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
24package jdk.vm.ci.hotspot;
25
26import static jdk.vm.ci.common.InitTimer.timer;
27import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime;
28
29import java.lang.reflect.Executable;
30
31import jdk.vm.ci.code.BytecodeFrame;
32import jdk.vm.ci.code.InstalledCode;
33import jdk.vm.ci.code.InvalidInstalledCodeException;
34import jdk.vm.ci.code.TargetDescription;
35import jdk.vm.ci.common.InitTimer;
36import jdk.vm.ci.common.JVMCIError;
37import jdk.vm.ci.meta.JavaType;
38import jdk.vm.ci.meta.ResolvedJavaMethod;
39import jdk.vm.ci.meta.ResolvedJavaType;
40
41/**
42 * Calls from Java into HotSpot. The behavior of all the methods in this class that take a native
43 * pointer as an argument (e.g., {@link #getSymbol(long)}) is undefined if the argument does not
44 * denote a valid native object.
45 */
46final class CompilerToVM {
47    /**
48     * Initializes the native part of the JVMCI runtime.
49     */
50    private static native void registerNatives();
51
52    static {
53        initialize();
54    }
55
56    @SuppressWarnings("try")
57    private static void initialize() {
58        try (InitTimer t = timer("CompilerToVM.registerNatives")) {
59            registerNatives();
60        }
61    }
62
63    /**
64     * Gets the {@link CompilerToVM} instance associated with the singleton
65     * {@link HotSpotJVMCIRuntime} instance.
66     */
67    public static CompilerToVM compilerToVM() {
68        return runtime().getCompilerToVM();
69    }
70
71    /**
72     * Copies the original bytecode of {@code method} into a new byte array and returns it.
73     *
74     * @return a new byte array containing the original bytecode of {@code method}
75     */
76    native byte[] getBytecode(HotSpotResolvedJavaMethodImpl method);
77
78    /**
79     * Gets the number of entries in {@code method}'s exception handler table or 0 if it has no
80     * exception handler table.
81     */
82    native int getExceptionTableLength(HotSpotResolvedJavaMethodImpl method);
83
84    /**
85     * Gets the address of the first entry in {@code method}'s exception handler table.
86     *
87     * Each entry is a native object described by these fields:
88     *
89     * <ul>
90     * <li>{@link HotSpotVMConfig#exceptionTableElementSize}</li>
91     * <li>{@link HotSpotVMConfig#exceptionTableElementStartPcOffset}</li>
92     * <li>{@link HotSpotVMConfig#exceptionTableElementEndPcOffset}</li>
93     * <li>{@link HotSpotVMConfig#exceptionTableElementHandlerPcOffset}</li>
94     * <li>{@link HotSpotVMConfig#exceptionTableElementCatchTypeIndexOffset}
95     * </ul>
96     *
97     * @return 0 if {@code method} has no exception handlers (i.e.
98     *         {@code getExceptionTableLength(method) == 0})
99     */
100    native long getExceptionTableStart(HotSpotResolvedJavaMethodImpl method);
101
102    /**
103     * Determines whether {@code method} is currently compilable by the JVMCI compiler being used by
104     * the VM. This can return false if JVMCI compilation failed earlier for {@code method}, a
105     * breakpoint is currently set in {@code method} or {@code method} contains other bytecode
106     * features that require special handling by the VM.
107     */
108    native boolean isCompilable(HotSpotResolvedJavaMethodImpl method);
109
110    /**
111     * Determines if {@code method} is targeted by a VM directive (e.g.,
112     * {@code -XX:CompileCommand=dontinline,<pattern>}) or annotation (e.g.,
113     * {@code jdk.internal.vm.annotation.DontInline}) that specifies it should not be inlined.
114     */
115    native boolean hasNeverInlineDirective(HotSpotResolvedJavaMethodImpl method);
116
117    /**
118     * Determines if {@code method} should be inlined at any cost. This could be because:
119     * <ul>
120     * <li>a CompileOracle directive may forces inlining of this methods</li>
121     * <li>an annotation forces inlining of this method</li>
122     * </ul>
123     */
124    native boolean shouldInlineMethod(HotSpotResolvedJavaMethodImpl method);
125
126    /**
127     * Used to implement {@link ResolvedJavaType#findUniqueConcreteMethod(ResolvedJavaMethod)}.
128     *
129     * @param method the method on which to base the search
130     * @param actualHolderType the best known type of receiver
131     * @return the method result or 0 is there is no unique concrete method for {@code method}
132     */
133    native HotSpotResolvedJavaMethodImpl findUniqueConcreteMethod(HotSpotResolvedObjectTypeImpl actualHolderType, HotSpotResolvedJavaMethodImpl method);
134
135    /**
136     * Gets the implementor for the interface class {@code type}.
137     *
138     * @return the implementor if there is a single implementor, 0 if there is no implementor, or
139     *         {@code type} itself if there is more than one implementor
140     */
141    native HotSpotResolvedObjectTypeImpl getImplementor(HotSpotResolvedObjectTypeImpl type);
142
143    /**
144     * Determines if {@code method} is ignored by security stack walks.
145     */
146    native boolean methodIsIgnoredBySecurityStackWalk(HotSpotResolvedJavaMethodImpl method);
147
148    /**
149     * Converts a name to a type.
150     *
151     * @param name a well formed Java type in {@linkplain JavaType#getName() internal} format
152     * @param accessingClass the context of resolution (must not be null)
153     * @param resolve force resolution to a {@link ResolvedJavaType}. If true, this method will
154     *            either return a {@link ResolvedJavaType} or throw an exception
155     * @return the type for {@code name} or 0 if resolution failed and {@code resolve == false}
156     * @throws LinkageError if {@code resolve == true} and the resolution failed
157     */
158    native HotSpotResolvedObjectTypeImpl lookupType(String name, Class<?> accessingClass, boolean resolve);
159
160    /**
161     * Resolves the entry at index {@code cpi} in {@code constantPool} to an object.
162     *
163     * The behavior of this method is undefined if {@code cpi} does not denote one of the following
164     * entry types: {@code JVM_CONSTANT_MethodHandle}, {@code JVM_CONSTANT_MethodHandleInError},
165     * {@code JVM_CONSTANT_MethodType} and {@code JVM_CONSTANT_MethodTypeInError}.
166     */
167    native Object resolveConstantInPool(HotSpotConstantPool constantPool, int cpi);
168
169    /**
170     * Resolves the entry at index {@code cpi} in {@code constantPool} to an object, looking in the
171     * constant pool cache first.
172     *
173     * The behavior of this method is undefined if {@code cpi} does not denote a
174     * {@code JVM_CONSTANT_String} entry.
175     */
176    native Object resolvePossiblyCachedConstantInPool(HotSpotConstantPool constantPool, int cpi);
177
178    /**
179     * Gets the {@code JVM_CONSTANT_NameAndType} index from the entry at index {@code cpi} in
180     * {@code constantPool}.
181     *
182     * The behavior of this method is undefined if {@code cpi} does not denote an entry containing a
183     * {@code JVM_CONSTANT_NameAndType} index.
184     */
185    native int lookupNameAndTypeRefIndexInPool(HotSpotConstantPool constantPool, int cpi);
186
187    /**
188     * Gets the name of the {@code JVM_CONSTANT_NameAndType} entry referenced by another entry
189     * denoted by {@code which} in {@code constantPool}.
190     *
191     * The behavior of this method is undefined if {@code which} does not denote a entry that
192     * references a {@code JVM_CONSTANT_NameAndType} entry.
193     */
194    native String lookupNameInPool(HotSpotConstantPool constantPool, int which);
195
196    /**
197     * Gets the signature of the {@code JVM_CONSTANT_NameAndType} entry referenced by another entry
198     * denoted by {@code which} in {@code constantPool}.
199     *
200     * The behavior of this method is undefined if {@code which} does not denote a entry that
201     * references a {@code JVM_CONSTANT_NameAndType} entry.
202     */
203    native String lookupSignatureInPool(HotSpotConstantPool constantPool, int which);
204
205    /**
206     * Gets the {@code JVM_CONSTANT_Class} index from the entry at index {@code cpi} in
207     * {@code constantPool}.
208     *
209     * The behavior of this method is undefined if {@code cpi} does not denote an entry containing a
210     * {@code JVM_CONSTANT_Class} index.
211     */
212    native int lookupKlassRefIndexInPool(HotSpotConstantPool constantPool, int cpi);
213
214    /**
215     * Looks up a class denoted by the {@code JVM_CONSTANT_Class} entry at index {@code cpi} in
216     * {@code constantPool}. This method does not perform any resolution.
217     *
218     * The behavior of this method is undefined if {@code cpi} does not denote a
219     * {@code JVM_CONSTANT_Class} entry.
220     *
221     * @return the resolved class entry or a String otherwise
222     */
223    native Object lookupKlassInPool(HotSpotConstantPool constantPool, int cpi);
224
225    /**
226     * Looks up a method denoted by the entry at index {@code cpi} in {@code constantPool}. This
227     * method does not perform any resolution.
228     *
229     * The behavior of this method is undefined if {@code cpi} does not denote an entry representing
230     * a method.
231     *
232     * @param opcode the opcode of the instruction for which the lookup is being performed or
233     *            {@code -1}. If non-negative, then resolution checks specific to the bytecode it
234     *            denotes are performed if the method is already resolved. Should any of these
235     *            checks fail, 0 is returned.
236     * @return the resolved method entry, 0 otherwise
237     */
238    native HotSpotResolvedJavaMethodImpl lookupMethodInPool(HotSpotConstantPool constantPool, int cpi, byte opcode);
239
240    /**
241     * Ensures that the type referenced by the specified {@code JVM_CONSTANT_InvokeDynamic} entry at
242     * index {@code cpi} in {@code constantPool} is loaded and initialized.
243     *
244     * The behavior of this method is undefined if {@code cpi} does not denote a
245     * {@code JVM_CONSTANT_InvokeDynamic} entry.
246     */
247    native void resolveInvokeDynamicInPool(HotSpotConstantPool constantPool, int cpi);
248
249    /**
250     * If {@code cpi} denotes an entry representing a
251     * <a href="https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-2.html#jvms-2.9">signature
252     * polymorphic</a> method, this method ensures that the type referenced by the entry is loaded
253     * and initialized. It {@code cpi} does not denote a signature polymorphic method, this method
254     * does nothing.
255     */
256    native void resolveInvokeHandleInPool(HotSpotConstantPool constantPool, int cpi);
257
258    /**
259     * Gets the list of type names (in the format of {@link JavaType#getName()}) denoting the
260     * classes that define signature polymorphic methods.
261     */
262    native String[] getSignaturePolymorphicHolders();
263
264    /**
265     * Gets the resolved type denoted by the entry at index {@code cpi} in {@code constantPool}.
266     *
267     * The behavior of this method is undefined if {@code cpi} does not denote an entry representing
268     * a class.
269     *
270     * @throws LinkageError if resolution failed
271     */
272    native HotSpotResolvedObjectTypeImpl resolveTypeInPool(HotSpotConstantPool constantPool, int cpi) throws LinkageError;
273
274    /**
275     * Looks up and attempts to resolve the {@code JVM_CONSTANT_Field} entry for at index
276     * {@code cpi} in {@code constantPool}. For some opcodes, checks are performed that require the
277     * {@code method} that contains {@code opcode} to be specified. The values returned in
278     * {@code info} are:
279     *
280     * <pre>
281     *     [ flags,  // fieldDescriptor::access_flags()
282     *       offset, // fieldDescriptor::offset()
283     *       index   // fieldDescriptor::index()
284     *     ]
285     * </pre>
286     *
287     * The behavior of this method is undefined if {@code cpi} does not denote a
288     * {@code JVM_CONSTANT_Field} entry.
289     *
290     * @param info an array in which the details of the field are returned
291     * @return the type defining the field if resolution is successful, 0 otherwise
292     */
293    native HotSpotResolvedObjectTypeImpl resolveFieldInPool(HotSpotConstantPool constantPool, int cpi, HotSpotResolvedJavaMethodImpl method, byte opcode, int[] info);
294
295    /**
296     * Converts {@code cpci} from an index into the cache for {@code constantPool} to an index
297     * directly into {@code constantPool}.
298     *
299     * The behavior of this method is undefined if {@code ccpi} is an invalid constant pool cache
300     * index.
301     */
302    native int constantPoolRemapInstructionOperandFromCache(HotSpotConstantPool constantPool, int cpci);
303
304    /**
305     * Gets the appendix object (if any) associated with the entry at index {@code cpi} in
306     * {@code constantPool}.
307     */
308    native Object lookupAppendixInPool(HotSpotConstantPool constantPool, int cpi);
309
310    /**
311     * Installs the result of a compilation into the code cache.
312     *
313     * @param target the target where this code should be installed
314     * @param compiledCode the result of a compilation
315     * @param code the details of the installed CodeBlob are written to this object
316     * @return the outcome of the installation which will be one of
317     *         {@link HotSpotVMConfig#codeInstallResultOk},
318     *         {@link HotSpotVMConfig#codeInstallResultCacheFull},
319     *         {@link HotSpotVMConfig#codeInstallResultCodeTooLarge},
320     *         {@link HotSpotVMConfig#codeInstallResultDependenciesFailed} or
321     *         {@link HotSpotVMConfig#codeInstallResultDependenciesInvalid}.
322     * @throws JVMCIError if there is something wrong with the compiled code or the associated
323     *             metadata.
324     */
325    native int installCode(TargetDescription target, HotSpotCompiledCode compiledCode, InstalledCode code, HotSpotSpeculationLog speculationLog);
326
327    /**
328     * Generates the VM metadata for some compiled code and copies them into {@code metaData}. This
329     * method does not install anything into the code cache.
330     *
331     * @param target the target where this code would be installed
332     * @param compiledCode the result of a compilation
333     * @param metaData the metadata is written to this object
334     * @return the outcome of the installation which will be one of
335     *         {@link HotSpotVMConfig#codeInstallResultOk},
336     *         {@link HotSpotVMConfig#codeInstallResultCacheFull},
337     *         {@link HotSpotVMConfig#codeInstallResultCodeTooLarge},
338     *         {@link HotSpotVMConfig#codeInstallResultDependenciesFailed} or
339     *         {@link HotSpotVMConfig#codeInstallResultDependenciesInvalid}.
340     * @throws JVMCIError if there is something wrong with the compiled code or the metadata
341     */
342    native int getMetadata(TargetDescription target, HotSpotCompiledCode compiledCode, HotSpotMetaData metaData);
343
344    /**
345     * Resets all compilation statistics.
346     */
347    native void resetCompilationStatistics();
348
349    /**
350     * Reads the database of VM info. The return value encodes the info in a nested object array
351     * that is described by the pseudo Java object {@code info} below:
352     *
353     * <pre>
354     *     info = [
355     *         VMField[] vmFields,
356     *         [String name, Long size, ...] vmTypeSizes,
357     *         [String name, Long value, ...] vmConstants,
358     *         [String name, Long value, ...] vmAddresses,
359     *         VMFlag[] vmFlags
360     *         VMIntrinsicMethod[] vmIntrinsics
361     *     ]
362     * </pre>
363     *
364     * @return VM info as encoded above
365     */
366    native Object[] readConfiguration();
367
368    /**
369     * Resolves the implementation of {@code method} for virtual dispatches on objects of dynamic
370     * type {@code exactReceiver}. This resolution process only searches "up" the class hierarchy of
371     * {@code exactReceiver}.
372     *
373     * @param caller the caller or context type used to perform access checks
374     * @return the link-time resolved method (might be abstract) or {@code null} if it is either a
375     *         signature polymorphic method or can not be linked.
376     */
377    native HotSpotResolvedJavaMethodImpl resolveMethod(HotSpotResolvedObjectTypeImpl exactReceiver, HotSpotResolvedJavaMethodImpl method, HotSpotResolvedObjectTypeImpl caller);
378
379    /**
380     * Gets the static initializer of {@code type}.
381     *
382     * @return 0 if {@code type} has no static initializer
383     */
384    native HotSpotResolvedJavaMethodImpl getClassInitializer(HotSpotResolvedObjectTypeImpl type);
385
386    /**
387     * Determines if {@code type} or any of its currently loaded subclasses overrides
388     * {@code Object.finalize()}.
389     */
390    native boolean hasFinalizableSubclass(HotSpotResolvedObjectTypeImpl type);
391
392    /**
393     * Gets the method corresponding to {@code executable}.
394     */
395    native HotSpotResolvedJavaMethodImpl asResolvedJavaMethod(Executable executable);
396
397    /**
398     * Gets the maximum absolute offset of a PC relative call to {@code address} from any position
399     * in the code cache.
400     *
401     * @param address an address that may be called from any code in the code cache
402     * @return -1 if {@code address == 0}
403     */
404    native long getMaxCallTargetOffset(long address);
405
406    /**
407     * Gets a textual disassembly of {@code codeBlob}.
408     *
409     * @return a non-zero length string containing a disassembly of {@code codeBlob} or null if
410     *         {@code codeBlob} could not be disassembled for some reason
411     */
412    // The HotSpot disassembler seems not to be thread safe so it's better to synchronize its usage
413    synchronized native String disassembleCodeBlob(InstalledCode installedCode);
414
415    /**
416     * Gets a stack trace element for {@code method} at bytecode index {@code bci}.
417     */
418    native StackTraceElement getStackTraceElement(HotSpotResolvedJavaMethodImpl method, int bci);
419
420    /**
421     * Executes some {@code installedCode} with arguments {@code args}.
422     *
423     * @return the result of executing {@code installedCode}
424     * @throws InvalidInstalledCodeException if {@code installedCode} has been invalidated
425     */
426    native Object executeInstalledCode(Object[] args, InstalledCode installedCode) throws InvalidInstalledCodeException;
427
428    /**
429     * Gets the line number table for {@code method}. The line number table is encoded as (bci,
430     * source line number) pairs.
431     *
432     * @return the line number table for {@code method} or null if it doesn't have one
433     */
434    native long[] getLineNumberTable(HotSpotResolvedJavaMethodImpl method);
435
436    /**
437     * Gets the number of entries in the local variable table for {@code method}.
438     *
439     * @return the number of entries in the local variable table for {@code method}
440     */
441    native int getLocalVariableTableLength(HotSpotResolvedJavaMethodImpl method);
442
443    /**
444     * Gets the address of the first entry in the local variable table for {@code method}.
445     *
446     * Each entry is a native object described by these fields:
447     *
448     * <ul>
449     * <li>{@link HotSpotVMConfig#localVariableTableElementSize}</li>
450     * <li>{@link HotSpotVMConfig#localVariableTableElementLengthOffset}</li>
451     * <li>{@link HotSpotVMConfig#localVariableTableElementNameCpIndexOffset}</li>
452     * <li>{@link HotSpotVMConfig#localVariableTableElementDescriptorCpIndexOffset}</li>
453     * <li>{@link HotSpotVMConfig#localVariableTableElementSlotOffset}
454     * <li>{@link HotSpotVMConfig#localVariableTableElementStartBciOffset}
455     * </ul>
456     *
457     * @return 0 if {@code method} does not have a local variable table
458     */
459    native long getLocalVariableTableStart(HotSpotResolvedJavaMethodImpl method);
460
461    /**
462     * Determines if {@code method} should not be inlined or compiled.
463     */
464    native void doNotInlineOrCompile(HotSpotResolvedJavaMethodImpl method);
465
466    /**
467     * Invalidates the profiling information for {@code method} and (re)initializes it such that
468     * profiling restarts upon its next invocation.
469     */
470    native void reprofile(HotSpotResolvedJavaMethodImpl method);
471
472    /**
473     * Invalidates {@code installedCode} such that {@link InvalidInstalledCodeException} will be
474     * raised the next time {@code installedCode} is executed.
475     */
476    native void invalidateInstalledCode(InstalledCode installedCode);
477
478    /**
479     * Collects the current values of all JVMCI benchmark counters, summed up over all threads.
480     */
481    native long[] collectCounters();
482
483    /**
484     * Determines if {@code metaspaceMethodData} is mature.
485     */
486    native boolean isMature(long metaspaceMethodData);
487
488    /**
489     * Generate a unique id to identify the result of the compile.
490     */
491    native int allocateCompileId(HotSpotResolvedJavaMethodImpl method, int entryBCI);
492
493    /**
494     * Determines if {@code method} has OSR compiled code identified by {@code entryBCI} for
495     * compilation level {@code level}.
496     */
497    native boolean hasCompiledCodeForOSR(HotSpotResolvedJavaMethodImpl method, int entryBCI, int level);
498
499    /**
500     * Gets the value of {@code metaspaceSymbol} as a String.
501     */
502    native String getSymbol(long metaspaceSymbol);
503
504    /**
505     * Looks for the next Java stack frame matching an entry in {@code methods}.
506     *
507     * @param frame the starting point of the search, where {@code null} refers to the topmost frame
508     * @param methods the methods to look for, where {@code null} means that any frame is returned
509     * @return the frame, or {@code null} if the end of the stack was reached during the search
510     */
511    native HotSpotStackFrameReference getNextStackFrame(HotSpotStackFrameReference frame, ResolvedJavaMethod[] methods, int initialSkip);
512
513    /**
514     * Materializes all virtual objects within {@code stackFrame} and updates its locals.
515     *
516     * @param invalidate if {@code true}, the compiled method for the stack frame will be
517     *            invalidated
518     */
519    native void materializeVirtualObjects(HotSpotStackFrameReference stackFrame, boolean invalidate);
520
521    /**
522     * Gets the v-table index for interface method {@code method} in the receiver {@code type} or
523     * {@link HotSpotVMConfig#invalidVtableIndex} if {@code method} is not in {@code type}'s
524     * v-table.
525     *
526     * @throws InternalError if {@code type} is an interface or {@code method} is not held by an
527     *             interface or class represented by {@code type} is not initialized
528     */
529    native int getVtableIndexForInterfaceMethod(HotSpotResolvedObjectTypeImpl type, HotSpotResolvedJavaMethodImpl method);
530
531    /**
532     * Determines if debug info should also be emitted at non-safepoint locations.
533     */
534    native boolean shouldDebugNonSafepoints();
535
536    /**
537     * Writes {@code length} bytes from {@code bytes} starting at offset {@code offset} to the
538     * HotSpot's log stream.
539     *
540     * @exception NullPointerException if {@code bytes == null}
541     * @exception IndexOutOfBoundsException if copying would cause access of data outside array
542     *                bounds
543     */
544    native void writeDebugOutput(byte[] bytes, int offset, int length);
545
546    /**
547     * Flush HotSpot's log stream.
548     */
549    native void flushDebugOutput();
550
551    /**
552     * Read a HotSpot Method* value from the memory location described by {@code base} plus
553     * {@code displacement} and return the {@link HotSpotResolvedJavaMethodImpl} wrapping it. This
554     * method does no checking that the memory location actually contains a valid pointer and may
555     * crash the VM if an invalid location is provided. If the {@code base} is null then
556     * {@code displacement} is used by itself. If {@code base} is a
557     * {@link HotSpotResolvedJavaMethodImpl}, {@link HotSpotConstantPool} or
558     * {@link HotSpotResolvedObjectTypeImpl} then the metaspace pointer is fetched from that object
559     * and added to {@code displacement}. Any other non-null object type causes an
560     * {@link IllegalArgumentException} to be thrown.
561     *
562     * @param base an object to read from or null
563     * @param displacement
564     * @return null or the resolved method for this location
565     */
566    native HotSpotResolvedJavaMethodImpl getResolvedJavaMethod(Object base, long displacement);
567
568    /**
569     * Gets the {@code ConstantPool*} associated with {@code object} and returns a
570     * {@link HotSpotConstantPool} wrapping it.
571     *
572     * @param object a {@link HotSpotResolvedJavaMethodImpl} or
573     *            {@link HotSpotResolvedObjectTypeImpl} object
574     * @return a {@link HotSpotConstantPool} wrapping the {@code ConstantPool*} associated with
575     *         {@code object}
576     * @throws NullPointerException if {@code object == null}
577     * @throws IllegalArgumentException if {@code object} is neither a
578     *             {@link HotSpotResolvedJavaMethodImpl} nor a {@link HotSpotResolvedObjectTypeImpl}
579     */
580    native HotSpotConstantPool getConstantPool(Object object);
581
582    /**
583     * Read a HotSpot Klass* value from the memory location described by {@code base} plus
584     * {@code displacement} and return the {@link HotSpotResolvedObjectTypeImpl} wrapping it. This
585     * method does no checking that the memory location actually contains a valid pointer and may
586     * crash the VM if an invalid location is provided. If the {@code base} is null then
587     * {@code displacement} is used by itself. If {@code base} is a
588     * {@link HotSpotResolvedJavaMethodImpl}, {@link HotSpotConstantPool} or
589     * {@link HotSpotResolvedObjectTypeImpl} then the metaspace pointer is fetched from that object
590     * and added to {@code displacement}. Any other non-null object type causes an
591     * {@link IllegalArgumentException} to be thrown.
592     *
593     * @param base an object to read from or null
594     * @param displacement
595     * @param compressed true if the location contains a compressed Klass*
596     * @return null or the resolved method for this location
597     */
598    native HotSpotResolvedObjectTypeImpl getResolvedJavaType(Object base, long displacement, boolean compressed);
599
600    /**
601     * Return the size of the HotSpot ProfileData* pointed at by {@code position}. If
602     * {@code position} is outside the space of the MethodData then an
603     * {@link IllegalArgumentException} is thrown. A {@code position} inside the MethodData but that
604     * isn't pointing at a valid ProfileData will crash the VM.
605     *
606     * @param metaspaceMethodData
607     * @param position
608     * @return the size of the ProfileData item pointed at by {@code position}
609     * @throws IllegalArgumentException if an out of range position is given
610     */
611    native int methodDataProfileDataSize(long metaspaceMethodData, int position);
612
613    /**
614     * Gets the fingerprint for a given Klass*
615     *
616     * @param metaspaceKlass
617     * @return the value of the fingerprint (zero for arrays and synthetic classes).
618     */
619    native long getFingerprint(long metaspaceKlass);
620
621    /**
622     * Return the amount of native stack required for the interpreter frames represented by
623     * {@code frame}. This is used when emitting the stack banging code to ensure that there is
624     * enough space for the frames during deoptimization.
625     *
626     * @param frame
627     * @return the number of bytes required for deoptimization of this frame state
628     */
629    native int interpreterFrameSize(BytecodeFrame frame);
630
631    /**
632     * Invokes non-public method {@code java.lang.invoke.LambdaForm.compileToBytecode()} on
633     * {@code lambdaForm} (which must be a {@code java.lang.invoke.LambdaForm} instance).
634     */
635    native void compileToBytecode(Object lambdaForm);
636
637    /**
638     * Gets the value of the VM flag named {@code name}.
639     *
640     * @param name name of a VM option
641     * @return {@code this} if the named VM option doesn't exist, a {@link String} or {@code null}
642     *         if its type is {@code ccstr} or {@code ccstrlist}, a {@link Double} if its type is
643     *         {@code double}, a {@link Boolean} if its type is {@code bool} otherwise a
644     *         {@link Long}
645     */
646    native Object getFlagValue(String name);
647
648    /**
649     * Gets the host class for {@code type}.
650     */
651    native HotSpotResolvedObjectTypeImpl getHostClass(HotSpotResolvedObjectTypeImpl type);
652}
653