< prev index next >

src/hotspot/os/posix/os_posix.hpp

Print this page

        

@@ -232,110 +232,65 @@
   PlatformParker();
 };
 
 // Workaround for a bug in macOSX kernel's pthread support (fixed in Mojave?).
 // Avoid ever allocating a pthread_mutex_t at the same address as one of our
-// former pthread_cond_t, by using freelists of mutexes and condvars.
+// former pthread_cond_t, by using a freelist of mutex/condvar pairs.
 // Conditional to avoid extra indirection and padding loss on other platforms.
 #ifdef __APPLE__
 #define PLATFORM_MONITOR_IMPL_INDIRECT 1
 #else
 #define PLATFORM_MONITOR_IMPL_INDIRECT 0
 #endif
 
-// Platform specific implementations that underpin VM Mutex/Monitor classes
-
-class PlatformMutex : public CHeapObj<mtSynchronizer> {
-#if PLATFORM_MONITOR_IMPL_INDIRECT
-  class Mutex : public CHeapObj<mtSynchronizer> {
-   public:
+// Platform specific implementation that underpins VM Monitor/Mutex class
+class PlatformMonitor : public CHeapObj<mtSynchronizer> {
+  class Impl : public CHeapObj<mtSynchronizer> {
+  public:
     pthread_mutex_t _mutex;
-    Mutex* _next;
+    pthread_cond_t _cond;
+    Impl* _next;
 
-    Mutex();
-    ~Mutex();
+    Impl();
+    ~Impl();
   };
 
-  Mutex* _impl;
+#if PLATFORM_MONITOR_IMPL_INDIRECT
 
-  static pthread_mutex_t _freelist_lock; // used for mutex and cond freelists
-  static Mutex* _mutex_freelist;
+  Impl* _impl;
 
- protected:
-  class WithFreeListLocked;
   pthread_mutex_t* mutex() { return &(_impl->_mutex); }
+  pthread_cond_t* cond() { return &(_impl->_cond); }
+
+  class WithFreeListLocked;
+  static pthread_mutex_t _freelist_lock;
+  static Impl* _freelist;
 
  public:
-  PlatformMutex();              // Use freelist allocation of impl.
-  ~PlatformMutex();
+  PlatformMonitor();            // Use freelist allocation of impl.
+  ~PlatformMonitor();
 
   static void init();           // Initialize the freelist.
 
 #else
 
-  pthread_mutex_t _mutex;
+  Impl _impl;
 
- protected:
-  pthread_mutex_t* mutex() { return &_mutex; }
+  pthread_mutex_t* mutex() { return &(_impl._mutex); }
+  pthread_cond_t* cond() { return &(_impl._cond); }
 
  public:
   static void init() {}         // Nothing needed for the non-indirect case.
 
-  PlatformMutex();
-  ~PlatformMutex();
+  // Default constructor and destructor.
 
 #endif // PLATFORM_MONITOR_IMPL_INDIRECT
 
-private:
-  // Disable copying
-  PlatformMutex(const PlatformMutex&);
-  PlatformMutex& operator=(const PlatformMutex&);
-
  public:
   void lock();
   void unlock();
   bool try_lock();
-};
-
-class PlatformMonitor : public PlatformMutex {
-#if PLATFORM_MONITOR_IMPL_INDIRECT
-  class Cond : public CHeapObj<mtSynchronizer> {
-   public:
-    pthread_cond_t _cond;
-    Cond* _next;
-
-    Cond();
-    ~Cond();
-  };
-
-  Cond* _impl;
-
-  static Cond* _cond_freelist;
-
-  pthread_cond_t* cond() { return &(_impl->_cond); }
-
- public:
-  PlatformMonitor();            // Use freelist allocation of impl.
-  ~PlatformMonitor();
-
-#else
-
-  pthread_cond_t _cond;
-  pthread_cond_t* cond() { return &_cond; }
-
- public:
-  PlatformMonitor();
-  ~PlatformMonitor();
-
-#endif // PLATFORM_MONITOR_IMPL_INDIRECT
-
- private:
-  // Disable copying
-  PlatformMonitor(const PlatformMonitor&);
-  PlatformMonitor& operator=(const PlatformMonitor&);
-
- public:
   int wait(jlong millis);
   void notify();
   void notify_all();
 };
 
< prev index next >