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


< prev index next >