mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
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:
parent
440ffd13d6
commit
06cea98803
5 changed files with 73 additions and 9 deletions
|
@ -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) {
|
||||
throwable->obj_field_put(detailMessage_offset, value);
|
||||
}
|
||||
|
|
|
@ -520,6 +520,7 @@ class java_lang_Throwable: AllStatic {
|
|||
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);
|
||||
|
|
|
@ -430,9 +430,18 @@ IRT_ENTRY(address, InterpreterRuntime::exception_handler_for_exception(JavaThrea
|
|||
|
||||
// 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);
|
||||
}
|
||||
|
|
|
@ -520,14 +520,10 @@ bool ConstantPool::resolve_class_constants(TRAPS) {
|
|||
|
||||
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);
|
||||
Symbol* message = java_lang_Throwable::detail_message(pending_exception);
|
||||
if (message != NULL) {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
// Return specific message for the tag
|
||||
switch (tag.value()) {
|
||||
|
|
48
hotspot/test/runtime/CommandLine/TraceExceptionsTest.java
Normal file
48
hotspot/test/runtime/CommandLine/TraceExceptionsTest.java
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue