Skip to content

Commit 9308d18

Browse files
committedOct 24, 2019
8232788: Move biased locking initalization
Reviewed-by: pchilanomate, dholmes
1 parent 31ab60e commit 9308d18

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed
 

‎src/hotspot/share/classfile/systemDictionary.cpp

-20
Original file line numberDiff line numberDiff line change
@@ -2132,26 +2132,6 @@ void SystemDictionary::update_dictionary(unsigned int d_hash,
21322132
{
21332133
MutexLocker mu1(SystemDictionary_lock, THREAD);
21342134

2135-
// See whether biased locking is enabled and if so set it for this
2136-
// klass.
2137-
// Note that this must be done past the last potential blocking
2138-
// point / safepoint. We might enable biased locking lazily using a
2139-
// VM_Operation to iterate the SystemDictionary and installing the
2140-
// biasable mark word into each InstanceKlass's prototype header.
2141-
// To avoid race conditions where we accidentally miss enabling the
2142-
// optimization for one class in the process of being added to the
2143-
// dictionary, we must not safepoint after the test of
2144-
// BiasedLocking::enabled().
2145-
if (UseBiasedLocking && BiasedLocking::enabled()) {
2146-
// Set biased locking bit for all loaded classes; it will be
2147-
// cleared if revocation occurs too often for this type
2148-
// NOTE that we must only do this when the class is initally
2149-
// defined, not each time it is referenced from a new class loader
2150-
if (k->class_loader() == class_loader()) {
2151-
k->set_prototype_header(markWord::biased_locking_prototype());
2152-
}
2153-
}
2154-
21552135
// Make a new dictionary entry.
21562136
Dictionary* dictionary = loader_data->dictionary();
21572137
InstanceKlass* sd_check = find_class(d_hash, name, dictionary);

‎src/hotspot/share/oops/instanceKlass.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
#include "prims/jvmtiThreadState.hpp"
7070
#include "prims/methodComparator.hpp"
7171
#include "runtime/atomic.hpp"
72+
#include "runtime/biasedLocking.hpp"
7273
#include "runtime/fieldDescriptor.inline.hpp"
7374
#include "runtime/handles.inline.hpp"
7475
#include "runtime/javaCalls.hpp"
@@ -456,6 +457,12 @@ InstanceKlass::InstanceKlass(const ClassFileParser& parser, unsigned kind, Klass
456457
if (Arguments::is_dumping_archive()) {
457458
SystemDictionaryShared::init_dumptime_info(this);
458459
}
460+
461+
// Set biased locking bit for all instances of this class; it will be
462+
// cleared if revocation occurs too often for this type
463+
if (UseBiasedLocking && BiasedLocking::enabled()) {
464+
set_prototype_header(markWord::biased_locking_prototype());
465+
}
459466
}
460467

461468
void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data,
@@ -2408,6 +2415,11 @@ void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handl
24082415
// --> see ArrayKlass::complete_create_array_klass()
24092416
array_klasses()->restore_unshareable_info(ClassLoaderData::the_null_class_loader_data(), Handle(), CHECK);
24102417
}
2418+
2419+
// Initialize current biased locking state.
2420+
if (UseBiasedLocking && BiasedLocking::enabled()) {
2421+
set_prototype_header(markWord::biased_locking_prototype());
2422+
}
24112423
}
24122424

24132425
// returns true IFF is_in_error_state() has been changed as a result of this call.

‎test/hotspot/gtest/oops/test_markOop.cpp ‎test/hotspot/gtest/oops/test_markWord.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "memory/universe.hpp"
2828
#include "oops/oop.inline.hpp"
2929
#include "runtime/atomic.hpp"
30+
#include "runtime/biasedLocking.hpp"
3031
#include "runtime/interfaceSupport.inline.hpp"
3132
#include "runtime/orderAccess.hpp"
3233
#include "runtime/os.hpp"
@@ -84,10 +85,14 @@ TEST_VM(markWord, printing) {
8485
ThreadInVMfromNative invm(THREAD);
8586
ResourceMark rm(THREAD);
8687

88+
if (!UseBiasedLocking || !BiasedLocking::enabled()) {
89+
// Can't test this with biased locking disabled.
90+
return;
91+
}
92+
8793
oop obj = SystemDictionary::Byte_klass()->allocate_instance(THREAD);
8894

8995
FlagSetting fs(WizardMode, true);
90-
FlagSetting bf(UseBiasedLocking, true);
9196

9297
HandleMark hm(THREAD);
9398
Handle h_obj(THREAD, obj);

0 commit comments

Comments
 (0)
Please sign in to comment.