1 /*
2 * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2012, 2015 SAP SE. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
775
776 //////////////////////////////////////////////////////////////////////////////
777 // create new thread
778
779 // Thread start routine for all newly created threads
780 static void *java_start(Thread *thread) {
781
782 // find out my own stack dimensions
783 {
784 // actually, this should do exactly the same as thread->record_stack_base_and_size...
785 address base = 0;
786 size_t size = 0;
787 query_stack_dimensions(&base, &size);
788 thread->set_stack_base(base);
789 thread->set_stack_size(size);
790 }
791
792 const pthread_t pthread_id = ::pthread_self();
793 const tid_t kernel_thread_id = ::thread_self();
794
795 log_info(os, thread)("Thread is alive (pthread id " UINTX_FORMAT ", tid " UINTX_FORMAT ")",
796 (uintx) pthread_id, (uintx) kernel_thread_id);
797
798 // Normally, pthread stacks on AIX live in the data segment (are allocated with malloc()
799 // by the pthread library). In rare cases, this may not be the case, e.g. when third-party
800 // tools hook pthread_create(). In this case, we may run into problems establishing
801 // guard pages on those stacks, because the stacks may reside in memory which is not
802 // protectable (shmated).
803 if (thread->stack_base() > ::sbrk(0)) {
804 log_warning(os, thread)("Thread " UINTX_FORMAT ": stack not in data segment.", (uintx)pthread_id);
805 }
806
807 // Try to randomize the cache line index of hot stack frames.
808 // This helps when threads of the same stack traces evict each other's
809 // cache lines. The threads can be either from the same JVM instance, or
810 // from different JVM instances. The benefit is especially true for
811 // processors with hyperthreading technology.
812
813 static int counter = 0;
814 int pid = os::current_process_id();
815 alloca(((pid ^ counter++) & 7) * 128);
816
817 thread->initialize_thread_current();
818
819 OSThread* osthread = thread->osthread();
820
821 // Thread_id is pthread id.
822 osthread->set_thread_id(pthread_id);
823
824 // .. but keep kernel thread id too for diagnostics
825 osthread->set_kernel_thread_id(kernel_thread_id);
826
827 // Initialize signal mask for this thread.
828 os::Aix::hotspot_sigmask(thread);
829
830 // Initialize floating point control register.
831 os::Aix::init_thread_fpu_state();
832
833 assert(osthread->get_state() == RUNNABLE, "invalid os thread state");
834
835 // Call one more level start routine.
836 thread->run();
837
838 log_info(os, thread)("Thread finished (pthread id " UINTX_FORMAT ", tid " UINTX_FORMAT ").",
839 (uintx) pthread_id, (uintx) kernel_thread_id);
840
841 return 0;
842 }
843
844 bool os::create_thread(Thread* thread, ThreadType thr_type, size_t stack_size) {
845
846 assert(thread->osthread() == NULL, "caller responsible");
847
848 // Allocate the OSThread object
849 OSThread* osthread = new OSThread(NULL, NULL);
850 if (osthread == NULL) {
851 return false;
852 }
853
854 // set the correct thread state
855 osthread->set_thread_type(thr_type);
856
857 // Initial state is ALLOCATED but not INITIALIZED
858 osthread->set_state(ALLOCATED);
859
961
962 // initialize floating point control register
963 os::Aix::init_thread_fpu_state();
964
965 // Initial thread state is RUNNABLE
966 osthread->set_state(RUNNABLE);
967
968 thread->set_osthread(osthread);
969
970 if (UseNUMA) {
971 int lgrp_id = os::numa_get_group_id();
972 if (lgrp_id != -1) {
973 thread->set_lgrp_id(lgrp_id);
974 }
975 }
976
977 // initialize signal mask for this thread
978 // and save the caller's signal mask
979 os::Aix::hotspot_sigmask(thread);
980
981 log_info(os, thread)("Thread attached (pthread id " UINTX_FORMAT ", tid " UINTX_FORMAT ")",
982 (uintx) pthread_id, (uintx) kernel_thread_id);
983
984 return true;
985 }
986
987 void os::pd_start_thread(Thread* thread) {
988 int status = pthread_continue_np(thread->osthread()->pthread_id());
989 assert(status == 0, "thr_continue failed");
990 }
991
992 // Free OS resources related to the OSThread
993 void os::free_thread(OSThread* osthread) {
994 assert(osthread != NULL, "osthread not set");
995
996 if (Thread::current()->osthread() == osthread) {
997 // Restore caller's signal mask
998 sigset_t sigmask = osthread->caller_sigmask();
999 pthread_sigmask(SIG_SETMASK, &sigmask, NULL);
1000 }
1001
1002 delete osthread;
|
1 /*
2 * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2012, 2016 SAP SE. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
775
776 //////////////////////////////////////////////////////////////////////////////
777 // create new thread
778
779 // Thread start routine for all newly created threads
780 static void *java_start(Thread *thread) {
781
782 // find out my own stack dimensions
783 {
784 // actually, this should do exactly the same as thread->record_stack_base_and_size...
785 address base = 0;
786 size_t size = 0;
787 query_stack_dimensions(&base, &size);
788 thread->set_stack_base(base);
789 thread->set_stack_size(size);
790 }
791
792 const pthread_t pthread_id = ::pthread_self();
793 const tid_t kernel_thread_id = ::thread_self();
794
795 log_info(os, thread)("Thread is alive (tid: " UINTX_FORMAT ", kernel thread id: " UINTX_FORMAT ").",
796 os::current_thread_id(), (uintx) kernel_thread_id);
797
798 // Normally, pthread stacks on AIX live in the data segment (are allocated with malloc()
799 // by the pthread library). In rare cases, this may not be the case, e.g. when third-party
800 // tools hook pthread_create(). In this case, we may run into problems establishing
801 // guard pages on those stacks, because the stacks may reside in memory which is not
802 // protectable (shmated).
803 if (thread->stack_base() > ::sbrk(0)) {
804 log_warning(os, thread)("Thread stack not in data segment.");
805 }
806
807 // Try to randomize the cache line index of hot stack frames.
808 // This helps when threads of the same stack traces evict each other's
809 // cache lines. The threads can be either from the same JVM instance, or
810 // from different JVM instances. The benefit is especially true for
811 // processors with hyperthreading technology.
812
813 static int counter = 0;
814 int pid = os::current_process_id();
815 alloca(((pid ^ counter++) & 7) * 128);
816
817 thread->initialize_thread_current();
818
819 OSThread* osthread = thread->osthread();
820
821 // Thread_id is pthread id.
822 osthread->set_thread_id(pthread_id);
823
824 // .. but keep kernel thread id too for diagnostics
825 osthread->set_kernel_thread_id(kernel_thread_id);
826
827 // Initialize signal mask for this thread.
828 os::Aix::hotspot_sigmask(thread);
829
830 // Initialize floating point control register.
831 os::Aix::init_thread_fpu_state();
832
833 assert(osthread->get_state() == RUNNABLE, "invalid os thread state");
834
835 // Call one more level start routine.
836 thread->run();
837
838 log_info(os, thread)("Thread finished (tid: " UINTX_FORMAT ", kernel thread id: " UINTX_FORMAT ").",
839 os::current_thread_id(), (uintx) kernel_thread_id);
840
841 return 0;
842 }
843
844 bool os::create_thread(Thread* thread, ThreadType thr_type, size_t stack_size) {
845
846 assert(thread->osthread() == NULL, "caller responsible");
847
848 // Allocate the OSThread object
849 OSThread* osthread = new OSThread(NULL, NULL);
850 if (osthread == NULL) {
851 return false;
852 }
853
854 // set the correct thread state
855 osthread->set_thread_type(thr_type);
856
857 // Initial state is ALLOCATED but not INITIALIZED
858 osthread->set_state(ALLOCATED);
859
961
962 // initialize floating point control register
963 os::Aix::init_thread_fpu_state();
964
965 // Initial thread state is RUNNABLE
966 osthread->set_state(RUNNABLE);
967
968 thread->set_osthread(osthread);
969
970 if (UseNUMA) {
971 int lgrp_id = os::numa_get_group_id();
972 if (lgrp_id != -1) {
973 thread->set_lgrp_id(lgrp_id);
974 }
975 }
976
977 // initialize signal mask for this thread
978 // and save the caller's signal mask
979 os::Aix::hotspot_sigmask(thread);
980
981 log_info(os, thread)("Thread attached (tid: " UINTX_FORMAT ", kernel thread id: " UINTX_FORMAT ").",
982 os::current_thread_id(), (uintx) kernel_thread_id);
983
984 return true;
985 }
986
987 void os::pd_start_thread(Thread* thread) {
988 int status = pthread_continue_np(thread->osthread()->pthread_id());
989 assert(status == 0, "thr_continue failed");
990 }
991
992 // Free OS resources related to the OSThread
993 void os::free_thread(OSThread* osthread) {
994 assert(osthread != NULL, "osthread not set");
995
996 if (Thread::current()->osthread() == osthread) {
997 // Restore caller's signal mask
998 sigset_t sigmask = osthread->caller_sigmask();
999 pthread_sigmask(SIG_SETMASK, &sigmask, NULL);
1000 }
1001
1002 delete osthread;
|