8267870: Remove unnecessary char_converter during class loading

Reviewed-by: dholmes, iklam
This commit is contained in:
Coleen Phillimore 2021-06-16 12:41:51 +00:00
parent 3ad658677b
commit af13fe1107
5 changed files with 12 additions and 76 deletions

View File

@ -614,9 +614,8 @@ Klass* ClassListParser::load_current_class(Symbol* class_name_symbol, TRAPS) {
// delegate to the correct loader (boot, platform or app) depending on
// the package name.
Handle s = java_lang_String::create_from_symbol(class_name_symbol, CHECK_NULL);
// ClassLoader.loadClass() wants external class name format, i.e., convert '/' chars to '.'
Handle ext_class_name = java_lang_String::externalize_classname(s, CHECK_NULL);
Handle ext_class_name = java_lang_String::externalize_classname(class_name_symbol, CHECK_NULL);
Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
JavaCalls::call_virtual(&result,

View File

@ -25,6 +25,7 @@
#include "precompiled.hpp"
#include "classfile/javaAssertions.hpp"
#include "classfile/javaClasses.hpp"
#include "classfile/symbolTable.hpp"
#include "classfile/systemDictionary.hpp"
#include "classfile/vmClasses.hpp"
#include "classfile/vmSymbols.hpp"
@ -127,7 +128,8 @@ oop JavaAssertions::createAssertionStatusDirectives(TRAPS) {
}
void JavaAssertions::fillJavaArrays(const OptionList* p, int len,
objArrayHandle names, typeArrayHandle enabled, TRAPS) {
objArrayHandle names,
typeArrayHandle enabled, TRAPS) {
// Fill in the parallel names and enabled (boolean) arrays. Start at the end
// of the array and work backwards, so the order of items in the arrays
// matches the order on the command line (the list is in reverse order, since
@ -135,8 +137,8 @@ objArrayHandle names, typeArrayHandle enabled, TRAPS) {
int index;
for (index = len - 1; p != 0; p = p->next(), --index) {
assert(index >= 0, "length does not match list");
Handle s = java_lang_String::create_from_str(p->name(), CHECK);
s = java_lang_String::char_converter(s, JVM_SIGNATURE_SLASH, JVM_SIGNATURE_DOT, CHECK);
TempNewSymbol name = SymbolTable::new_symbol(p->name());
Handle s = java_lang_String::externalize_classname(name, CHECK);
names->obj_at_put(index, s());
enabled->bool_at_put(index, p->enabled());
}

View File

@ -469,70 +469,9 @@ char* java_lang_String::as_platform_dependent_str(Handle java_string, TRAPS) {
return native_platform_string;
}
Handle java_lang_String::char_converter(Handle java_string, jchar from_char, jchar to_char, TRAPS) {
oop obj = java_string();
// Typical usage is to convert all '/' to '.' in string.
typeArrayOop value = java_lang_String::value(obj);
int length = java_lang_String::length(obj, value);
bool is_latin1 = java_lang_String::is_latin1(obj);
// First check if any from_char exist
int index; // Declared outside, used later
for (index = 0; index < length; index++) {
jchar c = !is_latin1 ? value->char_at(index) :
((jchar) value->byte_at(index)) & 0xff;
if (c == from_char) {
break;
}
}
if (index == length) {
// No from_char, so do not copy.
return java_string;
}
// Check if result string will be latin1
bool to_is_latin1 = false;
// Replacement char must be latin1
if (CompactStrings && UNICODE::is_latin1(to_char)) {
if (is_latin1) {
// Source string is latin1 as well
to_is_latin1 = true;
} else if (!UNICODE::is_latin1(from_char)) {
// We are replacing an UTF16 char. Scan string to
// check if result can be latin1 encoded.
to_is_latin1 = true;
for (index = 0; index < length; index++) {
jchar c = value->char_at(index);
if (c != from_char && !UNICODE::is_latin1(c)) {
to_is_latin1 = false;
break;
}
}
}
}
// Create new UNICODE (or byte) buffer. Must handlize value because GC
// may happen during String and char array creation.
typeArrayHandle h_value(THREAD, value);
Handle string = basic_create(length, to_is_latin1, CHECK_NH);
typeArrayOop from_buffer = h_value();
typeArrayOop to_buffer = java_lang_String::value(string());
// Copy contents
for (index = 0; index < length; index++) {
jchar c = (!is_latin1) ? from_buffer->char_at(index) :
((jchar) from_buffer->byte_at(index)) & 0xff;
if (c == from_char) {
c = to_char;
}
if (!to_is_latin1) {
to_buffer->char_at_put(index, c);
} else {
to_buffer->byte_at_put(index, (jbyte) c);
}
}
return string;
Handle java_lang_String::externalize_classname(Symbol* java_name, TRAPS) {
ResourceMark rm(THREAD);
return create_from_str(java_name->as_klass_external_name(), THREAD);
}
jchar* java_lang_String::as_unicode_string(oop java_string, int& length, TRAPS) {

View File

@ -145,7 +145,6 @@ class java_lang_String : AllStatic {
static oop create_oop_from_str(const char* utf8_str, TRAPS);
static Handle create_from_symbol(Symbol* symbol, TRAPS);
static Handle create_from_platform_dependent_str(const char* str, TRAPS);
static Handle char_converter(Handle java_string, jchar from_char, jchar to_char, TRAPS);
static void set_compact_strings(bool value);
@ -228,10 +227,8 @@ class java_lang_String : AllStatic {
static bool equals(oop str1, oop str2);
static inline bool value_equals(typeArrayOop str_value1, typeArrayOop str_value2);
// Conversion between '.' and '/' formats
static Handle externalize_classname(Handle java_string, TRAPS) {
return char_converter(java_string, JVM_SIGNATURE_SLASH, JVM_SIGNATURE_DOT, THREAD);
}
// Conversion between '.' and '/' formats, and allocate a String from the result.
static Handle externalize_classname(Symbol* java_name, TRAPS);
// Conversion
static Symbol* as_symbol(oop java_string);

View File

@ -1309,9 +1309,8 @@ InstanceKlass* SystemDictionary::load_instance_class_impl(Symbol* class_name, Ha
jt->get_thread_stat()->perf_timers_addr(),
PerfClassTraceTime::CLASS_LOAD);
Handle s = java_lang_String::create_from_symbol(class_name, CHECK_NULL);
// Translate to external class name format, i.e., convert '/' chars to '.'
Handle string = java_lang_String::externalize_classname(s, CHECK_NULL);
Handle string = java_lang_String::externalize_classname(class_name, CHECK_NULL);
JavaValue result(T_OBJECT);