author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 46724 | hotspot/src/share/vm/runtime/jniHandles.hpp@a4653c2a4e65 |
child 47794 | e84aa2c71241 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
44406
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
2 |
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5531
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5531
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5531
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#ifndef SHARE_VM_RUNTIME_JNIHANDLES_HPP |
26 |
#define SHARE_VM_RUNTIME_JNIHANDLES_HPP |
|
27 |
||
37466 | 28 |
#include "memory/allocation.hpp" |
7397 | 29 |
#include "runtime/handles.hpp" |
30 |
||
1 | 31 |
class JNIHandleBlock; |
32 |
||
33 |
||
34 |
// Interface for creating and resolving local/global JNI handles |
|
35 |
||
36 |
class JNIHandles : AllStatic { |
|
37 |
friend class VMStructs; |
|
38 |
private: |
|
39 |
static JNIHandleBlock* _global_handles; // First global handle block |
|
40 |
static JNIHandleBlock* _weak_global_handles; // First weak global handle block |
|
41 |
static oop _deleted_handle; // Sentinel marking deleted handles |
|
42 |
||
44406
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
43 |
inline static bool is_jweak(jobject handle); |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
44 |
inline static oop& jobject_ref(jobject handle); // NOT jweak! |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
45 |
inline static oop& jweak_ref(jobject handle); |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
46 |
|
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
47 |
template<bool external_guard> inline static oop guard_value(oop value); |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
48 |
template<bool external_guard> inline static oop resolve_impl(jobject handle); |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
49 |
template<bool external_guard> static oop resolve_jweak(jweak handle); |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
50 |
|
1 | 51 |
public: |
44406
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
52 |
// Low tag bit in jobject used to distinguish a jweak. jweak is |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
53 |
// type equivalent to jobject, but there are places where we need to |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
54 |
// be able to distinguish jweak values from other jobjects, and |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
55 |
// is_weak_global_handle is unsuitable for performance reasons. To |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
56 |
// provide such a test we add weak_tag_value to the (aligned) byte |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
57 |
// address designated by the jobject to produce the corresponding |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
58 |
// jweak. Accessing the value of a jobject must account for it |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
59 |
// being a possibly offset jweak. |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
60 |
static const uintptr_t weak_tag_size = 1; |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
61 |
static const uintptr_t weak_tag_alignment = (1u << weak_tag_size); |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
62 |
static const uintptr_t weak_tag_mask = weak_tag_alignment - 1; |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
63 |
static const int weak_tag_value = 1; |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
64 |
|
1 | 65 |
// Resolve handle into oop |
66 |
inline static oop resolve(jobject handle); |
|
67 |
// Resolve externally provided handle into oop with some guards |
|
68 |
inline static oop resolve_external_guard(jobject handle); |
|
69 |
// Resolve handle into oop, result guaranteed not to be null |
|
70 |
inline static oop resolve_non_null(jobject handle); |
|
71 |
||
72 |
// Local handles |
|
73 |
static jobject make_local(oop obj); |
|
74 |
static jobject make_local(JNIEnv* env, oop obj); // Fast version when env is known |
|
75 |
static jobject make_local(Thread* thread, oop obj); // Even faster version when current thread is known |
|
76 |
inline static void destroy_local(jobject handle); |
|
77 |
||
78 |
// Global handles |
|
79 |
static jobject make_global(Handle obj); |
|
80 |
static void destroy_global(jobject handle); |
|
81 |
||
82 |
// Weak global handles |
|
83 |
static jobject make_weak_global(Handle obj); |
|
84 |
static void destroy_weak_global(jobject handle); |
|
85 |
||
86 |
// Sentinel marking deleted handles in block. Note that we cannot store NULL as |
|
87 |
// the sentinel, since clearing weak global JNI refs are done by storing NULL in |
|
88 |
// the handle. The handle may not be reused before destroy_weak_global is called. |
|
89 |
static oop deleted_handle() { return _deleted_handle; } |
|
90 |
||
91 |
// Initialization |
|
92 |
static void initialize(); |
|
93 |
||
94 |
// Debugging |
|
95 |
static void print_on(outputStream* st); |
|
96 |
static void print() { print_on(tty); } |
|
97 |
static void verify(); |
|
98 |
static bool is_local_handle(Thread* thread, jobject handle); |
|
99 |
static bool is_frame_handle(JavaThread* thr, jobject obj); |
|
100 |
static bool is_global_handle(jobject handle); |
|
101 |
static bool is_weak_global_handle(jobject handle); |
|
102 |
static long global_handle_memory_usage(); |
|
103 |
static long weak_global_handle_memory_usage(); |
|
104 |
||
105 |
// Garbage collection support(global handles only, local handles are traversed from thread) |
|
106 |
// Traversal of regular global handles |
|
107 |
static void oops_do(OopClosure* f); |
|
108 |
// Traversal of weak global handles. Unreachable oops are cleared. |
|
32817
acc2744fd84b
8136627: Backout JDK-8133818 Additional number of processed references printed with -XX:+PrintReferenceGC after JDK-8047125
kbarrett
parents:
32607
diff
changeset
|
109 |
static void weak_oops_do(BoolObjectClosure* is_alive, OopClosure* f); |
37106 | 110 |
// Traversal of weak global handles. |
111 |
static void weak_oops_do(OopClosure* f); |
|
1 | 112 |
}; |
113 |
||
114 |
||
115 |
||
116 |
// JNI handle blocks holding local/global JNI handles |
|
117 |
||
13195 | 118 |
class JNIHandleBlock : public CHeapObj<mtInternal> { |
1 | 119 |
friend class VMStructs; |
4013 | 120 |
friend class CppInterpreter; |
121 |
||
1 | 122 |
private: |
123 |
enum SomeConstants { |
|
124 |
block_size_in_oops = 32 // Number of handles per handle block |
|
125 |
}; |
|
126 |
||
127 |
oop _handles[block_size_in_oops]; // The handles |
|
128 |
int _top; // Index of next unused handle |
|
129 |
JNIHandleBlock* _next; // Link to next block |
|
130 |
||
131 |
// The following instance variables are only used by the first block in a chain. |
|
22551 | 132 |
// Having two types of blocks complicates the code and the space overhead in negligible. |
1 | 133 |
JNIHandleBlock* _last; // Last block in use |
134 |
JNIHandleBlock* _pop_frame_link; // Block to restore on PopLocalFrame call |
|
135 |
oop* _free_list; // Handle free list |
|
136 |
int _allocate_before_rebuild; // Number of blocks to allocate before rebuilding free list |
|
137 |
||
25058
4542f853c2ac
8043224: -Xcheck:jni improvements to exception checking and excessive local refs
dsimms
parents:
22551
diff
changeset
|
138 |
// Check JNI, "planned capacity" for current frame (or push/ensure) |
4542f853c2ac
8043224: -Xcheck:jni improvements to exception checking and excessive local refs
dsimms
parents:
22551
diff
changeset
|
139 |
size_t _planned_capacity; |
4542f853c2ac
8043224: -Xcheck:jni improvements to exception checking and excessive local refs
dsimms
parents:
22551
diff
changeset
|
140 |
|
1 | 141 |
#ifndef PRODUCT |
142 |
JNIHandleBlock* _block_list_link; // Link for list below |
|
143 |
static JNIHandleBlock* _block_list; // List of all allocated blocks (for debugging only) |
|
144 |
#endif |
|
145 |
||
146 |
static JNIHandleBlock* _block_free_list; // Free list of currently unused blocks |
|
147 |
static int _blocks_allocated; // For debugging/printing |
|
148 |
||
149 |
// Fill block with bad_handle values |
|
150 |
void zap(); |
|
151 |
||
152 |
// Free list computation |
|
153 |
void rebuild_free_list(); |
|
154 |
||
46724
a4653c2a4e65
8185263: Fix zero build after 8169881, 8175318, 8178350
stuefe
parents:
46703
diff
changeset
|
155 |
// No more handles in the both the current and following blocks |
a4653c2a4e65
8185263: Fix zero build after 8169881, 8175318, 8178350
stuefe
parents:
46703
diff
changeset
|
156 |
void clear() { _top = 0; } |
a4653c2a4e65
8185263: Fix zero build after 8169881, 8175318, 8178350
stuefe
parents:
46703
diff
changeset
|
157 |
|
1 | 158 |
public: |
159 |
// Handle allocation |
|
160 |
jobject allocate_handle(oop obj); |
|
161 |
||
36508 | 162 |
// Release Handle |
163 |
void release_handle(jobject); |
|
164 |
||
1 | 165 |
// Block allocation and block free list management |
166 |
static JNIHandleBlock* allocate_block(Thread* thread = NULL); |
|
167 |
static void release_block(JNIHandleBlock* block, Thread* thread = NULL); |
|
168 |
||
169 |
// JNI PushLocalFrame/PopLocalFrame support |
|
170 |
JNIHandleBlock* pop_frame_link() const { return _pop_frame_link; } |
|
171 |
void set_pop_frame_link(JNIHandleBlock* block) { _pop_frame_link = block; } |
|
172 |
||
173 |
// Stub generator support |
|
174 |
static int top_offset_in_bytes() { return offset_of(JNIHandleBlock, _top); } |
|
175 |
||
176 |
// Garbage collection support |
|
177 |
// Traversal of regular handles |
|
178 |
void oops_do(OopClosure* f); |
|
179 |
// Traversal of weak handles. Unreachable oops are cleared. |
|
32817
acc2744fd84b
8136627: Backout JDK-8133818 Additional number of processed references printed with -XX:+PrintReferenceGC after JDK-8047125
kbarrett
parents:
32607
diff
changeset
|
180 |
void weak_oops_do(BoolObjectClosure* is_alive, OopClosure* f); |
1 | 181 |
|
25058
4542f853c2ac
8043224: -Xcheck:jni improvements to exception checking and excessive local refs
dsimms
parents:
22551
diff
changeset
|
182 |
// Checked JNI support |
4542f853c2ac
8043224: -Xcheck:jni improvements to exception checking and excessive local refs
dsimms
parents:
22551
diff
changeset
|
183 |
void set_planned_capacity(size_t planned_capacity) { _planned_capacity = planned_capacity; } |
4542f853c2ac
8043224: -Xcheck:jni improvements to exception checking and excessive local refs
dsimms
parents:
22551
diff
changeset
|
184 |
const size_t get_planned_capacity() { return _planned_capacity; } |
4542f853c2ac
8043224: -Xcheck:jni improvements to exception checking and excessive local refs
dsimms
parents:
22551
diff
changeset
|
185 |
const size_t get_number_of_live_handles(); |
4542f853c2ac
8043224: -Xcheck:jni improvements to exception checking and excessive local refs
dsimms
parents:
22551
diff
changeset
|
186 |
|
1 | 187 |
// Debugging |
188 |
bool chain_contains(jobject handle) const; // Does this block or following blocks contain handle |
|
189 |
bool contains(jobject handle) const; // Does this block contain handle |
|
190 |
int length() const; // Length of chain starting with this block |
|
191 |
long memory_usage() const; |
|
192 |
#ifndef PRODUCT |
|
193 |
static bool any_contains(jobject handle); // Does any block currently in use contain handle |
|
194 |
static void print_statistics(); |
|
195 |
#endif |
|
196 |
}; |
|
197 |
||
44406
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
198 |
inline bool JNIHandles::is_jweak(jobject handle) { |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
199 |
STATIC_ASSERT(weak_tag_size == 1); |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
200 |
STATIC_ASSERT(weak_tag_value == 1); |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
201 |
return (reinterpret_cast<uintptr_t>(handle) & weak_tag_mask) != 0; |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
202 |
} |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
203 |
|
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
204 |
inline oop& JNIHandles::jobject_ref(jobject handle) { |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
205 |
assert(!is_jweak(handle), "precondition"); |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
206 |
return *reinterpret_cast<oop*>(handle); |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
207 |
} |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
208 |
|
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
209 |
inline oop& JNIHandles::jweak_ref(jobject handle) { |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
210 |
assert(is_jweak(handle), "precondition"); |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
211 |
char* ptr = reinterpret_cast<char*>(handle) - weak_tag_value; |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
212 |
return *reinterpret_cast<oop*>(ptr); |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
213 |
} |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
214 |
|
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
215 |
// external_guard is true if called from resolve_external_guard. |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
216 |
// Treat deleted (and possibly zapped) as NULL for external_guard, |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
217 |
// else as (asserted) error. |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
218 |
template<bool external_guard> |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
219 |
inline oop JNIHandles::guard_value(oop value) { |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
220 |
if (!external_guard) { |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
221 |
assert(value != badJNIHandle, "Pointing to zapped jni handle area"); |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
222 |
assert(value != deleted_handle(), "Used a deleted global handle"); |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
223 |
} else if ((value == badJNIHandle) || (value == deleted_handle())) { |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
224 |
value = NULL; |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
225 |
} |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
226 |
return value; |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
227 |
} |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
228 |
|
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
229 |
// external_guard is true if called from resolve_external_guard. |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
230 |
template<bool external_guard> |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
231 |
inline oop JNIHandles::resolve_impl(jobject handle) { |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
232 |
assert(handle != NULL, "precondition"); |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
233 |
oop result; |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
234 |
if (is_jweak(handle)) { // Unlikely |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
235 |
result = resolve_jweak<external_guard>(handle); |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
236 |
} else { |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
237 |
result = jobject_ref(handle); |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
238 |
// Construction of jobjects canonicalize a null value into a null |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
239 |
// jobject, so for non-jweak the pointee should never be null. |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
240 |
assert(external_guard || result != NULL, |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
241 |
"Invalid value read from jni handle"); |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
242 |
result = guard_value<external_guard>(result); |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
243 |
} |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
244 |
return result; |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
245 |
} |
1 | 246 |
|
247 |
inline oop JNIHandles::resolve(jobject handle) { |
|
44406
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
248 |
oop result = NULL; |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
249 |
if (handle != NULL) { |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
250 |
result = resolve_impl<false /* external_guard */ >(handle); |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
251 |
} |
1 | 252 |
return result; |
44406
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
253 |
} |
1 | 254 |
|
44406
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
255 |
// Resolve some erroneous cases to NULL, rather than treating them as |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
256 |
// possibly unchecked errors. In particular, deleted handles are |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
257 |
// treated as NULL (though a deleted and later reallocated handle |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
258 |
// isn't detected). |
1 | 259 |
inline oop JNIHandles::resolve_external_guard(jobject handle) { |
44406
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
260 |
oop result = NULL; |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
261 |
if (handle != NULL) { |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
262 |
result = resolve_impl<true /* external_guard */ >(handle); |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
263 |
} |
1 | 264 |
return result; |
44406
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
265 |
} |
1 | 266 |
|
267 |
inline oop JNIHandles::resolve_non_null(jobject handle) { |
|
268 |
assert(handle != NULL, "JNI handle should not be null"); |
|
44406
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
269 |
oop result = resolve_impl<false /* external_guard */ >(handle); |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
270 |
assert(result != NULL, "NULL read from jni handle"); |
1 | 271 |
return result; |
44406
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
272 |
} |
1 | 273 |
|
274 |
inline void JNIHandles::destroy_local(jobject handle) { |
|
275 |
if (handle != NULL) { |
|
44406
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
276 |
jobject_ref(handle) = deleted_handle(); |
1 | 277 |
} |
278 |
} |
|
7397 | 279 |
|
280 |
#endif // SHARE_VM_RUNTIME_JNIHANDLES_HPP |