Skip to content

Commit bf917ba

Browse files
committed
8304687: Move add_to_hierarchy
Reviewed-by: dholmes, fparain
1 parent 63d4afb commit bf917ba

File tree

9 files changed

+53
-56
lines changed

9 files changed

+53
-56
lines changed

src/hotspot/share/cds/lambdaFormInvokers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ void LambdaFormInvokers::regenerate_class(char* class_name, ClassFileStream& st,
209209
assert(result->java_mirror() != nullptr, "must be");
210210
add_regenerated_class(result->java_mirror());
211211

212-
SystemDictionary::add_to_hierarchy(THREAD, result);
212+
result->add_to_hierarchy(THREAD);
213213

214214
// new class not linked yet.
215215
MetaspaceShared::try_link_class(THREAD, result);

src/hotspot/share/ci/ciEnv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ void ciEnv::register_method(ciMethod* target,
10681068
// To prevent compile queue updates.
10691069
MutexLocker locker(THREAD, MethodCompileQueue_lock);
10701070

1071-
// Prevent SystemDictionary::add_to_hierarchy from running
1071+
// Prevent InstanceKlass::add_to_hierarchy from running
10721072
// and invalidating our dependencies until we install this method.
10731073
// No safepoints are allowed. Otherwise, class redefinition can occur in between.
10741074
MutexLocker ml(Compile_lock);

src/hotspot/share/classfile/systemDictionary.cpp

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
#include "classfile/systemDictionary.hpp"
4545
#include "classfile/vmClasses.hpp"
4646
#include "classfile/vmSymbols.hpp"
47-
#include "code/codeCache.hpp"
4847
#include "gc/shared/gcTraceTime.inline.hpp"
4948
#include "interpreter/bootstrapInfo.hpp"
5049
#include "jfr/jfrEvents.hpp"
@@ -70,7 +69,6 @@
7069
#include "prims/jvmtiExport.hpp"
7170
#include "prims/methodHandles.hpp"
7271
#include "runtime/arguments.hpp"
73-
#include "runtime/deoptimization.hpp"
7472
#include "runtime/handles.inline.hpp"
7573
#include "runtime/java.hpp"
7674
#include "runtime/javaCalls.hpp"
@@ -831,7 +829,7 @@ InstanceKlass* SystemDictionary::resolve_hidden_class_from_stream(
831829
}
832830

833831
// Add to class hierarchy, and do possible deoptimizations.
834-
add_to_hierarchy(THREAD, k);
832+
k->add_to_hierarchy(THREAD);
835833
// But, do not add to dictionary.
836834

837835
k->link_class(CHECK_NULL);
@@ -1418,7 +1416,7 @@ void SystemDictionary::define_instance_class(InstanceKlass* k, Handle class_load
14181416
}
14191417

14201418
// Add to class hierarchy, and do possible deoptimizations.
1421-
add_to_hierarchy(THREAD, k);
1419+
k->add_to_hierarchy(THREAD);
14221420

14231421
{
14241422
MutexLocker mu_r(THREAD, Compile_lock);
@@ -1536,49 +1534,6 @@ InstanceKlass* SystemDictionary::find_or_define_instance_class(Symbol* class_nam
15361534
}
15371535

15381536

1539-
// ----------------------------------------------------------------------------
1540-
// Update hierarchy. This is done before the new klass has been added to the SystemDictionary. The Compile_lock
1541-
// is grabbed, to ensure that the compiler is not using the class hierarchy.
1542-
1543-
void SystemDictionary::add_to_hierarchy(JavaThread* current, InstanceKlass* k) {
1544-
assert(k != nullptr, "just checking");
1545-
assert(!SafepointSynchronize::is_at_safepoint(), "must NOT be at safepoint");
1546-
1547-
// In case we are not using CHA based vtables we need to make sure the loaded
1548-
// deopt is completed before anyone links this class.
1549-
// Linking is done with _init_monitor held, by loading and deopting with it
1550-
// held we make sure the deopt is completed before linking.
1551-
if (!UseVtableBasedCHA) {
1552-
k->init_monitor()->lock();
1553-
}
1554-
1555-
DeoptimizationScope deopt_scope;
1556-
{
1557-
MutexLocker ml(current, Compile_lock);
1558-
1559-
k->set_init_state(InstanceKlass::loaded);
1560-
// make sure init_state store is already done.
1561-
// The compiler reads the hierarchy outside of the Compile_lock.
1562-
// Access ordering is used to add to hierarchy.
1563-
1564-
// Link into hierarchy.
1565-
k->append_to_sibling_list(); // add to superklass/sibling list
1566-
k->process_interfaces(); // handle all "implements" declarations
1567-
1568-
// Now mark all code that depended on old class hierarchy.
1569-
// Note: must be done *after* linking k into the hierarchy (was bug 12/9/97)
1570-
if (Universe::is_fully_initialized()) {
1571-
CodeCache::mark_dependents_on(&deopt_scope, k);
1572-
}
1573-
}
1574-
// Perform the deopt handshake outside Compile_lock.
1575-
deopt_scope.deoptimize_marked();
1576-
1577-
if (!UseVtableBasedCHA) {
1578-
k->init_monitor()->unlock();
1579-
}
1580-
}
1581-
15821537
// ----------------------------------------------------------------------------
15831538
// GC support
15841539

src/hotspot/share/classfile/systemDictionary.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,6 @@ class SystemDictionary : AllStatic {
360360
// Return Symbol or throw exception if name given is can not be a valid Symbol.
361361
static Symbol* class_name_symbol(const char* name, Symbol* exception, TRAPS);
362362

363-
// Setup link to hierarchy and deoptimize
364-
static void add_to_hierarchy(JavaThread* current, InstanceKlass* k);
365363
protected:
366364

367365
// Basic find on loaded classes

src/hotspot/share/classfile/systemDictionaryShared.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ InstanceKlass* SystemDictionaryShared::prepare_shared_lambda_proxy_class(Instanc
852852
EventClassLoad class_load_start_event;
853853

854854
// Add to class hierarchy, and do possible deoptimizations.
855-
SystemDictionary::add_to_hierarchy(THREAD, loaded_lambda);
855+
loaded_lambda->add_to_hierarchy(THREAD);
856856
// But, do not add to dictionary.
857857

858858
loaded_lambda->link_class(CHECK_NULL);

src/hotspot/share/classfile/vmClasses.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ void vmClasses::resolve_shared_class(InstanceKlass* klass, ClassLoaderData* load
249249
SystemDictionary::load_shared_class_misc(klass, loader_data);
250250
Dictionary* dictionary = loader_data->dictionary();
251251
dictionary->add_klass(THREAD, klass->name(), klass);
252-
SystemDictionary::add_to_hierarchy(THREAD, klass);
252+
klass->add_to_hierarchy(THREAD);
253253
assert(klass->is_loaded(), "Must be in at least loaded state");
254254
}
255255

src/hotspot/share/jvmci/jvmciRuntime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2120,7 +2120,7 @@ JVMCI::CodeInstallResult JVMCIRuntime::register_method(JVMCIEnv* JVMCIENV,
21202120
// To prevent compile queue updates.
21212121
MutexLocker locker(THREAD, MethodCompileQueue_lock);
21222122

2123-
// Prevent SystemDictionary::add_to_hierarchy from running
2123+
// Prevent InstanceKlass::add_to_hierarchy from running
21242124
// and invalidating our dependencies until we install this method.
21252125
MutexLocker ml(Compile_lock);
21262126

src/hotspot/share/oops/instanceKlass.cpp

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,46 @@ void InstanceKlass::set_initialization_state_and_notify(ClassState state, JavaTh
12051205
ml.notify_all();
12061206
}
12071207

1208+
// Update hierarchy. This is done before the new klass has been added to the SystemDictionary. The Compile_lock
1209+
// is grabbed, to ensure that the compiler is not using the class hierarchy.
1210+
void InstanceKlass::add_to_hierarchy(JavaThread* current) {
1211+
assert(!SafepointSynchronize::is_at_safepoint(), "must NOT be at safepoint");
1212+
1213+
// In case we are not using CHA based vtables we need to make sure the loaded
1214+
// deopt is completed before anyone links this class.
1215+
// Linking is done with _init_monitor held, by loading and deopting with it
1216+
// held we make sure the deopt is completed before linking.
1217+
if (!UseVtableBasedCHA) {
1218+
init_monitor()->lock();
1219+
}
1220+
1221+
DeoptimizationScope deopt_scope;
1222+
{
1223+
MutexLocker ml(current, Compile_lock);
1224+
1225+
set_init_state(InstanceKlass::loaded);
1226+
// make sure init_state store is already done.
1227+
// The compiler reads the hierarchy outside of the Compile_lock.
1228+
// Access ordering is used to add to hierarchy.
1229+
1230+
// Link into hierarchy.
1231+
append_to_sibling_list(); // add to superklass/sibling list
1232+
process_interfaces(); // handle all "implements" declarations
1233+
1234+
// Now mark all code that depended on old class hierarchy.
1235+
// Note: must be done *after* linking k into the hierarchy (was bug 12/9/97)
1236+
if (Universe::is_fully_initialized()) {
1237+
CodeCache::mark_dependents_on(&deopt_scope, this);
1238+
}
1239+
}
1240+
// Perform the deopt handshake outside Compile_lock.
1241+
deopt_scope.deoptimize_marked();
1242+
1243+
if (!UseVtableBasedCHA) {
1244+
init_monitor()->unlock();
1245+
}
1246+
}
1247+
12081248
InstanceKlass* InstanceKlass::implementor() const {
12091249
InstanceKlass* volatile* ik = adr_implementor();
12101250
if (ik == nullptr) {
@@ -2512,7 +2552,7 @@ void InstanceKlass::remove_unshareable_info() {
25122552
// Reset to the 'allocated' state to prevent any premature accessing to
25132553
// a shared class at runtime while the class is still being loaded and
25142554
// restored. A class' init_state is set to 'loaded' at runtime when it's
2515-
// being added to class hierarchy (see SystemDictionary:::add_to_hierarchy()).
2555+
// being added to class hierarchy (see InstanceKlass:::add_to_hierarchy()).
25162556
_init_state = allocated;
25172557

25182558
{ // Otherwise this needs to take out the Compile_lock.
@@ -2586,7 +2626,7 @@ void InstanceKlass::init_shared_package_entry() {
25862626

25872627
void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain,
25882628
PackageEntry* pkg_entry, TRAPS) {
2589-
// SystemDictionary::add_to_hierarchy() sets the init_state to loaded
2629+
// InstanceKlass::add_to_hierarchy() sets the init_state to loaded
25902630
// before the InstanceKlass is added to the SystemDictionary. Make
25912631
// sure the current state is <loaded.
25922632
assert(!is_loaded(), "invalid init state");

src/hotspot/share/oops/instanceKlass.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,8 @@ class InstanceKlass: public Klass {
856856
void mark_dependent_nmethods(DeoptimizationScope* deopt_scope, KlassDepChange& changes);
857857
void add_dependent_nmethod(nmethod* nm);
858858
void clean_dependency_context();
859+
// Setup link to hierarchy and deoptimize
860+
void add_to_hierarchy(JavaThread* current);
859861

860862
// On-stack replacement support
861863
nmethod* osr_nmethods_head() const { return _osr_nmethods_head; };
@@ -892,9 +894,11 @@ class InstanceKlass: public Klass {
892894
void add_implementor(InstanceKlass* ik); // ik is a new class that implements this interface
893895
void init_implementor(); // initialize
894896

897+
private:
895898
// link this class into the implementors list of every interface it implements
896899
void process_interfaces();
897900

901+
public:
898902
// virtual operations from Klass
899903
GrowableArray<Klass*>* compute_secondary_supers(int num_extra_slots,
900904
Array<InstanceKlass*>* transitive_interfaces);

0 commit comments

Comments
 (0)