hotspot/src/share/vm/oops/instanceKlass.cpp
changeset 46697 2fdbdc5e0765
parent 46630 75aa3e39d02c
child 46701 f559541c0daa
--- a/hotspot/src/share/vm/oops/instanceKlass.cpp	Thu Jul 20 15:44:51 2017 +0800
+++ b/hotspot/src/share/vm/oops/instanceKlass.cpp	Thu Jul 20 11:01:20 2017 -0400
@@ -2344,47 +2344,40 @@
   return false;
 }
 
+// return true if this class and other_class are in the same package. Classloader
+// and classname information is enough to determine a class's package
 bool InstanceKlass::is_same_class_package(oop other_class_loader,
                                           const Symbol* other_class_name) const {
-  oop this_class_loader = class_loader();
-  const Symbol* const this_class_name = name();
-
-  return InstanceKlass::is_same_class_package(this_class_loader,
-                                             this_class_name,
-                                             other_class_loader,
-                                             other_class_name);
-}
-
-// return true if two classes are in the same package, classloader
-// and classname information is enough to determine a class's package
-bool InstanceKlass::is_same_class_package(oop class_loader1, const Symbol* class_name1,
-                                          oop class_loader2, const Symbol* class_name2) {
-  if (class_loader1 != class_loader2) {
+  if (class_loader() != other_class_loader) {
     return false;
-  } else if (class_name1 == class_name2) {
-    return true;
-  } else {
+  }
+  if (name()->fast_compare(other_class_name) == 0) {
+     return true;
+  }
+
+  {
     ResourceMark rm;
 
     bool bad_class_name = false;
-    const char* name1 = ClassLoader::package_from_name((const char*) class_name1->as_C_string(), &bad_class_name);
-    if (bad_class_name) {
-      return false;
-    }
-
-    const char* name2 = ClassLoader::package_from_name((const char*) class_name2->as_C_string(), &bad_class_name);
+    const char* other_pkg =
+      ClassLoader::package_from_name((const char*) other_class_name->as_C_string(), &bad_class_name);
     if (bad_class_name) {
       return false;
     }
-
-    if ((name1 == NULL) || (name2 == NULL)) {
-      // One of the two doesn't have a package.  Only return true
-      // if the other one also doesn't have a package.
-      return name1 == name2;
+    // Check that package_from_name() returns NULL, not "", if there is no package.
+    assert(other_pkg == NULL || strlen(other_pkg) > 0, "package name is empty string");
+
+    const Symbol* const this_package_name =
+      this->package() != NULL ? this->package()->name() : NULL;
+
+    if (this_package_name == NULL || other_pkg == NULL) {
+      // One of the two doesn't have a package.  Only return true if the other
+      // one also doesn't have a package.
+      return (const char*)this_package_name == other_pkg;
     }
 
-    // Check that package is identical
-    return (strcmp(name1, name2) == 0);
+    // Check if package is identical
+    return this_package_name->equals(other_pkg);
   }
 }