37 #include "runtime/atomic.hpp" |
37 #include "runtime/atomic.hpp" |
38 #include "runtime/globals.hpp" |
38 #include "runtime/globals.hpp" |
39 #include "runtime/interfaceSupport.hpp" |
39 #include "runtime/interfaceSupport.hpp" |
40 #include "runtime/orderAccess.inline.hpp" |
40 #include "runtime/orderAccess.inline.hpp" |
41 #include "runtime/reflection.hpp" |
41 #include "runtime/reflection.hpp" |
|
42 #include "runtime/thread.hpp" |
|
43 #include "runtime/threadSMR.hpp" |
42 #include "runtime/vm_version.hpp" |
44 #include "runtime/vm_version.hpp" |
43 #include "services/threadService.hpp" |
45 #include "services/threadService.hpp" |
44 #include "trace/tracing.hpp" |
46 #include "trace/tracing.hpp" |
45 #include "utilities/align.hpp" |
47 #include "utilities/align.hpp" |
46 #include "utilities/copy.hpp" |
48 #include "utilities/copy.hpp" |
935 |
937 |
936 UNSAFE_ENTRY(void, Unsafe_Unpark(JNIEnv *env, jobject unsafe, jobject jthread)) { |
938 UNSAFE_ENTRY(void, Unsafe_Unpark(JNIEnv *env, jobject unsafe, jobject jthread)) { |
937 Parker* p = NULL; |
939 Parker* p = NULL; |
938 |
940 |
939 if (jthread != NULL) { |
941 if (jthread != NULL) { |
940 oop java_thread = JNIHandles::resolve_non_null(jthread); |
942 ThreadsListHandle tlh; |
|
943 JavaThread* thr = NULL; |
|
944 oop java_thread = NULL; |
|
945 (void) tlh.cv_internal_thread_to_JavaThread(jthread, &thr, &java_thread); |
941 if (java_thread != NULL) { |
946 if (java_thread != NULL) { |
|
947 // This is a valid oop. |
942 jlong lp = java_lang_Thread::park_event(java_thread); |
948 jlong lp = java_lang_Thread::park_event(java_thread); |
943 if (lp != 0) { |
949 if (lp != 0) { |
944 // This cast is OK even though the jlong might have been read |
950 // This cast is OK even though the jlong might have been read |
945 // non-atomically on 32bit systems, since there, one word will |
951 // non-atomically on 32bit systems, since there, one word will |
946 // always be zero anyway and the value set is always the same |
952 // always be zero anyway and the value set is always the same |
947 p = (Parker*)addr_from_java(lp); |
953 p = (Parker*)addr_from_java(lp); |
948 } else { |
954 } else { |
949 // Grab lock if apparently null or using older version of library |
955 // Not cached in the java.lang.Thread oop yet (could be an |
950 MutexLocker mu(Threads_lock); |
956 // older version of library). |
951 java_thread = JNIHandles::resolve_non_null(jthread); |
957 if (thr != NULL) { |
952 |
958 // The JavaThread is alive. |
953 if (java_thread != NULL) { |
959 p = thr->parker(); |
954 JavaThread* thr = java_lang_Thread::thread(java_thread); |
960 if (p != NULL) { |
955 if (thr != NULL) { |
961 // Cache the Parker in the java.lang.Thread oop for next time. |
956 p = thr->parker(); |
962 java_lang_Thread::set_park_event(java_thread, addr_to_java(p)); |
957 if (p != NULL) { // Bind to Java thread for next time. |
|
958 java_lang_Thread::set_park_event(java_thread, addr_to_java(p)); |
|
959 } |
|
960 } |
963 } |
961 } |
964 } |
962 } |
965 } |
963 } |
966 } |
964 } |
967 } // ThreadsListHandle is destroyed here. |
965 |
968 |
966 if (p != NULL) { |
969 if (p != NULL) { |
967 HOTSPOT_THREAD_UNPARK((uintptr_t) p); |
970 HOTSPOT_THREAD_UNPARK((uintptr_t) p); |
968 p->unpark(); |
971 p->unpark(); |
969 } |
972 } |