From ed68337235e5438c146828888fcf6dda3bb44a8b Mon Sep 17 00:00:00 2001 From: Irwin D'Souza Date: Tue, 14 Jan 2025 11:36:10 -0500 Subject: [PATCH] Close and Reopen log files across a checkpoint/restore 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 --- runtime/compiler/runtime/CRRuntime.cpp | 61 ++++++++++++++++++++++++++ runtime/compiler/runtime/CRRuntime.hpp | 10 +++++ 2 files changed, 71 insertions(+) diff --git a/runtime/compiler/runtime/CRRuntime.cpp b/runtime/compiler/runtime/CRRuntime.cpp index 2af1a3857e2..d7119984604 100644 --- a/runtime/compiler/runtime/CRRuntime.cpp +++ b/runtime/compiler/runtime/CRRuntime.cpp @@ -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" @@ -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, "wb", true); + TR_VerboseLog::vlogRelease(); + } + + if (privateConfig->rtLogFileName) + { + JITRT_LOCK_LOG(getJITConfig()); + privateConfig->rtLogFile = fileOpen(TR::Options::getCmdLineOptions(), getJITConfig(), privateConfig->rtLogFileName, "wb", true); + 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() { @@ -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 @@ -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"); diff --git a/runtime/compiler/runtime/CRRuntime.hpp b/runtime/compiler/runtime/CRRuntime.hpp index 22da6bceba0..fc06d2ee4d9 100644 --- a/runtime/compiler/runtime/CRRuntime.hpp +++ b/runtime/compiler/runtime/CRRuntime.hpp @@ -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