gc
This commit is contained in:
parent
815db27637
commit
219768d524
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
10
njvm.c
10
njvm.c
@ -336,7 +336,6 @@ int heapSizeKiB;
|
||||
char *memTargetPtr;
|
||||
char *freeHeapPtr;
|
||||
char *halfHeapPtr;
|
||||
int gcCount = 0;
|
||||
|
||||
#define MSB (1 << (8 * sizeof(unsigned int) - 1))
|
||||
#define IS_PRIMITIVE(objRef) (((objRef)->size & MSB) == 0)
|
||||
@ -348,7 +347,7 @@ ObjRef copyObjectToFreeMem(ObjRef orig) {
|
||||
if (IS_PRIMITIVE(orig)) {
|
||||
size = GET_SIZE(orig);
|
||||
} else {
|
||||
size = sizeof(void *) + sizeof(unsigned int) + sizeof(bool) + GET_SIZE(orig) * sizeof(ObjRef *);
|
||||
size = sizeof(void *) + sizeof(unsigned int) + sizeof(bool) + (GET_SIZE(orig) * sizeof(void *));
|
||||
}
|
||||
memcpy(freeHeapPtr, orig, size);
|
||||
ObjRef oldPtr = (ObjRef) freeHeapPtr;
|
||||
@ -369,7 +368,6 @@ ObjRef relocate(ObjRef orig) {
|
||||
orig->forwardPointer = copy;
|
||||
}
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
@ -419,12 +417,14 @@ void garbageCollector() {
|
||||
for (int i = 0; i < *sda.size; i++) {
|
||||
sda.sda[i] = relocate(sda.sda[i]);
|
||||
}
|
||||
scan();
|
||||
|
||||
for (int i = 0; i < *reg.size; i++) {
|
||||
reg.stack[i].u.objRef = relocate(reg.stack[i].u.objRef);
|
||||
}
|
||||
scan();
|
||||
if (purgeFlag) {
|
||||
memset(memToPurgePtr, 0, heapSizeKiB * 1024 / 2);
|
||||
}
|
||||
gcCount++;
|
||||
}
|
||||
|
||||
ObjRef alloc(unsigned int objectSize) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user