factor/vm/data_heap.hpp

69 lines
1.2 KiB
C++
Raw Normal View History

2009-05-04 02:46:13 -04:00
namespace factor
{
2009-05-02 05:04:19 -04:00
/* generational copying GC divides memory into zones */
2009-05-04 05:50:24 -04:00
struct zone {
2009-05-02 05:04:19 -04:00
/* allocation pointer is 'here'; its offset is hardcoded in the
2009-05-02 10:19:09 -04:00
compiler backends */
2009-05-04 05:50:24 -04:00
cell start;
cell here;
cell size;
cell end;
2009-05-02 10:19:09 -04:00
};
2009-05-02 05:04:19 -04:00
2009-05-04 05:50:24 -04:00
struct data_heap {
segment *seg;
2009-05-02 05:04:19 -04:00
2009-05-04 05:50:24 -04:00
cell young_size;
cell aging_size;
cell tenured_size;
2009-05-02 05:04:19 -04:00
2009-05-04 05:50:24 -04:00
cell gen_count;
2009-05-02 05:04:19 -04:00
2009-05-04 05:50:24 -04:00
zone *generations;
zone *semispaces;
2009-05-02 05:04:19 -04:00
2009-05-04 05:50:24 -04:00
cell *allot_markers;
cell *allot_markers_end;
2009-05-02 05:04:19 -04:00
2009-05-04 05:50:24 -04:00
cell *cards;
cell *cards_end;
2009-05-02 05:04:19 -04:00
2009-05-04 05:50:24 -04:00
cell *decks;
cell *decks_end;
/* the 0th generation is where new objects are allocated. */
cell nursery() { return 0; }
/* where objects hang around */
cell aging() { return gen_count - 2; }
/* the oldest generation */
cell tenured() { return gen_count - 1; }
bool have_aging_p() { return gen_count > 2; }
2009-05-02 10:19:09 -04:00
};
2009-05-02 05:04:19 -04:00
static const cell max_gen_count = 3;
2009-05-02 05:04:19 -04:00
2009-05-04 05:50:24 -04:00
inline static bool in_zone(zone *z, object *pointer)
2009-05-02 05:04:19 -04:00
{
2009-05-04 05:50:24 -04:00
return (cell)pointer >= z->start && (cell)pointer < z->end;
2009-05-02 05:04:19 -04:00
}
/* set up guard pages to check for under/overflow.
size must be a multiple of the page size */
segment *alloc_segment(cell size); // defined in OS-*.cpp files PD
2009-05-04 05:50:24 -04:00
void dealloc_segment(segment *block);
2009-05-02 05:04:19 -04:00
PRIMITIVE(data_room);
PRIMITIVE(size);
2009-05-02 05:04:19 -04:00
PRIMITIVE(begin_scan);
PRIMITIVE(next_object);
PRIMITIVE(end_scan);
2009-05-02 05:04:19 -04:00
2009-05-04 02:46:13 -04:00
}