|
1 | 1 | /* |
2 | | - * Copyright (c) 2017, 2021, 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 |
@@ -245,6 +245,10 @@ class VM_HandshakeAllThreads: public VM_Operation { |
245 | 245 | number_of_threads_issued++; |
246 | 246 | } |
247 | 247 |
|
| 248 | + // Separate the arming of the poll in add_operation() above from |
| 249 | + // the read of JavaThread state in the try_process() call below. |
| 250 | + OrderAccess::fence(); |
| 251 | + |
248 | 252 | if (number_of_threads_issued < 1) { |
249 | 253 | log_handshake_info(start_time_ns, _op->name(), 0, 0, "no threads alive"); |
250 | 254 | return; |
@@ -357,6 +361,10 @@ void Handshake::execute(HandshakeClosure* hs_cl, JavaThread* target) { |
357 | 361 | return; |
358 | 362 | } |
359 | 363 |
|
| 364 | + // Separate the arming of the poll in add_operation() above from |
| 365 | + // the read of JavaThread state in the try_process() call below. |
| 366 | + OrderAccess::fence(); |
| 367 | + |
360 | 368 | // Keeps count on how many of own emitted handshakes |
361 | 369 | // this thread execute. |
362 | 370 | int emitted_handshakes_executed = 0; |
@@ -481,6 +489,10 @@ bool HandshakeState::process_by_self(bool allow_suspend) { |
481 | 489 | // It by-passes the NSV by manually doing the transition. |
482 | 490 | NoSafepointVerifier nsv; |
483 | 491 |
|
| 492 | + // Separate all the writes above for other threads reading state |
| 493 | + // set by this thread in case the operation is ThreadSuspendHandshake. |
| 494 | + OrderAccess::fence(); |
| 495 | + |
484 | 496 | while (has_operation()) { |
485 | 497 | MutexLocker ml(&_lock, Mutex::_no_safepoint_check_flag); |
486 | 498 |
|
|
0 commit comments