Skip to content

Commit

Permalink
new memory region
Browse files Browse the repository at this point in the history
  • Loading branch information
dsouzai committed Feb 25, 2020
1 parent 3cb6c3a commit c526847
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
18 changes: 18 additions & 0 deletions compiler/env/Region.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,24 @@
*******************************************************************************/

#include "env/MemorySegment.hpp"

#if defined (NEW_MEMORY)
#include "env/OMRTestSegmentAllocator.hpp"
#else
#include "env/SegmentProvider.hpp"
#endif

#include "env/Region.hpp"
#include "infra/ReferenceWrapper.hpp"
#include "env/TRMemory.hpp"

namespace TR {

#if defined (NEW_MEMORY)
Region::Region(TestAlloc::SegmentAllocator &segmentProvider, TestAlloc::RawAllocator &rawAllocator) :
#else
Region::Region(TR::SegmentProvider &segmentProvider, TR::RawAllocator rawAllocator) :
#endif
_bytesAllocated(0),
_segmentProvider(segmentProvider),
_rawAllocator(rawAllocator),
Expand Down Expand Up @@ -68,7 +78,11 @@ Region::~Region() throw()
)
{
_currentSegment = TR::ref(latestSegment.get().unlink());
#if defined (NEW_MEMORY)
_segmentProvider.deallocate(latestSegment);
#else
_segmentProvider.release(latestSegment);
#endif
}
TR_ASSERT(_currentSegment.get() == _initialSegment, "self-referencial link was broken");
}
Expand All @@ -82,7 +96,11 @@ Region::allocate(size_t const size, void *hint)
_bytesAllocated += roundedSize;
return _currentSegment.get().allocate(roundedSize);
}
#if defined (NEW_MEMORY)
TR::MemorySegment &newSegment = _segmentProvider.allocate(roundedSize);
#else
TR::MemorySegment &newSegment = _segmentProvider.request(roundedSize);
#endif
TR_ASSERT(newSegment.remaining() >= roundedSize, "Allocated segment is too small");
newSegment.link(_currentSegment.get());
_currentSegment = TR::ref(newSegment);
Expand Down
20 changes: 20 additions & 0 deletions compiler/env/Region.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,20 @@
#include "infra/ReferenceWrapper.hpp"
#include "env/TypedAllocator.hpp"
#include "env/MemorySegment.hpp"

#if defined (NEW_MEMORY)
#include "env/OMRTestRawAllocator.hpp"
#include "env/OMRTestSegmentAllocator.hpp"
#else
#include "env/RawAllocator.hpp"
#endif

namespace TR {

#if !defined (NEW_MEMORY)
class SegmentProvider;
#endif

class RegionProfiler;

class Region
Expand Down Expand Up @@ -85,7 +94,11 @@ class Region
};

public:
#if defined (NEW_MEMORY)
Region(TestAlloc::SegmentAllocator &segmentProvider, TestAlloc::RawAllocator &rawAllocator);
#else
Region(TR::SegmentProvider &segmentProvider, TR::RawAllocator rawAllocator);
#endif
Region(const Region &prototype);
virtual ~Region() throw();
void * allocate(const size_t bytes, void * hint = 0);
Expand Down Expand Up @@ -143,8 +156,15 @@ class Region
size_t round(size_t bytes);

size_t _bytesAllocated;

#if defined (NEW_MEMORY)
TestAlloc::SegmentAllocator &_segmentProvider;
TestAlloc::RawAllocator &_rawAllocator;
#else
TR::SegmentProvider &_segmentProvider;
TR::RawAllocator _rawAllocator;
#endif

TR::MemorySegment _initialSegment;
TR::reference_wrapper<TR::MemorySegment> _currentSegment;

Expand Down

0 comments on commit c526847

Please sign in to comment.