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