< prev index next >
src/hotspot/share/classfile/classLoader.cpp
Print this page
rev 58452 : imported patch pkg_name_from_class
*** 174,253 ****
return false;
}
return (strncmp(str + (str_len - str_to_find_len), str_to_find, str_to_find_len) == 0);
}
- // Used to obtain the package name from a fully qualified class name.
- // It is the responsibility of the caller to establish a ResourceMark.
- const char* ClassLoader::package_from_name(const char* const class_name, bool* bad_class_name) {
- if (class_name == NULL) {
- if (bad_class_name != NULL) {
- *bad_class_name = true;
- }
- return NULL;
- }
-
- if (bad_class_name != NULL) {
- *bad_class_name = false;
- }
-
- const char* const last_slash = strrchr(class_name, JVM_SIGNATURE_SLASH);
- if (last_slash == NULL) {
- // No package name
- return NULL;
- }
-
- char* class_name_ptr = (char*) class_name;
- // Skip over '['s
- if (*class_name_ptr == JVM_SIGNATURE_ARRAY) {
- do {
- class_name_ptr++;
- } while (*class_name_ptr == JVM_SIGNATURE_ARRAY);
-
- // Fully qualified class names should not contain a 'L'.
- // Set bad_class_name to true to indicate that the package name
- // could not be obtained due to an error condition.
- // In this situation, is_same_class_package returns false.
- if (*class_name_ptr == JVM_SIGNATURE_CLASS) {
- if (bad_class_name != NULL) {
- *bad_class_name = true;
- }
- return NULL;
- }
- }
-
- int length = last_slash - class_name_ptr;
-
- // A class name could have just the slash character in the name.
- if (length <= 0) {
- // No package name
- if (bad_class_name != NULL) {
- *bad_class_name = true;
- }
- return NULL;
- }
-
- // drop name after last slash (including slash)
- // Ex., "java/lang/String.class" => "java/lang"
- char* pkg_name = NEW_RESOURCE_ARRAY(char, length + 1);
- strncpy(pkg_name, class_name_ptr, length);
- *(pkg_name+length) = '\0';
-
- return (const char *)pkg_name;
- }
-
// Given a fully qualified class name, find its defining package in the class loader's
// package entry table.
! PackageEntry* ClassLoader::get_package_entry(const char* class_name, ClassLoaderData* loader_data, TRAPS) {
! ResourceMark rm(THREAD);
! const char *pkg_name = ClassLoader::package_from_name(class_name);
if (pkg_name == NULL) {
return NULL;
}
PackageEntryTable* pkgEntryTable = loader_data->packages();
! TempNewSymbol pkg_symbol = SymbolTable::new_symbol(pkg_name);
! return pkgEntryTable->lookup_only(pkg_symbol);
}
const char* ClassPathEntry::copy_path(const char* path) {
char* copy = NEW_C_HEAP_ARRAY(char, strlen(path)+1, mtClass);
strcpy(copy, path);
--- 174,191 ----
return false;
}
return (strncmp(str + (str_len - str_to_find_len), str_to_find, str_to_find_len) == 0);
}
// Given a fully qualified class name, find its defining package in the class loader's
// package entry table.
! PackageEntry* ClassLoader::get_package_entry(Symbol* pkg_name, ClassLoaderData* loader_data, TRAPS) {
if (pkg_name == NULL) {
return NULL;
}
PackageEntryTable* pkgEntryTable = loader_data->packages();
! return pkgEntryTable->lookup_only(pkg_name);
}
const char* ClassPathEntry::copy_path(const char* path) {
char* copy = NEW_C_HEAP_ARRAY(char, strlen(path)+1, mtClass);
strcpy(copy, path);
*** 405,422 ****
ClassFileStream* ClassPathImageEntry::open_stream_for_loader(const char* name, ClassLoaderData* loader_data, TRAPS) {
jlong size;
JImageLocationRef location = (*JImageFindResource)(_jimage, "", get_jimage_version_string(), name, &size);
if (location == 0) {
! ResourceMark rm;
! const char* pkg_name = ClassLoader::package_from_name(name);
if (pkg_name != NULL) {
if (!Universe::is_module_initialized()) {
location = (*JImageFindResource)(_jimage, JAVA_BASE_NAME, get_jimage_version_string(), name, &size);
} else {
! PackageEntry* package_entry = ClassLoader::get_package_entry(name, loader_data, CHECK_NULL);
if (package_entry != NULL) {
ResourceMark rm;
// Get the module name
ModuleEntry* module = package_entry->module();
assert(module != NULL, "Boot classLoader package missing module");
--- 343,360 ----
ClassFileStream* ClassPathImageEntry::open_stream_for_loader(const char* name, ClassLoaderData* loader_data, TRAPS) {
jlong size;
JImageLocationRef location = (*JImageFindResource)(_jimage, "", get_jimage_version_string(), name, &size);
if (location == 0) {
! TempNewSymbol class_name = SymbolTable::new_symbol(name);
! TempNewSymbol pkg_name = InstanceKlass::package_from_name(class_name);
if (pkg_name != NULL) {
if (!Universe::is_module_initialized()) {
location = (*JImageFindResource)(_jimage, JAVA_BASE_NAME, get_jimage_version_string(), name, &size);
} else {
! PackageEntry* package_entry = ClassLoader::get_package_entry(pkg_name, loader_data, CHECK_NULL);
if (package_entry != NULL) {
ResourceMark rm;
// Get the module name
ModuleEntry* module = package_entry->module();
assert(module != NULL, "Boot classLoader package missing module");
*** 1027,1055 ****
int ClassLoader::crc32(int crc, const char* buf, int len) {
return (*Crc32)(crc, (const jbyte*)buf, len);
}
! // Function add_package extracts the package from the fully qualified class name
! // and checks if the package is in the boot loader's package entry table. If so,
! // then it sets the classpath_index in the package entry record.
//
// The classpath_index field is used to find the entry on the boot loader class
// path for packages with classes loaded by the boot loader from -Xbootclasspath/a
// in an unnamed module. It is also used to indicate (for all packages whose
// classes are loaded by the boot loader) that at least one of the package's
// classes has been loaded.
! bool ClassLoader::add_package(const char *fullq_class_name, s2 classpath_index, TRAPS) {
! assert(fullq_class_name != NULL, "just checking");
// Get package name from fully qualified class name.
! ResourceMark rm(THREAD);
! const char *cp = package_from_name(fullq_class_name);
! if (cp != NULL) {
PackageEntryTable* pkg_entry_tbl = ClassLoaderData::the_null_class_loader_data()->packages();
! TempNewSymbol pkg_symbol = SymbolTable::new_symbol(cp);
! PackageEntry* pkg_entry = pkg_entry_tbl->lookup_only(pkg_symbol);
if (pkg_entry != NULL) {
assert(classpath_index != -1, "Unexpected classpath_index");
pkg_entry->set_classpath_index(classpath_index);
} else {
return false;
--- 965,991 ----
int ClassLoader::crc32(int crc, const char* buf, int len) {
return (*Crc32)(crc, (const jbyte*)buf, len);
}
! // Function add_package checks if the package of the InstanceKlass is in the
! // boot loader's package entry table. If so, then it sets the classpath_index
! // in the package entry record.
//
// The classpath_index field is used to find the entry on the boot loader class
// path for packages with classes loaded by the boot loader from -Xbootclasspath/a
// in an unnamed module. It is also used to indicate (for all packages whose
// classes are loaded by the boot loader) that at least one of the package's
// classes has been loaded.
! bool ClassLoader::add_package(const InstanceKlass* ik, s2 classpath_index, TRAPS) {
! assert(ik != NULL, "just checking");
// Get package name from fully qualified class name.
! PackageEntry* ik_pkg = ik->package();
! if (ik_pkg != NULL) {
PackageEntryTable* pkg_entry_tbl = ClassLoaderData::the_null_class_loader_data()->packages();
! PackageEntry* pkg_entry = pkg_entry_tbl->lookup_only(ik_pkg->name());
if (pkg_entry != NULL) {
assert(classpath_index != -1, "Unexpected classpath_index");
pkg_entry->set_classpath_index(classpath_index);
} else {
return false;
*** 1164,1174 ****
const char* const file_name,
TRAPS) {
ClassFileStream* stream = NULL;
// Find the class' defining module in the boot loader's module entry table
! PackageEntry* pkg_entry = get_package_entry(class_name, ClassLoaderData::the_null_class_loader_data(), CHECK_NULL);
ModuleEntry* mod_entry = (pkg_entry != NULL) ? pkg_entry->module() : NULL;
// If the module system has not defined java.base yet, then
// classes loaded are assumed to be defined to java.base.
// When java.base is eventually defined by the module system,
--- 1100,1112 ----
const char* const file_name,
TRAPS) {
ClassFileStream* stream = NULL;
// Find the class' defining module in the boot loader's module entry table
! TempNewSymbol class_name_symbol = SymbolTable::new_symbol(class_name);
! TempNewSymbol pkg_name = InstanceKlass::package_from_name(class_name_symbol);
! PackageEntry* pkg_entry = get_package_entry(pkg_name, ClassLoaderData::the_null_class_loader_data(), CHECK_NULL);
ModuleEntry* mod_entry = (pkg_entry != NULL) ? pkg_entry->module() : NULL;
// If the module system has not defined java.base yet, then
// classes loaded are assumed to be defined to java.base.
// When java.base is eventually defined by the module system,
*** 1315,1325 ****
log_error(cds)("Preload Error: Failed to load %s", class_name);
}
return NULL;
}
! if (!add_package(file_name, classpath_index, THREAD)) {
return NULL;
}
return result;
}
--- 1253,1263 ----
log_error(cds)("Preload Error: Failed to load %s", class_name);
}
return NULL;
}
! if (!add_package(result, classpath_index, THREAD)) {
return NULL;
}
return result;
}
< prev index next >