|
30 | 30 | #include "runtime/atomic.hpp"
|
31 | 31 | #include "runtime/handshake.hpp"
|
32 | 32 | #include "runtime/safepoint.hpp"
|
| 33 | +#include "runtime/stackWatermarkSet.hpp" |
33 | 34 | #include "runtime/thread.inline.hpp"
|
34 | 35 |
|
35 | 36 | // Caller is responsible for using a memory barrier if needed.
|
@@ -62,26 +63,29 @@ bool SafepointMechanism::global_poll() {
|
62 | 63 | return (SafepointSynchronize::_state != SafepointSynchronize::_not_synchronized);
|
63 | 64 | }
|
64 | 65 |
|
65 |
| -bool SafepointMechanism::should_process_no_suspend(JavaThread* thread) { |
66 |
| - if (global_poll() || thread->handshake_state()->has_a_non_suspend_operation()) { |
67 |
| - return true; |
68 |
| - } else { |
69 |
| - // We ignore suspend requests if any and just check before returning if we need |
70 |
| - // to fix the thread's oops and first few frames due to a possible safepoint. |
71 |
| - StackWatermarkSet::on_safepoint(thread); |
72 |
| - update_poll_values(thread); |
73 |
| - OrderAccess::cross_modify_fence(); |
74 |
| - return false; |
75 |
| - } |
76 |
| -} |
77 |
| - |
78 | 66 | bool SafepointMechanism::should_process(JavaThread* thread, bool allow_suspend) {
|
79 | 67 | if (!local_poll_armed(thread)) {
|
80 | 68 | return false;
|
81 | 69 | } else if (allow_suspend) {
|
82 | 70 | return true;
|
83 | 71 | }
|
84 |
| - return should_process_no_suspend(thread); |
| 72 | + // We are armed but we should ignore suspend operations. |
| 73 | + if (global_poll() || // Safepoint |
| 74 | + thread->handshake_state()->has_a_non_suspend_operation() || // Non-suspend handshake |
| 75 | + !StackWatermarkSet::processing_started(thread)) { // StackWatermark processing is not started |
| 76 | + return true; |
| 77 | + } |
| 78 | + |
| 79 | + // It has boiled down to two possibilities: |
| 80 | + // 1: We have nothing to process, this just a disarm poll. |
| 81 | + // 2: We have a suspend handshake, which cannot be processed. |
| 82 | + // We update the poll value in case of a disarm, to reduce false positives. |
| 83 | + update_poll_values(thread); |
| 84 | + |
| 85 | + // We are now about to avoid processing and thus no cross modify fence will be executed. |
| 86 | + // In case a safepoint happened, while being blocked, we execute it here. |
| 87 | + OrderAccess::cross_modify_fence(); |
| 88 | + return false; |
85 | 89 | }
|
86 | 90 |
|
87 | 91 | void SafepointMechanism::process_if_requested(JavaThread* thread, bool allow_suspend) {
|
|
0 commit comments