< prev index next >

src/hotspot/os/linux/os_linux.cpp

Print this page
rev 56578 : 8232211: Remove dead code from os.hpp|cpp
Reviewed-by: TBD
rev 56579 : imported patch dead_os2


 131 
 132 // for timer info max values which include all bits
 133 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF)
 134 
 135 enum CoredumpFilterBit {
 136   FILE_BACKED_PVT_BIT = 1 << 2,
 137   FILE_BACKED_SHARED_BIT = 1 << 3,
 138   LARGEPAGES_BIT = 1 << 6,
 139   DAX_SHARED_BIT = 1 << 8
 140 };
 141 
 142 ////////////////////////////////////////////////////////////////////////////////
 143 // global variables
 144 julong os::Linux::_physical_memory = 0;
 145 
 146 address   os::Linux::_initial_thread_stack_bottom = NULL;
 147 uintptr_t os::Linux::_initial_thread_stack_size   = 0;
 148 
 149 int (*os::Linux::_pthread_getcpuclockid)(pthread_t, clockid_t *) = NULL;
 150 int (*os::Linux::_pthread_setname_np)(pthread_t, const char*) = NULL;
 151 Mutex* os::Linux::_createThread_lock = NULL;
 152 pthread_t os::Linux::_main_thread;
 153 int os::Linux::_page_size = -1;
 154 bool os::Linux::_supports_fast_thread_cpu_time = false;
 155 uint32_t os::Linux::_os_version = 0;
 156 const char * os::Linux::_glibc_version = NULL;
 157 const char * os::Linux::_libpthread_version = NULL;
 158 
 159 static jlong initial_time_count=0;
 160 
 161 static int clock_tics_per_sec = 100;
 162 
 163 // If the VM might have been created on the primordial thread, we need to resolve the
 164 // primordial thread stack bounds and check if the current thread might be the
 165 // primordial thread in places. If we know that the primordial thread is never used,
 166 // such as when the VM was created by one of the standard java launchers, we can
 167 // avoid this
 168 static bool suppress_primordial_thread_resolution = false;
 169 
 170 // For diagnostics to print a message once. see run_periodic_checks
 171 static sigset_t check_signal_done;
 172 static bool check_signals = true;
 173 
 174 // Signal number used to suspend/resume a thread
 175 


