Skip to content
Permalink
Browse files
8257831: Suspend with handshakes
Reviewed-by: dcubed, rrich, dholmes, pchilanomate, sspitsyn
  • Loading branch information
robehn committed Apr 22, 2021
1 parent 28af31d commit 86bd44fe80c6222f81662b2167c402571ed68f43
Showing with 468 additions and 1,079 deletions.
  1. +1 −22 src/hotspot/os/aix/attachListener_aix.cpp
  2. +1 −22 src/hotspot/os/bsd/attachListener_bsd.cpp
  3. +1 −22 src/hotspot/os/linux/attachListener_linux.cpp
  4. +0 −7 src/hotspot/os/posix/os_posix.cpp
  5. +4 −27 src/hotspot/os/posix/signals_posix.cpp
  6. +1 −15 src/hotspot/os/windows/attachListener_windows.cpp
  7. +1 −28 src/hotspot/os/windows/os_windows.cpp
  8. +1 −0 src/hotspot/share/logging/logTag.hpp
  9. +2 −41 src/hotspot/share/prims/jvm.cpp
  10. +41 −47 src/hotspot/share/prims/jvmtiEnv.cpp
  11. +4 −5 src/hotspot/share/prims/jvmtiEnvBase.cpp
  12. +3 −37 src/hotspot/share/prims/jvmtiImpl.cpp
  13. +49 −47 src/hotspot/share/prims/jvmtiRawMonitor.cpp
  14. +0 −5 src/hotspot/share/prims/jvmtiThreadState.cpp
  15. +1 −3 src/hotspot/share/prims/jvmtiThreadState.hpp
  16. +2 −0 src/hotspot/share/runtime/arguments.cpp
  17. +0 −10 src/hotspot/share/runtime/globals.hpp
  18. +121 −10 src/hotspot/share/runtime/handshake.cpp
  19. +64 −10 src/hotspot/share/runtime/handshake.hpp
  20. +0 −4 src/hotspot/share/runtime/monitorDeflationThread.cpp
  21. +5 −22 src/hotspot/share/runtime/mutex.cpp
  22. +3 −7 src/hotspot/share/runtime/mutex.hpp
  23. +2 −3 src/hotspot/share/runtime/mutexLocker.hpp
  24. +2 −3 src/hotspot/share/runtime/nonJavaThread.cpp
  25. +2 −2 src/hotspot/share/runtime/notificationThread.cpp
  26. +63 −46 src/hotspot/share/runtime/objectMonitor.cpp
  27. +0 −2 src/hotspot/share/runtime/os.cpp
  28. +20 −16 src/hotspot/share/runtime/safepointMechanism.cpp
  29. +0 −1 src/hotspot/share/runtime/sweeper.cpp
  30. +38 −344 src/hotspot/share/runtime/thread.cpp
  31. +21 −171 src/hotspot/share/runtime/thread.hpp
  32. +3 −25 src/hotspot/share/runtime/thread.inline.hpp
  33. +0 −2 src/hotspot/share/runtime/vmStructs.cpp
  34. +1 −1 src/hotspot/share/services/management.cpp
  35. +1 −1 src/hotspot/share/services/threadService.cpp
  36. +3 −3 src/hotspot/share/services/threadService.hpp
  37. +1 −22 src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/Thread.java
  38. +1 −4 test/hotspot/gtest/threadHelper.inline.hpp
  39. +3 −8 test/hotspot/jtreg/serviceability/jvmti/SuspendWithCurrentThread/SuspendWithCurrentThread.java
  40. +2 −34 test/hotspot/jtreg/serviceability/jvmti/SuspendWithCurrentThread/libSuspendWithCurrentThread.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.
*
@@ -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);
@@ -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;
}

@@ -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;
}

@@ -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;
}

@@ -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
@@ -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);
@@ -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;
}

@@ -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;
}

@@ -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;
}

@@ -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
@@ -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);
@@ -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;
}

@@ -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;
}

@@ -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;
}

@@ -1664,8 +1664,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) {
@@ -1688,11 +1686,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() {
@@ -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"
@@ -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
@@ -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:
@@ -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;
}

@@ -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
@@ -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) {
@@ -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();
}


@@ -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;
}

@@ -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
@@ -5487,15 +5466,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();
}
}
}

@@ -174,6 +174,7 @@
LOG_TAG(stringtable) \
LOG_TAG(subclass) \
LOG_TAG(survivor) \
LOG_TAG(suspend) \
LOG_TAG(sweep) \
LOG_TAG(symboltable) \
LOG_TAG(system) \

1 comment on commit 86bd44f

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 86bd44f Apr 22, 2021

Please sign in to comment.