test/hotspot/jtreg/serviceability/sa/ClhsdbInspect.java
author sspitsyn
Tue, 26 Jun 2018 13:50:59 -0700
changeset 50802 fa380b3b2b7d
parent 50791 b1e90a8a876c
child 51287 7b1ddbafa134
permissions -rw-r--r--
8205721: Problem list serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatArrayCorrectnessTest.java Summary: Add the test to the ProblemList.txt Reviewed-by: dcubed
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
/*
48866
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
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.apps.LingeredApp;
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    29
50791
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 48866
diff changeset
    30
/**
48401
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 'inspect' command
50791
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 48866
diff changeset
    34
 * @requires vm.hasSA
48401
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    35
 * @library /test/lib
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    36
 * @run main/othervm ClhsdbInspect
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
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    39
public class ClhsdbInspect {
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    40
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    41
    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
    42
        System.out.println("Starting the ClhsdbInspect test");
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
        LingeredAppWithLock theApp = null;
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    45
        try {
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    46
            ClhsdbLauncher test = new ClhsdbLauncher();
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    47
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    48
            theApp = new LingeredAppWithLock();
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    49
            LingeredApp.startApp(null, theApp);
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    50
            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
    51
48866
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    52
            // Run the 'jstack -v' command to get the address of a Method*,
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    53
            // the oop address of a java.lang.ref.ReferenceQueue$Lock
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    54
            // and the oop address of a java.lang.Class object
48401
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    55
            List<String> cmds = List.of("jstack -v");
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    56
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    57
            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
    58
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    59
            if (jstackOutput == null) {
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    60
                // 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
    61
                // and if we are skipping this.
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    62
                LingeredApp.stopApp(theApp);
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    63
                return;
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    64
            }
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
            Map<String, String> tokensMap = new HashMap<>();
48866
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    67
            tokensMap.put("(a java.lang.Class for LingeredAppWithLock)",
48401
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    68
                          "instance of Oop for java/lang/Class");
48866
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    69
            tokensMap.put("Method*=", "Type is Method");
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    70
            tokensMap.put("(a java.lang.ref.ReferenceQueue$Lock)",
48401
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    71
                          "instance of Oop for java/lang/ref/ReferenceQueue$Lock");
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    72
48866
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    73
            String[] lines = jstackOutput.split("\\R");
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    74
48401
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    75
            for (String key: tokensMap.keySet()) {
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    76
                cmds = new ArrayList<String>();
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    77
                Map<String, List<String>> expStrMap = new HashMap<>();
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    78
48866
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    79
                String addressString = null;
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    80
                for (String line : lines) {
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    81
                    if (line.contains(key)) {
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    82
                        // Escape the token "Method*=" because the split method uses
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    83
                        // a regex, not just a straight String.
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    84
                        String escapedKey = key.replace("*","\\*");
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    85
                        String[] words = line.split(escapedKey+"|[ ]");
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    86
                        for (String word : words) {
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    87
                            word = word.replace("<","").replace(">","");
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    88
                            if (word.startsWith("0x")) {
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    89
                                addressString = word;
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    90
                                break;
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    91
                            }
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    92
                        }
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    93
                        if (addressString != null)
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    94
                            break;
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    95
                      }
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    96
                  }
48401
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    97
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    98
                String cmd = "inspect " + addressString;
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    99
                cmds.add(cmd);
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   100
                expStrMap.put(cmd, List.of(tokensMap.get(key)));
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   101
                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
            }
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   103
        } catch (Exception ex) {
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   104
            throw new RuntimeException("Test ERROR " + ex, ex);
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   105
        } finally {
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   106
            LingeredApp.stopApp(theApp);
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   107
        }
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   108
        System.out.println("Test PASSED");
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
}