test/hotspot/jtreg/serviceability/sa/ClhsdbSymbolTable.java
branchhttp-client-branch
changeset 56833 be0819373531
parent 56819 4cd8d88dab38
parent 51093 4db6e8715e35
child 56834 577317b61442
equal deleted inserted replaced
56819:4cd8d88dab38 56833:be0819373531
     1 /*
       
     2  * Copyright (c) 2017, 2018, 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  * @requires vm.hasSA
       
    35  * @library /test/lib
       
    36  * @run main/othervm ClhsdbSymbolTable
       
    37  */
       
    38 
       
    39 public class ClhsdbSymbolTable {
       
    40 
       
    41     public static void main(String[] args) throws Exception {
       
    42         System.out.println("Starting the ClhsdbSymbolTable test");
       
    43 
       
    44         LingeredApp theApp = null;
       
    45         try {
       
    46             ClhsdbLauncher test = new ClhsdbLauncher();
       
    47 
       
    48             theApp = LingeredApp.startApp();
       
    49             System.out.println("Started LingeredApp with pid " + theApp.getPid());
       
    50 
       
    51             // Test the symboltable command
       
    52             List<String> cmds = List.of(
       
    53                 "symboltable main",
       
    54                 "symboltable java/lang/Class",
       
    55                 "symboltable java/lang/Object",
       
    56                 "symboltable java/lang/String",
       
    57                 "symboltable java/util/List",
       
    58                 "symboltable jdk/test/lib/apps/LingeredApp");
       
    59 
       
    60             Map<String, List<String>> expStrMap = new HashMap<>();
       
    61             expStrMap.put("symboltable main", List.of(
       
    62                 "sun.jvm.hotspot.oops.Symbol@"));
       
    63             expStrMap.put("symboltable java/lang/Class", List.of(
       
    64                 "sun.jvm.hotspot.oops.Symbol@"));
       
    65             expStrMap.put("symboltable java/lang/Object", List.of(
       
    66                 "sun.jvm.hotspot.oops.Symbol@"));
       
    67             expStrMap.put("symboltable java/lang/String", List.of(
       
    68                 "sun.jvm.hotspot.oops.Symbol@"));
       
    69             expStrMap.put("symboltable java/util/List", List.of(
       
    70                 "sun.jvm.hotspot.oops.Symbol@"));
       
    71             expStrMap.put("symboltable jdk/test/lib/apps/LingeredApp", List.of(
       
    72                 "sun.jvm.hotspot.oops.Symbol@"));
       
    73             String consolidatedOutput =
       
    74                 test.run(theApp.getPid(), cmds, expStrMap, null);
       
    75 
       
    76             // Test the 'symbol' command passing in the address obtained from
       
    77             // the 'symboltable' command
       
    78             expStrMap = new HashMap<>();
       
    79             cmds = new ArrayList<String>();
       
    80             int expectedStringsIdx = 0;
       
    81             String expectedStrings[] = {"#main",
       
    82                                         "#java/lang/Class", "#java/lang/Object",
       
    83                                         "#java/lang/String", "#java/util/List",
       
    84                                         "#jdk/test/lib/apps/LingeredApp"};
       
    85             if (consolidatedOutput != null) {
       
    86                 // Output could be null due to attach permission issues
       
    87                 // and if we are skipping this.
       
    88                 String[] singleCommandOutputs = consolidatedOutput.split("hsdb>");
       
    89 
       
    90                 for (String singleCommandOutput : singleCommandOutputs) {
       
    91                     if (singleCommandOutput.contains("@")) {
       
    92                         String[] tokens = singleCommandOutput.split("@");
       
    93                         String addressString = tokens[1].replace("\n","");
       
    94 
       
    95                         // tokens[1] represents the address of the symbol
       
    96                         String cmd = "symbol " + addressString;
       
    97                         cmds.add(cmd);
       
    98                         expStrMap.put(cmd, List.of
       
    99                             (expectedStrings[expectedStringsIdx++]));
       
   100                     }
       
   101                 }
       
   102                 test.run(theApp.getPid(), cmds, expStrMap, null);
       
   103             }
       
   104         } catch (Exception ex) {
       
   105             throw new RuntimeException("Test ERROR " + ex, ex);
       
   106         } finally {
       
   107             LingeredApp.stopApp(theApp);
       
   108         }
       
   109         System.out.println("Test PASSED");
       
   110     }
       
   111 }