test/hotspot/jtreg/serviceability/sa/ClhsdbScanOops.java
author goetz
Mon, 25 Jun 2018 23:04:21 +0200
changeset 50791 b1e90a8a876c
parent 48401 be065f758154
child 51287 7b1ddbafa134
permissions -rw-r--r--
8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach Reviewed-by: jgeorge, cjplummer
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48401
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
     1
/*
50791
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 48401
diff changeset
     2
 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
48401
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
     4
 *
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
     7
 * published by the Free Software Foundation.
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
     8
 *
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    13
 * accompanied this code).
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    14
 *
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    18
 *
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    21
 * questions.
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    22
 */
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    23
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    24
import java.util.HashMap;
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    25
import java.util.List;
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    26
import java.util.Map;
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    27
import java.util.ArrayList;
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    28
import jdk.test.lib.Utils;
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    29
import jdk.test.lib.apps.LingeredApp;
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    30
50791
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 48401
diff changeset
    31
/**
48401
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    32
 * @test
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    33
 * @bug 8192985
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    34
 * @summary Test the clhsdb 'scanoops' command
50791
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 48401
diff changeset
    35
 * @requires vm.hasSA
48401
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    36
 * @library /test/lib
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    37
 * @run main/othervm/timeout=1200 ClhsdbScanOops
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    38
 */
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    39
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    40
public class ClhsdbScanOops {
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    41
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    42
    private static void testWithGcType(String gc) throws Exception {
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    43
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    44
        LingeredApp theApp = null;
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    45
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    46
        try {
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    47
            ClhsdbLauncher test = new ClhsdbLauncher();
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    48
            List<String> vmArgs = new ArrayList<String>();
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    49
            vmArgs.add(gc);
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    50
            theApp = LingeredApp.startApp(vmArgs);
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    51
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    52
            System.out.println ("Started LingeredApp with the GC option " + gc +
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    53
                                " and pid " + theApp.getPid());
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    54
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    55
            // Run the 'universe' command to get the address ranges
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    56
            List<String> cmds = List.of("universe");
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    57
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    58
            String universeOutput = test.run(theApp.getPid(), cmds, null, null);
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    59
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    60
            if (universeOutput == null) {
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    61
                // Output could be null due to attach permission issues
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    62
                // and if we are skipping this.
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    63
                LingeredApp.stopApp(theApp);
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    64
                return;
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    65
            }
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    66
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    67
            cmds = new ArrayList<String>();
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    68
            Map<String, List<String>> expStrMap = new HashMap<>();
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    69
            Map<String, List<String>> unExpStrMap = new HashMap<>();
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    70
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    71
            String startAddress = null;
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    72
            String endAddress = null;
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    73
            String[] snippets = null;
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    74
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    75
            if (gc.contains("UseParallelGC")) {
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    76
                snippets = universeOutput.split("eden =  ");
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    77
            } else {
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    78
                snippets = universeOutput.split("eden \\[");
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    79
            }
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    80
            String[] words = snippets[1].split(",");
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    81
            // Get the addresses from Eden
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    82
            startAddress = words[0].replace("[", "");
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    83
            endAddress = words[1];
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    84
            String cmd = "scanoops " + startAddress + " " + endAddress;
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    85
            cmds.add(cmd);
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    86
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    87
            expStrMap.put(cmd, List.of
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    88
                ("java/lang/Object", "java/lang/Class", "java/lang/Thread",
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    89
                 "java/lang/String", "[B", "[I"));
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    90
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    91
            // Test the 'type' option also
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    92
            // scanoops <start addr> <end addr> java/lang/String
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    93
            // Ensure that only the java/lang/String oops are printed.
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    94
            cmd = cmd + " java/lang/String";
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    95
            cmds.add(cmd);
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    96
            expStrMap.put(cmd, List.of("java/lang/String"));
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    97
            unExpStrMap.put(cmd, List.of("java/lang/Thread"));
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    98
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    99
            test.run(theApp.getPid(), cmds, expStrMap, unExpStrMap);
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   100
        } catch (Exception ex) {
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   101
            throw new RuntimeException("Test ERROR " + ex, ex);
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   102
        } finally {
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   103
            LingeredApp.stopApp(theApp);
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   104
        }
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   105
    }
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   106
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   107
    public static void main(String[] args) throws Exception {
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   108
        System.out.println("Starting the ClhsdbScanOops test");
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   109
        try {
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   110
            testWithGcType("-XX:+UseParallelGC");
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   111
            testWithGcType("-XX:+UseSerialGC");
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   112
        } catch (Exception e) {
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   113
            throw new Error("Test failed with " + e);
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   114
        }
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   115
        System.out.println("Test PASSED");
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   116
    }
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   117
}