test/jdk/sun/tools/jhsdb/JShellHeapDumpTest.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58448 f45278353668
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55647
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
     1
/*
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
     4
 *
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
     8
 *
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    13
 * accompanied this code).
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    14
 *
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    18
 *
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    21
 * questions.
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    22
 */
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    23
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    24
/**
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    25
 * @test
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    26
 * @bug 8225715
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    27
 * @requires vm.hasSAandCanAttach
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    28
 * @library /test/lib
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    29
 * @compile JShellHeapDumpTest.java
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    30
 * @run main/timeout=240 JShellHeapDumpTest
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    31
 */
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    32
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    33
import static jdk.test.lib.Asserts.assertTrue;
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    34
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    35
import java.io.IOException;
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    36
import java.io.File;
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    37
import java.util.List;
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    38
import java.util.Arrays;
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    39
import java.util.Map;
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    40
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    41
import jdk.test.lib.JDKToolLauncher;
58364
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
    42
import jdk.test.lib.JDKToolFinder;
55647
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    43
import jdk.test.lib.process.OutputAnalyzer;
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    44
import jdk.test.lib.process.ProcessTools;
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    45
import jdk.test.lib.hprof.parser.HprofReader;
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    46
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    47
import jdk.jshell.JShell;
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    48
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    49
public class JShellHeapDumpTest {
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    50
58448
f45278353668 8231288: "jhsdb jmap" test needed to reproduce issues that used to be reproduced by JShellHeapDumpTest
cjplummer
parents: 58389
diff changeset
    51
    static Process jShellProcess;
f45278353668 8231288: "jhsdb jmap" test needed to reproduce issues that used to be reproduced by JShellHeapDumpTest
cjplummer
parents: 58389
diff changeset
    52
    static boolean doSleep = true; // By default do a short sleep when app starts up
55647
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    53
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    54
    public static void launch(String expectedMessage, List<String> toolArgs)
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    55
        throws IOException {
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    56
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    57
        try {
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    58
            launchJshell();
58364
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
    59
            long jShellPID = jShellProcess.pid();
55647
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    60
58364
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
    61
            System.out.println("Starting " + toolArgs.get(0) + " against " + jShellPID);
55647
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    62
            JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    63
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    64
            for (String cmd : toolArgs) {
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    65
                launcher.addToolArg(cmd);
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    66
            }
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    67
58364
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
    68
            launcher.addToolArg("--pid=" + Long.toString(jShellPID));
55647
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    69
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    70
            ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand());
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    71
            OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
58364
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
    72
            System.out.println("jhsdb jmap stdout:");
55647
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    73
            System.out.println(output.getStdout());
58364
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
    74
            System.out.println("jhsdb jmap stderr:");
55647
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    75
            System.out.println(output.getStderr());
58364
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
    76
            System.out.println("###### End of all output:");
55647
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    77
            output.shouldHaveExitValue(0);
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    78
        } catch (Exception ex) {
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    79
            throw new RuntimeException("Test ERROR " + ex, ex);
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    80
        } finally {
58364
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
    81
            if (jShellProcess.isAlive()) {
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
    82
                System.out.println("Destroying jshell");
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
    83
                jShellProcess.destroy();
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
    84
                System.out.println("Jshell destroyed");
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
    85
            } else {
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
    86
                System.out.println("Jshell not alive");
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
    87
            }
55647
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    88
        }
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    89
    }
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    90
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    91
    public static void launch(String expectedMessage, String... toolArgs)
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    92
        throws IOException {
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    93
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    94
        launch(expectedMessage, Arrays.asList(toolArgs));
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    95
    }
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    96
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    97
    public static void printStackTraces(String file) throws IOException {
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    98
        try {
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
    99
            String output = HprofReader.getStack(file, 0);
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   100
            if (!output.contains("JShellToolProvider")) {
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   101
                throw new RuntimeException("'JShellToolProvider' missing from stdout/stderr");
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   102
            }
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   103
        } catch (Exception ex) {
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   104
            throw new RuntimeException("Test ERROR " + ex, ex);
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   105
        }
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   106
    }
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   107
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   108
    public static void testHeapDump() throws IOException {
58364
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
   109
        File hprofFile = new File("jhsdb.jmap.heap." +
55647
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   110
                             System.currentTimeMillis() + ".hprof");
58364
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
   111
        if (hprofFile.exists()) {
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
   112
            hprofFile.delete();
55647
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   113
        }
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   114
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   115
        launch("heap written to", "jmap",
58364
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
   116
               "--binaryheap", "--dumpfile=" + hprofFile.getAbsolutePath());
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
   117
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
   118
        assertTrue(hprofFile.exists() && hprofFile.isFile(),
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
   119
                   "Could not create dump file " + hprofFile.getAbsolutePath());
55647
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   120
58364
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
   121
        printStackTraces(hprofFile.getAbsolutePath());
55647
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   122
58364
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
   123
        System.out.println("hprof file size: " + hprofFile.length());
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
   124
        hprofFile.delete();
55647
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   125
    }
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   126
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   127
    public static void launchJshell() throws IOException {
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   128
        System.out.println("Starting Jshell");
58364
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
   129
        long startTime = System.currentTimeMillis();
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
   130
        try {
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
   131
            ProcessBuilder pb = new ProcessBuilder(JDKToolFinder.getTestJDKTool("jshell"));
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
   132
            jShellProcess = ProcessTools.startProcess("JShell", pb,
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
   133
                                                      s -> {  // warm-up predicate
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
   134
                                                          return s.contains("Welcome to JShell");
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
   135
                                                      });
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
   136
        } catch (Exception ex) {
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
   137
            throw new RuntimeException("Test ERROR " + ex, ex);
55647
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   138
        }
58364
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
   139
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
   140
        long elapsedTime = System.currentTimeMillis() - startTime;
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
   141
        System.out.println("Jshell Started in " + elapsedTime + "ms");
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
   142
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
   143
        // Give jshell a chance to fully start up. This makes SA more stable for the jmap dump.
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
   144
        try {
58448
f45278353668 8231288: "jhsdb jmap" test needed to reproduce issues that used to be reproduced by JShellHeapDumpTest
cjplummer
parents: 58389
diff changeset
   145
            if (doSleep) {
f45278353668 8231288: "jhsdb jmap" test needed to reproduce issues that used to be reproduced by JShellHeapDumpTest
cjplummer
parents: 58389
diff changeset
   146
                Thread.sleep(2000);
f45278353668 8231288: "jhsdb jmap" test needed to reproduce issues that used to be reproduced by JShellHeapDumpTest
cjplummer
parents: 58389
diff changeset
   147
            }
58364
2c87d191056c 8228625: [TESTBUG] sun/tools/jhsdb/JShellHeapDumpTest.java fails with RuntimeException 'JShellToolProvider' missing from stdout/stderr
cjplummer
parents: 55647
diff changeset
   148
        } catch (Exception e) {
55647
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   149
        }
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   150
    }
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   151
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   152
    public static void main(String[] args) throws Exception {
58448
f45278353668 8231288: "jhsdb jmap" test needed to reproduce issues that used to be reproduced by JShellHeapDumpTest
cjplummer
parents: 58389
diff changeset
   153
        if (args.length == 1) {
f45278353668 8231288: "jhsdb jmap" test needed to reproduce issues that used to be reproduced by JShellHeapDumpTest
cjplummer
parents: 58389
diff changeset
   154
            if (args[0].equals("nosleep")) {
f45278353668 8231288: "jhsdb jmap" test needed to reproduce issues that used to be reproduced by JShellHeapDumpTest
cjplummer
parents: 58389
diff changeset
   155
                doSleep = false;
f45278353668 8231288: "jhsdb jmap" test needed to reproduce issues that used to be reproduced by JShellHeapDumpTest
cjplummer
parents: 58389
diff changeset
   156
            } else {
f45278353668 8231288: "jhsdb jmap" test needed to reproduce issues that used to be reproduced by JShellHeapDumpTest
cjplummer
parents: 58389
diff changeset
   157
                throw new RuntimeException("Invalid arg: " + args[0]);
f45278353668 8231288: "jhsdb jmap" test needed to reproduce issues that used to be reproduced by JShellHeapDumpTest
cjplummer
parents: 58389
diff changeset
   158
            }
f45278353668 8231288: "jhsdb jmap" test needed to reproduce issues that used to be reproduced by JShellHeapDumpTest
cjplummer
parents: 58389
diff changeset
   159
        } else if (args.length != 0) {
f45278353668 8231288: "jhsdb jmap" test needed to reproduce issues that used to be reproduced by JShellHeapDumpTest
cjplummer
parents: 58389
diff changeset
   160
            throw new RuntimeException("Too many args: " + args.length);
f45278353668 8231288: "jhsdb jmap" test needed to reproduce issues that used to be reproduced by JShellHeapDumpTest
cjplummer
parents: 58389
diff changeset
   161
        }
55647
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   162
        testHeapDump();
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   163
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   164
        // The test throws RuntimeException on error.
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   165
        // IOException is thrown if Jshell can't start because of some bad
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   166
        // environment condition
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   167
        System.out.println("Test PASSED");
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   168
    }
f60890de1dfb 8225715: jhsdb jmap fails to write binary heap dump of a jshell process
fmatte
parents:
diff changeset
   169
}