test/hotspot/jtreg/serviceability/sa/ClhsdbFindPC.java
author kvn
Wed, 08 Aug 2018 18:38:34 -0700
changeset 51341 09cc8813ae51
parent 50791 b1e90a8a876c
child 53267 0b6d6db878b6
permissions -rw-r--r--
8207965: C2-only debug build fails Reviewed-by: kvn, iignatyev Contributed-by: xxinliu@amazon.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48381
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
     1
/*
48982
9a8fddef7ad0 8196930: [Testbug] serviceability/sa/ClhsdbFindPC.java fails to find expected output
sballal
parents: 48381
diff changeset
     2
 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
48381
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
     4
 *
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
     8
 *
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    13
 * accompanied this code).
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    14
 *
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    18
 *
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    21
 * questions.
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    22
 */
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    23
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    24
import java.util.HashMap;
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    25
import java.util.List;
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    26
import java.util.Map;
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    27
import java.util.ArrayList;
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    28
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    29
import jdk.test.lib.apps.LingeredApp;
50791
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 48982
diff changeset
    30
/**
48381
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    31
 * @test
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    32
 * @bug 8193124
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    33
 * @summary Test the clhsdb 'findpc' command
50791
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 48982
diff changeset
    34
 * @requires vm.hasSA
51341
09cc8813ae51 8207965: C2-only debug build fails
kvn
parents: 50791
diff changeset
    35
 * @requires vm.compiler1.enabled
48381
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    36
 * @library /test/lib
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    37
 * @run main/othervm ClhsdbFindPC
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    38
 */
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    39
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    40
public class ClhsdbFindPC {
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    41
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    42
    private static void testFindPC(boolean withXcomp) throws Exception {
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    43
        LingeredApp theApp = null;
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    44
        try {
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    45
            ClhsdbLauncher test = new ClhsdbLauncher();
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    46
            theApp = withXcomp ? LingeredApp.startApp(List.of("-Xcomp"))
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    47
                               : LingeredApp.startApp(List.of("-Xint"));
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    48
            System.out.print("Started LingeredApp ");
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    49
            if (withXcomp) {
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    50
                System.out.print("(-Xcomp) ");
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    51
            } else {
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    52
                System.out.print("(-Xint) ");
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    53
            }
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    54
            System.out.println("with pid " + theApp.getPid());
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    55
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    56
            // Run 'jstack -v' command to get the pc
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    57
            List<String> cmds = List.of("jstack -v");
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    58
            String output = test.run(theApp.getPid(), cmds, null, null);
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    59
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    60
            // Test the 'findpc' command passing in the pc obtained from
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    61
            // the 'jstack -v' command
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    62
            cmds = new ArrayList<String>();
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    63
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    64
            // Output could be null if the test was skipped due to
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    65
            // attach permission issues.
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    66
            if (output != null) {
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    67
                String cmdStr = null;
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    68
                String[] parts = output.split("LingeredApp.main");
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    69
                String[] tokens = parts[1].split(" ");
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    70
                for (String token : tokens) {
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    71
                    if (token.contains("pc")) {
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    72
                        String[] address = token.split("=");
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    73
                        // address[1] represents the address of the Method
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    74
                        cmdStr = "findpc " + address[1].replace(",","");
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    75
                        cmds.add(cmdStr);
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    76
                        break;
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    77
                    }
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    78
                }
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    79
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    80
                Map<String, List<String>> expStrMap = new HashMap<>();
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    81
                if (withXcomp) {
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    82
                    expStrMap.put(cmdStr, List.of(
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    83
                            "In code in NMethod for jdk/test/lib/apps/LingeredApp.main",
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    84
                            "content:",
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    85
                            "oops:",
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    86
                            "frame size:"));
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    87
                } else {
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    88
                    expStrMap.put(cmdStr, List.of(
48982
9a8fddef7ad0 8196930: [Testbug] serviceability/sa/ClhsdbFindPC.java fails to find expected output
sballal
parents: 48381
diff changeset
    89
                            "In interpreter codelet"));
48381
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    90
                }
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    91
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    92
                test.run(theApp.getPid(), cmds, expStrMap, null);
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    93
            }
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    94
        } catch (Exception ex) {
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    95
            throw new RuntimeException("Test ERROR " + ex, ex);
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    96
        } finally {
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    97
            LingeredApp.stopApp(theApp);
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    98
        }
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
    99
    }
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
   100
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
   101
    public static void main(String[] args) throws Exception {
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
   102
        System.out.println("Starting the ClhsdbFindPC test");
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
   103
        testFindPC(true);
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
   104
        testFindPC(false);
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
   105
        System.out.println("Test PASSED");
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
   106
    }
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
   107
}
8b434af2703d 8193124: SA: Testcases for clhsdb jdis and findpc commands
sballal
parents:
diff changeset
   108