src/os/linux/vm/os_linux.cpp

Print this page




  84 # include <sys/time.h>
  85 # include <sys/times.h>
  86 # include <sys/utsname.h>
  87 # include <sys/socket.h>
  88 # include <sys/wait.h>
  89 # include <pwd.h>
  90 # include <poll.h>
  91 # include <semaphore.h>
  92 # include <fcntl.h>
  93 # include <string.h>
  94 # include <syscall.h>
  95 # include <sys/sysinfo.h>
  96 # include <gnu/libc-version.h>
  97 # include <sys/ipc.h>
  98 # include <sys/shm.h>
  99 # include <link.h>
 100 # include <stdint.h>
 101 # include <inttypes.h>
 102 # include <sys/ioctl.h>
 103 






 104 #define MAX_PATH    (2 * K)
 105 
 106 // for timer info max values which include all bits
 107 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF)
 108 
 109 #define LARGEPAGES_BIT (1 << 6)
 110 ////////////////////////////////////////////////////////////////////////////////
 111 // global variables
 112 julong os::Linux::_physical_memory = 0;
 113 
 114 address   os::Linux::_initial_thread_stack_bottom = NULL;
 115 uintptr_t os::Linux::_initial_thread_stack_size   = 0;
 116 
 117 int (*os::Linux::_clock_gettime)(clockid_t, struct timespec *) = NULL;
 118 int (*os::Linux::_pthread_getcpuclockid)(pthread_t, clockid_t *) = NULL;
 119 Mutex* os::Linux::_createThread_lock = NULL;
 120 pthread_t os::Linux::_main_thread;
 121 int os::Linux::_page_size = -1;
 122 const int os::Linux::_vm_default_page_size = (8 * K);
 123 bool os::Linux::_is_floating_stack = false;


1319 ////////////////////////////////////////////////////////////////////////////////
1320 // time support
1321 
1322 // Time since start-up in seconds to a fine granularity.
1323 // Used by VMSelfDestructTimer and the MemProfiler.
1324 double os::elapsedTime() {
1325 
1326   return (double)(os::elapsed_counter()) * 0.000001;
1327 }
1328 
1329 jlong os::elapsed_counter() {
1330   timeval time;
1331   int status = gettimeofday(&time, NULL);
1332   return jlong(time.tv_sec) * 1000 * 1000 + jlong(time.tv_usec) - initial_time_count;
1333 }
1334 
1335 jlong os::elapsed_frequency() {
1336   return (1000 * 1000);
1337 }
1338 
1339 // For now, we say that linux does not support vtime.  I have no idea
1340 // whether it can actually be made to (DLD, 9/13/05).
1341 
1342 bool os::supports_vtime() { return false; }
1343 bool os::enable_vtime()   { return false; }
1344 bool os::vtime_enabled()  { return false; }

