47 char* ptr = reinterpret_cast<char*>(handle) - weak_tag_value; |
47 char* ptr = reinterpret_cast<char*>(handle) - weak_tag_value; |
48 return reinterpret_cast<oop*>(ptr); |
48 return reinterpret_cast<oop*>(ptr); |
49 } |
49 } |
50 |
50 |
51 // external_guard is true if called from resolve_external_guard. |
51 // external_guard is true if called from resolve_external_guard. |
52 template<bool external_guard> |
52 template <DecoratorSet decorators, bool external_guard> |
53 inline oop JNIHandles::resolve_impl(jobject handle) { |
53 inline oop JNIHandles::resolve_impl(jobject handle) { |
54 assert(handle != NULL, "precondition"); |
54 assert(handle != NULL, "precondition"); |
55 assert(!current_thread_in_native(), "must not be in native"); |
55 assert(!current_thread_in_native(), "must not be in native"); |
56 oop result; |
56 oop result; |
57 if (is_jweak(handle)) { // Unlikely |
57 if (is_jweak(handle)) { // Unlikely |
58 result = resolve_jweak(handle); |
58 result = NativeAccess<ON_PHANTOM_OOP_REF|decorators>::oop_load(jweak_ptr(handle)); |
59 } else { |
59 } else { |
60 result = NativeAccess<>::oop_load(jobject_ptr(handle)); |
60 result = NativeAccess<decorators>::oop_load(jobject_ptr(handle)); |
61 // Construction of jobjects canonicalize a null value into a null |
61 // Construction of jobjects canonicalize a null value into a null |
62 // jobject, so for non-jweak the pointee should never be null. |
62 // jobject, so for non-jweak the pointee should never be null. |
63 assert(external_guard || result != NULL, "Invalid JNI handle"); |
63 assert(external_guard || result != NULL, "Invalid JNI handle"); |
64 } |
64 } |
65 return result; |
65 return result; |
66 } |
66 } |
67 |
67 |
68 inline oop JNIHandles::resolve(jobject handle) { |
68 inline oop JNIHandles::resolve(jobject handle) { |
69 oop result = NULL; |
69 oop result = NULL; |
70 if (handle != NULL) { |
70 if (handle != NULL) { |
71 result = resolve_impl<false /* external_guard */ >(handle); |
71 result = resolve_impl<0 /* decorators */, false /* external_guard */>(handle); |
72 } |
72 } |
73 return result; |
73 return result; |
74 } |
74 } |
75 |
75 |
|
76 inline oop JNIHandles::resolve_no_keepalive(jobject handle) { |
|
77 oop result = NULL; |
|
78 if (handle != NULL) { |
|
79 result = resolve_impl<AS_NO_KEEPALIVE, false /* external_guard */>(handle); |
|
80 } |
|
81 return result; |
|
82 } |
|
83 |
|
84 inline bool JNIHandles::is_same_object(jobject handle1, jobject handle2) { |
|
85 oop obj1 = resolve_no_keepalive(handle1); |
|
86 oop obj2 = resolve_no_keepalive(handle2); |
|
87 return oopDesc::equals(obj1, obj2); |
|
88 } |
|
89 |
76 inline oop JNIHandles::resolve_non_null(jobject handle) { |
90 inline oop JNIHandles::resolve_non_null(jobject handle) { |
77 assert(handle != NULL, "JNI handle should not be null"); |
91 assert(handle != NULL, "JNI handle should not be null"); |
78 oop result = resolve_impl<false /* external_guard */ >(handle); |
92 oop result = resolve_impl<0 /* decorators */, false /* external_guard */>(handle); |
79 assert(result != NULL, "NULL read from jni handle"); |
93 assert(result != NULL, "NULL read from jni handle"); |
80 return result; |
94 return result; |
81 } |
95 } |
82 |
96 |
83 inline void JNIHandles::destroy_local(jobject handle) { |
97 inline void JNIHandles::destroy_local(jobject handle) { |