mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8231895: Avoid String allocations in JVM_FindLoadedClass
Reviewed-by: jiangli, dholmes, iklam
This commit is contained in:
parent
0009f8a51f
commit
b9204e62a4
2 changed files with 11 additions and 4 deletions
|
@ -202,7 +202,6 @@ class java_lang_String : AllStatic {
|
|||
|
||||
// Conversion between '.' and '/' formats
|
||||
static Handle externalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '/', '.', THREAD); }
|
||||
static Handle internalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '.', '/', THREAD); }
|
||||
|
||||
// Conversion
|
||||
static Symbol* as_symbol(oop java_string);
|
||||
|
|
|
@ -990,13 +990,21 @@ JVM_ENTRY(jclass, JVM_FindLoadedClass(JNIEnv *env, jobject loader, jstring name)
|
|||
ResourceMark rm(THREAD);
|
||||
|
||||
Handle h_name (THREAD, JNIHandles::resolve_non_null(name));
|
||||
Handle string = java_lang_String::internalize_classname(h_name, CHECK_NULL);
|
||||
char* str = java_lang_String::as_utf8_string(h_name());
|
||||
|
||||
const char* str = java_lang_String::as_utf8_string(string());
|
||||
// Sanity check, don't expect null
|
||||
if (str == NULL) return NULL;
|
||||
|
||||
const int str_len = (int)strlen(str);
|
||||
// Internalize the string, converting '.' to '/' in string.
|
||||
char* p = (char*)str;
|
||||
while (*p != '\0') {
|
||||
if (*p == '.') {
|
||||
*p = '/';
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
const int str_len = (int)(p - str);
|
||||
if (str_len > Symbol::max_length()) {
|
||||
// It's impossible to create this class; the name cannot fit
|
||||
// into the constant pool.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue