hotspot/src/os/linux/vm/os_linux.cpp
changeset 41070 496463b4e206
parent 40929 de043f8e5c04
child 42062 473286891dd8
equal deleted inserted replaced
40931:d4d2a4a0e023 41070:496463b4e206
   699 
   699 
   700   return 0;
   700   return 0;
   701 }
   701 }
   702 
   702 
   703 bool os::create_thread(Thread* thread, ThreadType thr_type,
   703 bool os::create_thread(Thread* thread, ThreadType thr_type,
   704                        size_t stack_size) {
   704                        size_t req_stack_size) {
   705   assert(thread->osthread() == NULL, "caller responsible");
   705   assert(thread->osthread() == NULL, "caller responsible");
   706 
   706 
   707   // Allocate the OSThread object
   707   // Allocate the OSThread object
   708   OSThread* osthread = new OSThread(NULL, NULL);
   708   OSThread* osthread = new OSThread(NULL, NULL);
   709   if (osthread == NULL) {
   709   if (osthread == NULL) {
   721   // init thread attributes
   721   // init thread attributes
   722   pthread_attr_t attr;
   722   pthread_attr_t attr;
   723   pthread_attr_init(&attr);
   723   pthread_attr_init(&attr);
   724   pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
   724   pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
   725 
   725 
   726   // stack size
       
   727   // calculate stack size if it's not specified by caller
   726   // calculate stack size if it's not specified by caller
   728   if (stack_size == 0) {
   727   size_t stack_size = os::Posix::get_initial_stack_size(thr_type, req_stack_size);
   729     stack_size = os::Linux::default_stack_size(thr_type);
       
   730 
       
   731     switch (thr_type) {
       
   732     case os::java_thread:
       
   733       // Java threads use ThreadStackSize which default value can be
       
   734       // changed with the flag -Xss
       
   735       assert(JavaThread::stack_size_at_create() > 0, "this should be set");
       
   736       stack_size = JavaThread::stack_size_at_create();
       
   737       break;
       
   738     case os::compiler_thread:
       
   739       if (CompilerThreadStackSize > 0) {
       
   740         stack_size = (size_t)(CompilerThreadStackSize * K);
       
   741         break;
       
   742       } // else fall through:
       
   743         // use VMThreadStackSize if CompilerThreadStackSize is not defined
       
   744     case os::vm_thread:
       
   745     case os::pgc_thread:
       
   746     case os::cgc_thread:
       
   747     case os::watcher_thread:
       
   748       if (VMThreadStackSize > 0) stack_size = (size_t)(VMThreadStackSize * K);
       
   749       break;
       
   750     }
       
   751   }
       
   752 
       
   753   stack_size = MAX2(stack_size, os::Linux::min_stack_allowed);
       
   754   pthread_attr_setstacksize(&attr, stack_size);
   728   pthread_attr_setstacksize(&attr, stack_size);
   755 
   729 
   756   // glibc guard page
   730   // glibc guard page
   757   pthread_attr_setguardsize(&attr, os::Linux::default_guard_size(thr_type));
   731   pthread_attr_setguardsize(&attr, os::Linux::default_guard_size(thr_type));
   758 
   732 
   954 // Locate initial thread stack. This special handling of initial thread stack
   928 // Locate initial thread stack. This special handling of initial thread stack
   955 // is needed because pthread_getattr_np() on most (all?) Linux distros returns
   929 // is needed because pthread_getattr_np() on most (all?) Linux distros returns
   956 // bogus value for initial thread.
   930 // bogus value for initial thread.
   957 void os::Linux::capture_initial_stack(size_t max_size) {
   931 void os::Linux::capture_initial_stack(size_t max_size) {
   958   // stack size is the easy part, get it from RLIMIT_STACK
   932   // stack size is the easy part, get it from RLIMIT_STACK
   959   size_t stack_size;
       
   960   struct rlimit rlim;
   933   struct rlimit rlim;
   961   getrlimit(RLIMIT_STACK, &rlim);
   934   getrlimit(RLIMIT_STACK, &rlim);
   962   stack_size = rlim.rlim_cur;
   935   size_t stack_size = rlim.rlim_cur;
   963 
   936 
   964   // 6308388: a bug in ld.so will relocate its own .data section to the
   937   // 6308388: a bug in ld.so will relocate its own .data section to the
   965   //   lower end of primordial stack; reduce ulimit -s value a little bit
   938   //   lower end of primordial stack; reduce ulimit -s value a little bit
   966   //   so we won't install guard page on ld.so's data section.
   939   //   so we won't install guard page on ld.so's data section.
   967   stack_size -= 2 * page_size();
   940   stack_size -= 2 * page_size();
  4791   }
  4764   }
  4792 
  4765 
  4793   Linux::signal_sets_init();
  4766   Linux::signal_sets_init();
  4794   Linux::install_signal_handlers();
  4767   Linux::install_signal_handlers();
  4795 
  4768 
  4796   // Check minimum allowable stack size for thread creation and to initialize
  4769   // Check and sets minimum stack sizes against command line options
  4797   // the java system classes, including StackOverflowError - depends on page
  4770   if (Posix::set_minimum_stack_sizes() == JNI_ERR) {
  4798   // size.  Add two 4K pages for compiler2 recursion in main thread.
       
  4799   // Add in 4*BytesPerWord 4K pages to account for VM stack during
       
  4800   // class initialization depending on 32 or 64 bit VM.
       
  4801   os::Linux::min_stack_allowed = MAX2(os::Linux::min_stack_allowed,
       
  4802                                       JavaThread::stack_guard_zone_size() +
       
  4803                                       JavaThread::stack_shadow_zone_size() +
       
  4804                                       (4*BytesPerWord COMPILER2_PRESENT(+2)) * 4 * K);
       
  4805 
       
  4806   os::Linux::min_stack_allowed = align_size_up(os::Linux::min_stack_allowed, os::vm_page_size());
       
  4807 
       
  4808   size_t threadStackSizeInBytes = ThreadStackSize * K;
       
  4809   if (threadStackSizeInBytes != 0 &&
       
  4810       threadStackSizeInBytes < os::Linux::min_stack_allowed) {
       
  4811     tty->print_cr("\nThe stack size specified is too small, "
       
  4812                   "Specify at least " SIZE_FORMAT "k",
       
  4813                   os::Linux::min_stack_allowed/ K);
       
  4814     return JNI_ERR;
  4771     return JNI_ERR;
  4815   }
  4772   }
  4816 
       
  4817   // Make the stack size a multiple of the page size so that
       
  4818   // the yellow/red zones can be guarded.
       
  4819   JavaThread::set_stack_size_at_create(round_to(threadStackSizeInBytes,
       
  4820                                                 vm_page_size()));
       
  4821 
       
  4822   Linux::capture_initial_stack(JavaThread::stack_size_at_create());
  4773   Linux::capture_initial_stack(JavaThread::stack_size_at_create());
  4823 
  4774 
  4824 #if defined(IA32)
  4775 #if defined(IA32)
  4825   workaround_expand_exec_shield_cs_limit();
  4776   workaround_expand_exec_shield_cs_limit();
  4826 #endif
  4777 #endif