Java Code Examples for sun.hotspot.WhiteBox#getWhiteBox()

The following examples show how to use sun.hotspot.WhiteBox#getWhiteBox() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CheckSharingWithDefaultArchive.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (!Platform.isDefaultCDSArchiveSupported()) {
        throw new RuntimeException("Supported platform");
    }

    WhiteBox wb = WhiteBox.getWhiteBox();
    String classes[] = {"java.lang.Object",
                        "java.lang.String",
                        "java.lang.Class"};
    // If maping fails, sharing is disabled
    if (wb.isSharingEnabled()) {
        for (int i = 0; i < classes.length; i++) {
            Class c = Class.forName(classes[i]);
            if (wb.isSharedClass(c)) {
                System.out.println(classes[i] + " is shared.");
            } else {
                throw new RuntimeException(classes[i] + " is not shared");
            }
        }
    } else {
       throw new RuntimeException("Sharing is not enabled.");
    }
}
 
Example 2
Source File: RunUnitTestsConcurrently.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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.");
}
 
Example 3
Source File: MallocTestType.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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=");
}
 
Example 4
Source File: TestCapacityUntilGCWrapAround.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    if (Platform.is32bit()) {
        WhiteBox wb = WhiteBox.getWhiteBox();

        long before = wb.metaspaceCapacityUntilGC();
        // Now force possible overflow of capacity_until_GC.
        long after = wb.incMetaspaceCapacityUntilGC(MAX_UINT);

        Asserts.assertGTE(after, before,
                          "Increasing with MAX_UINT should not cause wrap around: " + after + " < " + before);
        Asserts.assertLTE(after, MAX_UINT,
                          "Increasing with MAX_UINT should not cause value larger than MAX_UINT:" + after);
    }
}
 
Example 5
Source File: MallocSiteHashOverflow.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {

        // Size of entries based on malloc tracking header defined in mallocTracker.hpp
        // For 32-bit systems, create 257 malloc sites with the same hash bucket to overflow a hash bucket
        long entries = 257;

        OutputAnalyzer output;
        WhiteBox wb = WhiteBox.getWhiteBox();
        int MAX_HASH_SIZE = wb.NMTGetHashSize();

        // Grab my own PID
        String pid = Integer.toString(ProcessTools.getProcessId());
        ProcessBuilder pb = new ProcessBuilder();

        // Verify that current tracking level is "detail"
        pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "statistics"});
        output = new OutputAnalyzer(pb.start());
        output.shouldContain("Native Memory Tracking Statistics");

        // Attempt to cause NMT to downgrade tracking level by allocating small amounts
        // of memory with random pseudo call stack
        int pc = 1;
        for (int i = 0; i < entries; i++) {
            long addr = wb.NMTMallocWithPseudoStack(1, pc);
            if (addr == 0) {
                throw new RuntimeException("NMTMallocWithPseudoStack: out of memory");
            }
            // We free memory here since it doesn't affect pseudo malloc alloc site hash table entries
            wb.NMTFree(addr);
            pc += MAX_HASH_SIZE;
            if (i == entries) {
                // Verify that tracking has been downgraded
                pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "statistics"});
                output = new OutputAnalyzer(pb.start());
                output.shouldContain("Tracking level has been downgraded due to lack of resources");
            }
        }
    }
 
Example 6
Source File: MallocTestType.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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);

  // Use WB API to ensure that all data has been merged before we continue
  if (!wb.NMTWaitForDataMerge()) {
    throw new Exception("Call to WB API NMTWaitForDataMerge() failed");
  }

  // 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);

  // Use WB API to ensure that all data has been merged before we continue
  if (!wb.NMTWaitForDataMerge()) {
    throw new Exception("Call to WB API NMTWaitForDataMerge() failed");
  }
  output = new OutputAnalyzer(pb.start());
  output.shouldNotContain("Test (reserved=");
}
 
Example 7
Source File: TestHumongousCodeCacheRoots.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
    // do some work so that the compiler compiles this method, inlining the
    // reference to the integer array (which is a humonguous object) into
    // the code cache.
    for(int i = 0; i < n; i++) {
        AA[i] = 0;
        BB[i] = 0;
    }
    // trigger a GC that checks that the verification code allows humongous
    // objects with code cache roots; objects should be all live here.
    System.gc();

    // deoptimize everyhing: this should make all compiled code zombies.
    WhiteBox wb = WhiteBox.getWhiteBox();
    wb.deoptimizeAll();

    // trigger a GC that checks that the verification code allows humongous
    // objects with code cache roots; objects should be all live here.
    System.gc();

    // wait a little for the code cache sweeper to try to clean up zombie nmethods
    // and unregister the code roots.
    try { Thread.sleep(5000); } catch (InterruptedException ex) { }

    // do some work on the arrays to make sure that they need to be live after the GCs
    for(int i = 0; i < n; i++) {
        AA[i] = 1;
        BB[i] = 10;
    }

    System.out.println();
}
 
