Skip to content

Commit 86bd44f

Browse files
committed
8257831: Suspend with handshakes
Reviewed-by: dcubed, rrich, dholmes, pchilanomate, sspitsyn
1 parent 28af31d commit 86bd44f

40 files changed

+468
-1079
lines changed

src/hotspot/os/aix/attachListener_aix.cpp

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2012, 2018 SAP SE. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -440,10 +440,6 @@ void AixAttachOperation::complete(jint result, bufferedStream* st) {
440440
JavaThread* thread = JavaThread::current();
441441
ThreadBlockInVM tbivm(thread);
442442

443-
thread->set_suspend_equivalent();
444-
// cleared by handle_special_suspend_equivalent_condition() or
445-
// java_suspend_self() via check_and_wait_while_suspended()
446-
447443
// write operation result
448444
char msg[32];
449445
sprintf(msg, "%d\n", result);
@@ -459,9 +455,6 @@ void AixAttachOperation::complete(jint result, bufferedStream* st) {
459455
// done
460456
::close(this->socket());
461457

462-
// were we externally suspended while we were waiting?
463-
thread->check_and_wait_while_suspended();
464-
465458
delete this;
466459
}
467460

@@ -472,15 +465,8 @@ AttachOperation* AttachListener::dequeue() {
472465
JavaThread* thread = JavaThread::current();
473466
ThreadBlockInVM tbivm(thread);
474467

475-
thread->set_suspend_equivalent();
476-
// cleared by handle_special_suspend_equivalent_condition() or
477-
// java_suspend_self() via check_and_wait_while_suspended()
478-
479468
AttachOperation* op = AixAttachListener::dequeue();
480469

481-
// were we externally suspended while we were waiting?
482-
thread->check_and_wait_while_suspended();
483-
484470
return op;
485471
}
486472

@@ -511,15 +497,8 @@ int AttachListener::pd_init() {
511497
JavaThread* thread = JavaThread::current();
512498
ThreadBlockInVM tbivm(thread);
513499

514-
thread->set_suspend_equivalent();
515-
// cleared by handle_special_suspend_equivalent_condition() or
516-
// java_suspend_self() via check_and_wait_while_suspended()
517-
518500
int ret_code = AixAttachListener::init();
519501

520-
// were we externally suspended while we were waiting?
521-
thread->check_and_wait_while_suspended();
522-
523502
return ret_code;
524503
}
525504

src/hotspot/os/bsd/attachListener_bsd.cpp

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2021, 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
@@ -409,10 +409,6 @@ void BsdAttachOperation::complete(jint result, bufferedStream* st) {
409409
JavaThread* thread = JavaThread::current();
410410
ThreadBlockInVM tbivm(thread);
411411

412-
thread->set_suspend_equivalent();
413-
// cleared by handle_special_suspend_equivalent_condition() or
414-
// java_suspend_self() via check_and_wait_while_suspended()
415-
416412
// write operation result
417413
char msg[32];
418414
sprintf(msg, "%d\n", result);
@@ -427,9 +423,6 @@ void BsdAttachOperation::complete(jint result, bufferedStream* st) {
427423
// done
428424
::close(this->socket());
429425

430-
// were we externally suspended while we were waiting?
431-
thread->check_and_wait_while_suspended();
432-
433426
delete this;
434427
}
435428

@@ -440,15 +433,8 @@ AttachOperation* AttachListener::dequeue() {
440433
JavaThread* thread = JavaThread::current();
441434
ThreadBlockInVM tbivm(thread);
442435

443-
thread->set_suspend_equivalent();
444-
// cleared by handle_special_suspend_equivalent_condition() or
445-
// java_suspend_self() via check_and_wait_while_suspended()
446-
447436
AttachOperation* op = BsdAttachListener::dequeue();
448437

449-
// were we externally suspended while we were waiting?
450-
thread->check_and_wait_while_suspended();
451-
452438
return op;
453439
}
454440

@@ -479,15 +465,8 @@ int AttachListener::pd_init() {
479465
JavaThread* thread = JavaThread::current();
480466
ThreadBlockInVM tbivm(thread);
481467

482-
thread->set_suspend_equivalent();
483-
// cleared by handle_special_suspend_equivalent_condition() or
484-
// java_suspend_self() via check_and_wait_while_suspended()
485-
486468
int ret_code = BsdAttachListener::init();
487469

488-
// were we externally suspended while we were waiting?
489-
thread->check_and_wait_while_suspended();
490-
491470
return ret_code;
492471
}
493472

src/hotspot/os/linux/attachListener_linux.cpp

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2021, 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
@@ -409,10 +409,6 @@ void LinuxAttachOperation::complete(jint result, bufferedStream* st) {
409409
JavaThread* thread = JavaThread::current();
410410
ThreadBlockInVM tbivm(thread);
411411

412-
thread->set_suspend_equivalent();
413-
// cleared by handle_special_suspend_equivalent_condition() or
414-
// java_suspend_self() via check_and_wait_while_suspended()
415-
416412
// write operation result
417413
char msg[32];
418414
sprintf(msg, "%d\n", result);
@@ -427,9 +423,6 @@ void LinuxAttachOperation::complete(jint result, bufferedStream* st) {
427423
// done
428424
::close(this->socket());
429425

430-
// were we externally suspended while we were waiting?
431-
thread->check_and_wait_while_suspended();
432-
433426
delete this;
434427
}
435428

@@ -440,15 +433,8 @@ AttachOperation* AttachListener::dequeue() {
440433
JavaThread* thread = JavaThread::current();
441434
ThreadBlockInVM tbivm(thread);
442435

443-
thread->set_suspend_equivalent();
444-
// cleared by handle_special_suspend_equivalent_condition() or
445-
// java_suspend_self() via check_and_wait_while_suspended()
446-
447436
AttachOperation* op = LinuxAttachListener::dequeue();
448437

449-
// were we externally suspended while we were waiting?
450-
thread->check_and_wait_while_suspended();
451-
452438
return op;
453439
}
454440

@@ -479,15 +465,8 @@ int AttachListener::pd_init() {
479465
JavaThread* thread = JavaThread::current();
480466
ThreadBlockInVM tbivm(thread);
481467

482-
thread->set_suspend_equivalent();
483-
// cleared by handle_special_suspend_equivalent_condition() or
484-
// java_suspend_self() via check_and_wait_while_suspended()
485-
486468
int ret_code = LinuxAttachListener::init();
487469

488-
// were we externally suspended while we were waiting?
489-
thread->check_and_wait_while_suspended();
490-
491470
return ret_code;
492471
}
493472

src/hotspot/os/posix/os_posix.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,8 +1664,6 @@ void Parker::park(bool isAbsolute, jlong time) {
16641664
}
16651665

16661666
OSThreadWaitState osts(jt->osthread(), false /* not Object.wait() */);
1667-
jt->set_suspend_equivalent();
1668-
// cleared by handle_special_suspend_equivalent_condition() or java_suspend_self()
16691667

16701668
assert(_cur_index == -1, "invariant");
16711669
if (time == 0) {
@@ -1688,11 +1686,6 @@ void Parker::park(bool isAbsolute, jlong time) {
16881686
// Paranoia to ensure our locked and lock-free paths interact
16891687
// correctly with each other and Java-level accesses.
16901688
OrderAccess::fence();
1691-
1692-
// If externally suspended while waiting, re-suspend
1693-
if (jt->handle_special_suspend_equivalent_condition()) {
1694-
jt->java_suspend_self();
1695-
}
16961689
}
16971690

16981691
void Parker::unpark() {

src/hotspot/os/posix/signals_posix.cpp

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "runtime/java.hpp"
3333
#include "runtime/os.hpp"
3434
#include "runtime/osThread.hpp"
35+
#include "runtime/semaphore.inline.hpp"
3536
#include "runtime/stubRoutines.hpp"
3637
#include "runtime/thread.hpp"
3738
#include "signals_posix.hpp"
@@ -369,27 +370,7 @@ static int check_pending_signals() {
369370
return i;
370371
}
371372
}
372-
JavaThread *thread = JavaThread::current();
373-
ThreadBlockInVM tbivm(thread);
374-
375-
bool threadIsSuspended;
376-
do {
377-
thread->set_suspend_equivalent();
378-
// cleared by handle_special_suspend_equivalent_condition() or java_suspend_self()
379-
sig_semaphore->wait();
380-
381-
// were we externally suspended while we were waiting?
382-
threadIsSuspended = thread->handle_special_suspend_equivalent_condition();
383-
if (threadIsSuspended) {
384-
// The semaphore has been incremented, but while we were waiting
385-
// another thread suspended us. We don't want to continue running
386-
// while suspended because that would surprise the thread that
387-
// suspended us.
388-
sig_semaphore->signal();
389-
390-
thread->java_suspend_self();
391-
}
392-
} while (threadIsSuspended);
373+
sig_semaphore->wait_with_safepoint_check(JavaThread::current());
393374
}
394375
ShouldNotReachHere();
395376
return 0; // Satisfy compiler
@@ -1555,10 +1536,6 @@ void PosixSignals::hotspot_sigmask(Thread* thread) {
15551536
// - sets target osthread state to continue
15561537
// - sends signal to end the sigsuspend loop in the SR_handler
15571538
//
1558-
// Note that the SR_lock plays no role in this suspend/resume protocol,
1559-
// but is checked for NULL in SR_handler as a thread termination indicator.
1560-
// The SR_lock is, however, used by JavaThread::java_suspend()/java_resume() APIs.
1561-
//
15621539
// Note that resume_clear_context() and suspend_save_context() are needed
15631540
// by SR_handler(), so that fetch_frame_from_context() works,
15641541
// which in part is used by:
@@ -1603,11 +1580,11 @@ static void SR_handler(int sig, siginfo_t* siginfo, ucontext_t* context) {
16031580

16041581
// On some systems we have seen signal delivery get "stuck" until the signal
16051582
// mask is changed as part of thread termination. Check that the current thread
1606-
// has not already terminated (via SR_lock()) - else the following assertion
1583+
// has not already terminated - else the following assertion
16071584
// will fail because the thread is no longer a JavaThread as the ~JavaThread
16081585
// destructor has completed.
16091586

1610-
if (thread->SR_lock() == NULL) {
1587+
if (thread->has_terminated()) {
16111588
return;
16121589
}
16131590

src/hotspot/os/windows/attachListener_windows.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2021, 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
@@ -310,10 +310,6 @@ void Win32AttachOperation::complete(jint result, bufferedStream* result_stream)
310310
JavaThread* thread = JavaThread::current();
311311
ThreadBlockInVM tbivm(thread);
312312

313-
thread->set_suspend_equivalent();
314-
// cleared by handle_special_suspend_equivalent_condition() or
315-
// java_suspend_self() via check_and_wait_while_suspended()
316-
317313
HANDLE hPipe = open_pipe();
318314
int lastError = (int)::GetLastError();
319315
if (hPipe != INVALID_HANDLE_VALUE) {
@@ -351,9 +347,6 @@ void Win32AttachOperation::complete(jint result, bufferedStream* result_stream)
351347

352348
::ReleaseMutex(Win32AttachListener::mutex());
353349
}
354-
355-
// were we externally suspended while we were waiting?
356-
thread->check_and_wait_while_suspended();
357350
}
358351

359352

@@ -363,15 +356,8 @@ AttachOperation* AttachListener::dequeue() {
363356
JavaThread* thread = JavaThread::current();
364357
ThreadBlockInVM tbivm(thread);
365358

366-
thread->set_suspend_equivalent();
367-
// cleared by handle_special_suspend_equivalent_condition() or
368-
// java_suspend_self() via check_and_wait_while_suspended()
369-
370359
AttachOperation* op = Win32AttachListener::dequeue();
371360

372-
// were we externally suspended while we were waiting?
373-
thread->check_and_wait_while_suspended();
374-
375361
return op;
376362
}
377363

src/hotspot/os/windows/os_windows.cpp

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,28 +2207,7 @@ static int check_pending_signals() {
22072207
return i;
22082208
}
22092209
}
2210-
JavaThread *thread = JavaThread::current();
2211-
2212-
ThreadBlockInVM tbivm(thread);
2213-
2214-
bool threadIsSuspended;
2215-
do {
2216-
thread->set_suspend_equivalent();
2217-
// cleared by handle_special_suspend_equivalent_condition() or java_suspend_self()
2218-
sig_sem->wait();
2219-
2220-
// were we externally suspended while we were waiting?
2221-
threadIsSuspended = thread->handle_special_suspend_equivalent_condition();
2222-
if (threadIsSuspended) {
2223-
// The semaphore has been incremented, but while we were waiting
2224-
// another thread suspended us. We don't want to continue running
2225-
// while suspended because that would surprise the thread that
2226-
// suspended us.
2227-
sig_sem->signal();
2228-
2229-
thread->java_suspend_self();
2230-
}
2231-
} while (threadIsSuspended);
2210+
sig_sem->wait_with_safepoint_check(JavaThread::current());
22322211
}
22332212
ShouldNotReachHere();
22342213
return 0; // Satisfy compiler
@@ -5487,15 +5466,9 @@ void Parker::park(bool isAbsolute, jlong time) {
54875466
} else {
54885467
ThreadBlockInVM tbivm(thread);
54895468
OSThreadWaitState osts(thread->osthread(), false /* not Object.wait() */);
5490-
thread->set_suspend_equivalent();
54915469

54925470
WaitForSingleObject(_ParkHandle, time);
54935471
ResetEvent(_ParkHandle);
5494-
5495-
// If externally suspended while waiting, re-suspend
5496-
if (thread->handle_special_suspend_equivalent_condition()) {
5497-
thread->java_suspend_self();
5498-
}
54995472
}
55005473
}
55015474

src/hotspot/share/logging/logTag.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@
174174
LOG_TAG(stringtable) \
175175
LOG_TAG(subclass) \
176176
LOG_TAG(survivor) \
177+
LOG_TAG(suspend) \
177178
LOG_TAG(sweep) \
178179
LOG_TAG(symboltable) \
179180
LOG_TAG(system) \

0 commit comments

Comments
 (0)