Changed data structures for root management. Added ObjectScanner to abstract object scanning.

This commit is contained in:
beard%netscape.com 2002-01-10 22:21:52 +00:00
Родитель 7df3a4d014
Коммит 3e0c32db03
2 изменённых файлов: 28 добавлений и 10 удалений

Просмотреть файл

@ -47,13 +47,13 @@ Collector::~Collector()
}
void
Collector::addRoot(void* root, size_type n)
Collector::addRoot(pointer* root, size_type n)
{
mRoots.push_back(RootSegment(pointer(root), n));
mRoots.push_back(RootSegment(root, n));
}
void
Collector::removeRoot(void* root)
Collector::removeRoot(pointer* root)
{
for (RootSegments::iterator i = mRoots.begin(), e = mRoots.end(); i != e; ++i) {
if (i->first == root) {
@ -118,8 +118,8 @@ Collector::collect()
for (RootSegments::iterator i = mRoots.begin(), e = mRoots.end(); i != e; ++i) {
RootSegment& r = *i;
pointer* refs = (pointer*) r.first;
pointer* limit = (pointer*) (r.first + r.second);
pointer* refs = r.first;
pointer* limit = r.first + r.second;
while (refs < limit) {
pointer& ref = *refs++;
if (ref) {
@ -200,7 +200,7 @@ void testCollector()
Collector gc;
ConsCell* head = 0;
gc.addRoot(&head, sizeof(ConsCell*));
gc.addRoot(reinterpret_cast<Collector::pointer*>(&head));
const uint32 kCellCount = 100;

Просмотреть файл

@ -67,6 +67,20 @@ namespace JavaScript
typedef char *pointer;
typedef const char *const_pointer;
/**
* Abstract class used by clients of the collector to scan objects.
*/
class ObjectScanner {
public:
/**
* For each object associated with this scanner, the collector
* will call the scan method until it returns NULL. The return
* value should be a pointer to a slot in the object that
* contains a valid pointer or NULL.
*/
virtual pointer* scan(size_type& offset) = 0;
};
struct ObjectHeader {
size_type mSize;
pointer mType;
@ -75,8 +89,12 @@ namespace JavaScript
Collector();
~Collector();
void addRoot(void* root, size_type n);
void removeRoot(void* root);
/**
* Adds a root, which is required to be a densely packed array of pointers.
* Each element of a root array must contain either a valid pointer or NULL.
*/
void addRoot(pointer* root, size_type count = 1);
void removeRoot(pointer* root);
pointer allocateObject(size_type n, pointer type = 0);
float64* allocateFloat64(float64 value = 0.0);
@ -139,7 +157,7 @@ namespace JavaScript
Space<char> mObjectSpace;
Space<float64> mFloatSpace;
typedef pair<pointer, size_type> RootSegment;
typedef pair<pointer*, size_type> RootSegment;
typedef deque<RootSegment> RootSegments;
RootSegments mRoots;