Example 8
Source File: TestHumongousCodeCacheRoots.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
    // do some work so that the compiler compiles this method, inlining the
    // reference to the integer array (which is a humonguous object) into
    // the code cache.
    for(int i = 0; i < n; i++) {
        AA[i] = 0;
        BB[i] = 0;
    }
    // trigger a GC that checks that the verification code allows humongous
    // objects with code cache roots; objects should be all live here.
    System.gc();

    // deoptimize everyhing: this should make all compiled code zombies.
    WhiteBox wb = WhiteBox.getWhiteBox();
    wb.deoptimizeAll();

    // trigger a GC that checks that the verification code allows humongous
    // objects with code cache roots; objects should be all live here.
    System.gc();

    // wait a little for the code cache sweeper to try to clean up zombie nmethods
    // and unregister the code roots.
    try { Thread.sleep(5000); } catch (InterruptedException ex) { }

    // do some work on the arrays to make sure that they need to be live after the GCs
    for(int i = 0; i < n; i++) {
        AA[i] = 1;
        BB[i] = 10;
    }

    System.out.println();
}
 
Example 9
Source File: ReadVMPageSize.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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);
  }
}
 
Example 10
Source File: TestHumongousCodeCacheRoots.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
    // do some work so that the compiler compiles this method, inlining the
    // reference to the integer array (which is a humonguous object) into
    // the code cache.
    for(int i = 0; i < n; i++) {
        AA[i] = 0;
        BB[i] = 0;
    }
    // trigger a GC that checks that the verification code allows humongous
    // objects with code cache roots; objects should be all live here.
    System.gc();

    // deoptimize everyhing: this should make all compiled code zombies.
    WhiteBox wb = WhiteBox.getWhiteBox();
    wb.deoptimizeAll();

    // trigger a GC that checks that the verification code allows humongous
    // objects with code cache roots; objects should be all live here.
    System.gc();

    // wait a little for the code cache sweeper to try to clean up zombie nmethods
    // and unregister the code roots.
    try { Thread.sleep(5000); } catch (InterruptedException ex) { }

    // do some work on the arrays to make sure that they need to be live after the GCs
    for(int i = 0; i < n; i++) {
        AA[i] = 1;
        BB[i] = 10;
    }

    System.out.println();
}
 
Example 11
Source File: TestGCHeapConfigurationEventWith32BitOops.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void verify() throws Exception {
    WhiteBox wb = WhiteBox.getWhiteBox();
    long heapAlignment = wb.getHeapAlignment();
    long alignedHeapSize = GCHelper.alignUp(megabytes(100), heapAlignment);
    verifyMinHeapSizeIs(megabytes(100));
    verifyInitialHeapSizeIs(alignedHeapSize);
    verifyMaxHeapSizeIs(alignedHeapSize);
    verifyUsesCompressedOopsIs(true);
    verifyObjectAlignmentInBytesIs(8);
    verifyHeapAddressBitsIs(32);
    verifyCompressedOopModeIs("32-bit");
}
 
Example 12
Source File: ParserTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public ParserTest() throws Exception {
    wb = WhiteBox.getWhiteBox();

    testNanoTime();
    testJLong();
    testBool();
    testQuotes();
    testMemorySize();
}
 
Example 13
Source File: TestCapacityUntilGCWrapAround.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    if (Platform.is32bit()) {
        WhiteBox wb = WhiteBox.getWhiteBox();

        long before = wb.metaspaceCapacityUntilGC();
        // Now force possible overflow of capacity_until_GC.
        long after = wb.incMetaspaceCapacityUntilGC(MAX_UINT);

        Asserts.assertGTE(after, before,
                          "Increasing with MAX_UINT should not cause wrap around: " + after + " < " + before);
        Asserts.assertLTE(after, MAX_UINT,
                          "Increasing with MAX_UINT should not cause value larger than MAX_UINT:" + after);
    }
}
 
