mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2025-12-06 09:29:38 +01:00
8304820: Statically allocate ObjectSynchronizer mutexes
Reviewed-by: dcubed, dholmes
(cherry picked from commit fe42312f9b)
This commit is contained in:
committed by
Vitaly Provodin
parent
e8e90325bd
commit
094dc9a38f
@@ -245,12 +245,20 @@ int dtrace_waited_probe(ObjectMonitor* monitor, Handle obj, JavaThread* thr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const int NINFLATIONLOCKS = 256;
|
||||
static PlatformMutex* gInflationLocks[NINFLATIONLOCKS];
|
||||
static constexpr size_t inflation_lock_count() {
|
||||
return 256;
|
||||
}
|
||||
|
||||
// Static storage for an array of PlatformMutex.
|
||||
alignas(PlatformMutex) static uint8_t _inflation_locks[inflation_lock_count()][sizeof(PlatformMutex)];
|
||||
|
||||
static inline PlatformMutex* inflation_lock(size_t index) {
|
||||
return reinterpret_cast<PlatformMutex*>(_inflation_locks[index]);
|
||||
}
|
||||
|
||||
void ObjectSynchronizer::initialize() {
|
||||
for (int i = 0; i < NINFLATIONLOCKS; i++) {
|
||||
gInflationLocks[i] = new PlatformMutex();
|
||||
for (size_t i = 0; i < inflation_lock_count(); i++) {
|
||||
::new(static_cast<void*>(inflation_lock(i))) PlatformMutex();
|
||||
}
|
||||
// Start the ceiling with the estimate for one thread.
|
||||
set_in_use_list_ceiling(AvgMonitorsPerThreadEstimate);
|
||||
@@ -740,11 +748,11 @@ static markWord read_stable_mark(oop obj) {
|
||||
// then for each thread on the list, set the flag and unpark() the thread.
|
||||
|
||||
// Index into the lock array based on the current object address.
|
||||
static_assert(is_power_of_2(NINFLATIONLOCKS), "must be");
|
||||
int ix = (cast_from_oop<intptr_t>(obj) >> 5) & (NINFLATIONLOCKS-1);
|
||||
static_assert(is_power_of_2(inflation_lock_count()), "must be");
|
||||
size_t ix = (cast_from_oop<intptr_t>(obj) >> 5) & (inflation_lock_count() - 1);
|
||||
int YieldThenBlock = 0;
|
||||
assert(ix >= 0 && ix < NINFLATIONLOCKS, "invariant");
|
||||
gInflationLocks[ix]->lock();
|
||||
assert(ix < inflation_lock_count(), "invariant");
|
||||
inflation_lock(ix)->lock();
|
||||
while (obj->mark_acquire() == markWord::INFLATING()) {
|
||||
// Beware: naked_yield() is advisory and has almost no effect on some platforms
|
||||
// so we periodically call current->_ParkEvent->park(1).
|
||||
@@ -755,7 +763,7 @@ static markWord read_stable_mark(oop obj) {
|
||||
os::naked_yield();
|
||||
}
|
||||
}
|
||||
gInflationLocks[ix]->unlock();
|
||||
inflation_lock(ix)->unlock();
|
||||
}
|
||||
} else {
|
||||
SpinPause(); // SMP-polite spinning
|
||||
|
||||
Reference in New Issue
Block a user