885 address base = 0;
886 size_t size = 0;
887 query_stack_dimensions(&base, &size);
888 thread->set_stack_base(base);
889 thread->set_stack_size(size);
890 }
891
892 // Do some sanity checks.
893 CHECK_CURRENT_STACK_PTR(thread->stack_base(), thread->stack_size());
894
895 // Try to randomize the cache line index of hot stack frames.
896 // This helps when threads of the same stack traces evict each other's
897 // cache lines. The threads can be either from the same JVM instance, or
898 // from different JVM instances. The benefit is especially true for
899 // processors with hyperthreading technology.
900
901 static int counter = 0;
902 int pid = os::current_process_id();
903 alloca(((pid ^ counter++) & 7) * 128);
904
905 ThreadLocalStorage::set_thread(thread);
906
907 OSThread* osthread = thread->osthread();
908
909 // thread_id is kernel thread id (similar to Solaris LWP id)
910 osthread->set_thread_id(os::Aix::gettid());
911
912 // initialize signal mask for this thread
913 os::Aix::hotspot_sigmask(thread);
914
915 // initialize floating point control register
916 os::Aix::init_thread_fpu_state();
917
918 assert(osthread->get_state() == RUNNABLE, "invalid os thread state");
919
920 // call one more level start routine
921 thread->run();
922
923 return 0;
924 }
925
1058
1059 return true;
1060 }
1061
1062 void os::pd_start_thread(Thread* thread) {
1063 int status = pthread_continue_np(thread->osthread()->pthread_id());
1064 assert(status == 0, "thr_continue failed");
1065 }
1066
1067 // Free OS resources related to the OSThread
1068 void os::free_thread(OSThread* osthread) {
1069 assert(osthread != NULL, "osthread not set");
1070
1071 if (Thread::current()->osthread() == osthread) {
1072 // Restore caller's signal mask
1073 sigset_t sigmask = osthread->caller_sigmask();
1074 pthread_sigmask(SIG_SETMASK, &sigmask, NULL);
1075 }
1076
1077 delete osthread;
1078 }
1079
1080 //////////////////////////////////////////////////////////////////////////////
1081 // thread local storage
1082
1083 int os::allocate_thread_local_storage() {
1084 pthread_key_t key;
1085 int rslt = pthread_key_create(&key, NULL);
1086 assert(rslt == 0, "cannot allocate thread local storage");
1087 return (int)key;
1088 }
1089
1090 // Note: This is currently not used by VM, as we don't destroy TLS key
1091 // on VM exit.
1092 void os::free_thread_local_storage(int index) {
1093 int rslt = pthread_key_delete((pthread_key_t)index);
1094 assert(rslt == 0, "invalid index");
1095 }
1096
1097 void os::thread_local_storage_at_put(int index, void* value) {
1098 int rslt = pthread_setspecific((pthread_key_t)index, value);
1099 assert(rslt == 0, "pthread_setspecific failed");
1100 }
1101
1102 extern "C" Thread* get_thread() {
1103 return ThreadLocalStorage::thread();
1104 }
1105
1106 ////////////////////////////////////////////////////////////////////////////////
1107 // time support
1108
1109 // Time since start-up in seconds to a fine granularity.
1110 // Used by VMSelfDestructTimer and the MemProfiler.
1111 double os::elapsedTime() {
1112 return (double)(os::elapsed_counter()) * 0.000001;
1113 }
1114
1115 jlong os::elapsed_counter() {
1116 timeval time;
1117 int status = gettimeofday(&time, NULL);
1118 return jlong(time.tv_sec) * 1000 * 1000 + jlong(time.tv_usec) - initial_time_count;
1119 }
1120
1121 jlong os::elapsed_frequency() {
1122 return (1000 * 1000);
1123 }
|
885 address base = 0;
886 size_t size = 0;
887 query_stack_dimensions(&base, &size);
888 thread->set_stack_base(base);
889 thread->set_stack_size(size);
890 }
891
892 // Do some sanity checks.
893 CHECK_CURRENT_STACK_PTR(thread->stack_base(), thread->stack_size());
894
895 // Try to randomize the cache line index of hot stack frames.
896 // This helps when threads of the same stack traces evict each other's
897 // cache lines. The threads can be either from the same JVM instance, or
898 // from different JVM instances. The benefit is especially true for
899 // processors with hyperthreading technology.
900
901 static int counter = 0;
902 int pid = os::current_process_id();
903 alloca(((pid ^ counter++) & 7) * 128);
904
905 thread->initialize_thread_current();
906
907 OSThread* osthread = thread->osthread();
908
909 // thread_id is kernel thread id (similar to Solaris LWP id)
910 osthread->set_thread_id(os::Aix::gettid());
911
912 // initialize signal mask for this thread
913 os::Aix::hotspot_sigmask(thread);
914
915 // initialize floating point control register
916 os::Aix::init_thread_fpu_state();
917
918 assert(osthread->get_state() == RUNNABLE, "invalid os thread state");
919
920 // call one more level start routine
921 thread->run();
922
923 return 0;
924 }
925
1058
1059 return true;
1060 }
1061
1062 void os::pd_start_thread(Thread* thread) {
1063 int status = pthread_continue_np(thread->osthread()->pthread_id());
1064 assert(status == 0, "thr_continue failed");
1065 }
1066
1067 // Free OS resources related to the OSThread
1068 void os::free_thread(OSThread* osthread) {
1069 assert(osthread != NULL, "osthread not set");
1070
1071 if (Thread::current()->osthread() == osthread) {
1072 // Restore caller's signal mask
1073 sigset_t sigmask = osthread->caller_sigmask();
1074 pthread_sigmask(SIG_SETMASK, &sigmask, NULL);
1075 }
1076
1077 delete osthread;
1078 }
1079
1080 ////////////////////////////////////////////////////////////////////////////////
1081 // time support
1082
1083 // Time since start-up in seconds to a fine granularity.
1084 // Used by VMSelfDestructTimer and the MemProfiler.
1085 double os::elapsedTime() {
1086 return (double)(os::elapsed_counter()) * 0.000001;
1087 }
1088
1089 jlong os::elapsed_counter() {
1090 timeval time;
1091 int status = gettimeofday(&time, NULL);
1092 return jlong(time.tv_sec) * 1000 * 1000 + jlong(time.tv_usec) - initial_time_count;
1093 }
1094
1095 jlong os::elapsed_frequency() {
1096 return (1000 * 1000);
1097 }
|