author | coleenp |
Fri, 06 Jul 2018 09:10:07 -0400 | |
changeset 50946 | be2d74d91351 |
parent 49679 | 7084eec5c723 |
child 51996 | 84743156e780 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
50946
be2d74d91351
8205417: Obsolete UnlinkSymbolsALot debugging option
coleenp
parents:
49679
diff
changeset
|
2 |
* Copyright (c) 1997, 2018, 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:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
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:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
49449
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47881
diff
changeset
|
25 |
#ifndef SHARE_VM_RUNTIME_INTERFACESUPPORT_INLINE_HPP |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47881
diff
changeset
|
26 |
#define SHARE_VM_RUNTIME_INTERFACESUPPORT_INLINE_HPP |
7397 | 27 |
|
28 |
#include "runtime/handles.inline.hpp" |
|
29 |
#include "runtime/mutexLocker.hpp" |
|
30 |
#include "runtime/orderAccess.hpp" |
|
31 |
#include "runtime/os.hpp" |
|
47881
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
32 |
#include "runtime/safepointMechanism.inline.hpp" |
49594
898ef81cbc0e
8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents:
49449
diff
changeset
|
33 |
#include "runtime/safepointVerifiers.hpp" |
49449
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47881
diff
changeset
|
34 |
#include "runtime/thread.hpp" |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47881
diff
changeset
|
35 |
#include "runtime/vm_operations.hpp" |
7397 | 36 |
#include "utilities/globalDefinitions.hpp" |
40010 | 37 |
#include "utilities/macros.hpp" |
7397 | 38 |
#include "utilities/preserveException.hpp" |
39 |
||
1 | 40 |
// Wrapper for all entry points to the virtual machine. |
41 |
||
10969
3ecf25293e5a
7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents:
10565
diff
changeset
|
42 |
// InterfaceSupport provides functionality used by the VM_LEAF_BASE and |
3ecf25293e5a
7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents:
10565
diff
changeset
|
43 |
// VM_ENTRY_BASE macros. These macros are used to guard entry points into |
3ecf25293e5a
7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents:
10565
diff
changeset
|
44 |
// the VM and perform checks upon leave of the VM. |
1 | 45 |
|
46 |
||
47 |
class InterfaceSupport: AllStatic { |
|
48 |
# ifdef ASSERT |
|
49 |
public: |
|
50 |
static long _scavenge_alot_counter; |
|
51 |
static long _fullgc_alot_counter; |
|
52 |
static long _number_of_calls; |
|
53 |
static long _fullgc_alot_invocation; |
|
54 |
||
55 |
// Helper methods used to implement +ScavengeALot and +FullGCALot |
|
56 |
static void check_gc_alot() { if (ScavengeALot || FullGCALot) gc_alot(); } |
|
57 |
static void gc_alot(); |
|
58 |
||
59 |
static void walk_stack_from(vframe* start_vf); |
|
60 |
static void walk_stack(); |
|
61 |
||
62 |
static void zombieAll(); |
|
63 |
static void deoptimizeAll(); |
|
64 |
static void stress_derived_pointers(); |
|
65 |
static void verify_stack(); |
|
66 |
static void verify_last_frame(); |
|
67 |
# endif |
|
68 |
||
69 |
public: |
|
46604
d409276ee40c
8183198: Factor out thread state serialization into a proper helper function
mgerdin
parents:
46373
diff
changeset
|
70 |
static void serialize_thread_state_with_handler(JavaThread* thread) { |
d409276ee40c
8183198: Factor out thread state serialization into a proper helper function
mgerdin
parents:
46373
diff
changeset
|
71 |
serialize_thread_state_internal(thread, true); |
d409276ee40c
8183198: Factor out thread state serialization into a proper helper function
mgerdin
parents:
46373
diff
changeset
|
72 |
} |
d409276ee40c
8183198: Factor out thread state serialization into a proper helper function
mgerdin
parents:
46373
diff
changeset
|
73 |
|
d409276ee40c
8183198: Factor out thread state serialization into a proper helper function
mgerdin
parents:
46373
diff
changeset
|
74 |
// Should only call this if we know that we have a proper SEH set up. |
d409276ee40c
8183198: Factor out thread state serialization into a proper helper function
mgerdin
parents:
46373
diff
changeset
|
75 |
static void serialize_thread_state(JavaThread* thread) { |
d409276ee40c
8183198: Factor out thread state serialization into a proper helper function
mgerdin
parents:
46373
diff
changeset
|
76 |
serialize_thread_state_internal(thread, false); |
d409276ee40c
8183198: Factor out thread state serialization into a proper helper function
mgerdin
parents:
46373
diff
changeset
|
77 |
} |
40010 | 78 |
|
46604
d409276ee40c
8183198: Factor out thread state serialization into a proper helper function
mgerdin
parents:
46373
diff
changeset
|
79 |
private: |
d409276ee40c
8183198: Factor out thread state serialization into a proper helper function
mgerdin
parents:
46373
diff
changeset
|
80 |
static void serialize_thread_state_internal(JavaThread* thread, bool needs_exception_handler) { |
d409276ee40c
8183198: Factor out thread state serialization into a proper helper function
mgerdin
parents:
46373
diff
changeset
|
81 |
// Make sure new state is seen by VM thread |
d409276ee40c
8183198: Factor out thread state serialization into a proper helper function
mgerdin
parents:
46373
diff
changeset
|
82 |
if (os::is_MP()) { |
d409276ee40c
8183198: Factor out thread state serialization into a proper helper function
mgerdin
parents:
46373
diff
changeset
|
83 |
if (UseMembar) { |
d409276ee40c
8183198: Factor out thread state serialization into a proper helper function
mgerdin
parents:
46373
diff
changeset
|
84 |
// Force a fence between the write above and read below |
d409276ee40c
8183198: Factor out thread state serialization into a proper helper function
mgerdin
parents:
46373
diff
changeset
|
85 |
OrderAccess::fence(); |
d409276ee40c
8183198: Factor out thread state serialization into a proper helper function
mgerdin
parents:
46373
diff
changeset
|
86 |
} else { |
d409276ee40c
8183198: Factor out thread state serialization into a proper helper function
mgerdin
parents:
46373
diff
changeset
|
87 |
// store to serialize page so VM thread can do pseudo remote membar |
d409276ee40c
8183198: Factor out thread state serialization into a proper helper function
mgerdin
parents:
46373
diff
changeset
|
88 |
if (needs_exception_handler) { |
d409276ee40c
8183198: Factor out thread state serialization into a proper helper function
mgerdin
parents:
46373
diff
changeset
|
89 |
os::write_memory_serialize_page_with_handler(thread); |
d409276ee40c
8183198: Factor out thread state serialization into a proper helper function
mgerdin
parents:
46373
diff
changeset
|
90 |
} else { |
d409276ee40c
8183198: Factor out thread state serialization into a proper helper function
mgerdin
parents:
46373
diff
changeset
|
91 |
os::write_memory_serialize_page(thread); |
d409276ee40c
8183198: Factor out thread state serialization into a proper helper function
mgerdin
parents:
46373
diff
changeset
|
92 |
} |
d409276ee40c
8183198: Factor out thread state serialization into a proper helper function
mgerdin
parents:
46373
diff
changeset
|
93 |
} |
d409276ee40c
8183198: Factor out thread state serialization into a proper helper function
mgerdin
parents:
46373
diff
changeset
|
94 |
} |
d409276ee40c
8183198: Factor out thread state serialization into a proper helper function
mgerdin
parents:
46373
diff
changeset
|
95 |
} |
1 | 96 |
}; |
97 |
||
98 |
||
99 |
// Basic class for all thread transition classes. |
|
100 |
||
101 |
class ThreadStateTransition : public StackObj { |
|
102 |
protected: |
|
103 |
JavaThread* _thread; |
|
104 |
public: |
|
105 |
ThreadStateTransition(JavaThread *thread) { |
|
106 |
_thread = thread; |
|
107 |
assert(thread != NULL && thread->is_Java_thread(), "must be Java thread"); |
|
108 |
} |
|
109 |
||
110 |
// Change threadstate in a manner, so safepoint can detect changes. |
|
111 |
// Time-critical: called on exit from every runtime routine |
|
112 |
static inline void transition(JavaThread *thread, JavaThreadState from, JavaThreadState to) { |
|
113 |
assert(from != _thread_in_Java, "use transition_from_java"); |
|
114 |
assert(from != _thread_in_native, "use transition_from_native"); |
|
115 |
assert((from & 1) == 0 && (to & 1) == 0, "odd numbers are transitions states"); |
|
116 |
assert(thread->thread_state() == from, "coming from wrong thread state"); |
|
46373
e8e9b36783f3
8166927: interfaceSupport.hpp has ancient comments about TSO
dholmes
parents:
41084
diff
changeset
|
117 |
// Change to transition state |
1 | 118 |
thread->set_thread_state((JavaThreadState)(from + 1)); |
119 |
||
46604
d409276ee40c
8183198: Factor out thread state serialization into a proper helper function
mgerdin
parents:
46373
diff
changeset
|
120 |
InterfaceSupport::serialize_thread_state(thread); |
1 | 121 |
|
47881
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
122 |
SafepointMechanism::block_if_requested(thread); |
1 | 123 |
thread->set_thread_state(to); |
124 |
||
125 |
CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops();) |
|
126 |
} |
|
127 |
||
128 |
// transition_and_fence must be used on any thread state transition |
|
129 |
// where there might not be a Java call stub on the stack, in |
|
130 |
// particular on Windows where the Structured Exception Handler is |
|
131 |
// set up in the call stub. os::write_memory_serialize_page() can |
|
132 |
// fault and we can't recover from it on Windows without a SEH in |
|
133 |
// place. |
|
134 |
static inline void transition_and_fence(JavaThread *thread, JavaThreadState from, JavaThreadState to) { |
|
135 |
assert(thread->thread_state() == from, "coming from wrong thread state"); |
|
136 |
assert((from & 1) == 0 && (to & 1) == 0, "odd numbers are transitions states"); |
|
46373
e8e9b36783f3
8166927: interfaceSupport.hpp has ancient comments about TSO
dholmes
parents:
41084
diff
changeset
|
137 |
// Change to transition state |
1 | 138 |
thread->set_thread_state((JavaThreadState)(from + 1)); |
139 |
||
46604
d409276ee40c
8183198: Factor out thread state serialization into a proper helper function
mgerdin
parents:
46373
diff
changeset
|
140 |
InterfaceSupport::serialize_thread_state_with_handler(thread); |
1 | 141 |
|
47881
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
142 |
SafepointMechanism::block_if_requested(thread); |
1 | 143 |
thread->set_thread_state(to); |
144 |
||
145 |
CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops();) |
|
146 |
} |
|
147 |
||
148 |
// Same as above, but assumes from = _thread_in_Java. This is simpler, since we |
|
149 |
// never block on entry to the VM. This will break the code, since e.g. preserve arguments |
|
150 |
// have not been setup. |
|
151 |
static inline void transition_from_java(JavaThread *thread, JavaThreadState to) { |
|
152 |
assert(thread->thread_state() == _thread_in_Java, "coming from wrong thread state"); |
|
153 |
thread->set_thread_state(to); |
|
154 |
} |
|
155 |
||
156 |
static inline void transition_from_native(JavaThread *thread, JavaThreadState to) { |
|
157 |
assert((to & 1) == 0, "odd numbers are transitions states"); |
|
158 |
assert(thread->thread_state() == _thread_in_native, "coming from wrong thread state"); |
|
46373
e8e9b36783f3
8166927: interfaceSupport.hpp has ancient comments about TSO
dholmes
parents:
41084
diff
changeset
|
159 |
// Change to transition state |
1 | 160 |
thread->set_thread_state(_thread_in_native_trans); |
161 |
||
46604
d409276ee40c
8183198: Factor out thread state serialization into a proper helper function
mgerdin
parents:
46373
diff
changeset
|
162 |
InterfaceSupport::serialize_thread_state_with_handler(thread); |
1 | 163 |
|
164 |
// We never install asynchronous exceptions when coming (back) in |
|
165 |
// to the runtime from native code because the runtime is not set |
|
166 |
// up to handle exceptions floating around at arbitrary points. |
|
47881
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
167 |
if (SafepointMechanism::poll(thread) || thread->is_suspend_after_native()) { |
1 | 168 |
JavaThread::check_safepoint_and_suspend_for_native_trans(thread); |
169 |
||
170 |
// Clear unhandled oops anywhere where we could block, even if we don't. |
|
171 |
CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops();) |
|
172 |
} |
|
173 |
||
174 |
thread->set_thread_state(to); |
|
175 |
} |
|
176 |
protected: |
|
177 |
void trans(JavaThreadState from, JavaThreadState to) { transition(_thread, from, to); } |
|
178 |
void trans_from_java(JavaThreadState to) { transition_from_java(_thread, to); } |
|
179 |
void trans_from_native(JavaThreadState to) { transition_from_native(_thread, to); } |
|
180 |
void trans_and_fence(JavaThreadState from, JavaThreadState to) { transition_and_fence(_thread, from, to); } |
|
181 |
}; |
|
182 |
||
47881
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
183 |
class ThreadInVMForHandshake : public ThreadStateTransition { |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
184 |
const JavaThreadState _original_state; |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
185 |
|
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
186 |
void transition_back() { |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
187 |
// This can be invoked from transition states and must return to the original state properly |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
188 |
assert(_thread->thread_state() == _thread_in_vm, "should only call when leaving VM after handshake"); |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
189 |
_thread->set_thread_state(_thread_in_vm_trans); |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
190 |
|
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
191 |
InterfaceSupport::serialize_thread_state(_thread); |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
192 |
|
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
193 |
SafepointMechanism::block_if_requested(_thread); |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
194 |
|
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
195 |
_thread->set_thread_state(_original_state); |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
196 |
} |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
197 |
|
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
198 |
public: |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
199 |
|
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
200 |
ThreadInVMForHandshake(JavaThread* thread) : ThreadStateTransition(thread), |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
201 |
_original_state(thread->thread_state()) { |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
202 |
|
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
203 |
if (thread->has_last_Java_frame()) { |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
204 |
thread->frame_anchor()->make_walkable(thread); |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
205 |
} |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
206 |
|
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
207 |
thread->set_thread_state(_thread_in_vm); |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
208 |
} |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
209 |
|
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
210 |
~ThreadInVMForHandshake() { |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
211 |
transition_back(); |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
212 |
} |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
213 |
|
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
214 |
}; |
1 | 215 |
|
216 |
class ThreadInVMfromJava : public ThreadStateTransition { |
|
217 |
public: |
|
218 |
ThreadInVMfromJava(JavaThread* thread) : ThreadStateTransition(thread) { |
|
219 |
trans_from_java(_thread_in_vm); |
|
220 |
} |
|
221 |
~ThreadInVMfromJava() { |
|
40926
2fd1cf3e70e9
8137035: nsk/stress/stack/stack tests got EXCEPTION_STACK_OVERFLOW on Windows 64 bit
fparain
parents:
40010
diff
changeset
|
222 |
if (_thread->stack_yellow_reserved_zone_disabled()) { |
2fd1cf3e70e9
8137035: nsk/stress/stack/stack tests got EXCEPTION_STACK_OVERFLOW on Windows 64 bit
fparain
parents:
40010
diff
changeset
|
223 |
_thread->enable_stack_yellow_reserved_zone(); |
2fd1cf3e70e9
8137035: nsk/stress/stack/stack tests got EXCEPTION_STACK_OVERFLOW on Windows 64 bit
fparain
parents:
40010
diff
changeset
|
224 |
} |
1 | 225 |
trans(_thread_in_vm, _thread_in_Java); |
226 |
// Check for pending. async. exceptions or suspends. |
|
227 |
if (_thread->has_special_runtime_exit_condition()) _thread->handle_special_runtime_exit_condition(); |
|
228 |
} |
|
229 |
}; |
|
230 |
||
231 |
||
232 |
class ThreadInVMfromUnknown { |
|
233 |
private: |
|
234 |
JavaThread* _thread; |
|
235 |
public: |
|
236 |
ThreadInVMfromUnknown() : _thread(NULL) { |
|
237 |
Thread* t = Thread::current(); |
|
238 |
if (t->is_Java_thread()) { |
|
239 |
JavaThread* t2 = (JavaThread*) t; |
|
240 |
if (t2->thread_state() == _thread_in_native) { |
|
241 |
_thread = t2; |
|
242 |
ThreadStateTransition::transition_from_native(t2, _thread_in_vm); |
|
243 |
// Used to have a HandleMarkCleaner but that is dangerous as |
|
244 |
// it could free a handle in our (indirect, nested) caller. |
|
245 |
// We expect any handles will be short lived and figure we |
|
246 |
// don't need an actual HandleMark. |
|
247 |
} |
|
248 |
} |
|
249 |
} |
|
250 |
~ThreadInVMfromUnknown() { |
|
251 |
if (_thread) { |
|
252 |
ThreadStateTransition::transition_and_fence(_thread, _thread_in_vm, _thread_in_native); |
|
253 |
} |
|
254 |
} |
|
255 |
}; |
|
256 |
||
257 |
||
258 |
class ThreadInVMfromNative : public ThreadStateTransition { |
|
259 |
public: |
|
260 |
ThreadInVMfromNative(JavaThread* thread) : ThreadStateTransition(thread) { |
|
261 |
trans_from_native(_thread_in_vm); |
|
262 |
} |
|
263 |
~ThreadInVMfromNative() { |
|
264 |
trans_and_fence(_thread_in_vm, _thread_in_native); |
|
265 |
} |
|
266 |
}; |
|
267 |
||
268 |
||
269 |
class ThreadToNativeFromVM : public ThreadStateTransition { |
|
270 |
public: |
|
271 |
ThreadToNativeFromVM(JavaThread *thread) : ThreadStateTransition(thread) { |
|
272 |
// We are leaving the VM at this point and going directly to native code. |
|
273 |
// Block, if we are in the middle of a safepoint synchronization. |
|
274 |
assert(!thread->owns_locks(), "must release all locks when leaving VM"); |
|
275 |
thread->frame_anchor()->make_walkable(thread); |
|
276 |
trans_and_fence(_thread_in_vm, _thread_in_native); |
|
277 |
// Check for pending. async. exceptions or suspends. |
|
278 |
if (_thread->has_special_runtime_exit_condition()) _thread->handle_special_runtime_exit_condition(false); |
|
279 |
} |
|
280 |
||
281 |
~ThreadToNativeFromVM() { |
|
282 |
trans_from_native(_thread_in_vm); |
|
41084
fc5db29fa08e
8164086: Checked JNI pending exception check should be cleared when returning to Java frame
dsimms
parents:
40926
diff
changeset
|
283 |
assert(!_thread->is_pending_jni_exception_check(), "Pending JNI Exception Check"); |
1 | 284 |
// We don't need to clear_walkable because it will happen automagically when we return to java |
285 |
} |
|
286 |
}; |
|
287 |
||
288 |
||
289 |
class ThreadBlockInVM : public ThreadStateTransition { |
|
290 |
public: |
|
291 |
ThreadBlockInVM(JavaThread *thread) |
|
292 |
: ThreadStateTransition(thread) { |
|
293 |
// Once we are blocked vm expects stack to be walkable |
|
294 |
thread->frame_anchor()->make_walkable(thread); |
|
295 |
trans_and_fence(_thread_in_vm, _thread_blocked); |
|
296 |
} |
|
297 |
~ThreadBlockInVM() { |
|
298 |
trans_and_fence(_thread_blocked, _thread_in_vm); |
|
299 |
// We don't need to clear_walkable because it will happen automagically when we return to java |
|
300 |
} |
|
301 |
}; |
|
302 |
||
303 |
||
304 |
// This special transition class is only used to prevent asynchronous exceptions |
|
305 |
// from being installed on vm exit in situations where we can't tolerate them. |
|
306 |
// See bugs: 4324348, 4854693, 4998314, 5040492, 5050705. |
|
307 |
class ThreadInVMfromJavaNoAsyncException : public ThreadStateTransition { |
|
308 |
public: |
|
309 |
ThreadInVMfromJavaNoAsyncException(JavaThread* thread) : ThreadStateTransition(thread) { |
|
310 |
trans_from_java(_thread_in_vm); |
|
311 |
} |
|
312 |
~ThreadInVMfromJavaNoAsyncException() { |
|
40926
2fd1cf3e70e9
8137035: nsk/stress/stack/stack tests got EXCEPTION_STACK_OVERFLOW on Windows 64 bit
fparain
parents:
40010
diff
changeset
|
313 |
if (_thread->stack_yellow_reserved_zone_disabled()) { |
2fd1cf3e70e9
8137035: nsk/stress/stack/stack tests got EXCEPTION_STACK_OVERFLOW on Windows 64 bit
fparain
parents:
40010
diff
changeset
|
314 |
_thread->enable_stack_yellow_reserved_zone(); |
2fd1cf3e70e9
8137035: nsk/stress/stack/stack tests got EXCEPTION_STACK_OVERFLOW on Windows 64 bit
fparain
parents:
40010
diff
changeset
|
315 |
} |
1 | 316 |
trans(_thread_in_vm, _thread_in_Java); |
317 |
// NOTE: We do not check for pending. async. exceptions. |
|
318 |
// If we did and moved the pending async exception over into the |
|
319 |
// pending exception field, we would need to deopt (currently C2 |
|
320 |
// only). However, to do so would require that we transition back |
|
321 |
// to the _thread_in_vm state. Instead we postpone the handling of |
|
322 |
// the async exception. |
|
323 |
||
40926
2fd1cf3e70e9
8137035: nsk/stress/stack/stack tests got EXCEPTION_STACK_OVERFLOW on Windows 64 bit
fparain
parents:
40010
diff
changeset
|
324 |
|
1 | 325 |
// Check for pending. suspends only. |
326 |
if (_thread->has_special_runtime_exit_condition()) |
|
327 |
_thread->handle_special_runtime_exit_condition(false); |
|
328 |
} |
|
329 |
}; |
|
330 |
||
331 |
// Debug class instantiated in JRT_ENTRY and ITR_ENTRY macro. |
|
332 |
// Can be used to verify properties on enter/exit of the VM. |
|
333 |
||
334 |
#ifdef ASSERT |
|
335 |
class VMEntryWrapper { |
|
336 |
public: |
|
49449
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47881
diff
changeset
|
337 |
VMEntryWrapper(); |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47881
diff
changeset
|
338 |
~VMEntryWrapper(); |
1 | 339 |
}; |
340 |
||
341 |
||
342 |
class VMNativeEntryWrapper { |
|
343 |
public: |
|
344 |
VMNativeEntryWrapper() { |
|
345 |
if (GCALotAtAllSafepoints) InterfaceSupport::check_gc_alot(); |
|
346 |
} |
|
347 |
||
348 |
~VMNativeEntryWrapper() { |
|
349 |
if (GCALotAtAllSafepoints) InterfaceSupport::check_gc_alot(); |
|
350 |
} |
|
351 |
}; |
|
352 |
||
353 |
#endif |
|
354 |
||
355 |
||
356 |
// VM-internal runtime interface support |
|
357 |
||
49594
898ef81cbc0e
8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents:
49449
diff
changeset
|
358 |
// Definitions for JRT (Java (Compiler/Shared) Runtime) |
898ef81cbc0e
8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents:
49449
diff
changeset
|
359 |
|
898ef81cbc0e
8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents:
49449
diff
changeset
|
360 |
// JRT_LEAF currently can be called from either _thread_in_Java or |
898ef81cbc0e
8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents:
49449
diff
changeset
|
361 |
// _thread_in_native mode. In _thread_in_native, it is ok |
898ef81cbc0e
8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents:
49449
diff
changeset
|
362 |
// for another thread to trigger GC. The rest of the JRT_LEAF |
898ef81cbc0e
8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents:
49449
diff
changeset
|
363 |
// rules apply. |
898ef81cbc0e
8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents:
49449
diff
changeset
|
364 |
class JRTLeafVerifier : public NoSafepointVerifier { |
898ef81cbc0e
8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents:
49449
diff
changeset
|
365 |
static bool should_verify_GC(); |
898ef81cbc0e
8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents:
49449
diff
changeset
|
366 |
public: |
898ef81cbc0e
8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents:
49449
diff
changeset
|
367 |
#ifdef ASSERT |
898ef81cbc0e
8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents:
49449
diff
changeset
|
368 |
JRTLeafVerifier(); |
898ef81cbc0e
8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents:
49449
diff
changeset
|
369 |
~JRTLeafVerifier(); |
898ef81cbc0e
8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents:
49449
diff
changeset
|
370 |
#else |
898ef81cbc0e
8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents:
49449
diff
changeset
|
371 |
JRTLeafVerifier() {} |
898ef81cbc0e
8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents:
49449
diff
changeset
|
372 |
~JRTLeafVerifier() {} |
898ef81cbc0e
8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents:
49449
diff
changeset
|
373 |
#endif |
898ef81cbc0e
8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents:
49449
diff
changeset
|
374 |
}; |
898ef81cbc0e
8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents:
49449
diff
changeset
|
375 |
|
1 | 376 |
#ifdef ASSERT |
377 |
||
378 |
class RuntimeHistogramElement : public HistogramElement { |
|
379 |
public: |
|
380 |
RuntimeHistogramElement(const char* name); |
|
381 |
}; |
|
382 |
||
383 |
#define TRACE_CALL(result_type, header) \ |
|
384 |
InterfaceSupport::_number_of_calls++; \ |
|
385 |
if (CountRuntimeCalls) { \ |
|
386 |
static RuntimeHistogramElement* e = new RuntimeHistogramElement(#header); \ |
|
387 |
if (e != NULL) e->increment_count(); \ |
|
388 |
} |
|
389 |
#else |
|
390 |
#define TRACE_CALL(result_type, header) \ |
|
391 |
/* do nothing */ |
|
392 |
#endif |
|
393 |
||
394 |
||
395 |
// LEAF routines do not lock, GC or throw exceptions |
|
396 |
||
10969
3ecf25293e5a
7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents:
10565
diff
changeset
|
397 |
#define VM_LEAF_BASE(result_type, header) \ |
1 | 398 |
TRACE_CALL(result_type, header) \ |
399 |
debug_only(NoHandleMark __hm;) \ |
|
11961
0abd4cd26e5a
7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents:
10969
diff
changeset
|
400 |
os::verify_stack_alignment(); \ |
1 | 401 |
/* begin of body */ |
402 |
||
36086 | 403 |
#define VM_ENTRY_BASE_FROM_LEAF(result_type, header, thread) \ |
404 |
TRACE_CALL(result_type, header) \ |
|
405 |
debug_only(ResetNoHandleMark __rnhm;) \ |
|
406 |
HandleMarkCleaner __hm(thread); \ |
|
407 |
Thread* THREAD = thread; \ |
|
408 |
os::verify_stack_alignment(); \ |
|
409 |
/* begin of body */ |
|
410 |
||
1 | 411 |
|
412 |
// ENTRY routines may lock, GC and throw exceptions |
|
413 |
||
10969
3ecf25293e5a
7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents:
10565
diff
changeset
|
414 |
#define VM_ENTRY_BASE(result_type, header, thread) \ |
1 | 415 |
TRACE_CALL(result_type, header) \ |
416 |
HandleMarkCleaner __hm(thread); \ |
|
417 |
Thread* THREAD = thread; \ |
|
11961
0abd4cd26e5a
7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents:
10969
diff
changeset
|
418 |
os::verify_stack_alignment(); \ |
1 | 419 |
/* begin of body */ |
420 |
||
421 |
||
422 |
// QUICK_ENTRY routines behave like ENTRY but without a handle mark |
|
423 |
||
10969
3ecf25293e5a
7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents:
10565
diff
changeset
|
424 |
#define VM_QUICK_ENTRY_BASE(result_type, header, thread) \ |
1 | 425 |
TRACE_CALL(result_type, header) \ |
426 |
debug_only(NoHandleMark __hm;) \ |
|
427 |
Thread* THREAD = thread; \ |
|
11961
0abd4cd26e5a
7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents:
10969
diff
changeset
|
428 |
os::verify_stack_alignment(); \ |
1 | 429 |
/* begin of body */ |
430 |
||
431 |
||
432 |
// Definitions for IRT (Interpreter Runtime) |
|
433 |
// (thread is an argument passed in to all these routines) |
|
434 |
||
435 |
#define IRT_ENTRY(result_type, header) \ |
|
436 |
result_type header { \ |
|
437 |
ThreadInVMfromJava __tiv(thread); \ |
|
10969
3ecf25293e5a
7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents:
10565
diff
changeset
|
438 |
VM_ENTRY_BASE(result_type, header, thread) \ |
1 | 439 |
debug_only(VMEntryWrapper __vew;) |
440 |
||
441 |
||
442 |
#define IRT_LEAF(result_type, header) \ |
|
443 |
result_type header { \ |
|
10969
3ecf25293e5a
7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents:
10565
diff
changeset
|
444 |
VM_LEAF_BASE(result_type, header) \ |
35492
c8c0273e6b91
8146690: Make all classes in GC follow the naming convention.
david
parents:
34633
diff
changeset
|
445 |
debug_only(NoSafepointVerifier __nspv(true);) |
1 | 446 |
|
447 |
||
448 |
#define IRT_ENTRY_NO_ASYNC(result_type, header) \ |
|
449 |
result_type header { \ |
|
450 |
ThreadInVMfromJavaNoAsyncException __tiv(thread); \ |
|
10969
3ecf25293e5a
7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents:
10565
diff
changeset
|
451 |
VM_ENTRY_BASE(result_type, header, thread) \ |
1 | 452 |
debug_only(VMEntryWrapper __vew;) |
453 |
||
454 |
#define IRT_END } |
|
455 |
||
456 |
#define JRT_ENTRY(result_type, header) \ |
|
457 |
result_type header { \ |
|
458 |
ThreadInVMfromJava __tiv(thread); \ |
|
10969
3ecf25293e5a
7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents:
10565
diff
changeset
|
459 |
VM_ENTRY_BASE(result_type, header, thread) \ |
1 | 460 |
debug_only(VMEntryWrapper __vew;) |
461 |
||
462 |
||
463 |
#define JRT_LEAF(result_type, header) \ |
|
464 |
result_type header { \ |
|
10969
3ecf25293e5a
7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents:
10565
diff
changeset
|
465 |
VM_LEAF_BASE(result_type, header) \ |
35492
c8c0273e6b91
8146690: Make all classes in GC follow the naming convention.
david
parents:
34633
diff
changeset
|
466 |
debug_only(JRTLeafVerifier __jlv;) |
1 | 467 |
|
468 |
||
469 |
#define JRT_ENTRY_NO_ASYNC(result_type, header) \ |
|
470 |
result_type header { \ |
|
471 |
ThreadInVMfromJavaNoAsyncException __tiv(thread); \ |
|
10969
3ecf25293e5a
7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents:
10565
diff
changeset
|
472 |
VM_ENTRY_BASE(result_type, header, thread) \ |
1 | 473 |
debug_only(VMEntryWrapper __vew;) |
474 |
||
475 |
// Same as JRT Entry but allows for return value after the safepoint |
|
476 |
// to get back into Java from the VM |
|
477 |
#define JRT_BLOCK_ENTRY(result_type, header) \ |
|
478 |
result_type header { \ |
|
479 |
TRACE_CALL(result_type, header) \ |
|
480 |
HandleMarkCleaner __hm(thread); |
|
481 |
||
482 |
#define JRT_BLOCK \ |
|
483 |
{ \ |
|
484 |
ThreadInVMfromJava __tiv(thread); \ |
|
485 |
Thread* THREAD = thread; \ |
|
486 |
debug_only(VMEntryWrapper __vew;) |
|
487 |
||
29070 | 488 |
#define JRT_BLOCK_NO_ASYNC \ |
489 |
{ \ |
|
490 |
ThreadInVMfromJavaNoAsyncException __tiv(thread); \ |
|
491 |
Thread* THREAD = thread; \ |
|
492 |
debug_only(VMEntryWrapper __vew;) |
|
493 |
||
1 | 494 |
#define JRT_BLOCK_END } |
495 |
||
496 |
#define JRT_END } |
|
497 |
||
498 |
// Definitions for JNI |
|
499 |
||
500 |
#define JNI_ENTRY(result_type, header) \ |
|
501 |
JNI_ENTRY_NO_PRESERVE(result_type, header) \ |
|
502 |
WeakPreserveExceptionMark __wem(thread); |
|
503 |
||
36551 | 504 |
#define JNI_ENTRY_NO_PRESERVE(result_type, header) \ |
1 | 505 |
extern "C" { \ |
36551 | 506 |
result_type JNICALL header { \ |
1 | 507 |
JavaThread* thread=JavaThread::thread_from_jni_environment(env); \ |
508 |
assert( !VerifyJNIEnvThread || (thread == Thread::current()), "JNIEnv is only valid in same thread"); \ |
|
509 |
ThreadInVMfromNative __tiv(thread); \ |
|
510 |
debug_only(VMNativeEntryWrapper __vew;) \ |
|
10969
3ecf25293e5a
7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents:
10565
diff
changeset
|
511 |
VM_ENTRY_BASE(result_type, header, thread) |
1 | 512 |
|
513 |
||
514 |
// Ensure that the VMNativeEntryWrapper constructor, which can cause |
|
10969
3ecf25293e5a
7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents:
10565
diff
changeset
|
515 |
// a GC, is called outside the NoHandleMark (set via VM_QUICK_ENTRY_BASE). |
1 | 516 |
#define JNI_QUICK_ENTRY(result_type, header) \ |
517 |
extern "C" { \ |
|
36551 | 518 |
result_type JNICALL header { \ |
1 | 519 |
JavaThread* thread=JavaThread::thread_from_jni_environment(env); \ |
520 |
assert( !VerifyJNIEnvThread || (thread == Thread::current()), "JNIEnv is only valid in same thread"); \ |
|
521 |
ThreadInVMfromNative __tiv(thread); \ |
|
522 |
debug_only(VMNativeEntryWrapper __vew;) \ |
|
10969
3ecf25293e5a
7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents:
10565
diff
changeset
|
523 |
VM_QUICK_ENTRY_BASE(result_type, header, thread) |
1 | 524 |
|
525 |
||
526 |
#define JNI_LEAF(result_type, header) \ |
|
527 |
extern "C" { \ |
|
36551 | 528 |
result_type JNICALL header { \ |
1 | 529 |
JavaThread* thread=JavaThread::thread_from_jni_environment(env); \ |
530 |
assert( !VerifyJNIEnvThread || (thread == Thread::current()), "JNIEnv is only valid in same thread"); \ |
|
10969
3ecf25293e5a
7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents:
10565
diff
changeset
|
531 |
VM_LEAF_BASE(result_type, header) |
1 | 532 |
|
533 |
||
534 |
// Close the routine and the extern "C" |
|
535 |
#define JNI_END } } |
|
536 |
||
537 |
||
538 |
||
539 |
// Definitions for JVM |
|
540 |
||
541 |
#define JVM_ENTRY(result_type, header) \ |
|
542 |
extern "C" { \ |
|
543 |
result_type JNICALL header { \ |
|
544 |
JavaThread* thread=JavaThread::thread_from_jni_environment(env); \ |
|
545 |
ThreadInVMfromNative __tiv(thread); \ |
|
546 |
debug_only(VMNativeEntryWrapper __vew;) \ |
|
10969
3ecf25293e5a
7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents:
10565
diff
changeset
|
547 |
VM_ENTRY_BASE(result_type, header, thread) |
1 | 548 |
|
549 |
||
550 |
#define JVM_ENTRY_NO_ENV(result_type, header) \ |
|
551 |
extern "C" { \ |
|
552 |
result_type JNICALL header { \ |
|
34633
2a6c7c7b30a7
8132510: Replace ThreadLocalStorage with compiler/language-based thread-local variables
dholmes
parents:
34285
diff
changeset
|
553 |
JavaThread* thread = JavaThread::current(); \ |
1 | 554 |
ThreadInVMfromNative __tiv(thread); \ |
555 |
debug_only(VMNativeEntryWrapper __vew;) \ |
|
10969
3ecf25293e5a
7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents:
10565
diff
changeset
|
556 |
VM_ENTRY_BASE(result_type, header, thread) |
1 | 557 |
|
558 |
||
559 |
#define JVM_QUICK_ENTRY(result_type, header) \ |
|
560 |
extern "C" { \ |
|
561 |
result_type JNICALL header { \ |
|
562 |
JavaThread* thread=JavaThread::thread_from_jni_environment(env); \ |
|
563 |
ThreadInVMfromNative __tiv(thread); \ |
|
564 |
debug_only(VMNativeEntryWrapper __vew;) \ |
|
10969
3ecf25293e5a
7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents:
10565
diff
changeset
|
565 |
VM_QUICK_ENTRY_BASE(result_type, header, thread) |
1 | 566 |
|
567 |
||
568 |
#define JVM_LEAF(result_type, header) \ |
|
569 |
extern "C" { \ |
|
570 |
result_type JNICALL header { \ |
|
571 |
VM_Exit::block_if_vm_exited(); \ |
|
10969
3ecf25293e5a
7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents:
10565
diff
changeset
|
572 |
VM_LEAF_BASE(result_type, header) |
1 | 573 |
|
574 |
||
36086 | 575 |
#define JVM_ENTRY_FROM_LEAF(env, result_type, header) \ |
576 |
{ { \ |
|
577 |
JavaThread* thread=JavaThread::thread_from_jni_environment(env); \ |
|
578 |
ThreadInVMfromNative __tiv(thread); \ |
|
579 |
debug_only(VMNativeEntryWrapper __vew;) \ |
|
580 |
VM_ENTRY_BASE_FROM_LEAF(result_type, header, thread) |
|
581 |
||
582 |
||
1 | 583 |
#define JVM_END } } |
7397 | 584 |
|
49449
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47881
diff
changeset
|
585 |
#endif // SHARE_VM_RUNTIME_INTERFACESUPPORT_INLINE_HPP |