Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8257831: Suspend with handshakes #3191

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 1 addition & 22 deletions src/hotspot/os/aix/attachListener_aix.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2018 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -440,10 +440,6 @@ void AixAttachOperation::complete(jint result, bufferedStream* st) {
JavaThread* thread = JavaThread::current();
ThreadBlockInVM tbivm(thread);

thread->set_suspend_equivalent();
// cleared by handle_special_suspend_equivalent_condition() or
// java_suspend_self() via check_and_wait_while_suspended()

// write operation result
char msg[32];
sprintf(msg, "%d\n", result);
Expand All @@ -459,9 +455,6 @@ void AixAttachOperation::complete(jint result, bufferedStream* st) {
// done
::close(this->socket());

// were we externally suspended while we were waiting?
thread->check_and_wait_while_suspended();

delete this;
}

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

thread->set_suspend_equivalent();
// cleared by handle_special_suspend_equivalent_condition() or
// java_suspend_self() via check_and_wait_while_suspended()

AttachOperation* op = AixAttachListener::dequeue();

// were we externally suspended while we were waiting?
thread->check_and_wait_while_suspended();

return op;
}

Expand Down Expand Up @@ -511,15 +497,8 @@ int AttachListener::pd_init() {
JavaThread* thread = JavaThread::current();
ThreadBlockInVM tbivm(thread);

thread->set_suspend_equivalent();
// cleared by handle_special_suspend_equivalent_condition() or
// java_suspend_self() via check_and_wait_while_suspended()

int ret_code = AixAttachListener::init();

// were we externally suspended while we were waiting?
thread->check_and_wait_while_suspended();

return ret_code;
}

Expand Down
23 changes: 1 addition & 22 deletions src/hotspot/os/bsd/attachListener_bsd.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -409,10 +409,6 @@ void BsdAttachOperation::complete(jint result, bufferedStream* st) {
JavaThread* thread = JavaThread::current();
ThreadBlockInVM tbivm(thread);

thread->set_suspend_equivalent();
// cleared by handle_special_suspend_equivalent_condition() or
// java_suspend_self() via check_and_wait_while_suspended()

// write operation result
char msg[32];
sprintf(msg, "%d\n", result);
Expand All @@ -427,9 +423,6 @@ void BsdAttachOperation::complete(jint result, bufferedStream* st) {
// done
::close(this->socket());

// were we externally suspended while we were waiting?
thread->check_and_wait_while_suspended();

delete this;
}

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

thread->set_suspend_equivalent();
// cleared by handle_special_suspend_equivalent_condition() or
// java_suspend_self() via check_and_wait_while_suspended()

AttachOperation* op = BsdAttachListener::dequeue();

// were we externally suspended while we were waiting?
thread->check_and_wait_while_suspended();

return op;
}

Expand Down Expand Up @@ -479,15 +465,8 @@ int AttachListener::pd_init() {
JavaThread* thread = JavaThread::current();
ThreadBlockInVM tbivm(thread);

thread->set_suspend_equivalent();
// cleared by handle_special_suspend_equivalent_condition() or
// java_suspend_self() via check_and_wait_while_suspended()

int ret_code = BsdAttachListener::init();

// were we externally suspended while we were waiting?
thread->check_and_wait_while_suspended();

return ret_code;
}

Expand Down
23 changes: 1 addition & 22 deletions src/hotspot/os/linux/attachListener_linux.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -409,10 +409,6 @@ void LinuxAttachOperation::complete(jint result, bufferedStream* st) {
JavaThread* thread = JavaThread::current();
ThreadBlockInVM tbivm(thread);

thread->set_suspend_equivalent();
// cleared by handle_special_suspend_equivalent_condition() or
// java_suspend_self() via check_and_wait_while_suspended()

// write operation result
char msg[32];
sprintf(msg, "%d\n", result);
Expand All @@ -427,9 +423,6 @@ void LinuxAttachOperation::complete(jint result, bufferedStream* st) {
// done
::close(this->socket());

// were we externally suspended while we were waiting?
thread->check_and_wait_while_suspended();

delete this;
}

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

thread->set_suspend_equivalent();
// cleared by handle_special_suspend_equivalent_condition() or
// java_suspend_self() via check_and_wait_while_suspended()

AttachOperation* op = LinuxAttachListener::dequeue();

// were we externally suspended while we were waiting?
thread->check_and_wait_while_suspended();

return op;
}

Expand Down Expand Up @@ -479,15 +465,8 @@ int AttachListener::pd_init() {
JavaThread* thread = JavaThread::current();
ThreadBlockInVM tbivm(thread);

thread->set_suspend_equivalent();
// cleared by handle_special_suspend_equivalent_condition() or
// java_suspend_self() via check_and_wait_while_suspended()

int ret_code = LinuxAttachListener::init();

// were we externally suspended while we were waiting?
thread->check_and_wait_while_suspended();

return ret_code;
}

Expand Down
7 changes: 0 additions & 7 deletions src/hotspot/os/posix/os_posix.cpp
Expand Up @@ -1604,8 +1604,6 @@ void Parker::park(bool isAbsolute, jlong time) {
}

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

