src/os/linux/vm/os_linux.cpp

Print this page




1882 void * os::Linux::dll_load_in_vmthread(const char *filename, char *ebuf,
1883                                        int ebuflen) {
1884   void * result = NULL;
1885   if (LoadExecStackDllInVMThread) {
1886     result = dlopen_helper(filename, ebuf, ebuflen);
1887   }
1888 
1889   // Since 7019808, libjvm.so is linked with -noexecstack. If the VM loads a
1890   // library that requires an executable stack, or which does not have this
1891   // stack attribute set, dlopen changes the stack attribute to executable. The
1892   // read protection of the guard pages gets lost.
1893   //
1894   // Need to check _stack_is_executable again as multiple VM_LinuxDllLoad
1895   // may have been queued at the same time.
1896 
1897   if (!_stack_is_executable) {
1898     JavaThread *jt = Threads::first();
1899 
1900     while (jt) {
1901       if (!jt->stack_guard_zone_unused() &&        // Stack not yet fully initialized
1902           jt->stack_yellow_zone_enabled()) {       // No pending stack overflow exceptions
1903         if (!os::guard_memory((char *) jt->stack_red_zone_base() - jt->stack_red_zone_size(),
1904                               jt->stack_yellow_zone_size() + jt->stack_red_zone_size())) {
1905           warning("Attempt to reguard stack yellow zone failed.");
1906         }
1907       }
1908       jt = jt->next();
1909     }
1910   }
1911 
1912   return result;
1913 }
1914 
1915 void* os::dll_lookup(void* handle, const char* name) {
1916   void* res = dlsym(handle, name);
1917   return res;
1918 }
1919 
1920 void* os::get_default_process_handle() {
1921   return (void*)::dlopen(NULL, RTLD_LAZY);
1922 }


4631   }
4632   // Only set the clock if CLOCK_MONOTONIC is available
4633   if (os::supports_monotonic_clock()) {
4634     if ((status = pthread_condattr_setclock(_condattr, CLOCK_MONOTONIC)) != 0) {
4635       if (status == EINVAL) {
4636         warning("Unable to use monotonic clock with relative timed-waits" \
4637                 " - changes to the time-of-day clock may have adverse affects");
4638       } else {
4639         fatal("pthread_condattr_setclock: %s", strerror(status));
4640       }
4641     }
4642   }
4643   // else it defaults to CLOCK_REALTIME
4644 
4645   // If the pagesize of the VM is greater than 8K determine the appropriate
4646   // number of initial guard pages.  The user can change this with the
4647   // command line arguments, if needed.
4648   if (vm_page_size() > (int)Linux::vm_default_page_size()) {
4649     StackYellowPages = 1;
4650     StackRedPages = 1;





4651     StackShadowPages = round_to((StackShadowPages*Linux::vm_default_page_size()), vm_page_size()) / vm_page_size();
4652   }
4653 
4654   // retrieve entry point for pthread_setname_np
4655   Linux::_pthread_setname_np =
4656     (int(*)(pthread_t, const char*))dlsym(RTLD_DEFAULT, "pthread_setname_np");
4657 
4658 }
4659 
4660 // To install functions for atexit system call
4661 extern "C" {
4662   static void perfMemory_exit_helper() {
4663     perfMemory_exit();
4664   }
4665 }
4666 
4667 // this is called _after_ the global arguments have been parsed
4668 jint os::init_2(void) {
4669   Linux::fast_thread_clock_init();
4670 


4692                  (intptr_t)mem_serialize_page);
4693     }
4694 #endif
4695   }
4696 
4697   // initialize suspend/resume support - must do this before signal_sets_init()
4698   if (SR_initialize() != 0) {
4699     perror("SR_initialize failed");
4700     return JNI_ERR;
4701   }
4702 
4703   Linux::signal_sets_init();
4704   Linux::install_signal_handlers();
4705 
4706   // Check minimum allowable stack size for thread creation and to initialize
4707   // the java system classes, including StackOverflowError - depends on page
4708   // size.  Add a page for compiler2 recursion in main thread.
4709   // Add in 2*BytesPerWord times page size to account for VM stack during
4710   // class initialization depending on 32 or 64 bit VM.
4711   os::Linux::min_stack_allowed = MAX2(os::Linux::min_stack_allowed,
4712                                       (size_t)(StackYellowPages+StackRedPages+StackShadowPages) * Linux::page_size() +
4713                                       (2*BytesPerWord COMPILER2_PRESENT(+1)) * Linux::vm_default_page_size());
4714 
4715   size_t threadStackSizeInBytes = ThreadStackSize * K;
4716   if (threadStackSizeInBytes != 0 &&
4717       threadStackSizeInBytes < os::Linux::min_stack_allowed) {
4718     tty->print_cr("\nThe stack size specified is too small, "
4719                   "Specify at least " SIZE_FORMAT "k",
4720                   os::Linux::min_stack_allowed/ K);
4721     return JNI_ERR;
4722   }
4723 
4724   // Make the stack size a multiple of the page size so that
4725   // the yellow/red zones can be guarded.
4726   JavaThread::set_stack_size_at_create(round_to(threadStackSizeInBytes,
4727                                                 vm_page_size()));
4728 
4729   Linux::capture_initial_stack(JavaThread::stack_size_at_create());
4730 
4731 #if defined(IA32)
4732   workaround_expand_exec_shield_cs_limit();




