708 return true;
709 } else if (!strncmp(option->optionString, "-Xmaxjitcodesize", 16)) {
710 return true;
711 }
712 return false;
713 }
714
715 bool os::Solaris::valid_stack_address(Thread* thread, address sp) {
716 address stackStart = (address)thread->stack_base();
717 address stackEnd = (address)(stackStart - (address)thread->stack_size());
718 if (sp < stackStart && sp >= stackEnd) return true;
719 return false;
720 }
721
722 extern "C" void breakpoint() {
723 // use debugger to set breakpoint here
724 }
725
726 static thread_t main_thread;
727
728 // Thread start routine for all new Java threads
729 extern "C" void* java_start(void* thread_addr) {
730 // Try to randomize the cache line index of hot stack frames.
731 // This helps when threads of the same stack traces evict each other's
732 // cache lines. The threads can be either from the same JVM instance, or
733 // from different JVM instances. The benefit is especially true for
734 // processors with hyperthreading technology.
735 static int counter = 0;
736 int pid = os::current_process_id();
737 alloca(((pid ^ counter++) & 7) * 128);
738
739 int prio;
740 Thread* thread = (Thread*)thread_addr;
741
742 thread->initialize_thread_current();
743
744 OSThread* osthr = thread->osthread();
745
746 osthr->set_lwp_id(_lwp_self()); // Store lwp in case we are bound
747 thread->_schedctl = (void *) schedctl_init();
748
749 log_info(os, thread)("Thread is alive (tid: " UINTX_FORMAT ").",
779 } else if (ThreadPriorityVerbose) {
780 warning("Can't set priority in _start routine, thread id hasn't been set\n");
781 }
782
783 assert(osthr->get_state() == RUNNABLE, "invalid os thread state");
784
785 // initialize signal mask for this thread
786 os::Solaris::hotspot_sigmask(thread);
787
788 thread->run();
789
790 // One less thread is executing
791 // When the VMThread gets here, the main thread may have already exited
792 // which frees the CodeHeap containing the Atomic::dec code
793 if (thread != VMThread::vm_thread() && VMThread::vm_thread() != NULL) {
794 Atomic::dec(&os::Solaris::_os_thread_count);
795 }
796
797 log_info(os, thread)("Thread finished (tid: " UINTX_FORMAT ").", os::current_thread_id());
798
799 if (UseDetachedThreads) {
800 thr_exit(NULL);
801 ShouldNotReachHere();
802 }
803 return NULL;
804 }
805
806 static OSThread* create_os_thread(Thread* thread, thread_t thread_id) {
807 // Allocate the OSThread object
808 OSThread* osthread = new OSThread(NULL, NULL);
809 if (osthread == NULL) return NULL;
810
811 // Store info on the Solaris thread into the OSThread
812 osthread->set_thread_id(thread_id);
813 osthread->set_lwp_id(_lwp_self());
814 thread->_schedctl = (void *) schedctl_init();
815
816 if (UseNUMA) {
817 int lgrp_id = os::numa_get_group_id();
818 if (lgrp_id != -1) {
992 return false;
993 } else {
994 // Release the memory again
995 os::release_memory(mem, VirtualMemoryBangSize);
996 }
997 }
998
999 // Setup osthread because the child thread may need it.
1000 thread->set_osthread(osthread);
1001
1002 // Create the Solaris thread
1003 thread_t tid = 0;
1004 long flags = (UseDetachedThreads ? THR_DETACHED : 0) | THR_SUSPENDED;
1005 int status;
1006
1007 // Mark that we don't have an lwp or thread id yet.
1008 // In case we attempt to set the priority before the thread starts.
1009 osthread->set_lwp_id(-1);
1010 osthread->set_thread_id(-1);
1011
1012 status = thr_create(NULL, stack_size, java_start, thread, flags, &tid);
1013
1014 char buf[64];
1015 if (status == 0) {
1016 log_info(os, thread)("Thread started (tid: " UINTX_FORMAT ", attributes: %s). ",
1017 (uintx) tid, describe_thr_create_attributes(buf, sizeof(buf), stack_size, flags));
1018 } else {
1019 log_warning(os, thread)("Failed to start thread - thr_create failed (%s) for attributes: %s.",
1020 os::errno_name(status), describe_thr_create_attributes(buf, sizeof(buf), stack_size, flags));
1021 }
1022
1023 if (status != 0) {
1024 thread->set_osthread(NULL);
1025 // Need to clean up stuff we've allocated so far
1026 delete osthread;
1027 return false;
1028 }
1029
1030 Atomic::inc(&os::Solaris::_os_thread_count);
1031
1032 // Store info on the Solaris thread into the OSThread
1204 vm_exit(1);
1205 }
1206 assert(jt->stack_size() >= stack_size,
1207 "Attempt to map more stack than was allocated");
1208 jt->set_stack_size(stack_size);
1209 }
1210
1211 // With the T2 libthread (T1 is no longer supported) threads are always bound
1212 // and we use stackbanging in all cases.
1213
1214 os::Solaris::init_thread_fpu_state();
1215 std::set_terminate(_handle_uncaught_cxx_exception);
1216 }
1217
1218
1219
1220 // Free Solaris resources related to the OSThread
1221 void os::free_thread(OSThread* osthread) {
1222 assert(osthread != NULL, "os::free_thread but osthread not set");
1223
1224
1225 // We are told to free resources of the argument thread,
1226 // but we can only really operate on the current thread.
1227 // The main thread must take the VMThread down synchronously
1228 // before the main thread exits and frees up CodeHeap
1229 guarantee((Thread::current()->osthread() == osthread
1230 || (osthread == VMThread::vm_thread()->osthread())), "os::free_thread but not current thread");
1231 if (Thread::current()->osthread() == osthread) {
1232 // Restore caller's signal mask
1233 sigset_t sigmask = osthread->caller_sigmask();
1234 pthread_sigmask(SIG_SETMASK, &sigmask, NULL);
1235 }
1236 delete osthread;
1237 }
1238
1239 void os::pd_start_thread(Thread* thread) {
1240 int status = thr_continue(thread->osthread()->thread_id());
1241 assert_status(status == 0, status, "thr_continue failed");
1242 }
1243
1244
1245 intx os::current_thread_id() {
1246 return (intx)thr_self();
1247 }
1248
1249 static pid_t _initial_pid = 0;
1250
1251 int os::current_process_id() {
1252 return (int)(_initial_pid ? _initial_pid : getpid());
1253 }
1254
1255 // gethrtime() should be monotonic according to the documentation,
|
708 return true;
709 } else if (!strncmp(option->optionString, "-Xmaxjitcodesize", 16)) {
710 return true;
711 }
712 return false;
713 }
714
715 bool os::Solaris::valid_stack_address(Thread* thread, address sp) {
716 address stackStart = (address)thread->stack_base();
717 address stackEnd = (address)(stackStart - (address)thread->stack_size());
718 if (sp < stackStart && sp >= stackEnd) return true;
719 return false;
720 }
721
722 extern "C" void breakpoint() {
723 // use debugger to set breakpoint here
724 }
725
726 static thread_t main_thread;
727
728 // Thread start routine for all newly created threads
729 extern "C" void* thread_native_entry(void* thread_addr) {
730 // Try to randomize the cache line index of hot stack frames.
731 // This helps when threads of the same stack traces evict each other's
732 // cache lines. The threads can be either from the same JVM instance, or
733 // from different JVM instances. The benefit is especially true for
734 // processors with hyperthreading technology.
735 static int counter = 0;
736 int pid = os::current_process_id();
737 alloca(((pid ^ counter++) & 7) * 128);
738
739 int prio;
740 Thread* thread = (Thread*)thread_addr;
741
742 thread->initialize_thread_current();
743
744 OSThread* osthr = thread->osthread();
745
746 osthr->set_lwp_id(_lwp_self()); // Store lwp in case we are bound
747 thread->_schedctl = (void *) schedctl_init();
748
749 log_info(os, thread)("Thread is alive (tid: " UINTX_FORMAT ").",
779 } else if (ThreadPriorityVerbose) {
780 warning("Can't set priority in _start routine, thread id hasn't been set\n");
781 }
782
783 assert(osthr->get_state() == RUNNABLE, "invalid os thread state");
784
785 // initialize signal mask for this thread
786 os::Solaris::hotspot_sigmask(thread);
787
788 thread->run();
789
790 // One less thread is executing
791 // When the VMThread gets here, the main thread may have already exited
792 // which frees the CodeHeap containing the Atomic::dec code
793 if (thread != VMThread::vm_thread() && VMThread::vm_thread() != NULL) {
794 Atomic::dec(&os::Solaris::_os_thread_count);
795 }
796
797 log_info(os, thread)("Thread finished (tid: " UINTX_FORMAT ").", os::current_thread_id());
798
799 // If a thread has not deleted itself ("delete this") as part of its
800 // termination sequence, we have to ensure thread-local-storage is
801 // cleared before we actually terminate. No threads should ever be
802 // deleted asynchronously with respect to their termination.
803 if (Thread::current_or_null_safe() != NULL) {
804 assert(Thread::current_or_null_safe() == thread, "current thread is wrong");
805 thread->clear_thread_current();
806 }
807
808 if (UseDetachedThreads) {
809 thr_exit(NULL);
810 ShouldNotReachHere();
811 }
812 return NULL;
813 }
814
815 static OSThread* create_os_thread(Thread* thread, thread_t thread_id) {
816 // Allocate the OSThread object
817 OSThread* osthread = new OSThread(NULL, NULL);
818 if (osthread == NULL) return NULL;
819
820 // Store info on the Solaris thread into the OSThread
821 osthread->set_thread_id(thread_id);
822 osthread->set_lwp_id(_lwp_self());
823 thread->_schedctl = (void *) schedctl_init();
824
825 if (UseNUMA) {
826 int lgrp_id = os::numa_get_group_id();
827 if (lgrp_id != -1) {
1001 return false;
1002 } else {
1003 // Release the memory again
1004 os::release_memory(mem, VirtualMemoryBangSize);
1005 }
1006 }
1007
1008 // Setup osthread because the child thread may need it.
1009 thread->set_osthread(osthread);
1010
1011 // Create the Solaris thread
1012 thread_t tid = 0;
1013 long flags = (UseDetachedThreads ? THR_DETACHED : 0) | THR_SUSPENDED;
1014 int status;
1015
1016 // Mark that we don't have an lwp or thread id yet.
1017 // In case we attempt to set the priority before the thread starts.
1018 osthread->set_lwp_id(-1);
1019 osthread->set_thread_id(-1);
1020
1021 status = thr_create(NULL, stack_size, thread_native_entry, thread, flags, &tid);
1022
1023 char buf[64];
1024 if (status == 0) {
1025 log_info(os, thread)("Thread started (tid: " UINTX_FORMAT ", attributes: %s). ",
1026 (uintx) tid, describe_thr_create_attributes(buf, sizeof(buf), stack_size, flags));
1027 } else {
1028 log_warning(os, thread)("Failed to start thread - thr_create failed (%s) for attributes: %s.",
1029 os::errno_name(status), describe_thr_create_attributes(buf, sizeof(buf), stack_size, flags));
1030 }
1031
1032 if (status != 0) {
1033 thread->set_osthread(NULL);
1034 // Need to clean up stuff we've allocated so far
1035 delete osthread;
1036 return false;
1037 }
1038
1039 Atomic::inc(&os::Solaris::_os_thread_count);
1040
1041 // Store info on the Solaris thread into the OSThread
1213 vm_exit(1);
1214 }
1215 assert(jt->stack_size() >= stack_size,
1216 "Attempt to map more stack than was allocated");
1217 jt->set_stack_size(stack_size);
1218 }
1219
1220 // With the T2 libthread (T1 is no longer supported) threads are always bound
1221 // and we use stackbanging in all cases.
1222
1223 os::Solaris::init_thread_fpu_state();
1224 std::set_terminate(_handle_uncaught_cxx_exception);
1225 }
1226
1227
1228
1229 // Free Solaris resources related to the OSThread
1230 void os::free_thread(OSThread* osthread) {
1231 assert(osthread != NULL, "os::free_thread but osthread not set");
1232
1233 // We are told to free resources of the argument thread,
1234 // but we can only really operate on the current thread.
1235 assert(Thread::current()->osthread() == osthread,
1236 "os::free_thread but not current thread");
1237
1238 // Restore caller's signal mask
1239 sigset_t sigmask = osthread->caller_sigmask();
1240 pthread_sigmask(SIG_SETMASK, &sigmask, NULL);
1241
1242 delete osthread;
1243 }
1244
1245 void os::pd_start_thread(Thread* thread) {
1246 int status = thr_continue(thread->osthread()->thread_id());
1247 assert_status(status == 0, status, "thr_continue failed");
1248 }
1249
1250
1251 intx os::current_thread_id() {
1252 return (intx)thr_self();
1253 }
1254
1255 static pid_t _initial_pid = 0;
1256
1257 int os::current_process_id() {
1258 return (int)(_initial_pid ? _initial_pid : getpid());
1259 }
1260
1261 // gethrtime() should be monotonic according to the documentation,
|