1 //===-- jitcs_memmgr.h - A memory manager for code and data -----*- C++ -*-===//
3 // The manager is an allocator based on Doug Leah's malloc. Memory is allocated
4 // from the system with execution permission.
7 //===----------------------------------------------------------------------===//
9 #ifndef _JITCS_MEMMGR_H_
10 #define _JITCS_MEMMGR_H_
12 #include "jitcs_base.h"
13 #include "jitcs_adt_refcounter.h"
14 #include "jitcs_adt_slice.h"
26 static RefCounter
<MemoryMgr
> Create();
33 * allocate area for function relevant constants (aligned to 16 byte)
34 * allocate area for code (aligned to cache line size, currently 64 byte)
35 * allocated areas are stored in a function object, function objects can be forced to free allocated storage
37 CodeAndData
allocate(size_t data
, size_t code
);
38 CodeAndData
shortenAllocation(CodeAndData
, size_t data
, size_t code
);
39 void deallocate(CodeAndData
);
42 size_t getTotalSpace();
43 size_t getAllocatedSpace();
44 size_t getFreeSpace();
45 size_t getReachableFreeSpace();
49 // called from RefCounter
50 friend class RefCounter
<MemoryMgr
>;
51 void _incRef() { ++_refCnt
; }
52 void _decRef() { if (!--_refCnt
) _release(); }
56 std::unique_ptr
<MemoryMgrImpl
> _mgr
;
60 } // end of namespace jitcs