This commit is contained in:
nilspolek 2024-01-28 22:19:26 +01:00
parent 815db27637
commit 219768d524
6 changed files with 5 additions and 5 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

10
njvm.c
View File

@ -336,7 +336,6 @@ int heapSizeKiB;
char *memTargetPtr; char *memTargetPtr;
char *freeHeapPtr; char *freeHeapPtr;
char *halfHeapPtr; char *halfHeapPtr;
int gcCount = 0;
#define MSB (1 << (8 * sizeof(unsigned int) - 1)) #define MSB (1 << (8 * sizeof(unsigned int) - 1))
#define IS_PRIMITIVE(objRef) (((objRef)->size & MSB) == 0) #define IS_PRIMITIVE(objRef) (((objRef)->size & MSB) == 0)
@ -348,7 +347,7 @@ ObjRef copyObjectToFreeMem(ObjRef orig) {
if (IS_PRIMITIVE(orig)) { if (IS_PRIMITIVE(orig)) {
size = GET_SIZE(orig); size = GET_SIZE(orig);
} else { } 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); memcpy(freeHeapPtr, orig, size);
ObjRef oldPtr = (ObjRef) freeHeapPtr; ObjRef oldPtr = (ObjRef) freeHeapPtr;
@ -369,7 +368,6 @@ ObjRef relocate(ObjRef orig) {
orig->forwardPointer = copy; orig->forwardPointer = copy;
} }
} }
return copy; return copy;
} }
@ -419,12 +417,14 @@ void garbageCollector() {
for (int i = 0; i < *sda.size; i++) { for (int i = 0; i < *sda.size; i++) {
sda.sda[i] = relocate(sda.sda[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) { if (purgeFlag) {
memset(memToPurgePtr, 0, heapSizeKiB * 1024 / 2); memset(memToPurgePtr, 0, heapSizeKiB * 1024 / 2);
} }
gcCount++;
} }
ObjRef alloc(unsigned int objectSize) { ObjRef alloc(unsigned int objectSize) {

BIN
njvm.o

Binary file not shown.