< prev index next >

src/hotspot/os/posix/os_posix.hpp

Print this page




 217 
 218 class PlatformParker : public CHeapObj<mtSynchronizer> {
 219  protected:
 220   enum {
 221     REL_INDEX = 0,
 222     ABS_INDEX = 1
 223   };
 224   int _cur_index;  // which cond is in use: -1, 0, 1
 225   pthread_mutex_t _mutex[1];
 226   pthread_cond_t  _cond[2]; // one for relative times and one for absolute
 227 
 228  public:       // TODO-FIXME: make dtor private
 229   ~PlatformParker() { guarantee(false, "invariant"); }
 230 
 231  public:
 232   PlatformParker();
 233 };
 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 freelists of mutexes and condvars.
 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 
 245 // Platform specific implementations that underpin VM Mutex/Monitor classes
 246 
 247 class PlatformMutex : public CHeapObj<mtSynchronizer> {
 248 #if PLATFORM_MONITOR_IMPL_INDIRECT
 249   class Mutex : public CHeapObj<mtSynchronizer> {
 250    public:
 251     pthread_mutex_t _mutex;
 252     Mutex* _next;

 253 
 254     Mutex();
 255     ~Mutex();
 256   };
 257 
 258   Mutex* _impl;
 259 
 260   static pthread_mutex_t _freelist_lock; // used for mutex and cond freelists
 261   static Mutex* _mutex_freelist;
 262 
 263  protected:
 264   class WithFreeListLocked;
 265   pthread_mutex_t* mutex() { return &(_impl->_mutex); }





 266 
 267  public:
 268   PlatformMutex();              // Use freelist allocation of impl.
 269   ~PlatformMutex();
 270 
 271   static void init();           // Initialize the freelist.
 272 
 273 #else
 274 
 275   pthread_mutex_t _mutex;
 276 
 277  protected:
 278   pthread_mutex_t* mutex() { return &_mutex; }
 279 
 280  public:
 281   static void init() {}         // Nothing needed for the non-indirect case.
 282 
 283   PlatformMutex();
 284   ~PlatformMutex();
 285 
 286 #endif // PLATFORM_MONITOR_IMPL_INDIRECT
 287 
 288 private:
 289   // Disable copying
 290   PlatformMutex(const PlatformMutex&);
 291   PlatformMutex& operator=(const PlatformMutex&);
 292 
 293  public:
 294   void lock();
 295   void unlock();
 296   bool try_lock();
 297 };
 298 
 299 class PlatformMonitor : public PlatformMutex {
 300 #if PLATFORM_MONITOR_IMPL_INDIRECT
 301   class Cond : public CHeapObj<mtSynchronizer> {
 302    public:
 303     pthread_cond_t _cond;
 304     Cond* _next;
 305 
 306     Cond();
 307     ~Cond();
 308   };
 309 
 310   Cond* _impl;
 311 
 312   static Cond* _cond_freelist;
 313 
 314   pthread_cond_t* cond() { return &(_impl->_cond); }
 315 
 316  public:
 317   PlatformMonitor();            // Use freelist allocation of impl.
 318   ~PlatformMonitor();
 319 
 320 #else
 321 
 322   pthread_cond_t _cond;
 323   pthread_cond_t* cond() { return &_cond; }
 324 
 325  public:
 326   PlatformMonitor();
 327   ~PlatformMonitor();
 328 
 329 #endif // PLATFORM_MONITOR_IMPL_INDIRECT
 330 
 331  private:
 332   // Disable copying
 333   PlatformMonitor(const PlatformMonitor&);
 334   PlatformMonitor& operator=(const PlatformMonitor&);
 335 
 336  public:
 337   int wait(jlong millis);
 338   void notify();
 339   void notify_all();
 340 };
 341 
 342 #endif // !SOLARIS
 343 
 344 #endif // OS_POSIX_OS_POSIX_HPP


 217 
 218 class PlatformParker : public CHeapObj<mtSynchronizer> {
 219  protected:
 220   enum {
 221     REL_INDEX = 0,
 222     ABS_INDEX = 1
 223   };
 224   int _cur_index;  // which cond is in use: -1, 0, 1
 225   pthread_mutex_t _mutex[1];
 226   pthread_cond_t  _cond[2]; // one for relative times and one for absolute
 227 
 228  public:       // TODO-FIXME: make dtor private
 229   ~PlatformParker() { guarantee(false, "invariant"); }
 230 
 231  public:
 232   PlatformParker();
 233 };
 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 
 245 // Platform specific implementation that underpins VM Monitor/Mutex class
 246 class PlatformMonitor : public CHeapObj<mtSynchronizer> {
 247   class Impl : public CHeapObj<mtSynchronizer> {
 248   public:


 249     pthread_mutex_t _mutex;
 250     pthread_cond_t _cond;
 251     Impl* _next;
 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.
 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:
 289   void lock();
 290   void unlock();
 291   bool try_lock();








































 292   int wait(jlong millis);
 293   void notify();
 294   void notify_all();
 295 };
 296 
 297 #endif // !SOLARIS
 298 
 299 #endif // OS_POSIX_OS_POSIX_HPP
< prev index next >