8283574: Use Klass::_id for type checks in the C++ code

Reviewed-by: tschatzl, kbarrett
This commit is contained in:
Stefan Karlsson 2022-03-24 06:02:09 +00:00
parent 5cf580e0fb
commit af18b1111a
11 changed files with 40 additions and 65 deletions

View File

@ -138,7 +138,7 @@ inline void G1FullGCMarker::follow_object(oop obj) {
} else {
obj->oop_iterate(mark_closure());
if (VerifyDuringGC) {
if (obj->is_instance() && InstanceKlass::cast(obj->klass())->is_reference_instance_klass()) {
if (obj->is_instanceRef()) {
return;
}
_verify_closure.set_containing_obj(obj);

View File

@ -43,7 +43,7 @@ public:
static const KlassID ID = InstanceClassLoaderKlassID;
private:
InstanceClassLoaderKlass(const ClassFileParser& parser) : InstanceKlass(parser, InstanceKlass::_kind_class_loader, ID) {}
InstanceClassLoaderKlass(const ClassFileParser& parser) : InstanceKlass(parser, ID) {}
public:
InstanceClassLoaderKlass() { assert(DumpSharedSpaces || UseSharedSpaces, "only for CDS"); }

View File

@ -442,13 +442,12 @@ InstanceKlass* InstanceKlass::allocate_instance_klass(const ClassFileParser& par
if (class_name == vmSymbols::java_lang_Class()) {
// mirror
ik = new (loader_data, size, THREAD) InstanceMirrorKlass(parser);
}
else if (is_class_loader(class_name, parser)) {
} else if (is_class_loader(class_name, parser)) {
// class loader
ik = new (loader_data, size, THREAD) InstanceClassLoaderKlass(parser);
} else {
// normal
ik = new (loader_data, size, THREAD) InstanceKlass(parser, InstanceKlass::_kind_other);
ik = new (loader_data, size, THREAD) InstanceKlass(parser);
}
} else {
// reference
@ -486,7 +485,7 @@ Array<int>* InstanceKlass::create_new_default_vtable_indices(int len, TRAPS) {
return vtable_indices;
}
InstanceKlass::InstanceKlass(const ClassFileParser& parser, unsigned kind, KlassID id) :
InstanceKlass::InstanceKlass(const ClassFileParser& parser, KlassID id) :
Klass(id),
_nest_members(NULL),
_nest_host(NULL),
@ -501,7 +500,6 @@ InstanceKlass::InstanceKlass(const ClassFileParser& parser, unsigned kind, Klass
_init_thread(NULL)
{
set_vtable_length(parser.vtable_size());
set_kind(kind);
set_access_flags(parser.access_flags());
if (parser.is_hidden()) set_is_hidden();
set_layout_helper(Klass::instance_layout_helper(parser.layout_size(),

View File

@ -136,7 +136,7 @@ class InstanceKlass: public Klass {
static const KlassID ID = InstanceKlassID;
protected:
InstanceKlass(const ClassFileParser& parser, unsigned kind, KlassID id = ID);
InstanceKlass(const ClassFileParser& parser, KlassID id = ID);
public:
InstanceKlass() { assert(DumpSharedSpaces || UseSharedSpaces, "only for CDS"); }
@ -229,15 +229,7 @@ class InstanceKlass: public Klass {
// _idnum_allocated_count.
u1 _init_state; // state of class
// This can be used to quickly discriminate among the four kinds of
// InstanceKlass. This should be an enum (?)
static const unsigned _kind_other = 0; // concrete InstanceKlass
static const unsigned _kind_reference = 1; // InstanceRefKlass
static const unsigned _kind_class_loader = 2; // InstanceClassLoaderKlass
static const unsigned _kind_mirror = 3; // InstanceMirrorKlass
u1 _reference_type; // reference type
u1 _kind; // kind of InstanceKlass
enum {
_misc_rewritten = 1 << 0, // methods rewritten.
@ -787,24 +779,8 @@ public:
void set_has_resolved_methods() {
_access_flags.set_has_resolved_methods();
}
private:
void set_kind(unsigned kind) {
_kind = (u1)kind;
}
bool is_kind(unsigned desired) const {
return _kind == (u1)desired;
}
public:
// Other is anything that is not one of the more specialized kinds of InstanceKlass.
bool is_other_instance_klass() const { return is_kind(_kind_other); }
bool is_reference_instance_klass() const { return is_kind(_kind_reference); }
bool is_mirror_instance_klass() const { return is_kind(_kind_mirror); }
bool is_class_loader_instance_klass() const { return is_kind(_kind_class_loader); }
#if INCLUDE_JVMTI
void init_previous_versions() {

View File

@ -50,7 +50,7 @@ class InstanceMirrorKlass: public InstanceKlass {
private:
static int _offset_of_static_fields;
InstanceMirrorKlass(const ClassFileParser& parser) : InstanceKlass(parser, InstanceKlass::_kind_mirror, ID) {}
InstanceMirrorKlass(const ClassFileParser& parser) : InstanceKlass(parser, ID) {}
public:
InstanceMirrorKlass() { assert(DumpSharedSpaces || UseSharedSpaces, "only for CDS"); }
@ -60,7 +60,7 @@ class InstanceMirrorKlass: public InstanceKlass {
}
static const InstanceMirrorKlass* cast(const Klass* k) {
assert(InstanceKlass::cast(k)->is_mirror_instance_klass(), "cast to InstanceMirrorKlass");
assert(k->is_mirror_instance_klass(), "cast to InstanceMirrorKlass");
return static_cast<const InstanceMirrorKlass*>(k);
}

View File

@ -87,7 +87,6 @@ void InstanceRefKlass::oop_verify_on(oop obj, outputStream* st) {
oop next = java_lang_ref_Reference::next(obj);
if (next != NULL) {
guarantee(oopDesc::is_oop(next), "next field should be an oop");
guarantee(next->is_instance(), "next field should be an instance");
guarantee(InstanceKlass::cast(next->klass())->is_reference_instance_klass(), "next field verify failed");
guarantee(next->is_instanceRef(), "next field verify failed");
}
}

View File

@ -53,7 +53,7 @@ class InstanceRefKlass: public InstanceKlass {
static const KlassID ID = InstanceRefKlassID;
private:
InstanceRefKlass(const ClassFileParser& parser) : InstanceKlass(parser, InstanceKlass::_kind_reference, ID) {}
InstanceRefKlass(const ClassFileParser& parser) : InstanceKlass(parser, ID) {}
public:
InstanceRefKlass() { assert(DumpSharedSpaces || UseSharedSpaces, "only for CDS"); }

View File

@ -614,18 +614,16 @@ protected:
}
public:
#endif
inline bool is_instance_klass() const { return assert_same_query(
layout_helper_is_instance(layout_helper()),
is_instance_klass_slow()); }
inline bool is_array_klass() const { return assert_same_query(
layout_helper_is_array(layout_helper()),
is_array_klass_slow()); }
inline bool is_objArray_klass() const { return assert_same_query(
layout_helper_is_objArray(layout_helper()),
is_objArray_klass_slow()); }
inline bool is_typeArray_klass() const { return assert_same_query(
layout_helper_is_typeArray(layout_helper()),
is_typeArray_klass_slow()); }
bool is_instance_klass() const { return assert_same_query(_id <= InstanceClassLoaderKlassID, is_instance_klass_slow()); }
// Other is anything that is not one of the more specialized kinds of InstanceKlass.
bool is_other_instance_klass() const { return _id == InstanceKlassID; }
bool is_reference_instance_klass() const { return _id == InstanceRefKlassID; }
bool is_mirror_instance_klass() const { return _id == InstanceMirrorKlassID; }
bool is_class_loader_instance_klass() const { return _id == InstanceClassLoaderKlassID; }
bool is_array_klass() const { return assert_same_query( _id >= TypeArrayKlassID, is_array_klass_slow()); }
bool is_objArray_klass() const { return assert_same_query( _id == ObjArrayKlassID, is_objArray_klass_slow()); }
bool is_typeArray_klass() const { return assert_same_query( _id == TypeArrayKlassID, is_typeArray_klass_slow()); }
#undef assert_same_query
// Access flags

View File

@ -134,10 +134,11 @@ void VerifyOopClosure::do_oop(oop* p) { VerifyOopClosure::do_oop_work(p);
void VerifyOopClosure::do_oop(narrowOop* p) { VerifyOopClosure::do_oop_work(p); }
// type test operations that doesn't require inclusion of oop.inline.hpp.
bool oopDesc::is_instance_noinline() const { return is_instance(); }
bool oopDesc::is_array_noinline() const { return is_array(); }
bool oopDesc::is_objArray_noinline() const { return is_objArray(); }
bool oopDesc::is_typeArray_noinline() const { return is_typeArray(); }
bool oopDesc::is_instance_noinline() const { return is_instance(); }
bool oopDesc::is_instanceRef_noinline() const { return is_instanceRef(); }
bool oopDesc::is_array_noinline() const { return is_array(); }
bool oopDesc::is_objArray_noinline() const { return is_objArray(); }
bool oopDesc::is_typeArray_noinline() const { return is_typeArray(); }
bool oopDesc::has_klass_gap() {
// Only has a klass gap when compressed class pointers are used.

View File

@ -107,16 +107,18 @@ class oopDesc {
inline size_t size_given_klass(Klass* klass);
// type test operations (inlined in oop.inline.hpp)
inline bool is_instance() const;
inline bool is_array() const;
inline bool is_objArray() const;
inline bool is_typeArray() const;
inline bool is_instance() const;
inline bool is_instanceRef() const;
inline bool is_array() const;
inline bool is_objArray() const;
inline bool is_typeArray() const;
// type test operations that don't require inclusion of oop.inline.hpp.
bool is_instance_noinline() const;
bool is_array_noinline() const;
bool is_objArray_noinline() const;
bool is_typeArray_noinline() const;
bool is_instance_noinline() const;
bool is_instanceRef_noinline() const;
bool is_array_noinline() const;
bool is_objArray_noinline() const;
bool is_typeArray_noinline() const;
protected:
inline oop as_oop() const { return const_cast<oopDesc*>(this); }

View File

@ -195,10 +195,11 @@ size_t oopDesc::size_given_klass(Klass* klass) {
return s;
}
bool oopDesc::is_instance() const { return klass()->is_instance_klass(); }
bool oopDesc::is_array() const { return klass()->is_array_klass(); }
bool oopDesc::is_objArray() const { return klass()->is_objArray_klass(); }
bool oopDesc::is_typeArray() const { return klass()->is_typeArray_klass(); }
bool oopDesc::is_instance() const { return klass()->is_instance_klass(); }
bool oopDesc::is_instanceRef() const { return klass()->is_reference_instance_klass(); }
bool oopDesc::is_array() const { return klass()->is_array_klass(); }
bool oopDesc::is_objArray() const { return klass()->is_objArray_klass(); }
bool oopDesc::is_typeArray() const { return klass()->is_typeArray_klass(); }
template<typename T>
T* oopDesc::field_addr(int offset) const { return reinterpret_cast<T*>(cast_from_oop<intptr_t>(as_oop()) + offset); }