Another massive overhaul to make calling conventions work. Solved several
[jitcs.git] / include / jitcs_memmgr.h
blobc7901943b1c1a1a9472ce97213202b36b00834ee
1 //===-- jitcs_memmgr.h - A memory manager for code and data -----*- C++ -*-===//
2 //
3 // The manager is an allocator based on Doug Leah's malloc. Memory is allocated
4 // from the system with execution permission.
5 // TODO:
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef _JITCS_MEMMGR_H_
10 #define _JITCS_MEMMGR_H_
12 #include "jitcs_base.h"
13 #include <memory>
15 namespace jitcs {
16 class MemoryMgrImpl;
18 class MemoryMgr {
19 public:
20 struct Space {
21 u8* start; size_t size;
22 static Space Make(u8* s, size_t sz) { Space ps; ps.start = s; ps.size = sz; return ps; }
24 struct CodeAndData {
25 Space data, code;
27 public:
28 MemoryMgr();
29 ~MemoryMgr();
31 public:
32 /* todo
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 void deallocate(CodeAndData);
40 bool check();
41 size_t getTotalSpace();
42 size_t getAllocatedSpace();
43 size_t getFreeSpace();
44 size_t getReachableFreeSpace();
45 bool shrink();
47 private:
48 std::unique_ptr<MemoryMgrImpl> _mgr;
51 } // end of namespace jitcs
53 #endif
54 // _JITCS_MEMMGR_H_