src/os/linux/vm/os_linux.cpp

Print this page




 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 bool os::Linux::_is_floating_stack = false;
 123 bool os::Linux::_is_NPTL = false;
 124 bool os::Linux::_supports_fast_thread_cpu_time = false;
 125 const char * os::Linux::_glibc_version = NULL;
 126 const char * os::Linux::_libpthread_version = NULL;
 127 
 128 static jlong initial_time_count=0;
 129 
 130 static int clock_tics_per_sec = 100;
 131 
 132 // For diagnostics to print a message once. see run_periodic_checks
 133 static sigset_t check_signal_done;
 134 static bool check_signals = true;;
 135 
 136 static pid_t _initial_pid = 0;
 137 
 138 /* Signal number used to suspend/resume a thread */
 139 
 140 /* do not use any signal number less than SIGSEGV, see 4355769 */
 141 static int SR_signum = SIGUSR2;


4232 
4233   init_random(1234567);
4234 
4235   ThreadCritical::initialize();
4236 
4237   Linux::set_page_size(sysconf(_SC_PAGESIZE));
4238   if (Linux::page_size() == -1) {
4239     fatal(err_msg("os_linux.cpp: os::init: sysconf failed (%s)",
4240                   strerror(errno)));
4241   }
4242   init_page_sizes((size_t) Linux::page_size());
4243 
4244   Linux::initialize_system_info();
4245 
4246   // main_thread points to the aboriginal thread
4247   Linux::_main_thread = pthread_self();
4248 
4249   Linux::clock_init();
4250   initial_time_count = os::elapsed_counter();
4251   pthread_mutex_init(&dl_mutex, NULL);









