test/hotspot/jtreg/serviceability/sa/ClhsdbInspect.java
author jgeorge
Tue, 05 Feb 2019 00:43:38 +0530
changeset 53635 247e5ca412f5
parent 53596 bb40a5303c84
permissions -rw-r--r--
8215568: Refactor SA clhsdb tests to use ClhsdbLauncher Summary: Refactoring the SA tests which test clhsdb commands to use ClhsdbLauncher for uniformity and ease of maintainence Reviewed-by: jcbeyler, dholmes
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
/*
53140
697b5f5dec56 8213457: serviceability/sa/ClhsdbInspect.java time out
jgeorge
parents: 51287
diff changeset
     2
 * Copyright (c) 2017, 2019, 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
50791
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 48866
diff changeset
    24
/**
48401
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    25
 * @test
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    26
 * @bug 8192985
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    27
 * @summary Test the clhsdb 'inspect' command
50791
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 48866
diff changeset
    28
 * @requires vm.hasSA
48401
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    29
 * @library /test/lib
53140
697b5f5dec56 8213457: serviceability/sa/ClhsdbInspect.java time out
jgeorge
parents: 51287
diff changeset
    30
 * @run main/othervm/timeout=480 ClhsdbInspect
48401
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    31
 */
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    32
51287
7b1ddbafa134 8208655: use JTreg skipped status in hotspot tests
iignatyev
parents: 50791
diff changeset
    33
import java.util.HashMap;
7b1ddbafa134 8208655: use JTreg skipped status in hotspot tests
iignatyev
parents: 50791
diff changeset
    34
import java.util.List;
7b1ddbafa134 8208655: use JTreg skipped status in hotspot tests
iignatyev
parents: 50791
diff changeset
    35
import java.util.Map;
7b1ddbafa134 8208655: use JTreg skipped status in hotspot tests
iignatyev
parents: 50791
diff changeset
    36
import java.util.ArrayList;
7b1ddbafa134 8208655: use JTreg skipped status in hotspot tests
iignatyev
parents: 50791
diff changeset
    37
import jdk.test.lib.apps.LingeredApp;
7b1ddbafa134 8208655: use JTreg skipped status in hotspot tests
iignatyev
parents: 50791
diff changeset
    38
import jtreg.SkippedException;
7b1ddbafa134 8208655: use JTreg skipped status in hotspot tests
iignatyev
parents: 50791
diff changeset
    39
48401
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    40
public class ClhsdbInspect {
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
    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
    43
        System.out.println("Starting the ClhsdbInspect test");
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    44
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    45
        LingeredAppWithLock theApp = null;
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
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    49
            theApp = new LingeredAppWithLock();
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    50
            LingeredApp.startApp(null, theApp);
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    51
            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
    52
48866
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    53
            // 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
    54
            // the oop address of a java.lang.ref.ReferenceQueue$Lock
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    55
            // 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
    56
            List<String> cmds = List.of("jstack -v");
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 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
    59
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    60
            Map<String, String> tokensMap = new HashMap<>();
48866
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    61
            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
    62
                          "instance of Oop for java/lang/Class");
48866
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    63
            tokensMap.put("Method*=", "Type is Method");
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    64
            tokensMap.put("(a java.lang.ref.ReferenceQueue$Lock)",
53635
247e5ca412f5 8215568: Refactor SA clhsdb tests to use ClhsdbLauncher
jgeorge
parents: 53596
diff changeset
    65
                          "instance of Oop for java/lang/ref/ReferenceQueue\\$Lock");
48401
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    66
48866
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    67
            String[] lines = jstackOutput.split("\\R");
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    68
48401
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    69
            for (String key: tokensMap.keySet()) {
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
                Map<String, List<String>> expStrMap = new HashMap<>();
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 addressString = null;
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    74
                for (String line : lines) {
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    75
                    if (line.contains(key)) {
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    76
                        // Escape the token "Method*=" because the split method uses
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    77
                        // a regex, not just a straight String.
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    78
                        String escapedKey = key.replace("*","\\*");
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    79
                        String[] words = line.split(escapedKey+"|[ ]");
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    80
                        for (String word : words) {
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    81
                            word = word.replace("<","").replace(">","");
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    82
                            if (word.startsWith("0x")) {
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    83
                                addressString = word;
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    84
                                break;
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    85
                            }
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    86
                        }
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    87
                        if (addressString != null)
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    88
                            break;
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    89
                      }
b983e6032aa7 8196361: JTReg failure: serviceability/sa/ClhsdbInspect.java
dstewart
parents: 48401
diff changeset
    90
                  }
48401
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    91
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    92
                String cmd = "inspect " + addressString;
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    93
                cmds.add(cmd);
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    94
                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
    95
                test.run(theApp.getPid(), cmds, expStrMap, null);
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    96
            }
51287
7b1ddbafa134 8208655: use JTreg skipped status in hotspot tests
iignatyev
parents: 50791
diff changeset
    97
        } catch (SkippedException e) {
7b1ddbafa134 8208655: use JTreg skipped status in hotspot tests
iignatyev
parents: 50791
diff changeset
    98
            throw e;
48401
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
    99
        } catch (Exception ex) {
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   100
            throw new RuntimeException("Test ERROR " + ex, ex);
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   101
        } finally {
be065f758154 8192985: SA: Test cases for the clhsdb 'inspect', 'scanoops' and 'printas' commands
jgeorge
parents:
diff changeset
   102
            LingeredApp.stopApp(theApp);
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
        System.out.println("Test PASSED");
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
}