8029395: SA: jstack throws WrongTypeException
authorsla
Wed, 04 Dec 2013 14:43:50 +0100
changeset 22216 888245fbd0a5
parent 22215 579f4a1a4aa6
child 22217 163b4d58a6f2
8029395: SA: jstack throws WrongTypeException Summary: SA missed some TLABs Reviewed-by: dsamersoff, mgerdin, brutisso
hotspot/agent/src/share/classes/sun/jvm/hotspot/oops/ObjectHeap.java
hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/ThreadLocalAllocBuffer.java
--- a/hotspot/agent/src/share/classes/sun/jvm/hotspot/oops/ObjectHeap.java	Wed Dec 04 08:10:31 2013 -0500
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/oops/ObjectHeap.java	Wed Dec 04 14:43:50 2013 +0100
@@ -364,7 +364,7 @@
       }
       catch (AddressException e) {
         // This is okay at the top of these regions
-      }
+          }
       catch (UnknownOopException e) {
         // This is okay at the top of these regions
       }
@@ -373,7 +373,7 @@
     visitor.epilogue();
   }
 
-  private void addLiveRegions(List input, List output) {
+  private void addLiveRegions(String name, List input, List output) {
      for (Iterator itr = input.iterator(); itr.hasNext();) {
         MemRegion reg = (MemRegion) itr.next();
         Address top = reg.end();
@@ -386,6 +386,9 @@
         }
         output.add(top);
         output.add(bottom);
+        if (DEBUG) {
+          System.err.println("Live region: " + name + ": " + bottom + ", " + top);
+        }
      }
   }
 
@@ -395,7 +398,7 @@
      }
 
      public void doSpace(Space s) {
-        addLiveRegions(s.getLiveRegions(), liveRegions);
+        addLiveRegions(s.toString(), s.getLiveRegions(), liveRegions);
      }
      private List liveRegions;
   }
@@ -426,11 +429,11 @@
        ParallelScavengeHeap psh = (ParallelScavengeHeap) heap;
        PSYoungGen youngGen = psh.youngGen();
        // Add eden space
-       addLiveRegions(youngGen.edenSpace().getLiveRegions(), liveRegions);
+       addLiveRegions("eden", youngGen.edenSpace().getLiveRegions(), liveRegions);
        // Add from-space but not to-space
-       addLiveRegions(youngGen.fromSpace().getLiveRegions(), liveRegions);
+       addLiveRegions("from", youngGen.fromSpace().getLiveRegions(), liveRegions);
        PSOldGen oldGen = psh.oldGen();
-       addLiveRegions(oldGen.objectSpace().getLiveRegions(), liveRegions);
+       addLiveRegions("old ", oldGen.objectSpace().getLiveRegions(), liveRegions);
     } else if (heap instanceof G1CollectedHeap) {
         G1CollectedHeap g1h = (G1CollectedHeap) heap;
         g1h.heapRegionIterate(lrc);
@@ -451,23 +454,27 @@
 
     if (VM.getVM().getUseTLAB()) {
       for (JavaThread thread = VM.getVM().getThreads().first(); thread != null; thread = thread.next()) {
-        if (thread.isJavaThread()) {
-          ThreadLocalAllocBuffer tlab = thread.tlab();
-          if (tlab.start() != null) {
-            if ((tlab.top() == null) || (tlab.end() == null)) {
-              System.err.print("Warning: skipping invalid TLAB for thread ");
+        ThreadLocalAllocBuffer tlab = thread.tlab();
+        if (tlab.start() != null) {
+          if ((tlab.top() == null) || (tlab.end() == null)) {
+            System.err.print("Warning: skipping invalid TLAB for thread ");
+            thread.printThreadIDOn(System.err);
+            System.err.println();
+          } else {
+            if (DEBUG) {
+              System.err.print("TLAB for " + thread.getThreadName() + ", #");
               thread.printThreadIDOn(System.err);
-              System.err.println();
-            } else {
-              // Go from:
-              //  - below start() to start()
-              //  - start() to top()
-              //  - end() and above
-              liveRegions.add(tlab.start());
-              liveRegions.add(tlab.start());
-              liveRegions.add(tlab.top());
-              liveRegions.add(tlab.hardEnd());
+              System.err.print(": ");
+              tlab.printOn(System.err);
             }
+            // Go from:
+            //  - below start() to start()
+            //  - start() to top()
+            //  - end() and above
+            liveRegions.add(tlab.start());
+            liveRegions.add(tlab.start());
+            liveRegions.add(tlab.top());
+            liveRegions.add(tlab.hardEnd());
           }
         }
       }
@@ -480,6 +487,15 @@
       Assert.that(liveRegions.size() % 2 == 0, "Must have even number of region boundaries");
     }
 
+    if (DEBUG) {
+      System.err.println("liveRegions:");
+      for (int i = 0; i < liveRegions.size(); i += 2) {
+          Address bottom = (Address) liveRegions.get(i);
+          Address top    = (Address) liveRegions.get(i+1);
+          System.err.println(" " + bottom + " - " + top);
+      }
+    }
+
     return liveRegions;
   }
 
--- a/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/ThreadLocalAllocBuffer.java	Wed Dec 04 08:10:31 2013 -0500
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/ThreadLocalAllocBuffer.java	Wed Dec 04 14:43:50 2013 +0100
@@ -109,6 +109,6 @@
 
   public void printOn(PrintStream tty) {
     tty.println(" [" + start() + "," +
-                top() + "," + end() + ")");
+                top() + "," + end() + ",{" + hardEnd() + "})");
   }
 }