corda/src/heap.h

70 lines
1.7 KiB
C
Raw Normal View History

2007-06-02 23:36:55 +00:00
#ifndef HEAP_H
#define HEAP_H
2007-06-20 19:20:25 +00:00
#include "system.h"
#include "allocator.h"
2007-06-20 19:20:25 +00:00
namespace vm {
class Heap: public Allocator {
2007-06-02 23:36:55 +00:00
public:
enum CollectionType {
MinorCollection,
MajorCollection
};
enum Status {
Null,
Reachable,
Unreachable,
Tenured
};
2007-06-02 23:36:55 +00:00
class Visitor {
public:
2007-06-02 23:36:55 +00:00
virtual ~Visitor() { }
virtual void visit(void*) = 0;
2007-06-02 23:36:55 +00:00
};
2007-06-20 16:58:35 +00:00
class Walker {
public:
2007-06-20 16:58:35 +00:00
virtual ~Walker() { }
virtual bool visit(unsigned) = 0;
};
class Client {
public:
virtual ~Client() { }
virtual void collect(void* context, CollectionType type) = 0;
2007-06-20 16:58:35 +00:00
virtual void visitRoots(Visitor*) = 0;
virtual bool isFixed(void*) = 0;
virtual unsigned sizeInWords(void*) = 0;
virtual unsigned copiedSizeInWords(void*) = 0;
virtual void copy(void*, void*) = 0;
2007-06-20 16:58:35 +00:00
virtual void walk(void*, Walker*) = 0;
2007-06-02 23:36:55 +00:00
};
virtual ~Heap() { }
virtual void setClient(Client* client) = 0;
virtual void collect(CollectionType type, unsigned footprint) = 0;
virtual void* allocateFixed(Allocator* allocator, unsigned sizeInWords,
bool objectMask, unsigned* totalInBytes) = 0;
virtual void* allocateImmortal(Allocator* allocator, unsigned sizeInWords,
bool executable, bool objectMask,
unsigned* totalInBytes) = 0;
virtual bool needsMark(void* p) = 0;
virtual void mark(void* p, unsigned offset, unsigned count) = 0;
virtual void pad(void* p) = 0;
2007-06-20 17:42:13 +00:00
virtual void* follow(void* p) = 0;
virtual Status status(void* p) = 0;
virtual CollectionType collectionType() = 0;
virtual void disposeFixies() = 0;
virtual void dispose() = 0;
2007-06-02 23:36:55 +00:00
};
Heap* makeHeap(System* system, unsigned limit);
2007-06-20 19:20:25 +00:00
} // namespace vm
2007-06-02 23:36:55 +00:00
#endif//HEAP_H