8199567: [Nestmates] Cleanup instanceKlass.cpp
authordholmes
Tue, 23 Oct 2018 17:01:48 -0400
changeset 52232 c9459e2f7bc8
parent 52231 66432f0e91bd
child 52233 d682023cdd8c
child 52267 0f81b26228ec
8199567: [Nestmates] Cleanup instanceKlass.cpp Reviewed-by: lfoltan, coleenp
src/hotspot/share/oops/instanceKlass.cpp
--- a/src/hotspot/share/oops/instanceKlass.cpp	Tue Oct 23 10:32:39 2018 -0700
+++ b/src/hotspot/share/oops/instanceKlass.cpp	Tue Oct 23 17:01:48 2018 -0400
@@ -165,25 +165,35 @@
                                 k->external_name(), this->external_name());
   }
 
-  // Check names first and if they match then check actual klass. This avoids
-  // resolving anything unnecessarily.
+  // Check for a resolved cp entry , else fall back to a name check.
+  // We don't want to resolve any class other than the one being checked.
   for (int i = 0; i < _nest_members->length(); i++) {
     int cp_index = _nest_members->at(i);
-    Symbol* name = _constants->klass_name_at(cp_index);
-    if (name == k->name()) {
-      log_trace(class, nestmates)("- Found it at nest_members[%d] => cp[%d]", i, cp_index);
-
-      // names match so check actual klass - this may trigger class loading if
-      // it doesn't match (but that should be impossible)
+    if (_constants->tag_at(cp_index).is_klass()) {
       Klass* k2 = _constants->klass_at(cp_index, CHECK_false);
       if (k2 == k) {
-        log_trace(class, nestmates)("- class is listed as a nest member");
+        log_trace(class, nestmates)("- class is listed at nest_members[%d] => cp[%d]", i, cp_index);
         return true;
-      } else {
-        // same name but different klass!
-        log_trace(class, nestmates)(" - klass comparison failed!");
-        // can't have different classes for the same name, so we're done
-        return false;
+      }
+    }
+    else {
+      Symbol* name = _constants->klass_name_at(cp_index);
+      if (name == k->name()) {
+        log_trace(class, nestmates)("- Found it at nest_members[%d] => cp[%d]", i, cp_index);
+
+        // names match so check actual klass - this may trigger class loading if
+        // it doesn't match (but that should be impossible)
+        Klass* k2 = _constants->klass_at(cp_index, CHECK_false);
+        if (k2 == k) {
+          log_trace(class, nestmates)("- class is listed as a nest member");
+          return true;
+        }
+        else {
+          // same name but different klass!
+          log_trace(class, nestmates)(" - klass comparison failed!");
+          // can't have two names the same, so we're done
+          return false;
+        }
       }
     }
   }