com.oracle.java.testlibrary.JDKToolLauncher Java Examples

The following examples show how to use com.oracle.java.testlibrary.JDKToolLauncher. 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: Test8028623.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
  }
 
Example #2
Source File: Test8028623.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
  }
 
Example #3
Source File: Test8028623.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
  }
 
Example #4
Source File: Test8028623.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
  }
 
Example #5
Source File: Test8028623.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
  }
 
Example #6
Source File: JMapHProfLargeHeapTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static void testHProfFileFormat(String vmArgs, long heapSize,
        String expectedFormat) throws Exception, IOException,
        InterruptedException, FileNotFoundException {
    ProcessBuilder procBuilder = ProcessTools.createJavaProcessBuilder(
            vmArgs, "JMapHProfLargeHeapProc", String.valueOf(heapSize));
    procBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
    Process largeHeapProc = procBuilder.start();

    try (Scanner largeHeapScanner = new Scanner(
            largeHeapProc.getInputStream());) {
        String pidstring = null;
        while ((pidstring = largeHeapScanner.findInLine("PID\\[[0-9].*\\]")) == null) {
            Thread.sleep(500);
        }
        int pid = Integer.parseInt(pidstring.substring(4,
                pidstring.length() - 1));
        System.out.println("Extracted pid: " + pid);

        JDKToolLauncher jMapLauncher = JDKToolLauncher
                .createUsingTestJDK("jmap");
        jMapLauncher.addToolArg("-dump:format=b,file=" + pid + "-"
                + HEAP_DUMP_FILE_NAME);
        jMapLauncher.addToolArg(String.valueOf(pid));

        ProcessBuilder jMapProcessBuilder = new ProcessBuilder(
                jMapLauncher.getCommand());
        System.out.println("jmap command: "
                + Arrays.toString(jMapLauncher.getCommand()));

        Process jMapProcess = jMapProcessBuilder.start();
        OutputAnalyzer analyzer = new OutputAnalyzer(jMapProcess);
        analyzer.shouldHaveExitValue(0);
        analyzer.shouldContain(pid + "-" + HEAP_DUMP_FILE_NAME);
        analyzer.shouldContain("Heap dump file created");

        largeHeapProc.getOutputStream().write('\n');

        File dumpFile = new File(pid + "-" + HEAP_DUMP_FILE_NAME);
        Asserts.assertTrue(dumpFile.exists(), "Heap dump file not found.");

        try (Reader reader = new BufferedReader(new FileReader(dumpFile))) {
            CharBuffer buf = CharBuffer.allocate(expectedFormat.length());
            reader.read(buf);
            buf.clear();
            Asserts.assertEQ(buf.toString(), expectedFormat,
                    "Wrong file format. Expected '" + expectedFormat
                            + "', but found '" + buf.toString() + "'");
        }

        System.out.println("Success!");

    } finally {
        largeHeapProc.destroyForcibly();
    }
}
 
Example #7
Source File: JMapHProfLargeHeapTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private static void testHProfFileFormat(String vmArgs, long heapSize,
        String expectedFormat) throws Exception, IOException,
        InterruptedException, FileNotFoundException {
    ProcessBuilder procBuilder = ProcessTools.createJavaProcessBuilder(
            vmArgs, "JMapHProfLargeHeapProc", String.valueOf(heapSize));
    procBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
    Process largeHeapProc = procBuilder.start();

    try (Scanner largeHeapScanner = new Scanner(
            largeHeapProc.getInputStream());) {
        String pidstring = null;
        while ((pidstring = largeHeapScanner.findInLine("PID\\[[0-9].*\\]")) == null) {
            Thread.sleep(500);
        }
        int pid = Integer.parseInt(pidstring.substring(4,
                pidstring.length() - 1));
        System.out.println("Extracted pid: " + pid);

        JDKToolLauncher jMapLauncher = JDKToolLauncher
                .createUsingTestJDK("jmap");
        jMapLauncher.addToolArg("-dump:format=b,file=" + pid + "-"
                + HEAP_DUMP_FILE_NAME);
        jMapLauncher.addToolArg(String.valueOf(pid));

        ProcessBuilder jMapProcessBuilder = new ProcessBuilder(
                jMapLauncher.getCommand());
        System.out.println("jmap command: "
                + Arrays.toString(jMapLauncher.getCommand()));

        Process jMapProcess = jMapProcessBuilder.start();
        OutputAnalyzer analyzer = new OutputAnalyzer(jMapProcess);
        analyzer.shouldHaveExitValue(0);
        analyzer.shouldContain(pid + "-" + HEAP_DUMP_FILE_NAME);
        analyzer.shouldContain("Heap dump file created");

        largeHeapProc.getOutputStream().write('\n');

        File dumpFile = new File(pid + "-" + HEAP_DUMP_FILE_NAME);
        Asserts.assertTrue(dumpFile.exists(), "Heap dump file not found.");

        try (Reader reader = new BufferedReader(new FileReader(dumpFile))) {
            CharBuffer buf = CharBuffer.allocate(expectedFormat.length());
            reader.read(buf);
            buf.clear();
            Asserts.assertEQ(buf.toString(), expectedFormat,
                    "Wrong file format. Expected '" + expectedFormat
                            + "', but found '" + buf.toString() + "'");
        }

        System.out.println("Success!");

    } finally {
        largeHeapProc.destroyForcibly();
    }
}
 
