|
1 | 1 | /* |
2 | | - * Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
@@ -251,8 +251,13 @@ class VM_HandshakeAllThreads: public VM_Operation { |
251 | 251 | thr->handshake_state()->add_operation(_op); |
252 | 252 | number_of_threads_issued++; |
253 | 253 | } |
| 254 | + |
| 255 | + // Separate the arming of the poll in add_operation() above from |
| 256 | + // the read of JavaThread state in the try_process() call below. |
254 | 257 | if (UseSystemMemoryBarrier) { |
255 | 258 | SystemMemoryBarrier::emit(); |
| 259 | + } else { |
| 260 | + OrderAccess::fence(); |
256 | 261 | } |
257 | 262 |
|
258 | 263 | if (number_of_threads_issued < 1) { |
@@ -380,6 +385,8 @@ void Handshake::execute(HandshakeClosure* hs_cl, ThreadsListHandle* tlh, JavaThr |
380 | 385 | // the read of JavaThread state in the try_process() call below. |
381 | 386 | if (UseSystemMemoryBarrier) { |
382 | 387 | SystemMemoryBarrier::emit(); |
| 388 | + } else { |
| 389 | + OrderAccess::fence(); |
383 | 390 | } |
384 | 391 |
|
385 | 392 | // Keeps count on how many of own emitted handshakes |
@@ -559,6 +566,10 @@ bool HandshakeState::process_by_self(bool allow_suspend, bool check_async_except |
559 | 566 | // Threads shouldn't block if they are in the middle of printing, but... |
560 | 567 | ttyLocker::break_tty_lock_for_safepoint(os::current_thread_id()); |
561 | 568 |
|
| 569 | + // Separate all the writes above for other threads reading state |
| 570 | + // set by this thread in case the operation is ThreadSuspendHandshake. |
| 571 | + OrderAccess::fence(); |
| 572 | + |
562 | 573 | while (has_operation()) { |
563 | 574 | // Handshakes cannot safely safepoint. The exceptions to this rule are |
564 | 575 | // the asynchronous suspension and unsafe access error handshakes. |
|
0 commit comments