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=");
  }
  public static void main (String[] args) {

    System.out.println(\u00CB);

    try {
        if (!Platform.shouldSAAttach()) {
            System.out.println("SA attach not expected to work - test skipped.");
            return;
        }
        int pid = ProcessTools.getProcessId();
        JDKToolLauncher jmap = JDKToolLauncher.create("jmap")
                                              .addToolArg("-F")
                                              .addToolArg("-dump:live,format=b,file=" + dumpFile)
                                              .addToolArg(Integer.toString(pid));
        ProcessBuilder pb = new ProcessBuilder(jmap.getCommand());
        OutputBuffer output = ProcessTools.getOutput(pb);
        Process p = pb.start();
        int e = p.waitFor();
        System.out.println("stdout:");
        System.out.println(output.getStdout());
        System.out.println("stderr:");
        System.out.println(output.getStderr());

        if (e != 0) {
            throw new RuntimeException("jmap returns: " + e);
        }
        if (! new File(dumpFile).exists()) {
            throw new RuntimeException("dump file NOT created: '" + dumpFile + "'");
        }
    } catch (Throwable t) {
        t.printStackTrace();
        throw new RuntimeException("Test failed with: " + t);
    }
  }
예제 #3
0
  private static void testGCId(String gcFlag, String logFlag) throws Exception {
    // GCID logging enabled
    ProcessBuilder pb_enabled =
        ProcessTools.createJavaProcessBuilder(
            "-XX:+" + gcFlag,
            "-XX:+" + logFlag,
            "-Xmx10M",
            "-XX:+PrintGCID",
            GCTest.class.getName());
    verifyContainsGCIDs(new OutputAnalyzer(pb_enabled.start()));

    // GCID logging disabled
    ProcessBuilder pb_disabled =
        ProcessTools.createJavaProcessBuilder(
            "-XX:+" + gcFlag,
            "-XX:+" + logFlag,
            "-Xmx10M",
            "-XX:-PrintGCID",
            GCTest.class.getName());
    verifyContainsNoGCIDs(new OutputAnalyzer(pb_disabled.start()));

    // GCID logging default
    ProcessBuilder pb_default =
        ProcessTools.createJavaProcessBuilder(
            "-XX:+" + gcFlag, "-XX:+" + logFlag, "-Xmx10M", GCTest.class.getName());
    verifyContainsNoGCIDs(new OutputAnalyzer(pb_default.start()));
  }
  public static void main(String args[]) throws Exception {

    ProcessBuilder pb =
        ProcessTools.createJavaProcessBuilder(
            "-showversion",
            "-XX:+UseParallelGC",
            "-XX:+UseAdaptiveGCBoundary",
            "-XX:+PrintCommandLineFlags",
            SystemGCCaller.class.getName());

    OutputAnalyzer output = new OutputAnalyzer(pb.start());

    output.shouldContain("+UseAdaptiveGCBoundary");

    output.shouldNotContain("error");

    output.shouldHaveExitValue(0);
  }