Example 14
Source File: UnloadTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void run() throws Exception {
    final WhiteBox wb = WhiteBox.getWhiteBox();

    ClassUnloadCommon.failIf(wb.isClassAlive(className), "is not expected to be alive yet");

    ClassLoader cl = ClassUnloadCommon.newClassLoader();
    Class<?> c = cl.loadClass(className);
    Object o = c.newInstance();

    ClassUnloadCommon.failIf(!wb.isClassAlive(className), "should be live here");

    cl = null; c = null; o = null;
    ClassUnloadCommon.triggerUnloading();
    ClassUnloadCommon.failIf(wb.isClassAlive(className), "should have been unloaded");
}
 
Example 15
Source File: MallocSiteTypeChange.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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();

      int pc = 1;
      long addr = wb.NMTMallocWithPseudoStack(4 * 1024, pc);

      // Verify that current tracking level is "detail"
      pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"});
      output = new OutputAnalyzer(pb.start());
      output.shouldContain("Test (reserved=4KB, committed=4KB)");

      pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "baseline"});
      output = new OutputAnalyzer(pb.start());
      output.shouldContain("Baseline succeeded");

      wb.NMTFree(addr);
      addr = wb.NMTMallocWithPseudoStackAndType(2 * 1024, pc, 7 /* mtInternal */ );
      pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "detail.diff"});
      output = new OutputAnalyzer(pb.start());
      output.shouldContain("(malloc=0KB type=Test -4KB)");
      output.shouldContain("(malloc=2KB type=Internal +2KB #1 +1)");
      output.shouldHaveExitValue(0);
}
 
Example 16
Source File: TestCapacityUntilGCWrapAround.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    if (Platform.is32bit()) {
        WhiteBox wb = WhiteBox.getWhiteBox();

        long before = wb.metaspaceCapacityUntilGC();
        // Now force possible overflow of capacity_until_GC.
        long after = wb.incMetaspaceCapacityUntilGC(MAX_UINT);

        Asserts.assertGTE(after, before,
                          "Increasing with MAX_UINT should not cause wrap around: " + after + " < " + before);
        Asserts.assertLTE(after, MAX_UINT,
                          "Increasing with MAX_UINT should not cause value larger than MAX_UINT:" + after);
    }
}
 
Example 17
Source File: ParserTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public ParserTest() throws Exception {
    wb = WhiteBox.getWhiteBox();

    testNanoTime();
    testJLong();
    testBool();
    testQuotes();
    testMemorySize();
}
 
Example 18
Source File: TestLargePageUseForAuxMemory.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (!Platform.isDebugBuild()) {
        System.out.println("Skip tests on non-debug builds because the required option TracePageSizes is a debug-only option.");
        return;
    }

    WhiteBox wb = WhiteBox.getWhiteBox();
    smallPageSize = wb.getVMPageSize();
    largePageSize = wb.getVMLargePageSize();

    if (largePageSize == 0) {
        System.out.println("Skip tests because large page support does not seem to be available on this platform.");
        return;
    }

    // To get large pages for the card table etc. we need at least a 1G heap (with 4k page size).
    // 32 bit systems will have problems reserving such an amount of contiguous space, so skip the
    // test there.
    if (!Platform.is32bit()) {
        // Size that a single card covers.
        final int cardSize = 512;

        final long heapSizeForCardTableUsingLargePages = largePageSize * cardSize;

        testVM(heapSizeForCardTableUsingLargePages, true, true);
        testVM(heapSizeForCardTableUsingLargePages + HEAP_REGION_SIZE, true, true);
        testVM(heapSizeForCardTableUsingLargePages - HEAP_REGION_SIZE, false, true);
    }

    // Minimum heap requirement to get large pages for bitmaps is 128M heap. This seems okay to test
    // everywhere.
    final int bitmapTranslationFactor = 8 * 8; // ObjectAlignmentInBytes * BitsPerByte
    final long heapSizeForBitmapUsingLargePages = largePageSize * bitmapTranslationFactor;

    testVM(heapSizeForBitmapUsingLargePages, false, true);
    testVM(heapSizeForBitmapUsingLargePages + HEAP_REGION_SIZE, false, true);
    testVM(heapSizeForBitmapUsingLargePages - HEAP_REGION_SIZE, false, false);
}
 
Example 19
Source File: TestUseCompressedOopsErgoTools.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
  WhiteBox wb = WhiteBox.getWhiteBox();
  System.out.print(wb.getCompressedOopsMaxHeapSize());
}
 
Example 20
Source File: TestUseCompressedOopsErgoTools.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
  WhiteBox wb = WhiteBox.getWhiteBox();
  System.out.print(wb.getCompressedOopsMaxHeapSize());
}