test/hotspot/jtreg/serviceability/sa/ClhsdbPrintAs.java
author ihse
Tue, 20 Feb 2018 21:47:54 +0100
changeset 48923 b75c9e2e3b1f
parent 48401 be065f758154
child 50791 b1e90a8a876c
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:
48401
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
     1
/*
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
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.apps.LingeredApp;
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    29
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    30
/*
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    31
 * @test
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    32
 * @bug 8192985
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    33
 * @summary Test the clhsdb 'printas' command
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    34
 * @library /test/lib
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    35
 * @run main/othervm ClhsdbPrintAs
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    36
 */
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    37
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    38
public class ClhsdbPrintAs {
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 static void main(String[] args) throws Exception {
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    41
        System.out.println("Starting the ClhsdbPrintAs test");
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    42
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    43
        LingeredApp theApp = null;
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    44
        try {
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    45
            ClhsdbLauncher test = new ClhsdbLauncher();
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    46
            theApp = LingeredApp.startApp();
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    47
            System.out.println("Started LingeredApp with pid " + theApp.getPid());
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    48
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    49
            // Run the 'jstack -v' command to get the address of a the Method*
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    50
            // representing LingeredApp.main
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    51
            List<String> cmds = List.of("jstack -v");
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    52
            Map<String, List<String>> expStrMap;
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    53
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    54
            String jstackOutput = test.run(theApp.getPid(), cmds, null, null);
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    55
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    56
            if (jstackOutput == null) {
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    57
                // 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
    58
                // and if we are skipping this.
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    59
                LingeredApp.stopApp(theApp);
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    60
                return;
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    61
            }
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    62
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    63
            String[] snippets = jstackOutput.split("LingeredApp.main");
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    64
            String addressString = null;
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
            String[] tokens = snippets[1].split("Method\\*=");
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    67
            String[] words = tokens[1].split(" ");
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    68
            addressString = words[0];
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    69
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    70
            cmds = new ArrayList<String>();
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    71
            expStrMap = new HashMap<>();
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    72
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    73
            String cmd = "printas Method " + addressString;
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    74
            cmds.add(cmd);
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    75
            expStrMap.put(cmd, List.of
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    76
                ("ConstMethod", "MethodCounters", "Method::_access_flags"));
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    77
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    78
            // Run the printas Method <addr> command to obtain the address
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    79
            // of ConstMethod*
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    80
            String methodDetailsOutput = test.run(theApp.getPid(), cmds, expStrMap, null);
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    81
            snippets = methodDetailsOutput.split("ConstMethod*");
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    82
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    83
            tokens = snippets[1].split(" ");
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    84
            for (String token : tokens) {
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    85
                if (token.contains("0x")) {
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    86
                    addressString = token.replace("\n", "");
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    87
                    break;
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    88
                }
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    89
            }
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
            cmds = new ArrayList<String>();
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    92
            expStrMap = new HashMap<>();
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    93
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    94
            cmd = "printas ConstMethod " + addressString;
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
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    97
                ("ConstantPool", "_max_locals", "_flags"));
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
            // Run the printas constMethod <addr> command to obtain the address
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   100
            // of ConstantPool*
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   101
            String constMethodDetailsOutput = test.run(theApp.getPid(), cmds, expStrMap, null);
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   102
            snippets = constMethodDetailsOutput.split("ConstantPool*");
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   103
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   104
            tokens = snippets[1].split(" ");
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   105
            for (String token : tokens) {
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   106
                if (token.contains("0x")) {
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   107
                    addressString = token.replace("\n", "");
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   108
                    break;
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   109
                }
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   110
            }
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   111
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   112
            cmds = new ArrayList<String>();
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   113
            expStrMap = new HashMap<>();
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
            cmd = "printas ConstantPool " + addressString;
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   116
            cmds.add(cmd);
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   117
            expStrMap.put(cmd, List.of
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   118
                ("ConstantPoolCache", "_pool_holder", "InstanceKlass*"));
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   119
            test.run(theApp.getPid(), cmds, expStrMap, null);
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   120
        } catch (Exception ex) {
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   121
            throw new RuntimeException("Test ERROR " + ex, ex);
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   122
        } finally {
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   123
            LingeredApp.stopApp(theApp);
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   124
        }
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   125
        System.out.println("Test PASSED");
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   126
    }
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   127
}