< prev index next >

test/hotspot/jtreg/serviceability/sa/ClhsdbInspect.java

Print this page

 40 public class ClhsdbInspect {
 41 
 42     public static void main(String[] args) throws Exception {
 43         System.out.println("Starting the ClhsdbInspect test");
 44 
 45         LingeredAppWithLock theApp = null;
 46         try {
 47             ClhsdbLauncher test = new ClhsdbLauncher();
 48 
 49             theApp = new LingeredAppWithLock();
 50             LingeredApp.startApp(theApp);
 51             System.out.println("Started LingeredApp with pid " + theApp.getPid());
 52 
 53             // Run the 'jstack -v' command to get the address of a Method*,
 54             // the oop address of a java.lang.ref.ReferenceQueue$Lock
 55             // and the oop address of a java.lang.Class object
 56             List<String> cmds = List.of("jstack -v");
 57 
 58             String jstackOutput = test.run(theApp.getPid(), cmds, null, null);
 59 

 60             Map<String, String> tokensMap = new HashMap<>();
 61             tokensMap.put("(a java.lang.Class for LingeredAppWithLock)",
 62                           "instance of Oop for java/lang/Class");
 63             tokensMap.put("Method*=", "Type is Method");
 64             tokensMap.put("(a java.lang.ref.ReferenceQueue$Lock)",
 65                           "instance of Oop for java/lang/ref/ReferenceQueue\\$Lock");


 66 
 67             String[] lines = jstackOutput.split("\\R");
 68 
 69             for (String key: tokensMap.keySet()) {
 70                 cmds = new ArrayList<String>();
 71                 Map<String, List<String>> expStrMap = new HashMap<>();
 72 
 73                 String addressString = null;
 74                 for (String line : lines) {
 75                     if (line.contains(key)) {
 76                         // Escape the token "Method*=" because the split method uses
 77                         // a regex, not just a straight String.
 78                         String escapedKey = key.replace("*","\\*");
 79                         String[] words = line.split(escapedKey+"|[ ]");
 80                         for (String word : words) {
 81                             word = word.replace("<","").replace(">","");
 82                             if (word.startsWith("0x")) {
 83                                 addressString = word;
 84                                 break;
 85                             }
 86                         }
 87                         if (addressString != null)
 88                             break;
 89                       }
 90                   }
 91 

 92                 String cmd = "inspect " + addressString;
 93                 cmds.add(cmd);
 94                 expStrMap.put(cmd, List.of(tokensMap.get(key)));
 95                 test.run(theApp.getPid(), cmds, expStrMap, null);
 96             }
 97 
 98             // This part is testing JDK-8261269. When inspecting a java object, we want to make
 99             // sure the address is not printed twice and that "Oop for ..." is not printed twice.
100             //
101             // The goal of this test is to dump the Class instance for java.lang.System. It contains
102             // some Oop statics, and that's where the redundant "Oop for..." was noticed. The script
103             // looks something like this:
104             //
105             // hsdb> class java.lang.System
106             // java/lang/System @0x000000080000f388
107             //
108             // hsdb> inspect 0x000000080000f388
109             // Type is InstanceKlass (size of 480)
110             // ...
111             // OopHandle Klass::_java_mirror: OopHandle @ 0x000000080000f400

 40 public class ClhsdbInspect {
 41 
 42     public static void main(String[] args) throws Exception {
 43         System.out.println("Starting the ClhsdbInspect test");
 44 
 45         LingeredAppWithLock theApp = null;
 46         try {
 47             ClhsdbLauncher test = new ClhsdbLauncher();
 48 
 49             theApp = new LingeredAppWithLock();
 50             LingeredApp.startApp(theApp);
 51             System.out.println("Started LingeredApp with pid " + theApp.getPid());
 52 
 53             // Run the 'jstack -v' command to get the address of a Method*,
 54             // the oop address of a java.lang.ref.ReferenceQueue$Lock
 55             // and the oop address of a java.lang.Class object
 56             List<String> cmds = List.of("jstack -v");
 57 
 58             String jstackOutput = test.run(theApp.getPid(), cmds, null, null);
 59 
 60             // the key is a literal, searched in the jstack output; the value is a regex searched in the clhsdb output
 61             Map<String, String> tokensMap = new HashMap<>();
 62             tokensMap.put("(a java.lang.Class for LingeredAppWithLock)",
 63                           "instance of Oop for java/lang/Class");
 64             tokensMap.put("Method*=", "Type is Method");
 65             tokensMap.put("(a java/util/concurrent/locks/AbstractQueuedSynchronizer$ConditionObject)",
 66                           "instance of Oop for java/util/concurrent/locks/AbstractQueuedSynchronizer\\$ConditionObject");
 67             
 68             // System.out.println("======>>>>>\n" + jstackOutput + "\n<<<<<========");
 69 
 70             String[] lines = jstackOutput.split("\\R");
 71 
 72             for (String key: tokensMap.keySet()) {
 73                 cmds = new ArrayList<String>();
 74                 Map<String, List<String>> expStrMap = new HashMap<>();
 75 
 76                 String addressString = null;
 77                 for (String line : lines) {
 78                     if (line.contains(key)) {
 79                         // Escape the token "Method*=" because the split method uses
 80                         // a regex, not just a straight String.
 81                         String escapedKey = key.replace("*","\\*");
 82                         String[] words = line.split(escapedKey+"|[ ]");
 83                         for (String word : words) {
 84                             word = word.replace("<","").replace(">","");
 85                             if (word.startsWith("0x")) {
 86                                 addressString = word;
 87                                 break;
 88                             }
 89                         }
 90                         if (addressString != null)
 91                             break;
 92                       }
 93                   }
 94 
 95                 if (addressString == null) throw new NullPointerException("Token '" + key + "' not found in jstack output");
 96                 String cmd = "inspect " + addressString;
 97                 cmds.add(cmd);
 98                 expStrMap.put(cmd, List.of(tokensMap.get(key)));
 99                 test.run(theApp.getPid(), cmds, expStrMap, null);
100             }
101 
102             // This part is testing JDK-8261269. When inspecting a java object, we want to make
103             // sure the address is not printed twice and that "Oop for ..." is not printed twice.
104             //
105             // The goal of this test is to dump the Class instance for java.lang.System. It contains
106             // some Oop statics, and that's where the redundant "Oop for..." was noticed. The script
107             // looks something like this:
108             //
109             // hsdb> class java.lang.System
110             // java/lang/System @0x000000080000f388
111             //
112             // hsdb> inspect 0x000000080000f388
113             // Type is InstanceKlass (size of 480)
114             // ...
115             // OopHandle Klass::_java_mirror: OopHandle @ 0x000000080000f400
< prev index next >