Skip to content

Commit

Permalink
Do not initialize / shutdown JIT for each test
Browse files Browse the repository at this point in the history
This commit avoid initialization and shutdown of JIT for *each* TRIL test
and instead shutdown / initialize JIT again every 5000 tests (this can
be easily changed).

to further reduce memory footprint of `comptest`. As in case of type
dictionary, during JIT initialization some internal structures are
allocated in persistent memory and thus never freed. More importantly,
this commit helps significantly to reduce memory footprint when running
tests under QEMU - the exact nature of why this help escapes me, but
probably has to do with memory used by QEMU's TCG "JIT".

With this change, running tests for x86_64 natively, the peak memory
consumption of `comptest` drops by another ~150MB (to 317MB). For RISC-V
using QEMU on x86_64 host peak memory consumption drops to 460MB.
  • Loading branch information
janvrany authored and jdekonin committed May 19, 2023
1 parent b337e85 commit cef6948
Showing 1 changed file with 44 additions and 8 deletions.
52 changes: 44 additions & 8 deletions fvtest/compilertest/control/TestJit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,30 +178,66 @@ initializeTestJit(TR_RuntimeHelper *helperIDs, void **helperAddresses, int32_t n
return true;
}

extern "C"
void
shutdownTestJit()
{
auto fe = TestCompiler::FrontEnd::instance();

TR::CodeCacheManager &codeCacheManager = fe->codeCacheManager();
codeCacheManager.destroy();

TR::CompilationController::shutdown();
}


static int initCount = 0;
const int initCountMax = 5000;
static std::string initOptions = "";

extern "C"
bool
initializeJitWithOptions(char *options)
{
return initializeTestJit(0, 0, 0, options);
if (// If initialized with different options...
(initCount > 0 && initOptions != options)
// ...or virtual "initialication" count reaches threshold
|| (initCount > initCountMax))
{
shutdownTestJit();
initCount = 0;
initOptions = "";
}

// Initialize if not initialized already
if (initCount == 0)
{
if (initializeTestJit(0, 0, 0, options))
{
initCount = 1;
initOptions = options;
}
}
// else increment "initialization" count.
else
{
initCount++;
}
return initCount > 0;
}

extern "C"
bool
initializeJit()
{
return initializeTestJit(0, 0, 0, (char *)"-Xjit:useILValidator");
return initializeJitWithOptions((char *)"-Xjit:useILValidator");
}

extern "C"
void
shutdownJit()
{
auto fe = TestCompiler::FrontEnd::instance();

TR::CodeCacheManager &codeCacheManager = fe->codeCacheManager();
codeCacheManager.destroy();

TR::CompilationController::shutdown();
// Do nothing, shutdown is handled in initializeJitWithOptions()
}

extern "C"
Expand Down

0 comments on commit cef6948

Please sign in to comment.