Skip to content

Commit 70f4650

Browse files
author
duke
committed
Backport 83e9e48
1 parent dc5298e commit 70f4650

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/hotspot/share/runtime/handshake.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
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.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -251,8 +251,13 @@ class VM_HandshakeAllThreads: public VM_Operation {
251251
thr->handshake_state()->add_operation(_op);
252252
number_of_threads_issued++;
253253
}
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.
254257
if (UseSystemMemoryBarrier) {
255258
SystemMemoryBarrier::emit();
259+
} else {
260+
OrderAccess::fence();
256261
}
257262

258263
if (number_of_threads_issued < 1) {
@@ -380,6 +385,8 @@ void Handshake::execute(HandshakeClosure* hs_cl, ThreadsListHandle* tlh, JavaThr
380385
// the read of JavaThread state in the try_process() call below.
381386
if (UseSystemMemoryBarrier) {
382387
SystemMemoryBarrier::emit();
388+
} else {
389+
OrderAccess::fence();
383390
}
384391

385392
// 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
559566
// Threads shouldn't block if they are in the middle of printing, but...
560567
ttyLocker::break_tty_lock_for_safepoint(os::current_thread_id());
561568

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+
562573
while (has_operation()) {
563574
// Handshakes cannot safely safepoint. The exceptions to this rule are
564575
// the asynchronous suspension and unsafe access error handshakes.

0 commit comments

Comments
 (0)