test/hotspot/jtreg/serviceability/sa/ClhsdbSymbolTable.java
changeset 48181 61a14b5cb1c6
child 50791 b1e90a8a876c
equal deleted inserted replaced
48180:e277fdf5e631 48181:61a14b5cb1c6
       
     1 /*
       
     2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 import java.util.HashMap;
       
    25 import java.util.List;
       
    26 import java.util.Map;
       
    27 import java.util.ArrayList;
       
    28 import jdk.test.lib.apps.LingeredApp;
       
    29 
       
    30 /*
       
    31  * @test
       
    32  * @bug 8191538
       
    33  * @summary Test the clhsdb 'symboltable' and 'symbol' commands
       
    34  * @library /test/lib
       
    35  * @run main/othervm ClhsdbSymbolTable
       
    36  */
       
    37 
       
    38 public class ClhsdbSymbolTable {
       
    39 
       
    40     public static void main(String[] args) throws Exception {
       
    41         System.out.println("Starting the ClhsdbSymbolTable test");
       
    42 
       
    43         LingeredApp theApp = null;
       
    44         try {
       
    45             ClhsdbLauncher test = new ClhsdbLauncher();
       
    46 
       
    47             theApp = LingeredApp.startApp();
       
    48             System.out.println("Started LingeredApp with pid " + theApp.getPid());
       
    49 
       
    50             // Test the symboltable command
       
    51             List<String> cmds = List.of(
       
    52                 "symboltable main",
       
    53                 "symboltable java/lang/Class",
       
    54                 "symboltable java/lang/Object",
       
    55                 "symboltable java/lang/String",
       
    56                 "symboltable java/util/List",
       
    57                 "symboltable jdk/test/lib/apps/LingeredApp");
       
    58 
       
    59             Map<String, List<String>> expStrMap = new HashMap<>();
       
    60             expStrMap.put("symboltable main", List.of(
       
    61                 "sun.jvm.hotspot.oops.Symbol@"));
       
    62             expStrMap.put("symboltable java/lang/Class", List.of(
       
    63                 "sun.jvm.hotspot.oops.Symbol@"));
       
    64             expStrMap.put("symboltable java/lang/Object", List.of(
       
    65                 "sun.jvm.hotspot.oops.Symbol@"));
       
    66             expStrMap.put("symboltable java/lang/String", List.of(
       
    67                 "sun.jvm.hotspot.oops.Symbol@"));
       
    68             expStrMap.put("symboltable java/util/List", List.of(
       
    69                 "sun.jvm.hotspot.oops.Symbol@"));
       
    70             expStrMap.put("symboltable jdk/test/lib/apps/LingeredApp", List.of(
       
    71                 "sun.jvm.hotspot.oops.Symbol@"));
       
    72             String consolidatedOutput =
       
    73                 test.run(theApp.getPid(), cmds, expStrMap, null);
       
    74 
       
    75             // Test the 'symbol' command passing in the address obtained from
       
    76             // the 'symboltable' command
       
    77             expStrMap = new HashMap<>();
       
    78             cmds = new ArrayList<String>();
       
    79             int expectedStringsIdx = 0;
       
    80             String expectedStrings[] = {"#main",
       
    81                                         "#java/lang/Class", "#java/lang/Object",
       
    82                                         "#java/lang/String", "#java/util/List",
       
    83                                         "#jdk/test/lib/apps/LingeredApp"};
       
    84             if (consolidatedOutput != null) {
       
    85                 // Output could be null due to attach permission issues
       
    86                 // and if we are skipping this.
       
    87                 String[] singleCommandOutputs = consolidatedOutput.split("hsdb>");
       
    88 
       
    89                 for (String singleCommandOutput : singleCommandOutputs) {
       
    90                     if (singleCommandOutput.contains("@")) {
       
    91                         String[] tokens = singleCommandOutput.split("@");
       
    92                         String addressString = tokens[1].replace("\n","");
       
    93 
       
    94                         // tokens[1] represents the address of the symbol
       
    95                         String cmd = "symbol " + addressString;
       
    96                         cmds.add(cmd);
       
    97                         expStrMap.put(cmd, List.of
       
    98                             (expectedStrings[expectedStringsIdx++]));
       
    99                     }
       
   100                 }
       
   101                 test.run(theApp.getPid(), cmds, expStrMap, null);
       
   102             }
       
   103         } catch (Exception ex) {
       
   104             throw new RuntimeException("Test ERROR " + ex, ex);
       
   105         } finally {
       
   106             LingeredApp.stopApp(theApp);
       
   107         }
       
   108         System.out.println("Test PASSED");
       
   109     }
       
   110 }