src/hotspot/share/oops/instanceKlass.cpp
changeset 52232 c9459e2f7bc8
parent 52096 7a1e2d7ac55a
child 52311 274ba8fbd96d
--- 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;
+        }
       }
     }
   }