8232071: Avoid shared dictionary lookup when the class name is not shared
authoriklam
Thu, 10 Oct 2019 10:48:31 -0700
changeset 58542 94fe833a244b
parent 58541 8bc609fcd691
child 58543 a7a606f6311c
8232071: Avoid shared dictionary lookup when the class name is not shared Reviewed-by: jiangli, ccheung
src/hotspot/share/classfile/systemDictionaryShared.cpp
src/hotspot/share/classfile/systemDictionaryShared.hpp
--- a/src/hotspot/share/classfile/systemDictionaryShared.cpp	Thu Oct 10 10:47:45 2019 -0700
+++ b/src/hotspot/share/classfile/systemDictionaryShared.cpp	Thu Oct 10 10:48:31 2019 -0700
@@ -905,14 +905,9 @@
     return NULL;
   }
 
-  const RunTimeSharedClassInfo* record = find_record(&_unregistered_dictionary, class_name);
+  const RunTimeSharedClassInfo* record = find_record(&_unregistered_dictionary, &_dynamic_unregistered_dictionary, class_name);
   if (record == NULL) {
-    if (DynamicArchive::is_mapped()) {
-      record = find_record(&_dynamic_unregistered_dictionary, class_name);
-    }
-    if (record == NULL) {
-      return NULL;
-    }
+    return NULL;
   }
 
   int clsfile_size  = cfs->length();
@@ -1412,29 +1407,34 @@
 }
 
 const RunTimeSharedClassInfo*
-SystemDictionaryShared::find_record(RunTimeSharedDictionary* dict, Symbol* name) {
-  if (UseSharedSpaces) {
-    unsigned int hash = primitive_hash<Symbol*>(name);
-    return dict->lookup(name, hash, 0);
-  } else {
+SystemDictionaryShared::find_record(RunTimeSharedDictionary* static_dict, RunTimeSharedDictionary* dynamic_dict, Symbol* name) {
+  if (!UseSharedSpaces || !name->is_shared()) {
+    // The names of all shared classes must also be a shared Symbol.
     return NULL;
   }
+
+  unsigned int hash = primitive_hash<Symbol*>(name);
+  const RunTimeSharedClassInfo* record = NULL;
+  if (!MetaspaceShared::is_shared_dynamic(name)) {
+    // The names of all shared classes in the static dict must also be in the
+    // static archive
+    record = static_dict->lookup(name, hash, 0);
+  }
+
+  if (record == NULL && DynamicArchive::is_mapped()) {
+    record = dynamic_dict->lookup(name, hash, 0);
+  }
+
+  return record;
 }
 
 InstanceKlass* SystemDictionaryShared::find_builtin_class(Symbol* name) {
-  const RunTimeSharedClassInfo* record = find_record(&_builtin_dictionary, name);
-  if (record) {
+  const RunTimeSharedClassInfo* record = find_record(&_builtin_dictionary, &_dynamic_builtin_dictionary, name);
+  if (record != NULL) {
     return record->_klass;
+  } else {
+    return NULL;
   }
-
-  if (DynamicArchive::is_mapped()) {
-    record = find_record(&_dynamic_builtin_dictionary, name);
-    if (record) {
-      return record->_klass;
-    }
-  }
-
-  return NULL;
 }
 
 void SystemDictionaryShared::update_shared_entry(InstanceKlass* k, int id) {
--- a/src/hotspot/share/classfile/systemDictionaryShared.hpp	Thu Oct 10 10:47:45 2019 -0700
+++ b/src/hotspot/share/classfile/systemDictionaryShared.hpp	Thu Oct 10 10:48:31 2019 -0700
@@ -223,7 +223,9 @@
 public:
   static InstanceKlass* find_builtin_class(Symbol* class_name);
 
-  static const RunTimeSharedClassInfo* find_record(RunTimeSharedDictionary* dict, Symbol* name);
+  static const RunTimeSharedClassInfo* find_record(RunTimeSharedDictionary* static_dict,
+                                                   RunTimeSharedDictionary* dynamic_dict,
+                                                   Symbol* name);
 
   static bool has_platform_or_app_classes();