8156133: FindCrashesAction in HSDB does not work except Solaris platform
authorysuenaga
Fri, 06 May 2016 09:13:31 +0900
changeset 38266 aa3dbc37ede9
parent 38262 8e814475a28a
child 38267 29feb145a316
8156133: FindCrashesAction in HSDB does not work except Solaris platform Reviewed-by: dsamersoff
hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/JavaThreadsPanel.java
hotspot/src/share/vm/runtime/vmStructs.cpp
hotspot/src/share/vm/utilities/vmError.hpp
--- a/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/JavaThreadsPanel.java	Tue May 10 03:37:36 2016 +0000
+++ b/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/JavaThreadsPanel.java	Fri May 06 09:13:31 2016 +0900
@@ -39,6 +39,7 @@
 
 import sun.jvm.hotspot.debugger.*;
 import sun.jvm.hotspot.runtime.*;
+import sun.jvm.hotspot.types.*;
 
 import sun.jvm.hotspot.ui.action.*;
 
@@ -55,8 +56,18 @@
     private JavaThreadsTableModel dataModel;
     private StatusBar statusBar;
     private JTable     threadTable;
-    private java.util.List cachedThreads = new ArrayList();
+    private java.util.List<CachedThread> cachedThreads = new ArrayList();
+    private static AddressField crashThread;
+
 
+    static {
+        VM.registerVMInitializedObserver(
+                            (o, a) -> initialize(VM.getVM().getTypeDataBase()));
+    }
+
+    private static void initialize(TypeDataBase db) {
+        crashThread = db.lookupType("VMError").getAddressField("_thread");
+    }
 
     /** Constructor assumes the threads panel is created while the VM is
         suspended. Subsequent resume and suspend operations of the VM
@@ -437,21 +448,14 @@
      * @return a flag which indicates if crashes were encountered.
      */
     private boolean fireShowThreadCrashes() {
-        boolean crash = false;
-        for (Iterator iter = cachedThreads.iterator(); iter.hasNext(); ) {
-            JavaThread t = (JavaThread) ((CachedThread) iter.next()).getThread();
-            sun.jvm.hotspot.runtime.Frame tmpFrame = t.getCurrentFrameGuess();
-            RegisterMap tmpMap = t.newRegisterMap(false);
-            while ((tmpFrame != null) && (!tmpFrame.isFirstFrame())) {
-                if (tmpFrame.isSignalHandlerFrameDbg()) {
-                    showThreadStackMemory(t);
-                    crash = true;
-                    break;
-                }
-                tmpFrame = tmpFrame.sender(tmpMap);
-            }
-        }
-        return crash;
+        Optional<JavaThread> crashed =
+                         cachedThreads.stream()
+                                      .map(t -> t.getThread())
+                                      .filter(t -> t.getAddress().equals(
+                                                        crashThread.getValue()))
+                                      .findAny();
+        crashed.ifPresent(this::showThreadStackMemory);
+        return crashed.isPresent();
     }
 
     private void cache() {
--- a/hotspot/src/share/vm/runtime/vmStructs.cpp	Tue May 10 03:37:36 2016 +0000
+++ b/hotspot/src/share/vm/runtime/vmStructs.cpp	Fri May 06 09:13:31 2016 +0900
@@ -1365,6 +1365,12 @@
      static_field(java_lang_Class,             _oop_size_offset,                              int)                                   \
      static_field(java_lang_Class,             _static_oop_field_count_offset,                int)                                   \
                                                                                                                                      \
+  /******************/                                                                                                               \
+  /* VMError fields */                                                                                                               \
+  /******************/                                                                                                               \
+                                                                                                                                     \
+     static_field(VMError,                     _thread,                                       Thread*)                               \
+                                                                                                                                     \
   /************************/                                                                                                         \
   /* Miscellaneous fields */                                                                                                         \
   /************************/                                                                                                         \
@@ -2215,6 +2221,12 @@
                                                                           \
   declare_toplevel_type(Arguments)                                        \
                                                                           \
+  /***********/                                                           \
+  /* VMError */                                                           \
+  /***********/                                                           \
+                                                                          \
+  declare_toplevel_type(VMError)                                          \
+                                                                          \
   /***************/                                                       \
   /* Other types */                                                       \
   /***************/                                                       \
--- a/hotspot/src/share/vm/utilities/vmError.hpp	Tue May 10 03:37:36 2016 +0000
+++ b/hotspot/src/share/vm/utilities/vmError.hpp	Fri May 06 09:13:31 2016 +0900
@@ -33,6 +33,7 @@
 class VMError : public AllStatic {
   friend class VM_ReportJavaOutOfMemory;
   friend class Decoder;
+  friend class VMStructs;
 
   static int         _id;               // Solaris/Linux signals: 0 - SIGRTMAX
                                         // Windows exceptions: 0xCxxxxxxx system errors