4252 }
4253 
4254 // To install functions for atexit system call
4255 extern "C" {
4256   static void perfMemory_exit_helper() {
4257     perfMemory_exit();
4258   }
4259 }
4260 
4261 // this is called _after_ the global arguments have been parsed
4262 jint os::init_2(void)
4263 {
4264   Linux::fast_thread_clock_init();
4265 
4266   // Allocate a single page and mark it as readable for safepoint polling
4267   address polling_page = (address) ::mmap(NULL, Linux::page_size(), PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
4268   guarantee( polling_page != MAP_FAILED, "os::init_2: failed to allocate polling page" );
4269 
4270   os::set_polling_page( polling_page );
4271 


4285 #endif
4286   }
4287 
4288   os::large_page_init();
4289 
4290   // initialize suspend/resume support - must do this before signal_sets_init()
4291   if (SR_initialize() != 0) {
4292     perror("SR_initialize failed");
4293     return JNI_ERR;
4294   }
4295 
4296   Linux::signal_sets_init();
4297   Linux::install_signal_handlers();
4298 
4299   // Check minimum allowable stack size for thread creation and to initialize
4300   // the java system classes, including StackOverflowError - depends on page
4301   // size.  Add a page for compiler2 recursion in main thread.
4302   // Add in 2*BytesPerWord times page size to account for VM stack during
4303   // class initialization depending on 32 or 64 bit VM.
4304   os::Linux::min_stack_allowed = MAX2(os::Linux::min_stack_allowed,
4305             (size_t)(StackYellowPages+StackRedPages+StackShadowPages+
4306                     2*BytesPerWord COMPILER2_PRESENT(+1)) * Linux::page_size());
4307 
4308   size_t threadStackSizeInBytes = ThreadStackSize * K;
4309   if (threadStackSizeInBytes != 0 &&
4310       threadStackSizeInBytes < os::Linux::min_stack_allowed) {
4311         tty->print_cr("\nThe stack size specified is too small, "
4312                       "Specify at least %dk",
4313                       os::Linux::min_stack_allowed/ K);
4314         return JNI_ERR;
4315   }
4316 
4317   // Make the stack size a multiple of the page size so that
4318   // the yellow/red zones can be guarded.
4319   JavaThread::set_stack_size_at_create(round_to(threadStackSizeInBytes,
4320         vm_page_size()));
4321 
4322   Linux::capture_initial_stack(JavaThread::stack_size_at_create());
4323 
4324   Linux::libpthread_init();
4325   if (PrintMiscellaneous && (Verbose || WizardMode)) {
4326      tty->print_cr("[HotSpot is running with %s, %s(%s)]\n",




 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;
 124 bool os::Linux::_is_NPTL = false;
 125 bool os::Linux::_supports_fast_thread_cpu_time = false;
 126 const char * os::Linux::_glibc_version = NULL;
 127 const char * os::Linux::_libpthread_version = NULL;
 128 
 129 static jlong initial_time_count=0;
 130 
 131 static int clock_tics_per_sec = 100;
 132 
 133 // For diagnostics to print a message once. see run_periodic_checks
 134 static sigset_t check_signal_done;
 135 static bool check_signals = true;;
 136 
 137 static pid_t _initial_pid = 0;
 138 
 139 /* Signal number used to suspend/resume a thread */
 140 
 141 /* do not use any signal number less than SIGSEGV, see 4355769 */
 142 static int SR_signum = SIGUSR2;


4233 
4234   init_random(1234567);
4235 
4236   ThreadCritical::initialize();
4237 
4238   Linux::set_page_size(sysconf(_SC_PAGESIZE));
4239   if (Linux::page_size() == -1) {
4240     fatal(err_msg("os_linux.cpp: os::init: sysconf failed (%s)",
4241                   strerror(errno)));
4242   }
4243   init_page_sizes((size_t) Linux::page_size());
4244 
4245   Linux::initialize_system_info();
4246 
4247   // main_thread points to the aboriginal thread
4248   Linux::_main_thread = pthread_self();
4249 
4250   Linux::clock_init();
4251   initial_time_count = os::elapsed_counter();
4252   pthread_mutex_init(&dl_mutex, NULL);
4253 
4254   // If the pagesize of the VM is greater than 8K determine the appropriate
4255   // number of initial guard pages.  The user can change this with the
4256   // command line arguments, if needed.
4257   if (vm_page_size() > (int)Linux::vm_default_page_size()) {
4258     StackYellowPages = 1;
4259     StackRedPages = 1;
4260     StackShadowPages = round_to((StackShadowPages*Linux::vm_default_page_size()), vm_page_size()) / vm_page_size();
4261   }
4262 }
4263 
4264 // To install functions for atexit system call
4265 extern "C" {
4266   static void perfMemory_exit_helper() {
4267     perfMemory_exit();
4268   }
4269 }
4270 
4271 // this is called _after_ the global arguments have been parsed
4272 jint os::init_2(void)
4273 {
4274   Linux::fast_thread_clock_init();
4275 
4276   // Allocate a single page and mark it as readable for safepoint polling
4277   address polling_page = (address) ::mmap(NULL, Linux::page_size(), PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
4278   guarantee( polling_page != MAP_FAILED, "os::init_2: failed to allocate polling page" );
4279 
4280   os::set_polling_page( polling_page );
4281 


4295 #endif
4296   }
4297 
4298   os::large_page_init();
4299 
4300   // initialize suspend/resume support - must do this before signal_sets_init()
4301   if (SR_initialize() != 0) {
4302     perror("SR_initialize failed");
4303     return JNI_ERR;
4304   }
4305 
4306   Linux::signal_sets_init();
4307   Linux::install_signal_handlers();
4308 
4309   // Check minimum allowable stack size for thread creation and to initialize
4310   // the java system classes, including StackOverflowError - depends on page
4311   // size.  Add a page for compiler2 recursion in main thread.
4312   // Add in 2*BytesPerWord times page size to account for VM stack during
4313   // class initialization depending on 32 or 64 bit VM.
4314   os::Linux::min_stack_allowed = MAX2(os::Linux::min_stack_allowed,
4315             (size_t)(StackYellowPages+StackRedPages+StackShadowPages) * Linux::page_size() +
4316                     (2*BytesPerWord COMPILER2_PRESENT(+1)) * Linux::vm_default_page_size());
4317 
4318   size_t threadStackSizeInBytes = ThreadStackSize * K;
4319   if (threadStackSizeInBytes != 0 &&
4320       threadStackSizeInBytes < os::Linux::min_stack_allowed) {
4321         tty->print_cr("\nThe stack size specified is too small, "
4322                       "Specify at least %dk",
4323                       os::Linux::min_stack_allowed/ K);
4324         return JNI_ERR;
4325   }
4326 
4327   // Make the stack size a multiple of the page size so that
4328   // the yellow/red zones can be guarded.
4329   JavaThread::set_stack_size_at_create(round_to(threadStackSizeInBytes,
4330         vm_page_size()));
4331 
4332   Linux::capture_initial_stack(JavaThread::stack_size_at_create());
4333 
4334   Linux::libpthread_init();
4335   if (PrintMiscellaneous && (Verbose || WizardMode)) {
4336      tty->print_cr("[HotSpot is running with %s, %s(%s)]\n",