Merge

Wed, 09 Apr 2014 03:48:28 -0700

author
kevinw
date
Wed, 09 Apr 2014 03:48:28 -0700
changeset 6554
58fab66a8297
parent 6552
8847586c9037
parent 6553
21dd1c827123
child 6555
a57ba009d4dc
child 6610
b127b0d6de7f

Merge

     1.1 --- a/src/os/bsd/vm/os_bsd.cpp	Thu Apr 03 17:49:31 2014 +0400
     1.2 +++ b/src/os/bsd/vm/os_bsd.cpp	Wed Apr 09 03:48:28 2014 -0700
     1.3 @@ -914,9 +914,20 @@
     1.4  //////////////////////////////////////////////////////////////////////////////
     1.5  // thread local storage
     1.6  
     1.7 +// Restore the thread pointer if the destructor is called. This is in case
     1.8 +// someone from JNI code sets up a destructor with pthread_key_create to run
     1.9 +// detachCurrentThread on thread death. Unless we restore the thread pointer we
    1.10 +// will hang or crash. When detachCurrentThread is called the key will be set
    1.11 +// to null and we will not be called again. If detachCurrentThread is never
    1.12 +// called we could loop forever depending on the pthread implementation.
    1.13 +static void restore_thread_pointer(void* p) {
    1.14 +  Thread* thread = (Thread*) p;
    1.15 +  os::thread_local_storage_at_put(ThreadLocalStorage::thread_index(), thread);
    1.16 +}
    1.17 +
    1.18  int os::allocate_thread_local_storage() {
    1.19    pthread_key_t key;
    1.20 -  int rslt = pthread_key_create(&key, NULL);
    1.21 +  int rslt = pthread_key_create(&key, restore_thread_pointer);
    1.22    assert(rslt == 0, "cannot allocate thread local storage");
    1.23    return (int)key;
    1.24  }
     2.1 --- a/src/os/linux/vm/os_linux.cpp	Thu Apr 03 17:49:31 2014 +0400
     2.2 +++ b/src/os/linux/vm/os_linux.cpp	Wed Apr 09 03:48:28 2014 -0700
     2.3 @@ -1074,9 +1074,20 @@
     2.4  //////////////////////////////////////////////////////////////////////////////
     2.5  // thread local storage
     2.6  
     2.7 +// Restore the thread pointer if the destructor is called. This is in case
     2.8 +// someone from JNI code sets up a destructor with pthread_key_create to run
     2.9 +// detachCurrentThread on thread death. Unless we restore the thread pointer we
    2.10 +// will hang or crash. When detachCurrentThread is called the key will be set
    2.11 +// to null and we will not be called again. If detachCurrentThread is never
    2.12 +// called we could loop forever depending on the pthread implementation.
    2.13 +static void restore_thread_pointer(void* p) {
    2.14 +  Thread* thread = (Thread*) p;
    2.15 +  os::thread_local_storage_at_put(ThreadLocalStorage::thread_index(), thread);
    2.16 +}
    2.17 +
    2.18  int os::allocate_thread_local_storage() {
    2.19    pthread_key_t key;
    2.20 -  int rslt = pthread_key_create(&key, NULL);
    2.21 +  int rslt = pthread_key_create(&key, restore_thread_pointer);
    2.22    assert(rslt == 0, "cannot allocate thread local storage");
    2.23    return (int)key;
    2.24  }
     3.1 --- a/src/share/vm/runtime/vmThread.cpp	Thu Apr 03 17:49:31 2014 +0400
     3.2 +++ b/src/share/vm/runtime/vmThread.cpp	Wed Apr 09 03:48:28 2014 -0700
     3.3 @@ -316,6 +316,9 @@
     3.4      _terminate_lock->notify();
     3.5    }
     3.6  
     3.7 +  // Thread destructor usually does this.
     3.8 +  ThreadLocalStorage::set_thread(NULL);
     3.9 +
    3.10    // Deletion must be done synchronously by the JNI DestroyJavaVM thread
    3.11    // so that the VMThread deletion completes before the main thread frees
    3.12    // up the CodeHeap.

mercurial