8262028: Make InstanceKlass::implementor return InstanceKlass

Reviewed-by: coleenp, ccheung, vlivanov
This commit is contained in:
Harold Seigel 2021-03-01 13:25:23 +00:00
parent fe8e3707c5
commit 75bf10610f
4 changed files with 36 additions and 36 deletions

View file

@ -1342,7 +1342,7 @@ Klass* ClassHierarchyWalker::find_witness_anywhere(InstanceKlass* context_type,
return NULL; // no implementors return NULL; // no implementors
} else if (nof_impls == 1) { // unique implementor } else if (nof_impls == 1) { // unique implementor
assert(context_type != context_type->implementor(), "not unique"); assert(context_type != context_type->implementor(), "not unique");
context_type = InstanceKlass::cast(context_type->implementor()); context_type = context_type->implementor();
} else { // nof_impls >= 2 } else { // nof_impls >= 2
// Avoid this case: *I.m > { A.m, C }; B.m > C // Avoid this case: *I.m > { A.m, C }; B.m > C
// Here, I.m has 2 concrete implementations, but m appears unique // Here, I.m has 2 concrete implementations, but m appears unique

View file

@ -1223,37 +1223,37 @@ void InstanceKlass::set_initialization_state_and_notify(ClassState state, TRAPS)
} }
} }
Klass* InstanceKlass::implementor() const { InstanceKlass* InstanceKlass::implementor() const {
Klass* volatile* k = adr_implementor(); InstanceKlass* volatile* ik = adr_implementor();
if (k == NULL) { if (ik == NULL) {
return NULL; return NULL;
} else { } else {
// This load races with inserts, and therefore needs acquire. // This load races with inserts, and therefore needs acquire.
Klass* kls = Atomic::load_acquire(k); InstanceKlass* ikls = Atomic::load_acquire(ik);
if (kls != NULL && !kls->is_loader_alive()) { if (ikls != NULL && !ikls->is_loader_alive()) {
return NULL; // don't return unloaded class return NULL; // don't return unloaded class
} else { } else {
return kls; return ikls;
} }
} }
} }
void InstanceKlass::set_implementor(Klass* k) { void InstanceKlass::set_implementor(InstanceKlass* ik) {
assert_locked_or_safepoint(Compile_lock); assert_locked_or_safepoint(Compile_lock);
assert(is_interface(), "not interface"); assert(is_interface(), "not interface");
Klass* volatile* addr = adr_implementor(); InstanceKlass* volatile* addr = adr_implementor();
assert(addr != NULL, "null addr"); assert(addr != NULL, "null addr");
if (addr != NULL) { if (addr != NULL) {
Atomic::release_store(addr, k); Atomic::release_store(addr, ik);
} }
} }
int InstanceKlass::nof_implementors() const { int InstanceKlass::nof_implementors() const {
Klass* k = implementor(); InstanceKlass* ik = implementor();
if (k == NULL) { if (ik == NULL) {
return 0; return 0;
} else if (k != this) { } else if (ik != this) {
return 1; return 1;
} else { } else {
return 2; return 2;
@ -1269,29 +1269,29 @@ int InstanceKlass::nof_implementors() const {
// self - more than one implementor // self - more than one implementor
// //
// The _implementor field only exists for interfaces. // The _implementor field only exists for interfaces.
void InstanceKlass::add_implementor(Klass* k) { void InstanceKlass::add_implementor(InstanceKlass* ik) {
if (Universe::is_fully_initialized()) { if (Universe::is_fully_initialized()) {
assert_lock_strong(Compile_lock); assert_lock_strong(Compile_lock);
} }
assert(is_interface(), "not interface"); assert(is_interface(), "not interface");
// Filter out my subinterfaces. // Filter out my subinterfaces.
// (Note: Interfaces are never on the subklass list.) // (Note: Interfaces are never on the subklass list.)
if (InstanceKlass::cast(k)->is_interface()) return; if (ik->is_interface()) return;
// Filter out subclasses whose supers already implement me. // Filter out subclasses whose supers already implement me.
// (Note: CHA must walk subclasses of direct implementors // (Note: CHA must walk subclasses of direct implementors
// in order to locate indirect implementors.) // in order to locate indirect implementors.)
Klass* sk = k->super(); InstanceKlass* super_ik = ik->java_super();
if (sk != NULL && InstanceKlass::cast(sk)->implements_interface(this)) if (super_ik != NULL && super_ik->implements_interface(this))
// We only need to check one immediate superclass, since the // We only need to check one immediate superclass, since the
// implements_interface query looks at transitive_interfaces. // implements_interface query looks at transitive_interfaces.
// Any supers of the super have the same (or fewer) transitive_interfaces. // Any supers of the super have the same (or fewer) transitive_interfaces.
return; return;
Klass* ik = implementor(); InstanceKlass* iklass = implementor();
if (ik == NULL) { if (iklass == NULL) {
set_implementor(k); set_implementor(ik);
} else if (ik != this && ik != k) { } else if (iklass != this && iklass != ik) {
// There is already an implementor. Use itself as an indicator of // There is already an implementor. Use itself as an indicator of
// more than one implementors. // more than one implementors.
set_implementor(this); set_implementor(this);
@ -1299,7 +1299,7 @@ void InstanceKlass::add_implementor(Klass* k) {
// The implementor also implements the transitive_interfaces // The implementor also implements the transitive_interfaces
for (int index = 0; index < local_interfaces()->length(); index++) { for (int index = 0; index < local_interfaces()->length(); index++) {
InstanceKlass::cast(local_interfaces()->at(index))->add_implementor(k); local_interfaces()->at(index)->add_implementor(ik);
} }
} }
@ -1314,7 +1314,7 @@ void InstanceKlass::process_interfaces() {
// link this class into the implementors list of every interface it implements // link this class into the implementors list of every interface it implements
for (int i = local_interfaces()->length() - 1; i >= 0; i--) { for (int i = local_interfaces()->length() - 1; i >= 0; i--) {
assert(local_interfaces()->at(i)->is_klass(), "must be a klass"); assert(local_interfaces()->at(i)->is_klass(), "must be a klass");
InstanceKlass* interf = InstanceKlass::cast(local_interfaces()->at(i)); InstanceKlass* interf = local_interfaces()->at(i);
assert(interf->is_interface(), "expected interface"); assert(interf->is_interface(), "expected interface");
interf->add_implementor(this); interf->add_implementor(this);
} }
@ -2344,11 +2344,11 @@ void InstanceKlass::clean_implementors_list() {
assert (ClassUnloading, "only called for ClassUnloading"); assert (ClassUnloading, "only called for ClassUnloading");
for (;;) { for (;;) {
// Use load_acquire due to competing with inserts // Use load_acquire due to competing with inserts
Klass* impl = Atomic::load_acquire(adr_implementor()); InstanceKlass* impl = Atomic::load_acquire(adr_implementor());
if (impl != NULL && !impl->is_loader_alive()) { if (impl != NULL && !impl->is_loader_alive()) {
// NULL this field, might be an unloaded klass or NULL // NULL this field, might be an unloaded instance klass or NULL
Klass* volatile* klass = adr_implementor(); InstanceKlass* volatile* iklass = adr_implementor();
if (Atomic::cmpxchg(klass, impl, (Klass*)NULL) == impl) { if (Atomic::cmpxchg(iklass, impl, (InstanceKlass*)NULL) == impl) {
// Successfully unlinking implementor. // Successfully unlinking implementor.
if (log_is_enabled(Trace, class, unload)) { if (log_is_enabled(Trace, class, unload)) {
ResourceMark rm; ResourceMark rm;

View file

@ -327,7 +327,7 @@ class InstanceKlass: public Klass {
// embedded nonstatic oop-map blocks follows here // embedded nonstatic oop-map blocks follows here
// embedded implementor of this interface follows here // embedded implementor of this interface follows here
// The embedded implementor only exists if the current klass is an // The embedded implementor only exists if the current klass is an
// iterface. The possible values of the implementor fall into following // interface. The possible values of the implementor fall into following
// three cases: // three cases:
// NULL: no implementor. // NULL: no implementor.
// A Klass* that's not itself: one implementor. // A Klass* that's not itself: one implementor.
@ -1016,10 +1016,10 @@ public:
#endif #endif
// Access to the implementor of an interface. // Access to the implementor of an interface.
Klass* implementor() const; InstanceKlass* implementor() const;
void set_implementor(Klass* k); void set_implementor(InstanceKlass* ik);
int nof_implementors() const; int nof_implementors() const;
void add_implementor(Klass* k); // k is a new class that implements this interface void add_implementor(InstanceKlass* ik); // ik is a new class that implements this interface
void init_implementor(); // initialize void init_implementor(); // initialize
// link this class into the implementors list of every interface it implements // link this class into the implementors list of every interface it implements
@ -1087,7 +1087,7 @@ public:
inline OopMapBlock* start_of_nonstatic_oop_maps() const; inline OopMapBlock* start_of_nonstatic_oop_maps() const;
inline Klass** end_of_nonstatic_oop_maps() const; inline Klass** end_of_nonstatic_oop_maps() const;
inline Klass* volatile* adr_implementor() const; inline InstanceKlass* volatile* adr_implementor() const;
inline InstanceKlass** adr_unsafe_anonymous_host() const; inline InstanceKlass** adr_unsafe_anonymous_host() const;
inline address adr_fingerprint() const; inline address adr_fingerprint() const;

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -74,9 +74,9 @@ inline Klass** InstanceKlass::end_of_nonstatic_oop_maps() const {
nonstatic_oop_map_count()); nonstatic_oop_map_count());
} }
inline Klass* volatile* InstanceKlass::adr_implementor() const { inline InstanceKlass* volatile* InstanceKlass::adr_implementor() const {
if (is_interface()) { if (is_interface()) {
return (Klass* volatile*)end_of_nonstatic_oop_maps(); return (InstanceKlass* volatile*)end_of_nonstatic_oop_maps();
} else { } else {
return NULL; return NULL;
} }
@ -102,7 +102,7 @@ inline address InstanceKlass::adr_fingerprint() const {
return (address)(adr_host + 1); return (address)(adr_host + 1);
} }
Klass* volatile* adr_impl = adr_implementor(); InstanceKlass* volatile* adr_impl = adr_implementor();
if (adr_impl != NULL) { if (adr_impl != NULL) {
return (address)(adr_impl + 1); return (address)(adr_impl + 1);
} }