8231895: Avoid String allocations in JVM_FindLoadedClass
authorredestad
Mon, 07 Oct 2019 12:06:47 +0200
changeset 58469 ccbb5a2bf3ab
parent 58468 97cd0aa39787
child 58470 8991796c17d4
8231895: Avoid String allocations in JVM_FindLoadedClass Reviewed-by: jiangli, dholmes, iklam
src/hotspot/share/classfile/javaClasses.hpp
src/hotspot/share/prims/jvm.cpp
--- a/src/hotspot/share/classfile/javaClasses.hpp	Mon Oct 07 07:53:38 2019 +0200
+++ b/src/hotspot/share/classfile/javaClasses.hpp	Mon Oct 07 12:06:47 2019 +0200
@@ -202,7 +202,6 @@
 
   // 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);
--- a/src/hotspot/share/prims/jvm.cpp	Mon Oct 07 07:53:38 2019 +0200
+++ b/src/hotspot/share/prims/jvm.cpp	Mon Oct 07 12:06:47 2019 +0200
@@ -990,13 +990,21 @@
   ResourceMark rm(THREAD);
 
   Handle h_name (THREAD, JNIHandles::resolve_non_null(name));
-  Handle string = java_lang_String::internalize_classname(h_name, CHECK_NULL);
-
-  const char* str   = java_lang_String::as_utf8_string(string());
+  char* str = java_lang_String::as_utf8_string(h_name());
+
   // 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.