< prev index next >

src/hotspot/os/linux/os_linux.cpp

Print this page




5555 }
5556 
5557 
5558 // Remap a block of memory.
5559 char* os::pd_remap_memory(int fd, const char* file_name, size_t file_offset,
5560                           char *addr, size_t bytes, bool read_only,
5561                           bool allow_exec) {
5562   // same as map_memory() on this OS
5563   return os::map_memory(fd, file_name, file_offset, addr, bytes, read_only,
5564                         allow_exec);
5565 }
5566 
5567 
5568 // Unmap a block of memory.
5569 bool os::pd_unmap_memory(char* addr, size_t bytes) {
5570   return munmap(addr, bytes) == 0;
5571 }
5572 
5573 static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time);
5574 
5575 static clockid_t thread_cpu_clockid(Thread* thread) {
5576   pthread_t tid = thread->osthread()->pthread_id();
5577   clockid_t clockid;
5578 
5579   // Get thread clockid
5580   int rc = os::Linux::pthread_getcpuclockid(tid, &clockid);
5581   assert(rc == 0, "pthread_getcpuclockid is expected to return 0 code");
5582   return clockid;






5583 }
5584 
5585 // current_thread_cpu_time(bool) and thread_cpu_time(Thread*, bool)
5586 // are used by JVM M&M and JVMTI to get user+sys or user CPU time
5587 // of a thread.
5588 //
5589 // current_thread_cpu_time() and thread_cpu_time(Thread*) returns
5590 // the fast estimate available on the platform.
5591 
5592 jlong os::current_thread_cpu_time() {
5593   if (os::Linux::supports_fast_thread_cpu_time()) {
5594     return os::Linux::fast_thread_cpu_time(CLOCK_THREAD_CPUTIME_ID);
5595   } else {
5596     // return user + sys since the cost is the same
5597     return slow_thread_cpu_time(Thread::current(), true /* user + sys */);
5598   }
5599 }
5600 
5601 jlong os::thread_cpu_time(Thread* thread) {
5602   // consistent with what current_thread_cpu_time() returns
5603   if (os::Linux::supports_fast_thread_cpu_time()) {
5604     return os::Linux::fast_thread_cpu_time(thread_cpu_clockid(thread));
5605   } else {
5606     return slow_thread_cpu_time(thread, true /* user + sys */);
5607   }
5608 }
5609 
5610 jlong os::current_thread_cpu_time(bool user_sys_cpu_time) {
5611   if (user_sys_cpu_time && os::Linux::supports_fast_thread_cpu_time()) {
5612     return os::Linux::fast_thread_cpu_time(CLOCK_THREAD_CPUTIME_ID);
5613   } else {
5614     return slow_thread_cpu_time(Thread::current(), user_sys_cpu_time);
5615   }
5616 }
5617 
5618 jlong os::thread_cpu_time(Thread *thread, bool user_sys_cpu_time) {
5619   if (user_sys_cpu_time && os::Linux::supports_fast_thread_cpu_time()) {
5620     return os::Linux::fast_thread_cpu_time(thread_cpu_clockid(thread));
5621   } else {
5622     return slow_thread_cpu_time(thread, user_sys_cpu_time);
5623   }
5624 }
5625 
5626 //  -1 on error.
5627 static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time) {
5628   pid_t  tid = thread->osthread()->thread_id();
5629   char *s;
5630   char stat[2048];
5631   int statlen;
5632   char proc_name[64];
5633   int count;
5634   long sys_time, user_time;
5635   char cdummy;
5636   int idummy;
5637   long ldummy;
5638   FILE *fp;
5639 
5640   snprintf(proc_name, 64, "/proc/self/task/%d/stat", tid);




5555 }
5556 
5557 
5558 // Remap a block of memory.
5559 char* os::pd_remap_memory(int fd, const char* file_name, size_t file_offset,
5560                           char *addr, size_t bytes, bool read_only,
5561                           bool allow_exec) {
5562   // same as map_memory() on this OS
5563   return os::map_memory(fd, file_name, file_offset, addr, bytes, read_only,
5564                         allow_exec);
5565 }
5566 
5567 
5568 // Unmap a block of memory.
5569 bool os::pd_unmap_memory(char* addr, size_t bytes) {
5570   return munmap(addr, bytes) == 0;
5571 }
5572 
5573 static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time);
5574 
5575 static jlong fast_cpu_time(Thread *thread) {

5576     clockid_t clockid;
5577     int rc = os::Linux::pthread_getcpuclockid(thread->osthread()->pthread_id(),
5578                                               &clockid);
5579     if (rc == 0) {
5580       return os::Linux::fast_thread_cpu_time(clockid);
5581     }
5582     else {
5583       // It's possible to encounter a terminated native thread that failed
5584       // to detach itself from the VM - which should result in ESRCH.
5585       assert_status(rc == ESRCH, rc, "pthread_getcpuclockid failed");
5586       return -1;
5587     }
5588 }
5589 
5590 // current_thread_cpu_time(bool) and thread_cpu_time(Thread*, bool)
5591 // are used by JVM M&M and JVMTI to get user+sys or user CPU time
5592 // of a thread.
5593 //
5594 // current_thread_cpu_time() and thread_cpu_time(Thread*) returns
5595 // the fast estimate available on the platform.
5596 
5597 jlong os::current_thread_cpu_time() {
5598   if (os::Linux::supports_fast_thread_cpu_time()) {
5599     return os::Linux::fast_thread_cpu_time(CLOCK_THREAD_CPUTIME_ID);
5600   } else {
5601     // return user + sys since the cost is the same
5602     return slow_thread_cpu_time(Thread::current(), true /* user + sys */);
5603   }
5604 }
5605 
5606 jlong os::thread_cpu_time(Thread* thread) {
5607   // consistent with what current_thread_cpu_time() returns
5608   if (os::Linux::supports_fast_thread_cpu_time()) {
5609     return fast_cpu_time(thread);
5610   } else {
5611     return slow_thread_cpu_time(thread, true /* user + sys */);
5612   }
5613 }
5614 
5615 jlong os::current_thread_cpu_time(bool user_sys_cpu_time) {
5616   if (user_sys_cpu_time && os::Linux::supports_fast_thread_cpu_time()) {
5617     return os::Linux::fast_thread_cpu_time(CLOCK_THREAD_CPUTIME_ID);
5618   } else {
5619     return slow_thread_cpu_time(Thread::current(), user_sys_cpu_time);
5620   }
5621 }
5622 
5623 jlong os::thread_cpu_time(Thread *thread, bool user_sys_cpu_time) {
5624   if (user_sys_cpu_time && os::Linux::supports_fast_thread_cpu_time()) {
5625     return fast_cpu_time(thread);
5626   } else {
5627     return slow_thread_cpu_time(thread, user_sys_cpu_time);
5628   }
5629 }
5630 
5631 //  -1 on error.
5632 static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time) {
5633   pid_t  tid = thread->osthread()->thread_id();
5634   char *s;
5635   char stat[2048];
5636   int statlen;
5637   char proc_name[64];
5638   int count;
5639   long sys_time, user_time;
5640   char cdummy;
5641   int idummy;
5642   long ldummy;
5643   FILE *fp;
5644 
5645   snprintf(proc_name, 64, "/proc/self/task/%d/stat", tid);


< prev index next >