8048933: -XX:+TraceExceptions output should include the message

Wed, 09 Jul 2014 22:37:48 -0400

author
coleenp
date
Wed, 09 Jul 2014 22:37:48 -0400
changeset 9970
f614bd5c9561
parent 9969
40f45911050f
child 9971
414c1dcfc3f3
child 9973
a06d5e5fe5e0

8048933: -XX:+TraceExceptions output should include the message
Summary: Add the exception detail message to the tracing output
Reviewed-by: minqi, dholmes

src/share/vm/classfile/javaClasses.cpp file | annotate | diff | comparison | revisions
src/share/vm/classfile/javaClasses.hpp file | annotate | diff | comparison | revisions
src/share/vm/interpreter/interpreterRuntime.cpp file | annotate | diff | comparison | revisions
src/share/vm/oops/constantPool.cpp file | annotate | diff | comparison | revisions
test/runtime/CommandLine/TraceExceptionsTest.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/classfile/javaClasses.cpp	Thu Aug 25 09:23:45 2016 -0400
     1.2 +++ b/src/share/vm/classfile/javaClasses.cpp	Wed Jul 09 22:37:48 2014 -0400
     1.3 @@ -1235,6 +1235,16 @@
     1.4  }
     1.5  
     1.6  
     1.7 +// Return Symbol for detailed_message or NULL
     1.8 +Symbol* java_lang_Throwable::detail_message(oop throwable) {
     1.9 +  PRESERVE_EXCEPTION_MARK;  // Keep original exception
    1.10 +  oop detailed_message = java_lang_Throwable::message(throwable);
    1.11 +  if (detailed_message != NULL) {
    1.12 +    return java_lang_String::as_symbol(detailed_message, THREAD);
    1.13 +  }
    1.14 +  return NULL;
    1.15 +}
    1.16 +
    1.17  void java_lang_Throwable::set_message(oop throwable, oop value) {
    1.18    throwable->obj_field_put(detailMessage_offset, value);
    1.19  }
     2.1 --- a/src/share/vm/classfile/javaClasses.hpp	Thu Aug 25 09:23:45 2016 -0400
     2.2 +++ b/src/share/vm/classfile/javaClasses.hpp	Wed Jul 09 22:37:48 2014 -0400
     2.3 @@ -518,6 +518,7 @@
     2.4    static oop message(oop throwable);
     2.5    static oop message(Handle throwable);
     2.6    static void set_message(oop throwable, oop value);
     2.7 +  static Symbol* detail_message(oop throwable);
     2.8    static void print_stack_element(outputStream *st, Handle mirror, int method,
     2.9                                    int version, int bci, int cpref);
    2.10    static void print_stack_element(outputStream *st, methodHandle method, int bci);
     3.1 --- a/src/share/vm/interpreter/interpreterRuntime.cpp	Thu Aug 25 09:23:45 2016 -0400
     3.2 +++ b/src/share/vm/interpreter/interpreterRuntime.cpp	Wed Jul 09 22:37:48 2014 -0400
     3.3 @@ -447,9 +447,18 @@
     3.4  
     3.5      // tracing
     3.6      if (TraceExceptions) {
     3.7 -      ttyLocker ttyl;
     3.8        ResourceMark rm(thread);
     3.9 -      tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")", h_exception->print_value_string(), (address)h_exception());
    3.10 +      Symbol* message = java_lang_Throwable::detail_message(h_exception());
    3.11 +      ttyLocker ttyl;  // Lock after getting the detail message
    3.12 +      if (message != NULL) {
    3.13 +        tty->print_cr("Exception <%s: %s> (" INTPTR_FORMAT ")",
    3.14 +                      h_exception->print_value_string(), message->as_C_string(),
    3.15 +                      (address)h_exception());
    3.16 +      } else {
    3.17 +        tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")",
    3.18 +                      h_exception->print_value_string(),
    3.19 +                      (address)h_exception());
    3.20 +      }
    3.21        tty->print_cr(" thrown in interpreter method <%s>", h_method->print_value_string());
    3.22        tty->print_cr(" at bci %d for thread " INTPTR_FORMAT, current_bci, thread);
    3.23      }
     4.1 --- a/src/share/vm/oops/constantPool.cpp	Thu Aug 25 09:23:45 2016 -0400
     4.2 +++ b/src/share/vm/oops/constantPool.cpp	Wed Jul 09 22:37:48 2014 -0400
     4.3 @@ -571,13 +571,9 @@
     4.4  
     4.5  Symbol* ConstantPool::exception_message(constantPoolHandle this_oop, int which, constantTag tag, oop pending_exception) {
     4.6    // Dig out the detailed message to reuse if possible
     4.7 -  Symbol* message = NULL;
     4.8 -  oop detailed_message = java_lang_Throwable::message(pending_exception);
     4.9 -  if (detailed_message != NULL) {
    4.10 -     message = java_lang_String::as_symbol_or_null(detailed_message);
    4.11 -     if (message != NULL) {
    4.12 -       return message;
    4.13 -     }
    4.14 +  Symbol* message = java_lang_Throwable::detail_message(pending_exception);
    4.15 +  if (message != NULL) {
    4.16 +    return message;
    4.17    }
    4.18  
    4.19    // Return specific message for the tag
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/runtime/CommandLine/TraceExceptionsTest.java	Wed Jul 09 22:37:48 2014 -0400
     5.3 @@ -0,0 +1,48 @@
     5.4 +/*
     5.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5.7 + *
     5.8 + * This code is free software; you can redistribute it and/or modify it
     5.9 + * under the terms of the GNU General Public License version 2 only, as
    5.10 + * published by the Free Software Foundation.
    5.11 + *
    5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    5.14 + * FITNESS FOR A PARTICULAR PURPOSE.    See the GNU General Public License
    5.15 + * version 2 for more details (a copy is included in the LICENSE file that
    5.16 + * accompanied this code).
    5.17 + *
    5.18 + * You should have received a copy of the GNU General Public License version
    5.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    5.21 + *
    5.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    5.23 + * or visit www.oracle.com if you need additional information or have any
    5.24 + * questions.
    5.25 + */
    5.26 +
    5.27 +/*
    5.28 + * @test
    5.29 + * @bug 8048933
    5.30 + * @summary TraceExceptions output should have the exception message - useful for ClassNotFoundExceptions especially
    5.31 + * @library /testlibrary
    5.32 + */
    5.33 +
    5.34 +import com.oracle.java.testlibrary.*;
    5.35 +
    5.36 +public class TraceExceptionsTest {
    5.37 +    public static void main(String[] args) throws Exception {
    5.38 +
    5.39 +        if (!Platform.isDebugBuild()) {
    5.40 +          System.out.println("Skip the test on product builds since XX:+TraceExceptions is not available on product builds");
    5.41 +          return;
    5.42 +        }
    5.43 +
    5.44 +        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
    5.45 +            "-XX:+TraceExceptions", "NoClassFound");
    5.46 +        OutputAnalyzer output = new OutputAnalyzer(pb.start());
    5.47 +        output.shouldContain("<a 'java/lang/ClassNotFoundException': NoClassFound>");
    5.48 +        output.shouldNotContain("<a 'java/lang/ClassNotFoundException'>");
    5.49 +        output.shouldHaveExitValue(1);
    5.50 +    }
    5.51 +}

mercurial