Example #8
Source File: JMapHProfLargeHeapTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static void testHProfFileFormat(String vmArgs, long heapSize,
        String expectedFormat) throws Exception, IOException,
        InterruptedException, FileNotFoundException {
    ProcessBuilder procBuilder = ProcessTools.createJavaProcessBuilder(
            vmArgs, "JMapHProfLargeHeapProc", String.valueOf(heapSize));
    procBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
    Process largeHeapProc = procBuilder.start();

    try (Scanner largeHeapScanner = new Scanner(
            largeHeapProc.getInputStream());) {
        String pidstring = null;
        while ((pidstring = largeHeapScanner.findInLine("PID\\[[0-9].*\\]")) == null) {
            Thread.sleep(500);
        }
        int pid = Integer.parseInt(pidstring.substring(4,
                pidstring.length() - 1));
        System.out.println("Extracted pid: " + pid);

        JDKToolLauncher jMapLauncher = JDKToolLauncher
                .createUsingTestJDK("jmap");
        jMapLauncher.addToolArg("-dump:format=b,file=" + pid + "-"
                + HEAP_DUMP_FILE_NAME);
        jMapLauncher.addToolArg(String.valueOf(pid));

        ProcessBuilder jMapProcessBuilder = new ProcessBuilder(
                jMapLauncher.getCommand());
        System.out.println("jmap command: "
                + Arrays.toString(jMapLauncher.getCommand()));

        Process jMapProcess = jMapProcessBuilder.start();
        OutputAnalyzer analyzer = new OutputAnalyzer(jMapProcess);
        analyzer.shouldHaveExitValue(0);
        analyzer.shouldContain(pid + "-" + HEAP_DUMP_FILE_NAME);
        analyzer.shouldContain("Heap dump file created");

        largeHeapProc.getOutputStream().write('\n');

        File dumpFile = new File(pid + "-" + HEAP_DUMP_FILE_NAME);
        Asserts.assertTrue(dumpFile.exists(), "Heap dump file not found.");

        try (Reader reader = new BufferedReader(new FileReader(dumpFile))) {
            CharBuffer buf = CharBuffer.allocate(expectedFormat.length());
            reader.read(buf);
            buf.clear();
            Asserts.assertEQ(buf.toString(), expectedFormat,
                    "Wrong file format. Expected '" + expectedFormat
                            + "', but found '" + buf.toString() + "'");
        }

        System.out.println("Success!");

    } finally {
        largeHeapProc.destroyForcibly();
    }
}
 
