test/hotspot/jtreg/serviceability/sa/TestUniverse.java
author ihse
Tue, 20 Feb 2018 21:47:54 +0100
changeset 48923 b75c9e2e3b1f
parent 47900 75d365bfc2e6
child 49463 ccb003941743
permissions -rw-r--r--
8198450: Make jdk.internal.vm.compiler/module-info.java.extra reproducable Reviewed-by: erikj, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47900
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
     1
/*
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
     4
 *
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
     7
 * published by the Free Software Foundation.
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
     8
 *
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    13
 * accompanied this code).
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    14
 *
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    18
 *
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    21
 * questions.
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    22
 */
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    23
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    24
import java.util.ArrayList;
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    25
import java.util.List;
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    26
import java.io.IOException;
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    27
import java.util.stream.Collectors;
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    28
import java.io.OutputStream;
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    29
import jdk.test.lib.apps.LingeredApp;
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    30
import jdk.test.lib.JDKToolLauncher;
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    31
import jdk.test.lib.Platform;
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    32
import jdk.test.lib.process.OutputAnalyzer;
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    33
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    34
/*
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    35
 * @test
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    36
 * @summary Test the 'universe' command of jhsdb clhsdb.
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    37
 * @bug 8190307
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    38
 * @library /test/lib
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    39
 * @build jdk.test.lib.apps.*
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    40
 * @run main/othervm TestUniverse
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    41
 */
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    42
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    43
public class TestUniverse {
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    44
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    45
    private static void testClhsdbForUniverse(long lingeredAppPid,
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    46
                                              String gc) throws Exception {
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    47
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    48
        Process p;
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    49
        JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    50
        launcher.addToolArg("clhsdb");
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    51
        launcher.addToolArg("--pid");
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    52
        launcher.addToolArg(Long.toString(lingeredAppPid));
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    53
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    54
        ProcessBuilder pb = new ProcessBuilder();
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    55
        pb.command(launcher.getCommand());
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    56
        System.out.println(
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    57
            pb.command().stream().collect(Collectors.joining(" ")));
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    58
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    59
        try {
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    60
            p = pb.start();
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    61
        } catch (Exception attachE) {
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    62
            throw new Error("Couldn't start jhsdb or attach to LingeredApp : " + attachE);
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    63
        }
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    64
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    65
        // Issue the 'universe' command at the clhsdb prompt.
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    66
        OutputStream input = p.getOutputStream();
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    67
        try {
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    68
            input.write("universe\n".getBytes());
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    69
            input.write("quit\n".getBytes());
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    70
            input.flush();
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    71
        } catch (IOException ioe) {
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    72
            throw new Error("Problem issuing the 'universe' command ", ioe);
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    73
        }
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    74
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    75
        OutputAnalyzer output = new OutputAnalyzer(p);
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    76
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    77
        try {
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    78
            p.waitFor();
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    79
        } catch (InterruptedException ie) {
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    80
            p.destroyForcibly();
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    81
            throw new Error("Problem awaiting the child process: " + ie, ie);
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    82
        }
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    83
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    84
        output.shouldHaveExitValue(0);
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    85
        System.out.println(output.getOutput());
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    86
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    87
        output.shouldContain("Heap Parameters");
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    88
        if (gc.contains("G1GC")) {
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    89
            output.shouldContain("garbage-first heap");
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    90
        }
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    91
        if (gc.contains("UseConcMarkSweepGC")) {
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    92
            output.shouldContain("Gen 1: concurrent mark-sweep generation");
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    93
        }
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    94
        if (gc.contains("UseSerialGC")) {
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    95
            output.shouldContain("Gen 1:   old");
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    96
        }
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    97
        if (gc.contains("UseParallelGC")) {
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    98
            output.shouldContain("ParallelScavengeHeap");
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
    99
            output.shouldContain("PSYoungGen");
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   100
            output.shouldContain("eden");
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   101
        }
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   102
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   103
    }
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   104
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   105
    public static void test(String gc) throws Exception {
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   106
        LingeredApp app = null;
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   107
        try {
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   108
            List<String> vmArgs = new ArrayList<String>();
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   109
            vmArgs.add(gc);
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   110
            app = LingeredApp.startApp(vmArgs);
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   111
            System.out.println ("Started LingeredApp with the GC option " + gc +
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   112
                                " and pid " + app.getPid());
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   113
            testClhsdbForUniverse(app.getPid(), gc);
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   114
        } finally {
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   115
            LingeredApp.stopApp(app);
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   116
        }
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   117
    }
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   118
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   119
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   120
    public static void main (String... args) throws Exception {
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   121
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   122
        if (!Platform.shouldSAAttach()) {
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   123
            System.out.println(
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   124
               "SA attach not expected to work - test skipped.");
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   125
            return;
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   126
        }
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   127
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   128
        try {
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   129
            test("-XX:+UseG1GC");
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   130
            test("-XX:+UseParallelGC");
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   131
            test("-XX:+UseSerialGC");
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   132
            test("-XX:+UseConcMarkSweepGC");
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   133
        } catch (Exception e) {
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   134
            throw new Error("Test failed with " + e);
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   135
        }
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   136
    }
75d365bfc2e6 8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff changeset
   137
}