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 { } else {
obj->oop_iterate(mark_closure()); obj->oop_iterate(mark_closure());
if (VerifyDuringGC) { if (VerifyDuringGC) {
if (obj->is_instance() && InstanceKlass::cast(obj->klass())->is_reference_instance_klass()) { if (obj->is_instanceRef()) {
return; return;
} }
_verify_closure.set_containing_obj(obj); _verify_closure.set_containing_obj(obj);

View File

@ -43,7 +43,7 @@ public:
static const KlassID ID = InstanceClassLoaderKlassID; static const KlassID ID = InstanceClassLoaderKlassID;
private: private:
InstanceClassLoaderKlass(const ClassFileParser& parser) : InstanceKlass(parser, InstanceKlass::_kind_class_loader, ID) {} InstanceClassLoaderKlass(const ClassFileParser& parser) : InstanceKlass(parser, ID) {}
public: public:
InstanceClassLoaderKlass() { assert(DumpSharedSpaces || UseSharedSpaces, "only for CDS"); } 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()) { if (class_name == vmSymbols::java_lang_Class()) {
// mirror // mirror
ik = new (loader_data, size, THREAD) InstanceMirrorKlass(parser); 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 // class loader
ik = new (loader_data, size, THREAD) InstanceClassLoaderKlass(parser); ik = new (loader_data, size, THREAD) InstanceClassLoaderKlass(parser);
} else { } else {
// normal // normal
ik = new (loader_data, size, THREAD) InstanceKlass(parser, InstanceKlass::_kind_other); ik = new (loader_data, size, THREAD) InstanceKlass(parser);
} }
} else { } else {
// reference // reference
@ -486,7 +485,7 @@ Array<int>* InstanceKlass::create_new_default_vtable_indices(int len, TRAPS) {
return vtable_indices; return vtable_indices;
} }
InstanceKlass::InstanceKlass(const ClassFileParser& parser, unsigned kind, KlassID id) : InstanceKlass::InstanceKlass(const ClassFileParser& parser, KlassID id) :
Klass(id), Klass(id),
_nest_members(NULL), _nest_members(NULL),
_nest_host(NULL), _nest_host(NULL),
@ -501,7 +500,6 @@ InstanceKlass::InstanceKlass(const ClassFileParser& parser, unsigned kind, Klass
_init_thread(NULL) _init_thread(NULL)
{ {
set_vtable_length(parser.vtable_size()); set_vtable_length(parser.vtable_size());
set_kind(kind);
set_access_flags(parser.access_flags()); set_access_flags(parser.access_flags());
if (parser.is_hidden()) set_is_hidden(); if (parser.is_hidden()) set_is_hidden();
set_layout_helper(Klass::instance_layout_helper(parser.layout_size(), 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; static const KlassID ID = InstanceKlassID;
protected: protected:
InstanceKlass(const ClassFileParser& parser, unsigned kind, KlassID id = ID); InstanceKlass(const ClassFileParser& parser, KlassID id = ID);
public: public:
InstanceKlass() { assert(DumpSharedSpaces || UseSharedSpaces, "only for CDS"); } InstanceKlass() { assert(DumpSharedSpaces || UseSharedSpaces, "only for CDS"); }
@ -229,15 +229,7 @@ class InstanceKlass: public Klass {
// _idnum_allocated_count. // _idnum_allocated_count.
u1 _init_state; // state of class 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 _reference_type; // reference type
u1 _kind; // kind of InstanceKlass
enum { enum {
_misc_rewritten = 1 << 0, // methods rewritten. _misc_rewritten = 1 << 0, // methods rewritten.
@ -787,24 +779,8 @@ public:
void set_has_resolved_methods() { void set_has_resolved_methods() {
_access_flags.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: 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 #if INCLUDE_JVMTI
void init_previous_versions() { void init_previous_versions() {

View File

@ -50,7 +50,7 @@ class InstanceMirrorKlass: public InstanceKlass {
private: private:
static int _offset_of_static_fields; static int _offset_of_static_fields;
InstanceMirrorKlass(const ClassFileParser& parser) : InstanceKlass(parser, InstanceKlass::_kind_mirror, ID) {} InstanceMirrorKlass(const ClassFileParser& parser) : InstanceKlass(parser, ID) {}
public: public:
InstanceMirrorKlass() { assert(DumpSharedSpaces || UseSharedSpaces, "only for CDS"); } InstanceMirrorKlass() { assert(DumpSharedSpaces || UseSharedSpaces, "only for CDS"); }
@ -60,7 +60,7 @@ class InstanceMirrorKlass: public InstanceKlass {
} }
static const InstanceMirrorKlass* cast(const Klass* k) { 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); 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); oop next = java_lang_ref_Reference::next(obj);
if (next != NULL) { if (next != NULL) {
guarantee(oopDesc::is_oop(next), "next field should be an oop"); guarantee(oopDesc::is_oop(next), "next field should be an oop");
guarantee(next->is_instance(), "next field should be an instance"); guarantee(next->is_instanceRef(), "next field verify failed");
guarantee(InstanceKlass::cast(next->klass())->is_reference_instance_klass(), "next field verify failed");
} }
} }

View File

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

View File

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

View File

@ -135,6 +135,7 @@ void VerifyOopClosure::do_oop(narrowOop* p) { VerifyOopClosure::do_oop_work(p);
// type test operations that doesn't require inclusion of oop.inline.hpp. // type test operations that doesn't require inclusion of oop.inline.hpp.
bool oopDesc::is_instance_noinline() const { return is_instance(); } 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_array_noinline() const { return is_array(); }
bool oopDesc::is_objArray_noinline() const { return is_objArray(); } bool oopDesc::is_objArray_noinline() const { return is_objArray(); }
bool oopDesc::is_typeArray_noinline() const { return is_typeArray(); } bool oopDesc::is_typeArray_noinline() const { return is_typeArray(); }

View File

@ -108,12 +108,14 @@ class oopDesc {
// type test operations (inlined in oop.inline.hpp) // type test operations (inlined in oop.inline.hpp)
inline bool is_instance() const; inline bool is_instance() const;
inline bool is_instanceRef() const;
inline bool is_array() const; inline bool is_array() const;
inline bool is_objArray() const; inline bool is_objArray() const;
inline bool is_typeArray() const; inline bool is_typeArray() const;
// type test operations that don't require inclusion of oop.inline.hpp. // type test operations that don't require inclusion of oop.inline.hpp.
bool is_instance_noinline() const; bool is_instance_noinline() const;
bool is_instanceRef_noinline() const;
bool is_array_noinline() const; bool is_array_noinline() const;
bool is_objArray_noinline() const; bool is_objArray_noinline() const;
bool is_typeArray_noinline() const; bool is_typeArray_noinline() const;

View File

@ -196,6 +196,7 @@ size_t oopDesc::size_given_klass(Klass* klass) {
} }
bool oopDesc::is_instance() const { return klass()->is_instance_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_array() const { return klass()->is_array_klass(); }
bool oopDesc::is_objArray() const { return klass()->is_objArray_klass(); } bool oopDesc::is_objArray() const { return klass()->is_objArray_klass(); }
bool oopDesc::is_typeArray() const { return klass()->is_typeArray_klass(); } bool oopDesc::is_typeArray() const { return klass()->is_typeArray_klass(); }