Example #9
Source File: JMapHProfLargeHeapTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private static void testHProfFileFormat(String vmArgs, long heapSize,
        String expectedFormat) throws Exception, IOException,
        InterruptedException, FileNotFoundException {
    ProcessBuilder procBuilder = ProcessTools.createJavaProcessBuilder(
            vmArgs, "JMapHProfLargeHeapProc", String.valueOf(heapSize));
    procBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
    Process largeHeapProc = procBuilder.start();

    try (Scanner largeHeapScanner = new Scanner(
            largeHeapProc.getInputStream());) {
        String pidstring = null;
        while ((pidstring = largeHeapScanner.findInLine("PID\\[[0-9].*\\]")) == null) {
            Thread.sleep(500);
        }
        int pid = Integer.parseInt(pidstring.substring(4,
                pidstring.length() - 1));
        System.out.println("Extracted pid: " + pid);

        JDKToolLauncher jMapLauncher = JDKToolLauncher
                .createUsingTestJDK("jmap");
        jMapLauncher.addToolArg("-dump:format=b,file=" + pid + "-"
                + HEAP_DUMP_FILE_NAME);
        jMapLauncher.addToolArg(String.valueOf(pid));

        ProcessBuilder jMapProcessBuilder = new ProcessBuilder(
                jMapLauncher.getCommand());
        System.out.println("jmap command: "
                + Arrays.toString(jMapLauncher.getCommand()));

        Process jMapProcess = jMapProcessBuilder.start();
        OutputAnalyzer analyzer = new OutputAnalyzer(jMapProcess);
        analyzer.shouldHaveExitValue(0);
        analyzer.shouldContain(pid + "-" + HEAP_DUMP_FILE_NAME);
        analyzer.shouldContain("Heap dump file created");

        largeHeapProc.getOutputStream().write('\n');

        File dumpFile = new File(pid + "-" + HEAP_DUMP_FILE_NAME);
        Asserts.assertTrue(dumpFile.exists(), "Heap dump file not found.");

        try (Reader reader = new BufferedReader(new FileReader(dumpFile))) {
            CharBuffer buf = CharBuffer.allocate(expectedFormat.length());
            reader.read(buf);
            buf.clear();
            Asserts.assertEQ(buf.toString(), expectedFormat,
                    "Wrong file format. Expected '" + expectedFormat
                            + "', but found '" + buf.toString() + "'");
        }

        System.out.println("Success!");

    } finally {
        largeHeapProc.destroyForcibly();
    }
}
 
Example #10
Source File: JMapHProfLargeHeapTest.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private static void testHProfFileFormat(String vmArgs, long heapSize,
        String expectedFormat) throws Exception, IOException,
        InterruptedException, FileNotFoundException {
    ProcessBuilder procBuilder = ProcessTools.createJavaProcessBuilder(
            vmArgs, "JMapHProfLargeHeapProc", String.valueOf(heapSize));
    procBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
    Process largeHeapProc = procBuilder.start();

    try (Scanner largeHeapScanner = new Scanner(
            largeHeapProc.getInputStream());) {
        String pidstring = null;
        while ((pidstring = largeHeapScanner.findInLine("PID\\[[0-9].*\\]")) == null) {
            Thread.sleep(500);
        }
        int pid = Integer.parseInt(pidstring.substring(4,
                pidstring.length() - 1));
        System.out.println("Extracted pid: " + pid);

        JDKToolLauncher jMapLauncher = JDKToolLauncher
                .createUsingTestJDK("jmap");
        jMapLauncher.addToolArg("-dump:format=b,file=" + pid + "-"
                + HEAP_DUMP_FILE_NAME);
        jMapLauncher.addToolArg(String.valueOf(pid));

        ProcessBuilder jMapProcessBuilder = new ProcessBuilder(
                jMapLauncher.getCommand());
        System.out.println("jmap command: "
                + Arrays.toString(jMapLauncher.getCommand()));

        Process jMapProcess = jMapProcessBuilder.start();
        OutputAnalyzer analyzer = new OutputAnalyzer(jMapProcess);
        analyzer.shouldHaveExitValue(0);
        analyzer.shouldContain(pid + "-" + HEAP_DUMP_FILE_NAME);
        analyzer.shouldContain("Heap dump file created");

        largeHeapProc.getOutputStream().write('\n');

        File dumpFile = new File(pid + "-" + HEAP_DUMP_FILE_NAME);
        Asserts.assertTrue(dumpFile.exists(), "Heap dump file not found.");

        try (Reader reader = new BufferedReader(new FileReader(dumpFile))) {
            CharBuffer buf = CharBuffer.allocate(expectedFormat.length());
            reader.read(buf);
            buf.clear();
            Asserts.assertEQ(buf.toString(), expectedFormat,
                    "Wrong file format. Expected '" + expectedFormat
                            + "', but found '" + buf.toString() + "'");
        }

        System.out.println("Success!");

    } finally {
        largeHeapProc.destroyForcibly();
    }
}
 
