8314794: Improve UTF8 String supports
Reviewed-by: dholmes, coleenp, rhalade
This commit is contained in:
parent
46c3768645
commit
227fc5e591
src/hotspot/share/utilities
@ -44,6 +44,9 @@
|
||||
#include "utilities/events.hpp"
|
||||
#include "utilities/exceptions.hpp"
|
||||
|
||||
// Limit exception message components to 64K (the same max as Symbols)
|
||||
#define MAX_LEN 65535
|
||||
|
||||
// Implementation of ThreadShadow
|
||||
void check_ThreadShadow() {
|
||||
const ByteSize offset1 = byte_offset_of(ThreadShadow, _pending_exception);
|
||||
@ -114,10 +117,11 @@ bool Exceptions::special_exception(JavaThread* thread, const char* file, int lin
|
||||
if (h_exception.is_null() && !thread->can_call_java()) {
|
||||
ResourceMark rm(thread);
|
||||
const char* exc_value = h_name != nullptr ? h_name->as_C_string() : "null";
|
||||
log_info(exceptions)("Thread cannot call Java so instead of throwing exception <%s%s%s> (" PTR_FORMAT ") \n"
|
||||
log_info(exceptions)("Thread cannot call Java so instead of throwing exception <%.*s%s%.*s> (" PTR_FORMAT ") \n"
|
||||
"at [%s, line %d]\nfor thread " PTR_FORMAT ",\n"
|
||||
"throwing pre-allocated exception: %s",
|
||||
exc_value, message ? ": " : "", message ? message : "",
|
||||
MAX_LEN, exc_value, message ? ": " : "",
|
||||
MAX_LEN, message ? message : "",
|
||||
p2i(h_exception()), file, line, p2i(thread),
|
||||
Universe::vm_exception()->print_value_string());
|
||||
// We do not care what kind of exception we get for a thread which
|
||||
@ -143,10 +147,11 @@ void Exceptions::_throw(JavaThread* thread, const char* file, int line, Handle h
|
||||
|
||||
// tracing (do this up front - so it works during boot strapping)
|
||||
// Note, the print_value_string() argument is not called unless logging is enabled!
|
||||
log_info(exceptions)("Exception <%s%s%s> (" PTR_FORMAT ") \n"
|
||||
log_info(exceptions)("Exception <%.*s%s%.*s> (" PTR_FORMAT ") \n"
|
||||
"thrown [%s, line %d]\nfor thread " PTR_FORMAT,
|
||||
h_exception->print_value_string(),
|
||||
message ? ": " : "", message ? message : "",
|
||||
MAX_LEN, h_exception->print_value_string(),
|
||||
message ? ": " : "",
|
||||
MAX_LEN, message ? message : "",
|
||||
p2i(h_exception()), file, line, p2i(thread));
|
||||
|
||||
// for AbortVMOnException flag
|
||||
@ -566,13 +571,13 @@ void Exceptions::log_exception(Handle exception, const char* message) {
|
||||
ResourceMark rm;
|
||||
const char* detail_message = java_lang_Throwable::message_as_utf8(exception());
|
||||
if (detail_message != nullptr) {
|
||||
log_info(exceptions)("Exception <%s: %s>\n thrown in %s",
|
||||
exception->print_value_string(),
|
||||
detail_message,
|
||||
message);
|
||||
log_info(exceptions)("Exception <%.*s: %.*s>\n thrown in %.*s",
|
||||
MAX_LEN, exception->print_value_string(),
|
||||
MAX_LEN, detail_message,
|
||||
MAX_LEN, message);
|
||||
} else {
|
||||
log_info(exceptions)("Exception <%s>\n thrown in %s",
|
||||
exception->print_value_string(),
|
||||
message);
|
||||
log_info(exceptions)("Exception <%.*s>\n thrown in %.*s",
|
||||
MAX_LEN, exception->print_value_string(),
|
||||
MAX_LEN, message);
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
#include "precompiled.hpp"
|
||||
#include "memory/allocation.hpp"
|
||||
#include "utilities/checkedCast.hpp"
|
||||
#include "utilities/debug.hpp"
|
||||
#include "utilities/globalDefinitions.hpp"
|
||||
#include "utilities/utf8.hpp"
|
||||
@ -431,12 +432,16 @@ int UNICODE::utf8_size(jbyte c) {
|
||||
|
||||
template<typename T>
|
||||
int UNICODE::utf8_length(const T* base, int length) {
|
||||
int result = 0;
|
||||
size_t result = 0;
|
||||
for (int index = 0; index < length; index++) {
|
||||
T c = base[index];
|
||||
result += utf8_size(c);
|
||||
int sz = utf8_size(c);
|
||||
if (result + sz > INT_MAX-1) {
|
||||
break;
|
||||
}
|
||||
result += sz;
|
||||
}
|
||||
return result;
|
||||
return checked_cast<int>(result);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
Loading…
x
Reference in New Issue
Block a user