changeset 8159:3dcebb19e38e

Add module id to stack traces and thread dumps
author sla
date Tue, 31 Mar 2015 13:28:26 +0200
parents 85b392d69c83
children bbc6dfd8f329
files src/share/vm/classfile/javaClasses.cpp src/share/vm/classfile/javaClasses.hpp src/share/vm/runtime/frame.cpp
diffstat 3 files changed, 61 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/classfile/javaClasses.cpp	Mon Mar 30 16:20:06 2015 -0400
+++ b/src/share/vm/classfile/javaClasses.cpp	Tue Mar 31 13:28:26 2015 +0200
@@ -1519,28 +1519,42 @@
     }
   }
 
+  char *module_name = NULL, *module_version = NULL;
+  ModuleEntry* module = holder->module();
+  if (module != NULL) {
+    module_name = module->name()->as_C_string();
+    buf_len += (int)strlen(module_name);
+    module_version = module->version()->as_C_string();
+    buf_len += (int)strlen(module_version);
+  }
+
   // Allocate temporary buffer with extra space for formatting and line number
   char* buf = NEW_RESOURCE_ARRAY(char, buf_len + 64);
 
   // Print stack trace line in buffer
-  sprintf(buf, "\tat %s.%s", klass_name, method_name);
+  sprintf(buf, "\tat %s.%s(", klass_name, method_name);
+
+  // Print module information
+  if (module_name != NULL) {
+    sprintf(buf + (int)strlen(buf), "%s@%s/", module_name, module_version);
+  }
 
   if (!version_matches(method, version)) {
-    strcat(buf, "(Redefined)");
+    strcat(buf, "Redefined)");
   } else {
     int line_number = get_line_number(method, bci);
     if (line_number == -2) {
-      strcat(buf, "(Native Method)");
+      strcat(buf, "Native Method)");
     } else {
       if (source_file_name != NULL && (line_number != -1)) {
         // Sourcename and linenumber
-        sprintf(buf + (int)strlen(buf), "(%s:%d)", source_file_name, line_number);
+        sprintf(buf + (int)strlen(buf), "%s:%d)", source_file_name, line_number);
       } else if (source_file_name != NULL) {
         // Just sourcename
-        sprintf(buf + (int)strlen(buf), "(%s)", source_file_name);
+        sprintf(buf + (int)strlen(buf), "%s)", source_file_name);
       } else {
         // Neither sourcename nor linenumber
-        sprintf(buf + (int)strlen(buf), "(Unknown Source)");
+        sprintf(buf + (int)strlen(buf), "Unknown Source)");
       }
       nmethod* nm = method->code();
       if (WizardMode && nm != NULL) {
@@ -1926,6 +1940,16 @@
   oop methodname = StringTable::intern(method->name(), CHECK_0);
   java_lang_StackTraceElement::set_methodName(element(), methodname);
 
+  // Fill in module name
+  ModuleEntry* module = holder->module();
+  if (module != NULL) {
+    int len = module->name()->utf8_length() + module->version()->utf8_length() + 1 + 1;
+    char* buf = NEW_RESOURCE_ARRAY(char, len);
+    jio_snprintf(buf, len, "%s@%s", module->name()->as_utf8(), module->version()->as_utf8());
+    oop module_id = StringTable::intern(buf, CHECK_0);
+    java_lang_StackTraceElement::set_moduleId(element(), module_id);
+  }
+
   if (!version_matches(method, version)) {
     // The method was redefined, accurate line number information isn't available
     java_lang_StackTraceElement::set_fileName(element(), NULL);
@@ -3313,6 +3337,7 @@
 int java_lang_StackTraceElement::methodName_offset;
 int java_lang_StackTraceElement::fileName_offset;
 int java_lang_StackTraceElement::lineNumber_offset;
+int java_lang_StackTraceElement::moduleId_offset;
 int java_lang_AssertionStatusDirectives::classes_offset;
 int java_lang_AssertionStatusDirectives::classEnabled_offset;
 int java_lang_AssertionStatusDirectives::packages_offset;
@@ -3342,6 +3367,10 @@
   element->int_field_put(lineNumber_offset, value);
 }
 
+void java_lang_StackTraceElement::set_moduleId(oop element, oop value) {
+  element->obj_field_put(moduleId_offset, value);
+}
+
 
 // Support for java Assertions - java_lang_AssertionStatusDirectives.
 
@@ -3436,6 +3465,7 @@
   java_lang_System::static_security_offset = java_lang_System::hc_static_security_offset * x;
 
   // java_lang_StackTraceElement
+  java_lang_StackTraceElement::moduleId_offset = java_lang_StackTraceElement::hc_moduleId_offset * x + header;
   java_lang_StackTraceElement::declaringClass_offset = java_lang_StackTraceElement::hc_declaringClass_offset  * x + header;
   java_lang_StackTraceElement::methodName_offset = java_lang_StackTraceElement::hc_methodName_offset * x + header;
   java_lang_StackTraceElement::fileName_offset   = java_lang_StackTraceElement::hc_fileName_offset   * x + header;
--- a/src/share/vm/classfile/javaClasses.hpp	Mon Mar 30 16:20:06 2015 -0400
+++ b/src/share/vm/classfile/javaClasses.hpp	Tue Mar 31 13:28:26 2015 +0200
@@ -1331,12 +1331,14 @@
 class java_lang_StackTraceElement: AllStatic {
  private:
   enum {
-    hc_declaringClass_offset  = 0,
-    hc_methodName_offset = 1,
-    hc_fileName_offset   = 2,
-    hc_lineNumber_offset = 3
+    hc_moduleId_offset = 0,
+    hc_declaringClass_offset = 1,
+    hc_methodName_offset = 2,
+    hc_fileName_offset   = 3,
+    hc_lineNumber_offset = 4
   };
 
+  static int moduleId_offset;
   static int declaringClass_offset;
   static int methodName_offset;
   static int fileName_offset;
@@ -1344,6 +1346,7 @@
 
  public:
   // Setters
+  static void set_moduleId(oop element, oop value);
   static void set_declaringClass(oop element, oop value);
   static void set_methodName(oop element, oop value);
   static void set_fileName(oop element, oop value);
--- a/src/share/vm/runtime/frame.cpp	Mon Mar 30 16:20:06 2015 -0400
+++ b/src/share/vm/runtime/frame.cpp	Tue Mar 31 13:28:26 2015 +0200
@@ -644,6 +644,13 @@
         m->name_and_sig_as_C_string(buf, buflen);
         st->print("j  %s", buf);
         st->print("+%d", this->interpreter_frame_bci());
+        ModuleEntry* module = m->method_holder()->module();
+        if (module != NULL) {
+          module->name()->as_C_string(buf, buflen);
+          st->print(" %s", buf);
+          module->version()->as_C_string(buf, buflen);
+          st->print("@%s", buf);
+        }
       } else {
         st->print("j  " PTR_FORMAT, pc());
       }
@@ -661,10 +668,19 @@
       Method* m = nm->method();
       if (m != NULL) {
         m->name_and_sig_as_C_string(buf, buflen);
-        st->print("J %d%s %s %s (%d bytes) @ " PTR_FORMAT " [" PTR_FORMAT "+0x%x]",
+        st->print("J %d%s %s %s",
                   nm->compile_id(), (nm->is_osr_method() ? "%" : ""),
                   ((nm->compiler() != NULL) ? nm->compiler()->name() : ""),
-                  buf, m->code_size(), _pc, _cb->code_begin(), _pc - _cb->code_begin());
+                  buf);
+        ModuleEntry* module = m->method_holder()->module();
+        if (module != NULL) {
+          module->name()->as_C_string(buf, buflen);
+          st->print(" %s", buf);
+          module->version()->as_C_string(buf, buflen);
+          st->print("@%s", buf);
+        }
+        st->print(" (%d bytes) @ " PTR_FORMAT " [" PTR_FORMAT "+0x%x]",
+                  m->code_size(), _pc, _cb->code_begin(), _pc - _cb->code_begin());
       } else {
         st->print("J  " PTR_FORMAT, pc());
       }