When a new subtype of MetaData is added, CPP_VTABLE_PATCH_TYPES_DO needs to be updated:
http://hg.openjdk.java.net/jdk/jdk/file/0348e9be94d1/src/hotspot/share/memory/metaspaceShared.cpp#l673
If a new InstanceFooKlass type is added.
#define CPP_VTABLE_PATCH_TYPES_DO(f) \
f(ConstantPool) \
f(InstanceKlass) \
f(InstanceClassLoaderKlass) \
f(InstanceMirrorKlass) \
f(InstanceRefKlass) \
>>>> must add a new case here f(InstanceFooKlass)
f(Method) \
f(ObjArrayKlass) \
f(TypeArrayKlass)
Also MetaspaceShared::fix_cpp_vtable_for_dynamic_archive need to be updated:
case MetaspaceObj::ClassType:
{
Klass* k = (Klass*)obj;
assert(k->is_klass(), "must be");
if (k->is_instance_klass()) {
InstanceKlass* ik = InstanceKlass::cast(k);
if (ik->is_class_loader_instance_klass()) {
kind = InstanceClassLoaderKlass_Kind;
} else if (ik->is_reference_instance_klass()) {
kind = InstanceRefKlass_Kind;
} else if (ik->is_mirror_instance_klass()) {
kind = InstanceMirrorKlass_Kind;
>>> must add a check for ik->is_foo_instance_klass()
} else {
kind = InstanceKlass_Kind;
}
} else if (k->is_typeArray_klass()) {
kind = TypeArrayKlass_Kind;
} else {
assert(k->is_objArray_klass(), "must be");
kind = ObjArrayKlass_Kind;
}
}
(without the new check, instances of InstanceFooKlass will be incorrectly given an InstanceKlass_Kind because k->is_instance_klass() returns true).
Recently, new subtypes of MetaData have been added in the valhalla and loom projects, but it was not obvoius that the above needed to be updated, leading to mysterious crashes when running with a CDS archive.
We need to add asserts to make sure CPP_VTABLE_PATCH_TYPES_DO is updated properly, and change fix_cpp_vtable_for_dynamic_archive to use a more precise check than k->is_instance_klass().
http://hg.openjdk.java.net/jdk/jdk/file/0348e9be94d1/src/hotspot/share/memory/metaspaceShared.cpp#l673
If a new InstanceFooKlass type is added.
#define CPP_VTABLE_PATCH_TYPES_DO(f) \
f(ConstantPool) \
f(InstanceKlass) \
f(InstanceClassLoaderKlass) \
f(InstanceMirrorKlass) \
f(InstanceRefKlass) \
>>>> must add a new case here f(InstanceFooKlass)
f(Method) \
f(ObjArrayKlass) \
f(TypeArrayKlass)
Also MetaspaceShared::fix_cpp_vtable_for_dynamic_archive need to be updated:
case MetaspaceObj::ClassType:
{
Klass* k = (Klass*)obj;
assert(k->is_klass(), "must be");
if (k->is_instance_klass()) {
InstanceKlass* ik = InstanceKlass::cast(k);
if (ik->is_class_loader_instance_klass()) {
kind = InstanceClassLoaderKlass_Kind;
} else if (ik->is_reference_instance_klass()) {
kind = InstanceRefKlass_Kind;
} else if (ik->is_mirror_instance_klass()) {
kind = InstanceMirrorKlass_Kind;
>>> must add a check for ik->is_foo_instance_klass()
} else {
kind = InstanceKlass_Kind;
}
} else if (k->is_typeArray_klass()) {
kind = TypeArrayKlass_Kind;
} else {
assert(k->is_objArray_klass(), "must be");
kind = ObjArrayKlass_Kind;
}
}
(without the new check, instances of InstanceFooKlass will be incorrectly given an InstanceKlass_Kind because k->is_instance_klass() returns true).
Recently, new subtypes of MetaData have been added in the valhalla and loom projects, but it was not obvoius that the above needed to be updated, leading to mysterious crashes when running with a CDS archive.
We need to add asserts to make sure CPP_VTABLE_PATCH_TYPES_DO is updated properly, and change fix_cpp_vtable_for_dynamic_archive to use a more precise check than k->is_instance_klass().
1.
|
Move CDS C++ vtable code to cppVtables.cpp | Resolved | Ioi Lam |