mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8241371: Refactor and consolidate package_from_name
Reviewed-by: iklam, lfoltan
This commit is contained in:
parent
7dc952ec20
commit
23d6a788b4
12 changed files with 145 additions and 180 deletions
|
@ -2641,24 +2641,6 @@ const char* InstanceKlass::signature_name() const {
|
|||
return dest;
|
||||
}
|
||||
|
||||
// Used to obtain the package name from a fully qualified class name.
|
||||
Symbol* InstanceKlass::package_from_name(const Symbol* name, TRAPS) {
|
||||
if (name == NULL) {
|
||||
return NULL;
|
||||
} else {
|
||||
if (name->utf8_length() <= 0) {
|
||||
return NULL;
|
||||
}
|
||||
ResourceMark rm(THREAD);
|
||||
const char* package_name = ClassLoader::package_from_name((const char*) name->as_C_string());
|
||||
if (package_name == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
Symbol* pkg_name = SymbolTable::new_symbol(package_name);
|
||||
return pkg_name;
|
||||
}
|
||||
}
|
||||
|
||||
ModuleEntry* InstanceKlass::module() const {
|
||||
// For an unsafe anonymous class return the host class' module
|
||||
if (is_unsafe_anonymous()) {
|
||||
|
@ -2680,7 +2662,7 @@ void InstanceKlass::set_package(ClassLoaderData* loader_data, TRAPS) {
|
|||
// ensure java/ packages only loaded by boot or platform builtin loaders
|
||||
check_prohibited_package(name(), loader_data, CHECK);
|
||||
|
||||
TempNewSymbol pkg_name = package_from_name(name(), CHECK);
|
||||
TempNewSymbol pkg_name = ClassLoader::package_from_class_name(name());
|
||||
|
||||
if (pkg_name != NULL && loader_data != NULL) {
|
||||
|
||||
|
@ -2776,13 +2758,12 @@ bool InstanceKlass::is_same_class_package(oop other_class_loader,
|
|||
ResourceMark rm;
|
||||
|
||||
bool bad_class_name = false;
|
||||
const char* other_pkg =
|
||||
ClassLoader::package_from_name((const char*) other_class_name->as_C_string(), &bad_class_name);
|
||||
TempNewSymbol other_pkg = ClassLoader::package_from_class_name(other_class_name, &bad_class_name);
|
||||
if (bad_class_name) {
|
||||
return false;
|
||||
}
|
||||
// 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");
|
||||
// Check that package_from_class_name() returns NULL, not "", if there is no package.
|
||||
assert(other_pkg == NULL || other_pkg->utf8_length() > 0, "package name is empty string");
|
||||
|
||||
const Symbol* const this_package_name =
|
||||
this->package() != NULL ? this->package()->name() : NULL;
|
||||
|
@ -2790,11 +2771,11 @@ bool InstanceKlass::is_same_class_package(oop other_class_loader,
|
|||
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;
|
||||
return this_package_name == other_pkg;
|
||||
}
|
||||
|
||||
// Check if package is identical
|
||||
return this_package_name->equals(other_pkg);
|
||||
return this_package_name->fast_compare(other_pkg) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2828,7 +2809,7 @@ void InstanceKlass::check_prohibited_package(Symbol* class_name,
|
|||
ResourceMark rm(THREAD);
|
||||
char* name = class_name->as_C_string();
|
||||
if (strncmp(name, JAVAPKG, JAVAPKG_LEN) == 0 && name[JAVAPKG_LEN] == '/') {
|
||||
TempNewSymbol pkg_name = InstanceKlass::package_from_name(class_name, CHECK);
|
||||
TempNewSymbol pkg_name = ClassLoader::package_from_class_name(class_name);
|
||||
assert(pkg_name != NULL, "Error in parsing package name starting with 'java/'");
|
||||
name = pkg_name->as_C_string();
|
||||
const char* class_loader_name = loader_data->loader_name_and_id();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue