Skip to content

Commit

Permalink
Merge pull request #15202 from dsouzai/criuHang
Browse files Browse the repository at this point in the history
Prevent hangs when preparing the JIT for checkpoint
  • Loading branch information
mpirvu authored Jun 11, 2022
2 parents 3d06b2f + 85827c0 commit 20c2e83
Showing 1 changed file with 31 additions and 1 deletion.
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());

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

0 comments on commit 20c2e83

Please sign in to comment.