Within the VM there are several places that have been introduced due to Jigsaw support to strip the package name from the fully qualified class name. These need to be consolidated into one or two utility functions that are consistent about various error checking when trying to search for the '/' character. In addition to reduce the same code being duplicated throughout the VM. Right now there are the following instances:
1. ClassLoader::package_from_name
(formerly was ClassPathImageEntry::name_to_package)
2. InstanceKlass::package_from_name
3. There is code in SystemDIctionary::resolve_from_stream that picks out the package name.
const char* pkg = "java/";
if (!HAS_PENDING_EXCEPTION &&
!class_loader.is_null() &&
!SystemDictionary::is_platform_class_loader(class_loader) &&
parsed_name != NULL &&
!strncmp((const char*)parsed_name->bytes(), pkg, strlen(pkg))) {
// It is illegal to define classes in the "java." package from
// JVM_DefineClass or jni_DefineClass unless you're the bootclassloader
ResourceMark rm(THREAD);
char* name = parsed_name->as_C_string();
char* index = strrchr(name, '/');
*index = '\0'; // chop to just the package name
while ((index = strchr(name, '/')) != NULL) {
*index = '.'; // replace '/' with '.' in package name
}
4. A check of classfile/modules.cpp also need to be made to see if there is any similar code there as well.
I envision 2 functions that obtain the package name. One that takes a char* parameter and the other that takes a Symbol* parameter but both use the same underlying method that does the searching for the actual package name.
1. ClassLoader::package_from_name
(formerly was ClassPathImageEntry::name_to_package)
2. InstanceKlass::package_from_name
3. There is code in SystemDIctionary::resolve_from_stream that picks out the package name.
const char* pkg = "java/";
if (!HAS_PENDING_EXCEPTION &&
!class_loader.is_null() &&
!SystemDictionary::is_platform_class_loader(class_loader) &&
parsed_name != NULL &&
!strncmp((const char*)parsed_name->bytes(), pkg, strlen(pkg))) {
// It is illegal to define classes in the "java." package from
// JVM_DefineClass or jni_DefineClass unless you're the bootclassloader
ResourceMark rm(THREAD);
char* name = parsed_name->as_C_string();
char* index = strrchr(name, '/');
*index = '\0'; // chop to just the package name
while ((index = strchr(name, '/')) != NULL) {
*index = '.'; // replace '/' with '.' in package name
}
4. A check of classfile/modules.cpp also need to be made to see if there is any similar code there as well.
I envision 2 functions that obtain the package name. One that takes a char* parameter and the other that takes a Symbol* parameter but both use the same underlying method that does the searching for the actual package name.