test/hotspot/jtreg/runtime/SharedArchiveFile/DumpSharedDictionary.java
author iklam
Tue, 02 Oct 2018 14:32:33 -0700
changeset 51990 6003e034cdd8
parent 49931 840e26123940
permissions -rw-r--r--
8209946: [TESTBUG] CDS tests should use "@run driver" Reviewed-by: ccheung, jiangli, mseledtsov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
46747
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
     1
/*
49008
d777541fceba 8191375: Add high-level jtreg VMProps to filter out CDS tests
iklam
parents: 48469
diff changeset
     2
 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
46747
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
     4
 *
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
     8
 *
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    13
 * accompanied this code).
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    14
 *
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    18
 *
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    21
 * questions.
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    22
 */
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    23
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    24
/*
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    25
 * @test
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    26
 * @bug 8130072
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    27
 * @summary Check that Shared Dictionary is printed out with jcmd
48469
7312ae4465d6 8193672: [test] Enhance vm.cds property to check for all conditions required to run CDS tests
iklam
parents: 47216
diff changeset
    28
 * @requires vm.cds
46747
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    29
 * @library /test/lib
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    30
 * @modules java.base/jdk.internal.misc
51990
6003e034cdd8 8209946: [TESTBUG] CDS tests should use "@run driver"
iklam
parents: 49931
diff changeset
    31
 * @run driver DumpSharedDictionary
46747
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    32
 */
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    33
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    34
import jdk.test.lib.cds.CDSTestUtils;
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    35
import jdk.test.lib.process.ProcessTools;
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    36
import jdk.test.lib.process.OutputAnalyzer;
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    37
import jdk.test.lib.JDKToolFinder;
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    38
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    39
public class DumpSharedDictionary {
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    40
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    41
    public static void main(String[] args) throws Exception {
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    42
        if (args.length == 0) {
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    43
            // Start this process
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    44
            ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    45
                "-XX:SharedArchiveFile=./DumpSharedDictionary.jsa",
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    46
                "-Xshare:dump");
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    47
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    48
            OutputAnalyzer out = CDSTestUtils.executeAndLog(pb, "dump");
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    49
            out.shouldHaveExitValue(0);
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    50
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    51
            String testjdkPath = System.getProperty("test.jdk");
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    52
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    53
            pb = ProcessTools.createJavaProcessBuilder(
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    54
                    "-XX:SharedArchiveFile=./DumpSharedDictionary.jsa",
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    55
                    "-Dtest.jdk=" + testjdkPath,
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    56
                    "-Xshare:on", "DumpSharedDictionary", "test");
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    57
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    58
            out = CDSTestUtils.executeAndLog(pb, "exec");
46781
81d54b338660 8186044: [TESTBUG] DumpSharedDictionary test sometimes fails in JPRT
coleenp
parents: 46747
diff changeset
    59
            if (!CDSTestUtils.isUnableToMap(out)) {
81d54b338660 8186044: [TESTBUG] DumpSharedDictionary test sometimes fails in JPRT
coleenp
parents: 46747
diff changeset
    60
                out.shouldHaveExitValue(0);
81d54b338660 8186044: [TESTBUG] DumpSharedDictionary test sometimes fails in JPRT
coleenp
parents: 46747
diff changeset
    61
            }
46747
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    62
        } else {
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    63
            // Grab my own PID
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    64
            String pid = Long.toString(ProcessTools.getProcessId());
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    65
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    66
            ProcessBuilder pb = new ProcessBuilder();
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    67
            pb.command(new String[] {JDKToolFinder.getJDKTool("jcmd"), pid, "VM.systemdictionary"});
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    68
            OutputAnalyzer output = CDSTestUtils.executeAndLog(pb, "jcmd-systemdictionary");
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    69
            try {
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    70
                output.shouldContain("Shared Dictionary statistics:");
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    71
                output.shouldContain("Number of buckets");
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    72
                output.shouldContain("Number of entries");
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    73
                output.shouldContain("Maximum bucket size");
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    74
            } catch (RuntimeException e) {
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    75
                output.shouldContain("Unknown diagnostic command");
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    76
            }
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    77
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    78
            pb.command(new String[] {JDKToolFinder.getJDKTool("jcmd"), pid, "VM.systemdictionary", "-verbose"});
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    79
            output = CDSTestUtils.executeAndLog(pb, "jcmd-systemdictionary-verbose");
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    80
            try {
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    81
                output.shouldContain("Shared Dictionary");
49348
fde3feaaa4ed 8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents: 49008
diff changeset
    82
                output.shouldContain("Dictionary for loader data: 0x");
46747
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    83
                output.shouldContain("^java.lang.String");
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    84
            } catch (RuntimeException e) {
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    85
                output.shouldContain("Unknown diagnostic command");
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    86
            }
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    87
        }
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    88
    }
7b6570052b58 8130072: Add a flag to print out statistics for both system dictionary and shared dictionary
coleenp
parents:
diff changeset
    89
}