15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 // no precompiled headers
26 #include "classfile/classLoader.hpp"
27 #include "classfile/systemDictionary.hpp"
28 #include "classfile/vmSymbols.hpp"
29 #include "code/icBuffer.hpp"
30 #include "code/vtableStubs.hpp"
31 #include "compiler/compileBroker.hpp"
32 #include "compiler/disassembler.hpp"
33 #include "interpreter/interpreter.hpp"
34 #include "jvm_solaris.h"
35 #include "memory/allocation.inline.hpp"
36 #include "memory/filemap.hpp"
37 #include "mutex_solaris.inline.hpp"
38 #include "oops/oop.inline.hpp"
39 #include "os_share_solaris.hpp"
40 #include "os_solaris.inline.hpp"
41 #include "prims/jniFastGetField.hpp"
42 #include "prims/jvm.h"
43 #include "prims/jvm_misc.hpp"
44 #include "runtime/arguments.hpp"
45 #include "runtime/atomic.inline.hpp"
46 #include "runtime/extendedPC.hpp"
47 #include "runtime/globals.hpp"
48 #include "runtime/interfaceSupport.hpp"
49 #include "runtime/java.hpp"
50 #include "runtime/javaCalls.hpp"
51 #include "runtime/mutexLocker.hpp"
52 #include "runtime/objectMonitor.hpp"
53 #include "runtime/orderAccess.inline.hpp"
54 #include "runtime/osThread.hpp"
719 extern "C" void* java_start(void* thread_addr) {
720 // Try to randomize the cache line index of hot stack frames.
721 // This helps when threads of the same stack traces evict each other's
722 // cache lines. The threads can be either from the same JVM instance, or
723 // from different JVM instances. The benefit is especially true for
724 // processors with hyperthreading technology.
725 static int counter = 0;
726 int pid = os::current_process_id();
727 alloca(((pid ^ counter++) & 7) * 128);
728
729 int prio;
730 Thread* thread = (Thread*)thread_addr;
731
732 thread->initialize_thread_current();
733
734 OSThread* osthr = thread->osthread();
735
736 osthr->set_lwp_id(_lwp_self()); // Store lwp in case we are bound
737 thread->_schedctl = (void *) schedctl_init();
738
739 if (UseNUMA) {
740 int lgrp_id = os::numa_get_group_id();
741 if (lgrp_id != -1) {
742 thread->set_lgrp_id(lgrp_id);
743 }
744 }
745
746 // If the creator called set priority before we started,
747 // we need to call set_native_priority now that we have an lwp.
748 // We used to get the priority from thr_getprio (we called
749 // thr_setprio way back in create_thread) and pass it to
750 // set_native_priority, but Solaris scales the priority
751 // in java_to_os_priority, so when we read it back here,
752 // we pass trash to set_native_priority instead of what's
753 // in java_to_os_priority. So we save the native priority
754 // in the osThread and recall it here.
755
756 if (osthr->thread_id() != -1) {
757 if (UseThreadPriorities) {
758 int prio = osthr->native_priority();
764 os::set_native_priority(thread, prio);
765 }
766 } else if (ThreadPriorityVerbose) {
767 warning("Can't set priority in _start routine, thread id hasn't been set\n");
768 }
769
770 assert(osthr->get_state() == RUNNABLE, "invalid os thread state");
771
772 // initialize signal mask for this thread
773 os::Solaris::hotspot_sigmask(thread);
774
775 thread->run();
776
777 // One less thread is executing
778 // When the VMThread gets here, the main thread may have already exited
779 // which frees the CodeHeap containing the Atomic::dec code
780 if (thread != VMThread::vm_thread() && VMThread::vm_thread() != NULL) {
781 Atomic::dec(&os::Solaris::_os_thread_count);
782 }
783
784 if (UseDetachedThreads) {
785 thr_exit(NULL);
786 ShouldNotReachHere();
787 }
788 return NULL;
789 }
790
791 static OSThread* create_os_thread(Thread* thread, thread_t thread_id) {
792 // Allocate the OSThread object
793 OSThread* osthread = new OSThread(NULL, NULL);
794 if (osthread == NULL) return NULL;
795
796 // Store info on the Solaris thread into the OSThread
797 osthread->set_thread_id(thread_id);
798 osthread->set_lwp_id(_lwp_self());
799 thread->_schedctl = (void *) schedctl_init();
800
801 if (UseNUMA) {
802 int lgrp_id = os::numa_get_group_id();
803 if (lgrp_id != -1) {
836 }
837 }
838
839 bool os::create_attached_thread(JavaThread* thread) {
840 #ifdef ASSERT
841 thread->verify_not_published();
842 #endif
843 OSThread* osthread = create_os_thread(thread, thr_self());
844 if (osthread == NULL) {
845 return false;
846 }
847
848 // Initial thread state is RUNNABLE
849 osthread->set_state(RUNNABLE);
850 thread->set_osthread(osthread);
851
852 // initialize signal mask for this thread
853 // and save the caller's signal mask
854 os::Solaris::hotspot_sigmask(thread);
855
856 return true;
857 }
858
859 bool os::create_main_thread(JavaThread* thread) {
860 #ifdef ASSERT
861 thread->verify_not_published();
862 #endif
863 if (_starting_thread == NULL) {
864 _starting_thread = create_os_thread(thread, main_thread);
865 if (_starting_thread == NULL) {
866 return false;
867 }
868 }
869
870 // The primodial thread is runnable from the start
871 _starting_thread->set_state(RUNNABLE);
872
873 thread->set_osthread(_starting_thread);
874
875 // initialize signal mask for this thread
958 // Release the memory again
959 os::release_memory(mem, VirtualMemoryBangSize);
960 }
961 }
962
963 // Setup osthread because the child thread may need it.
964 thread->set_osthread(osthread);
965
966 // Create the Solaris thread
967 thread_t tid = 0;
968 long flags = (UseDetachedThreads ? THR_DETACHED : 0) | THR_SUSPENDED;
969 int status;
970
971 // Mark that we don't have an lwp or thread id yet.
972 // In case we attempt to set the priority before the thread starts.
973 osthread->set_lwp_id(-1);
974 osthread->set_thread_id(-1);
975
976 status = thr_create(NULL, stack_size, java_start, thread, flags, &tid);
977 if (status != 0) {
978 if (PrintMiscellaneous && (Verbose || WizardMode)) {
979 perror("os::create_thread");
980 }
981 thread->set_osthread(NULL);
982 // Need to clean up stuff we've allocated so far
983 delete osthread;
984 return false;
985 }
986
987 Atomic::inc(&os::Solaris::_os_thread_count);
988
989 // Store info on the Solaris thread into the OSThread
990 osthread->set_thread_id(tid);
991
992 // Remember that we created this thread so we can set priority on it
993 osthread->set_vm_created();
994
995 // Initial thread state is INITIALIZED, not SUSPENDED
996 osthread->set_state(INITIALIZED);
997
998 // The thread is returned suspended (in state INITIALIZED), and is started higher up in the call chain
999 return true;
1000 }
1001
1002 // defined for >= Solaris 10. This allows builds on earlier versions
1003 // of Solaris to take advantage of the newly reserved Solaris JVM signals.
1004 // With SIGJVM1, SIGJVM2, ASYNC_SIGNAL is SIGJVM2. Previously INTERRUPT_SIGNAL
|
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 // no precompiled headers
26 #include "classfile/classLoader.hpp"
27 #include "classfile/systemDictionary.hpp"
28 #include "classfile/vmSymbols.hpp"
29 #include "code/icBuffer.hpp"
30 #include "code/vtableStubs.hpp"
31 #include "compiler/compileBroker.hpp"
32 #include "compiler/disassembler.hpp"
33 #include "interpreter/interpreter.hpp"
34 #include "jvm_solaris.h"
35 #include "logging/log.hpp"
36 #include "memory/allocation.inline.hpp"
37 #include "memory/filemap.hpp"
38 #include "mutex_solaris.inline.hpp"
39 #include "oops/oop.inline.hpp"
40 #include "os_share_solaris.hpp"
41 #include "os_solaris.inline.hpp"
42 #include "prims/jniFastGetField.hpp"
43 #include "prims/jvm.h"
44 #include "prims/jvm_misc.hpp"
45 #include "runtime/arguments.hpp"
46 #include "runtime/atomic.inline.hpp"
47 #include "runtime/extendedPC.hpp"
48 #include "runtime/globals.hpp"
49 #include "runtime/interfaceSupport.hpp"
50 #include "runtime/java.hpp"
51 #include "runtime/javaCalls.hpp"
52 #include "runtime/mutexLocker.hpp"
53 #include "runtime/objectMonitor.hpp"
54 #include "runtime/orderAccess.inline.hpp"
55 #include "runtime/osThread.hpp"
720 extern "C" void* java_start(void* thread_addr) {
721 // Try to randomize the cache line index of hot stack frames.
722 // This helps when threads of the same stack traces evict each other's
723 // cache lines. The threads can be either from the same JVM instance, or
724 // from different JVM instances. The benefit is especially true for
725 // processors with hyperthreading technology.
726 static int counter = 0;
727 int pid = os::current_process_id();
728 alloca(((pid ^ counter++) & 7) * 128);
729
730 int prio;
731 Thread* thread = (Thread*)thread_addr;
732
733 thread->initialize_thread_current();
734
735 OSThread* osthr = thread->osthread();
736
737 osthr->set_lwp_id(_lwp_self()); // Store lwp in case we are bound
738 thread->_schedctl = (void *) schedctl_init();
739
740 log_debug(os)("Thread is alive (tid: " UINTX_FORMAT ").",
741 os::current_thread_id());
742
743 if (UseNUMA) {
744 int lgrp_id = os::numa_get_group_id();
745 if (lgrp_id != -1) {
746 thread->set_lgrp_id(lgrp_id);
747 }
748 }
749
750 // If the creator called set priority before we started,
751 // we need to call set_native_priority now that we have an lwp.
752 // We used to get the priority from thr_getprio (we called
753 // thr_setprio way back in create_thread) and pass it to
754 // set_native_priority, but Solaris scales the priority
755 // in java_to_os_priority, so when we read it back here,
756 // we pass trash to set_native_priority instead of what's
757 // in java_to_os_priority. So we save the native priority
758 // in the osThread and recall it here.
759
760 if (osthr->thread_id() != -1) {
761 if (UseThreadPriorities) {
762 int prio = osthr->native_priority();
768 os::set_native_priority(thread, prio);
769 }
770 } else if (ThreadPriorityVerbose) {
771 warning("Can't set priority in _start routine, thread id hasn't been set\n");
772 }
773
774 assert(osthr->get_state() == RUNNABLE, "invalid os thread state");
775
776 // initialize signal mask for this thread
777 os::Solaris::hotspot_sigmask(thread);
778
779 thread->run();
780
781 // One less thread is executing
782 // When the VMThread gets here, the main thread may have already exited
783 // which frees the CodeHeap containing the Atomic::dec code
784 if (thread != VMThread::vm_thread() && VMThread::vm_thread() != NULL) {
785 Atomic::dec(&os::Solaris::_os_thread_count);
786 }
787
788 log_debug(os)("Thread finished (tid: " UINTX_FORMAT ").", os::current_thread_id());
789
790 if (UseDetachedThreads) {
791 thr_exit(NULL);
792 ShouldNotReachHere();
793 }
794 return NULL;
795 }
796
797 static OSThread* create_os_thread(Thread* thread, thread_t thread_id) {
798 // Allocate the OSThread object
799 OSThread* osthread = new OSThread(NULL, NULL);
800 if (osthread == NULL) return NULL;
801
802 // Store info on the Solaris thread into the OSThread
803 osthread->set_thread_id(thread_id);
804 osthread->set_lwp_id(_lwp_self());
805 thread->_schedctl = (void *) schedctl_init();
806
807 if (UseNUMA) {
808 int lgrp_id = os::numa_get_group_id();
809 if (lgrp_id != -1) {
842 }
843 }
844
845 bool os::create_attached_thread(JavaThread* thread) {
846 #ifdef ASSERT
847 thread->verify_not_published();
848 #endif
849 OSThread* osthread = create_os_thread(thread, thr_self());
850 if (osthread == NULL) {
851 return false;
852 }
853
854 // Initial thread state is RUNNABLE
855 osthread->set_state(RUNNABLE);
856 thread->set_osthread(osthread);
857
858 // initialize signal mask for this thread
859 // and save the caller's signal mask
860 os::Solaris::hotspot_sigmask(thread);
861
862 log_debug(os)("Thread attached (tid: " UINTX_FORMAT ").",
863 os::current_thread_id());
864
865 return true;
866 }
867
868 bool os::create_main_thread(JavaThread* thread) {
869 #ifdef ASSERT
870 thread->verify_not_published();
871 #endif
872 if (_starting_thread == NULL) {
873 _starting_thread = create_os_thread(thread, main_thread);
874 if (_starting_thread == NULL) {
875 return false;
876 }
877 }
878
879 // The primodial thread is runnable from the start
880 _starting_thread->set_state(RUNNABLE);
881
882 thread->set_osthread(_starting_thread);
883
884 // initialize signal mask for this thread
967 // Release the memory again
968 os::release_memory(mem, VirtualMemoryBangSize);
969 }
970 }
971
972 // Setup osthread because the child thread may need it.
973 thread->set_osthread(osthread);
974
975 // Create the Solaris thread
976 thread_t tid = 0;
977 long flags = (UseDetachedThreads ? THR_DETACHED : 0) | THR_SUSPENDED;
978 int status;
979
980 // Mark that we don't have an lwp or thread id yet.
981 // In case we attempt to set the priority before the thread starts.
982 osthread->set_lwp_id(-1);
983 osthread->set_thread_id(-1);
984
985 status = thr_create(NULL, stack_size, java_start, thread, flags, &tid);
986 if (status != 0) {
987 log_warning(os)("Failed to start thread - thr_create failed (%s)",
988 strerror(status));
989 thread->set_osthread(NULL);
990 // Need to clean up stuff we've allocated so far
991 delete osthread;
992 return false;
993 } else {
994 log_debug(os)("Thread started (tid: " UINTX_FORMAT ").", (uintx) tid);
995 }
996
997 Atomic::inc(&os::Solaris::_os_thread_count);
998
999 // Store info on the Solaris thread into the OSThread
1000 osthread->set_thread_id(tid);
1001
1002 // Remember that we created this thread so we can set priority on it
1003 osthread->set_vm_created();
1004
1005 // Initial thread state is INITIALIZED, not SUSPENDED
1006 osthread->set_state(INITIALIZED);
1007
1008 // The thread is returned suspended (in state INITIALIZED), and is started higher up in the call chain
1009 return true;
1010 }
1011
1012 // defined for >= Solaris 10. This allows builds on earlier versions
1013 // of Solaris to take advantage of the newly reserved Solaris JVM signals.
1014 // With SIGJVM1, SIGJVM2, ASYNC_SIGNAL is SIGJVM2. Previously INTERRUPT_SIGNAL
|