Skip to content

Commit

Permalink
switch to using new memory
Browse files Browse the repository at this point in the history
  • Loading branch information
dsouzai committed Feb 25, 2020
1 parent 7a52b2d commit 634851c
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 0 deletions.
80 changes: 80 additions & 0 deletions runtime/compiler/control/CompilationThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,13 @@
#include "env/annotations/AnnotationBase.hpp"
#include "runtime/MethodMetaData.h"
#include "env/J9JitMemory.hpp"
#if defined(NEW_MEMORY)
#include "env/J9TestSegmentAllocator.hpp"
#else
#include "env/J9SegmentCache.hpp"
#include "env/SystemSegmentProvider.hpp"
#include "env/DebugSegmentProvider.hpp"
#endif
#if defined(JITSERVER_SUPPORT)
#include "control/JITClientCompilationThread.hpp"
#include "control/JITServerCompilationThread.hpp"
Expand Down Expand Up @@ -3862,12 +3866,21 @@ TR::CompilationInfoPerThread::doSuspend()
_compInfo.acquireCompMonitor(getCompilationThread());
}

#if defined(NEW_MEMORY)
TestAlloc::J9SegmentCache
TR::CompilationInfoPerThread::initializeSegmentCache(TestAlloc::SegmentAllocator &segmentProvider)
#else
J9::J9SegmentCache
TR::CompilationInfoPerThread::initializeSegmentCache(J9::J9SegmentProvider &segmentProvider)
#endif
{
try
{
#if defined(NEW_MEMORY)
TestAlloc::J9SegmentCache segmentCache(1 << 24, segmentProvider);
#else
J9::J9SegmentCache segmentCache(1 << 24, segmentProvider);
#endif
return segmentCache;
}
catch (const std::bad_alloc &allocationFailure)
Expand All @@ -3879,7 +3892,11 @@ TR::CompilationInfoPerThread::initializeSegmentCache(J9::J9SegmentProvider &segm
}
try
{
#if defined(NEW_MEMORY)
TestAlloc::J9SegmentCache segmentCache(1 << 21, segmentProvider);
#else
J9::J9SegmentCache segmentCache(1 << 21, segmentProvider);
#endif
return segmentCache;
}
catch (const std::bad_alloc &allocationFailure)
Expand All @@ -3889,7 +3906,11 @@ TR::CompilationInfoPerThread::initializeSegmentCache(J9::J9SegmentProvider &segm
TR_VerboseLog::writeLineLocked(TR_Vlog_PERF, "Failed to initialize segment cache of size 1 << 21");
}
}
#if defined(NEW_MEMORY)
TestAlloc::J9SegmentCache segmentCache(1 << 16, segmentProvider);
#else
J9::J9SegmentCache segmentCache(1 << 16, segmentProvider);
#endif
return segmentCache;
}

