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

Add the exception detail message to the tracing output

Reviewed-by: minqi, dholmes
This commit is contained in:
Coleen Phillimore 2014-07-09 22:37:48 -04:00
parent 440ffd13d6
commit 06cea98803
5 changed files with 73 additions and 9 deletions

View file

@ -1239,6 +1239,16 @@ oop java_lang_Throwable::message(Handle throwable) {
} }
// 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) { void java_lang_Throwable::set_message(oop throwable, oop value) {
throwable->obj_field_put(detailMessage_offset, value); throwable->obj_field_put(detailMessage_offset, value);
} }

View file

@ -520,6 +520,7 @@ class java_lang_Throwable: AllStatic {
static oop message(oop throwable); static oop message(oop throwable);
static oop message(Handle throwable); static oop message(Handle throwable);
static void set_message(oop throwable, oop value); 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, static void print_stack_element(outputStream *st, Handle mirror, int method,
int version, int bci); int version, int bci);
static void print_stack_element(outputStream *st, methodHandle method, int bci); static void print_stack_element(outputStream *st, methodHandle method, int bci);

View file

@ -430,9 +430,18 @@ IRT_ENTRY(address, InterpreterRuntime::exception_handler_for_exception(JavaThrea
// tracing // tracing
if (TraceExceptions) { if (TraceExceptions) {
ttyLocker ttyl;
ResourceMark rm(thread); 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(" thrown in interpreter method <%s>", h_method->print_value_string());
tty->print_cr(" at bci %d for thread " INTPTR_FORMAT, current_bci, thread); tty->print_cr(" at bci %d for thread " INTPTR_FORMAT, current_bci, thread);
} }

View file

@ -520,13 +520,9 @@ bool ConstantPool::resolve_class_constants(TRAPS) {
Symbol* ConstantPool::exception_message(constantPoolHandle this_cp, int which, constantTag tag, oop pending_exception) { Symbol* ConstantPool::exception_message(constantPoolHandle this_cp, int which, constantTag tag, oop pending_exception) {
// Dig out the detailed message to reuse if possible // Dig out the detailed message to reuse if possible
Symbol* message = NULL; Symbol* message = java_lang_Throwable::detail_message(pending_exception);
oop detailed_message = java_lang_Throwable::message(pending_exception); if (message != NULL) {
if (detailed_message != NULL) { return message;
message = java_lang_String::as_symbol_or_null(detailed_message);
if (message != NULL) {
return message;
}
} }
// Return specific message for the tag // Return specific message for the tag

View file

@ -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);
}
}