@@ -245,12 +245,20 @@ int dtrace_waited_probe(ObjectMonitor* monitor, Handle obj, JavaThread* thr) {
245
245
return 0 ;
246
246
}
247
247
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
+ }
250
258
251
259
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 ();
254
262
}
255
263
// Start the ceiling with the estimate for one thread.
256
264
set_in_use_list_ceiling (AvgMonitorsPerThreadEstimate);
@@ -740,11 +748,11 @@ static markWord read_stable_mark(oop obj) {
740
748
// then for each thread on the list, set the flag and unpark() the thread.
741
749
742
750
// 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 );
745
753
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 ();
748
756
while (obj->mark_acquire () == markWord::INFLATING ()) {
749
757
// Beware: naked_yield() is advisory and has almost no effect on some platforms
750
758
// so we periodically call current->_ParkEvent->park(1).
@@ -755,7 +763,7 @@ static markWord read_stable_mark(oop obj) {
755
763
os::naked_yield ();
756
764
}
757
765
}
758
- gInflationLocks [ix] ->unlock ();
766
+ inflation_lock (ix) ->unlock ();
759
767
}
760
768
} else {
761
769
SpinPause (); // SMP-polite spinning
0 commit comments