assert(_cur_index == -1, "invariant");
if (time == 0) {
Expand All @@ -1628,11 +1626,6 @@ void Parker::park(bool isAbsolute, jlong time) {
// Paranoia to ensure our locked and lock-free paths interact
// correctly with each other and Java-level accesses.
OrderAccess::fence();

// If externally suspended while waiting, re-suspend
if (jt->handle_special_suspend_equivalent_condition()) {
jt->java_suspend_self();
}
}

void Parker::unpark() {
Expand Down
31 changes: 4 additions & 27 deletions src/hotspot/os/posix/signals_posix.cpp
Expand Up @@ -32,6 +32,7 @@
#include "runtime/java.hpp"
#include "runtime/os.hpp"
#include "runtime/osThread.hpp"
#include "runtime/semaphore.inline.hpp"
#include "runtime/stubRoutines.hpp"
#include "runtime/thread.hpp"
#include "signals_posix.hpp"
Expand Down Expand Up @@ -369,27 +370,7 @@ static int check_pending_signals() {
return i;
}
}
JavaThread *thread = JavaThread::current();
ThreadBlockInVM tbivm(thread);

bool threadIsSuspended;
do {
thread->set_suspend_equivalent();
// cleared by handle_special_suspend_equivalent_condition() or java_suspend_self()
sig_semaphore->wait();

// were we externally suspended while we were waiting?
threadIsSuspended = thread->handle_special_suspend_equivalent_condition();
if (threadIsSuspended) {
// The semaphore has been incremented, but while we were waiting
// another thread suspended us. We don't want to continue running
// while suspended because that would surprise the thread that
// suspended us.
sig_semaphore->signal();

thread->java_suspend_self();
}
} while (threadIsSuspended);
sig_semaphore->wait_with_safepoint_check(JavaThread::current());
}
ShouldNotReachHere();
return 0; // Satisfy compiler
Expand Down Expand Up @@ -1555,10 +1536,6 @@ void PosixSignals::hotspot_sigmask(Thread* thread) {
// - sets target osthread state to continue
// - sends signal to end the sigsuspend loop in the SR_handler
//
// Note that the SR_lock plays no role in this suspend/resume protocol,
// but is checked for NULL in SR_handler as a thread termination indicator.
// The SR_lock is, however, used by JavaThread::java_suspend()/java_resume() APIs.
//
// Note that resume_clear_context() and suspend_save_context() are needed
// by SR_handler(), so that fetch_frame_from_context() works,
// which in part is used by:
Expand Down Expand Up @@ -1603,11 +1580,11 @@ static void SR_handler(int sig, siginfo_t* siginfo, ucontext_t* context) {

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

if (thread->SR_lock() == NULL) {
if (thread->has_terminated()) {
return;
}

Expand Down
16 changes: 1 addition & 15 deletions src/hotspot/os/windows/attachListener_windows.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -310,10 +310,6 @@ void Win32AttachOperation::complete(jint result, bufferedStream* result_stream)
JavaThread* thread = JavaThread::current();
ThreadBlockInVM tbivm(thread);

thread->set_suspend_equivalent();
// cleared by handle_special_suspend_equivalent_condition() or
// java_suspend_self() via check_and_wait_while_suspended()

HANDLE hPipe = open_pipe();
int lastError = (int)::GetLastError();
if (hPipe != INVALID_HANDLE_VALUE) {
Expand Down Expand Up @@ -351,9 +347,6 @@ void Win32AttachOperation::complete(jint result, bufferedStream* result_stream)

::ReleaseMutex(Win32AttachListener::mutex());
}

// were we externally suspended while we were waiting?
thread->check_and_wait_while_suspended();
}


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

thread->set_suspend_equivalent();
// cleared by handle_special_suspend_equivalent_condition() or
// java_suspend_self() via check_and_wait_while_suspended()

AttachOperation* op = Win32AttachListener::dequeue();

// were we externally suspended while we were waiting?
thread->check_and_wait_while_suspended();

return op;
}

Expand Down
29 changes: 1 addition & 28 deletions src/hotspot/os/windows/os_windows.cpp
Expand Up @@ -2207,28 +2207,7 @@ static int check_pending_signals() {
return i;
}
}
JavaThread *thread = JavaThread::current();

ThreadBlockInVM tbivm(thread);

bool threadIsSuspended;
do {
thread->set_suspend_equivalent();
// cleared by handle_special_suspend_equivalent_condition() or java_suspend_self()
sig_sem->wait();

// were we externally suspended while we were waiting?
threadIsSuspended = thread->handle_special_suspend_equivalent_condition();
if (threadIsSuspended) {
// The semaphore has been incremented, but while we were waiting
// another thread suspended us. We don't want to continue running
// while suspended because that would surprise the thread that
// suspended us.
sig_sem->signal();

thread->java_suspend_self();
}
} while (threadIsSuspended);
sig_sem->wait_with_safepoint_check(JavaThread::current());
}
ShouldNotReachHere();
return 0; // Satisfy compiler
Expand Down Expand Up @@ -5475,15 +5454,9 @@ void Parker::park(bool isAbsolute, jlong time) {
} else {
ThreadBlockInVM tbivm(thread);
OSThreadWaitState osts(thread->osthread(), false /* not Object.wait() */);
thread->set_suspend_equivalent();

WaitForSingleObject(_ParkHandle, time);
ResetEvent(_ParkHandle);

// If externally suspended while waiting, re-suspend
if (thread->handle_special_suspend_equivalent_condition()) {
thread->java_suspend_self();
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/logging/logTag.hpp
Expand Up @@ -173,6 +173,7 @@
LOG_TAG(stringtable) \
LOG_TAG(subclass) \
LOG_TAG(survivor) \
LOG_TAG(suspend) \
LOG_TAG(sweep) \
LOG_TAG(symboltable) \
LOG_TAG(system) \
Expand Down