Skip to content

Commit

Permalink
Merge pull request #15 from lmaisons/code_cache_manager
Browse files Browse the repository at this point in the history
Refactor and clean up CodeCacheManager
  • Loading branch information
0xdaryl authored Sep 27, 2017
2 parents 4c79f04 + 67cd4fe commit 9d92728
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 25 deletions.
2 changes: 1 addition & 1 deletion runtime/tr.source/trj9/control/rossa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ onLoadInternal(
memset(codeCacheManager, 0, sizeof(TR::CodeCacheManager));

// must initialize manager using the global (not thread specific) fe because current thread isn't guaranteed to live longer than the manager
new (codeCacheManager) TR::CodeCacheManager(feWithoutThread);
new (codeCacheManager) TR::CodeCacheManager(feWithoutThread, TR::Compiler->rawAllocator);

TR::CodeCacheConfig &codeCacheConfig = codeCacheManager->codeCacheConfig();

Expand Down
9 changes: 8 additions & 1 deletion runtime/tr.source/trj9/env/RawAllocator.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2016 IBM Corp. and others
* Copyright (c) 2000, 2017 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -39,6 +39,7 @@ using J9::RawAllocator;
#endif // #ifndef TR_RAW_ALLOCATOR

#include <new>
#include "env/TypedAllocator.hpp"
#include "j9.h"
#undef min
#undef max
Expand Down Expand Up @@ -95,6 +96,12 @@ class RawAllocator

friend class SegmentAllocator;

template < typename T >
operator TR::typed_allocator< T, TR::RawAllocator >()
{
return TR::typed_allocator< T, TR::RawAllocator >(*this);
}

private:

J9JavaVM * _javaVM;
Expand Down
7 changes: 5 additions & 2 deletions runtime/tr.source/trj9/runtime/CodeCacheManager.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2016 IBM Corp. and others
* Copyright (c) 2000, 2017 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -30,7 +30,10 @@ namespace TR {
class OMR_EXTENSIBLE CodeCacheManager : public J9::CodeCacheManagerConnector
{
public:
CodeCacheManager(TR_FrontEnd *fe) : J9::CodeCacheManagerConnector(fe) { }
CodeCacheManager(TR_FrontEnd *fe, TR::RawAllocator rawAllocator) :
J9::CodeCacheManagerConnector(fe, rawAllocator)
{
}
};

}
Expand Down
23 changes: 7 additions & 16 deletions runtime/tr.source/trj9/runtime/J9CodeCacheManager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2016 IBM Corp. and others
* Copyright (c) 2000, 2017 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -57,6 +57,12 @@ J9::CodeCacheManager::self()
return static_cast<TR::CodeCacheManager *>(this);
}

TR_FrontEnd *
J9::CodeCacheManager::fe()
{
return _fe;
}

TR_J9VMBase *
J9::CodeCacheManager::fej9()
{
Expand All @@ -72,21 +78,6 @@ J9::CodeCacheManager::initialize(bool useConsolidatedCache, uint32_t numberOfCod
return self()->OMR::CodeCacheManager::initialize(useConsolidatedCache, numberOfCodeCachesToCreateAtStartup);
}

void *
J9::CodeCacheManager::getMemory(size_t sizeInBytes)
{
PORT_ACCESS_FROM_JITCONFIG(TR::CodeCacheManager::jitConfig());
return j9mem_allocate_memory(sizeInBytes, J9MEM_CATEGORY_JIT);
}

void
J9::CodeCacheManager::freeMemory(void *memoryToFree)
{
PORT_ACCESS_FROM_JITCONFIG(TR::CodeCacheManager::jitConfig());
j9mem_free_memory(memoryToFree);
}


void
J9::CodeCacheManager::addCodeCache(TR::CodeCache *codeCache)
{
Expand Down
11 changes: 6 additions & 5 deletions runtime/tr.source/trj9/runtime/J9CodeCacheManager.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2016 IBM Corp. and others
* Copyright (c) 2000, 2017 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -51,7 +51,9 @@ class OMR_EXTENSIBLE CodeCacheManager : public OMR::CodeCacheManagerConnector
TR::CodeCacheManager *self();

public:
CodeCacheManager(TR_FrontEnd *fe) : OMR::CodeCacheManagerConnector(fe)
CodeCacheManager(TR_FrontEnd *fe, TR::RawAllocator rawAllocator) :
OMR::CodeCacheManagerConnector(rawAllocator),
_fe(fe)
{
_codeCacheManager = reinterpret_cast<TR::CodeCacheManager *>(this);
}
Expand All @@ -62,13 +64,11 @@ class OMR_EXTENSIBLE CodeCacheManager : public OMR::CodeCacheManagerConnector
static J9JITConfig *jitConfig() { return _jitConfig; }
static J9JavaVM *javaVM() { return _javaVM; }

TR_FrontEnd *fe();
TR_J9VMBase *fej9();

TR::CodeCache *initialize(bool useConsolidatedCache, uint32_t numberOfCodeCachesToCreateAtStartup);

void *getMemory(size_t sizeInBytes);
void freeMemory(void *memoryToFree);

void addCodeCache(TR::CodeCache *codeCache);

TR::CodeCacheMemorySegment *allocateCodeCacheSegment(size_t segmentSize,
Expand Down Expand Up @@ -104,6 +104,7 @@ class OMR_EXTENSIBLE CodeCacheManager : public OMR::CodeCacheManagerConnector
void onClassRedefinition(TR_OpaqueMethodBlock *oldMethod, TR_OpaqueMethodBlock *newMethod);

private :
TR_FrontEnd *_fe;
static TR::CodeCacheManager *_codeCacheManager;
static J9JITConfig *_jitConfig;
static J9JavaVM *_javaVM;
Expand Down

0 comments on commit 9d92728

Please sign in to comment.