Skip to content

Commit

Permalink
Close and Reopen log files across a checkpoint/restore
Browse files Browse the repository at this point in the history
A common best practice in CRIU mode, at least in OpenJ9, is to close all
open files before a checkpoint, and reopen them on restore. The JIT
would keep log files such as the vlog and rtLog open across a
checkpoint/restore boundary. This commit closes these files on
checkpoint and reopens them on restore.

Signed-off-by: Irwin D'Souza <[email protected]>
  • Loading branch information
dsouzai committed Jan 17, 2025
1 parent 8a2ed5a commit 7a3856d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
61 changes: 61 additions & 0 deletions runtime/compiler/runtime/CRRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "infra/Assert.hpp"
#include "infra/CriticalSection.hpp"
#include "infra/Monitor.hpp"
#include "runtime/CodeRuntime.hpp"
#include "runtime/CRRuntime.hpp"
#include "runtime/IProfiler.hpp"
#include "runtime/J9VMAccess.hpp"
Expand Down Expand Up @@ -677,6 +678,62 @@ TR::CRRuntime::resetStartTime()
_restoreTime = persistentInfo->getElapsedTime();
}

void
TR::CRRuntime::closeLogFiles()
{
TR_JitPrivateConfig *privateConfig = (TR_JitPrivateConfig*)getJITConfig()->privateConfig;

if (privateConfig->vLogFileName)
{
TR_VerboseLog::vlogAcquire();
j9jit_fclose(privateConfig->vLogFile);
privateConfig->vLogFile = NULL;
TR_VerboseLog::vlogRelease();
}

if (privateConfig->rtLogFileName)
{
JITRT_LOCK_LOG(getJITConfig());
j9jit_fclose(privateConfig->rtLogFile);
privateConfig->rtLogFile = NULL;
JITRT_UNLOCK_LOG(getJITConfig());

TR::CompilationInfoPerThread * const * arrayOfCompInfoPT = getCompInfo()->getArrayOfCompilationInfoPerThread();
for (int32_t i = 0; i < getCompInfo()->getNumTotalAllocatedCompilationThreads(); i++)
{
TR::CompilationInfoPerThread *compThreadInfoPT = arrayOfCompInfoPT[i];
compThreadInfoPT->closeRTLogFile();
}
}
}

void
TR::CRRuntime::reopenLogFiles()
{
TR_JitPrivateConfig *privateConfig = (TR_JitPrivateConfig*)getJITConfig()->privateConfig;

if (privateConfig->vLogFileName)
{
TR_VerboseLog::vlogAcquire();
privateConfig->vLogFile = fileOpen(TR::Options::getCmdLineOptions(), getJITConfig(), privateConfig->vLogFileName, "ab", false);
TR_VerboseLog::vlogRelease();
}

if (privateConfig->rtLogFileName)
{
JITRT_LOCK_LOG(getJITConfig());
privateConfig->rtLogFile = fileOpen(TR::Options::getCmdLineOptions(), getJITConfig(), privateConfig->rtLogFileName, "ab", false);
JITRT_UNLOCK_LOG(getJITConfig());

TR::CompilationInfoPerThread * const * arrayOfCompInfoPT = getCompInfo()->getArrayOfCompilationInfoPerThread();
for (int32_t i = 0; i < getCompInfo()->getNumTotalAllocatedCompilationThreads(); i++)
{
TR::CompilationInfoPerThread *compThreadInfoPT = arrayOfCompInfoPT[i];
compThreadInfoPT->openRTLogFile();
}
}
}

void
TR::CRRuntime::prepareForCheckpoint()
{
Expand Down Expand Up @@ -751,6 +808,8 @@ TR::CRRuntime::prepareForCheckpoint()

if (TR::Options::getCmdLineOptions()->getVerboseOption(TR_VerboseCheckpointRestore))
TR_VerboseLog::writeLineLocked(TR_Vlog_CHECKPOINT_RESTORE, "Ready for checkpoint");

closeLogFiles();
}

void
Expand All @@ -762,6 +821,8 @@ TR::CRRuntime::prepareForRestore()
PORT_ACCESS_FROM_JAVAVM(vm);
OMRPORT_ACCESS_FROM_J9PORT(PORTLIB);

reopenLogFiles();

if (TR::Options::getCmdLineOptions()->getVerboseOption(TR_VerboseCheckpointRestore))
TR_VerboseLog::writeLineLocked(TR_Vlog_CHECKPOINT_RESTORE, "Preparing for restore");

Expand Down
10 changes: 10 additions & 0 deletions runtime/compiler/runtime/CRRuntime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,16 @@ class CRRuntime
*/
void resetStartTime();

/**
* @brief Closes various log files
*/
void closeLogFiles();

/**
* @brief Reopens log files closed at checkpoint
*/
void reopenLogFiles();

/**
* @brief Helper method to push a J9Method onto the front of list that is
* used to memoize a future compilation of said J9Method. This method
Expand Down

0 comments on commit 7a3856d

Please sign in to comment.