8193332: MetaspaceShared::check_shared_class_loader_type is not used during archive creation

Reviewed-by: lfoltan, jiangli
This commit is contained in:
Ioi Lam 2018-05-21 21:27:12 -07:00
parent 03096d9b75
commit f9742fc0a6
6 changed files with 29 additions and 16 deletions

View file

@ -311,6 +311,7 @@ InstanceKlass* ClassListParser::load_class_from_source(Symbol* class_name, TRAPS
// This tells JVM_FindLoadedClass to not find this class.
k->set_shared_classpath_index(UNREGISTERED_INDEX);
k->clear_class_loader_type();
}
return k;

View file

@ -1410,16 +1410,12 @@ InstanceKlass* ClassLoader::load_class(Symbol* name, bool search_append_only, TR
s2 classpath_index = 0;
ClassPathEntry* e = NULL;
// If DumpSharedSpaces is true boot loader visibility boundaries are set to:
// - [jimage] + [_first_append_entry to _last_append_entry] (all path entries).
//
// If search_append_only is true, boot loader visibility boundaries are
// set to be _first_append_entry to the end. This includes:
// [-Xbootclasspath/a]; [jvmti appended entries]
//
// If both DumpSharedSpaces and search_append_only are false, boot loader
// visibility boundaries are set to be the --patch-module entries plus the base piece.
// This would include:
// If search_append_only is false, boot loader visibility boundaries are
// set to be the --patch-module entries plus the base piece. This includes:
// [--patch-module=<module>=<file>(<pathsep><file>)*]; [jimage | exploded module build]
//
@ -1455,7 +1451,7 @@ InstanceKlass* ClassLoader::load_class(Symbol* name, bool search_append_only, TR
}
// Load Attempt #3: [-Xbootclasspath/a]; [jvmti appended entries]
if ((search_append_only || DumpSharedSpaces) && (NULL == stream)) {
if (search_append_only && (NULL == stream)) {
// For the boot loader append path search, the starting classpath_index
// for the appended piece is always 1 to account for either the
// _jrt_entry or the _exploded_entries.

View file

@ -1411,6 +1411,9 @@ void VM_PopulateDumpSharedSpace::doit() {
// Move classes from platform/system dictionaries into the boot dictionary
SystemDictionary::combine_shared_dictionaries();
// Make sure all classes have a correct loader type.
ClassLoaderData::the_null_class_loader_data()->dictionary()->classes_do(MetaspaceShared::check_shared_class_loader_type);
// Remove all references outside the metadata
tty->print("Removing unshareable information ... ");
remove_unshareable_in_classes();
@ -1610,13 +1613,14 @@ class CheckSharedClassesClosure : public KlassClosure {
}
};
void MetaspaceShared::check_shared_class_loader_type(Klass* k) {
if (k->is_instance_klass()) {
InstanceKlass* ik = InstanceKlass::cast(k);
u2 loader_type = ik->loader_type();
ResourceMark rm;
guarantee(loader_type != 0,
"Class loader type is not set for this class %s", ik->name()->as_C_string());
void MetaspaceShared::check_shared_class_loader_type(InstanceKlass* ik) {
ResourceMark rm;
if (ik->shared_classpath_index() == UNREGISTERED_INDEX) {
guarantee(ik->loader_type() == 0,
"Class loader type must not be set for this class %s", ik->name()->as_C_string());
} else {
guarantee(ik->loader_type() != 0,
"Class loader type must be set for this class %s", ik->name()->as_C_string());
}
}

View file

@ -225,7 +225,7 @@ class MetaspaceShared : AllStatic {
static bool try_link_class(InstanceKlass* ik, TRAPS);
static void link_and_cleanup_shared_classes(TRAPS);
static void check_shared_class_loader_type(Klass* obj);
static void check_shared_class_loader_type(InstanceKlass* ik);
// Allocate a block of memory from the "mc", "ro", or "rw" regions.
static char* misc_code_space_alloc(size_t num_bytes);

View file

@ -326,6 +326,10 @@ class InstanceKlass: public Klass {
return (_misc_flags & _misc_is_shared_app_class) != 0;
}
void clear_class_loader_type() {
_misc_flags &= ~loader_type_bits();
}
void set_class_loader_type(s2 loader_type) {
switch (loader_type) {
case ClassLoader::BOOT_LOADER:

View file

@ -115,7 +115,15 @@ public class BootAppendTests {
"-XX:SharedClassListFile=" + classlist.getPath());
// Make sure all the classes were successfully archived.
for (String archiveClass : ARCHIVE_CLASSES) {
out.shouldNotContain("Preload Warning: Cannot find " + archiveClass);
String msg = "Preload Warning: Cannot find " + archiveClass;
if (archiveClass.equals(BOOT_APPEND_MODULE_CLASS)) {
// We shouldn't archive a class in the appended boot class path that
// are the java.desktop module. Such a class cannot be loaded
// at runtime anyway.
out.shouldContain(msg);
} else {
out.shouldNotContain(msg);
}
}
}