1347 #ifndef SUPPORTS_CLOCK_MONOTONIC
1348 #error "Build platform doesn't support clock_gettime and related functionality"
1349 #endif
1350 
1351 // Time since start-up in seconds to a fine granularity.
1352 // Used by VMSelfDestructTimer and the MemProfiler.
1353 double os::elapsedTime() {
1354 
1355   return ((double)os::elapsed_counter()) / os::elapsed_frequency(); // nanosecond resolution
1356 }
1357 
1358 jlong os::elapsed_counter() {
1359   return javaTimeNanos() - initial_time_count;
1360 }
1361 
1362 jlong os::elapsed_frequency() {
1363   return NANOSECS_PER_SEC; // nanosecond resolution
1364 }
1365 
1366 bool os::supports_vtime() { return true; }
1367 bool os::enable_vtime()   { return false; }
1368 bool os::vtime_enabled()  { return false; }
1369 
1370 double os::elapsedVTime() {
1371   struct rusage usage;
1372   int retval = getrusage(RUSAGE_THREAD, &usage);
1373   if (retval == 0) {
1374     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);
1375   } else {
1376     // better than nothing, but not much
1377     return elapsedTime();
1378   }
1379 }
1380 
1381 jlong os::javaTimeMillis() {
1382   timeval time;
1383   int status = gettimeofday(&time, NULL);
1384   assert(status != -1, "linux error");
1385   return jlong(time.tv_sec) * 1000  +  jlong(time.tv_usec / 1000);
1386 }
1387 
1388 void os::javaTimeSystemUTC(jlong &seconds, jlong &nanos) {


4806       }
4807     }
4808   }
4809 }
4810 
4811 // This is the fastest way to get thread cpu time on Linux.
4812 // Returns cpu time (user+sys) for any thread, not only for current.
4813 // POSIX compliant clocks are implemented in the kernels 2.6.16+.
4814 // It might work on 2.6.10+ with a special kernel/glibc patch.
4815 // For reference, please, see IEEE Std 1003.1-2004:
4816 //   http://www.unix.org/single_unix_specification
4817 
4818 jlong os::Linux::fast_thread_cpu_time(clockid_t clockid) {
4819   struct timespec tp;
4820   int rc = os::Posix::clock_gettime(clockid, &tp);
4821   assert(rc == 0, "clock_gettime is expected to return 0 code");
4822 
4823   return (tp.tv_sec * NANOSECS_PER_SEC) + tp.tv_nsec;
4824 }
4825 
4826 void os::Linux::initialize_os_info() {
4827   assert(_os_version == 0, "OS info already initialized");
4828 
4829   struct utsname _uname;
4830 
4831   uint32_t major;
4832   uint32_t minor;
4833   uint32_t fix;
4834 
4835   int rc;
4836 
4837   // Kernel version is unknown if
4838   // verification below fails.
4839   _os_version = 0x01000000;
4840 
4841   rc = uname(&_uname);
4842   if (rc != -1) {
4843 
4844     rc = sscanf(_uname.release,"%d.%d.%d", &major, &minor, &fix);
4845     if (rc == 3) {
4846 
4847       if (major < 256 && minor < 256 && fix < 256) {
4848         // Kernel version format is as expected,
4849         // set it overriding unknown state.
4850         _os_version = (major << 16) |
4851                       (minor << 8 ) |
4852                       (fix   << 0 ) ;
4853       }
4854     }
4855   }
4856 }
4857 
4858 uint32_t os::Linux::os_version() {
4859   assert(_os_version != 0, "not initialized");
4860   return _os_version & 0x00FFFFFF;
4861 }
4862 
4863 bool os::Linux::os_version_is_known() {
4864   assert(_os_version != 0, "not initialized");
4865   return _os_version & 0x01000000 ? false : true;
4866 }
4867 
4868 /////
4869 // glibc on Linux platform uses non-documented flag
4870 // to indicate, that some special sort of signal
4871 // trampoline is used.
4872 // We will never set this flag, and we should
4873 // ignore this flag in our diagnostic
4874 #ifdef SIGNIFICANT_SIGNAL_MASK
4875   #undef SIGNIFICANT_SIGNAL_MASK
4876 #endif
4877 #define SIGNIFICANT_SIGNAL_MASK (~0x04000000)
4878 
4879 static const char* get_signal_handler_name(address handler,
4880                                            char* buf, int buflen) {
4881   int offset = 0;
4882   bool found = os::dll_address_to_library_name(handler, buf, buflen, &offset);
4883   if (found) {
4884     // skip directory names
4885     const char *p1, *p2;
4886     p1 = buf;
4887     size_t len = strlen(os::file_separator());


5067 extern void report_error(char* file_name, int line_no, char* title,
5068                          char* format, ...);
5069 
5070 // this is called _before_ most of the global arguments have been parsed
5071 void os::init(void) {
5072   char dummy;   // used to get a guess on initial stack address
5073 
5074   clock_tics_per_sec = sysconf(_SC_CLK_TCK);
5075 
5076   init_random(1234567);
5077 
5078   Linux::set_page_size(sysconf(_SC_PAGESIZE));
5079   if (Linux::page_size() == -1) {
5080     fatal("os_linux.cpp: os::init: sysconf failed (%s)",
5081           os::strerror(errno));
5082   }
5083   init_page_sizes((size_t) Linux::page_size());
5084 
5085   Linux::initialize_system_info();
5086 
5087   Linux::initialize_os_info();
5088 
5089   os::Linux::CPUPerfTicks pticks;
5090   bool res = os::Linux::get_tick_information(&pticks, -1);
5091 
5092   if (res && pticks.has_steal_ticks) {
5093     has_initial_tick_info = true;
5094     initial_total_ticks = pticks.total;
5095     initial_steal_ticks = pticks.steal;
5096   }
5097 
5098   // _main_thread points to the thread that created/loaded the JVM.
5099   Linux::_main_thread = pthread_self();
5100 
5101   // retrieve entry point for pthread_setname_np
5102   Linux::_pthread_setname_np =
5103     (int(*)(pthread_t, const char*))dlsym(RTLD_DEFAULT, "pthread_setname_np");
5104 
5105   os::Posix::init();
5106 
5107   initial_time_count = javaTimeNanos();
5108 


5245   if (UseNUMA) {
5246     Linux::numa_init();
5247   }
5248 
5249   if (MaxFDLimit) {
5250     // set the number of file descriptors to max. print out error
5251     // if getrlimit/setrlimit fails but continue regardless.
5252     struct rlimit nbr_files;
5253     int status = getrlimit(RLIMIT_NOFILE, &nbr_files);
5254     if (status != 0) {
5255       log_info(os)("os::init_2 getrlimit failed: %s", os::strerror(errno));
5256     } else {
5257       nbr_files.rlim_cur = nbr_files.rlim_max;
5258       status = setrlimit(RLIMIT_NOFILE, &nbr_files);
5259       if (status != 0) {
5260         log_info(os)("os::init_2 setrlimit failed: %s", os::strerror(errno));
5261       }
5262     }
5263   }
5264 
5265   // Initialize lock used to serialize thread creation (see os::create_thread)
5266   Linux::set_createThread_lock(new Mutex(Mutex::leaf, "createThread_lock", false));
5267 
5268   // at-exit methods are called in the reverse order of their registration.
5269   // atexit functions are called on return from main or as a result of a
5270   // call to exit(3C). There can be only 32 of these functions registered
5271   // and atexit() does not set errno.
5272 
5273   if (PerfAllowAtExitRegistration) {
5274     // only register atexit functions if PerfAllowAtExitRegistration is set.
5275     // atexit functions can be delayed until process exit time, which
5276     // can be problematic for embedded VM situations. Embedded VMs should
5277     // call DestroyJavaVM() to assure that VM resources are released.
5278 
5279     // note: perfMemory_exit_helper atexit function may be removed in
5280     // the future if the appropriate cleanup code can be added to the
5281     // VM_Exit VMOperation's doit method.
5282     if (atexit(perfMemory_exit_helper) != 0) {
5283       warning("os::init_2 atexit(perfMemory_exit_helper) failed");
5284     }
5285   }
5286 
5287   // initialize thread priority policy


5446   }
5447 
5448   return active_cpus;
5449 }
5450 
5451 uint os::processor_id() {
5452   const int id = Linux::sched_getcpu();
5453   assert(id >= 0 && id < _processor_count, "Invalid processor id");
5454   return (uint)id;
5455 }
5456 
5457 void os::set_native_thread_name(const char *name) {
5458   if (Linux::_pthread_setname_np) {
5459     char buf [16]; // according to glibc manpage, 16 chars incl. '/0'
5460     snprintf(buf, sizeof(buf), "%s", name);
5461     buf[sizeof(buf) - 1] = '\0';
5462     const int rc = Linux::_pthread_setname_np(pthread_self(), buf);
5463     // ERANGE should not happen; all other errors should just be ignored.
5464     assert(rc != ERANGE, "pthread_setname_np failed");
5465   }
5466 }
5467 
5468 bool os::distribute_processes(uint length, uint* distribution) {
5469   // Not yet implemented.
5470   return false;
5471 }
5472 
5473 bool os::bind_to_processor(uint processor_id) {
5474   // Not yet implemented.
5475   return false;
5476 }
5477 
5478 ///
5479 
5480 void os::SuspendedThreadTask::internal_do_task() {
5481   if (do_suspend(_thread->osthread())) {
5482     SuspendedThreadTaskContext context(_thread, _thread->osthread()->ucontext());
5483     do_task(context);
5484     do_resume(_thread->osthread());
5485   }
5486 }
5487 
5488 ////////////////////////////////////////////////////////////////////////////////
5489 // debug support
5490 




 131 
 132 // for timer info max values which include all bits
 133 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF)
 134 
 135 enum CoredumpFilterBit {
 136   FILE_BACKED_PVT_BIT = 1 << 2,
 137   FILE_BACKED_SHARED_BIT = 1 << 3,
 138   LARGEPAGES_BIT = 1 << 6,
 139   DAX_SHARED_BIT = 1 << 8
 140 };
 141 
 142 ////////////////////////////////////////////////////////////////////////////////
 143 // global variables
 144 julong os::Linux::_physical_memory = 0;
 145 
 146 address   os::Linux::_initial_thread_stack_bottom = NULL;
 147 uintptr_t os::Linux::_initial_thread_stack_size   = 0;
 148 
 149 int (*os::Linux::_pthread_getcpuclockid)(pthread_t, clockid_t *) = NULL;
 150 int (*os::Linux::_pthread_setname_np)(pthread_t, const char*) = NULL;

 151 pthread_t os::Linux::_main_thread;
 152 int os::Linux::_page_size = -1;
 153 bool os::Linux::_supports_fast_thread_cpu_time = false;

 154 const char * os::Linux::_glibc_version = NULL;
 155 const char * os::Linux::_libpthread_version = NULL;
 156 
 157 static jlong initial_time_count=0;
 158 
 159 static int clock_tics_per_sec = 100;
 160 
 161 // If the VM might have been created on the primordial thread, we need to resolve the
 162 // primordial thread stack bounds and check if the current thread might be the
 163 // primordial thread in places. If we know that the primordial thread is never used,
 164 // such as when the VM was created by one of the standard java launchers, we can
 165 // avoid this
 166 static bool suppress_primordial_thread_resolution = false;
 167 
 168 // For diagnostics to print a message once. see run_periodic_checks
 169 static sigset_t check_signal_done;
 170 static bool check_signals = true;
 171 
 172 // Signal number used to suspend/resume a thread
 173 


