Skip to content

Commit af13fe1

Browse files
committedJun 16, 2021
8267870: Remove unnecessary char_converter during class loading
Reviewed-by: dholmes, iklam
1 parent 3ad6586 commit af13fe1

File tree

5 files changed

+12
-76
lines changed

5 files changed

+12
-76
lines changed
 

‎src/hotspot/share/cds/classListParser.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -614,9 +614,8 @@ Klass* ClassListParser::load_current_class(Symbol* class_name_symbol, TRAPS) {
614614
// delegate to the correct loader (boot, platform or app) depending on
615615
// the package name.
616616

617-
Handle s = java_lang_String::create_from_symbol(class_name_symbol, CHECK_NULL);
618617
// ClassLoader.loadClass() wants external class name format, i.e., convert '/' chars to '.'
619-
Handle ext_class_name = java_lang_String::externalize_classname(s, CHECK_NULL);
618+
Handle ext_class_name = java_lang_String::externalize_classname(class_name_symbol, CHECK_NULL);
620619
Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
621620

622621
JavaCalls::call_virtual(&result,

‎src/hotspot/share/classfile/javaAssertions.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "precompiled.hpp"
2626
#include "classfile/javaAssertions.hpp"
2727
#include "classfile/javaClasses.hpp"
28+
#include "classfile/symbolTable.hpp"
2829
#include "classfile/systemDictionary.hpp"
2930
#include "classfile/vmClasses.hpp"
3031
#include "classfile/vmSymbols.hpp"
@@ -127,16 +128,17 @@ oop JavaAssertions::createAssertionStatusDirectives(TRAPS) {
127128
}
128129

129130
void JavaAssertions::fillJavaArrays(const OptionList* p, int len,
130-
objArrayHandle names, typeArrayHandle enabled, TRAPS) {
131+
objArrayHandle names,
132+
typeArrayHandle enabled, TRAPS) {
131133
// Fill in the parallel names and enabled (boolean) arrays. Start at the end
132134
// of the array and work backwards, so the order of items in the arrays
133135
// matches the order on the command line (the list is in reverse order, since
134136
// it was created by prepending successive items from the command line).
135137
int index;
136138
for (index = len - 1; p != 0; p = p->next(), --index) {
137139
assert(index >= 0, "length does not match list");
138-
Handle s = java_lang_String::create_from_str(p->name(), CHECK);
139-
s = java_lang_String::char_converter(s, JVM_SIGNATURE_SLASH, JVM_SIGNATURE_DOT, CHECK);
140+
TempNewSymbol name = SymbolTable::new_symbol(p->name());
141+
Handle s = java_lang_String::externalize_classname(name, CHECK);
140142
names->obj_at_put(index, s());
141143
enabled->bool_at_put(index, p->enabled());
142144
}

‎src/hotspot/share/classfile/javaClasses.cpp

+3-64
Original file line numberDiff line numberDiff line change
@@ -469,70 +469,9 @@ char* java_lang_String::as_platform_dependent_str(Handle java_string, TRAPS) {
469469
return native_platform_string;
470470
}
471471

472-
Handle java_lang_String::char_converter(Handle java_string, jchar from_char, jchar to_char, TRAPS) {
473-
oop obj = java_string();
474-
// Typical usage is to convert all '/' to '.' in string.
475-
typeArrayOop value = java_lang_String::value(obj);
476-
int length = java_lang_String::length(obj, value);
477-
bool is_latin1 = java_lang_String::is_latin1(obj);
478-
479-
// First check if any from_char exist
480-
int index; // Declared outside, used later
481-
for (index = 0; index < length; index++) {
482-
jchar c = !is_latin1 ? value->char_at(index) :
483-
((jchar) value->byte_at(index)) & 0xff;
484-
if (c == from_char) {
485-
break;
486-
}
487-
}
488-
if (index == length) {
489-
// No from_char, so do not copy.
490-
return java_string;
491-
}
492-
493-
// Check if result string will be latin1
494-
bool to_is_latin1 = false;
495-
496-
// Replacement char must be latin1
497-
if (CompactStrings && UNICODE::is_latin1(to_char)) {
498-
if (is_latin1) {
499-
// Source string is latin1 as well
500-
to_is_latin1 = true;
501-
} else if (!UNICODE::is_latin1(from_char)) {
502-
// We are replacing an UTF16 char. Scan string to
503-
// check if result can be latin1 encoded.
504-
to_is_latin1 = true;
505-
for (index = 0; index < length; index++) {
506-
jchar c = value->char_at(index);
507-
if (c != from_char && !UNICODE::is_latin1(c)) {
508-
to_is_latin1 = false;
509-
break;
510-
}
511-
}
512-
}
513-
}
514-
515-
// Create new UNICODE (or byte) buffer. Must handlize value because GC
516-
// may happen during String and char array creation.
517-
typeArrayHandle h_value(THREAD, value);
518-
Handle string = basic_create(length, to_is_latin1, CHECK_NH);
519-
typeArrayOop from_buffer = h_value();
520-
typeArrayOop to_buffer = java_lang_String::value(string());
521-
522-
// Copy contents
523-
for (index = 0; index < length; index++) {
524-
jchar c = (!is_latin1) ? from_buffer->char_at(index) :
525-
((jchar) from_buffer->byte_at(index)) & 0xff;
526-
if (c == from_char) {
527-
c = to_char;
528-
}
529-
if (!to_is_latin1) {
530-
to_buffer->char_at_put(index, c);
531-
} else {
532-
to_buffer->byte_at_put(index, (jbyte) c);
533-
}
534-
}
535-
return string;
472+
Handle java_lang_String::externalize_classname(Symbol* java_name, TRAPS) {
473+
ResourceMark rm(THREAD);
474+
return create_from_str(java_name->as_klass_external_name(), THREAD);
536475
}
537476

538477
jchar* java_lang_String::as_unicode_string(oop java_string, int& length, TRAPS) {

‎src/hotspot/share/classfile/javaClasses.hpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ class java_lang_String : AllStatic {
145145
static oop create_oop_from_str(const char* utf8_str, TRAPS);
146146
static Handle create_from_symbol(Symbol* symbol, TRAPS);
147147
static Handle create_from_platform_dependent_str(const char* str, TRAPS);
148-
static Handle char_converter(Handle java_string, jchar from_char, jchar to_char, TRAPS);
149148

150149
static void set_compact_strings(bool value);
151150

@@ -228,10 +227,8 @@ class java_lang_String : AllStatic {
228227
static bool equals(oop str1, oop str2);
229228
static inline bool value_equals(typeArrayOop str_value1, typeArrayOop str_value2);
230229

231-
// Conversion between '.' and '/' formats
232-
static Handle externalize_classname(Handle java_string, TRAPS) {
233-
return char_converter(java_string, JVM_SIGNATURE_SLASH, JVM_SIGNATURE_DOT, THREAD);
234-
}
230+
// Conversion between '.' and '/' formats, and allocate a String from the result.
231+
static Handle externalize_classname(Symbol* java_name, TRAPS);
235232

236233
// Conversion
237234
static Symbol* as_symbol(oop java_string);

‎src/hotspot/share/classfile/systemDictionary.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1309,9 +1309,8 @@ InstanceKlass* SystemDictionary::load_instance_class_impl(Symbol* class_name, Ha
13091309
jt->get_thread_stat()->perf_timers_addr(),
13101310
PerfClassTraceTime::CLASS_LOAD);
13111311

1312-
Handle s = java_lang_String::create_from_symbol(class_name, CHECK_NULL);
13131312
// Translate to external class name format, i.e., convert '/' chars to '.'
1314-
Handle string = java_lang_String::externalize_classname(s, CHECK_NULL);
1313+
Handle string = java_lang_String::externalize_classname(class_name, CHECK_NULL);
13151314

13161315
JavaValue result(T_OBJECT);
13171316

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Jun 16, 2021

@openjdk-notifier[bot]
Please sign in to comment.