src/os/bsd/vm/os_bsd.hpp

Print this page
rev 4773 : 8005849: JEP 167: Event-Based JVM Tracing
Reviewed-by: acorn, coleenp, sla
Contributed-by: Karen Kinnear <karen.kinnear@oracle.com>, Bengt Rutisson <bengt.rutisson@oracle.com>, Calvin Cheung <calvin.cheung@oracle.com>, Erik Gahlin <erik.gahlin@oracle.com>, Erik Helin <erik.helin@oracle.com>, Jesper Wilhelmsson <jesper.wilhelmsson@oracle.com>, Keith McGuigan <keith.mcguigan@oracle.com>, Mattias Tobiasson <mattias.tobiasson@oracle.com>, Markus Gronlund <markus.gronlund@oracle.com>, Mikael Auno <mikael.auno@oracle.com>, Nils Eliasson <nils.eliasson@oracle.com>, Nils Loodin <nils.loodin@oracle.com>, Rickard Backman <rickard.backman@oracle.com>, Staffan Larsen <staffan.larsen@oracle.com>, Stefan Karlsson <stefan.karlsson@oracle.com>, Yekaterina Kantserova <yekaterina.kantserova@oracle.com>


 128   static size_t default_guard_size(os::ThreadType thr_type);
 129 
 130   // Real-time clock functions
 131   static void clock_init(void);
 132 
 133   static inline bool supports_monotonic_clock() {
 134     return _clock_gettime != NULL;
 135   }
 136 
 137   static int clock_gettime(clockid_t clock_id, struct timespec *tp) {
 138     return _clock_gettime ? _clock_gettime(clock_id, tp) : -1;
 139   }
 140 
 141   // Stack repair handling
 142 
 143   // none present
 144 
 145   // BsdThreads work-around for 6292965
 146   static int safe_cond_timedwait(pthread_cond_t *_cond, pthread_mutex_t *_mutex, const struct timespec *_abstime);
 147 
 148 
 149   // Bsd suspend/resume support - this helper is a shadow of its former
 150   // self now that low-level suspension is barely used, and old workarounds
 151   // for BsdThreads are no longer needed.
 152   class SuspendResume {
 153   private:
 154     volatile int  _suspend_action;
 155     volatile jint _state;
 156   public:
 157     // values for suspend_action:
 158     enum {
 159       SR_NONE              = 0x00,
 160       SR_SUSPEND           = 0x01,  // suspend request
 161       SR_CONTINUE          = 0x02,  // resume request
 162       SR_SUSPENDED         = 0x20   // values for _state: + SR_NONE
 163     };
 164 
 165     SuspendResume() { _suspend_action = SR_NONE; _state = SR_NONE; }
 166 
 167     int suspend_action() const     { return _suspend_action; }
 168     void set_suspend_action(int x) { _suspend_action = x;    }
 169 
 170     // atomic updates for _state
 171     inline void set_suspended();
 172     inline void clear_suspended();
 173     bool is_suspended()            { return _state & SR_SUSPENDED;       }
 174 
 175     #undef SR_SUSPENDED
 176   };
 177 
 178 private:
 179   typedef int (*sched_getcpu_func_t)(void);
 180   typedef int (*numa_node_to_cpus_func_t)(int node, unsigned long *buffer, int bufferlen);
 181   typedef int (*numa_max_node_func_t)(void);
 182   typedef int (*numa_available_func_t)(void);
 183   typedef int (*numa_tonode_memory_func_t)(void *start, size_t size, int node);
 184   typedef void (*numa_interleave_memory_func_t)(void *start, size_t size, unsigned long *nodemask);
 185 
 186   static sched_getcpu_func_t _sched_getcpu;
 187   static numa_node_to_cpus_func_t _numa_node_to_cpus;
 188   static numa_max_node_func_t _numa_max_node;
 189   static numa_available_func_t _numa_available;
 190   static numa_tonode_memory_func_t _numa_tonode_memory;
 191   static numa_interleave_memory_func_t _numa_interleave_memory;
 192   static unsigned long* _numa_all_nodes;
 193 
 194   static void set_sched_getcpu(sched_getcpu_func_t func) { _sched_getcpu = func; }
 195   static void set_numa_node_to_cpus(numa_node_to_cpus_func_t func) { _numa_node_to_cpus = func; }
 196   static void set_numa_max_node(numa_max_node_func_t func) { _numa_max_node = func; }
 197   static void set_numa_available(numa_available_func_t func) { _numa_available = func; }


 233   public:
 234     PlatformEvent() {
 235       int status;
 236       status = pthread_cond_init (_cond, NULL);
 237       assert_status(status == 0, status, "cond_init");
 238       status = pthread_mutex_init (_mutex, NULL);
 239       assert_status(status == 0, status, "mutex_init");
 240       _Event   = 0 ;
 241       _nParked = 0 ;
 242       _Assoc   = NULL ;
 243     }
 244 
 245     // Use caution with reset() and fired() -- they may require MEMBARs
 246     void reset() { _Event = 0 ; }
 247     int  fired() { return _Event; }
 248     void park () ;
 249     void unpark () ;
 250     int  TryPark () ;
 251     int  park (jlong millis) ;
 252     void SetAssociation (Thread * a) { _Assoc = a ; }
 253 } ;
 254 
 255 class PlatformParker : public CHeapObj<mtInternal> {
 256   protected:
 257     pthread_mutex_t _mutex [1] ;
 258     pthread_cond_t  _cond  [1] ;
 259 
 260   public:       // TODO-FIXME: make dtor private
 261     ~PlatformParker() { guarantee (0, "invariant") ; }
 262 
 263   public:
 264     PlatformParker() {
 265       int status;
 266       status = pthread_cond_init (_cond, NULL);
 267       assert_status(status == 0, status, "cond_init");
 268       status = pthread_mutex_init (_mutex, NULL);
 269       assert_status(status == 0, status, "mutex_init");
 270     }
 271 } ;
 272 
 273 #endif // OS_BSD_VM_OS_BSD_HPP


 128   static size_t default_guard_size(os::ThreadType thr_type);
 129 
 130   // Real-time clock functions
 131   static void clock_init(void);
 132 
 133   static inline bool supports_monotonic_clock() {
 134     return _clock_gettime != NULL;
 135   }
 136 
 137   static int clock_gettime(clockid_t clock_id, struct timespec *tp) {
 138     return _clock_gettime ? _clock_gettime(clock_id, tp) : -1;
 139   }
 140 
 141   // Stack repair handling
 142 
 143   // none present
 144 
 145   // BsdThreads work-around for 6292965
 146   static int safe_cond_timedwait(pthread_cond_t *_cond, pthread_mutex_t *_mutex, const struct timespec *_abstime);
 147 






























 148 private:
 149   typedef int (*sched_getcpu_func_t)(void);
 150   typedef int (*numa_node_to_cpus_func_t)(int node, unsigned long *buffer, int bufferlen);
 151   typedef int (*numa_max_node_func_t)(void);
 152   typedef int (*numa_available_func_t)(void);
 153   typedef int (*numa_tonode_memory_func_t)(void *start, size_t size, int node);
 154   typedef void (*numa_interleave_memory_func_t)(void *start, size_t size, unsigned long *nodemask);
 155 
 156   static sched_getcpu_func_t _sched_getcpu;
 157   static numa_node_to_cpus_func_t _numa_node_to_cpus;
 158   static numa_max_node_func_t _numa_max_node;
 159   static numa_available_func_t _numa_available;
 160   static numa_tonode_memory_func_t _numa_tonode_memory;
 161   static numa_interleave_memory_func_t _numa_interleave_memory;
 162   static unsigned long* _numa_all_nodes;
 163 
 164   static void set_sched_getcpu(sched_getcpu_func_t func) { _sched_getcpu = func; }
 165   static void set_numa_node_to_cpus(numa_node_to_cpus_func_t func) { _numa_node_to_cpus = func; }
 166   static void set_numa_max_node(numa_max_node_func_t func) { _numa_max_node = func; }
 167   static void set_numa_available(numa_available_func_t func) { _numa_available = func; }


 203   public:
 204     PlatformEvent() {
 205       int status;
 206       status = pthread_cond_init (_cond, NULL);
 207       assert_status(status == 0, status, "cond_init");
 208       status = pthread_mutex_init (_mutex, NULL);
 209       assert_status(status == 0, status, "mutex_init");
 210       _Event   = 0 ;
 211       _nParked = 0 ;
 212       _Assoc   = NULL ;
 213     }
 214 
 215     // Use caution with reset() and fired() -- they may require MEMBARs
 216     void reset() { _Event = 0 ; }
 217     int  fired() { return _Event; }
 218     void park () ;
 219     void unpark () ;
 220     int  TryPark () ;
 221     int  park (jlong millis) ;
 222     void SetAssociation (Thread * a) { _Assoc = a ; }
 223 };
 224 
 225 class PlatformParker : public CHeapObj<mtInternal> {
 226   protected:
 227     pthread_mutex_t _mutex [1] ;
 228     pthread_cond_t  _cond  [1] ;
 229 
 230   public:       // TODO-FIXME: make dtor private
 231     ~PlatformParker() { guarantee (0, "invariant") ; }
 232 
 233   public:
 234     PlatformParker() {
 235       int status;
 236       status = pthread_cond_init (_cond, NULL);
 237       assert_status(status == 0, status, "cond_init");
 238       status = pthread_mutex_init (_mutex, NULL);
 239       assert_status(status == 0, status, "mutex_init");
 240     }
 241 };
 242 
 243 #endif // OS_BSD_VM_OS_BSD_HPP