2010-12-06 03:21:09 +00:00
|
|
|
/* Copyright (c) 2008-2010, Avian Contributors
|
2008-02-19 18:06:52 +00:00
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software
|
|
|
|
for any purpose with or without fee is hereby granted, provided
|
|
|
|
that the above copyright notice and this permission notice appear
|
|
|
|
in all copies.
|
|
|
|
|
|
|
|
There is NO WARRANTY for this software. See license.txt for
|
|
|
|
details. */
|
|
|
|
|
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"
|
2008-01-13 22:05:08 +00:00
|
|
|
#include "allocator.h"
|
2007-06-20 19:20:25 +00:00
|
|
|
|
2007-06-18 19:23:44 +00:00
|
|
|
namespace vm {
|
|
|
|
|
2008-01-13 22:05:08 +00:00
|
|
|
class Heap: public Allocator {
|
2007-06-02 23:36:55 +00:00
|
|
|
public:
|
|
|
|
enum CollectionType {
|
|
|
|
MinorCollection,
|
|
|
|
MajorCollection
|
|
|
|
};
|
|
|
|
|
2007-07-10 01:43:43 +00:00
|
|
|
enum Status {
|
2007-07-20 03:18:25 +00:00
|
|
|
Null,
|
2007-07-10 01:43:43 +00:00
|
|
|
Reachable,
|
|
|
|
Unreachable,
|
|
|
|
Tenured
|
|
|
|
};
|
|
|
|
|
2007-06-02 23:36:55 +00:00
|
|
|
class Visitor {
|
2007-06-03 01:58:47 +00:00
|
|
|
public:
|
2007-09-07 00:21:52 +00:00
|
|
|
virtual void visit(void*) = 0;
|
2007-06-02 23:36:55 +00:00
|
|
|
};
|
|
|
|
|
2007-06-20 16:58:35 +00:00
|
|
|
class Walker {
|
2007-06-03 01:58:47 +00:00
|
|
|
public:
|
2007-06-20 16:58:35 +00:00
|
|
|
virtual bool visit(unsigned) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Client {
|
|
|
|
public:
|
2008-01-13 22:05:08 +00:00
|
|
|
virtual void collect(void* context, CollectionType type) = 0;
|
2007-06-20 16:58:35 +00:00
|
|
|
virtual void visitRoots(Visitor*) = 0;
|
2007-10-28 19:14:53 +00:00
|
|
|
virtual bool isFixed(void*) = 0;
|
|
|
|
virtual unsigned sizeInWords(void*) = 0;
|
2007-07-02 14:19:05 +00:00
|
|
|
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;
|
2010-11-18 17:55:00 +00:00
|
|
|
virtual void outOfMemory() = 0;
|
2007-06-02 23:36:55 +00:00
|
|
|
};
|
|
|
|
|
2008-01-13 22:05:08 +00:00
|
|
|
virtual void setClient(Client* client) = 0;
|
2008-12-02 02:38:00 +00:00
|
|
|
virtual void setImmortalHeap(uintptr_t* start, unsigned sizeInWords) = 0;
|
2007-10-28 19:14:53 +00:00
|
|
|
virtual void collect(CollectionType type, unsigned footprint) = 0;
|
2008-01-14 23:37:24 +00:00
|
|
|
virtual void* allocateFixed(Allocator* allocator, unsigned sizeInWords,
|
|
|
|
bool objectMask, unsigned* totalInBytes) = 0;
|
2008-11-29 02:31:06 +00:00
|
|
|
virtual void* allocateImmortalFixed(Allocator* allocator,
|
|
|
|
unsigned sizeInWords, bool objectMask,
|
|
|
|
unsigned* totalInBytes) = 0;
|
2007-10-28 19:14:53 +00:00
|
|
|
virtual void mark(void* p, unsigned offset, unsigned count) = 0;
|
2008-01-14 16:39:57 +00:00
|
|
|
virtual void pad(void* p) = 0;
|
2007-06-20 17:42:13 +00:00
|
|
|
virtual void* follow(void* p) = 0;
|
2007-07-10 01:43:43 +00:00
|
|
|
virtual Status status(void* p) = 0;
|
|
|
|
virtual CollectionType collectionType() = 0;
|
2008-01-13 22:05:08 +00:00
|
|
|
virtual void disposeFixies() = 0;
|
2007-06-20 02:28:31 +00:00
|
|
|
virtual void dispose() = 0;
|
2007-06-02 23:36:55 +00:00
|
|
|
};
|
|
|
|
|
2008-01-13 22:05:08 +00:00
|
|
|
Heap* makeHeap(System* system, unsigned limit);
|
2007-06-20 19:20:25 +00:00
|
|
|
|
2007-06-18 19:23:44 +00:00
|
|
|
} // namespace vm
|
|
|
|
|
2007-06-02 23:36:55 +00:00
|
|
|
#endif//HEAP_H
|