Skip to content

Commit 2427c90

Browse files
committed
8366024: Remove unnecessary InstanceKlass::cast()
Reviewed-by: coleenp, dholmes
1 parent 80ab094 commit 2427c90

File tree

16 files changed

+83
-99
lines changed

16 files changed

+83
-99
lines changed

src/hotspot/share/classfile/classFileParser.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4092,31 +4092,29 @@ static Array<InstanceKlass*>* compute_transitive_interfaces(const InstanceKlass*
40924092

40934093
void ClassFileParser::check_super_class_access(const InstanceKlass* this_klass, TRAPS) {
40944094
assert(this_klass != nullptr, "invariant");
4095-
const Klass* const super = this_klass->super();
4095+
const InstanceKlass* const super = this_klass->java_super();
40964096

40974097
if (super != nullptr) {
4098-
const InstanceKlass* super_ik = InstanceKlass::cast(super);
4099-
41004098
if (super->is_final()) {
4101-
classfile_icce_error("class %s cannot inherit from final class %s", super_ik, THREAD);
4099+
classfile_icce_error("class %s cannot inherit from final class %s", super, THREAD);
41024100
return;
41034101
}
41044102

4105-
if (super_ik->is_sealed()) {
4103+
if (super->is_sealed()) {
41064104
stringStream ss;
41074105
ResourceMark rm(THREAD);
4108-
if (!super_ik->has_as_permitted_subclass(this_klass, ss)) {
4106+
if (!super->has_as_permitted_subclass(this_klass, ss)) {
41094107
classfile_icce_error(ss.as_string(), THREAD);
41104108
return;
41114109
}
41124110
}
41134111

41144112
Reflection::VerifyClassAccessResults vca_result =
4115-
Reflection::verify_class_access(this_klass, InstanceKlass::cast(super), false);
4113+
Reflection::verify_class_access(this_klass, super, false);
41164114
if (vca_result != Reflection::ACCESS_OK) {
41174115
ResourceMark rm(THREAD);
41184116
char* msg = Reflection::verify_class_access_msg(this_klass,
4119-
InstanceKlass::cast(super),
4117+
super,
41204118
vca_result);
41214119

41224120
// Names are all known to be < 64k so we know this formatted message is not excessively large.
@@ -4218,7 +4216,7 @@ static void check_final_method_override(const InstanceKlass* this_klass, TRAPS)
42184216
// skip supers that don't have final methods.
42194217
if (k->has_final_method()) {
42204218
// lookup a matching method in the super class hierarchy
4221-
super_m = InstanceKlass::cast(k)->lookup_method(name, signature);
4219+
super_m = k->lookup_method(name, signature);
42224220
if (super_m == nullptr) {
42234221
break; // didn't find any match; get out
42244222
}

src/hotspot/share/classfile/fieldLayoutBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ void FieldLayout::reconstruct_layout(const InstanceKlass* ik, bool& has_instance
316316
block->set_offset(fs.offset());
317317
all_fields->append(block);
318318
}
319-
ik = ik->super() == nullptr ? nullptr : InstanceKlass::cast(ik->super());
319+
ik = ik->java_super() == nullptr ? nullptr : ik->java_super();
320320
}
321321
assert(last_offset == -1 || last_offset > 0, "Sanity");
322322
if (last_offset > 0 &&

src/hotspot/share/classfile/systemDictionary.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ bool SystemDictionary::check_shared_class_super_types(InstanceKlass* ik, Handle
10491049
// load <ik> from the shared archive.
10501050

10511051
if (ik->super() != nullptr) {
1052-
bool check_super = check_shared_class_super_type(ik, InstanceKlass::cast(ik->super()),
1052+
bool check_super = check_shared_class_super_type(ik, ik->java_super(),
10531053
class_loader, true,
10541054
CHECK_false);
10551055
if (!check_super) {

src/hotspot/share/classfile/vmClasses.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,10 @@ void vmClasses::resolve_shared_class(InstanceKlass* klass, ClassLoaderData* load
225225
}
226226

227227
// add super and interfaces first
228-
Klass* super = klass->super();
228+
InstanceKlass* super = klass->java_super();
229229
if (super != nullptr && super->class_loader_data() == nullptr) {
230230
assert(super->is_instance_klass(), "Super should be instance klass");
231-
resolve_shared_class(InstanceKlass::cast(super), loader_data, domain, CHECK);
231+
resolve_shared_class(super, loader_data, domain, CHECK);
232232
}
233233

234234
Array<InstanceKlass*>* ifs = klass->local_interfaces();

src/hotspot/share/jfr/instrumentation/jfrEventClassTransformer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ static bool annotation_value(const InstanceKlass* ik, const Symbol* annotation_t
214214
if (has_annotation(ik, annotation_type, default_value, value)) {
215215
return true;
216216
}
217-
InstanceKlass* const super = InstanceKlass::cast(ik->super());
217+
InstanceKlass* const super = ik->java_super();
218218
return super != nullptr && JdkJfrEvent::is_a(super) ? annotation_value(super, annotation_type, default_value, value) : false;
219219
}
220220

src/hotspot/share/jfr/leakprofiler/chains/edgeUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const Symbol* EdgeUtils::field_name(const Edge& edge, jshort* modifiers) {
7676
}
7777
jfs.next();
7878
}
79-
ik = (const InstanceKlass*)ik->super();
79+
ik = ik->java_super();
8080
}
8181
*modifiers = 0;
8282
return nullptr;

src/hotspot/share/jvmci/jvmciCompilerToVM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2012,7 +2012,7 @@ C2V_VMENTRY_NULL(jobject, getInterfaces, (JNIEnv* env, jobject, ARGUMENT_PAIR(kl
20122012
JVMCIObjectArray interfaces = JVMCIENV->new_HotSpotResolvedObjectTypeImpl_array(size, JVMCI_CHECK_NULL);
20132013
for (int index = 0; index < size; index++) {
20142014
JVMCIKlassHandle klass(THREAD);
2015-
Klass* k = iklass->local_interfaces()->at(index);
2015+
InstanceKlass* k = iklass->local_interfaces()->at(index);
20162016
klass = k;
20172017
JVMCIObject type = JVMCIENV->get_jvmci_type(klass, JVMCI_CHECK_NULL);
20182018
JVMCIENV->put_object_at(interfaces, index, type);

src/hotspot/share/oops/instanceKlass.cpp

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data,
575575
}
576576

577577
void InstanceKlass::deallocate_interfaces(ClassLoaderData* loader_data,
578-
const Klass* super_klass,
578+
const InstanceKlass* super_klass,
579579
Array<InstanceKlass*>* local_interfaces,
580580
Array<InstanceKlass*>* transitive_interfaces) {
581581
// Only deallocate transitive interfaces if not empty, same as super class
@@ -584,7 +584,7 @@ void InstanceKlass::deallocate_interfaces(ClassLoaderData* loader_data,
584584
if (ti != Universe::the_empty_instance_klass_array() && ti != local_interfaces) {
585585
// check that the interfaces don't come from super class
586586
Array<InstanceKlass*>* sti = (super_klass == nullptr) ? nullptr :
587-
InstanceKlass::cast(super_klass)->transitive_interfaces();
587+
super_klass->transitive_interfaces();
588588
if (ti != sti && ti != nullptr && !ti->is_shared()) {
589589
MetadataFactory::free_array<InstanceKlass*>(loader_data, ti);
590590
}
@@ -677,7 +677,7 @@ void InstanceKlass::deallocate_contents(ClassLoaderData* loader_data) {
677677
}
678678
set_secondary_supers(nullptr, SECONDARY_SUPERS_BITMAP_EMPTY);
679679

680-
deallocate_interfaces(loader_data, super(), local_interfaces(), transitive_interfaces());
680+
deallocate_interfaces(loader_data, java_super(), local_interfaces(), transitive_interfaces());
681681
set_transitive_interfaces(nullptr);
682682
set_local_interfaces(nullptr);
683683

@@ -942,7 +942,7 @@ bool InstanceKlass::link_class_impl(TRAPS) {
942942
JavaThread* jt = THREAD;
943943

944944
// link super class before linking this class
945-
Klass* super_klass = super();
945+
InstanceKlass* super_klass = java_super();
946946
if (super_klass != nullptr) {
947947
if (super_klass->is_interface()) { // check if super class is an interface
948948
ResourceMark rm(THREAD);
@@ -957,8 +957,7 @@ bool InstanceKlass::link_class_impl(TRAPS) {
957957
return false;
958958
}
959959

960-
InstanceKlass* ik_super = InstanceKlass::cast(super_klass);
961-
ik_super->link_class_impl(CHECK_false);
960+
super_klass->link_class_impl(CHECK_false);
962961
}
963962

964963
// link all interfaces implemented by this class before linking this class
@@ -1805,15 +1804,15 @@ bool InstanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor*
18051804
Klass* InstanceKlass::find_interface_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
18061805
const int n = local_interfaces()->length();
18071806
for (int i = 0; i < n; i++) {
1808-
Klass* intf1 = local_interfaces()->at(i);
1807+
InstanceKlass* intf1 = local_interfaces()->at(i);
18091808
assert(intf1->is_interface(), "just checking type");
18101809
// search for field in current interface
1811-
if (InstanceKlass::cast(intf1)->find_local_field(name, sig, fd)) {
1810+
if (intf1->find_local_field(name, sig, fd)) {
18121811
assert(fd->is_static(), "interface field must be static");
18131812
return intf1;
18141813
}
18151814
// search for field in direct superinterfaces
1816-
Klass* intf2 = InstanceKlass::cast(intf1)->find_interface_field(name, sig, fd);
1815+
Klass* intf2 = intf1->find_interface_field(name, sig, fd);
18171816
if (intf2 != nullptr) return intf2;
18181817
}
18191818
// otherwise field lookup fails
@@ -1832,8 +1831,8 @@ Klass* InstanceKlass::find_field(Symbol* name, Symbol* sig, fieldDescriptor* fd)
18321831
if (intf != nullptr) return intf;
18331832
}
18341833
// 3) apply field lookup recursively if superclass exists
1835-
{ Klass* supr = super();
1836-
if (supr != nullptr) return InstanceKlass::cast(supr)->find_field(name, sig, fd);
1834+
{ InstanceKlass* supr = java_super();
1835+
if (supr != nullptr) return supr->find_field(name, sig, fd);
18371836
}
18381837
// 4) otherwise field lookup fails
18391838
return nullptr;
@@ -1852,8 +1851,8 @@ Klass* InstanceKlass::find_field(Symbol* name, Symbol* sig, bool is_static, fiel
18521851
if (intf != nullptr) return intf;
18531852
}
18541853
// 3) apply field lookup recursively if superclass exists
1855-
{ Klass* supr = super();
1856-
if (supr != nullptr) return InstanceKlass::cast(supr)->find_field(name, sig, is_static, fd);
1854+
{ InstanceKlass* supr = java_super();
1855+
if (supr != nullptr) return supr->find_field(name, sig, is_static, fd);
18571856
}
18581857
// 4) otherwise field lookup fails
18591858
return nullptr;
@@ -1872,12 +1871,12 @@ bool InstanceKlass::find_local_field_from_offset(int offset, bool is_static, fie
18721871

18731872

18741873
bool InstanceKlass::find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1875-
Klass* klass = const_cast<InstanceKlass*>(this);
1874+
const InstanceKlass* klass = this;
18761875
while (klass != nullptr) {
1877-
if (InstanceKlass::cast(klass)->find_local_field_from_offset(offset, is_static, fd)) {
1876+
if (klass->find_local_field_from_offset(offset, is_static, fd)) {
18781877
return true;
18791878
}
1880-
klass = klass->super();
1879+
klass = klass->java_super();
18811880
}
18821881
return false;
18831882
}
@@ -1920,7 +1919,7 @@ void InstanceKlass::do_local_static_fields(void f(fieldDescriptor*, Handle, TRAP
19201919
}
19211920

19221921
void InstanceKlass::do_nonstatic_fields(FieldClosure* cl) {
1923-
InstanceKlass* super = superklass();
1922+
InstanceKlass* super = java_super();
19241923
if (super != nullptr) {
19251924
super->do_nonstatic_fields(cl);
19261925
}
@@ -1937,7 +1936,7 @@ static int compare_fields_by_offset(FieldInfo* a, FieldInfo* b) {
19371936
}
19381937

19391938
void InstanceKlass::print_nonstatic_fields(FieldClosure* cl) {
1940-
InstanceKlass* super = superklass();
1939+
InstanceKlass* super = java_super();
19411940
if (super != nullptr) {
19421941
super->print_nonstatic_fields(cl);
19431942
}
@@ -2232,17 +2231,17 @@ Method* InstanceKlass::uncached_lookup_method(const Symbol* name,
22322231
OverpassLookupMode overpass_mode,
22332232
PrivateLookupMode private_mode) const {
22342233
OverpassLookupMode overpass_local_mode = overpass_mode;
2235-
const Klass* klass = this;
2234+
const InstanceKlass* klass = this;
22362235
while (klass != nullptr) {
2237-
Method* const method = InstanceKlass::cast(klass)->find_method_impl(name,
2238-
signature,
2239-
overpass_local_mode,
2240-
StaticLookupMode::find,
2241-
private_mode);
2236+
Method* const method = klass->find_method_impl(name,
2237+
signature,
2238+
overpass_local_mode,
2239+
StaticLookupMode::find,
2240+
private_mode);
22422241
if (method != nullptr) {
22432242
return method;
22442243
}
2245-
klass = klass->super();
2244+
klass = klass->java_super();
22462245
overpass_local_mode = OverpassLookupMode::skip; // Always ignore overpass methods in superclasses
22472246
}
22482247
return nullptr;
@@ -2252,12 +2251,12 @@ Method* InstanceKlass::uncached_lookup_method(const Symbol* name,
22522251
// search through class hierarchy and return true if this class or
22532252
// one of the superclasses was redefined
22542253
bool InstanceKlass::has_redefined_this_or_super() const {
2255-
const Klass* klass = this;
2254+
const InstanceKlass* klass = this;
22562255
while (klass != nullptr) {
2257-
if (InstanceKlass::cast(klass)->has_been_redefined()) {
2256+
if (klass->has_been_redefined()) {
22582257
return true;
22592258
}
2260-
klass = klass->super();
2259+
klass = klass->java_super();
22612260
}
22622261
return false;
22632262
}
@@ -3986,15 +3985,15 @@ void InstanceKlass::print_class_load_helper(ClassLoaderData* loader_data,
39863985

39873986
// Class hierarchy info
39883987
debug_stream.print(" klass: " PTR_FORMAT " super: " PTR_FORMAT,
3989-
p2i(this), p2i(superklass()));
3988+
p2i(this), p2i(java_super()));
39903989

39913990
// Interfaces
39923991
if (local_interfaces() != nullptr && local_interfaces()->length() > 0) {
39933992
debug_stream.print(" interfaces:");
39943993
int length = local_interfaces()->length();
39953994
for (int i = 0; i < length; i++) {
39963995
debug_stream.print(" " PTR_FORMAT,
3997-
p2i(InstanceKlass::cast(local_interfaces()->at(i))));
3996+
p2i(local_interfaces()->at(i)));
39983997
}
39993998
}
40003999

@@ -4207,19 +4206,17 @@ void InstanceKlass::oop_verify_on(oop obj, outputStream* st) {
42074206
obj->oop_iterate(&blk);
42084207
}
42094208

4210-
42114209
// JNIid class for jfieldIDs only
42124210
// Note to reviewers:
42134211
// These JNI functions are just moved over to column 1 and not changed
42144212
// in the compressed oops workspace.
4215-
JNIid::JNIid(Klass* holder, int offset, JNIid* next) {
4213+
JNIid::JNIid(InstanceKlass* holder, int offset, JNIid* next) {
42164214
_holder = holder;
42174215
_offset = offset;
42184216
_next = next;
42194217
DEBUG_ONLY(_is_static_field_id = false;)
42204218
}
42214219

4222-
42234220
JNIid* JNIid::find(int offset) {
42244221
JNIid* current = this;
42254222
while (current != nullptr) {
@@ -4237,11 +4234,10 @@ void JNIid::deallocate(JNIid* current) {
42374234
}
42384235
}
42394236

4240-
4241-
void JNIid::verify(Klass* holder) {
4237+
void JNIid::verify(InstanceKlass* holder) {
42424238
int first_field_offset = InstanceMirrorKlass::offset_of_static_fields();
42434239
int end_field_offset;
4244-
end_field_offset = first_field_offset + (InstanceKlass::cast(holder)->static_field_size() * wordSize);
4240+
end_field_offset = first_field_offset + (holder->static_field_size() * wordSize);
42454241

42464242
JNIid* current = this;
42474243
while (current != nullptr) {
@@ -4554,7 +4550,7 @@ void ClassHierarchyIterator::next() {
45544550
}
45554551
_visit_subclasses = true; // reset
45564552
while (_current->next_sibling() == nullptr && _current != _root) {
4557-
_current = _current->superklass(); // backtrack; no more sibling subclasses left
4553+
_current = _current->java_super(); // backtrack; no more sibling subclasses left
45584554
}
45594555
if (_current == _root) {
45604556
// Iteration is over (back at root after backtracking). Invalidate the iterator.

src/hotspot/share/oops/instanceKlass.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ class InstanceKlass: public Klass {
988988
static void deallocate_methods(ClassLoaderData* loader_data,
989989
Array<Method*>* methods);
990990
void static deallocate_interfaces(ClassLoaderData* loader_data,
991-
const Klass* super_klass,
991+
const InstanceKlass* super_klass,
992992
Array<InstanceKlass*>* local_interfaces,
993993
Array<InstanceKlass*>* transitive_interfaces);
994994
void static deallocate_record_components(ClassLoaderData* loader_data,
@@ -1205,7 +1205,7 @@ class PrintClassClosure : public KlassClosure {
12051205
class JNIid: public CHeapObj<mtClass> {
12061206
friend class VMStructs;
12071207
private:
1208-
Klass* _holder;
1208+
InstanceKlass* _holder;
12091209
JNIid* _next;
12101210
int _offset;
12111211
#ifdef ASSERT
@@ -1214,11 +1214,11 @@ class JNIid: public CHeapObj<mtClass> {
12141214

12151215
public:
12161216
// Accessors
1217-
Klass* holder() const { return _holder; }
1217+
InstanceKlass* holder() const { return _holder; }
12181218
int offset() const { return _offset; }
12191219
JNIid* next() { return _next; }
12201220
// Constructor
1221-
JNIid(Klass* holder, int offset, JNIid* next);
1221+
JNIid(InstanceKlass* holder, int offset, JNIid* next);
12221222
// Identifier lookup
12231223
JNIid* find(int offset);
12241224

@@ -1232,7 +1232,7 @@ class JNIid: public CHeapObj<mtClass> {
12321232
bool is_static_field_id() const { return _is_static_field_id; }
12331233
void set_is_static_field_id() { _is_static_field_id = true; }
12341234
#endif
1235-
void verify(Klass* holder);
1235+
void verify(InstanceKlass* holder);
12361236
};
12371237

12381238
// An iterator that's used to access the inner classes indices in the

0 commit comments

Comments
 (0)