1 /*
2 * Copyright (c) 2012, 2023, 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.test.whitebox;
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 jdk.test.whitebox.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
54 * at arbitrary memory addresses. It must never be passed to
55 * untrusted code.
56 */
57 public synchronized static WhiteBox getWhiteBox() {
58 @SuppressWarnings("removal")
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 private native long getObjectAddress0(Object o);
77 public long getObjectAddress(Object o) {
78 Objects.requireNonNull(o);
79 return getObjectAddress0(o);
80 }
81
82 public native int getHeapOopSize();
83 public native int getVMPageSize();
84 public native long getVMAllocationGranularity();
85 public native long getVMLargePageSize();
86 public native long getHeapSpaceAlignment();
87 public native long getHeapAlignment();
88
89 private native boolean isObjectInOldGen0(Object o);
90 public boolean isObjectInOldGen(Object o) {
91 Objects.requireNonNull(o);
92 return isObjectInOldGen0(o);
93 }
94
95 private native long getObjectSize0(Object o);
96 public long getObjectSize(Object o) {
97 Objects.requireNonNull(o);
98 return getObjectSize0(o);
99 }
100
101 // Runtime
102 // Make sure class name is in the correct format
103 public int countAliveClasses(String name) {
104 return countAliveClasses0(name.replace('.', '/'));
105 }
106 private native int countAliveClasses0(String name);
107
108 public boolean isClassAlive(String name) {
109 return countAliveClasses(name) != 0;
110 }
111
112 public native int getSymbolRefcount(String name);
113
114 public native boolean deflateIdleMonitors();
115
116 private native boolean isMonitorInflated0(Object obj);
117 public boolean isMonitorInflated(Object obj) {
118 Objects.requireNonNull(obj);
119 return isMonitorInflated0(obj);
120 }
121
122 public native void forceSafepoint();
123
124 public native void forceClassLoaderStatsSafepoint();
125
126 private native long getConstantPool0(Class<?> aClass);
127 public long getConstantPool(Class<?> aClass) {
128 Objects.requireNonNull(aClass);
129 return getConstantPool0(aClass);
130 }
131
132 private native int getConstantPoolCacheIndexTag0();
133 public int getConstantPoolCacheIndexTag() {
134 return getConstantPoolCacheIndexTag0();
135 }
136
137 private native int getConstantPoolCacheLength0(Class<?> aClass);
138 public int getConstantPoolCacheLength(Class<?> aClass) {
139 Objects.requireNonNull(aClass);
140 return getConstantPoolCacheLength0(aClass);
141 }
142
143 private native Object[] getResolvedReferences0(Class<?> aClass);
144 public Object[] getResolvedReferences(Class<?> aClass) {
145 Objects.requireNonNull(aClass);
146 return getResolvedReferences0(aClass);
147 }
148
149 private native int remapInstructionOperandFromCPCache0(Class<?> aClass, int index);
150 public int remapInstructionOperandFromCPCache(Class<?> aClass, int index) {
151 Objects.requireNonNull(aClass);
152 return remapInstructionOperandFromCPCache0(aClass, index);
153 }
154
155 private native int encodeConstantPoolIndyIndex0(int index);
156 public int encodeConstantPoolIndyIndex(int index) {
157 return encodeConstantPoolIndyIndex0(index);
158 }
159
160 private native int getIndyInfoLength0(Class<?> aClass);
161 public int getIndyInfoLength(Class<?> aClass) {
162 Objects.requireNonNull(aClass);
163 return getIndyInfoLength0(aClass);
164 }
165
166 private native int getIndyCPIndex0(Class<?> aClass, int index);
167 public int getIndyCPIndex(Class<?> aClass, int index) {
168 Objects.requireNonNull(aClass);
169 return getIndyCPIndex0(aClass, index);
170 }
171
172 // JVMTI
173 private native void addToBootstrapClassLoaderSearch0(String segment);
174 public void addToBootstrapClassLoaderSearch(String segment){
175 Objects.requireNonNull(segment);
176 addToBootstrapClassLoaderSearch0(segment);
177 }
178
179 private native void addToSystemClassLoaderSearch0(String segment);
180 public void addToSystemClassLoaderSearch(String segment) {
181 Objects.requireNonNull(segment);
182 addToSystemClassLoaderSearch0(segment);
183 }
184
185 // G1
186
187 public native boolean g1InConcurrentMark();
188 public native int g1CompletedConcurrentMarkCycles();
189
190 // Perform a complete concurrent GC cycle, using concurrent GC breakpoints.
191 // Completes any in-progress cycle before performing the requested cycle.
192 // Returns true if the cycle completed successfully. If the cycle was not
193 // successful (e.g. it was aborted), then throws RuntimeException if
194 // errorIfFail is true, returning false otherwise.
195 public boolean g1RunConcurrentGC(boolean errorIfFail) {
196 try {
197 // Take control, waiting until any in-progress cycle completes.
198 concurrentGCAcquireControl();
199 int count = g1CompletedConcurrentMarkCycles();
200 concurrentGCRunTo(AFTER_MARKING_STARTED, false);
201 concurrentGCRunToIdle();
202 if (count < g1CompletedConcurrentMarkCycles()) {
203 return true;
204 } else if (errorIfFail) {
205 throw new RuntimeException("Concurrent GC aborted");
206 } else {
207 return false;
208 }
209 } finally {
210 concurrentGCReleaseControl();
211 }
212 }
213
214 public void g1RunConcurrentGC() {
215 g1RunConcurrentGC(true);
216 }
217
218 // Start a concurrent GC cycle, using concurrent GC breakpoints.
219 // The concurrent GC will continue in parallel with the caller.
220 // Completes any in-progress cycle before starting the requested cycle.
221 public void g1StartConcurrentGC() {
222 try {
223 // Take control, waiting until any in-progress cycle completes.
224 concurrentGCAcquireControl();
225 concurrentGCRunTo(AFTER_MARKING_STARTED, false);
226 } finally {
227 // Release control, permitting the cycle to complete.
228 concurrentGCReleaseControl();
229 }
230 }
231
232 public native boolean g1HasRegionsToUncommit();
233 private native boolean g1IsHumongous0(Object o);
234 public boolean g1IsHumongous(Object o) {
235 Objects.requireNonNull(o);
236 return g1IsHumongous0(o);
237 }
238
239 private native boolean g1BelongsToHumongousRegion0(long adr);
240 public boolean g1BelongsToHumongousRegion(long adr) {
241 if (adr == 0) {
242 throw new IllegalArgumentException("adr argument should not be null");
243 }
244 return g1BelongsToHumongousRegion0(adr);
245 }
246
247
248 private native boolean g1BelongsToFreeRegion0(long adr);
249 public boolean g1BelongsToFreeRegion(long adr) {
250 if (adr == 0) {
251 throw new IllegalArgumentException("adr argument should not be null");
252 }
253 return g1BelongsToFreeRegion0(adr);
254 }
255
256 public native long g1NumMaxRegions();
257 public native long g1NumFreeRegions();
258 public native int g1RegionSize();
259 public native MemoryUsage g1AuxiliaryMemoryUsage();
260 private native Object[] parseCommandLine0(String commandline, char delim, DiagnosticCommand[] args);
261 public Object[] parseCommandLine(String commandline, char delim, DiagnosticCommand[] args) {
262 Objects.requireNonNull(args);
263 return parseCommandLine0(commandline, delim, args);
264 }
265
266 public native int g1ActiveMemoryNodeCount();
267 public native int[] g1MemoryNodeIds();
268
269 // Parallel GC
270 public native long psVirtualSpaceAlignment();
271 public native long psHeapGenerationAlignment();
272
273 /**
274 * Enumerates old regions with liveness less than specified and produces some statistics
275 * @param liveness percent of region's liveness (live_objects / total_region_size * 100).
276 * @return long[3] array where long[0] - total count of old regions
277 * long[1] - total memory of old regions
278 * long[2] - lowest estimation of total memory of old regions to be freed (non-full
279 * regions are not included)
280 */
281 public native long[] g1GetMixedGCInfo(int liveness);
282
283 // NMT
284 public native long NMTMalloc(long size);
285 public native void NMTFree(long mem);
286 public native long NMTReserveMemory(long size);
287 public native long NMTAttemptReserveMemoryAt(long addr, long size);
288 public native void NMTCommitMemory(long addr, long size);
289 public native void NMTUncommitMemory(long addr, long size);
290 public native void NMTReleaseMemory(long addr, long size);
291 public native long NMTMallocWithPseudoStack(long size, int index);
292 public native long NMTMallocWithPseudoStackAndType(long size, int index, int type);
293 public native int NMTGetHashSize();
294 public native long NMTNewArena(long initSize);
295 public native void NMTFreeArena(long arena);
296 public native void NMTArenaMalloc(long arena, long size);
297
298 // Compiler
299 public native boolean isC2OrJVMCIIncluded();
300 public native boolean isJVMCISupportedByGC();
301
302 public native int matchesMethod(Executable method, String pattern);
303 public native int matchesInline(Executable method, String pattern);
304 public native boolean shouldPrintAssembly(Executable method, int comp_level);
305 public native int deoptimizeFrames(boolean makeNotEntrant);
306 public native boolean isFrameDeoptimized(int depth);
307 public native void deoptimizeAll();
308
309 public boolean isMethodCompiled(Executable method) {
310 return isMethodCompiled(method, false /*not osr*/);
311 }
312 private native boolean isMethodCompiled0(Executable method, boolean isOsr);
313 public boolean isMethodCompiled(Executable method, boolean isOsr){
314 Objects.requireNonNull(method);
315 return isMethodCompiled0(method, isOsr);
316 }
317 public boolean isMethodCompilable(Executable method) {
318 return isMethodCompilable(method, -1 /*any*/);
319 }
320 public boolean isMethodCompilable(Executable method, int compLevel) {
321 return isMethodCompilable(method, compLevel, false /*not osr*/);
322 }
323 private native boolean isMethodCompilable0(Executable method, int compLevel, boolean isOsr);
324 public boolean isMethodCompilable(Executable method, int compLevel, boolean isOsr) {
325 Objects.requireNonNull(method);
326 return isMethodCompilable0(method, compLevel, isOsr);
327 }
328 private native boolean isMethodQueuedForCompilation0(Executable method);
329 public boolean isMethodQueuedForCompilation(Executable method) {
330 Objects.requireNonNull(method);
331 return isMethodQueuedForCompilation0(method);
332 }
333 // Determine if the compiler corresponding to the compilation level 'compLevel'
334 // and to the compilation context 'compilation_context' provides an intrinsic
335 // for the method 'method'. An intrinsic is available for method 'method' if:
336 // - the intrinsic is enabled (by using the appropriate command-line flag) and
337 // - the platform on which the VM is running provides the instructions necessary
338 // for the compiler to generate the intrinsic code.
339 //
340 // The compilation context is related to using the DisableIntrinsic flag on a
341 // per-method level, see hotspot/src/share/vm/compiler/abstractCompiler.hpp
342 // for more details.
343 public boolean isIntrinsicAvailable(Executable method,
344 Executable compilationContext,
345 int compLevel) {
346 Objects.requireNonNull(method);
347 return isIntrinsicAvailable0(method, compilationContext, compLevel);
348 }
349 // If usage of the DisableIntrinsic flag is not expected (or the usage can be ignored),
350 // use the below method that does not require the compilation context as argument.
351 public boolean isIntrinsicAvailable(Executable method, int compLevel) {
352 return isIntrinsicAvailable(method, null, compLevel);
353 }
354 private native boolean isIntrinsicAvailable0(Executable method,
355 Executable compilationContext,
356 int compLevel);
357 public int deoptimizeMethod(Executable method) {
358 return deoptimizeMethod(method, false /*not osr*/);
359 }
360 private native int deoptimizeMethod0(Executable method, boolean isOsr);
361 public int deoptimizeMethod(Executable method, boolean isOsr) {
362 Objects.requireNonNull(method);
363 return deoptimizeMethod0(method, isOsr);
364 }
365 public void makeMethodNotCompilable(Executable method) {
366 makeMethodNotCompilable(method, -1 /*any*/);
367 }
368 public void makeMethodNotCompilable(Executable method, int compLevel) {
369 makeMethodNotCompilable(method, compLevel, false /*not osr*/);
370 }
371 private native void makeMethodNotCompilable0(Executable method, int compLevel, boolean isOsr);
372 public void makeMethodNotCompilable(Executable method, int compLevel, boolean isOsr) {
373 Objects.requireNonNull(method);
374 makeMethodNotCompilable0(method, compLevel, isOsr);
375 }
376 public int getMethodCompilationLevel(Executable method) {
377 return getMethodCompilationLevel(method, false /*not osr*/);
378 }
379 private native int getMethodCompilationLevel0(Executable method, boolean isOsr);
380 public int getMethodCompilationLevel(Executable method, boolean isOsr) {
381 Objects.requireNonNull(method);
382 return getMethodCompilationLevel0(method, isOsr);
383 }
384 public int getMethodDecompileCount(Executable method) {
385 Objects.requireNonNull(method);
386 return getMethodDecompileCount0(method);
387 }
388 private native int getMethodDecompileCount0(Executable method);
389 // Get the total trap count of a method. If the trap count for a specific reason
390 // did overflow, this includes the overflow trap count of the method.
391 public int getMethodTrapCount(Executable method) {
392 Objects.requireNonNull(method);
393 return getMethodTrapCount0(method, null);
394 }
395 // Get the trap count of a method for a specific reason. If the trap count for
396 // that reason did overflow, this includes the overflow trap count of the method.
397 public int getMethodTrapCount(Executable method, String reason) {
398 Objects.requireNonNull(method);
399 return getMethodTrapCount0(method, reason);
400 }
401 private native int getMethodTrapCount0(Executable method, String reason);
402 // Get the total deopt count.
403 public int getDeoptCount() {
404 return getDeoptCount0(null, null);
405 }
406 // Get the deopt count for a specific reason and a specific action. If either
407 // one of 'reason' or 'action' is null, the method returns the sum of all
408 // deoptimizations with the specific 'action' or 'reason' respectively.
409 // If both arguments are null, the method returns the total deopt count.
410 public int getDeoptCount(String reason, String action) {
411 return getDeoptCount0(reason, action);
412 }
413 private native int getDeoptCount0(String reason, String action);
414 private native boolean testSetDontInlineMethod0(Executable method, boolean value);
415 public boolean testSetDontInlineMethod(Executable method, boolean value) {
416 Objects.requireNonNull(method);
417 return testSetDontInlineMethod0(method, value);
418 }
419 public int getCompileQueuesSize() {
420 return getCompileQueueSize(-1 /*any*/);
421 }
422 public native int getCompileQueueSize(int compLevel);
423 private native boolean testSetForceInlineMethod0(Executable method, boolean value);
424 public boolean testSetForceInlineMethod(Executable method, boolean value) {
425 Objects.requireNonNull(method);
426 return testSetForceInlineMethod0(method, value);
427 }
428 public boolean enqueueMethodForCompilation(Executable method, int compLevel) {
429 return enqueueMethodForCompilation(method, compLevel, -1 /*InvocationEntryBci*/);
430 }
431 private native boolean enqueueMethodForCompilation0(Executable method, int compLevel, int entry_bci);
432 public boolean enqueueMethodForCompilation(Executable method, int compLevel, int entry_bci) {
433 Objects.requireNonNull(method);
434 return enqueueMethodForCompilation0(method, compLevel, entry_bci);
435 }
436 private native boolean enqueueInitializerForCompilation0(Class<?> aClass, int compLevel);
437 public boolean enqueueInitializerForCompilation(Class<?> aClass, int compLevel) {
438 Objects.requireNonNull(aClass);
439 return enqueueInitializerForCompilation0(aClass, compLevel);
440 }
441 private native void clearMethodState0(Executable method);
442 public native void markMethodProfiled(Executable method);
443 public void clearMethodState(Executable method) {
444 Objects.requireNonNull(method);
445 clearMethodState0(method);
446 }
447 public native void lockCompilation();
448 public native void unlockCompilation();
449 private native int getMethodEntryBci0(Executable method);
450 public int getMethodEntryBci(Executable method) {
451 Objects.requireNonNull(method);
452 return getMethodEntryBci0(method);
453 }
454 private native Object[] getNMethod0(Executable method, boolean isOsr);
455 public Object[] getNMethod(Executable method, boolean isOsr) {
456 Objects.requireNonNull(method);
457 return getNMethod0(method, isOsr);
458 }
459 public native long allocateCodeBlob(int size, int type);
460 public long allocateCodeBlob(long size, int type) {
461 int intSize = (int) size;
462 if ((long) intSize != size || size < 0) {
463 throw new IllegalArgumentException(
464 "size argument has illegal value " + size);
465 }
466 return allocateCodeBlob( intSize, type);
467 }
468 public native void freeCodeBlob(long addr);
469 public native Object[] getCodeHeapEntries(int type);
470 public native int getCompilationActivityMode();
471 private native long getMethodData0(Executable method);
472 public long getMethodData(Executable method) {
473 Objects.requireNonNull(method);
474 return getMethodData0(method);
475 }
476 public native Object[] getCodeBlob(long addr);
477
478 private native void clearInlineCaches0(boolean preserve_static_stubs);
479 public void clearInlineCaches() {
480 clearInlineCaches0(false);
481 }
482 public void clearInlineCaches(boolean preserve_static_stubs) {
483 clearInlineCaches0(preserve_static_stubs);
484 }
485
486 // Intered strings
487 public native boolean isInStringTable(String str);
488
489 // Memory
490 public native void readReservedMemory();
491 public native long allocateMetaspace(ClassLoader classLoader, long size);
492 public native long incMetaspaceCapacityUntilGC(long increment);
493 public native long metaspaceCapacityUntilGC();
494 public native long metaspaceSharedRegionAlignment();
495
496 public native void cleanMetaspaces();
497
498 // Metaspace Arena Tests
499 public native long createMetaspaceTestContext(long commit_limit, long reserve_limit);
500 public native void destroyMetaspaceTestContext(long context);
501 public native void purgeMetaspaceTestContext(long context);
502 public native void printMetaspaceTestContext(long context);
503 public native long getTotalCommittedWordsInMetaspaceTestContext(long context);
504 public native long getTotalUsedWordsInMetaspaceTestContext(long context);
505 public native long createArenaInTestContext(long context, boolean is_micro);
506 public native void destroyMetaspaceTestArena(long arena);
507 public native long allocateFromMetaspaceTestArena(long arena, long word_size);
508 public native void deallocateToMetaspaceTestArena(long arena, long p, long word_size);
509
510 public native long maxMetaspaceAllocationSize();
511
512 // Don't use these methods directly
513 // Use jdk.test.whitebox.gc.GC class instead.
514 public native boolean isGCSupported(int name);
515 public native boolean isGCSupportedByJVMCICompiler(int name);
516 public native boolean isGCSelected(int name);
517 public native boolean isGCSelectedErgonomically();
518
519 // Force Young GC
520 public native void youngGC();
521
522 // Force Full GC
523 public native void fullGC();
524
525 // Returns true if the current GC supports concurrent collection control.
526 public native boolean supportsConcurrentGCBreakpoints();
527
528 private void checkConcurrentGCBreakpointsSupported() {
529 if (!supportsConcurrentGCBreakpoints()) {
530 throw new UnsupportedOperationException("Concurrent GC breakpoints not supported");
531 }
532 }
533
534 private native void concurrentGCAcquireControl0();
535 private native void concurrentGCReleaseControl0();
536 private native void concurrentGCRunToIdle0();
537 private native boolean concurrentGCRunTo0(String breakpoint);
538
539 private static boolean concurrentGCIsControlled = false;
540 private void checkConcurrentGCIsControlled() {
541 if (!concurrentGCIsControlled) {
542 throw new IllegalStateException("Not controlling concurrent GC");
543 }
544 }
545
546 // All collectors supporting concurrent GC breakpoints are expected
547 // to provide at least the following breakpoints.
548 public final String AFTER_MARKING_STARTED = "AFTER MARKING STARTED";
549 public final String BEFORE_MARKING_COMPLETED = "BEFORE MARKING COMPLETED";
550
551 // Collectors supporting concurrent GC breakpoints that do reference
552 // processing concurrently should provide the following breakpoint.
553 public final String AFTER_CONCURRENT_REFERENCE_PROCESSING_STARTED =
554 "AFTER CONCURRENT REFERENCE PROCESSING STARTED";
555
556 // G1 specific GC breakpoints.
557 public final String G1_AFTER_REBUILD_STARTED = "AFTER REBUILD STARTED";
558 public final String G1_BEFORE_REBUILD_COMPLETED = "BEFORE REBUILD COMPLETED";
559 public final String G1_AFTER_CLEANUP_STARTED = "AFTER CLEANUP STARTED";
560 public final String G1_BEFORE_CLEANUP_COMPLETED = "BEFORE CLEANUP COMPLETED";
561
562 public void concurrentGCAcquireControl() {
563 checkConcurrentGCBreakpointsSupported();
564 if (concurrentGCIsControlled) {
565 throw new IllegalStateException("Already controlling concurrent GC");
566 }
567 concurrentGCAcquireControl0();
568 concurrentGCIsControlled = true;
569 }
570
571 public void concurrentGCReleaseControl() {
572 checkConcurrentGCBreakpointsSupported();
573 concurrentGCReleaseControl0();
574 concurrentGCIsControlled = false;
575 }
576
577 // Keep concurrent GC idle. Release from breakpoint.
578 public void concurrentGCRunToIdle() {
579 checkConcurrentGCBreakpointsSupported();
580 checkConcurrentGCIsControlled();
581 concurrentGCRunToIdle0();
582 }
583
584 // Allow concurrent GC to run to breakpoint.
585 // Throws IllegalStateException if reached end of cycle first.
586 public void concurrentGCRunTo(String breakpoint) {
587 concurrentGCRunTo(breakpoint, true);
588 }
589
590 // Allow concurrent GC to run to breakpoint.
591 // Returns true if reached breakpoint. If reached end of cycle first,
592 // then throws IllegalStateException if errorIfFail is true, returning
593 // false otherwise.
594 public boolean concurrentGCRunTo(String breakpoint, boolean errorIfFail) {
595 checkConcurrentGCBreakpointsSupported();
596 checkConcurrentGCIsControlled();
597 if (breakpoint == null) {
598 throw new NullPointerException("null breakpoint");
599 } else if (concurrentGCRunTo0(breakpoint)) {
600 return true;
601 } else if (errorIfFail) {
602 throw new IllegalStateException("Missed requested breakpoint \"" + breakpoint + "\"");
603 } else {
604 return false;
605 }
606 }
607
608 // Tests on ReservedSpace/VirtualSpace classes
609 public native int stressVirtualSpaceResize(long reservedSpaceSize, long magnitude, long iterations);
610 public native void readFromNoaccessArea();
611 public native long getThreadStackSize();
612 public native long getThreadRemainingStackSize();
613
614 // CPU features
615 public native String getCPUFeatures();
616
617 // VM flags
618 public native boolean isConstantVMFlag(String name);
619 public native boolean isDefaultVMFlag(String name);
620 public native boolean isLockedVMFlag(String name);
621 public native void setBooleanVMFlag(String name, boolean value);
622 public native void setIntVMFlag(String name, long value);
623 public native void setUintVMFlag(String name, long value);
624 public native void setIntxVMFlag(String name, long value);
625 public native void setUintxVMFlag(String name, long value);
626 public native void setUint64VMFlag(String name, long value);
627 public native void setSizeTVMFlag(String name, long value);
628 public native void setStringVMFlag(String name, String value);
629 public native void setDoubleVMFlag(String name, double value);
630 public native Boolean getBooleanVMFlag(String name);
631 public native Long getIntVMFlag(String name);
632 public native Long getUintVMFlag(String name);
633 public native Long getIntxVMFlag(String name);
634 public native Long getUintxVMFlag(String name);
635 public native Long getUint64VMFlag(String name);
636 public native Long getSizeTVMFlag(String name);
637 public native String getStringVMFlag(String name);
638 public native Double getDoubleVMFlag(String name);
639 private final List<Function<String,Object>> flagsGetters = Arrays.asList(
640 this::getBooleanVMFlag, this::getIntVMFlag, this::getUintVMFlag,
641 this::getIntxVMFlag, this::getUintxVMFlag, this::getUint64VMFlag,
642 this::getSizeTVMFlag, this::getStringVMFlag, this::getDoubleVMFlag);
643
644 public Object getVMFlag(String name) {
645 return flagsGetters.stream()
646 .map(f -> f.apply(name))
647 .filter(x -> x != null)
648 .findAny()
649 .orElse(null);
650 }
651
652 // Jigsaw
653 public native void DefineModule(Object module, boolean is_open, String version,
654 String location, Object[] packages);
655 public native void AddModuleExports(Object from_module, String pkg, Object to_module);
656 public native void AddReadsModule(Object from_module, Object source_module);
657 public native void AddModuleExportsToAllUnnamed(Object module, String pkg);
658 public native void AddModuleExportsToAll(Object module, String pkg);
659
660 public native int getCDSOffsetForName0(String name);
661 public int getCDSOffsetForName(String name) throws Exception {
662 int offset = getCDSOffsetForName0(name);
663 if (offset == -1) {
664 throw new RuntimeException(name + " not found");
665 }
666 return offset;
667 }
668 public native int getCDSConstantForName0(String name);
669 public int getCDSConstantForName(String name) throws Exception {
670 int constant = getCDSConstantForName0(name);
671 if (constant == -1) {
672 throw new RuntimeException(name + " not found");
673 }
674 return constant;
675 }
676 public native Boolean getMethodBooleanOption(Executable method, String name);
677 public native Long getMethodIntxOption(Executable method, String name);
678 public native Long getMethodUintxOption(Executable method, String name);
679 public native Double getMethodDoubleOption(Executable method, String name);
680 public native String getMethodStringOption(Executable method, String name);
681 private final List<BiFunction<Executable,String,Object>> methodOptionGetters
682 = Arrays.asList(this::getMethodBooleanOption, this::getMethodIntxOption,
683 this::getMethodUintxOption, this::getMethodDoubleOption,
684 this::getMethodStringOption);
685
686 public Object getMethodOption(Executable method, String name) {
687 return methodOptionGetters.stream()
688 .map(f -> f.apply(method, name))
689 .filter(x -> x != null)
690 .findAny()
691 .orElse(null);
692 }
693
694 // Sharing & archiving
695 public native int getCDSGenericHeaderMinVersion();
696 public native int getCurrentCDSVersion();
697 public native String getDefaultArchivePath();
698 public native boolean cdsMemoryMappingFailed();
699 public native boolean isSharingEnabled();
700 public native boolean isSharedClass(Class<?> c);
701 public native boolean areSharedStringsMapped();
702 public native boolean isSharedInternedString(String s);
703 public native boolean isCDSIncluded();
704 public native boolean isJFRIncluded();
705 public native boolean isDTraceIncluded();
706 public native boolean canWriteJavaHeapArchive();
707 public native void linkClass(Class<?> c);
708 public native boolean areOpenArchiveHeapObjectsMapped();
709
710 // Compiler Directive
711 public native int addCompilerDirective(String compDirect);
712 public native void removeCompilerDirective(int count);
713
714 // Handshakes
715 public native int handshakeWalkStack(Thread t, boolean all_threads);
716 public native boolean handshakeReadMonitors(Thread t);
717 public native void asyncHandshakeWalkStack(Thread t);
718
719 public native void lockAndBlock(boolean suspender);
720
721 // Returns true on linux if library has the noexecstack flag set.
722 public native boolean checkLibSpecifiesNoexecstack(String libfilename);
723
724 // Container testing
725 public native boolean isContainerized();
726 public native int validateCgroup(String procCgroups,
727 String procSelfCgroup,
728 String procSelfMountinfo);
729 public native void printOsInfo();
730 public native long hostPhysicalMemory();
731 public native long hostPhysicalSwap();
732
733 // Decoder
734 public native void disableElfSectionCache();
735
736 // Resolved Method Table
737 public native long resolvedMethodItemsCount();
738
739 // Protection Domain Table
740 public native int protectionDomainRemovedCount();
741
742 public native int getKlassMetadataSize(Class<?> c);
743
744 // ThreadSMR GC safety check for threadObj
745 public native void checkThreadObjOfTerminatingThread(Thread target);
746
747 // libc name
748 public native String getLibcName();
749
750 // Walk stack frames of current thread
751 public native void verifyFrames(boolean log, boolean updateRegisterMap);
752
753 public native boolean isJVMTIIncluded();
754
755 public native void waitUnsafe(int time_ms);
756
757 public native void lockCritical();
758
759 public native void unlockCritical();
760
761 public native boolean setVirtualThreadsNotifyJvmtiMode(boolean enabled);
762
763 public native void preTouchMemory(long addr, long size);
764 }