提交 6cbf10fc 编写于 作者: K kevinw

Merge

...@@ -914,9 +914,20 @@ void os::free_thread(OSThread* osthread) { ...@@ -914,9 +914,20 @@ void os::free_thread(OSThread* osthread) {
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// thread local storage // thread local storage
// Restore the thread pointer if the destructor is called. This is in case
// someone from JNI code sets up a destructor with pthread_key_create to run
// detachCurrentThread on thread death. Unless we restore the thread pointer we
// will hang or crash. When detachCurrentThread is called the key will be set
// to null and we will not be called again. If detachCurrentThread is never
// called we could loop forever depending on the pthread implementation.
static void restore_thread_pointer(void* p) {
Thread* thread = (Thread*) p;
os::thread_local_storage_at_put(ThreadLocalStorage::thread_index(), thread);
}
int os::allocate_thread_local_storage() { int os::allocate_thread_local_storage() {
pthread_key_t key; pthread_key_t key;
int rslt = pthread_key_create(&key, NULL); int rslt = pthread_key_create(&key, restore_thread_pointer);
assert(rslt == 0, "cannot allocate thread local storage"); assert(rslt == 0, "cannot allocate thread local storage");
return (int)key; return (int)key;
} }
......
...@@ -1074,9 +1074,20 @@ void os::free_thread(OSThread* osthread) { ...@@ -1074,9 +1074,20 @@ void os::free_thread(OSThread* osthread) {
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// thread local storage // thread local storage
// Restore the thread pointer if the destructor is called. This is in case
// someone from JNI code sets up a destructor with pthread_key_create to run
// detachCurrentThread on thread death. Unless we restore the thread pointer we
// will hang or crash. When detachCurrentThread is called the key will be set
// to null and we will not be called again. If detachCurrentThread is never
// called we could loop forever depending on the pthread implementation.
static void restore_thread_pointer(void* p) {
Thread* thread = (Thread*) p;
os::thread_local_storage_at_put(ThreadLocalStorage::thread_index(), thread);
}
int os::allocate_thread_local_storage() { int os::allocate_thread_local_storage() {
pthread_key_t key; pthread_key_t key;
int rslt = pthread_key_create(&key, NULL); int rslt = pthread_key_create(&key, restore_thread_pointer);
assert(rslt == 0, "cannot allocate thread local storage"); assert(rslt == 0, "cannot allocate thread local storage");
return (int)key; return (int)key;
} }
......
...@@ -316,6 +316,9 @@ void VMThread::run() { ...@@ -316,6 +316,9 @@ void VMThread::run() {
_terminate_lock->notify(); _terminate_lock->notify();
} }
// Thread destructor usually does this.
ThreadLocalStorage::set_thread(NULL);
// Deletion must be done synchronously by the JNI DestroyJavaVM thread // Deletion must be done synchronously by the JNI DestroyJavaVM thread
// so that the VMThread deletion completes before the main thread frees // so that the VMThread deletion completes before the main thread frees
// up the CodeHeap. // up the CodeHeap.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册