1345 #ifndef SUPPORTS_CLOCK_MONOTONIC
1346 #error "Build platform doesn't support clock_gettime and related functionality"
1347 #endif
1348 
1349 // Time since start-up in seconds to a fine granularity.
1350 // Used by VMSelfDestructTimer and the MemProfiler.
1351 double os::elapsedTime() {
1352 
1353   return ((double)os::elapsed_counter()) / os::elapsed_frequency(); // nanosecond resolution
1354 }
1355 
1356 jlong os::elapsed_counter() {
1357   return javaTimeNanos() - initial_time_count;
1358 }
1359 
1360 jlong os::elapsed_frequency() {
1361   return NANOSECS_PER_SEC; // nanosecond resolution
1362 }
1363 
1364 bool os::supports_vtime() { return true; }


1365 
1366 double os::elapsedVTime() {
1367   struct rusage usage;
1368   int retval = getrusage(RUSAGE_THREAD, &usage);
1369   if (retval == 0) {
1370     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);
1371   } else {
1372     // better than nothing, but not much
1373     return elapsedTime();
1374   }
1375 }
1376 
1377 jlong os::javaTimeMillis() {
1378   timeval time;
1379   int status = gettimeofday(&time, NULL);
1380   assert(status != -1, "linux error");
1381   return jlong(time.tv_sec) * 1000  +  jlong(time.tv_usec / 1000);
1382 }
1383 
1384 void os::javaTimeSystemUTC(jlong &seconds, jlong &nanos) {


4802       }
4803     }
4804   }
4805 }
4806 
4807 // This is the fastest way to get thread cpu time on Linux.
4808 // Returns cpu time (user+sys) for any thread, not only for current.
4809 // POSIX compliant clocks are implemented in the kernels 2.6.16+.
4810 // It might work on 2.6.10+ with a special kernel/glibc patch.
4811 // For reference, please, see IEEE Std 1003.1-2004:
4812 //   http://www.unix.org/single_unix_specification
4813 
4814 jlong os::Linux::fast_thread_cpu_time(clockid_t clockid) {
4815   struct timespec tp;
4816   int rc = os::Posix::clock_gettime(clockid, &tp);
4817   assert(rc == 0, "clock_gettime is expected to return 0 code");
4818 
4819   return (tp.tv_sec * NANOSECS_PER_SEC) + tp.tv_nsec;
4820 }
4821 










































