2013-07-02 20:52:38 -06:00
|
|
|
/* Copyright (c) 2008-2013, Avian Contributors
|
2008-02-19 11:06:52 -07: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 17:36:55 -06:00
|
|
|
#ifndef HEAP_H
|
|
|
|
#define HEAP_H
|
|
|
|
|
2013-02-20 20:42:09 -07:00
|
|
|
#include <avian/vm/system/system.h>
|
2013-02-27 13:25:50 -07:00
|
|
|
#include "avian/allocator.h"
|
2007-06-20 13:20:25 -06:00
|
|
|
|
2007-06-18 13:23:44 -06:00
|
|
|
namespace vm {
|
|
|
|
|
2011-08-29 19:00:17 -06:00
|
|
|
// an object must survive TenureThreshold + 2 garbage collections
|
|
|
|
// before being copied to gen2 (must be at least 1):
|
|
|
|
const unsigned TenureThreshold = 3;
|
|
|
|
|
|
|
|
const unsigned FixieTenureThreshold = TenureThreshold + 2;
|
|
|
|
|
2008-01-13 15:05:08 -07:00
|
|
|
class Heap: public Allocator {
|
2007-06-02 17:36:55 -06:00
|
|
|
public:
|
|
|
|
enum CollectionType {
|
|
|
|
MinorCollection,
|
|
|
|
MajorCollection
|
|
|
|
};
|
|
|
|
|
2007-07-09 19:43:43 -06:00
|
|
|
enum Status {
|
2007-07-19 21:18:25 -06:00
|
|
|
Null,
|
2007-07-09 19:43:43 -06:00
|
|
|
Reachable,
|
|
|
|
Unreachable,
|
|
|
|
Tenured
|
|
|
|
};
|
|
|
|
|
2007-06-02 17:36:55 -06:00
|
|
|
class Visitor {
|
2007-06-02 19:58:47 -06:00
|
|
|
public:
|
2007-09-06 18:21:52 -06:00
|
|
|
virtual void visit(void*) = 0;
|
2007-06-02 17:36:55 -06:00
|
|
|
};
|
|
|
|
|
2007-06-20 10:58:35 -06:00
|
|
|
class Walker {
|
2007-06-02 19:58:47 -06:00
|
|
|
public:
|
2007-06-20 10:58:35 -06:00
|
|
|
virtual bool visit(unsigned) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Client {
|
|
|
|
public:
|
2008-01-13 15:05:08 -07:00
|
|
|
virtual void collect(void* context, CollectionType type) = 0;
|
2007-06-20 10:58:35 -06:00
|
|
|
virtual void visitRoots(Visitor*) = 0;
|
2007-10-28 13:14:53 -06:00
|
|
|
virtual bool isFixed(void*) = 0;
|
|
|
|
virtual unsigned sizeInWords(void*) = 0;
|
2007-07-02 08:19:05 -06:00
|
|
|
virtual unsigned copiedSizeInWords(void*) = 0;
|
|
|
|
virtual void copy(void*, void*) = 0;
|
2007-06-20 10:58:35 -06:00
|
|
|
virtual void walk(void*, Walker*) = 0;
|
2007-06-02 17:36:55 -06:00
|
|
|
};
|
|
|
|
|
2008-01-13 15:05:08 -07:00
|
|
|
virtual void setClient(Client* client) = 0;
|
2008-12-01 19:38:00 -07:00
|
|
|
virtual void setImmortalHeap(uintptr_t* start, unsigned sizeInWords) = 0;
|
2013-11-27 18:56:31 -06:00
|
|
|
virtual unsigned remaining() = 0;
|
2012-08-29 18:32:45 -06:00
|
|
|
virtual unsigned limit() = 0;
|
2013-03-07 20:17:05 -07:00
|
|
|
virtual bool limitExceeded(int pendingAllocation = 0) = 0;
|
|
|
|
virtual void collect(CollectionType type, unsigned footprint,
|
|
|
|
int pendingAllocation) = 0;
|
|
|
|
virtual unsigned fixedFootprint(unsigned sizeInWords, bool objectMask) = 0;
|
|
|
|
virtual void* allocateFixed(Allocator* allocator, unsigned sizeInWords,
|
|
|
|
bool objectMask) = 0;
|
|
|
|
virtual void* allocateImmortalFixed(Allocator* allocator,
|
|
|
|
unsigned sizeInWords,
|
|
|
|
bool objectMask) = 0;
|
2007-10-28 13:14:53 -06:00
|
|
|
virtual void mark(void* p, unsigned offset, unsigned count) = 0;
|
2008-01-14 09:39:57 -07:00
|
|
|
virtual void pad(void* p) = 0;
|
2007-06-20 11:42:13 -06:00
|
|
|
virtual void* follow(void* p) = 0;
|
2012-08-12 10:55:37 -06:00
|
|
|
virtual void postVisit() = 0;
|
2007-07-09 19:43:43 -06:00
|
|
|
virtual Status status(void* p) = 0;
|
|
|
|
virtual CollectionType collectionType() = 0;
|
2008-01-13 15:05:08 -07:00
|
|
|
virtual void disposeFixies() = 0;
|
2007-06-19 20:28:31 -06:00
|
|
|
virtual void dispose() = 0;
|
2007-06-02 17:36:55 -06:00
|
|
|
};
|
|
|
|
|
2008-01-13 15:05:08 -07:00
|
|
|
Heap* makeHeap(System* system, unsigned limit);
|
2007-06-20 13:20:25 -06:00
|
|
|
|
2007-06-18 13:23:44 -06:00
|
|
|
} // namespace vm
|
|
|
|
|
2007-06-02 17:36:55 -06:00
|
|
|
#endif//HEAP_H
|