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 {
40 public WhiteBoxPermission(String s) {
41 super(s);
42 }
43 }
44
45 private WhiteBox() {}
46 private static final WhiteBox instance = new WhiteBox();
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
55 * untrusted code.
56 */
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 {
66 registerNatives();
67 }
68
69 // Get the maximum heap size supporting COOPs
70 public native long getCompressedOopsMaxHeapSize();
71 // Arguments
72 public native void printHeapSizes();
73
74 // Memory
75 private native long getObjectAddress0(Object o);
76 public long getObjectAddress(Object o) {
77 Objects.requireNonNull(o);
78 return getObjectAddress0(o);
79 }
80
81 public native int getHeapOopSize();
82 public native int getVMPageSize();
83 public native long getVMAllocationGranularity();
84 public native long getVMLargePageSize();
85 public native long getHeapSpaceAlignment();
86 public native long getHeapAlignment();
87
88 private native boolean isObjectInOldGen0(Object o);
89 public boolean isObjectInOldGen(Object o) {
90 Objects.requireNonNull(o);
91 return isObjectInOldGen0(o);
92 }
93
94 private native long getObjectSize0(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
102 public boolean isClassAlive(String name) {
103 return isClassAlive0(name.replace('.', '/'));
104 }
105 private native boolean isClassAlive0(String name);
106
107 private native boolean isMonitorInflated0(Object obj);
108 public boolean isMonitorInflated(Object obj) {
109 Objects.requireNonNull(obj);
110 return isMonitorInflated0(obj);
111 }
112
113 public native void forceSafepoint();
114
115 private native long getConstantPool0(Class<?> aClass);
116 public long getConstantPool(Class<?> aClass) {
117 Objects.requireNonNull(aClass);
118 return getConstantPool0(aClass);
119 }
120
121 private native int getConstantPoolCacheIndexTag0();
122 public int getConstantPoolCacheIndexTag() {
123 return getConstantPoolCacheIndexTag0();
124 }
125
126 private native int getConstantPoolCacheLength0(Class<?> aClass);
127 public int getConstantPoolCacheLength(Class<?> aClass) {
128 Objects.requireNonNull(aClass);
129 return getConstantPoolCacheLength0(aClass);
130 }
131
132 private native int remapInstructionOperandFromCPCache0(Class<?> aClass, int index);
133 public int remapInstructionOperandFromCPCache(Class<?> aClass, int index) {
134 Objects.requireNonNull(aClass);
135 return remapInstructionOperandFromCPCache0(aClass, index);
136 }
137
138 private native int encodeConstantPoolIndyIndex0(int index);
139 public int encodeConstantPoolIndyIndex(int index) {
140 return encodeConstantPoolIndyIndex0(index);
141 }
142
143 // JVMTI
144 private native void addToBootstrapClassLoaderSearch0(String segment);
145 public void addToBootstrapClassLoaderSearch(String segment){
146 Objects.requireNonNull(segment);
147 addToBootstrapClassLoaderSearch0(segment);
148 }
149
150 private native void addToSystemClassLoaderSearch0(String segment);
151 public void addToSystemClassLoaderSearch(String segment) {
152 Objects.requireNonNull(segment);
153 addToSystemClassLoaderSearch0(segment);
154 }
155
156 // G1
157 public native boolean g1InConcurrentMark();
158 private native boolean g1IsHumongous0(Object o);
159 public boolean g1IsHumongous(Object o) {
160 Objects.requireNonNull(o);
161 return g1IsHumongous0(o);
162 }
163
164 private native boolean g1BelongsToHumongousRegion0(long adr);
165 public boolean g1BelongsToHumongousRegion(long adr) {
166 if (adr == 0) {
167 throw new IllegalArgumentException("adr argument should not be null");
168 }
169 return g1BelongsToHumongousRegion0(adr);
170 }
171
172
173 private native boolean g1BelongsToFreeRegion0(long adr);
174 public boolean g1BelongsToFreeRegion(long adr) {
175 if (adr == 0) {
176 throw new IllegalArgumentException("adr argument should not be null");
177 }
178 return g1BelongsToFreeRegion0(adr);
179 }
180
181 public native long g1NumMaxRegions();
182 public native long g1NumFreeRegions();
183 public native int g1RegionSize();
184 public native MemoryUsage g1AuxiliaryMemoryUsage();
185 private native Object[] parseCommandLine0(String commandline, char delim, DiagnosticCommand[] args);
186 public Object[] parseCommandLine(String commandline, char delim, DiagnosticCommand[] args) {
187 Objects.requireNonNull(args);
188 return parseCommandLine0(commandline, delim, args);
189 }
190
191 // Parallel GC
192 public native long psVirtualSpaceAlignment();
193 public native long psHeapGenerationAlignment();
194
195 /**
196 * Enumerates old regions with liveness less than specified and produces some statistics
197 * @param liveness percent of region's liveness (live_objects / total_region_size * 100).
198 * @return long[3] array where long[0] - total count of old regions
199 * long[1] - total memory of old regions
200 * long[2] - lowest estimation of total memory of old regions to be freed (non-full
201 * regions are not included)
202 */
203 public native long[] g1GetMixedGCInfo(int liveness);
204
205 // NMT
206 public native long NMTMalloc(long size);
207 public native void NMTFree(long mem);
208 public native long NMTReserveMemory(long size);
209 public native long NMTAttemptReserveMemoryAt(long addr, long size);
210 public native void NMTCommitMemory(long addr, long size);
211 public native void NMTUncommitMemory(long addr, long size);
212 public native void NMTReleaseMemory(long addr, long size);
213 public native long NMTMallocWithPseudoStack(long size, int index);
214 public native boolean NMTChangeTrackingLevel();
215 public native int NMTGetHashSize();
216
217 // Compiler
218 public native int matchesMethod(Executable method, String pattern);
219 public native int matchesInline(Executable method, String pattern);
220 public native boolean shouldPrintAssembly(Executable method, int comp_level);
221 public native int deoptimizeFrames(boolean makeNotEntrant);
222 public native void deoptimizeAll();
223
224 public boolean isMethodCompiled(Executable method) {
225 return isMethodCompiled(method, false /*not osr*/);
226 }
227 private native boolean isMethodCompiled0(Executable method, boolean isOsr);
228 public boolean isMethodCompiled(Executable method, boolean isOsr){
229 Objects.requireNonNull(method);
230 return isMethodCompiled0(method, isOsr);
231 }
232 public boolean isMethodCompilable(Executable method) {
233 return isMethodCompilable(method, -2 /*any*/);
234 }
235 public boolean isMethodCompilable(Executable method, int compLevel) {
236 return isMethodCompilable(method, compLevel, false /*not osr*/);
237 }
238 private native boolean isMethodCompilable0(Executable method, int compLevel, boolean isOsr);
239 public boolean isMethodCompilable(Executable method, int compLevel, boolean isOsr) {
240 Objects.requireNonNull(method);
241 return isMethodCompilable0(method, compLevel, isOsr);
242 }
243 private native boolean isMethodQueuedForCompilation0(Executable method);
244 public boolean isMethodQueuedForCompilation(Executable method) {
245 Objects.requireNonNull(method);
246 return isMethodQueuedForCompilation0(method);
247 }
248 // Determine if the compiler corresponding to the compilation level 'compLevel'
249 // and to the compilation context 'compilation_context' provides an intrinsic
250 // for the method 'method'. An intrinsic is available for method 'method' if:
251 // - the intrinsic is enabled (by using the appropriate command-line flag) and
252 // - the platform on which the VM is running provides the instructions necessary
253 // for the compiler to generate the intrinsic code.
254 //
255 // The compilation context is related to using the DisableIntrinsic flag on a
256 // per-method level, see hotspot/src/share/vm/compiler/abstractCompiler.hpp
257 // for more details.
258 public boolean isIntrinsicAvailable(Executable method,
259 Executable compilationContext,
260 int compLevel) {
261 Objects.requireNonNull(method);
262 return isIntrinsicAvailable0(method, compilationContext, compLevel);
263 }
264 // If usage of the DisableIntrinsic flag is not expected (or the usage can be ignored),
265 // use the below method that does not require the compilation context as argument.
266 public boolean isIntrinsicAvailable(Executable method, int compLevel) {
267 return isIntrinsicAvailable(method, null, compLevel);
268 }
269 private native boolean isIntrinsicAvailable0(Executable method,
270 Executable compilationContext,
271 int compLevel);
272 public int deoptimizeMethod(Executable method) {
273 return deoptimizeMethod(method, false /*not osr*/);
274 }
275 private native int deoptimizeMethod0(Executable method, boolean isOsr);
276 public int deoptimizeMethod(Executable method, boolean isOsr) {
277 Objects.requireNonNull(method);
278 return deoptimizeMethod0(method, isOsr);
279 }
280 public void makeMethodNotCompilable(Executable method) {
281 makeMethodNotCompilable(method, -2 /*any*/);
282 }
283 public void makeMethodNotCompilable(Executable method, int compLevel) {
284 makeMethodNotCompilable(method, compLevel, false /*not osr*/);
285 }
286 private native void makeMethodNotCompilable0(Executable method, int compLevel, boolean isOsr);
287 public void makeMethodNotCompilable(Executable method, int compLevel, boolean isOsr) {
288 Objects.requireNonNull(method);
289 makeMethodNotCompilable0(method, compLevel, isOsr);
290 }
291 public int getMethodCompilationLevel(Executable method) {
292 return getMethodCompilationLevel(method, false /*not ost*/);
293 }
294 private native int getMethodCompilationLevel0(Executable method, boolean isOsr);
295 public int getMethodCompilationLevel(Executable method, boolean isOsr) {
296 Objects.requireNonNull(method);
297 return getMethodCompilationLevel0(method, isOsr);
298 }
299 private native boolean testSetDontInlineMethod0(Executable method, boolean value);
300 public boolean testSetDontInlineMethod(Executable method, boolean value) {
301 Objects.requireNonNull(method);
302 return testSetDontInlineMethod0(method, value);
303 }
304 public int getCompileQueuesSize() {
305 return getCompileQueueSize(-2 /*any*/);
306 }
307 public native int getCompileQueueSize(int compLevel);
308 private native boolean testSetForceInlineMethod0(Executable method, boolean value);
309 public boolean testSetForceInlineMethod(Executable method, boolean value) {
310 Objects.requireNonNull(method);
311 return testSetForceInlineMethod0(method, value);
312 }
313 public boolean enqueueMethodForCompilation(Executable method, int compLevel) {
314 return enqueueMethodForCompilation(method, compLevel, -1 /*InvocationEntryBci*/);
315 }
316 private native boolean enqueueMethodForCompilation0(Executable method, int compLevel, int entry_bci);
317 public boolean enqueueMethodForCompilation(Executable method, int compLevel, int entry_bci) {
318 Objects.requireNonNull(method);
319 return enqueueMethodForCompilation0(method, compLevel, entry_bci);
320 }
321 private native boolean enqueueInitializerForCompilation0(Class<?> aClass, int compLevel);
322 public boolean enqueueInitializerForCompilation(Class<?> aClass, int compLevel) {
323 Objects.requireNonNull(aClass);
324 return enqueueInitializerForCompilation0(aClass, compLevel);
325 }
326 private native void clearMethodState0(Executable method);
327 public void clearMethodState(Executable method) {
328 Objects.requireNonNull(method);
329 clearMethodState0(method);
330 }
331 public native void lockCompilation();
332 public native void unlockCompilation();
333 private native int getMethodEntryBci0(Executable method);
334 public int getMethodEntryBci(Executable method) {
335 Objects.requireNonNull(method);
336 return getMethodEntryBci0(method);
337 }
338 private native Object[] getNMethod0(Executable method, boolean isOsr);
339 public Object[] getNMethod(Executable method, boolean isOsr) {
340 Objects.requireNonNull(method);
341 return getNMethod0(method, isOsr);
342 }
343 public native long allocateCodeBlob(int size, int type);
344 public long allocateCodeBlob(long size, int type) {
345 int intSize = (int) size;
346 if ((long) intSize != size || size < 0) {
347 throw new IllegalArgumentException(
348 "size argument has illegal value " + size);
349 }
350 return allocateCodeBlob( intSize, type);
351 }
352 public native void freeCodeBlob(long addr);
353 public native void forceNMethodSweep();
354 public native Object[] getCodeHeapEntries(int type);
355 public native int getCompilationActivityMode();
356 private native long getMethodData0(Executable method);
357 public long getMethodData(Executable method) {
358 Objects.requireNonNull(method);
359 return getMethodData0(method);
360 }
361 public native Object[] getCodeBlob(long addr);
362
|
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 import java.net.URL;
35
36 import sun.hotspot.parser.DiagnosticCommand;
37
38 public class WhiteBox {
39 @SuppressWarnings("serial")
40 public static class WhiteBoxPermission extends BasicPermission {
41 public WhiteBoxPermission(String s) {
42 super(s);
43 }
44 }
45
46 private WhiteBox() {}
47 private static final WhiteBox instance = new WhiteBox();
48 private static native void registerNatives();
49
50 /**
51 * Returns the singleton WhiteBox instance.
52 *
53 * The returned WhiteBox object should be carefully guarded
54 * by the caller, since it can be used to read and write data
56 * untrusted code.
57 */
58 public synchronized static WhiteBox getWhiteBox() {
59 SecurityManager sm = System.getSecurityManager();
60 if (sm != null) {
61 sm.checkPermission(new WhiteBoxPermission("getInstance"));
62 }
63 return instance;
64 }
65
66 static {
67 registerNatives();
68 }
69
70 // Get the maximum heap size supporting COOPs
71 public native long getCompressedOopsMaxHeapSize();
72 // Arguments
73 public native void printHeapSizes();
74
75 // Memory
76 public native long getObjectAddress(Object o);
77 public native int getHeapOopSize();
78 public native int getVMPageSize();
79 public native long getVMAllocationGranularity();
80 public native long getVMLargePageSize();
81 public native long getHeapSpaceAlignment();
82 public native long getHeapAlignment();
83
84 public native boolean isObjectInOldGen(Object o);
85 public native long getObjectSize(Object o);
86
87 public native boolean classKnownToNotExist(ClassLoader loader, String name);
88 public native URL[] getLookupCacheURLs(ClassLoader loader);
89 public native int[] getLookupCacheMatches(ClassLoader loader, String name);
90
91 // Runtime
92 // Make sure class name is in the correct format
93 public boolean isClassAlive(String name) {
94 return isClassAlive0(name.replace('.', '/'));
95 }
96 private native boolean isClassAlive0(String name);
97
98 public native boolean isMonitorInflated(Object obj);
99
100 public native void forceSafepoint();
101
102 private native long getConstantPool0(Class<?> aClass);
103 public long getConstantPool(Class<?> aClass) {
104 Objects.requireNonNull(aClass);
105 return getConstantPool0(aClass);
106 }
107
108 private native int getConstantPoolCacheIndexTag0();
109 public int getConstantPoolCacheIndexTag() {
110 return getConstantPoolCacheIndexTag0();
111 }
112
113 private native int getConstantPoolCacheLength0(Class<?> aClass);
114 public int getConstantPoolCacheLength(Class<?> aClass) {
115 Objects.requireNonNull(aClass);
116 return getConstantPoolCacheLength0(aClass);
117 }
118
119 private native int remapInstructionOperandFromCPCache0(Class<?> aClass, int index);
120 public int remapInstructionOperandFromCPCache(Class<?> aClass, int index) {
121 Objects.requireNonNull(aClass);
122 return remapInstructionOperandFromCPCache0(aClass, index);
123 }
124
125 private native int encodeConstantPoolIndyIndex0(int index);
126 public int encodeConstantPoolIndyIndex(int index) {
127 return encodeConstantPoolIndyIndex0(index);
128 }
129
130 // JVMTI
131 public native void addToBootstrapClassLoaderSearch(String segment);
132 public native void addToSystemClassLoaderSearch(String segment);
133
134 // G1
135 public native boolean g1InConcurrentMark();
136 public native boolean g1IsHumongous(Object o);
137 public native boolean g1BelongsToHumongousRegion(long adr);
138 public native boolean g1BelongsToFreeRegion(long adr);
139 public native long g1NumMaxRegions();
140 public native long g1NumFreeRegions();
141 public native int g1RegionSize();
142 public native MemoryUsage g1AuxiliaryMemoryUsage();
143 public native Object[] parseCommandLine(String commandline, DiagnosticCommand[] args);
144
145 // Parallel GC
146 public native long psVirtualSpaceAlignment();
147 public native long psHeapGenerationAlignment();
148
149 /**
150 * Enumerates old regions with liveness less than specified and produces some statistics
151 * @param liveness percent of region's liveness (live_objects / total_region_size * 100).
152 * @return long[3] array where long[0] - total count of old regions
153 * long[1] - total memory of old regions
154 * long[2] - lowest estimation of total memory of old regions to be freed (non-full
155 * regions are not included)
156 */
157 public native long[] g1GetMixedGCInfo(int liveness);
158
159 // NMT
160 public native long NMTMalloc(long size);
161 public native void NMTFree(long mem);
162 public native long NMTReserveMemory(long size);
163 public native long NMTAttemptReserveMemoryAt(long addr, long size);
164 public native void NMTCommitMemory(long addr, long size);
165 public native void NMTUncommitMemory(long addr, long size);
166 public native void NMTReleaseMemory(long addr, long size);
167 public native long NMTMallocWithPseudoStack(long size, int index);
168 public native long NMTMallocWithPseudoStackAndType(long size, int index, int type);
169 public native boolean NMTIsDetailSupported();
170 public native boolean NMTChangeTrackingLevel();
171 public native int NMTGetHashSize();
172
173 // Compiler
174 public native int matchesMethod(Executable method, String pattern);
175 public native int matchesInline(Executable method, String pattern);
176 public native boolean shouldPrintAssembly(Executable method, int comp_level);
177 public native int deoptimizeFrames(boolean makeNotEntrant);
178 public native void deoptimizeAll();
179
180 public boolean isMethodCompiled(Executable method) {
181 return isMethodCompiled(method, false /*not osr*/);
182 }
183 public native boolean isMethodCompiled(Executable method, boolean isOsr);
184 public boolean isMethodCompilable(Executable method) {
185 return isMethodCompilable(method, -2 /*any*/);
186 }
187 public boolean isMethodCompilable(Executable method, int compLevel) {
188 return isMethodCompilable(method, compLevel, false /*not osr*/);
189 }
190 public native boolean isMethodCompilable(Executable method, int compLevel, boolean isOsr);
191
192 public native boolean isMethodQueuedForCompilation(Executable method);
193
194 // Determine if the compiler corresponding to the compilation level 'compLevel'
195 // and to the compilation context 'compilation_context' provides an intrinsic
196 // for the method 'method'. An intrinsic is available for method 'method' if:
197 // - the intrinsic is enabled (by using the appropriate command-line flag) and
198 // - the platform on which the VM is running provides the instructions necessary
199 // for the compiler to generate the intrinsic code.
200 //
201 // The compilation context is related to using the DisableIntrinsic flag on a
202 // per-method level, see hotspot/src/share/vm/compiler/abstractCompiler.hpp
203 // for more details.
204 public boolean isIntrinsicAvailable(Executable method,
205 Executable compilationContext,
206 int compLevel) {
207 Objects.requireNonNull(method);
208 return isIntrinsicAvailable0(method, compilationContext, compLevel);
209 }
210 // If usage of the DisableIntrinsic flag is not expected (or the usage can be ignored),
211 // use the below method that does not require the compilation context as argument.
212 public boolean isIntrinsicAvailable(Executable method, int compLevel) {
213 return isIntrinsicAvailable(method, null, compLevel);
214 }
215 private native boolean isIntrinsicAvailable0(Executable method,
216 Executable compilationContext,
217 int compLevel);
218 public int deoptimizeMethod(Executable method) {
219 return deoptimizeMethod(method, false /*not osr*/);
220 }
221 public native int deoptimizeMethod(Executable method, boolean isOsr);
222 public void makeMethodNotCompilable(Executable method) {
223 makeMethodNotCompilable(method, -2 /*any*/);
224 }
225 public void makeMethodNotCompilable(Executable method, int compLevel) {
226 makeMethodNotCompilable(method, compLevel, false /*not osr*/);
227 }
228 public native void makeMethodNotCompilable(Executable method, int compLevel, boolean isOsr);
229 public int getMethodCompilationLevel(Executable method) {
230 return getMethodCompilationLevel(method, false /*not ost*/);
231 }
232 public native int getMethodCompilationLevel(Executable method, boolean isOsr);
233 public native boolean testSetDontInlineMethod(Executable method, boolean value);
234 public int getCompileQueuesSize() {
235 return getCompileQueueSize(-2 /*any*/);
236 }
237 public native int getCompileQueueSize(int compLevel);
238 public native boolean testSetForceInlineMethod(Executable method, boolean value);
239
240 public boolean enqueueMethodForCompilation(Executable method, int compLevel) {
241 return enqueueMethodForCompilation(method, compLevel, -1 /*InvocationEntryBci*/);
242 }
243 public native boolean enqueueMethodForCompilation(Executable method, int compLevel, int entry_bci);
244 public native boolean enqueueInitializerForCompilation(Class<?> aClass, int compLevel);
245 public native void clearMethodState(Executable method);
246 public native void lockCompilation();
247 public native void unlockCompilation();
248 public native int getMethodEntryBci(Executable method);
249 public native Object[] getNMethod(Executable method, boolean isOsr);
250 public native long allocateCodeBlob(int size, int type);
251 public long allocateCodeBlob(long size, int type) {
252 int intSize = (int) size;
253 if ((long) intSize != size || size < 0) {
254 throw new IllegalArgumentException(
255 "size argument has illegal value " + size);
256 }
257 return allocateCodeBlob( intSize, type);
258 }
259 public native void freeCodeBlob(long addr);
260 public native void forceNMethodSweep();
261 public native Object[] getCodeHeapEntries(int type);
262 public native int getCompilationActivityMode();
263 private native long getMethodData0(Executable method);
264 public long getMethodData(Executable method) {
265 Objects.requireNonNull(method);
266 return getMethodData0(method);
267 }
268 public native Object[] getCodeBlob(long addr);
269
|