20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_RUNTIME_INTERFACESUPPORT_INLINE_HPP
26 #define SHARE_RUNTIME_INTERFACESUPPORT_INLINE_HPP
27
28 #include "runtime/handles.inline.hpp"
29 #include "runtime/mutexLocker.hpp"
30 #include "runtime/orderAccess.hpp"
31 #include "runtime/os.hpp"
32 #include "runtime/safepointMechanism.inline.hpp"
33 #include "runtime/safepointVerifiers.hpp"
34 #include "runtime/thread.hpp"
35 #include "runtime/vmOperations.hpp"
36 #include "utilities/globalDefinitions.hpp"
37 #include "utilities/histogram.hpp"
38 #include "utilities/macros.hpp"
39 #include "utilities/preserveException.hpp"
40
41 // Wrapper for all entry points to the virtual machine.
42
43 // InterfaceSupport provides functionality used by the VM_LEAF_BASE and
44 // VM_ENTRY_BASE macros. These macros are used to guard entry points into
45 // the VM and perform checks upon leave of the VM.
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
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
130 class ThreadInVMForHandshake : public ThreadStateTransition {
131 const JavaThreadState _original_state;
132
133 void transition_back() {
134 // This can be invoked from transition states and must return to the original state properly
135 assert(_thread->thread_state() == _thread_in_vm, "should only call when leaving VM after handshake");
136 // Change to transition state and ensure it is seen by the VM thread.
137 _thread->set_thread_state_fence(_thread_in_vm_trans);
138
139 SafepointMechanism::block_if_requested(_thread);
140
141 _thread->set_thread_state(_original_state);
142
143 if (_original_state != _thread_blocked_trans && _original_state != _thread_in_vm_trans &&
144 _thread->has_special_runtime_exit_condition()) {
145 _thread->handle_special_runtime_exit_condition(
146 !_thread->is_at_poll_safepoint() && (_original_state != _thread_in_native_trans));
147 }
148 }
149
150 public:
151
152 ThreadInVMForHandshake(JavaThread* thread) : ThreadStateTransition(thread),
153 _original_state(thread->thread_state()) {
154
155 if (thread->has_last_Java_frame()) {
156 thread->frame_anchor()->make_walkable(thread);
157 }
158
160 }
161
162 ~ThreadInVMForHandshake() {
163 transition_back();
164 }
165
166 };
167
168 class ThreadInVMfromJava : public ThreadStateTransition {
169 public:
170 ThreadInVMfromJava(JavaThread* thread) : ThreadStateTransition(thread) {
171 trans_from_java(_thread_in_vm);
172 }
173 ~ThreadInVMfromJava() {
174 if (_thread->stack_yellow_reserved_zone_disabled()) {
175 _thread->enable_stack_yellow_reserved_zone();
176 }
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 }
|
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_RUNTIME_INTERFACESUPPORT_INLINE_HPP
26 #define SHARE_RUNTIME_INTERFACESUPPORT_INLINE_HPP
27
28 #include "runtime/handles.inline.hpp"
29 #include "runtime/mutexLocker.hpp"
30 #include "runtime/orderAccess.hpp"
31 #include "runtime/os.hpp"
32 #include "runtime/safepointMechanism.inline.hpp"
33 #include "runtime/safepointVerifiers.hpp"
34 #include "runtime/thread.hpp"
35 #include "runtime/vmOperations.hpp"
36 #include "utilities/globalDefinitions.hpp"
37 #include "utilities/histogram.hpp"
38 #include "utilities/macros.hpp"
39 #include "utilities/preserveException.hpp"
40 #if INCLUDE_G1GC
41 #include "gc/g1/g1EpochUpdater.inline.hpp"
42 #endif // INCLUDE_G1GC
43
44 // Wrapper for all entry points to the virtual machine.
45
46 // InterfaceSupport provides functionality used by the VM_LEAF_BASE and
47 // VM_ENTRY_BASE macros. These macros are used to guard entry points into
48 // the VM and perform checks upon leave of the VM.
49
50
51 class InterfaceSupport: AllStatic {
52 # ifdef ASSERT
53 public:
54 static long _scavenge_alot_counter;
55 static long _fullgc_alot_counter;
56 static long _number_of_calls;
57 static long _fullgc_alot_invocation;
58
59 // Helper methods used to implement +ScavengeALot and +FullGCALot
60 static void check_gc_alot() { if (ScavengeALot || FullGCALot) gc_alot(); }
61 static void gc_alot();
62
122 JavaThread::check_safepoint_and_suspend_for_native_trans(thread);
123 }
124
125 thread->set_thread_state(to);
126 }
127 protected:
128 void trans(JavaThreadState from, JavaThreadState to) { transition(_thread, from, to); }
129 void trans_from_java(JavaThreadState to) { transition_from_java(_thread, to); }
130 void trans_from_native(JavaThreadState to) { transition_from_native(_thread, to); }
131 };
132
133 class ThreadInVMForHandshake : public ThreadStateTransition {
134 const JavaThreadState _original_state;
135
136 void transition_back() {
137 // This can be invoked from transition states and must return to the original state properly
138 assert(_thread->thread_state() == _thread_in_vm, "should only call when leaving VM after handshake");
139 // Change to transition state and ensure it is seen by the VM thread.
140 _thread->set_thread_state_fence(_thread_in_vm_trans);
141
142 if (UseG1GC) {
143 G1EpochUpdater::update_epoch_self(_thread);
144 }
145
146 SafepointMechanism::block_if_requested(_thread);
147
148 _thread->set_thread_state(_original_state);
149
150 if (_original_state != _thread_blocked_trans && _original_state != _thread_in_vm_trans &&
151 _thread->has_special_runtime_exit_condition()) {
152 _thread->handle_special_runtime_exit_condition(
153 !_thread->is_at_poll_safepoint() && (_original_state != _thread_in_native_trans));
154 }
155 }
156
157 public:
158
159 ThreadInVMForHandshake(JavaThread* thread) : ThreadStateTransition(thread),
160 _original_state(thread->thread_state()) {
161
162 if (thread->has_last_Java_frame()) {
163 thread->frame_anchor()->make_walkable(thread);
164 }
165
167 }
168
169 ~ThreadInVMForHandshake() {
170 transition_back();
171 }
172
173 };
174
175 class ThreadInVMfromJava : public ThreadStateTransition {
176 public:
177 ThreadInVMfromJava(JavaThread* thread) : ThreadStateTransition(thread) {
178 trans_from_java(_thread_in_vm);
179 }
180 ~ThreadInVMfromJava() {
181 if (_thread->stack_yellow_reserved_zone_disabled()) {
182 _thread->enable_stack_yellow_reserved_zone();
183 }
184 trans(_thread_in_vm, _thread_in_Java);
185 // Check for pending. async. exceptions or suspends.
186 if (_thread->has_special_runtime_exit_condition()) _thread->handle_special_runtime_exit_condition();
187
188 if (UseG1GC) {
189 G1EpochUpdater::update_epoch_self(_thread);
190 }
191 }
192 };
193
194
195 class ThreadInVMfromUnknown {
196 JavaThread* _thread;
197 public:
198 ThreadInVMfromUnknown() : _thread(NULL) {
199 Thread* t = Thread::current();
200 if (t->is_Java_thread()) {
201 JavaThread* t2 = (JavaThread*) t;
202 if (t2->thread_state() == _thread_in_native) {
203 _thread = t2;
204 ThreadStateTransition::transition_from_native(t2, _thread_in_vm);
205 // Used to have a HandleMarkCleaner but that is dangerous as
206 // it could free a handle in our (indirect, nested) caller.
207 // We expect any handles will be short lived and figure we
208 // don't need an actual HandleMark.
209 }
210 }
|