1 /*
2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
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 *
874 _starting_thread = create_os_thread(thread, main_thread);
875 if (_starting_thread == NULL) {
876 return false;
877 }
878 }
879
880 // The primodial thread is runnable from the start
881 _starting_thread->set_state(RUNNABLE);
882
883 thread->set_osthread(_starting_thread);
884
885 // initialize signal mask for this thread
886 // and save the caller's signal mask
887 os::Solaris::hotspot_sigmask(thread);
888
889 return true;
890 }
891
892 // Helper function to trace thread attributes, similar to os::Posix::describe_pthread_attr()
893 static char* describe_thr_create_attributes(char* buf, size_t buflen,
894 size_t stacksize, long flags)
895 {
896 stringStream ss(buf, buflen);
897 ss.print("stacksize: " SIZE_FORMAT "k, ", stacksize / 1024);
898 ss.print("flags: ");
899 #define PRINT_FLAG(f) if (flags & f) ss.print( XSTR(f) " ");
900 #define ALL(X) \
901 X(THR_SUSPENDED) \
902 X(THR_DETACHED) \
903 X(THR_BOUND) \
904 X(THR_NEW_LWP) \
905 X(THR_DAEMON)
906 ALL(PRINT_FLAG)
907 #undef ALL
908 #undef PRINT_FLAG
909 return buf;
910 }
911
912 bool os::create_thread(Thread* thread, ThreadType thr_type,
913 size_t stack_size) {
914 // Allocate the OSThread object
915 OSThread* osthread = new OSThread(NULL, NULL);
916 if (osthread == NULL) {
917 return false;
918 }
919
989 }
990 }
991
992 // Setup osthread because the child thread may need it.
993 thread->set_osthread(osthread);
994
995 // Create the Solaris thread
996 thread_t tid = 0;
997 long flags = (UseDetachedThreads ? THR_DETACHED : 0) | THR_SUSPENDED;
998 int status;
999
1000 // Mark that we don't have an lwp or thread id yet.
1001 // In case we attempt to set the priority before the thread starts.
1002 osthread->set_lwp_id(-1);
1003 osthread->set_thread_id(-1);
1004
1005 status = thr_create(NULL, stack_size, java_start, thread, flags, &tid);
1006
1007 char buf[64];
1008 if (status == 0) {
1009 log_info(os, thread)("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ",
1010 (uintx) tid, describe_thr_create_attributes(buf, sizeof(buf), stack_size, flags));
1011 } else {
1012 log_warning(os, thread)("Failed to start thread - thr_create failed (%s) for attributes: %s.",
1013 strerror(status), describe_thr_create_attributes(buf, sizeof(buf), stack_size, flags));
1014 }
1015
1016 if (status != 0) {
1017 thread->set_osthread(NULL);
1018 // Need to clean up stuff we've allocated so far
1019 delete osthread;
1020 return false;
1021 }
1022
1023 Atomic::inc(&os::Solaris::_os_thread_count);
1024
1025 // Store info on the Solaris thread into the OSThread
1026 osthread->set_thread_id(tid);
1027
1028 // Remember that we created this thread so we can set priority on it
1029 osthread->set_vm_created();
|
1 /*
2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
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 *
874 _starting_thread = create_os_thread(thread, main_thread);
875 if (_starting_thread == NULL) {
876 return false;
877 }
878 }
879
880 // The primodial thread is runnable from the start
881 _starting_thread->set_state(RUNNABLE);
882
883 thread->set_osthread(_starting_thread);
884
885 // initialize signal mask for this thread
886 // and save the caller's signal mask
887 os::Solaris::hotspot_sigmask(thread);
888
889 return true;
890 }
891
892 // Helper function to trace thread attributes, similar to os::Posix::describe_pthread_attr()
893 static char* describe_thr_create_attributes(char* buf, size_t buflen,
894 size_t stacksize, long flags) {
895 stringStream ss(buf, buflen);
896 ss.print("stacksize: " SIZE_FORMAT "k, ", stacksize / 1024);
897 ss.print("flags: ");
898 #define PRINT_FLAG(f) if (flags & f) ss.print( #f " ");
899 #define ALL(X) \
900 X(THR_SUSPENDED) \
901 X(THR_DETACHED) \
902 X(THR_BOUND) \
903 X(THR_NEW_LWP) \
904 X(THR_DAEMON)
905 ALL(PRINT_FLAG)
906 #undef ALL
907 #undef PRINT_FLAG
908 return buf;
909 }
910
911 bool os::create_thread(Thread* thread, ThreadType thr_type,
912 size_t stack_size) {
913 // Allocate the OSThread object
914 OSThread* osthread = new OSThread(NULL, NULL);
915 if (osthread == NULL) {
916 return false;
917 }
918
988 }
989 }
990
991 // Setup osthread because the child thread may need it.
992 thread->set_osthread(osthread);
993
994 // Create the Solaris thread
995 thread_t tid = 0;
996 long flags = (UseDetachedThreads ? THR_DETACHED : 0) | THR_SUSPENDED;
997 int status;
998
999 // Mark that we don't have an lwp or thread id yet.
1000 // In case we attempt to set the priority before the thread starts.
1001 osthread->set_lwp_id(-1);
1002 osthread->set_thread_id(-1);
1003
1004 status = thr_create(NULL, stack_size, java_start, thread, flags, &tid);
1005
1006 char buf[64];
1007 if (status == 0) {
1008 log_info(os, thread)("Thread started (tid: " UINTX_FORMAT ", attributes: %s). ",
1009 (uintx) tid, describe_thr_create_attributes(buf, sizeof(buf), stack_size, flags));
1010 } else {
1011 log_warning(os, thread)("Failed to start thread - thr_create failed (%s) for attributes: %s.",
1012 strerror(status), describe_thr_create_attributes(buf, sizeof(buf), stack_size, flags));
1013 }
1014
1015 if (status != 0) {
1016 thread->set_osthread(NULL);
1017 // Need to clean up stuff we've allocated so far
1018 delete osthread;
1019 return false;
1020 }
1021
1022 Atomic::inc(&os::Solaris::_os_thread_count);
1023
1024 // Store info on the Solaris thread into the OSThread
1025 osthread->set_thread_id(tid);
1026
1027 // Remember that we created this thread so we can set priority on it
1028 osthread->set_vm_created();
|