Expand Down Expand Up @@ -3919,8 +3940,14 @@ TR::CompilationInfoPerThread::processEntries()
J9VMThread * compThread = getCompilationThread();
try
{
#if defined(NEW_MEMORY)
TestAlloc::J9RA rawAllocator(_jitConfig->javaVM);
TestAlloc::J9SA scratchSegmentAllocator(MEMORY_TYPE_JIT_SCRATCH_SPACE | MEMORY_TYPE_VIRTUAL, *_jitConfig->javaVM, rawAllocator);
TestAlloc::J9SegmentCache scratchSegmentCache(initializeSegmentCache(scratchSegmentAllocator).ref());
#else
J9::SegmentAllocator scratchSegmentAllocator(MEMORY_TYPE_JIT_SCRATCH_SPACE | MEMORY_TYPE_VIRTUAL, *_jitConfig->javaVM);
J9::J9SegmentCache scratchSegmentCache(initializeSegmentCache(scratchSegmentAllocator).ref());
#endif
while (getCompilationThreadState() == COMPTHREAD_ACTIVE)
{
TR::CompilationInfo::TR_CompThreadActions compThreadAction = TR::CompilationInfo::UNDEFINED_ACTION;
Expand Down Expand Up @@ -4111,7 +4138,11 @@ TR::CompilationInfoPerThread::processEntries()
}

void
#if defined(NEW_MEMORY)
TR::CompilationInfoPerThread::processEntry(TR_MethodToBeCompiled &entry, TestAlloc::SegmentAllocator &scratchSegmentProvider)
#else
TR::CompilationInfoPerThread::processEntry(TR_MethodToBeCompiled &entry, J9::J9SegmentProvider &scratchSegmentProvider)
#endif
{
TR::CompilationInfo *compInfo = getCompilationInfo();
J9VMThread *compThread = getCompilationThread();
Expand Down Expand Up @@ -6397,7 +6428,12 @@ void *TR::CompilationInfo::compileOnApplicationThread(J9VMThread * vmThread, TR:
bodyInfo->getMethodInfo()->setNextCompileLevel(optimizationPlan->getOptLevel(), optimizationPlan->insertInstrumentation());
}

#if defined(NEW_MEMORY)
TestAlloc::J9RA rawAllocator(_jitConfig->javaVM);
TestAlloc::J9SA scratchSegmentProvider(MEMORY_TYPE_JIT_SCRATCH_SPACE | MEMORY_TYPE_VIRTUAL, *_jitConfig->javaVM, rawAllocator);
#else
J9::SegmentAllocator scratchSegmentProvider(MEMORY_TYPE_JIT_SCRATCH_SPACE | MEMORY_TYPE_VIRTUAL, *_jitConfig->javaVM);
#endif
startPC = _compInfoForCompOnAppThread->compile(vmThread, &methodEntry, scratchSegmentProvider);

if (compErrCode)
Expand Down Expand Up @@ -7583,7 +7619,11 @@ TR::CompilationInfoPerThreadBase::postCompilationTasks(J9VMThread * vmThread,
void *
TR::CompilationInfoPerThreadBase::compile(J9VMThread * vmThread,
TR_MethodToBeCompiled *entry,
#if defined(NEW_MEMORY)
TestAlloc::SegmentAllocator &scratchSegmentProvider)
#else
J9::J9SegmentProvider &scratchSegmentProvider)
#endif
{
TR_ASSERT(!_compiler, "The previous compilation was not properly cleared.");

Expand Down Expand Up @@ -7613,6 +7653,25 @@ TR::CompilationInfoPerThreadBase::compile(J9VMThread * vmThread,

try
{
#if defined(NEW_MEMORY)
TestAlloc::J9RA rawAllocator(vmThread->javaVM);
TestAlloc::J9SystemSegmentProvider defaultSegmentProvider(
1 << 16,
(0 != scratchSegmentProvider.getPreferredSegmentSize()) ? scratchSegmentProvider.getPreferredSegmentSize()
: 1 << 24,
TR::Options::getScratchSpaceLimit(),
scratchSegmentProvider,
rawAllocator
);
TestAlloc::OMRDebugSegmentProvider debugSegmentProvider(
1 << 16,
rawAllocator
);
TestAlloc::SegmentAllocator &regionSegmentProvider =
TR::Options::getCmdLineOptions()->getOption(TR_EnableScratchMemoryDebugging) ?
static_cast<TestAlloc::SegmentAllocator &>(debugSegmentProvider) :
static_cast<TestAlloc::SegmentAllocator &>(defaultSegmentProvider);
#else
TR::RawAllocator rawAllocator(vmThread->javaVM);
J9::SystemSegmentProvider defaultSegmentProvider(
1 << 16,
Expand All @@ -7630,6 +7689,7 @@ TR::CompilationInfoPerThreadBase::compile(J9VMThread * vmThread,
TR::Options::getCmdLineOptions()->getOption(TR_EnableScratchMemoryDebugging) ?
static_cast<TR::SegmentAllocator &>(debugSegmentProvider) :
static_cast<TR::SegmentAllocator &>(defaultSegmentProvider);
#endif
TR::Region dispatchRegion(regionSegmentProvider, rawAllocator);
TR_Memory trMemory(*_compInfo.persistentMemory(), dispatchRegion);

Expand Down Expand Up @@ -7795,7 +7855,11 @@ TR::CompilationInfoPerThreadBase::wrappedCompile(J9PortLibrary *portLib, void *
J9JITConfig *jitConfig = that->_jitConfig;
bool reducedWarm = false;

#if defined(NEW_MEMORY)
TestAlloc::SegmentAllocator &scratchSegmentProvider = p->_scratchSegmentProvider;
#else
TR::SegmentAllocator &scratchSegmentProvider = p->_scratchSegmentProvider;
#endif

// cleanup the compilationShouldBeInterrupted flag.
that->setCompilationShouldBeInterrupted(0);
Expand Down Expand Up @@ -8771,7 +8835,11 @@ TR::CompilationInfoPerThreadBase::compile(
TR_ResolvedMethod * compilee,
TR_J9VMBase &vm,
TR_OptimizationPlan *optimizationPlan,
#if defined(NEW_MEMORY)
TestAlloc::SegmentAllocator const &scratchSegmentProvider
#else
TR::SegmentAllocator const &scratchSegmentProvider
#endif
)
{

Expand Down Expand Up @@ -10534,7 +10602,11 @@ void TR::CompilationInfoPerThreadBase::logCompilationSuccess(
J9VMThread * vmThread,
TR_J9VMBase &vm,
J9Method * method,
#if defined(NEW_MEMORY)
TestAlloc::SegmentAllocator const &scratchSegmentProvider,
#else
TR::SegmentAllocator const &scratchSegmentProvider,
#endif
TR_ResolvedMethod * compilee,
TR::Compilation * compiler,
TR_MethodMetaData * metaData,
Expand Down Expand Up @@ -10897,7 +10969,11 @@ printCompFailureInfo(TR::Compilation * comp, const char * reason)
void
TR::CompilationInfoPerThreadBase::processException(
J9VMThread *vmThread,
#if defined(NEW_MEMORY)
TestAlloc::SegmentAllocator const &scratchSegmentProvider,
#else
TR::SegmentAllocator const &scratchSegmentProvider,
#endif
TR::Compilation * compiler,
volatile bool & haveLockedClassUnloadMonitor,
const char *exceptionName
Expand Down Expand Up @@ -11169,7 +11245,11 @@ TR::CompilationInfoPerThreadBase::processException(
void
TR::CompilationInfoPerThreadBase::processExceptionCommonTasks(
J9VMThread *vmThread,
#if defined(NEW_MEMORY)
TestAlloc::SegmentAllocator const &scratchSegmentProvider,
#else
TR::SegmentAllocator const &scratchSegmentProvider,
#endif
TR::Compilation * compiler,
const char *exceptionName
)
Expand Down
38 changes: 38 additions & 0 deletions runtime/compiler/control/CompilationThread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@
#include "infra/Link.hpp"
#include "env/IO.hpp"
#include "runtime/RelocationRuntime.hpp"
#if defined(NEW_MEMORY)
#include "env/J9TestSegmentAllocator.hpp"
#else
#include "env/J9SegmentCache.hpp"
#endif
#if defined(JITSERVER_SUPPORT)
#include "env/VMJ9Server.hpp"
#include "env/PersistentCollections.hpp"
Expand Down Expand Up @@ -102,7 +106,11 @@ struct CompileParameters
J9VMThread * vmThread,
TR_RelocationRuntime *reloRuntime,
TR_OptimizationPlan * optimizationPlan,
#if defined(NEW_MEMORY)
TestAlloc::SegmentAllocator &scratchSegmentProvider,
#else
TR::SegmentAllocator &scratchSegmentProvider,
#endif
TR::Region &dispatchRegion,
TR_Memory &trMemory,
const TR::CompileIlGenRequest &ilGenRequest
Expand All @@ -125,7 +133,11 @@ struct CompileParameters
J9VMThread *_vmThread;
TR_RelocationRuntime *_reloRuntime;
TR_OptimizationPlan*_optimizationPlan;
#if defined(NEW_MEMORY)
TestAlloc::SegmentAllocator &_scratchSegmentProvider;
#else
TR::SegmentAllocator &_scratchSegmentProvider;
#endif
TR::Region &_dispatchRegion;
TR_Memory &_trMemory;
TR::CompileIlGenRequest _ilGenRequest;
Expand Down Expand Up @@ -161,9 +173,15 @@ class CompilationInfoPerThreadBase
void printCompilationThreadTime();
TR_MethodMetaData *getMetadata() {return _metadata;}
void setMetadata(TR_MethodMetaData *m) {_metadata = m;}
#if defined(NEW_MEMORY)
void *compile(J9VMThread *context, TR_MethodToBeCompiled *entry, TestAlloc::SegmentAllocator &scratchSegmentProvider);
TR_MethodMetaData *compile(J9VMThread *context, TR::Compilation *,
TR_ResolvedMethod *compilee, TR_J9VMBase &, TR_OptimizationPlan*, TestAlloc::SegmentAllocator const &scratchSegmentProvider);
#else
void *compile(J9VMThread *context, TR_MethodToBeCompiled *entry, J9::J9SegmentProvider &scratchSegmentProvider);
TR_MethodMetaData *compile(J9VMThread *context, TR::Compilation *,
TR_ResolvedMethod *compilee, TR_J9VMBase &, TR_OptimizationPlan*, TR::SegmentAllocator const &scratchSegmentProvider);
#endif
TR_MethodMetaData *performAOTLoad(J9VMThread *context, TR::Compilation *, TR_ResolvedMethod *compilee, TR_J9VMBase *vm, J9Method *method);

void preCompilationTasks(J9VMThread * vmThread,
Expand Down Expand Up @@ -301,23 +319,35 @@ class CompilationInfoPerThreadBase
J9VMThread *vmThread,
TR_J9VMBase & vm,
J9Method * method,
#if defined(NEW_MEMORY)
const TestAlloc::SegmentAllocator &scratchSegmentProvider,
#else
const TR::SegmentAllocator &scratchSegmentProvider,
#endif
TR_ResolvedMethod * compilee,
TR::Compilation *compiler,
TR_MethodMetaData *metadata,
TR_OptimizationPlan * optimizationPlan);

void processException(
J9VMThread *vmThread,
#if defined(NEW_MEMORY)
const TestAlloc::SegmentAllocator &scratchSegmentProvider,
#else
const TR::SegmentAllocator &scratchSegmentProvider,
#endif
TR::Compilation * compiler,
volatile bool & haveLockedClassUnloadMonitor,
const char *exceptionName
) throw();

void processExceptionCommonTasks(
J9VMThread *vmThread,
#if defined(NEW_MEMORY)
TestAlloc::SegmentAllocator const &scratchSegmentProvider,
#else
TR::SegmentAllocator const &scratchSegmentProvider,
#endif
TR::Compilation * compiler,
const char *exceptionName);

Expand Down Expand Up @@ -367,7 +397,11 @@ class CompilationInfoPerThread : public TR::CompilationInfoPerThreadBase
TR::Monitor *getCompThreadMonitor() { return _compThreadMonitor; }
void run();
void processEntries();
#if defined (NEW_MEMORY)
virtual void processEntry(TR_MethodToBeCompiled &entry, TestAlloc::SegmentAllocator &scratchSegmentProvider);
#else
virtual void processEntry(TR_MethodToBeCompiled &entry, J9::J9SegmentProvider &scratchSegmentProvider);
#endif
bool shouldPerformCompilation(TR_MethodToBeCompiled &entry);
void waitForWork();
void doSuspend();
Expand Down Expand Up @@ -400,7 +434,11 @@ class CompilationInfoPerThread : public TR::CompilationInfoPerThreadBase
#endif /* defined(JITSERVER_SUPPORT) */

protected:
#if defined(NEW_MEMORY)
TestAlloc::J9SegmentCache initializeSegmentCache(TestAlloc::SegmentAllocator &segmentProvider);
#else
J9::J9SegmentCache initializeSegmentCache(J9::J9SegmentProvider &segmentProvider);
#endif

j9thread_t _osThread;
J9VMThread *_compilationThread;
Expand Down
16 changes: 16 additions & 0 deletions runtime/compiler/control/HookedByTheJit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@
#include "runtime/IProfiler.hpp"
#include "runtime/HWProfiler.hpp"
#include "runtime/LMGuardedStorage.hpp"
#if defined(NEW_MEMORY)
#include "env/J9TestSegmentAllocator.hpp"
#else
#include "env/SystemSegmentProvider.hpp"
#endif
#if defined(JITSERVER_SUPPORT)
#include "control/JITServerHelpers.hpp"
#include "runtime/JITServerIProfiler.hpp"
Expand Down Expand Up @@ -4727,6 +4731,17 @@ void JitShutdown(J9JITConfig * jitConfig)
{
try
{
#if defined(NEW_MEMORY)
TestAlloc::J9RA rawAllocator(jitConfig->javaVM);
TestAlloc::J9SA segmentAllocator(MEMORY_TYPE_JIT_SCRATCH_SPACE | MEMORY_TYPE_VIRTUAL, *jitConfig->javaVM, rawAllocator);
TestAlloc::J9SystemSegmentProvider regionSegmentProvider(
1 << 20,
1 << 20,
TR::Options::getScratchSpaceLimit(),
segmentAllocator,
rawAllocator
);
#else
TR::RawAllocator rawAllocator(jitConfig->javaVM);
J9::SegmentAllocator segmentAllocator(MEMORY_TYPE_JIT_SCRATCH_SPACE | MEMORY_TYPE_VIRTUAL, *jitConfig->javaVM);
J9::SystemSegmentProvider regionSegmentProvider(
Expand All @@ -4736,6 +4751,7 @@ void JitShutdown(J9JITConfig * jitConfig)
segmentAllocator,
rawAllocator
);
#endif
TR::Region dispatchRegion(regionSegmentProvider, rawAllocator);
TR_Memory trMemory(*compInfo->persistentMemory(), dispatchRegion);

Expand Down
6 changes: 6 additions & 0 deletions runtime/compiler/ras/DebugExt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,14 @@ TR_DebugExt::TR_DebugExt(
_dbgMalloc(dbgjit_Malloc),
_dbgFree(dbgjit_Free),
_dbgGetExpression(dbgGetExpression),
#if defined(NEW_MEMORY)
_rawAllocator(::jitConfig->javaVM),
_debugSegmentProvider(1 << 20, dbgjit_Malloc, dbgjit_Free),
_debugRegion(_debugSegmentProvider, _rawAllocator),
#else
_debugSegmentProvider(1 << 20, dbgjit_Malloc, dbgjit_Free),
_debugRegion(_debugSegmentProvider, TR::RawAllocator(::jitConfig->javaVM)),
#endif
_isAOT(false),
_structureValid(false)
{
Expand Down
10 changes: 10 additions & 0 deletions runtime/compiler/ras/DebugExt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@
#include "ras/Debug.hpp"
#include "ras/InternalFunctionsExt.hpp"
#include "env/VMJ9.h"
#if defined(NEW_MEMORY)
#include "env/J9TestRawAllocator.hpp"
#include "env/J9TestSegmentAllocator.hpp"
#else
#include "ras/DebugExtSegmentProvider.hpp"
#endif
#include "env/Region.hpp"

class TR_CHTable;
Expand Down Expand Up @@ -302,7 +307,12 @@ class TR_DebugExt : public TR_Debug
void (*_dbgFree)(void *addr);
uintptrj_t (*_dbgGetExpression)(const char* args);

#if defined(NEW_MEMORY)
TestAlloc::J9RA _rawAllocator;
TestAlloc::DebugExtSegmentAllocator _debugSegmentProvider;
#else
J9::DebugSegmentProvider _debugSegmentProvider;
#endif
TR::Region _debugRegion;

TR_HashTable *_toRemotePtrMap;
Expand Down

0 comments on commit 634851c

Please sign in to comment.