Skip to content

Commit fe42312

Browse files
committed
8304820: Statically allocate ObjectSynchronizer mutexes
Reviewed-by: dcubed, dholmes
1 parent 2f36eb0 commit fe42312

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/hotspot/share/runtime/synchronizer.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,20 @@ int dtrace_waited_probe(ObjectMonitor* monitor, Handle obj, JavaThread* thr) {
245245
return 0;
246246
}
247247

248-
static const int NINFLATIONLOCKS = 256;
249-
static PlatformMutex* gInflationLocks[NINFLATIONLOCKS];
248+
static constexpr size_t inflation_lock_count() {
249+
return 256;
250+
}
251+
252+
// Static storage for an array of PlatformMutex.
253+
alignas(PlatformMutex) static uint8_t _inflation_locks[inflation_lock_count()][sizeof(PlatformMutex)];
254+
255+
static inline PlatformMutex* inflation_lock(size_t index) {
256+
return reinterpret_cast<PlatformMutex*>(_inflation_locks[index]);
257+
}
250258

251259
void ObjectSynchronizer::initialize() {
252-
for (int i = 0; i < NINFLATIONLOCKS; i++) {
253-
gInflationLocks[i] = new PlatformMutex();
260+
for (size_t i = 0; i < inflation_lock_count(); i++) {
261+
::new(static_cast<void*>(inflation_lock(i))) PlatformMutex();
254262
}
255263
// Start the ceiling with the estimate for one thread.
256264
set_in_use_list_ceiling(AvgMonitorsPerThreadEstimate);
@@ -740,11 +748,11 @@ static markWord read_stable_mark(oop obj) {
740748
// then for each thread on the list, set the flag and unpark() the thread.
741749

742750
// Index into the lock array based on the current object address.
743-
static_assert(is_power_of_2(NINFLATIONLOCKS), "must be");
744-
int ix = (cast_from_oop<intptr_t>(obj) >> 5) & (NINFLATIONLOCKS-1);
751+
static_assert(is_power_of_2(inflation_lock_count()), "must be");
752+
size_t ix = (cast_from_oop<intptr_t>(obj) >> 5) & (inflation_lock_count() - 1);
745753
int YieldThenBlock = 0;
746-
assert(ix >= 0 && ix < NINFLATIONLOCKS, "invariant");
747-
gInflationLocks[ix]->lock();
754+
assert(ix < inflation_lock_count(), "invariant");
755+
inflation_lock(ix)->lock();
748756
while (obj->mark_acquire() == markWord::INFLATING()) {
749757
// Beware: naked_yield() is advisory and has almost no effect on some platforms
750758
// so we periodically call current->_ParkEvent->park(1).
@@ -755,7 +763,7 @@ static markWord read_stable_mark(oop obj) {
755763
os::naked_yield();
756764
}
757765
}
758-
gInflationLocks[ix]->unlock();
766+
inflation_lock(ix)->unlock();
759767
}
760768
} else {
761769
SpinPause(); // SMP-polite spinning

0 commit comments

Comments
 (0)