2327 if (class2->is_instance_klass()) { 2328 classloader2 = class2->class_loader(); 2329 classpkg2 = class2->package(); 2330 } else { 2331 assert(class2->is_typeArray_klass(), "should be type array"); 2332 classloader2 = NULL; 2333 classpkg2 = NULL; 2334 } 2335 2336 // Same package is determined by comparing class loader 2337 // and package entries. Both must be the same. This rule 2338 // applies even to classes that are defined in the unnamed 2339 // package, they still must have the same class loader. 2340 if ((classloader1 == classloader2) && (classpkg1 == classpkg2)) { 2341 return true; 2342 } 2343 2344 return false; 2345 } 2346 2347 bool InstanceKlass::is_same_class_package(oop other_class_loader, 2348 const Symbol* other_class_name) const { 2349 oop this_class_loader = class_loader(); 2350 const Symbol* const this_class_name = name(); 2351 2352 return InstanceKlass::is_same_class_package(this_class_loader, 2353 this_class_name, 2354 other_class_loader, 2355 other_class_name); 2356 } 2357 2358 // return true if two classes are in the same package, classloader 2359 // and classname information is enough to determine a class's package 2360 bool InstanceKlass::is_same_class_package(oop class_loader1, const Symbol* class_name1, 2361 oop class_loader2, const Symbol* class_name2) { 2362 if (class_loader1 != class_loader2) { 2363 return false; 2364 } else if (class_name1 == class_name2) { 2365 return true; 2366 } else { 2367 ResourceMark rm; 2368 2369 bool bad_class_name = false; 2370 const char* name1 = ClassLoader::package_from_name((const char*) class_name1->as_C_string(), &bad_class_name); 2371 if (bad_class_name) { 2372 return false; 2373 } 2374 2375 const char* name2 = ClassLoader::package_from_name((const char*) class_name2->as_C_string(), &bad_class_name); 2376 if (bad_class_name) { 2377 return false; 2378 } 2379 2380 if ((name1 == NULL) || (name2 == NULL)) { 2381 // One of the two doesn't have a package. Only return true 2382 // if the other one also doesn't have a package. 2383 return name1 == name2; 2384 } 2385 2386 // Check that package is identical 2387 return (strcmp(name1, name2) == 0); 2388 } 2389 } 2390 2391 // Returns true iff super_method can be overridden by a method in targetclassname 2392 // See JLS 3rd edition 8.4.6.1 2393 // Assumes name-signature match 2394 // "this" is InstanceKlass of super_method which must exist 2395 // note that the InstanceKlass of the method in the targetclassname has not always been created yet 2396 bool InstanceKlass::is_override(const methodHandle& super_method, Handle targetclassloader, Symbol* targetclassname, TRAPS) { 2397 // Private methods can not be overridden 2398 if (super_method->is_private()) { 2399 return false; 2400 } 2401 // If super method is accessible, then override 2402 if ((super_method->is_protected()) || 2403 (super_method->is_public())) { 2404 return true; 2405 } 2406 // Package-private methods are not inherited outside of package 2407 assert(super_method->is_package_private(), "must be package private"); | 2327 if (class2->is_instance_klass()) { 2328 classloader2 = class2->class_loader(); 2329 classpkg2 = class2->package(); 2330 } else { 2331 assert(class2->is_typeArray_klass(), "should be type array"); 2332 classloader2 = NULL; 2333 classpkg2 = NULL; 2334 } 2335 2336 // Same package is determined by comparing class loader 2337 // and package entries. Both must be the same. This rule 2338 // applies even to classes that are defined in the unnamed 2339 // package, they still must have the same class loader. 2340 if ((classloader1 == classloader2) && (classpkg1 == classpkg2)) { 2341 return true; 2342 } 2343 2344 return false; 2345 } 2346 2347 // return true if this class and other_class are in the same package. Classloader 2348 // and classname information is enough to determine a class's package 2349 bool InstanceKlass::is_same_class_package(oop other_class_loader, 2350 const Symbol* other_class_name) const { 2351 if (class_loader() != other_class_loader) { 2352 return false; 2353 } 2354 if (name()->fast_compare(other_class_name) == 0) { 2355 return true; 2356 } 2357 2358 { 2359 ResourceMark rm; 2360 2361 bool bad_class_name = false; 2362 const char* other_pkg = 2363 ClassLoader::package_from_name((const char*) other_class_name->as_C_string(), &bad_class_name); 2364 if (bad_class_name) { 2365 return false; 2366 } 2367 // Check that package_from_name() returns NULL, not "", if there is no package. 2368 assert(other_pkg == NULL || strlen(other_pkg) > 0, "package name is empty string"); 2369 2370 const Symbol* const this_package_name = 2371 this->package() != NULL ? this->package()->name() : NULL; 2372 2373 if (this_package_name == NULL || other_pkg == NULL) { 2374 // One of the two doesn't have a package. Only return true if the other 2375 // one also doesn't have a package. 2376 return (const char*)this_package_name == other_pkg; 2377 } 2378 2379 // Check if package is identical 2380 return this_package_name->equals(other_pkg); 2381 } 2382 } 2383 2384 // Returns true iff super_method can be overridden by a method in targetclassname 2385 // See JLS 3rd edition 8.4.6.1 2386 // Assumes name-signature match 2387 // "this" is InstanceKlass of super_method which must exist 2388 // note that the InstanceKlass of the method in the targetclassname has not always been created yet 2389 bool InstanceKlass::is_override(const methodHandle& super_method, Handle targetclassloader, Symbol* targetclassname, TRAPS) { 2390 // Private methods can not be overridden 2391 if (super_method->is_private()) { 2392 return false; 2393 } 2394 // If super method is accessible, then override 2395 if ((super_method->is_protected()) || 2396 (super_method->is_public())) { 2397 return true; 2398 } 2399 // Package-private methods are not inherited outside of package 2400 assert(super_method->is_package_private(), "must be package private"); |