author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 57828 | 35db8fba55f9 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53149
259c36ef27df
8215731: Move forward class definitions out of globalDefinitions.hpp
coleenp
parents:
53060
diff
changeset
|
2 |
* Copyright (c) 1998, 2019, 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 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
53149
diff
changeset
|
25 |
#ifndef SHARE_RUNTIME_JNIHANDLES_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
53149
diff
changeset
|
26 |
#define SHARE_RUNTIME_JNIHANDLES_HPP |
7397 | 27 |
|
37466 | 28 |
#include "memory/allocation.hpp" |
7397 | 29 |
#include "runtime/handles.hpp" |
30 |
||
53149
259c36ef27df
8215731: Move forward class definitions out of globalDefinitions.hpp
coleenp
parents:
53060
diff
changeset
|
31 |
class JavaThread; |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
48465
diff
changeset
|
32 |
class OopStorage; |
53149
259c36ef27df
8215731: Move forward class definitions out of globalDefinitions.hpp
coleenp
parents:
53060
diff
changeset
|
33 |
class Thread; |
1 | 34 |
|
35 |
// Interface for creating and resolving local/global JNI handles |
|
36 |
||
37 |
class JNIHandles : AllStatic { |
|
38 |
friend class VMStructs; |
|
39 |
private: |
|
57828
35db8fba55f9
8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
57698
diff
changeset
|
40 |
// These are used by the serviceability agent. |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
48465
diff
changeset
|
41 |
static OopStorage* _global_handles; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
48465
diff
changeset
|
42 |
static OopStorage* _weak_global_handles; |
57828
35db8fba55f9
8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
57698
diff
changeset
|
43 |
friend void jni_handles_init(); |
1 | 44 |
|
44406
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
45 |
inline static bool is_jweak(jobject handle); |
49656
be608cad0b2a
8195972: Refactor oops in JNI to use the Access API
kbarrett
parents:
49192
diff
changeset
|
46 |
inline static oop* jobject_ptr(jobject handle); // NOT jweak! |
be608cad0b2a
8195972: Refactor oops in JNI to use the Access API
kbarrett
parents:
49192
diff
changeset
|
47 |
inline static oop* jweak_ptr(jobject handle); |
44406
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
48 |
|
53060
7aa1a37b04a2
8215451: JNI IsSameObject should not keep objects alive
pliden
parents:
49909
diff
changeset
|
49 |
template <DecoratorSet decorators, bool external_guard> inline static oop resolve_impl(jobject handle); |
7aa1a37b04a2
8215451: JNI IsSameObject should not keep objects alive
pliden
parents:
49909
diff
changeset
|
50 |
|
7aa1a37b04a2
8215451: JNI IsSameObject should not keep objects alive
pliden
parents:
49909
diff
changeset
|
51 |
// Resolve handle into oop, without keeping the object alive |
7aa1a37b04a2
8215451: JNI IsSameObject should not keep objects alive
pliden
parents:
49909
diff
changeset
|
52 |
inline static oop resolve_no_keepalive(jobject handle); |
44406
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
53 |
|
48465
f82e79958beb
8167372: Add code to check for getting oops while thread is in native
hseigel
parents:
48147
diff
changeset
|
54 |
// This method is not inlined in order to avoid circular includes between |
f82e79958beb
8167372: Add code to check for getting oops while thread is in native
hseigel
parents:
48147
diff
changeset
|
55 |
// this header file and thread.hpp. |
f82e79958beb
8167372: Add code to check for getting oops while thread is in native
hseigel
parents:
48147
diff
changeset
|
56 |
static bool current_thread_in_native(); |
f82e79958beb
8167372: Add code to check for getting oops while thread is in native
hseigel
parents:
48147
diff
changeset
|
57 |
|
1 | 58 |
public: |
44406
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
59 |
// 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
|
60 |
// 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
|
61 |
// 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
|
62 |
// 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
|
63 |
// 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
|
64 |
// 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
|
65 |
// 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
|
66 |
// being a possibly offset jweak. |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
67 |
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
|
68 |
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
|
69 |
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
|
70 |
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
|
71 |
|
1 | 72 |
// Resolve handle into oop |
73 |
inline static oop resolve(jobject handle); |
|
74 |
// Resolve handle into oop, result guaranteed not to be null |
|
75 |
inline static oop resolve_non_null(jobject handle); |
|
49192
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
48808
diff
changeset
|
76 |
// Resolve externally provided handle into oop with some guards |
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
48808
diff
changeset
|
77 |
static oop resolve_external_guard(jobject handle); |
1 | 78 |
|
53060
7aa1a37b04a2
8215451: JNI IsSameObject should not keep objects alive
pliden
parents:
49909
diff
changeset
|
79 |
// Check for equality without keeping objects alive |
7aa1a37b04a2
8215451: JNI IsSameObject should not keep objects alive
pliden
parents:
49909
diff
changeset
|
80 |
static bool is_same_object(jobject handle1, jobject handle2); |
7aa1a37b04a2
8215451: JNI IsSameObject should not keep objects alive
pliden
parents:
49909
diff
changeset
|
81 |
|
1 | 82 |
// Local handles |
83 |
static jobject make_local(oop obj); |
|
84 |
static jobject make_local(JNIEnv* env, oop obj); // Fast version when env is known |
|
85 |
static jobject make_local(Thread* thread, oop obj); // Even faster version when current thread is known |
|
86 |
inline static void destroy_local(jobject handle); |
|
87 |
||
88 |
// Global handles |
|
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
48465
diff
changeset
|
89 |
static jobject make_global(Handle obj, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM); |
1 | 90 |
static void destroy_global(jobject handle); |
91 |
||
92 |
// Weak global handles |
|
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
48465
diff
changeset
|
93 |
static jobject make_weak_global(Handle obj, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM); |
1 | 94 |
static void destroy_weak_global(jobject handle); |
47794
e84aa2c71241
8188102: [JVMCI] Convert special JVMCI oops in nmethod to jweak values
dnsimon
parents:
47216
diff
changeset
|
95 |
static bool is_global_weak_cleared(jweak handle); // Test jweak without resolution |
1 | 96 |
|
97 |
// Initialization |
|
98 |
static void initialize(); |
|
99 |
||
100 |
// Debugging |
|
101 |
static void print_on(outputStream* st); |
|
54807 | 102 |
static void print(); |
1 | 103 |
static void verify(); |
48808
2b0b7f222800
8195690: JNI GetObjectRefType doesn't handle NULL
kbarrett
parents:
48787
diff
changeset
|
104 |
// The category predicates all require handle != NULL. |
1 | 105 |
static bool is_local_handle(Thread* thread, jobject handle); |
48808
2b0b7f222800
8195690: JNI GetObjectRefType doesn't handle NULL
kbarrett
parents:
48787
diff
changeset
|
106 |
static bool is_frame_handle(JavaThread* thread, jobject handle); |
1 | 107 |
static bool is_global_handle(jobject handle); |
108 |
static bool is_weak_global_handle(jobject handle); |
|
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
48465
diff
changeset
|
109 |
static size_t global_handle_memory_usage(); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
48465
diff
changeset
|
110 |
static size_t weak_global_handle_memory_usage(); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
48465
diff
changeset
|
111 |
|
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
48465
diff
changeset
|
112 |
#ifndef PRODUCT |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
48465
diff
changeset
|
113 |
// Is handle from any local block of any thread? |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
48465
diff
changeset
|
114 |
static bool is_local_handle(jobject handle); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
48465
diff
changeset
|
115 |
#endif |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
48465
diff
changeset
|
116 |
|
48808
2b0b7f222800
8195690: JNI GetObjectRefType doesn't handle NULL
kbarrett
parents:
48787
diff
changeset
|
117 |
// precondition: handle != NULL. |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
48465
diff
changeset
|
118 |
static jobjectRefType handle_type(Thread* thread, jobject handle); |
1 | 119 |
|
120 |
// Garbage collection support(global handles only, local handles are traversed from thread) |
|
121 |
// Traversal of regular global handles |
|
122 |
static void oops_do(OopClosure* f); |
|
123 |
// 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
|
124 |
static void weak_oops_do(BoolObjectClosure* is_alive, OopClosure* f); |
37106 | 125 |
// Traversal of weak global handles. |
126 |
static void weak_oops_do(OopClosure* f); |
|
1 | 127 |
}; |
128 |
||
129 |
||
130 |
||
131 |
// JNI handle blocks holding local/global JNI handles |
|
132 |
||
13195 | 133 |
class JNIHandleBlock : public CHeapObj<mtInternal> { |
1 | 134 |
friend class VMStructs; |
4013 | 135 |
friend class CppInterpreter; |
136 |
||
1 | 137 |
private: |
138 |
enum SomeConstants { |
|
139 |
block_size_in_oops = 32 // Number of handles per handle block |
|
140 |
}; |
|
141 |
||
57698
9dc92e89243a
8229027: Improve how JNIHandleBlock::oops_do distinguishes oops from non-oops
eosterlund
parents:
55213
diff
changeset
|
142 |
uintptr_t _handles[block_size_in_oops]; // The handles |
1 | 143 |
int _top; // Index of next unused handle |
144 |
JNIHandleBlock* _next; // Link to next block |
|
145 |
||
146 |
// The following instance variables are only used by the first block in a chain. |
|
22551 | 147 |
// Having two types of blocks complicates the code and the space overhead in negligible. |
1 | 148 |
JNIHandleBlock* _last; // Last block in use |
149 |
JNIHandleBlock* _pop_frame_link; // Block to restore on PopLocalFrame call |
|
57698
9dc92e89243a
8229027: Improve how JNIHandleBlock::oops_do distinguishes oops from non-oops
eosterlund
parents:
55213
diff
changeset
|
150 |
uintptr_t* _free_list; // Handle free list |
55213
b78597cfcced
8225217: Backout: JDK-8224814: Remove dead JNIHandleBlock freelist code
dholmes
parents:
55153
diff
changeset
|
151 |
int _allocate_before_rebuild; // Number of blocks to allocate before rebuilding free list |
1 | 152 |
|
25058
4542f853c2ac
8043224: -Xcheck:jni improvements to exception checking and excessive local refs
dsimms
parents:
22551
diff
changeset
|
153 |
// 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
|
154 |
size_t _planned_capacity; |
4542f853c2ac
8043224: -Xcheck:jni improvements to exception checking and excessive local refs
dsimms
parents:
22551
diff
changeset
|
155 |
|
1 | 156 |
#ifndef PRODUCT |
157 |
JNIHandleBlock* _block_list_link; // Link for list below |
|
158 |
static JNIHandleBlock* _block_list; // List of all allocated blocks (for debugging only) |
|
159 |
#endif |
|
160 |
||
161 |
static JNIHandleBlock* _block_free_list; // Free list of currently unused blocks |
|
162 |
static int _blocks_allocated; // For debugging/printing |
|
163 |
||
164 |
// Fill block with bad_handle values |
|
48147 | 165 |
void zap() NOT_DEBUG_RETURN; |
1 | 166 |
|
55213
b78597cfcced
8225217: Backout: JDK-8224814: Remove dead JNIHandleBlock freelist code
dholmes
parents:
55153
diff
changeset
|
167 |
// Free list computation |
b78597cfcced
8225217: Backout: JDK-8224814: Remove dead JNIHandleBlock freelist code
dholmes
parents:
55153
diff
changeset
|
168 |
void rebuild_free_list(); |
b78597cfcced
8225217: Backout: JDK-8224814: Remove dead JNIHandleBlock freelist code
dholmes
parents:
55153
diff
changeset
|
169 |
|
46724
a4653c2a4e65
8185263: Fix zero build after 8169881, 8175318, 8178350
stuefe
parents:
46703
diff
changeset
|
170 |
// 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
|
171 |
void clear() { _top = 0; } |
a4653c2a4e65
8185263: Fix zero build after 8169881, 8175318, 8178350
stuefe
parents:
46703
diff
changeset
|
172 |
|
1 | 173 |
public: |
174 |
// Handle allocation |
|
175 |
jobject allocate_handle(oop obj); |
|
176 |
||
177 |
// Block allocation and block free list management |
|
178 |
static JNIHandleBlock* allocate_block(Thread* thread = NULL); |
|
179 |
static void release_block(JNIHandleBlock* block, Thread* thread = NULL); |
|
180 |
||
181 |
// JNI PushLocalFrame/PopLocalFrame support |
|
182 |
JNIHandleBlock* pop_frame_link() const { return _pop_frame_link; } |
|
183 |
void set_pop_frame_link(JNIHandleBlock* block) { _pop_frame_link = block; } |
|
184 |
||
185 |
// Stub generator support |
|
186 |
static int top_offset_in_bytes() { return offset_of(JNIHandleBlock, _top); } |
|
187 |
||
188 |
// Garbage collection support |
|
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
48465
diff
changeset
|
189 |
// Traversal of handles |
1 | 190 |
void oops_do(OopClosure* f); |
191 |
||
25058
4542f853c2ac
8043224: -Xcheck:jni improvements to exception checking and excessive local refs
dsimms
parents:
22551
diff
changeset
|
192 |
// Checked JNI support |
4542f853c2ac
8043224: -Xcheck:jni improvements to exception checking and excessive local refs
dsimms
parents:
22551
diff
changeset
|
193 |
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
|
194 |
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
|
195 |
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
|
196 |
|
1 | 197 |
// Debugging |
198 |
bool chain_contains(jobject handle) const; // Does this block or following blocks contain handle |
|
199 |
bool contains(jobject handle) const; // Does this block contain handle |
|
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
48465
diff
changeset
|
200 |
size_t length() const; // Length of chain starting with this block |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
48465
diff
changeset
|
201 |
size_t memory_usage() const; |
1 | 202 |
#ifndef PRODUCT |
203 |
static bool any_contains(jobject handle); // Does any block currently in use contain handle |
|
204 |
static void print_statistics(); |
|
205 |
#endif |
|
206 |
}; |
|
207 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
53149
diff
changeset
|
208 |
#endif // SHARE_RUNTIME_JNIHANDLES_HPP |