diff --git a/hotspot/src/share/vm/c1/c1_Runtime1.cpp b/hotspot/src/share/vm/c1/c1_Runtime1.cpp index aebc377527..b2bff3809d 100644 --- a/hotspot/src/share/vm/c1/c1_Runtime1.cpp +++ b/hotspot/src/share/vm/c1/c1_Runtime1.cpp @@ -58,6 +58,7 @@ #include "runtime/vframeArray.hpp" #include "utilities/copy.hpp" #include "utilities/events.hpp" +#include "utilities/exceptions.hpp" // Implementation of StubAssembler @@ -536,8 +537,9 @@ JRT_ENTRY_NO_ASYNC(static address, exception_handler_for_pc_helper(JavaThread* t if (TraceExceptions) { ttyLocker ttyl; ResourceMark rm; - tty->print_cr("Exception <%s> (" INTPTR_FORMAT ") thrown in compiled method <%s> at PC " INTPTR_FORMAT " for thread " INTPTR_FORMAT "", - exception->print_value_string(), p2i((address)exception()), nm->method()->print_value_string(), p2i(pc), p2i(thread)); + tty->print_cr("Exception <%.*s> (" INTPTR_FORMAT ") thrown in compiled method <%s> at PC " INTPTR_FORMAT " for thread " INTPTR_FORMAT "", + MAX_LEN, exception->print_value_string(), + p2i((address)exception()), nm->method()->print_value_string(), p2i(pc), p2i(thread)); } // for AbortVMOnException flag NOT_PRODUCT(Exceptions::debug_check_abort(exception)); diff --git a/hotspot/src/share/vm/interpreter/bytecodeInterpreter.cpp b/hotspot/src/share/vm/interpreter/bytecodeInterpreter.cpp index 3a5f31ae73..d9e561555f 100644 --- a/hotspot/src/share/vm/interpreter/bytecodeInterpreter.cpp +++ b/hotspot/src/share/vm/interpreter/bytecodeInterpreter.cpp @@ -2854,7 +2854,9 @@ run: if (TraceExceptions) { ttyLocker ttyl; ResourceMark rm; - tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")", except_oop->print_value_string(), p2i(except_oop())); + tty->print_cr("Exception <%.*s> (" INTPTR_FORMAT ")", + MAX_LEN, except_oop->print_value_string(), + p2i(except_oop())); tty->print_cr(" thrown in interpreter method <%s>", METHOD->print_value_string()); tty->print_cr(" at bci %d, continuing at %d for thread " INTPTR_FORMAT, (int)(istate->bcp() - METHOD->code_base()), @@ -2870,7 +2872,9 @@ run: if (TraceExceptions) { ttyLocker ttyl; ResourceMark rm; - tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")", except_oop->print_value_string(), p2i(except_oop())); + tty->print_cr("Exception <%.*s> (" INTPTR_FORMAT ")", + MAX_LEN, except_oop->print_value_string(), + p2i(except_oop())); tty->print_cr(" thrown in interpreter method <%s>", METHOD->print_value_string()); tty->print_cr(" at bci %d, unwinding for thread " INTPTR_FORMAT, (int)(istate->bcp() - METHOD->code_base()), diff --git a/hotspot/src/share/vm/interpreter/interpreterRuntime.cpp b/hotspot/src/share/vm/interpreter/interpreterRuntime.cpp index cad9d29008..425ad7f463 100644 --- a/hotspot/src/share/vm/interpreter/interpreterRuntime.cpp +++ b/hotspot/src/share/vm/interpreter/interpreterRuntime.cpp @@ -56,6 +56,7 @@ #include "runtime/synchronizer.hpp" #include "runtime/threadCritical.hpp" #include "utilities/events.hpp" +#include "utilities/exceptions.hpp" #ifdef TARGET_ARCH_x86 # include "vm_version_x86.hpp" #endif @@ -454,12 +455,13 @@ IRT_ENTRY(address, InterpreterRuntime::exception_handler_for_exception(JavaThrea const char* detail_message = java_lang_Throwable::message_as_utf8(h_exception()); ttyLocker ttyl; // Lock after getting the detail message if (detail_message != NULL) { - tty->print_cr("Exception <%s: %s> (" INTPTR_FORMAT ")", - h_exception->print_value_string(), detail_message, + tty->print_cr("Exception <%.*s: %.*s> (" INTPTR_FORMAT ")", + MAX_LEN, h_exception->print_value_string(), + MAX_LEN, detail_message, (address)h_exception()); } else { - tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")", - h_exception->print_value_string(), + tty->print_cr("Exception <%.*s> (" INTPTR_FORMAT ")", + MAX_LEN, h_exception->print_value_string(), (address)h_exception()); } tty->print_cr(" thrown in interpreter method <%s>", h_method->print_value_string()); diff --git a/hotspot/src/share/vm/utilities/exceptions.cpp b/hotspot/src/share/vm/utilities/exceptions.cpp index db4a17029f..c2ae600096 100644 --- a/hotspot/src/share/vm/utilities/exceptions.cpp +++ b/hotspot/src/share/vm/utilities/exceptions.cpp @@ -141,10 +141,11 @@ void Exceptions::_throw(Thread* thread, const char* file, int line, Handle h_exc // tracing (do this up front - so it works during boot strapping) if (TraceExceptions) { ttyLocker ttyl; - tty->print_cr("Exception <%s%s%s> (" INTPTR_FORMAT ") \n" + tty->print_cr("Exception <%.*s%s%.*s> (" INTPTR_FORMAT ") \n" "thrown [%s, line %d]\nfor thread " INTPTR_FORMAT, - h_exception->print_value_string(), - message ? ": " : "", message ? message : "", + MAX_LEN, h_exception->print_value_string(), + message ? ": " : "", + MAX_LEN, message ? message : "", (address)h_exception(), file, line, thread); } // for AbortVMOnException flag diff --git a/hotspot/src/share/vm/utilities/exceptions.hpp b/hotspot/src/share/vm/utilities/exceptions.hpp index 7e10f735e9..995c11d4d9 100644 --- a/hotspot/src/share/vm/utilities/exceptions.hpp +++ b/hotspot/src/share/vm/utilities/exceptions.hpp @@ -29,6 +29,9 @@ #include "oops/oopsHierarchy.hpp" #include "utilities/sizes.hpp" +// Limit exception message components to 64K (the same max as Symbols) +#define MAX_LEN 65535 + // This file provides the basic support for exception handling in the VM. // Note: We do not use C++ exceptions to avoid compiler dependencies and // unpredictable performance. diff --git a/hotspot/src/share/vm/utilities/utf8.cpp b/hotspot/src/share/vm/utilities/utf8.cpp index 8c013c9b30..ca60d37dce 100644 --- a/hotspot/src/share/vm/utilities/utf8.cpp +++ b/hotspot/src/share/vm/utilities/utf8.cpp @@ -317,14 +317,16 @@ int UNICODE::utf8_size(jchar c) { } int UNICODE::utf8_length(jchar* base, int length) { - int result = 0; + size_t result = 0; for (int index = 0; index < length; index++) { jchar c = base[index]; - if ((0x0001 <= c) && (c <= 0x007F)) result += 1; - else if (c <= 0x07FF) result += 2; - else result += 3; + int sz = utf8_size(c); + if (result + sz > INT_MAX-1) { + break; + } + result += sz; } - return result; + return static_cast(result); } char* UNICODE::as_utf8(jchar* base, int length) {