8266822: Rename MetaspaceShared::is_old_class to be more explicit about what "old" means

Reviewed-by: iklam, minqi, coleenp
This commit is contained in:
Calvin Cheung 2021-05-11 23:53:06 +00:00
parent 616244f43a
commit 57c6ba6e6b
7 changed files with 32 additions and 31 deletions

View File

@ -389,7 +389,7 @@ static void rewrite_nofast_bytecode(const methodHandle& method) {
void MetaspaceShared::rewrite_nofast_bytecodes_and_calculate_fingerprints(Thread* thread, InstanceKlass* ik) {
for (int i = 0; i < ik->methods()->length(); i++) {
methodHandle m(thread, ik->methods()->at(i));
if (!is_old_class(ik)) {
if (!ik->has_old_class_version()) {
rewrite_nofast_bytecode(m);
}
Fingerprinter fp(m);
@ -574,31 +574,10 @@ public:
ClassLoaderData* cld_at(int index) { return _loaded_cld.at(index); }
};
// Check if a class or its super class/interface is old.
bool MetaspaceShared::is_old_class(InstanceKlass* ik) {
if (ik == NULL) {
return false;
}
if (ik->major_version() < 50 /*JAVA_6_VERSION*/) {
return true;
}
if (is_old_class(ik->java_super())) {
return true;
}
Array<InstanceKlass*>* interfaces = ik->local_interfaces();
int len = interfaces->length();
for (int i = 0; i < len; i++) {
if (is_old_class(interfaces->at(i))) {
return true;
}
}
return false;
}
bool MetaspaceShared::linking_required(InstanceKlass* ik) {
// For static CDS dump, do not link old classes.
// For dynamic CDS dump, only link classes loaded by the builtin class loaders.
return DumpSharedSpaces ? !MetaspaceShared::is_old_class(ik) : !ik->is_shared_unregistered_class();
return DumpSharedSpaces ? !ik->has_old_class_version() : !ik->is_shared_unregistered_class();
}
bool MetaspaceShared::link_class_for_cds(InstanceKlass* ik, TRAPS) {
@ -778,7 +757,7 @@ bool MetaspaceShared::try_link_class(Thread* current, InstanceKlass* ik) {
ExceptionMark em(current);
Thread* THREAD = current; // For exception macros.
Arguments::assert_is_dumping_archive();
if (ik->is_loaded() && !ik->is_linked() && !MetaspaceShared::is_old_class(ik) &&
if (ik->is_loaded() && !ik->is_linked() && !ik->has_old_class_version() &&
!SystemDictionaryShared::has_class_failed_verification(ik)) {
bool saved = BytecodeVerificationLocal;
if (ik->is_shared_unregistered_class() && ik->class_loader() == NULL) {

View File

@ -137,7 +137,6 @@ public:
static void link_and_cleanup_shared_classes(TRAPS) NOT_CDS_RETURN;
static bool link_class_for_cds(InstanceKlass* ik, TRAPS) NOT_CDS_RETURN_(false);
static bool linking_required(InstanceKlass* ik) NOT_CDS_RETURN_(false);
static bool is_old_class(InstanceKlass* ik) NOT_CDS_RETURN_(false);
#if INCLUDE_CDS
// Alignment for the 2 core CDS regions (RW/RO) only.

View File

@ -1382,7 +1382,7 @@ bool SystemDictionaryShared::should_be_excluded(InstanceKlass* k) {
warn_excluded(k, "Failed verification");
return true;
} else {
if (!MetaspaceShared::is_old_class(k)) {
if (!k->has_old_class_version()) {
warn_excluded(k, "Not linked");
return true;
}
@ -1397,7 +1397,7 @@ bool SystemDictionaryShared::should_be_excluded(InstanceKlass* k) {
return true;
}
if (MetaspaceShared::is_old_class(k) && k->is_linked()) {
if (k->has_old_class_version() && k->is_linked()) {
warn_excluded(k, "Old class has been linked");
return true;
}

View File

@ -571,7 +571,7 @@ void Rewriter::rewrite(InstanceKlass* klass, TRAPS) {
#if INCLUDE_CDS
if (klass->is_shared()) {
assert(!klass->is_rewritten(), "rewritten shared classes cannot be rewritten again");
assert(MetaspaceShared::is_old_class(klass), "only shared old classes aren't rewritten");
assert(klass->has_old_class_version(), "only shared old classes aren't rewritten");
}
#endif // INCLUDE_CDS
ResourceMark rm(THREAD);

View File

@ -2429,7 +2429,7 @@ void InstanceKlass::metaspace_pointers_do(MetaspaceClosure* it) {
void InstanceKlass::remove_unshareable_info() {
if (MetaspaceShared::is_old_class(this)) {
if (has_old_class_version()) {
// Set the old class bit.
set_is_shared_old_klass();
}
@ -2568,6 +2568,28 @@ void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handl
}
}
// Check if a class or any of its supertypes has a version older than 50.
// CDS will not perform verification of old classes during dump time because
// without changing the old verifier, the verification constraint cannot be
// retrieved during dump time.
// Verification of archived old classes will be performed during run time.
bool InstanceKlass::has_old_class_version() const {
if (major_version() < 50 /*JAVA_6_VERSION*/) {
return true;
}
if (java_super() != NULL && java_super()->has_old_class_version()) {
return true;
}
Array<InstanceKlass*>* interfaces = local_interfaces();
int len = interfaces->length();
for (int i = 0; i < len; i++) {
if (interfaces->at(i)->has_old_class_version()) {
return true;
}
}
return false;
}
void InstanceKlass::set_shared_class_loader_type(s2 loader_type) {
switch (loader_type) {
case ClassLoader::BOOT_LOADER:

View File

@ -1250,6 +1250,7 @@ public:
virtual void remove_java_mirror();
void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, PackageEntry* pkg_entry, TRAPS);
void init_shared_package_entry();
bool has_old_class_version() const;
jint compute_modifier_flags() const;

View File

@ -1094,8 +1094,8 @@ void itableMethodEntry::initialize(InstanceKlass* klass, Method* m) {
#ifdef ASSERT
if (MetaspaceShared::is_in_shared_metaspace((void*)&_method) &&
!MetaspaceShared::remapped_readwrite() &&
!MetaspaceShared::is_old_class(m->method_holder()) &&
!MetaspaceShared::is_old_class(klass)) {
!m->method_holder()->has_old_class_version() &&
!klass->has_old_class_version()) {
// At runtime initialize_itable is rerun as part of link_class_impl()
// for a shared class loaded by the non-boot loader.
// The dumptime itable method entry should be the same as the runtime entry.