changeset 6758:bf4629bb1ad6

8048933: -XX:+TraceExceptions output should include the message Summary: Add the exception detail message to the tracing output Reviewed-by: minqi, dholmes
author coleenp
date Wed, 09 Jul 2014 22:37:48 -0400
parents 29b4f4e94ad7
children fb27a4c9ad54
files src/share/vm/classfile/javaClasses.cpp src/share/vm/classfile/javaClasses.hpp src/share/vm/interpreter/interpreterRuntime.cpp src/share/vm/oops/constantPool.cpp test/runtime/CommandLine/TraceExceptionsTest.java
diffstat 5 files changed, 73 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/classfile/javaClasses.cpp	Tue Jul 08 13:52:29 2014 -0400
+++ b/src/share/vm/classfile/javaClasses.cpp	Wed Jul 09 22:37:48 2014 -0400
@@ -1239,6 +1239,16 @@
 }
 
 
+// Return Symbol for detailed_message or NULL
+Symbol* java_lang_Throwable::detail_message(oop throwable) {
+  PRESERVE_EXCEPTION_MARK;  // Keep original exception
+  oop detailed_message = java_lang_Throwable::message(throwable);
+  if (detailed_message != NULL) {
+    return java_lang_String::as_symbol(detailed_message, THREAD);
+  }
+  return NULL;
+}
+
 void java_lang_Throwable::set_message(oop throwable, oop value) {
   throwable->obj_field_put(detailMessage_offset, value);
 }
--- a/src/share/vm/classfile/javaClasses.hpp	Tue Jul 08 13:52:29 2014 -0400
+++ b/src/share/vm/classfile/javaClasses.hpp	Wed Jul 09 22:37:48 2014 -0400
@@ -520,6 +520,7 @@
   static oop message(oop throwable);
   static oop message(Handle throwable);
   static void set_message(oop throwable, oop value);
+  static Symbol* detail_message(oop throwable);
   static void print_stack_element(outputStream *st, Handle mirror, int method,
                                   int version, int bci);
   static void print_stack_element(outputStream *st, methodHandle method, int bci);
--- a/src/share/vm/interpreter/interpreterRuntime.cpp	Tue Jul 08 13:52:29 2014 -0400
+++ b/src/share/vm/interpreter/interpreterRuntime.cpp	Wed Jul 09 22:37:48 2014 -0400
@@ -430,9 +430,18 @@
 
     // tracing
     if (TraceExceptions) {
-      ttyLocker ttyl;
       ResourceMark rm(thread);
-      tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")", h_exception->print_value_string(), (address)h_exception());
+      Symbol* message = java_lang_Throwable::detail_message(h_exception());
+      ttyLocker ttyl;  // Lock after getting the detail message
+      if (message != NULL) {
+        tty->print_cr("Exception <%s: %s> (" INTPTR_FORMAT ")",
+                      h_exception->print_value_string(), message->as_C_string(),
+                      (address)h_exception());
+      } else {
+        tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")",
+                      h_exception->print_value_string(),
+                      (address)h_exception());
+      }
       tty->print_cr(" thrown in interpreter method <%s>", h_method->print_value_string());
       tty->print_cr(" at bci %d for thread " INTPTR_FORMAT, current_bci, thread);
     }
--- a/src/share/vm/oops/constantPool.cpp	Tue Jul 08 13:52:29 2014 -0400
+++ b/src/share/vm/oops/constantPool.cpp	Wed Jul 09 22:37:48 2014 -0400
@@ -520,13 +520,9 @@
 
 Symbol* ConstantPool::exception_message(constantPoolHandle this_cp, int which, constantTag tag, oop pending_exception) {
   // Dig out the detailed message to reuse if possible
-  Symbol* message = NULL;
-  oop detailed_message = java_lang_Throwable::message(pending_exception);
-  if (detailed_message != NULL) {
-     message = java_lang_String::as_symbol_or_null(detailed_message);
-     if (message != NULL) {
-       return message;
-     }
+  Symbol* message = java_lang_Throwable::detail_message(pending_exception);
+  if (message != NULL) {
+    return message;
   }
 
   // Return specific message for the tag
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/runtime/CommandLine/TraceExceptionsTest.java	Wed Jul 09 22:37:48 2014 -0400
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.    See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8048933
+ * @summary TraceExceptions output should have the exception message - useful for ClassNotFoundExceptions especially
+ * @library /testlibrary
+ */
+
+import com.oracle.java.testlibrary.*;
+
+public class TraceExceptionsTest {
+    public static void main(String[] args) throws Exception {
+
+        if (!Platform.isDebugBuild()) {
+          System.out.println("Skip the test on product builds since XX:+TraceExceptions is not available on product builds");
+          return;
+        }
+
+        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
+            "-XX:+TraceExceptions", "NoClassFound");
+        OutputAnalyzer output = new OutputAnalyzer(pb.start());
+        output.shouldContain("<a 'java/lang/ClassNotFoundException': NoClassFound>");
+        output.shouldNotContain("<a 'java/lang/ClassNotFoundException'>");
+        output.shouldHaveExitValue(1);
+    }
+}