< prev index next >

src/os/bsd/vm/os_bsd.cpp

Print this page




 722 
 723   // Allocate the OSThread object
 724   OSThread* osthread = new OSThread(NULL, NULL);
 725   if (osthread == NULL) {
 726     return false;
 727   }
 728 
 729   // set the correct thread state
 730   osthread->set_thread_type(thr_type);
 731 
 732   // Initial state is ALLOCATED but not INITIALIZED
 733   osthread->set_state(ALLOCATED);
 734 
 735   thread->set_osthread(osthread);
 736 
 737   // init thread attributes
 738   pthread_attr_t attr;
 739   pthread_attr_init(&attr);
 740   pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
 741 
 742   // stack size
 743   if (os::Bsd::supports_variable_stack_size()) {
 744     // calculate stack size if it's not specified by caller
 745     if (stack_size == 0) {
 746       stack_size = os::Bsd::default_stack_size(thr_type);
 747 
 748       switch (thr_type) {
 749       case os::java_thread:
 750         // Java threads use ThreadStackSize which default value can be
 751         // changed with the flag -Xss
 752         assert(JavaThread::stack_size_at_create() > 0, "this should be set");
 753         stack_size = JavaThread::stack_size_at_create();
 754         break;
 755       case os::compiler_thread:
 756         if (CompilerThreadStackSize > 0) {
 757           stack_size = (size_t)(CompilerThreadStackSize * K);
 758           break;
 759         } // else fall through:
 760           // use VMThreadStackSize if CompilerThreadStackSize is not defined
 761       case os::vm_thread:
 762       case os::pgc_thread:
 763       case os::cgc_thread:
 764       case os::watcher_thread:
 765         if (VMThreadStackSize > 0) stack_size = (size_t)(VMThreadStackSize * K);
 766         break;
 767       }
 768     }
 769 
 770     stack_size = MAX2(stack_size, os::Bsd::min_stack_allowed);
 771     pthread_attr_setstacksize(&attr, stack_size);
 772   } else {
 773     // let pthread_create() pick the default value.
 774   }
 775 
 776   ThreadState state;
 777 
 778   {
 779     pthread_t tid;
 780     int ret = pthread_create(&tid, &attr, (void* (*)(void*)) java_start, thread);
 781 
 782     pthread_attr_destroy(&attr);
 783 
 784     if (ret != 0) {
 785       if (PrintMiscellaneous && (Verbose || WizardMode)) {
 786         perror("pthread_create()");
 787       }
 788       // Need to clean up stuff we've allocated so far
 789       thread->set_osthread(NULL);
 790       delete osthread;
 791       return false;
 792     }
 793 
 794     // Store pthread info into the OSThread




 722 
 723   // Allocate the OSThread object
 724   OSThread* osthread = new OSThread(NULL, NULL);
 725   if (osthread == NULL) {
 726     return false;
 727   }
 728 
 729   // set the correct thread state
 730   osthread->set_thread_type(thr_type);
 731 
 732   // Initial state is ALLOCATED but not INITIALIZED
 733   osthread->set_state(ALLOCATED);
 734 
 735   thread->set_osthread(osthread);
 736 
 737   // init thread attributes
 738   pthread_attr_t attr;
 739   pthread_attr_init(&attr);
 740   pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
 741 


 742   // calculate stack size if it's not specified by caller
 743   if (stack_size == 0) {
 744     stack_size = os::Bsd::default_stack_size(thr_type);
 745 
 746     switch (thr_type) {
 747     case os::java_thread:
 748       // Java threads use ThreadStackSize which default value can be
 749       // changed with the flag -Xss
 750       assert(JavaThread::stack_size_at_create() > 0, "this should be set");
 751       stack_size = JavaThread::stack_size_at_create();
 752       break;
 753     case os::compiler_thread:
 754       if (CompilerThreadStackSize > 0) {
 755         stack_size = (size_t)(CompilerThreadStackSize * K);
 756         break;
 757       } // else fall through:
 758         // use VMThreadStackSize if CompilerThreadStackSize is not defined
 759     case os::vm_thread:
 760     case os::pgc_thread:
 761     case os::cgc_thread:
 762     case os::watcher_thread:
 763       if (VMThreadStackSize > 0) stack_size = (size_t)(VMThreadStackSize * K);
 764       break;
 765     }
 766   }
 767 
 768   stack_size = MAX2(stack_size, os::Bsd::min_stack_allowed);
 769   pthread_attr_setstacksize(&attr, stack_size);



 770 
 771   ThreadState state;
 772 
 773   {
 774     pthread_t tid;
 775     int ret = pthread_create(&tid, &attr, (void* (*)(void*)) java_start, thread);
 776 
 777     pthread_attr_destroy(&attr);
 778 
 779     if (ret != 0) {
 780       if (PrintMiscellaneous && (Verbose || WizardMode)) {
 781         perror("pthread_create()");
 782       }
 783       // Need to clean up stuff we've allocated so far
 784       thread->set_osthread(NULL);
 785       delete osthread;
 786       return false;
 787     }
 788 
 789     // Store pthread info into the OSThread


< prev index next >