author | rehn |
Fri, 29 Nov 2019 12:09:25 +0100 | |
changeset 59325 | 3636bab5e81e |
parent 58527 | f9cc0141574c |
child 58679 | 9c3209ff7550 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
52877
diff
changeset
|
2 |
* Copyright (c) 1997, 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:
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 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
52877
diff
changeset
|
25 |
#ifndef SHARE_RUNTIME_INTERFACESUPPORT_INLINE_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
52877
diff
changeset
|
26 |
#define SHARE_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" |
52877
9e041366c764
8214850: Rename vm_operations.?pp files to vmOperations.?pp files
tschatzl
parents:
52460
diff
changeset
|
35 |
#include "runtime/vmOperations.hpp" |
7397 | 36 |
#include "utilities/globalDefinitions.hpp" |
54347
235883996bc7
8221698: Remove redundant includes from popular header files
iklam
parents:
54323
diff
changeset
|
37 |
#include "utilities/histogram.hpp" |
40010 | 38 |
#include "utilities/macros.hpp" |
7397 | 39 |
#include "utilities/preserveException.hpp" |
40 |
||
1 | 41 |
// Wrapper for all entry points to the virtual machine. |
42 |
||
10969
3ecf25293e5a
7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents:
10565
diff
changeset
|
43 |
// 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
|
44 |
// 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
|
45 |
// the VM and perform checks upon leave of the VM. |
1 | 46 |
|
47 |
||
48 |
class InterfaceSupport: AllStatic { |
|
49 |
# ifdef ASSERT |
|
50 |
public: |
|
51 |
static long _scavenge_alot_counter; |
|
52 |
static long _fullgc_alot_counter; |
|
53 |
static long _number_of_calls; |
|
54 |
static long _fullgc_alot_invocation; |
|
55 |
||
56 |
// Helper methods used to implement +ScavengeALot and +FullGCALot |
|
57 |
static void check_gc_alot() { if (ScavengeALot || FullGCALot) gc_alot(); } |
|
58 |
static void gc_alot(); |
|
59 |
||
60 |
static void walk_stack_from(vframe* start_vf); |
|
61 |
static void walk_stack(); |
|
62 |
||
63 |
static void zombieAll(); |
|
64 |
static void deoptimizeAll(); |
|
65 |
static void verify_stack(); |
|
66 |
static void verify_last_frame(); |
|
67 |
# endif |
|
68 |
}; |
|
69 |
||
70 |
||
71 |
// Basic class for all thread transition classes. |
|
72 |
||
73 |
class ThreadStateTransition : public StackObj { |
|
74 |
protected: |
|
75 |
JavaThread* _thread; |
|
76 |
public: |
|
77 |
ThreadStateTransition(JavaThread *thread) { |
|
78 |
_thread = thread; |
|
79 |
assert(thread != NULL && thread->is_Java_thread(), "must be Java thread"); |
|
80 |
} |
|
81 |
||
82 |
// Change threadstate in a manner, so safepoint can detect changes. |
|
83 |
// Time-critical: called on exit from every runtime routine |
|
84 |
static inline void transition(JavaThread *thread, JavaThreadState from, JavaThreadState to) { |
|
85 |
assert(from != _thread_in_Java, "use transition_from_java"); |
|
86 |
assert(from != _thread_in_native, "use transition_from_native"); |
|
87 |
assert((from & 1) == 0 && (to & 1) == 0, "odd numbers are transitions states"); |
|
88 |
assert(thread->thread_state() == from, "coming from wrong thread state"); |
|
57745 | 89 |
|
90 |
// Check NoSafepointVerifier |
|
91 |
// This also clears unhandled oops if CheckUnhandledOops is used. |
|
92 |
thread->check_possible_safepoint(); |
|
93 |
||
54495
941db9c0b5b5
8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents:
54347
diff
changeset
|
94 |
// Change to transition state and ensure it is seen by the VM thread. |
941db9c0b5b5
8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents:
54347
diff
changeset
|
95 |
thread->set_thread_state_fence((JavaThreadState)(from + 1)); |
1 | 96 |
|
47881
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
97 |
SafepointMechanism::block_if_requested(thread); |
1 | 98 |
thread->set_thread_state(to); |
99 |
} |
|
100 |
||
101 |
// Same as above, but assumes from = _thread_in_Java. This is simpler, since we |
|
102 |
// never block on entry to the VM. This will break the code, since e.g. preserve arguments |
|
103 |
// have not been setup. |
|
104 |
static inline void transition_from_java(JavaThread *thread, JavaThreadState to) { |
|
105 |
assert(thread->thread_state() == _thread_in_Java, "coming from wrong thread state"); |
|
106 |
thread->set_thread_state(to); |
|
107 |
} |
|
108 |
||
109 |
static inline void transition_from_native(JavaThread *thread, JavaThreadState to) { |
|
110 |
assert((to & 1) == 0, "odd numbers are transitions states"); |
|
111 |
assert(thread->thread_state() == _thread_in_native, "coming from wrong thread state"); |
|
54495
941db9c0b5b5
8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents:
54347
diff
changeset
|
112 |
// Change to transition state and ensure it is seen by the VM thread. |
941db9c0b5b5
8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents:
54347
diff
changeset
|
113 |
thread->set_thread_state_fence(_thread_in_native_trans); |
1 | 114 |
|
115 |
// We never install asynchronous exceptions when coming (back) in |
|
116 |
// to the runtime from native code because the runtime is not set |
|
117 |
// up to handle exceptions floating around at arbitrary points. |
|
52450 | 118 |
if (SafepointMechanism::should_block(thread) || thread->is_suspend_after_native()) { |
1 | 119 |
JavaThread::check_safepoint_and_suspend_for_native_trans(thread); |
120 |
} |
|
121 |
||
122 |
thread->set_thread_state(to); |
|
123 |
} |
|
124 |
protected: |
|
125 |
void trans(JavaThreadState from, JavaThreadState to) { transition(_thread, from, to); } |
|
126 |
void trans_from_java(JavaThreadState to) { transition_from_java(_thread, to); } |
|
127 |
void trans_from_native(JavaThreadState to) { transition_from_native(_thread, to); } |
|
128 |
}; |
|
129 |
||
47881
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
130 |
class ThreadInVMForHandshake : public ThreadStateTransition { |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
131 |
const JavaThreadState _original_state; |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
132 |
|
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
133 |
void transition_back() { |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
134 |
// 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
|
135 |
assert(_thread->thread_state() == _thread_in_vm, "should only call when leaving VM after handshake"); |
54495
941db9c0b5b5
8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents:
54347
diff
changeset
|
136 |
// Change to transition state and ensure it is seen by the VM thread. |
941db9c0b5b5
8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents:
54347
diff
changeset
|
137 |
_thread->set_thread_state_fence(_thread_in_vm_trans); |
47881
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
138 |
|
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
139 |
SafepointMechanism::block_if_requested(_thread); |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
140 |
|
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
141 |
_thread->set_thread_state(_original_state); |
54898
17926213de55
8223572: ~ThreadInVMForHandshake() should call handle_special_runtime_exit_condition()
rrich
parents:
54523
diff
changeset
|
142 |
|
17926213de55
8223572: ~ThreadInVMForHandshake() should call handle_special_runtime_exit_condition()
rrich
parents:
54523
diff
changeset
|
143 |
if (_original_state != _thread_blocked_trans && _original_state != _thread_in_vm_trans && |
17926213de55
8223572: ~ThreadInVMForHandshake() should call handle_special_runtime_exit_condition()
rrich
parents:
54523
diff
changeset
|
144 |
_thread->has_special_runtime_exit_condition()) { |
17926213de55
8223572: ~ThreadInVMForHandshake() should call handle_special_runtime_exit_condition()
rrich
parents:
54523
diff
changeset
|
145 |
_thread->handle_special_runtime_exit_condition( |
17926213de55
8223572: ~ThreadInVMForHandshake() should call handle_special_runtime_exit_condition()
rrich
parents:
54523
diff
changeset
|
146 |
!_thread->is_at_poll_safepoint() && (_original_state != _thread_in_native_trans)); |
17926213de55
8223572: ~ThreadInVMForHandshake() should call handle_special_runtime_exit_condition()
rrich
parents:
54523
diff
changeset
|
147 |
} |
47881
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
148 |
} |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
149 |
|
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
150 |
public: |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
151 |
|
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
152 |
ThreadInVMForHandshake(JavaThread* thread) : ThreadStateTransition(thread), |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
153 |
_original_state(thread->thread_state()) { |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
154 |
|
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
155 |
if (thread->has_last_Java_frame()) { |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
156 |
thread->frame_anchor()->make_walkable(thread); |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
157 |
} |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
158 |
|
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
159 |
thread->set_thread_state(_thread_in_vm); |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
160 |
} |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
161 |
|
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
162 |
~ThreadInVMForHandshake() { |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
163 |
transition_back(); |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
164 |
} |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
165 |
|
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
166 |
}; |
1 | 167 |
|
168 |
class ThreadInVMfromJava : public ThreadStateTransition { |
|
169 |
public: |
|
170 |
ThreadInVMfromJava(JavaThread* thread) : ThreadStateTransition(thread) { |
|
171 |
trans_from_java(_thread_in_vm); |
|
172 |
} |
|
173 |
~ThreadInVMfromJava() { |
|
40926
2fd1cf3e70e9
8137035: nsk/stress/stack/stack tests got EXCEPTION_STACK_OVERFLOW on Windows 64 bit
fparain
parents:
40010
diff
changeset
|
174 |
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
|
175 |
_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
|
176 |
} |
1 | 177 |
trans(_thread_in_vm, _thread_in_Java); |
178 |
// Check for pending. async. exceptions or suspends. |
|
179 |
if (_thread->has_special_runtime_exit_condition()) _thread->handle_special_runtime_exit_condition(); |
|
180 |
} |
|
181 |
}; |
|
182 |
||
183 |
||
184 |
class ThreadInVMfromUnknown { |
|
185 |
JavaThread* _thread; |
|
186 |
public: |
|
187 |
ThreadInVMfromUnknown() : _thread(NULL) { |
|
188 |
Thread* t = Thread::current(); |
|
189 |
if (t->is_Java_thread()) { |
|
190 |
JavaThread* t2 = (JavaThread*) t; |
|
191 |
if (t2->thread_state() == _thread_in_native) { |
|
192 |
_thread = t2; |
|
193 |
ThreadStateTransition::transition_from_native(t2, _thread_in_vm); |
|
194 |
// Used to have a HandleMarkCleaner but that is dangerous as |
|
195 |
// it could free a handle in our (indirect, nested) caller. |
|
196 |
// We expect any handles will be short lived and figure we |
|
197 |
// don't need an actual HandleMark. |
|
198 |
} |
|
199 |
} |
|
200 |
} |
|
201 |
~ThreadInVMfromUnknown() { |
|
202 |
if (_thread) { |
|
54495
941db9c0b5b5
8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents:
54347
diff
changeset
|
203 |
ThreadStateTransition::transition(_thread, _thread_in_vm, _thread_in_native); |
1 | 204 |
} |
205 |
} |
|
206 |
}; |
|
207 |
||
208 |
||
209 |
class ThreadInVMfromNative : public ThreadStateTransition { |
|
210 |
public: |
|
211 |
ThreadInVMfromNative(JavaThread* thread) : ThreadStateTransition(thread) { |
|
212 |
trans_from_native(_thread_in_vm); |
|
213 |
} |
|
214 |
~ThreadInVMfromNative() { |
|
54495
941db9c0b5b5
8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents:
54347
diff
changeset
|
215 |
trans(_thread_in_vm, _thread_in_native); |
1 | 216 |
} |
217 |
}; |
|
218 |
||
219 |
||
220 |
class ThreadToNativeFromVM : public ThreadStateTransition { |
|
221 |
public: |
|
222 |
ThreadToNativeFromVM(JavaThread *thread) : ThreadStateTransition(thread) { |
|
223 |
// We are leaving the VM at this point and going directly to native code. |
|
224 |
// Block, if we are in the middle of a safepoint synchronization. |
|
225 |
assert(!thread->owns_locks(), "must release all locks when leaving VM"); |
|
226 |
thread->frame_anchor()->make_walkable(thread); |
|
54495
941db9c0b5b5
8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents:
54347
diff
changeset
|
227 |
trans(_thread_in_vm, _thread_in_native); |
1 | 228 |
// Check for pending. async. exceptions or suspends. |
229 |
if (_thread->has_special_runtime_exit_condition()) _thread->handle_special_runtime_exit_condition(false); |
|
230 |
} |
|
231 |
||
232 |
~ThreadToNativeFromVM() { |
|
233 |
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
|
234 |
assert(!_thread->is_pending_jni_exception_check(), "Pending JNI Exception Check"); |
1 | 235 |
// We don't need to clear_walkable because it will happen automagically when we return to java |
236 |
} |
|
237 |
}; |
|
238 |
||
239 |
||
240 |
class ThreadBlockInVM : public ThreadStateTransition { |
|
241 |
public: |
|
242 |
ThreadBlockInVM(JavaThread *thread) |
|
243 |
: ThreadStateTransition(thread) { |
|
244 |
// Once we are blocked vm expects stack to be walkable |
|
245 |
thread->frame_anchor()->make_walkable(thread); |
|
54495
941db9c0b5b5
8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents:
54347
diff
changeset
|
246 |
trans(_thread_in_vm, _thread_blocked); |
1 | 247 |
} |
248 |
~ThreadBlockInVM() { |
|
54495
941db9c0b5b5
8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents:
54347
diff
changeset
|
249 |
trans(_thread_blocked, _thread_in_vm); |
54323 | 250 |
OrderAccess::cross_modify_fence(); |
1 | 251 |
// We don't need to clear_walkable because it will happen automagically when we return to java |
252 |
} |
|
253 |
}; |
|
254 |
||
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53244
diff
changeset
|
255 |
// Unlike ThreadBlockInVM, this class is designed to avoid certain deadlock scenarios while making |
57840 | 256 |
// transitions inside class Mutex in cases where we need to block for a safepoint or handshake. It |
257 |
// receives an extra argument compared to ThreadBlockInVM, the address of a pointer to the mutex we |
|
258 |
// are trying to acquire. This will be used to access and release the mutex if needed to avoid |
|
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53244
diff
changeset
|
259 |
// said deadlocks. |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53244
diff
changeset
|
260 |
// It works like ThreadBlockInVM but differs from it in two ways: |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53244
diff
changeset
|
261 |
// - When transitioning in (constructor), it checks for safepoints without blocking, i.e., calls |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53244
diff
changeset
|
262 |
// back if needed to allow a pending safepoint to continue but does not block in it. |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53244
diff
changeset
|
263 |
// - When transitioning back (destructor), if there is a pending safepoint or handshake it releases |
57840 | 264 |
// the mutex that is only partially acquired. |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53244
diff
changeset
|
265 |
class ThreadBlockInVMWithDeadlockCheck : public ThreadStateTransition { |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53244
diff
changeset
|
266 |
private: |
57840 | 267 |
Mutex** _in_flight_mutex_addr; |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53244
diff
changeset
|
268 |
|
57840 | 269 |
void release_mutex() { |
270 |
assert(_in_flight_mutex_addr != NULL, "_in_flight_mutex_addr should have been set on constructor"); |
|
271 |
Mutex* in_flight_mutex = *_in_flight_mutex_addr; |
|
272 |
if (in_flight_mutex != NULL) { |
|
273 |
in_flight_mutex->release_for_safepoint(); |
|
274 |
*_in_flight_mutex_addr = NULL; |
|
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53244
diff
changeset
|
275 |
} |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53244
diff
changeset
|
276 |
} |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53244
diff
changeset
|
277 |
public: |
57840 | 278 |
ThreadBlockInVMWithDeadlockCheck(JavaThread* thread, Mutex** in_flight_mutex_addr) |
279 |
: ThreadStateTransition(thread), _in_flight_mutex_addr(in_flight_mutex_addr) { |
|
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53244
diff
changeset
|
280 |
// Once we are blocked vm expects stack to be walkable |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53244
diff
changeset
|
281 |
thread->frame_anchor()->make_walkable(thread); |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53244
diff
changeset
|
282 |
|
53775 | 283 |
// All unsafe states are treated the same by the VMThread |
284 |
// so we can skip the _thread_in_vm_trans state here. Since |
|
285 |
// we don't read poll, it's enough to order the stores. |
|
286 |
OrderAccess::storestore(); |
|
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53244
diff
changeset
|
287 |
|
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53244
diff
changeset
|
288 |
thread->set_thread_state(_thread_blocked); |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53244
diff
changeset
|
289 |
} |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53244
diff
changeset
|
290 |
~ThreadBlockInVMWithDeadlockCheck() { |
54495
941db9c0b5b5
8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents:
54347
diff
changeset
|
291 |
// Change to transition state and ensure it is seen by the VM thread. |
941db9c0b5b5
8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents:
54347
diff
changeset
|
292 |
_thread->set_thread_state_fence((JavaThreadState)(_thread_blocked_trans)); |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53244
diff
changeset
|
293 |
|
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53244
diff
changeset
|
294 |
if (SafepointMechanism::should_block(_thread)) { |
57840 | 295 |
release_mutex(); |
53775 | 296 |
SafepointMechanism::block_if_requested(_thread); |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53244
diff
changeset
|
297 |
} |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53244
diff
changeset
|
298 |
|
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53244
diff
changeset
|
299 |
_thread->set_thread_state(_thread_in_vm); |
54323 | 300 |
OrderAccess::cross_modify_fence(); |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53244
diff
changeset
|
301 |
} |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53244
diff
changeset
|
302 |
}; |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
53244
diff
changeset
|
303 |
|
1 | 304 |
|
305 |
// This special transition class is only used to prevent asynchronous exceptions |
|
306 |
// from being installed on vm exit in situations where we can't tolerate them. |
|
307 |
// See bugs: 4324348, 4854693, 4998314, 5040492, 5050705. |
|
308 |
class ThreadInVMfromJavaNoAsyncException : public ThreadStateTransition { |
|
309 |
public: |
|
310 |
ThreadInVMfromJavaNoAsyncException(JavaThread* thread) : ThreadStateTransition(thread) { |
|
311 |
trans_from_java(_thread_in_vm); |
|
312 |
} |
|
313 |
~ThreadInVMfromJavaNoAsyncException() { |
|
40926
2fd1cf3e70e9
8137035: nsk/stress/stack/stack tests got EXCEPTION_STACK_OVERFLOW on Windows 64 bit
fparain
parents:
40010
diff
changeset
|
314 |
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
|
315 |
_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
|
316 |
} |
1 | 317 |
trans(_thread_in_vm, _thread_in_Java); |
318 |
// NOTE: We do not check for pending. async. exceptions. |
|
319 |
// If we did and moved the pending async exception over into the |
|
320 |
// pending exception field, we would need to deopt (currently C2 |
|
321 |
// only). However, to do so would require that we transition back |
|
322 |
// to the _thread_in_vm state. Instead we postpone the handling of |
|
323 |
// the async exception. |
|
324 |
||
40926
2fd1cf3e70e9
8137035: nsk/stress/stack/stack tests got EXCEPTION_STACK_OVERFLOW on Windows 64 bit
fparain
parents:
40010
diff
changeset
|
325 |
|
1 | 326 |
// Check for pending. suspends only. |
327 |
if (_thread->has_special_runtime_exit_condition()) |
|
328 |
_thread->handle_special_runtime_exit_condition(false); |
|
329 |
} |
|
330 |
}; |
|
331 |
||
57603
f9d9bed12d1a
8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents:
54898
diff
changeset
|
332 |
// Debug class instantiated in JRT_ENTRY macro. |
1 | 333 |
// Can be used to verify properties on enter/exit of the VM. |
334 |
||
335 |
#ifdef ASSERT |
|
336 |
class VMEntryWrapper { |
|
337 |
public: |
|
49449
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47881
diff
changeset
|
338 |
VMEntryWrapper(); |
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47881
diff
changeset
|
339 |
~VMEntryWrapper(); |
1 | 340 |
}; |
341 |
||
342 |
||
343 |
class VMNativeEntryWrapper { |
|
344 |
public: |
|
57603
f9d9bed12d1a
8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents:
54898
diff
changeset
|
345 |
VMNativeEntryWrapper(); |
f9d9bed12d1a
8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents:
54898
diff
changeset
|
346 |
~VMNativeEntryWrapper(); |
1 | 347 |
}; |
348 |
||
349 |
class RuntimeHistogramElement : public HistogramElement { |
|
350 |
public: |
|
351 |
RuntimeHistogramElement(const char* name); |
|
352 |
}; |
|
57603
f9d9bed12d1a
8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents:
54898
diff
changeset
|
353 |
#endif // ASSERT |
1 | 354 |
|
57603
f9d9bed12d1a
8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents:
54898
diff
changeset
|
355 |
#ifdef ASSERT |
1 | 356 |
#define TRACE_CALL(result_type, header) \ |
357 |
InterfaceSupport::_number_of_calls++; \ |
|
358 |
if (CountRuntimeCalls) { \ |
|
359 |
static RuntimeHistogramElement* e = new RuntimeHistogramElement(#header); \ |
|
360 |
if (e != NULL) e->increment_count(); \ |
|
361 |
} |
|
362 |
#else |
|
363 |
#define TRACE_CALL(result_type, header) \ |
|
364 |
/* do nothing */ |
|
57603
f9d9bed12d1a
8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents:
54898
diff
changeset
|
365 |
#endif // ASSERT |
1 | 366 |
|
367 |
||
368 |
// LEAF routines do not lock, GC or throw exceptions |
|
369 |
||
10969
3ecf25293e5a
7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents:
10565
diff
changeset
|
370 |
#define VM_LEAF_BASE(result_type, header) \ |
1 | 371 |
TRACE_CALL(result_type, header) \ |
372 |
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
|
373 |
os::verify_stack_alignment(); \ |
1 | 374 |
/* begin of body */ |
375 |
||
36086 | 376 |
#define VM_ENTRY_BASE_FROM_LEAF(result_type, header, thread) \ |
377 |
TRACE_CALL(result_type, header) \ |
|
378 |
debug_only(ResetNoHandleMark __rnhm;) \ |
|
379 |
HandleMarkCleaner __hm(thread); \ |
|
380 |
Thread* THREAD = thread; \ |
|
381 |
os::verify_stack_alignment(); \ |
|
382 |
/* begin of body */ |
|
383 |
||
1 | 384 |
|
385 |
// ENTRY routines may lock, GC and throw exceptions |
|
386 |
||
10969
3ecf25293e5a
7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents:
10565
diff
changeset
|
387 |
#define VM_ENTRY_BASE(result_type, header, thread) \ |
1 | 388 |
TRACE_CALL(result_type, header) \ |
389 |
HandleMarkCleaner __hm(thread); \ |
|
390 |
Thread* THREAD = thread; \ |
|
11961
0abd4cd26e5a
7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents:
10969
diff
changeset
|
391 |
os::verify_stack_alignment(); \ |
1 | 392 |
/* begin of body */ |
393 |
||
394 |
||
395 |
#define JRT_ENTRY(result_type, header) \ |
|
396 |
result_type header { \ |
|
397 |
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
|
398 |
VM_ENTRY_BASE(result_type, header, thread) \ |
1 | 399 |
debug_only(VMEntryWrapper __vew;) |
400 |
||
57603
f9d9bed12d1a
8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents:
54898
diff
changeset
|
401 |
// JRT_LEAF currently can be called from either _thread_in_Java or |
f9d9bed12d1a
8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents:
54898
diff
changeset
|
402 |
// _thread_in_native mode. |
f9d9bed12d1a
8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents:
54898
diff
changeset
|
403 |
// |
f9d9bed12d1a
8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents:
54898
diff
changeset
|
404 |
// JRT_LEAF rules: |
f9d9bed12d1a
8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents:
54898
diff
changeset
|
405 |
// A JRT_LEAF method may not interfere with safepointing by |
f9d9bed12d1a
8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents:
54898
diff
changeset
|
406 |
// 1) acquiring or blocking on a Mutex or JavaLock - checked |
f9d9bed12d1a
8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents:
54898
diff
changeset
|
407 |
// 2) allocating heap memory - checked |
f9d9bed12d1a
8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents:
54898
diff
changeset
|
408 |
// 3) executing a VM operation - checked |
f9d9bed12d1a
8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents:
54898
diff
changeset
|
409 |
// 4) executing a system call (including malloc) that could block or grab a lock |
f9d9bed12d1a
8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents:
54898
diff
changeset
|
410 |
// 5) invoking GC |
f9d9bed12d1a
8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents:
54898
diff
changeset
|
411 |
// 6) reaching a safepoint |
f9d9bed12d1a
8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents:
54898
diff
changeset
|
412 |
// 7) running too long |
f9d9bed12d1a
8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents:
54898
diff
changeset
|
413 |
// Nor may any method it calls. |
1 | 414 |
|
415 |
#define JRT_LEAF(result_type, header) \ |
|
416 |
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
|
417 |
VM_LEAF_BASE(result_type, header) \ |
57603
f9d9bed12d1a
8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents:
54898
diff
changeset
|
418 |
debug_only(NoSafepointVerifier __nsv;) |
1 | 419 |
|
420 |
||
421 |
#define JRT_ENTRY_NO_ASYNC(result_type, header) \ |
|
422 |
result_type header { \ |
|
423 |
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
|
424 |
VM_ENTRY_BASE(result_type, header, thread) \ |
1 | 425 |
debug_only(VMEntryWrapper __vew;) |
426 |
||
427 |
// Same as JRT Entry but allows for return value after the safepoint |
|
428 |
// to get back into Java from the VM |
|
429 |
#define JRT_BLOCK_ENTRY(result_type, header) \ |
|
430 |
result_type header { \ |
|
431 |
TRACE_CALL(result_type, header) \ |
|
432 |
HandleMarkCleaner __hm(thread); |
|
433 |
||
434 |
#define JRT_BLOCK \ |
|
435 |
{ \ |
|
436 |
ThreadInVMfromJava __tiv(thread); \ |
|
437 |
Thread* THREAD = thread; \ |
|
438 |
debug_only(VMEntryWrapper __vew;) |
|
439 |
||
29070 | 440 |
#define JRT_BLOCK_NO_ASYNC \ |
441 |
{ \ |
|
442 |
ThreadInVMfromJavaNoAsyncException __tiv(thread); \ |
|
443 |
Thread* THREAD = thread; \ |
|
444 |
debug_only(VMEntryWrapper __vew;) |
|
445 |
||
1 | 446 |
#define JRT_BLOCK_END } |
447 |
||
448 |
#define JRT_END } |
|
449 |
||
450 |
// Definitions for JNI |
|
451 |
||
452 |
#define JNI_ENTRY(result_type, header) \ |
|
453 |
JNI_ENTRY_NO_PRESERVE(result_type, header) \ |
|
454 |
WeakPreserveExceptionMark __wem(thread); |
|
455 |
||
36551 | 456 |
#define JNI_ENTRY_NO_PRESERVE(result_type, header) \ |
1 | 457 |
extern "C" { \ |
36551 | 458 |
result_type JNICALL header { \ |
1 | 459 |
JavaThread* thread=JavaThread::thread_from_jni_environment(env); \ |
460 |
assert( !VerifyJNIEnvThread || (thread == Thread::current()), "JNIEnv is only valid in same thread"); \ |
|
461 |
ThreadInVMfromNative __tiv(thread); \ |
|
462 |
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
|
463 |
VM_ENTRY_BASE(result_type, header, thread) |
1 | 464 |
|
465 |
||
466 |
#define JNI_LEAF(result_type, header) \ |
|
467 |
extern "C" { \ |
|
36551 | 468 |
result_type JNICALL header { \ |
1 | 469 |
JavaThread* thread=JavaThread::thread_from_jni_environment(env); \ |
470 |
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
|
471 |
VM_LEAF_BASE(result_type, header) |
1 | 472 |
|
473 |
||
474 |
// Close the routine and the extern "C" |
|
475 |
#define JNI_END } } |
|
476 |
||
477 |
||
478 |
||
479 |
// Definitions for JVM |
|
480 |
||
481 |
#define JVM_ENTRY(result_type, header) \ |
|
482 |
extern "C" { \ |
|
483 |
result_type JNICALL header { \ |
|
484 |
JavaThread* thread=JavaThread::thread_from_jni_environment(env); \ |
|
485 |
ThreadInVMfromNative __tiv(thread); \ |
|
486 |
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
|
487 |
VM_ENTRY_BASE(result_type, header, thread) |
1 | 488 |
|
489 |
||
490 |
#define JVM_ENTRY_NO_ENV(result_type, header) \ |
|
491 |
extern "C" { \ |
|
492 |
result_type JNICALL header { \ |
|
34633
2a6c7c7b30a7
8132510: Replace ThreadLocalStorage with compiler/language-based thread-local variables
dholmes
parents:
34285
diff
changeset
|
493 |
JavaThread* thread = JavaThread::current(); \ |
1 | 494 |
ThreadInVMfromNative __tiv(thread); \ |
495 |
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
|
496 |
VM_ENTRY_BASE(result_type, header, thread) |
1 | 497 |
|
498 |
||
499 |
#define JVM_LEAF(result_type, header) \ |
|
500 |
extern "C" { \ |
|
501 |
result_type JNICALL header { \ |
|
502 |
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
|
503 |
VM_LEAF_BASE(result_type, header) |
1 | 504 |
|
505 |
||
36086 | 506 |
#define JVM_ENTRY_FROM_LEAF(env, result_type, header) \ |
507 |
{ { \ |
|
508 |
JavaThread* thread=JavaThread::thread_from_jni_environment(env); \ |
|
509 |
ThreadInVMfromNative __tiv(thread); \ |
|
510 |
debug_only(VMNativeEntryWrapper __vew;) \ |
|
511 |
VM_ENTRY_BASE_FROM_LEAF(result_type, header, thread) |
|
512 |
||
513 |
||
1 | 514 |
#define JVM_END } } |
7397 | 515 |
|
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
52877
diff
changeset
|
516 |
#endif // SHARE_RUNTIME_INTERFACESUPPORT_INLINE_HPP |