8314794: Improve UTF8 String supports

Co-authored-by: Ekaterina Vergizova <evergizova@openjdk.org>
Reviewed-by: mbalao, andrew
Backport-of: ab2532d858de8d855529b6f2491f94c499f94009
This commit is contained in:
Aleksei Voitylov 2024-06-12 21:08:55 +03:00 committed by Andrew John Hughes
parent a717515a4e
commit 48e19d8467
6 changed files with 30 additions and 16 deletions

View File

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

View File

@ -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()),

View File

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

View File

@ -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

View File

@ -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.

View File

@ -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<int>(result);
}
char* UNICODE::as_utf8(jchar* base, int length) {