本文整理汇总了Java中sun.hotspot.WhiteBox.getWhiteBox方法的典型用法代码示例。如果您正苦于以下问题:Java WhiteBox.getWhiteBox方法的具体用法?Java WhiteBox.getWhiteBox怎么用?Java WhiteBox.getWhiteBox使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.hotspot.WhiteBox
的用法示例。
在下文中一共展示了WhiteBox.getWhiteBox方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import sun.hotspot.WhiteBox; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
WhiteBox wb = WhiteBox.getWhiteBox();
if (wb.areSharedStringsIgnored()) {
System.out.println("Shared strings are ignored, assuming PASS");
return;
}
// The string below is known to be added to CDS archive
String s = "<init>";
String internedS = s.intern();
// Check that it's a valid string
if (s.getClass() != String.class || !(s instanceof String)) {
throw new RuntimeException("Shared string is not a valid String: FAIL");
}
if (wb.isShared(internedS)) {
System.out.println("Found shared string, result: PASS");
} else {
throw new RuntimeException("String is not shared, result: FAIL");
}
}
示例2: main
import sun.hotspot.WhiteBox; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
OutputAnalyzer output;
WhiteBox wb = WhiteBox.getWhiteBox();
// Grab my own PID
String pid = Long.toString(ProcessTools.getProcessId());
ProcessBuilder pb = new ProcessBuilder();
// Use WB API to alloc and free with the mtTest type
long memAlloc3 = wb.NMTMalloc(128 * 1024);
long memAlloc2 = wb.NMTMalloc(256 * 1024);
wb.NMTFree(memAlloc3);
long memAlloc1 = wb.NMTMalloc(512 * 1024);
wb.NMTFree(memAlloc2);
// Run 'jcmd <pid> VM.native_memory summary'
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"});
output = new OutputAnalyzer(pb.start());
output.shouldContain("Test (reserved=512KB, committed=512KB)");
// Free the memory allocated by NMTAllocTest
wb.NMTFree(memAlloc1);
output = new OutputAnalyzer(pb.start());
output.shouldNotContain("Test (reserved=");
}
示例3: main
import sun.hotspot.WhiteBox; //导入方法依赖的package包/类
public static void main(String... args) {
WhiteBox wb = WhiteBox.getWhiteBox();
StringBuilder sb = new StringBuilder();
sb.append("1234x"); sb.append("x56789");
String str = sb.toString();
if (wb.isInStringTable(str)) {
throw new RuntimeException("String " + str + " is already interned");
}
str.intern();
if (!wb.isInStringTable(str)) {
throw new RuntimeException("String " + str + " is not interned");
}
str = sb.toString();
wb.fullGC();
if (wb.isInStringTable(str)) {
throw new RuntimeException("String " + str + " is in StringTable even after GC");
}
}
示例4: main
import sun.hotspot.WhiteBox; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
WhiteBox wb = WhiteBox.getWhiteBox();
wb.youngGC();
assertTrue(wb.g1StartConcMarkCycle());
while (wb.g1InConcurrentMark()) {
Thread.sleep(5);
}
wb.fullGC();
assertTrue(wb.g1StartConcMarkCycle());
while (wb.g1InConcurrentMark()) {
Thread.sleep(5);
}
assertTrue(wb.g1StartConcMarkCycle());
}
示例5: main
import sun.hotspot.WhiteBox; //导入方法依赖的package包/类
public static void main(String [] args) throws Exception {
if (args.length != 1) {
throw new IllegalArgumentException("Usage: <MetaspaceSize>");
}
WhiteBox wb = WhiteBox.getWhiteBox();
// Allocate past the MetaspaceSize limit.
long metaspaceSize = Long.parseLong(args[0]);
long allocationBeyondMetaspaceSize = metaspaceSize * 2;
long metaspace = wb.allocateMetaspace(null, allocationBeyondMetaspaceSize);
// Wait for at least one GC to occur. The caller will parse the log files produced.
GarbageCollectorMXBean cmsGCBean = getCMSGCBean();
while (cmsGCBean.getCollectionCount() == 0) {
Thread.sleep(100);
}
wb.freeMetaspace(null, metaspace, metaspace);
}
示例6: main
import sun.hotspot.WhiteBox; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
final WhiteBox wb = WhiteBox.getWhiteBox();
// Fetch the dir where the test class and the class
// to be loaded resides.
String classDir = TestClassUnloadingDisabled.class.getProtectionDomain().getCodeSource().getLocation().getPath();
String className = "ClassToLoadUnload";
assertFalse(wb.isClassAlive(className), "Should not be loaded yet");
// The NoPDClassLoader handles loading classes in the test directory
// and loads them without a protection domain, which in some cases
// keeps the class live regardless of marking state.
NoPDClassLoader nopd = new NoPDClassLoader(classDir);
nopd.loadClass(className);
assertTrue(wb.isClassAlive(className), "Class should be loaded");
// Clear the class-loader, class and object references to make
// class unloading possible.
nopd = null;
System.gc();
assertTrue(wb.isClassAlive(className), "Class should not have ben unloaded");
}
示例7: main
import sun.hotspot.WhiteBox; //导入方法依赖的package包/类
public static void main(String [] args) throws Exception {
if (args.length != 2) {
throw new IllegalArgumentException("Usage: <MetaspaceSize> <YoungGenSize>");
}
WhiteBox wb = WhiteBox.getWhiteBox();
// Allocate past the MetaspaceSize limit
long metaspaceSize = Long.parseLong(args[0]);
long allocationBeyondMetaspaceSize = metaspaceSize * 2;
long metaspace = wb.allocateMetaspace(null, allocationBeyondMetaspaceSize);
long youngGenSize = Long.parseLong(args[1]);
triggerYoungGCs(youngGenSize);
wb.freeMetaspace(null, metaspace, metaspace);
}
示例8: detectByteArrayAllocationOverhead
import sun.hotspot.WhiteBox; //导入方法依赖的package包/类
/**
* Detects amount of extra bytes required to allocate a byte array.
* Allocating a byte[n] array takes more then just n bytes in the heap.
* Extra bytes are required to store object reference and the length.
* This amount depends on bitness and other factors.
*
* @return byte[] memory overhead
*/
public static int detectByteArrayAllocationOverhead() {
WhiteBox whiteBox = WhiteBox.getWhiteBox();
int zeroLengthByteArraySize = (int) whiteBox.getObjectSize(new byte[0]);
// Since we do not know is there any padding in zeroLengthByteArraySize we cannot just take byte[0] size as overhead
for (int i = 1; i < MAX_PADDING_SIZE + 1; ++i) {
int realAllocationSize = (int) whiteBox.getObjectSize(new byte[i]);
if (realAllocationSize != zeroLengthByteArraySize) {
// It means we did not have any padding on previous step
return zeroLengthByteArraySize - (i - 1);
}
}
throw new Error("We cannot find byte[] memory overhead - should not reach here");
}
示例9: main
import sun.hotspot.WhiteBox; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
if (!Platform.isDebugBuild() || !Platform.is64bit()) {
return;
}
wb = WhiteBox.getWhiteBox();
System.out.println("Starting threads");
int threads = Integer.valueOf(args[0]);
timeout = Long.valueOf(args[1]);
timeStamp = System.currentTimeMillis();
Thread[] threadsArray = new Thread[threads];
for (int i = 0; i < threads; i++) {
threadsArray[i] = new Thread(new Worker());
threadsArray[i].start();
}
for (int i = 0; i < threads; i++) {
threadsArray[i].join();
}
System.out.println("Quitting test.");
}
示例10: main
import sun.hotspot.WhiteBox; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
OutputAnalyzer output;
WhiteBox wb = WhiteBox.getWhiteBox();
// Grab my own PID
String pid = Integer.toString(ProcessTools.getProcessId());
ProcessBuilder pb = new ProcessBuilder();
// Use WB API to alloc and free with the mtTest type
long memAlloc3 = wb.NMTMalloc(128 * 1024);
long memAlloc2 = wb.NMTMalloc(256 * 1024);
wb.NMTFree(memAlloc3);
long memAlloc1 = wb.NMTMalloc(512 * 1024);
wb.NMTFree(memAlloc2);
// Run 'jcmd <pid> VM.native_memory summary'
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"});
output = new OutputAnalyzer(pb.start());
output.shouldContain("Test (reserved=512KB, committed=512KB)");
// Free the memory allocated by NMTAllocTest
wb.NMTFree(memAlloc1);
output = new OutputAnalyzer(pb.start());
output.shouldNotContain("Test (reserved=");
}
示例11: main
import sun.hotspot.WhiteBox; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
WhiteBox wb = WhiteBox.getWhiteBox();
int pageSize = wb.getVMPageSize();
if (pageSize < 0) {
throw new Exception("pageSize < 0");
} else {
System.out.println("Page size = " + pageSize);
}
}
示例12: ParserTest
import sun.hotspot.WhiteBox; //导入方法依赖的package包/类
public ParserTest() throws Exception {
wb = WhiteBox.getWhiteBox();
testNanoTime();
testJLong();
testBool();
testQuotes();
testMemorySize();
testSingleLetterArg();
}
示例13: SegmentedCodeCacheDtraceTestWorker
import sun.hotspot.WhiteBox; //导入方法依赖的package包/类
public SegmentedCodeCacheDtraceTestWorker(int compLevels[], boolean inlines[]) {
wb = WhiteBox.getWhiteBox();
this.compLevels = Arrays.copyOf(compLevels, compLevels.length);
for (int i = 0; i < compLevels.length; i++) {
if (inlines[i]) {
wb.testSetForceInlineMethod(TESTED_METHODS_LIST.get(i), true);
} else {
wb.testSetDontInlineMethod(TESTED_METHODS_LIST.get(i), true);
}
}
}
示例14: main
import sun.hotspot.WhiteBox; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException{
WhiteBox wb = WhiteBox.getWhiteBox();
LinkedList<Object> garbageAndRefList = new LinkedList<Object>();
// Creating a 1M large byte array. Since the test specifies the heap
// region size to be 1m this will be a humongous object. We then
// store a pointer to the array in the static object to keep it live
// during the whole test.
humongous_reference_holder = new LargeRef(new byte[1 * 1024 * 1024]);
// Create some garbage and a reference to the humongous object each round.
for (int i = 0; i < 32; i++) {
garbageAndRefList.add(new byte[400*1000]);
garbageAndRefList.add(new LargeRef(humongous_reference_holder.ref()));
// Promote to old, goal is to get rem-set entries for the humongous
// object from different regions. The test specifies MaxTenuringThreshold=0,
// this will make sure we get objects promoted to old at once.
wb.youngGC();
}
// Clear the garbage and reference list.
garbageAndRefList.clear();
// Run a concurrent mark cycle to mark all references but the static one as dead.
wb.g1StartConcMarkCycle();
while (wb.g1InConcurrentMark()) {
Thread.sleep(100);
}
// Run a young collection to make sure humongous object still can't be eagerly reclaimed.
wb.youngGC();
// Will crash/assert if humongous object has been reclaimed.
wb.fullGC();
}
示例15: main
import sun.hotspot.WhiteBox; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
WhiteBox wb = WhiteBox.getWhiteBox();
long heapAlignment = wb.getHeapAlignment();
// When using large pages, Linux does not support freeing parts of reserved and committed memory.
// And current Linux implementation uses page size as a condition to actually freeing memory.
// If we allocate pages less than NUMA node, NUMA will try to use default page size and
// this will free the memory which Linux does not support.
// Assume the minimum NUMA node as 2.
long initHeap = heapAlignment;
long maxHeap = heapAlignment * 2;
String[] vmArgs = {"-XX:+UseParallelGC",
"-Xms" + String.valueOf(initHeap),
"-Xmx" + String.valueOf(maxHeap),
"-XX:+UseNUMA",
"-XX:+UseHugeTLBFS",
"-XX:+PrintFlagsFinal",
"-version"};
ProcessBuilder pb_enabled = ProcessTools.createJavaProcessBuilder(vmArgs);
OutputAnalyzer analyzer = new OutputAnalyzer(pb_enabled.start());
if (largePageOrNumaEnabled(analyzer)) {
// We reach here, if both NUMA and HugeTLB are supported.
// However final flags will not be printed as NUMA initialization will be failed.
checkAnalyzerValues(analyzer, 1, MSG_EXIT_TOO_SMALL_HEAP);
}
}