1345 double os::elapsedVTime() {





1346   // better than nothing, but not much
1347   return elapsedTime();

1348 }
1349 
1350 jlong os::javaTimeMillis() {
1351   timeval time;
1352   int status = gettimeofday(&time, NULL);
1353   assert(status != -1, "linux error");
1354   return jlong(time.tv_sec) * 1000  +  jlong(time.tv_usec / 1000);
1355 }
1356 
1357 #ifndef CLOCK_MONOTONIC
1358 #define CLOCK_MONOTONIC (1)
1359 #endif
1360 
1361 void os::Linux::clock_init() {
1362   // we do dlopen's in this particular order due to bug in linux
1363   // dynamical loader (see 6348968) leading to crash on exit
1364   void* handle = dlopen("librt.so.1", RTLD_LAZY);
1365   if (handle == NULL) {
1366     handle = dlopen("librt.so", RTLD_LAZY);
1367   }




  84 # include <sys/time.h>
  85 # include <sys/times.h>
  86 # include <sys/utsname.h>
  87 # include <sys/socket.h>
  88 # include <sys/wait.h>
  89 # include <pwd.h>
  90 # include <poll.h>
  91 # include <semaphore.h>
  92 # include <fcntl.h>
  93 # include <string.h>
  94 # include <syscall.h>
  95 # include <sys/sysinfo.h>
  96 # include <gnu/libc-version.h>
  97 # include <sys/ipc.h>
  98 # include <sys/shm.h>
  99 # include <link.h>
 100 # include <stdint.h>
 101 # include <inttypes.h>
 102 # include <sys/ioctl.h>
 103 
 104 // if RUSAGE_THREAD for getrusage() has not been defined, do it here. The code calling
 105 // getrusage() is prepared to handle the associated failure.
 106 #ifndef RUSAGE_THREAD
 107 #define RUSAGE_THREAD   1               /* only the calling thread */
 108 #endif
 109 
 110 #define MAX_PATH    (2 * K)
 111 
 112 // for timer info max values which include all bits
 113 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF)
 114 
 115 #define LARGEPAGES_BIT (1 << 6)
 116 ////////////////////////////////////////////////////////////////////////////////
 117 // global variables
 118 julong os::Linux::_physical_memory = 0;
 119 
 120 address   os::Linux::_initial_thread_stack_bottom = NULL;
 121 uintptr_t os::Linux::_initial_thread_stack_size   = 0;
 122 
 123 int (*os::Linux::_clock_gettime)(clockid_t, struct timespec *) = NULL;
 124 int (*os::Linux::_pthread_getcpuclockid)(pthread_t, clockid_t *) = NULL;
 125 Mutex* os::Linux::_createThread_lock = NULL;
 126 pthread_t os::Linux::_main_thread;
 127 int os::Linux::_page_size = -1;
 128 const int os::Linux::_vm_default_page_size = (8 * K);
 129 bool os::Linux::_is_floating_stack = false;


1325 ////////////////////////////////////////////////////////////////////////////////
1326 // time support
1327 
1328 // Time since start-up in seconds to a fine granularity.
1329 // Used by VMSelfDestructTimer and the MemProfiler.
1330 double os::elapsedTime() {
1331 
1332   return (double)(os::elapsed_counter()) * 0.000001;
1333 }
1334 
1335 jlong os::elapsed_counter() {
1336   timeval time;
1337   int status = gettimeofday(&time, NULL);
1338   return jlong(time.tv_sec) * 1000 * 1000 + jlong(time.tv_usec) - initial_time_count;
1339 }
1340 
1341 jlong os::elapsed_frequency() {
1342   return (1000 * 1000);
1343 }
1344 
1345 bool os::supports_vtime() { return true; }



1346 bool os::enable_vtime()   { return false; }
1347 bool os::vtime_enabled()  { return false; }
1348 
1349 double os::elapsedVTime() {
1350   struct rusage usage;
1351   int retval = getrusage(RUSAGE_THREAD, &usage);
1352   if (retval == 0) {
1353     return (double) (usage.ru_utime.tv_sec + usage.ru_stime.tv_sec) + (double) (usage.ru_utime.tv_usec + usage.ru_stime.tv_usec) / (1000 * 1000);
1354   } else {
1355     // better than nothing, but not much
1356     return elapsedTime();
1357   }
1358 }
1359 
1360 jlong os::javaTimeMillis() {
1361   timeval time;
1362   int status = gettimeofday(&time, NULL);
1363   assert(status != -1, "linux error");
1364   return jlong(time.tv_sec) * 1000  +  jlong(time.tv_usec / 1000);
1365 }
1366 
1367 #ifndef CLOCK_MONOTONIC
1368 #define CLOCK_MONOTONIC (1)
1369 #endif
1370 
1371 void os::Linux::clock_init() {
1372   // we do dlopen's in this particular order due to bug in linux
1373   // dynamical loader (see 6348968) leading to crash on exit
1374   void* handle = dlopen("librt.so.1", RTLD_LAZY);
1375   if (handle == NULL) {
1376     handle = dlopen("librt.so", RTLD_LAZY);
1377   }