230 |
230 |
231 public: |
231 public: |
232 PlatformParker(); |
232 PlatformParker(); |
233 }; |
233 }; |
234 |
234 |
|
235 // Workaround for a bug in macOSX kernel's pthread support (fixed in Mojave?). |
|
236 // Avoid ever allocating a pthread_mutex_t at the same address as one of our |
|
237 // former pthread_cond_t, by using a freelist of mutex/condvar pairs. |
|
238 // Conditional to avoid extra indirection and padding loss on other platforms. |
|
239 #ifdef __APPLE__ |
|
240 #define PLATFORM_MONITOR_IMPL_INDIRECT 1 |
|
241 #else |
|
242 #define PLATFORM_MONITOR_IMPL_INDIRECT 0 |
|
243 #endif |
|
244 |
235 // Platform specific implementation that underpins VM Monitor/Mutex class |
245 // Platform specific implementation that underpins VM Monitor/Mutex class |
236 class PlatformMonitor : public CHeapObj<mtSynchronizer> { |
246 class PlatformMonitor : public CHeapObj<mtSynchronizer> { |
237 private: |
247 class Impl : public CHeapObj<mtSynchronizer> { |
238 pthread_mutex_t _mutex; // Native mutex for locking |
248 public: |
239 pthread_cond_t _cond; // Native condition variable for blocking |
249 pthread_mutex_t _mutex; |
240 |
250 pthread_cond_t _cond; |
241 public: |
251 Impl* _next; |
242 PlatformMonitor(); |
252 |
|
253 Impl(); |
|
254 ~Impl(); |
|
255 }; |
|
256 |
|
257 #if PLATFORM_MONITOR_IMPL_INDIRECT |
|
258 |
|
259 Impl* _impl; |
|
260 |
|
261 pthread_mutex_t* mutex() { return &(_impl->_mutex); } |
|
262 pthread_cond_t* cond() { return &(_impl->_cond); } |
|
263 |
|
264 class WithFreeListLocked; |
|
265 static pthread_mutex_t _freelist_lock; |
|
266 static Impl* _freelist; |
|
267 |
|
268 public: |
|
269 PlatformMonitor(); // Use freelist allocation of impl. |
243 ~PlatformMonitor(); |
270 ~PlatformMonitor(); |
|
271 |
|
272 static void init(); // Initialize the freelist. |
|
273 |
|
274 #else |
|
275 |
|
276 Impl _impl; |
|
277 |
|
278 pthread_mutex_t* mutex() { return &(_impl._mutex); } |
|
279 pthread_cond_t* cond() { return &(_impl._cond); } |
|
280 |
|
281 public: |
|
282 static void init() {} // Nothing needed for the non-indirect case. |
|
283 |
|
284 // Default constructor and destructor. |
|
285 |
|
286 #endif // PLATFORM_MONITOR_IMPL_INDIRECT |
|
287 |
|
288 public: |
244 void lock(); |
289 void lock(); |
245 void unlock(); |
290 void unlock(); |
246 bool try_lock(); |
291 bool try_lock(); |
247 int wait(jlong millis); |
292 int wait(jlong millis); |
248 void notify(); |
293 void notify(); |