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