src/share/vm/runtime/jniHandles.cpp

changeset 9669
32bc598624bd
parent 9665
a8441ccaff15
child 9703
2fdf635bcf28
equal deleted inserted replaced
9668:acb9351e3a29 9669:32bc598624bd
28 #include "oops/oop.inline.hpp" 28 #include "oops/oop.inline.hpp"
29 #include "prims/jvmtiExport.hpp" 29 #include "prims/jvmtiExport.hpp"
30 #include "runtime/jniHandles.hpp" 30 #include "runtime/jniHandles.hpp"
31 #include "runtime/mutexLocker.hpp" 31 #include "runtime/mutexLocker.hpp"
32 #include "runtime/thread.inline.hpp" 32 #include "runtime/thread.inline.hpp"
33 #if INCLUDE_ALL_GCS
34 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
35 #endif
33 36
34 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC 37 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
35 38
36 JNIHandleBlock* JNIHandles::_global_handles = NULL; 39 JNIHandleBlock* JNIHandles::_global_handles = NULL;
37 JNIHandleBlock* JNIHandles::_weak_global_handles = NULL; 40 JNIHandleBlock* JNIHandles::_weak_global_handles = NULL;
85 } 88 }
86 89
87 return res; 90 return res;
88 } 91 }
89 92
90
91 jobject JNIHandles::make_weak_global(Handle obj) { 93 jobject JNIHandles::make_weak_global(Handle obj) {
92 assert(!Universe::heap()->is_gc_active(), "can't extend the root set during GC"); 94 assert(!Universe::heap()->is_gc_active(), "can't extend the root set during GC");
93 jobject res = NULL; 95 jobject res = NULL;
94 if (!obj.is_null()) { 96 if (!obj.is_null()) {
95 // ignore null handles 97 // ignore null handles
96 MutexLocker ml(JNIGlobalHandle_lock); 98 {
97 assert(Universe::heap()->is_in_reserved(obj()), "sanity check"); 99 MutexLocker ml(JNIGlobalHandle_lock);
98 res = _weak_global_handles->allocate_handle(obj()); 100 assert(Universe::heap()->is_in_reserved(obj()), "sanity check");
101 res = _weak_global_handles->allocate_handle(obj());
102 }
103 // Add weak tag.
104 assert(is_ptr_aligned(res, weak_tag_alignment), "invariant");
105 char* tptr = reinterpret_cast<char*>(res) + weak_tag_value;
106 res = reinterpret_cast<jobject>(tptr);
99 } else { 107 } else {
100 CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops()); 108 CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
101 } 109 }
102 return res; 110 return res;
103 } 111 }
104 112
113 template<bool external_guard>
114 oop JNIHandles::resolve_jweak(jweak handle) {
115 assert(is_jweak(handle), "precondition");
116 oop result = jweak_ref(handle);
117 result = guard_value<external_guard>(result);
118 #if INCLUDE_ALL_GCS
119 if (result != NULL && UseG1GC) {
120 G1SATBCardTableModRefBS::enqueue(result);
121 }
122 #endif // INCLUDE_ALL_GCS
123 return result;
124 }
125
126 template oop JNIHandles::resolve_jweak<true>(jweak);
127 template oop JNIHandles::resolve_jweak<false>(jweak);
105 128
106 void JNIHandles::destroy_global(jobject handle) { 129 void JNIHandles::destroy_global(jobject handle) {
107 if (handle != NULL) { 130 if (handle != NULL) {
108 assert(is_global_handle(handle), "Invalid delete of global JNI handle"); 131 assert(is_global_handle(handle), "Invalid delete of global JNI handle");
109 *((oop*)handle) = deleted_handle(); // Mark the handle as deleted, allocate will reuse it 132 jobject_ref(handle) = deleted_handle();
110 } 133 }
111 } 134 }
112
113 135
114 void JNIHandles::destroy_weak_global(jobject handle) { 136 void JNIHandles::destroy_weak_global(jobject handle) {
115 if (handle != NULL) { 137 if (handle != NULL) {
116 assert(!CheckJNICalls || is_weak_global_handle(handle), "Invalid delete of weak global JNI handle"); 138 jweak_ref(handle) = deleted_handle();
117 *((oop*)handle) = deleted_handle(); // Mark the handle as deleted, allocate will reuse it
118 } 139 }
119 } 140 }
120 141
121 142
122 void JNIHandles::oops_do(OopClosure* f) { 143 void JNIHandles::oops_do(OopClosure* f) {

mercurial