4822 /////
4823 // glibc on Linux platform uses non-documented flag
4824 // to indicate, that some special sort of signal
4825 // trampoline is used.
4826 // We will never set this flag, and we should
4827 // ignore this flag in our diagnostic
4828 #ifdef SIGNIFICANT_SIGNAL_MASK
4829   #undef SIGNIFICANT_SIGNAL_MASK
4830 #endif
4831 #define SIGNIFICANT_SIGNAL_MASK (~0x04000000)
4832 
4833 static const char* get_signal_handler_name(address handler,
4834                                            char* buf, int buflen) {
4835   int offset = 0;
4836   bool found = os::dll_address_to_library_name(handler, buf, buflen, &offset);
4837   if (found) {
4838     // skip directory names
4839     const char *p1, *p2;
4840     p1 = buf;
4841     size_t len = strlen(os::file_separator());


5021 extern void report_error(char* file_name, int line_no, char* title,
5022                          char* format, ...);
5023 
5024 // this is called _before_ most of the global arguments have been parsed
5025 void os::init(void) {
5026   char dummy;   // used to get a guess on initial stack address
5027 
5028   clock_tics_per_sec = sysconf(_SC_CLK_TCK);
5029 
5030   init_random(1234567);
5031 
5032   Linux::set_page_size(sysconf(_SC_PAGESIZE));
5033   if (Linux::page_size() == -1) {
5034     fatal("os_linux.cpp: os::init: sysconf failed (%s)",
5035           os::strerror(errno));
5036   }
5037   init_page_sizes((size_t) Linux::page_size());
5038 
5039   Linux::initialize_system_info();
5040 


5041   os::Linux::CPUPerfTicks pticks;
5042   bool res = os::Linux::get_tick_information(&pticks, -1);
5043 
5044   if (res && pticks.has_steal_ticks) {
5045     has_initial_tick_info = true;
5046     initial_total_ticks = pticks.total;
5047     initial_steal_ticks = pticks.steal;
5048   }
5049 
5050   // _main_thread points to the thread that created/loaded the JVM.
5051   Linux::_main_thread = pthread_self();
5052 
5053   // retrieve entry point for pthread_setname_np
5054   Linux::_pthread_setname_np =
5055     (int(*)(pthread_t, const char*))dlsym(RTLD_DEFAULT, "pthread_setname_np");
5056 
5057   os::Posix::init();
5058 
5059   initial_time_count = javaTimeNanos();
5060 


5197   if (UseNUMA) {
5198     Linux::numa_init();
5199   }
5200 
5201   if (MaxFDLimit) {
5202     // set the number of file descriptors to max. print out error
5203     // if getrlimit/setrlimit fails but continue regardless.
5204     struct rlimit nbr_files;
5205     int status = getrlimit(RLIMIT_NOFILE, &nbr_files);
5206     if (status != 0) {
5207       log_info(os)("os::init_2 getrlimit failed: %s", os::strerror(errno));
5208     } else {
5209       nbr_files.rlim_cur = nbr_files.rlim_max;
5210       status = setrlimit(RLIMIT_NOFILE, &nbr_files);
5211       if (status != 0) {
5212         log_info(os)("os::init_2 setrlimit failed: %s", os::strerror(errno));
5213       }
5214     }
5215   }
5216 



5217   // at-exit methods are called in the reverse order of their registration.
5218   // atexit functions are called on return from main or as a result of a
5219   // call to exit(3C). There can be only 32 of these functions registered
5220   // and atexit() does not set errno.
5221 
5222   if (PerfAllowAtExitRegistration) {
5223     // only register atexit functions if PerfAllowAtExitRegistration is set.
5224     // atexit functions can be delayed until process exit time, which
5225     // can be problematic for embedded VM situations. Embedded VMs should
5226     // call DestroyJavaVM() to assure that VM resources are released.
5227 
5228     // note: perfMemory_exit_helper atexit function may be removed in
5229     // the future if the appropriate cleanup code can be added to the
5230     // VM_Exit VMOperation's doit method.
5231     if (atexit(perfMemory_exit_helper) != 0) {
5232       warning("os::init_2 atexit(perfMemory_exit_helper) failed");
5233     }
5234   }
5235 
5236   // initialize thread priority policy


5395   }
5396 
5397   return active_cpus;
5398 }
5399 
5400 uint os::processor_id() {
5401   const int id = Linux::sched_getcpu();
5402   assert(id >= 0 && id < _processor_count, "Invalid processor id");
5403   return (uint)id;
5404 }
5405 
5406 void os::set_native_thread_name(const char *name) {
5407   if (Linux::_pthread_setname_np) {
5408     char buf [16]; // according to glibc manpage, 16 chars incl. '/0'
5409     snprintf(buf, sizeof(buf), "%s", name);
5410     buf[sizeof(buf) - 1] = '\0';
5411     const int rc = Linux::_pthread_setname_np(pthread_self(), buf);
5412     // ERANGE should not happen; all other errors should just be ignored.
5413     assert(rc != ERANGE, "pthread_setname_np failed");
5414   }





5415 }
5416 
5417 bool os::bind_to_processor(uint processor_id) {
5418   // Not yet implemented.
5419   return false;
5420 }
5421 
5422 ///
5423 
5424 void os::SuspendedThreadTask::internal_do_task() {
5425   if (do_suspend(_thread->osthread())) {
5426     SuspendedThreadTaskContext context(_thread, _thread->osthread()->ucontext());
5427     do_task(context);
5428     do_resume(_thread->osthread());
5429   }
5430 }
5431 
5432 ////////////////////////////////////////////////////////////////////////////////
5433 // debug support
5434 


< prev index next >