mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-20 15:25:27 +00:00
8263399: CDS should archive only classes allowed by module system
Reviewed-by: ccheung, minqi
This commit is contained in:
parent
9c84899da4
commit
da9ead5e7f
@ -579,34 +579,15 @@ Klass* ClassListParser::load_current_class(TRAPS) {
|
||||
vmSymbols::loadClass_name(),
|
||||
vmSymbols::string_class_signature(),
|
||||
ext_class_name,
|
||||
THREAD); // <-- failure is handled below
|
||||
CHECK_NULL);
|
||||
} else {
|
||||
// array classes are not supported in class list.
|
||||
THROW_NULL(vmSymbols::java_lang_ClassNotFoundException());
|
||||
}
|
||||
assert(result.get_type() == T_OBJECT, "just checking");
|
||||
oop obj = (oop) result.get_jobject();
|
||||
if (!HAS_PENDING_EXCEPTION && (obj != NULL)) {
|
||||
klass = java_lang_Class::as_Klass(obj);
|
||||
} else { // load classes in bootclasspath/a
|
||||
if (HAS_PENDING_EXCEPTION) {
|
||||
ArchiveUtils::check_for_oom(PENDING_EXCEPTION); // exit on OOM
|
||||
CLEAR_PENDING_EXCEPTION;
|
||||
}
|
||||
|
||||
if (non_array) {
|
||||
Klass* k = SystemDictionary::resolve_or_null(class_name_symbol, CHECK_NULL);
|
||||
if (k != NULL) {
|
||||
klass = k;
|
||||
} else {
|
||||
if (!HAS_PENDING_EXCEPTION) {
|
||||
THROW_NULL(vmSymbols::java_lang_ClassNotFoundException());
|
||||
} else {
|
||||
ArchiveUtils::check_for_oom(PENDING_EXCEPTION); // exit on OOM
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
assert(obj != NULL, "jdk.internal.loader.BuiltinClassLoader::loadClass never returns null");
|
||||
klass = java_lang_Class::as_Klass(obj);
|
||||
} else {
|
||||
// If "source:" tag is specified, all super class and super interfaces must be specified in the
|
||||
// class list file.
|
||||
|
||||
@ -708,10 +708,15 @@ int MetaspaceShared::preload_classes(const char* class_list_path, TRAPS) {
|
||||
}
|
||||
Klass* klass = parser.load_current_class(THREAD);
|
||||
if (HAS_PENDING_EXCEPTION) {
|
||||
if (klass == NULL &&
|
||||
(PENDING_EXCEPTION->klass()->name() == vmSymbols::java_lang_ClassNotFoundException())) {
|
||||
// print a warning only when the pending exception is class not found
|
||||
log_warning(cds)("Preload Warning: Cannot find %s", parser.current_class_name());
|
||||
if (klass == NULL) {
|
||||
Symbol* exception_klass_name = PENDING_EXCEPTION->klass()->name();
|
||||
if (exception_klass_name == vmSymbols::java_lang_ClassNotFoundException() ||
|
||||
exception_klass_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
|
||||
// print a warning only when the class is not found or has a version that's too old.
|
||||
// Todo: the CDS test cases expect "Cannot find" in the log, but we should consider
|
||||
// distinguishing the different failure modes.
|
||||
log_warning(cds)("Preload Warning: Cannot find %s", parser.current_class_name());
|
||||
}
|
||||
}
|
||||
CLEAR_PENDING_EXCEPTION;
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -48,8 +48,8 @@ public class BootAppendTests {
|
||||
private static final Path CLASSES_DIR = Paths.get("classes");
|
||||
|
||||
private static final String MAIN_CLASS = "jdk.test.Main";
|
||||
private static final String APP_MODULE_CLASS = "com/sun/tools/javac/MyMain";
|
||||
private static final String BOOT_APPEND_MODULE_CLASS = "sun/nio/cs/ext/MyClass";
|
||||
private static final String APP_MODULE_CLASS = "com/sun/tools/javac/MyMain"; // in module jdk.compiler (app loader)
|
||||
private static final String BOOT_APPEND_MODULE_CLASS = "sun/nio/cs/ext/MyClass"; // in module jdk.charsets (platform loader)
|
||||
private static final String BOOT_APPEND_CLASS = "sun/nio/cs/ext1/MyClass";
|
||||
private static final String[] ARCHIVE_CLASSES =
|
||||
{APP_MODULE_CLASS, BOOT_APPEND_MODULE_CLASS, BOOT_APPEND_CLASS};
|
||||
@ -104,10 +104,21 @@ public class BootAppendTests {
|
||||
appJar, TestCommon.list(ARCHIVE_CLASSES), "-Xbootclasspath/a:" + bootAppendJar);
|
||||
TestCommon.checkDump(output1);
|
||||
|
||||
if (!TestCommon.isUnableToMap(output1)) {
|
||||
if (!TestCommon.isUnableToMap(output1) &&
|
||||
!CDSTestUtils.DYNAMIC_DUMP // these messages aren't available in dynamic dump model
|
||||
) {
|
||||
// Make sure all the classes were successfully archived.
|
||||
for (String archiveClass : ARCHIVE_CLASSES) {
|
||||
output1.shouldNotContain("Preload Warning: Cannot find " + archiveClass);
|
||||
String msg = "Preload Warning: Cannot find " + archiveClass;
|
||||
if (archiveClass.equals(BOOT_APPEND_CLASS)) {
|
||||
// This class is in a package (sun/nio/cs/ext1) that doesn't belong to any
|
||||
// of the built-in modules. We can load it from -Xbootclasspath/a:
|
||||
output1.shouldNotContain(msg);
|
||||
} else {
|
||||
// This class belongs a package that belongs to a built-in module.
|
||||
// We shouldn't load it from -Xbootclasspath/a:
|
||||
output1.shouldContain(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user