8147447: serviceability/tmtools/jstack/WaitNotifyThreadTest.java test fails
authorakulyakh
Thu, 28 Jan 2016 14:58:57 +0300
changeset 35874 6c93eabea7c2
parent 35873 96fb98b25b13
child 35876 b5e595dbaa55
child 35879 9892f53e92c9
8147447: serviceability/tmtools/jstack/WaitNotifyThreadTest.java test fails Summary: corrected verification of the jstack object references Reviewed-by: sla
hotspot/test/serviceability/tmtools/jstack/WaitNotifyThreadTest.java
hotspot/test/serviceability/tmtools/jstack/utils/DefaultFormat.java
--- a/hotspot/test/serviceability/tmtools/jstack/WaitNotifyThreadTest.java	Thu Jan 28 10:18:45 2016 +0100
+++ b/hotspot/test/serviceability/tmtools/jstack/WaitNotifyThreadTest.java	Thu Jan 28 14:58:57 2016 +0300
@@ -88,6 +88,7 @@
     }
 
     private void doTest() throws Exception {
+
         // Verify stack trace consistency when notifying the thread
         doTest(new ActionNotify());
 
@@ -134,8 +135,7 @@
             if (mi.getName().startsWith(OBJECT_WAIT) && mi.getCompilationUnit() == null /*native method*/) {
                 if (mi.getLocks().size() == 1) {
                     MonitorInfo monInfo = mi.getLocks().getFirst();
-                    if (monInfo.getType().equals("waiting on")
-                            && monInfo.getMonitorClass().equals(OBJECT)) {
+                    if (monInfo.getType().equals("waiting on") && compareMonitorClass(monInfo)) {
                         monitorAddress = monInfo.getMonitorAddress();
                     } else {
                         System.err.println("Error: incorrect monitor info: " + monInfo.getType() + ", " + monInfo.getMonitorClass());
@@ -166,7 +166,7 @@
 
     private void assertMonitorInfo(String expectedMessage, MonitorInfo monInfo, String monitorAddress) {
         if (monInfo.getType().equals(expectedMessage)
-                && monInfo.getMonitorClass().equals(OBJECT + "11")
+                && compareMonitorClass(monInfo)
                 && monInfo.getMonitorAddress().equals(
                         monitorAddress)) {
             System.out.println("Correct monitor info found");
@@ -177,6 +177,13 @@
         }
     }
 
+    private boolean compareMonitorClass(MonitorInfo monInfo) {
+        // If monitor class info is present in the jstack output
+        // then compare it with the class of the actual monitor object
+        // If there is no monitor class info available then return true
+        return OBJECT.equals(monInfo.getMonitorClass()) || (monInfo.getMonitorClass() == null);
+    }
+
     private void analyzeThreadStackNoWaiting(ThreadStack ti2) {
         Iterator<MethodInfo> it = ti2.getStack().iterator();
 
--- a/hotspot/test/serviceability/tmtools/jstack/utils/DefaultFormat.java	Thu Jan 28 10:18:45 2016 +0100
+++ b/hotspot/test/serviceability/tmtools/jstack/utils/DefaultFormat.java	Thu Jan 28 14:58:57 2016 +0300
@@ -70,10 +70,18 @@
         return "^JNI\\sglobal\\sreferences:\\s((.+))$";
     }
 
+    // Sample string that matches the pattern:
+    // waiting on <0x000000008f64e6d0> (a java.lang.Object)
     protected String monitorInfoPattern() {
         return "^\\s+\\-\\s(locked|waiting\\son|waiting\\sto\\slock)\\s\\<(.*)\\>\\s\\(((.*))\\)$";
     }
 
+    // Sample string that matches the pattern:
+    // waiting on <no object reference available>
+    protected String monitorInfoNoObjectRefPattern() {
+        return "^\\s+\\-\\s(locked|waiting\\son|waiting\\sto\\slock)\\s\\<(.*)\\>$";
+    }
+
     protected String vmVersionInfoPattern() {
         return "Full\\sthread\\sdump\\s.*";
     }
@@ -100,7 +108,10 @@
                     currentMethodInfo = parseMethodInfo(line);
                     currentThreadStack.addMethod(currentMethodInfo);
                 } else if (line.matches(monitorInfoPattern())) {
-                    MonitorInfo mi = parseMonitorInfo(line);
+                    MonitorInfo mi = parseMonitorInfo(line, monitorInfoPattern());
+                    currentMethodInfo.getLocks().add(mi);
+                } else if (line.matches(monitorInfoNoObjectRefPattern())) {
+                    MonitorInfo mi = parseMonitorInfo(line, monitorInfoNoObjectRefPattern());
                     currentMethodInfo.getLocks().add(mi);
                 } else if (line.matches(extendedStatusPattern())) {
                     currentThreadStack.setExtendedStatus(parseExtendedStatus(line));
@@ -125,16 +136,17 @@
         return result;
     }
 
-    private MonitorInfo parseMonitorInfo(String line) {
+    private MonitorInfo parseMonitorInfo(String line, String pattern) {
         Scanner s = new Scanner(line);
-        s.findInLine(monitorInfoPattern());
+        s.findInLine(pattern);
         MonitorInfo mi = new MonitorInfo();
         MatchResult res = s.match();
 
         mi.setType(res.group(1));
         mi.setMonitorAddress(res.group(2));
-        mi.setMonitorClass(res.group(3));
-
+        if (res.groupCount() > 2) {
+            mi.setMonitorClass(res.group(3));
+        }
         return mi;
     }