84 res = _global_handles->allocate_handle(obj());
85 } else {
86 CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
87 }
88
89 return res;
90 }
91
92
93 jobject JNIHandles::make_weak_global(Handle obj) {
94 assert(!Universe::heap()->is_gc_active(), "can't extend the root set during GC");
95 jobject res = NULL;
96 if (!obj.is_null()) {
97 // ignore null handles
98 {
99 MutexLocker ml(JNIGlobalHandle_lock);
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);
107 } else {
108 CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
109 }
110 return res;
111 }
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 }
|
84 res = _global_handles->allocate_handle(obj());
85 } else {
86 CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
87 }
88
89 return res;
90 }
91
92
93 jobject JNIHandles::make_weak_global(Handle obj) {
94 assert(!Universe::heap()->is_gc_active(), "can't extend the root set during GC");
95 jobject res = NULL;
96 if (!obj.is_null()) {
97 // ignore null handles
98 {
99 MutexLocker ml(JNIGlobalHandle_lock);
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_aligned(res, weak_tag_alignment), "invariant");
105 char* tptr = reinterpret_cast<char*>(res) + weak_tag_value;
106 res = reinterpret_cast<jobject>(tptr);
107 } else {
108 CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
109 }
110 return res;
111 }
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 }
|