< prev index next >

src/os/bsd/vm/os_bsd.cpp

Print this page




 657   mach_msg_type_number_t            count = THREAD_IDENTIFIER_INFO_COUNT;
 658 
 659   thread_info(mach_thread_port, THREAD_IDENTIFIER_INFO,
 660               (thread_info_t) &m_ident_info, &count);
 661 
 662   return m_ident_info.thread_id;
 663 }
 664 #endif
 665 
 666 // Thread start routine for all newly created threads
 667 static void *java_start(Thread *thread) {
 668   // Try to randomize the cache line index of hot stack frames.
 669   // This helps when threads of the same stack traces evict each other's
 670   // cache lines. The threads can be either from the same JVM instance, or
 671   // from different JVM instances. The benefit is especially true for
 672   // processors with hyperthreading technology.
 673   static int counter = 0;
 674   int pid = os::current_process_id();
 675   alloca(((pid ^ counter++) & 7) * 128);
 676 
 677   ThreadLocalStorage::set_thread(thread);
 678 
 679   OSThread* osthread = thread->osthread();
 680   Monitor* sync = osthread->startThread_lock();
 681 
 682   osthread->set_thread_id(os::Bsd::gettid());
 683 
 684 #ifdef __APPLE__
 685   uint64_t unique_thread_id = locate_unique_thread_id(osthread->thread_id());
 686   guarantee(unique_thread_id != 0, "unique thread id was not found");
 687   osthread->set_unique_thread_id(unique_thread_id);
 688 #endif
 689   // initialize signal mask for this thread
 690   os::Bsd::hotspot_sigmask(thread);
 691 
 692   // initialize floating point control register
 693   os::Bsd::init_thread_fpu_state();
 694 
 695 #ifdef __APPLE__
 696   // register thread with objc gc
 697   if (objc_registerThreadWithCollectorFunction != NULL) {


 864 void os::pd_start_thread(Thread* thread) {
 865   OSThread * osthread = thread->osthread();
 866   assert(osthread->get_state() != INITIALIZED, "just checking");
 867   Monitor* sync_with_child = osthread->startThread_lock();
 868   MutexLockerEx ml(sync_with_child, Mutex::_no_safepoint_check_flag);
 869   sync_with_child->notify();
 870 }
 871 
 872 // Free Bsd resources related to the OSThread
 873 void os::free_thread(OSThread* osthread) {
 874   assert(osthread != NULL, "osthread not set");
 875 
 876   if (Thread::current()->osthread() == osthread) {
 877     // Restore caller's signal mask
 878     sigset_t sigmask = osthread->caller_sigmask();
 879     pthread_sigmask(SIG_SETMASK, &sigmask, NULL);
 880   }
 881 
 882   delete osthread;
 883 }
 884 
 885 //////////////////////////////////////////////////////////////////////////////
 886 // thread local storage
 887 
 888 // Restore the thread pointer if the destructor is called. This is in case
 889 // someone from JNI code sets up a destructor with pthread_key_create to run
 890 // detachCurrentThread on thread death. Unless we restore the thread pointer we
 891 // will hang or crash. When detachCurrentThread is called the key will be set
 892 // to null and we will not be called again. If detachCurrentThread is never
 893 // called we could loop forever depending on the pthread implementation.
 894 static void restore_thread_pointer(void* p) {
 895   Thread* thread = (Thread*) p;
 896   os::thread_local_storage_at_put(ThreadLocalStorage::thread_index(), thread);
 897 }
 898 
 899 int os::allocate_thread_local_storage() {
 900   pthread_key_t key;
 901   int rslt = pthread_key_create(&key, restore_thread_pointer);
 902   assert(rslt == 0, "cannot allocate thread local storage");
 903   return (int)key;
 904 }
 905 
 906 // Note: This is currently not used by VM, as we don't destroy TLS key
 907 // on VM exit.
 908 void os::free_thread_local_storage(int index) {
 909   int rslt = pthread_key_delete((pthread_key_t)index);
 910   assert(rslt == 0, "invalid index");
 911 }
 912 
 913 void os::thread_local_storage_at_put(int index, void* value) {
 914   int rslt = pthread_setspecific((pthread_key_t)index, value);
 915   assert(rslt == 0, "pthread_setspecific failed");
 916 }
 917 
 918 extern "C" Thread* get_thread() {
 919   return ThreadLocalStorage::thread();
 920 }
 921 
 922 
 923 ////////////////////////////////////////////////////////////////////////////////
 924 // time support
 925 
 926 // Time since start-up in seconds to a fine granularity.
 927 // Used by VMSelfDestructTimer and the MemProfiler.
 928 double os::elapsedTime() {
 929 
 930   return ((double)os::elapsed_counter()) / os::elapsed_frequency();
 931 }
 932 
 933 jlong os::elapsed_counter() {
 934   return javaTimeNanos() - initial_time_count;
 935 }
 936 
 937 jlong os::elapsed_frequency() {
 938   return NANOSECS_PER_SEC; // nanosecond resolution
 939 }
 940 
 941 bool os::supports_vtime() { return true; }




 657   mach_msg_type_number_t            count = THREAD_IDENTIFIER_INFO_COUNT;
 658 
 659   thread_info(mach_thread_port, THREAD_IDENTIFIER_INFO,
 660               (thread_info_t) &m_ident_info, &count);
 661 
 662   return m_ident_info.thread_id;
 663 }
 664 #endif
 665 
 666 // Thread start routine for all newly created threads
 667 static void *java_start(Thread *thread) {
 668   // Try to randomize the cache line index of hot stack frames.
 669   // This helps when threads of the same stack traces evict each other's
 670   // cache lines. The threads can be either from the same JVM instance, or
 671   // from different JVM instances. The benefit is especially true for
 672   // processors with hyperthreading technology.
 673   static int counter = 0;
 674   int pid = os::current_process_id();
 675   alloca(((pid ^ counter++) & 7) * 128);
 676 
 677   thread->initialize_thread_current();
 678 
 679   OSThread* osthread = thread->osthread();
 680   Monitor* sync = osthread->startThread_lock();
 681 
 682   osthread->set_thread_id(os::Bsd::gettid());
 683 
 684 #ifdef __APPLE__
 685   uint64_t unique_thread_id = locate_unique_thread_id(osthread->thread_id());
 686   guarantee(unique_thread_id != 0, "unique thread id was not found");
 687   osthread->set_unique_thread_id(unique_thread_id);
 688 #endif
 689   // initialize signal mask for this thread
 690   os::Bsd::hotspot_sigmask(thread);
 691 
 692   // initialize floating point control register
 693   os::Bsd::init_thread_fpu_state();
 694 
 695 #ifdef __APPLE__
 696   // register thread with objc gc
 697   if (objc_registerThreadWithCollectorFunction != NULL) {


 864 void os::pd_start_thread(Thread* thread) {
 865   OSThread * osthread = thread->osthread();
 866   assert(osthread->get_state() != INITIALIZED, "just checking");
 867   Monitor* sync_with_child = osthread->startThread_lock();
 868   MutexLockerEx ml(sync_with_child, Mutex::_no_safepoint_check_flag);
 869   sync_with_child->notify();
 870 }
 871 
 872 // Free Bsd resources related to the OSThread
 873 void os::free_thread(OSThread* osthread) {
 874   assert(osthread != NULL, "osthread not set");
 875 
 876   if (Thread::current()->osthread() == osthread) {
 877     // Restore caller's signal mask
 878     sigset_t sigmask = osthread->caller_sigmask();
 879     pthread_sigmask(SIG_SETMASK, &sigmask, NULL);
 880   }
 881 
 882   delete osthread;
 883 }






































 884 
 885 ////////////////////////////////////////////////////////////////////////////////
 886 // time support
 887 
 888 // Time since start-up in seconds to a fine granularity.
 889 // Used by VMSelfDestructTimer and the MemProfiler.
 890 double os::elapsedTime() {
 891 
 892   return ((double)os::elapsed_counter()) / os::elapsed_frequency();
 893 }
 894 
 895 jlong os::elapsed_counter() {
 896   return javaTimeNanos() - initial_time_count;
 897 }
 898 
 899 jlong os::elapsed_frequency() {
 900   return NANOSECS_PER_SEC; // nanosecond resolution
 901 }
 902 
 903 bool os::supports_vtime() { return true; }


< prev index next >