1 /*
2  * Copyright (c) 2012, 2019, 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 sun.hotspot;
25 
26 import java.lang.management.MemoryUsage;
27 import java.lang.reflect.Executable;
28 import java.util.Arrays;
29 import java.util.List;
30 import java.util.function.BiFunction;
31 import java.util.function.Function;
32 import java.security.BasicPermission;
33 import java.util.Objects;
34 
35 import sun.hotspot.parser.DiagnosticCommand;
36 
37 public class WhiteBox {
38   @SuppressWarnings("serial")
39   public static class WhiteBoxPermission extends BasicPermission {
WhiteBoxPermission(String s)40     public WhiteBoxPermission(String s) {
41       super(s);
42     }
43   }
44 
WhiteBox()45   private WhiteBox() {}
46   private static final WhiteBox instance = new WhiteBox();
registerNatives()47   private static native void registerNatives();
48 
49   /**
50    * Returns the singleton WhiteBox instance.
51    *
52    * The returned WhiteBox object should be carefully guarded
53    * by the caller, since it can be used to read and write data
54    * at arbitrary memory addresses. It must never be passed to
55    * untrusted code.
56    */
getWhiteBox()57   public synchronized static WhiteBox getWhiteBox() {
58     SecurityManager sm = System.getSecurityManager();
59     if (sm != null) {
60       sm.checkPermission(new WhiteBoxPermission("getInstance"));
61     }
62     return instance;
63   }
64 
65   static {
registerNatives()66     registerNatives();
67   }
68 
69   // Get the maximum heap size supporting COOPs
getCompressedOopsMaxHeapSize()70   public native long getCompressedOopsMaxHeapSize();
71   // Arguments
printHeapSizes()72   public native void printHeapSizes();
73 
74   // Memory
getObjectAddress0(Object o)75   private native long getObjectAddress0(Object o);
getObjectAddress(Object o)76   public           long getObjectAddress(Object o) {
77     Objects.requireNonNull(o);
78     return getObjectAddress0(o);
79   }
80 
getHeapOopSize()81   public native int  getHeapOopSize();
getVMPageSize()82   public native int  getVMPageSize();
getVMAllocationGranularity()83   public native long getVMAllocationGranularity();
getVMLargePageSize()84   public native long getVMLargePageSize();
getHeapSpaceAlignment()85   public native long getHeapSpaceAlignment();
getHeapAlignment()86   public native long getHeapAlignment();
87 
isObjectInOldGen0(Object o)88   private native boolean isObjectInOldGen0(Object o);
isObjectInOldGen(Object o)89   public         boolean isObjectInOldGen(Object o) {
90     Objects.requireNonNull(o);
91     return isObjectInOldGen0(o);
92   }
93 
getObjectSize0(Object o)94   private native long getObjectSize0(Object o);
getObjectSize(Object o)95   public         long getObjectSize(Object o) {
96     Objects.requireNonNull(o);
97     return getObjectSize0(o);
98   }
99 
100   // Runtime
101   // Make sure class name is in the correct format
isClassAlive(String name)102   public boolean isClassAlive(String name) {
103     return isClassAlive0(name.replace('.', '/'));
104   }
isClassAlive0(String name)105   private native boolean isClassAlive0(String name);
getSymbolRefcount(String name)106   public  native int getSymbolRefcount(String name);
107 
isMonitorInflated0(Object obj)108   private native boolean isMonitorInflated0(Object obj);
isMonitorInflated(Object obj)109   public         boolean isMonitorInflated(Object obj) {
110     Objects.requireNonNull(obj);
111     return isMonitorInflated0(obj);
112   }
113 
forceSafepoint()114   public native void forceSafepoint();
115 
getConstantPool0(Class<?> aClass)116   private native long getConstantPool0(Class<?> aClass);
getConstantPool(Class<?> aClass)117   public         long getConstantPool(Class<?> aClass) {
118     Objects.requireNonNull(aClass);
119     return getConstantPool0(aClass);
120   }
121 
getConstantPoolCacheIndexTag0()122   private native int getConstantPoolCacheIndexTag0();
getConstantPoolCacheIndexTag()123   public         int getConstantPoolCacheIndexTag() {
124     return getConstantPoolCacheIndexTag0();
125   }
126 
getConstantPoolCacheLength0(Class<?> aClass)127   private native int getConstantPoolCacheLength0(Class<?> aClass);
getConstantPoolCacheLength(Class<?> aClass)128   public         int getConstantPoolCacheLength(Class<?> aClass) {
129     Objects.requireNonNull(aClass);
130     return getConstantPoolCacheLength0(aClass);
131   }
132 
remapInstructionOperandFromCPCache0(Class<?> aClass, int index)133   private native int remapInstructionOperandFromCPCache0(Class<?> aClass, int index);
remapInstructionOperandFromCPCache(Class<?> aClass, int index)134   public         int remapInstructionOperandFromCPCache(Class<?> aClass, int index) {
135     Objects.requireNonNull(aClass);
136     return remapInstructionOperandFromCPCache0(aClass, index);
137   }
138 
encodeConstantPoolIndyIndex0(int index)139   private native int encodeConstantPoolIndyIndex0(int index);
encodeConstantPoolIndyIndex(int index)140   public         int encodeConstantPoolIndyIndex(int index) {
141     return encodeConstantPoolIndyIndex0(index);
142   }
143 
144   // JVMTI
addToBootstrapClassLoaderSearch0(String segment)145   private native void addToBootstrapClassLoaderSearch0(String segment);
addToBootstrapClassLoaderSearch(String segment)146   public         void addToBootstrapClassLoaderSearch(String segment){
147     Objects.requireNonNull(segment);
148     addToBootstrapClassLoaderSearch0(segment);
149   }
150 
addToSystemClassLoaderSearch0(String segment)151   private native void addToSystemClassLoaderSearch0(String segment);
addToSystemClassLoaderSearch(String segment)152   public         void addToSystemClassLoaderSearch(String segment) {
153     Objects.requireNonNull(segment);
154     addToSystemClassLoaderSearch0(segment);
155   }
156 
157   // G1
g1InConcurrentMark()158   public native boolean g1InConcurrentMark();
g1IsHumongous0(Object o)159   private native boolean g1IsHumongous0(Object o);
g1IsHumongous(Object o)160   public         boolean g1IsHumongous(Object o) {
161     Objects.requireNonNull(o);
162     return g1IsHumongous0(o);
163   }
164 
g1BelongsToHumongousRegion0(long adr)165   private native boolean g1BelongsToHumongousRegion0(long adr);
g1BelongsToHumongousRegion(long adr)166   public         boolean g1BelongsToHumongousRegion(long adr) {
167     if (adr == 0) {
168       throw new IllegalArgumentException("adr argument should not be null");
169     }
170     return g1BelongsToHumongousRegion0(adr);
171   }
172 
173 
g1BelongsToFreeRegion0(long adr)174   private native boolean g1BelongsToFreeRegion0(long adr);
g1BelongsToFreeRegion(long adr)175   public         boolean g1BelongsToFreeRegion(long adr) {
176     if (adr == 0) {
177       throw new IllegalArgumentException("adr argument should not be null");
178     }
179     return g1BelongsToFreeRegion0(adr);
180   }
181 
g1NumMaxRegions()182   public native long    g1NumMaxRegions();
g1NumFreeRegions()183   public native long    g1NumFreeRegions();
g1RegionSize()184   public native int     g1RegionSize();
g1AuxiliaryMemoryUsage()185   public native MemoryUsage g1AuxiliaryMemoryUsage();
parseCommandLine0(String commandline, char delim, DiagnosticCommand[] args)186   private  native Object[]    parseCommandLine0(String commandline, char delim, DiagnosticCommand[] args);
parseCommandLine(String commandline, char delim, DiagnosticCommand[] args)187   public          Object[]    parseCommandLine(String commandline, char delim, DiagnosticCommand[] args) {
188     Objects.requireNonNull(args);
189     return parseCommandLine0(commandline, delim, args);
190   }
191 
192   // Parallel GC
psVirtualSpaceAlignment()193   public native long psVirtualSpaceAlignment();
psHeapGenerationAlignment()194   public native long psHeapGenerationAlignment();
195 
196   /**
197    * Enumerates old regions with liveness less than specified and produces some statistics
198    * @param liveness percent of region's liveness (live_objects / total_region_size * 100).
199    * @return long[3] array where long[0] - total count of old regions
200    *                             long[1] - total memory of old regions
201    *                             long[2] - lowest estimation of total memory of old regions to be freed (non-full
202    *                             regions are not included)
203    */
g1GetMixedGCInfo(int liveness)204   public native long[] g1GetMixedGCInfo(int liveness);
205 
206   // NMT
NMTMalloc(long size)207   public native long NMTMalloc(long size);
NMTFree(long mem)208   public native void NMTFree(long mem);
NMTReserveMemory(long size)209   public native long NMTReserveMemory(long size);
NMTAttemptReserveMemoryAt(long addr, long size)210   public native long NMTAttemptReserveMemoryAt(long addr, long size);
NMTCommitMemory(long addr, long size)211   public native void NMTCommitMemory(long addr, long size);
NMTUncommitMemory(long addr, long size)212   public native void NMTUncommitMemory(long addr, long size);
NMTReleaseMemory(long addr, long size)213   public native void NMTReleaseMemory(long addr, long size);
NMTMallocWithPseudoStack(long size, int index)214   public native long NMTMallocWithPseudoStack(long size, int index);
NMTMallocWithPseudoStackAndType(long size, int index, int type)215   public native long NMTMallocWithPseudoStackAndType(long size, int index, int type);
NMTChangeTrackingLevel()216   public native boolean NMTChangeTrackingLevel();
NMTGetHashSize()217   public native int NMTGetHashSize();
NMTNewArena(long initSize)218   public native long NMTNewArena(long initSize);
NMTFreeArena(long arena)219   public native void NMTFreeArena(long arena);
NMTArenaMalloc(long arena, long size)220   public native void NMTArenaMalloc(long arena, long size);
221 
222   // Compiler
matchesMethod(Executable method, String pattern)223   public native int     matchesMethod(Executable method, String pattern);
matchesInline(Executable method, String pattern)224   public native int     matchesInline(Executable method, String pattern);
shouldPrintAssembly(Executable method, int comp_level)225   public native boolean shouldPrintAssembly(Executable method, int comp_level);
deoptimizeFrames(boolean makeNotEntrant)226   public native int     deoptimizeFrames(boolean makeNotEntrant);
deoptimizeAll()227   public native void    deoptimizeAll();
228 
isMethodCompiled(Executable method)229   public        boolean isMethodCompiled(Executable method) {
230     return isMethodCompiled(method, false /*not osr*/);
231   }
isMethodCompiled0(Executable method, boolean isOsr)232   private native boolean isMethodCompiled0(Executable method, boolean isOsr);
isMethodCompiled(Executable method, boolean isOsr)233   public         boolean isMethodCompiled(Executable method, boolean isOsr){
234     Objects.requireNonNull(method);
235     return isMethodCompiled0(method, isOsr);
236   }
isMethodCompilable(Executable method)237   public        boolean isMethodCompilable(Executable method) {
238     return isMethodCompilable(method, -2 /*any*/);
239   }
isMethodCompilable(Executable method, int compLevel)240   public        boolean isMethodCompilable(Executable method, int compLevel) {
241     return isMethodCompilable(method, compLevel, false /*not osr*/);
242   }
isMethodCompilable0(Executable method, int compLevel, boolean isOsr)243   private native boolean isMethodCompilable0(Executable method, int compLevel, boolean isOsr);
isMethodCompilable(Executable method, int compLevel, boolean isOsr)244   public         boolean isMethodCompilable(Executable method, int compLevel, boolean isOsr) {
245     Objects.requireNonNull(method);
246     return isMethodCompilable0(method, compLevel, isOsr);
247   }
isMethodQueuedForCompilation0(Executable method)248   private native boolean isMethodQueuedForCompilation0(Executable method);
isMethodQueuedForCompilation(Executable method)249   public         boolean isMethodQueuedForCompilation(Executable method) {
250     Objects.requireNonNull(method);
251     return isMethodQueuedForCompilation0(method);
252   }
253   // Determine if the compiler corresponding to the compilation level 'compLevel'
254   // and to the compilation context 'compilation_context' provides an intrinsic
255   // for the method 'method'. An intrinsic is available for method 'method' if:
256   //  - the intrinsic is enabled (by using the appropriate command-line flag) and
257   //  - the platform on which the VM is running provides the instructions necessary
258   //    for the compiler to generate the intrinsic code.
259   //
260   // The compilation context is related to using the DisableIntrinsic flag on a
261   // per-method level, see hotspot/src/share/vm/compiler/abstractCompiler.hpp
262   // for more details.
isIntrinsicAvailable(Executable method, Executable compilationContext, int compLevel)263   public boolean isIntrinsicAvailable(Executable method,
264                                       Executable compilationContext,
265                                       int compLevel) {
266       Objects.requireNonNull(method);
267       return isIntrinsicAvailable0(method, compilationContext, compLevel);
268   }
269   // If usage of the DisableIntrinsic flag is not expected (or the usage can be ignored),
270   // use the below method that does not require the compilation context as argument.
isIntrinsicAvailable(Executable method, int compLevel)271   public boolean isIntrinsicAvailable(Executable method, int compLevel) {
272       return isIntrinsicAvailable(method, null, compLevel);
273   }
isIntrinsicAvailable0(Executable method, Executable compilationContext, int compLevel)274   private native boolean isIntrinsicAvailable0(Executable method,
275                                                Executable compilationContext,
276                                                int compLevel);
deoptimizeMethod(Executable method)277   public        int     deoptimizeMethod(Executable method) {
278     return deoptimizeMethod(method, false /*not osr*/);
279   }
deoptimizeMethod0(Executable method, boolean isOsr)280   private native int     deoptimizeMethod0(Executable method, boolean isOsr);
deoptimizeMethod(Executable method, boolean isOsr)281   public         int     deoptimizeMethod(Executable method, boolean isOsr) {
282     Objects.requireNonNull(method);
283     return deoptimizeMethod0(method, isOsr);
284   }
makeMethodNotCompilable(Executable method)285   public        void    makeMethodNotCompilable(Executable method) {
286     makeMethodNotCompilable(method, -2 /*any*/);
287   }
makeMethodNotCompilable(Executable method, int compLevel)288   public        void    makeMethodNotCompilable(Executable method, int compLevel) {
289     makeMethodNotCompilable(method, compLevel, false /*not osr*/);
290   }
makeMethodNotCompilable0(Executable method, int compLevel, boolean isOsr)291   private native void    makeMethodNotCompilable0(Executable method, int compLevel, boolean isOsr);
makeMethodNotCompilable(Executable method, int compLevel, boolean isOsr)292   public         void    makeMethodNotCompilable(Executable method, int compLevel, boolean isOsr) {
293     Objects.requireNonNull(method);
294     makeMethodNotCompilable0(method, compLevel, isOsr);
295   }
getMethodCompilationLevel(Executable method)296   public        int     getMethodCompilationLevel(Executable method) {
297     return getMethodCompilationLevel(method, false /*not ost*/);
298   }
getMethodCompilationLevel0(Executable method, boolean isOsr)299   private native int     getMethodCompilationLevel0(Executable method, boolean isOsr);
getMethodCompilationLevel(Executable method, boolean isOsr)300   public         int     getMethodCompilationLevel(Executable method, boolean isOsr) {
301     Objects.requireNonNull(method);
302     return getMethodCompilationLevel0(method, isOsr);
303   }
testSetDontInlineMethod0(Executable method, boolean value)304   private native boolean testSetDontInlineMethod0(Executable method, boolean value);
testSetDontInlineMethod(Executable method, boolean value)305   public         boolean testSetDontInlineMethod(Executable method, boolean value) {
306     Objects.requireNonNull(method);
307     return testSetDontInlineMethod0(method, value);
308   }
getCompileQueuesSize()309   public        int     getCompileQueuesSize() {
310     return getCompileQueueSize(-2 /*any*/);
311   }
getCompileQueueSize(int compLevel)312   public native int     getCompileQueueSize(int compLevel);
testSetForceInlineMethod0(Executable method, boolean value)313   private native boolean testSetForceInlineMethod0(Executable method, boolean value);
testSetForceInlineMethod(Executable method, boolean value)314   public         boolean testSetForceInlineMethod(Executable method, boolean value) {
315     Objects.requireNonNull(method);
316     return testSetForceInlineMethod0(method, value);
317   }
enqueueMethodForCompilation(Executable method, int compLevel)318   public        boolean enqueueMethodForCompilation(Executable method, int compLevel) {
319     return enqueueMethodForCompilation(method, compLevel, -1 /*InvocationEntryBci*/);
320   }
enqueueMethodForCompilation0(Executable method, int compLevel, int entry_bci)321   private native boolean enqueueMethodForCompilation0(Executable method, int compLevel, int entry_bci);
enqueueMethodForCompilation(Executable method, int compLevel, int entry_bci)322   public  boolean enqueueMethodForCompilation(Executable method, int compLevel, int entry_bci) {
323     Objects.requireNonNull(method);
324     return enqueueMethodForCompilation0(method, compLevel, entry_bci);
325   }
enqueueInitializerForCompilation0(Class<?> aClass, int compLevel)326   private native boolean enqueueInitializerForCompilation0(Class<?> aClass, int compLevel);
enqueueInitializerForCompilation(Class<?> aClass, int compLevel)327   public  boolean enqueueInitializerForCompilation(Class<?> aClass, int compLevel) {
328     Objects.requireNonNull(aClass);
329     return enqueueInitializerForCompilation0(aClass, compLevel);
330   }
clearMethodState0(Executable method)331   private native void    clearMethodState0(Executable method);
markMethodProfiled(Executable method)332   public  native void    markMethodProfiled(Executable method);
clearMethodState(Executable method)333   public         void    clearMethodState(Executable method) {
334     Objects.requireNonNull(method);
335     clearMethodState0(method);
336   }
lockCompilation()337   public native void    lockCompilation();
unlockCompilation()338   public native void    unlockCompilation();
getMethodEntryBci0(Executable method)339   private native int     getMethodEntryBci0(Executable method);
getMethodEntryBci(Executable method)340   public         int     getMethodEntryBci(Executable method) {
341     Objects.requireNonNull(method);
342     return getMethodEntryBci0(method);
343   }
getNMethod0(Executable method, boolean isOsr)344   private native Object[] getNMethod0(Executable method, boolean isOsr);
getNMethod(Executable method, boolean isOsr)345   public         Object[] getNMethod(Executable method, boolean isOsr) {
346     Objects.requireNonNull(method);
347     return getNMethod0(method, isOsr);
348   }
allocateCodeBlob(int size, int type)349   public native long    allocateCodeBlob(int size, int type);
allocateCodeBlob(long size, int type)350   public        long    allocateCodeBlob(long size, int type) {
351       int intSize = (int) size;
352       if ((long) intSize != size || size < 0) {
353           throw new IllegalArgumentException(
354                 "size argument has illegal value " + size);
355       }
356       return allocateCodeBlob( intSize, type);
357   }
freeCodeBlob(long addr)358   public native void    freeCodeBlob(long addr);
forceNMethodSweep()359   public native void    forceNMethodSweep();
getCodeHeapEntries(int type)360   public native Object[] getCodeHeapEntries(int type);
getCompilationActivityMode()361   public native int     getCompilationActivityMode();
getMethodData0(Executable method)362   private native long getMethodData0(Executable method);
getMethodData(Executable method)363   public         long getMethodData(Executable method) {
364     Objects.requireNonNull(method);
365     return getMethodData0(method);
366   }
getCodeBlob(long addr)367   public native Object[] getCodeBlob(long addr);
368 
clearInlineCaches0(boolean preserve_static_stubs)369   private native void clearInlineCaches0(boolean preserve_static_stubs);
clearInlineCaches()370   public void clearInlineCaches() {
371     clearInlineCaches0(false);
372   }
clearInlineCaches(boolean preserve_static_stubs)373   public void clearInlineCaches(boolean preserve_static_stubs) {
374     clearInlineCaches0(preserve_static_stubs);
375   }
376 
377   // Intered strings
isInStringTable(String str)378   public native boolean isInStringTable(String str);
379 
380   // Memory
readReservedMemory()381   public native void readReservedMemory();
allocateMetaspace(ClassLoader classLoader, long size)382   public native long allocateMetaspace(ClassLoader classLoader, long size);
freeMetaspace(ClassLoader classLoader, long addr, long size)383   public native void freeMetaspace(ClassLoader classLoader, long addr, long size);
incMetaspaceCapacityUntilGC(long increment)384   public native long incMetaspaceCapacityUntilGC(long increment);
metaspaceCapacityUntilGC()385   public native long metaspaceCapacityUntilGC();
metaspaceShouldConcurrentCollect()386   public native boolean metaspaceShouldConcurrentCollect();
metaspaceReserveAlignment()387   public native long metaspaceReserveAlignment();
388 
389   // Don't use these methods directly
390   // Use sun.hotspot.gc.GC class instead.
isGCSupported(int name)391   public native boolean isGCSupported(int name);
isGCSelected(int name)392   public native boolean isGCSelected(int name);
isGCSelectedErgonomically()393   public native boolean isGCSelectedErgonomically();
394 
395   // Force Young GC
youngGC()396   public native void youngGC();
397 
398   // Force Full GC
fullGC()399   public native void fullGC();
400 
401   // Returns true if the current GC supports control of its concurrent
402   // phase via requestConcurrentGCPhase().  If false, a request will
403   // always fail.
supportsConcurrentGCPhaseControl()404   public native boolean supportsConcurrentGCPhaseControl();
405 
406   // Returns an array of concurrent phase names provided by this
407   // collector.  These are the names recognized by
408   // requestConcurrentGCPhase().
getConcurrentGCPhases()409   public native String[] getConcurrentGCPhases();
410 
411   // Attempt to put the collector into the indicated concurrent phase,
412   // and attempt to remain in that state until a new request is made.
413   //
414   // Returns immediately if already in the requested phase.
415   // Otherwise, waits until the phase is reached.
416   //
417   // Throws IllegalStateException if unsupported by the current collector.
418   // Throws NullPointerException if phase is null.
419   // Throws IllegalArgumentException if phase is not valid for the current collector.
requestConcurrentGCPhase(String phase)420   public void requestConcurrentGCPhase(String phase) {
421     if (!supportsConcurrentGCPhaseControl()) {
422       throw new IllegalStateException("Concurrent GC phase control not supported");
423     } else if (phase == null) {
424       throw new NullPointerException("null phase");
425     } else if (!requestConcurrentGCPhase0(phase)) {
426       throw new IllegalArgumentException("Unknown concurrent GC phase: " + phase);
427     }
428   }
429 
430   // Helper for requestConcurrentGCPhase().  Returns true if request
431   // succeeded, false if the phase is invalid.
requestConcurrentGCPhase0(String phase)432   private native boolean requestConcurrentGCPhase0(String phase);
433 
434   // Method tries to start concurrent mark cycle.
435   // It returns false if CM Thread is always in concurrent cycle.
g1StartConcMarkCycle()436   public native boolean g1StartConcMarkCycle();
437 
438   // Tests on ReservedSpace/VirtualSpace classes
stressVirtualSpaceResize(long reservedSpaceSize, long magnitude, long iterations)439   public native int stressVirtualSpaceResize(long reservedSpaceSize, long magnitude, long iterations);
runMemoryUnitTests()440   public native void runMemoryUnitTests();
readFromNoaccessArea()441   public native void readFromNoaccessArea();
getThreadStackSize()442   public native long getThreadStackSize();
getThreadRemainingStackSize()443   public native long getThreadRemainingStackSize();
444 
445   // CPU features
getCPUFeatures()446   public native String getCPUFeatures();
447 
448   // VM flags
isConstantVMFlag(String name)449   public native boolean isConstantVMFlag(String name);
isLockedVMFlag(String name)450   public native boolean isLockedVMFlag(String name);
setBooleanVMFlag(String name, boolean value)451   public native void    setBooleanVMFlag(String name, boolean value);
setIntVMFlag(String name, long value)452   public native void    setIntVMFlag(String name, long value);
setUintVMFlag(String name, long value)453   public native void    setUintVMFlag(String name, long value);
setIntxVMFlag(String name, long value)454   public native void    setIntxVMFlag(String name, long value);
setUintxVMFlag(String name, long value)455   public native void    setUintxVMFlag(String name, long value);
setUint64VMFlag(String name, long value)456   public native void    setUint64VMFlag(String name, long value);
setSizeTVMFlag(String name, long value)457   public native void    setSizeTVMFlag(String name, long value);
setStringVMFlag(String name, String value)458   public native void    setStringVMFlag(String name, String value);
setDoubleVMFlag(String name, double value)459   public native void    setDoubleVMFlag(String name, double value);
getBooleanVMFlag(String name)460   public native Boolean getBooleanVMFlag(String name);
getIntVMFlag(String name)461   public native Long    getIntVMFlag(String name);
getUintVMFlag(String name)462   public native Long    getUintVMFlag(String name);
getIntxVMFlag(String name)463   public native Long    getIntxVMFlag(String name);
getUintxVMFlag(String name)464   public native Long    getUintxVMFlag(String name);
getUint64VMFlag(String name)465   public native Long    getUint64VMFlag(String name);
getSizeTVMFlag(String name)466   public native Long    getSizeTVMFlag(String name);
getStringVMFlag(String name)467   public native String  getStringVMFlag(String name);
getDoubleVMFlag(String name)468   public native Double  getDoubleVMFlag(String name);
469   private final List<Function<String,Object>> flagsGetters = Arrays.asList(
470     this::getBooleanVMFlag, this::getIntVMFlag, this::getUintVMFlag,
471     this::getIntxVMFlag, this::getUintxVMFlag, this::getUint64VMFlag,
472     this::getSizeTVMFlag, this::getStringVMFlag, this::getDoubleVMFlag);
473 
getVMFlag(String name)474   public Object getVMFlag(String name) {
475     return flagsGetters.stream()
476                        .map(f -> f.apply(name))
477                        .filter(x -> x != null)
478                        .findAny()
479                        .orElse(null);
480   }
481 
482   // Jigsaw
DefineModule(Object module, boolean is_open, String version, String location, Object[] packages)483   public native void DefineModule(Object module, boolean is_open, String version,
484                                   String location, Object[] packages);
AddModuleExports(Object from_module, String pkg, Object to_module)485   public native void AddModuleExports(Object from_module, String pkg, Object to_module);
AddReadsModule(Object from_module, Object source_module)486   public native void AddReadsModule(Object from_module, Object source_module);
AddModuleExportsToAllUnnamed(Object module, String pkg)487   public native void AddModuleExportsToAllUnnamed(Object module, String pkg);
AddModuleExportsToAll(Object module, String pkg)488   public native void AddModuleExportsToAll(Object module, String pkg);
489 
getOffsetForName0(String name)490   public native int getOffsetForName0(String name);
getOffsetForName(String name)491   public int getOffsetForName(String name) throws Exception {
492     int offset = getOffsetForName0(name);
493     if (offset == -1) {
494       throw new RuntimeException(name + " not found");
495     }
496     return offset;
497   }
getMethodBooleanOption(Executable method, String name)498   public native Boolean getMethodBooleanOption(Executable method, String name);
getMethodIntxOption(Executable method, String name)499   public native Long    getMethodIntxOption(Executable method, String name);
getMethodUintxOption(Executable method, String name)500   public native Long    getMethodUintxOption(Executable method, String name);
getMethodDoubleOption(Executable method, String name)501   public native Double  getMethodDoubleOption(Executable method, String name);
getMethodStringOption(Executable method, String name)502   public native String  getMethodStringOption(Executable method, String name);
503   private final List<BiFunction<Executable,String,Object>> methodOptionGetters
504       = Arrays.asList(this::getMethodBooleanOption, this::getMethodIntxOption,
505           this::getMethodUintxOption, this::getMethodDoubleOption,
506           this::getMethodStringOption);
507 
getMethodOption(Executable method, String name)508   public Object getMethodOption(Executable method, String name) {
509     return methodOptionGetters.stream()
510                               .map(f -> f.apply(method, name))
511                               .filter(x -> x != null)
512                               .findAny()
513                               .orElse(null);
514   }
515 
516   // Safepoint Checking
assertMatchingSafepointCalls(boolean mutexSafepointValue, boolean attemptedNoSafepointValue)517   public native void assertMatchingSafepointCalls(boolean mutexSafepointValue, boolean attemptedNoSafepointValue);
518 
519   // Sharing & archiving
isShared(Object o)520   public native boolean isShared(Object o);
isSharedClass(Class<?> c)521   public native boolean isSharedClass(Class<?> c);
areSharedStringsIgnored()522   public native boolean areSharedStringsIgnored();
isCDSIncludedInVmBuild()523   public native boolean isCDSIncludedInVmBuild();
isJFRIncludedInVmBuild()524   public native boolean isJFRIncludedInVmBuild();
isJavaHeapArchiveSupported()525   public native boolean isJavaHeapArchiveSupported();
getResolvedReferences(Class<?> c)526   public native Object  getResolvedReferences(Class<?> c);
areOpenArchiveHeapObjectsMapped()527   public native boolean areOpenArchiveHeapObjectsMapped();
528 
529   // Compiler Directive
addCompilerDirective(String compDirect)530   public native int addCompilerDirective(String compDirect);
removeCompilerDirective(int count)531   public native void removeCompilerDirective(int count);
532 
533   // Handshakes
handshakeWalkStack(Thread t, boolean all_threads)534   public native int handshakeWalkStack(Thread t, boolean all_threads);
535 
536   // Returns true on linux if library has the noexecstack flag set.
checkLibSpecifiesNoexecstack(String libfilename)537   public native boolean checkLibSpecifiesNoexecstack(String libfilename);
538 
539   // Container testing
isContainerized()540   public native boolean isContainerized();
printOsInfo()541   public native void printOsInfo();
542 
543   // Decoder
disableElfSectionCache()544   public native void disableElfSectionCache();
545 
546   // Number of loaded AOT libraries
aotLibrariesCount()547   public native int aotLibrariesCount();
548 }
549