comparison src/os/bsd/vm/os_bsd.cpp @ 17845:21dd1c827123

8033696: "assert(thread != NULL) failed: just checking" due to Thread::current() and JNI pthread interaction Reviewed-by: dholmes, dsamersoff Contributed-by: andreas.eriksson@oracle.com
author kevinw
date Wed, 02 Apr 2014 18:40:52 +0200
parents 62c54fcc0a35
children 6048424d3865
comparison
equal deleted inserted replaced
17843:81d7a4b28dc5 17845:21dd1c827123
912 } 912 }
913 913
914 ////////////////////////////////////////////////////////////////////////////// 914 //////////////////////////////////////////////////////////////////////////////
915 // thread local storage 915 // thread local storage
916 916
917 // Restore the thread pointer if the destructor is called. This is in case
918 // someone from JNI code sets up a destructor with pthread_key_create to run
919 // detachCurrentThread on thread death. Unless we restore the thread pointer we
920 // will hang or crash. When detachCurrentThread is called the key will be set
921 // to null and we will not be called again. If detachCurrentThread is never
922 // called we could loop forever depending on the pthread implementation.
923 static void restore_thread_pointer(void* p) {
924 Thread* thread = (Thread*) p;
925 os::thread_local_storage_at_put(ThreadLocalStorage::thread_index(), thread);
926 }
927
917 int os::allocate_thread_local_storage() { 928 int os::allocate_thread_local_storage() {
918 pthread_key_t key; 929 pthread_key_t key;
919 int rslt = pthread_key_create(&key, NULL); 930 int rslt = pthread_key_create(&key, restore_thread_pointer);
920 assert(rslt == 0, "cannot allocate thread local storage"); 931 assert(rslt == 0, "cannot allocate thread local storage");
921 return (int)key; 932 return (int)key;
922 } 933 }
923 934
924 // Note: This is currently not used by VM, as we don't destroy TLS key 935 // Note: This is currently not used by VM, as we don't destroy TLS key