src/os/linux/vm/os_linux.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>


 193     return _clock_gettime ? _clock_gettime(clock_id, tp) : -1;
 194   }
 195 
 196   static int pthread_getcpuclockid(pthread_t tid, clockid_t *clock_id) {
 197     return _pthread_getcpuclockid ? _pthread_getcpuclockid(tid, clock_id) : -1;
 198   }
 199 
 200   static bool supports_fast_thread_cpu_time() {
 201     return _supports_fast_thread_cpu_time;
 202   }
 203 
 204   static jlong fast_thread_cpu_time(clockid_t clockid);
 205 
 206   // Stack repair handling
 207 
 208   // none present
 209 
 210   // LinuxThreads work-around for 6292965
 211   static int safe_cond_timedwait(pthread_cond_t *_cond, pthread_mutex_t *_mutex, const struct timespec *_abstime);
 212 
 213 
 214   // Linux suspend/resume support - this helper is a shadow of its former
 215   // self now that low-level suspension is barely used, and old workarounds
 216   // for LinuxThreads are no longer needed.
 217   class SuspendResume {
 218   private:
 219     volatile int  _suspend_action;
 220     volatile jint _state;
 221   public:
 222     // values for suspend_action:
 223     enum {
 224       SR_NONE              = 0x00,
 225       SR_SUSPEND           = 0x01,  // suspend request
 226       SR_CONTINUE          = 0x02,  // resume request
 227       SR_SUSPENDED         = 0x20   // values for _state: + SR_NONE
 228     };
 229 
 230     SuspendResume() { _suspend_action = SR_NONE; _state = SR_NONE; }
 231 
 232     int suspend_action() const     { return _suspend_action; }
 233     void set_suspend_action(int x) { _suspend_action = x;    }
 234 
 235     // atomic updates for _state
 236     inline void set_suspended();
 237     inline void clear_suspended();
 238     bool is_suspended()            { return _state & SR_SUSPENDED;       }
 239 
 240   };
 241 
 242 private:
 243   typedef int (*sched_getcpu_func_t)(void);
 244   typedef int (*numa_node_to_cpus_func_t)(int node, unsigned long *buffer, int bufferlen);
 245   typedef int (*numa_max_node_func_t)(void);
 246   typedef int (*numa_available_func_t)(void);
 247   typedef int (*numa_tonode_memory_func_t)(void *start, size_t size, int node);
 248   typedef void (*numa_interleave_memory_func_t)(void *start, size_t size, unsigned long *nodemask);
 249 
 250   static sched_getcpu_func_t _sched_getcpu;
 251   static numa_node_to_cpus_func_t _numa_node_to_cpus;
 252   static numa_max_node_func_t _numa_max_node;
 253   static numa_available_func_t _numa_available;
 254   static numa_tonode_memory_func_t _numa_tonode_memory;
 255   static numa_interleave_memory_func_t _numa_interleave_memory;
 256   static unsigned long* _numa_all_nodes;
 257 
 258   static void set_sched_getcpu(sched_getcpu_func_t func) { _sched_getcpu = func; }
 259   static void set_numa_node_to_cpus(numa_node_to_cpus_func_t func) { _numa_node_to_cpus = func; }
 260   static void set_numa_max_node(numa_max_node_func_t func) { _numa_max_node = func; }
 261   static void set_numa_available(numa_available_func_t func) { _numa_available = func; }


 316     int  park (jlong millis) ;
 317     void SetAssociation (Thread * a) { _Assoc = a ; }
 318 } ;
 319 
 320 class PlatformParker : public CHeapObj<mtInternal> {
 321   protected:
 322     pthread_mutex_t _mutex [1] ;
 323     pthread_cond_t  _cond  [1] ;
 324 
 325   public:       // TODO-FIXME: make dtor private
 326     ~PlatformParker() { guarantee (0, "invariant") ; }
 327 
 328   public:
 329     PlatformParker() {
 330       int status;
 331       status = pthread_cond_init (_cond, NULL);
 332       assert_status(status == 0, status, "cond_init");
 333       status = pthread_mutex_init (_mutex, NULL);
 334       assert_status(status == 0, status, "mutex_init");
 335     }
 336 } ;
 337 
 338 #endif // OS_LINUX_VM_OS_LINUX_HPP


 193     return _clock_gettime ? _clock_gettime(clock_id, tp) : -1;
 194   }
 195 
 196   static int pthread_getcpuclockid(pthread_t tid, clockid_t *clock_id) {
 197     return _pthread_getcpuclockid ? _pthread_getcpuclockid(tid, clock_id) : -1;
 198   }
 199 
 200   static bool supports_fast_thread_cpu_time() {
 201     return _supports_fast_thread_cpu_time;
 202   }
 203 
 204   static jlong fast_thread_cpu_time(clockid_t clockid);
 205 
 206   // Stack repair handling
 207 
 208   // none present
 209 
 210   // LinuxThreads work-around for 6292965
 211   static int safe_cond_timedwait(pthread_cond_t *_cond, pthread_mutex_t *_mutex, const struct timespec *_abstime);
 212 





























 213 private:
 214   typedef int (*sched_getcpu_func_t)(void);
 215   typedef int (*numa_node_to_cpus_func_t)(int node, unsigned long *buffer, int bufferlen);
 216   typedef int (*numa_max_node_func_t)(void);
 217   typedef int (*numa_available_func_t)(void);
 218   typedef int (*numa_tonode_memory_func_t)(void *start, size_t size, int node);
 219   typedef void (*numa_interleave_memory_func_t)(void *start, size_t size, unsigned long *nodemask);
 220 
 221   static sched_getcpu_func_t _sched_getcpu;
 222   static numa_node_to_cpus_func_t _numa_node_to_cpus;
 223   static numa_max_node_func_t _numa_max_node;
 224   static numa_available_func_t _numa_available;
 225   static numa_tonode_memory_func_t _numa_tonode_memory;
 226   static numa_interleave_memory_func_t _numa_interleave_memory;
 227   static unsigned long* _numa_all_nodes;
 228 
 229   static void set_sched_getcpu(sched_getcpu_func_t func) { _sched_getcpu = func; }
 230   static void set_numa_node_to_cpus(numa_node_to_cpus_func_t func) { _numa_node_to_cpus = func; }
 231   static void set_numa_max_node(numa_max_node_func_t func) { _numa_max_node = func; }
 232   static void set_numa_available(numa_available_func_t func) { _numa_available = func; }


 287     int  park (jlong millis) ;
 288     void SetAssociation (Thread * a) { _Assoc = a ; }
 289 } ;
 290 
 291 class PlatformParker : public CHeapObj<mtInternal> {
 292   protected:
 293     pthread_mutex_t _mutex [1] ;
 294     pthread_cond_t  _cond  [1] ;
 295 
 296   public:       // TODO-FIXME: make dtor private
 297     ~PlatformParker() { guarantee (0, "invariant") ; }
 298 
 299   public:
 300     PlatformParker() {
 301       int status;
 302       status = pthread_cond_init (_cond, NULL);
 303       assert_status(status == 0, status, "cond_init");
 304       status = pthread_mutex_init (_mutex, NULL);
 305       assert_status(status == 0, status, "mutex_init");
 306     }
 307 };
 308 
 309 #endif // OS_LINUX_VM_OS_LINUX_HPP