Example #11
Source File: JMapHProfLargeHeapTest.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private static void testHProfFileFormat(String vmArgs, long heapSize,
        String expectedFormat) throws Exception, IOException,
        InterruptedException, FileNotFoundException {
    ProcessBuilder procBuilder = ProcessTools.createJavaProcessBuilder(
            vmArgs, "JMapHProfLargeHeapProc", String.valueOf(heapSize));
    procBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
    Process largeHeapProc = procBuilder.start();

    try (Scanner largeHeapScanner = new Scanner(
            largeHeapProc.getInputStream());) {
        String pidstring = null;
        while ((pidstring = largeHeapScanner.findInLine("PID\\[[0-9].*\\]")) == null) {
            Thread.sleep(500);
        }
        int pid = Integer.parseInt(pidstring.substring(4,
                pidstring.length() - 1));
        System.out.println("Extracted pid: " + pid);

        JDKToolLauncher jMapLauncher = JDKToolLauncher
                .createUsingTestJDK("jmap");
        jMapLauncher.addToolArg("-dump:format=b,file=" + pid + "-"
                + HEAP_DUMP_FILE_NAME);
        jMapLauncher.addToolArg(String.valueOf(pid));

        ProcessBuilder jMapProcessBuilder = new ProcessBuilder(
                jMapLauncher.getCommand());
        System.out.println("jmap command: "
                + Arrays.toString(jMapLauncher.getCommand()));

        Process jMapProcess = jMapProcessBuilder.start();
        OutputAnalyzer analyzer = new OutputAnalyzer(jMapProcess);
        analyzer.shouldHaveExitValue(0);
        analyzer.shouldContain(pid + "-" + HEAP_DUMP_FILE_NAME);
        analyzer.shouldContain("Heap dump file created");

        largeHeapProc.getOutputStream().write('\n');

        File dumpFile = new File(pid + "-" + HEAP_DUMP_FILE_NAME);
        Asserts.assertTrue(dumpFile.exists(), "Heap dump file not found.");

        try (Reader reader = new BufferedReader(new FileReader(dumpFile))) {
            CharBuffer buf = CharBuffer.allocate(expectedFormat.length());
            reader.read(buf);
            buf.clear();
            Asserts.assertEQ(buf.toString(), expectedFormat,
                    "Wrong file format. Expected '" + expectedFormat
                            + "', but found '" + buf.toString() + "'");
        }

        System.out.println("Success!");

    } finally {
        largeHeapProc.destroyForcibly();
    }
}
 
Example #12
Source File: JMapHProfLargeHeapTest.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private static void testHProfFileFormat(String vmArgs, long heapSize,
        String expectedFormat) throws Exception, IOException,
        InterruptedException, FileNotFoundException {
    ProcessBuilder procBuilder = ProcessTools.createJavaProcessBuilder(
            vmArgs, "JMapHProfLargeHeapProc", String.valueOf(heapSize));
    procBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
    Process largeHeapProc = procBuilder.start();

    try (Scanner largeHeapScanner = new Scanner(
            largeHeapProc.getInputStream());) {
        String pidstring = null;
        while ((pidstring = largeHeapScanner.findInLine("PID\\[[0-9].*\\]")) == null) {
            Thread.sleep(500);
        }
        int pid = Integer.parseInt(pidstring.substring(4,
                pidstring.length() - 1));
        System.out.println("Extracted pid: " + pid);

        JDKToolLauncher jMapLauncher = JDKToolLauncher
                .createUsingTestJDK("jmap");
        jMapLauncher.addToolArg("-dump:format=b,file=" + pid + "-"
                + HEAP_DUMP_FILE_NAME);
        jMapLauncher.addToolArg(String.valueOf(pid));

        ProcessBuilder jMapProcessBuilder = new ProcessBuilder(
                jMapLauncher.getCommand());
        System.out.println("jmap command: "
                + Arrays.toString(jMapLauncher.getCommand()));

        Process jMapProcess = jMapProcessBuilder.start();
        OutputAnalyzer analyzer = new OutputAnalyzer(jMapProcess);
        analyzer.shouldHaveExitValue(0);
        analyzer.shouldContain(pid + "-" + HEAP_DUMP_FILE_NAME);
        analyzer.shouldContain("Heap dump file created");

        largeHeapProc.getOutputStream().write('\n');

        File dumpFile = new File(pid + "-" + HEAP_DUMP_FILE_NAME);
        Asserts.assertTrue(dumpFile.exists(), "Heap dump file not found.");

        try (Reader reader = new BufferedReader(new FileReader(dumpFile))) {
            CharBuffer buf = CharBuffer.allocate(expectedFormat.length());
            reader.read(buf);
            buf.clear();
            Asserts.assertEQ(buf.toString(), expectedFormat,
                    "Wrong file format. Expected '" + expectedFormat
                            + "', but found '" + buf.toString() + "'");
        }

        System.out.println("Success!");

    } finally {
        largeHeapProc.destroyForcibly();
    }
}