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

Prevent hangs when preparing the JIT for checkpoint #15202

Merged
merged 2 commits into from
Jun 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion runtime/compiler/control/CompilationThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2613,13 +2613,40 @@ void TR::CompilationInfo::resumeCompilationThread()
}

#if defined(J9VM_OPT_CRIU_SUPPORT)

class ReleaseVMAccessAndAcquireMonitor
{
public:
ReleaseVMAccessAndAcquireMonitor(J9VMThread *vmThread, TR::Monitor *monitor)
: _hadVMAccess(vmThread->publicFlags & J9_PUBLIC_FLAGS_VM_ACCESS),
_vmThread(vmThread),
_monitor(monitor)
{
if (_hadVMAccess)
releaseVMAccessNoSuspend(_vmThread);
_monitor->enter();
}

~ReleaseVMAccessAndAcquireMonitor()
{
_monitor->exit();
if (_hadVMAccess)
acquireVMAccessNoSuspend(_vmThread);
}

private:
bool _hadVMAccess;
J9VMThread *_vmThread;
TR::Monitor *_monitor;
};

void TR::CompilationInfo::prepareForCheckpoint()
{
J9JavaVM *vm = _jitConfig->javaVM;
J9VMThread *vmThread = vm->internalVMFunctions->currentVMThread(vm);

{
OMR::CriticalSection suspendCompThreadsForCheckpoint(getCompilationMonitor());
ReleaseVMAccessAndAcquireMonitor suspendCompThreadsForCheckpoint(vmThread, getCompilationMonitor());

dsouzai marked this conversation as resolved.
Show resolved Hide resolved
if (shouldCheckpointBeInterrupted())
return;
Expand All @@ -2635,6 +2662,9 @@ void TR::CompilationInfo::prepareForCheckpoint()
bool purgeMethodQueue = false;
suspendCompilationThread(purgeMethodQueue);

/* With the thread state now updated, notify any active comp threads waiting for work */
getCompilationMonitor()->notifyAll();

/* Wait until all compilation threads are suspended. */
for (int32_t i = 0; i < getNumTotalCompilationThreads(); i++)
{
Expand Down