1882 void * os::Linux::dll_load_in_vmthread(const char *filename, char *ebuf,
1883                                        int ebuflen) {
1884   void * result = NULL;
1885   if (LoadExecStackDllInVMThread) {
1886     result = dlopen_helper(filename, ebuf, ebuflen);
1887   }
1888 
1889   // Since 7019808, libjvm.so is linked with -noexecstack. If the VM loads a
1890   // library that requires an executable stack, or which does not have this
1891   // stack attribute set, dlopen changes the stack attribute to executable. The
1892   // read protection of the guard pages gets lost.
1893   //
1894   // Need to check _stack_is_executable again as multiple VM_LinuxDllLoad
1895   // may have been queued at the same time.
1896 
1897   if (!_stack_is_executable) {
1898     JavaThread *jt = Threads::first();
1899 
1900     while (jt) {
1901       if (!jt->stack_guard_zone_unused() &&     // Stack not yet fully initialized
1902           jt->stack_guards_enabled()) {         // No pending stack overflow exceptions
1903         if (!os::guard_memory((char *) jt->stack_red_zone_base() - jt->stack_red_zone_size(),
1904                               jt->stack_yellow_zone_size() + jt->stack_red_zone_size())) {
1905           warning("Attempt to reguard stack yellow zone failed.");
1906         }
1907       }
1908       jt = jt->next();
1909     }
1910   }
1911 
1912   return result;
1913 }
1914 
1915 void* os::dll_lookup(void* handle, const char* name) {
1916   void* res = dlsym(handle, name);
1917   return res;
1918 }
1919 
1920 void* os::get_default_process_handle() {
1921   return (void*)::dlopen(NULL, RTLD_LAZY);
1922 }


4631   }
4632   // Only set the clock if CLOCK_MONOTONIC is available
4633   if (os::supports_monotonic_clock()) {
4634     if ((status = pthread_condattr_setclock(_condattr, CLOCK_MONOTONIC)) != 0) {
4635       if (status == EINVAL) {
4636         warning("Unable to use monotonic clock with relative timed-waits" \
4637                 " - changes to the time-of-day clock may have adverse affects");
4638       } else {
4639         fatal("pthread_condattr_setclock: %s", strerror(status));
4640       }
4641     }
4642   }
4643   // else it defaults to CLOCK_REALTIME
4644 
4645   // If the pagesize of the VM is greater than 8K determine the appropriate
4646   // number of initial guard pages.  The user can change this with the
4647   // command line arguments, if needed.
4648   if (vm_page_size() > (int)Linux::vm_default_page_size()) {
4649     StackYellowPages = 1;
4650     StackRedPages = 1;
4651 #if defined(IA32) || defined(IA64)
4652     StackReservedPages = 1;
4653 #else
4654     StackReservedPages = 0;
4655 #endif
4656     StackShadowPages = round_to((StackShadowPages*Linux::vm_default_page_size()), vm_page_size()) / vm_page_size();
4657   }
4658 
4659   // retrieve entry point for pthread_setname_np
4660   Linux::_pthread_setname_np =
4661     (int(*)(pthread_t, const char*))dlsym(RTLD_DEFAULT, "pthread_setname_np");
4662 
4663 }
4664 
4665 // To install functions for atexit system call
4666 extern "C" {
4667   static void perfMemory_exit_helper() {
4668     perfMemory_exit();
4669   }
4670 }
4671 
4672 // this is called _after_ the global arguments have been parsed
4673 jint os::init_2(void) {
4674   Linux::fast_thread_clock_init();
4675 


4697                  (intptr_t)mem_serialize_page);
4698     }
4699 #endif
4700   }
4701 
4702   // initialize suspend/resume support - must do this before signal_sets_init()
4703   if (SR_initialize() != 0) {
4704     perror("SR_initialize failed");
4705     return JNI_ERR;
4706   }
4707 
4708   Linux::signal_sets_init();
4709   Linux::install_signal_handlers();
4710 
4711   // Check minimum allowable stack size for thread creation and to initialize
4712   // the java system classes, including StackOverflowError - depends on page
4713   // size.  Add a page for compiler2 recursion in main thread.
4714   // Add in 2*BytesPerWord times page size to account for VM stack during
4715   // class initialization depending on 32 or 64 bit VM.
4716   os::Linux::min_stack_allowed = MAX2(os::Linux::min_stack_allowed,
4717                                       (size_t)(StackReservedPages+StackYellowPages+StackRedPages+StackShadowPages) * Linux::page_size() +
4718                                       (2*BytesPerWord COMPILER2_PRESENT(+1)) * Linux::vm_default_page_size());
4719 
4720   size_t threadStackSizeInBytes = ThreadStackSize * K;
4721   if (threadStackSizeInBytes != 0 &&
4722       threadStackSizeInBytes < os::Linux::min_stack_allowed) {
4723     tty->print_cr("\nThe stack size specified is too small, "
4724                   "Specify at least " SIZE_FORMAT "k",
4725                   os::Linux::min_stack_allowed/ K);
4726     return JNI_ERR;
4727   }
4728 
4729   // Make the stack size a multiple of the page size so that
4730   // the yellow/red zones can be guarded.
4731   JavaThread::set_stack_size_at_create(round_to(threadStackSizeInBytes,
4732                                                 vm_page_size()));
4733 
4734   Linux::capture_initial_stack(JavaThread::stack_size_at_create());
4735 
4736 #if defined(IA32)
4737   workaround_expand_exec_shield_cs_limit();