706
707 // Allocate the OSThread object
708 OSThread* osthread = new OSThread(NULL, NULL);
709 if (osthread == NULL) {
710 return false;
711 }
712
713 // set the correct thread state
714 osthread->set_thread_type(thr_type);
715
716 // Initial state is ALLOCATED but not INITIALIZED
717 osthread->set_state(ALLOCATED);
718
719 thread->set_osthread(osthread);
720
721 // init thread attributes
722 pthread_attr_t attr;
723 pthread_attr_init(&attr);
724 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
725
726 // calculate stack size if it's not specified by caller
727 size_t stack_size = os::Posix::get_initial_stack_size(thr_type, req_stack_size);
728 pthread_attr_setstacksize(&attr, stack_size);
729
730 // glibc guard page
731 pthread_attr_setguardsize(&attr, os::Linux::default_guard_size(thr_type));
732
733 ThreadState state;
734
735 {
736 pthread_t tid;
737 int ret = pthread_create(&tid, &attr, (void* (*)(void*)) thread_native_entry, thread);
738
739 char buf[64];
740 if (ret == 0) {
741 log_info(os, thread)("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ",
742 (uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
743 } else {
744 log_warning(os, thread)("Failed to start thread - pthread_create failed (%s) for attributes: %s.",
745 os::errno_name(ret), os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
746 }
747
|
706
707 // Allocate the OSThread object
708 OSThread* osthread = new OSThread(NULL, NULL);
709 if (osthread == NULL) {
710 return false;
711 }
712
713 // set the correct thread state
714 osthread->set_thread_type(thr_type);
715
716 // Initial state is ALLOCATED but not INITIALIZED
717 osthread->set_state(ALLOCATED);
718
719 thread->set_osthread(osthread);
720
721 // init thread attributes
722 pthread_attr_t attr;
723 pthread_attr_init(&attr);
724 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
725
726 // Calculate stack size if it's not specified by caller.
727 size_t stack_size = os::Posix::get_initial_stack_size(thr_type, req_stack_size);
728 // In the Linux NPTL pthread implementation the guard size mechanism
729 // is not implemented properly. The posix standard requires to add
730 // the size of the guard pages to the stack size, instead Linux
731 // takes the space out of 'stacksize'. Thus we adapt the requested
732 // stack_size by the size of the guard pages to mimick proper
733 // behaviour.
734 stack_size = align_size_up(stack_size + os::Linux::default_guard_size(thr_type), vm_page_size());
735 pthread_attr_setstacksize(&attr, stack_size);
736
737 // glibc guard page
738 pthread_attr_setguardsize(&attr, os::Linux::default_guard_size(thr_type));
739
740 ThreadState state;
741
742 {
743 pthread_t tid;
744 int ret = pthread_create(&tid, &attr, (void* (*)(void*)) thread_native_entry, thread);
745
746 char buf[64];
747 if (ret == 0) {
748 log_info(os, thread)("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ",
749 (uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
750 } else {
751 log_warning(os, thread)("Failed to start thread - pthread_create failed (%s) for attributes: %s.",
752 os::errno_name(ret), os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
753 }
754
|