当前位置: 首页>>代码示例>>Java>>正文


Java WhiteBox类代码示例

本文整理汇总了Java中sun.hotspot.WhiteBox的典型用法代码示例。如果您正苦于以下问题:Java WhiteBox类的具体用法?Java WhiteBox怎么用?Java WhiteBox使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


WhiteBox类属于sun.hotspot包,在下文中一共展示了WhiteBox类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import sun.hotspot.WhiteBox; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
  if (args.length > 0) {
    WhiteBox.getWhiteBox().readReservedMemory();

    throw new Exception("Read of reserved/uncommitted memory unexpectedly succeeded, expected crash!");
  }

  ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
        "-Xbootclasspath/a:.",
        "-XX:+UnlockDiagnosticVMOptions",
        "-XX:+WhiteBoxAPI",
        "ReserveMemory",
        "test");

  OutputAnalyzer output = new OutputAnalyzer(pb.start());
  if (isWindows()) {
    output.shouldContain("EXCEPTION_ACCESS_VIOLATION");
  } else if (isOsx()) {
    output.shouldContain("SIGBUS");
  } else {
    output.shouldContain("SIGSEGV");
  }
}
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:24,代码来源:ReserveMemory.java

示例2: 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");
        }
    }
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:21,代码来源:SanityTest.java

示例3: 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());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:TestConcMarkCycleWB.java

示例4: 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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:TestCMSClassUnloadingEnabledHWM.java

示例5: 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");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:TestClassUnloadingDisabled.java

示例6: 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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:TestG1ClassUnloadingHWM.java

示例7: 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");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:Helpers.java

示例8: 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.");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:RunUnitTestsConcurrently.java

示例9: main

import sun.hotspot.WhiteBox; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
  if (args.length > 0) {
    WhiteBox.getWhiteBox().readReservedMemory();

    throw new Exception("Read of reserved/uncommitted memory unexpectedly succeeded, expected crash!");
  }

  ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
        "-Xbootclasspath/a:.",
        "-XX:+UnlockDiagnosticVMOptions",
        "-XX:+WhiteBoxAPI",
        "-XX:-TransmitErrorReport",
        "-XX:-CreateCoredumpOnCrash",
        "-Xmx32m",
        "ReserveMemory",
        "test");

  OutputAnalyzer output = new OutputAnalyzer(pb.start());
  if (Platform.isWindows()) {
    output.shouldContain("EXCEPTION_ACCESS_VIOLATION");
  } else if (Platform.isOSX()) {
    output.shouldContain("SIGBUS");
  } else {
    output.shouldContain("SIGSEGV");
  }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:ReserveMemory.java

示例10: main

import sun.hotspot.WhiteBox; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
    if (args.length > 0) {
        WhiteBox.getWhiteBox().assertMatchingSafepointCalls(false, false);
    }
    if (Platform.isDebugBuild()){
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
              "-Xbootclasspath/a:.",
              "-XX:+UnlockDiagnosticVMOptions",
              "-XX:+WhiteBoxAPI",
              "-XX:-TransmitErrorReport",
              "-XX:-CreateCoredumpOnCrash",
              "-Xmx32m",
              "AssertSafepointCheckConsistency2",
              "test");

        OutputAnalyzer output = new OutputAnalyzer(pb.start());
        output.shouldContain("assert").shouldContain("never");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:AssertSafepointCheckConsistency2.java

示例11: main

import sun.hotspot.WhiteBox; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
    if (args.length > 0) {
        WhiteBox.getWhiteBox().assertMatchingSafepointCalls(true, true);
    }
    if (Platform.isDebugBuild()){
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
              "-Xbootclasspath/a:.",
              "-XX:+UnlockDiagnosticVMOptions",
              "-XX:+WhiteBoxAPI",
              "-XX:-TransmitErrorReport",
              "-XX:-CreateCoredumpOnCrash",
              "-Xmx32m",
              "AssertSafepointCheckConsistency1",
              "test");
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
        output.shouldContain("assert").shouldContain("always");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:AssertSafepointCheckConsistency1.java

示例12: main

import sun.hotspot.WhiteBox; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
    if (args.length > 0) {
        WhiteBox.getWhiteBox().assertMatchingSafepointCalls(true, false);
    }
    if (Platform.isDebugBuild()){
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
           "-Xbootclasspath/a:.",
           "-XX:+UnlockDiagnosticVMOptions",
           "-XX:+WhiteBoxAPI",
           "-XX:-TransmitErrorReport",
           "-XX:-CreateCoredumpOnCrash",
           "-Xmx32m",
           "AssertSafepointCheckConsistency4",
           "test");

        OutputAnalyzer output = new OutputAnalyzer(pb.start());
        output.shouldNotContain("assert");
        output.shouldNotContain("never");
        output.shouldNotContain("always");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:AssertSafepointCheckConsistency4.java

示例13: main

import sun.hotspot.WhiteBox; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
    if (args.length > 0) {
        WhiteBox.getWhiteBox().assertMatchingSafepointCalls(false, true);
    }
    if (Platform.isDebugBuild()){
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
              "-Xbootclasspath/a:.",
              "-XX:+UnlockDiagnosticVMOptions",
              "-XX:+WhiteBoxAPI",
              "-XX:-TransmitErrorReport",
              "-XX:-CreateCoredumpOnCrash",
              "-Xmx32m",
              "AssertSafepointCheckConsistency3",
              "test");

        OutputAnalyzer output = new OutputAnalyzer(pb.start());
        output.shouldNotContain("assert");
        output.shouldNotContain("never");
        output.shouldNotContain("always");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:AssertSafepointCheckConsistency3.java

示例14: 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");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:SharedStringsWb.java

示例15: main

import sun.hotspot.WhiteBox; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
    WhiteBox wb = WhiteBox.getWhiteBox();
    long reserveSize = 256 * 1024;
    long addr;

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

    addr = wb.NMTReserveMemory(reserveSize);
    // Check for reserved
    pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "scale=KB"});
    output = new OutputAnalyzer(pb.start());
    output.shouldContain(" Test (reserved=256KB, committed=0KB)");

    wb.NMTReleaseMemory(addr, reserveSize);

    pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "scale=KB"});
    output = new OutputAnalyzer(pb.start());
    output.shouldNotContain("Test (reserved=");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:ReleaseNoCommit.java


注:本文中的sun.hotspot.WhiteBox类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。