added some things to GC
This commit is contained in:
parent
91b36a53d5
commit
03b88a8a76
52
GC.c
52
GC.c
@ -12,9 +12,12 @@
|
||||
typedef struct {
|
||||
unsigned int freiZeiger;
|
||||
unsigned int size;
|
||||
ObjRef *data;
|
||||
unsigned char *data;
|
||||
} *heapPartRef;
|
||||
|
||||
// SDA
|
||||
struct sda sda;
|
||||
|
||||
// Stack
|
||||
struct stack stack;
|
||||
#define SIZE 64
|
||||
@ -38,15 +41,58 @@ void copy(ObjRef obj){
|
||||
if(obj->brokenHeart == true) return;
|
||||
obj->brokenHeart = true;
|
||||
if (IS_PRIMITIVE(obj)){
|
||||
obj->forward_pointer = memcpy(secondary->data[secondary->freiZeiger],obj,obj->size);
|
||||
if(obj->size > secondary->size-secondary->freiZeiger) perror("Heap is to Small");
|
||||
obj->forward_pointer = memcpy((void *) secondary->data[secondary->freiZeiger], obj, obj->size);
|
||||
secondary->freiZeiger += obj->size;
|
||||
} else {
|
||||
if(sizeof(*obj) + (GET_ELEMENT_COUNT(obj) * sizeof(void *)) > secondary->size-secondary->freiZeiger) perror("Heap is to Small");
|
||||
GET_ELEMENT_COUNT(obj);
|
||||
obj->forward_pointer = memcpy(secondary->data[secondary->freiZeiger],obj,sizeof(*obj) + (GET_ELEMENT_COUNT(obj) * sizeof(void *)));
|
||||
obj->forward_pointer = memcpy((void *) secondary->data[secondary->freiZeiger], obj, sizeof(*obj) + (GET_ELEMENT_COUNT(obj) * sizeof(void *)));
|
||||
secondary->freiZeiger += sizeof(*obj) + (GET_ELEMENT_COUNT(obj) * sizeof(void *));
|
||||
for (int i = 0; i < GET_ELEMENT_COUNT(obj); ++i) {
|
||||
copy(getField(obj,i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void runGC(){
|
||||
int rootSize = *sda.size + *reg.size + *stack.size + 4;
|
||||
ObjRef* rootObjs = malloc(sizeof(ObjRef) * rootSize);
|
||||
if(rootObjs == NULL) perror("malloc");
|
||||
int counter = 0;
|
||||
//Bip
|
||||
rootObjs[0] = bip.op1;
|
||||
rootObjs[counter++] = bip.op2;
|
||||
rootObjs[counter++] = bip.res;
|
||||
rootObjs[counter++] = bip.rem;
|
||||
//SDA
|
||||
for (int i = 0; i < *sda.size; ++i) {
|
||||
rootObjs[counter++] = sda.sda[i];
|
||||
}
|
||||
//REG
|
||||
for (int i = 0; i < *reg.size; ++i) {
|
||||
rootObjs[counter++] = reg.stack[i].u.objRef;
|
||||
}
|
||||
//STACK
|
||||
for (int i = 0; i < *stack.size; ++i) {
|
||||
rootObjs[counter++] = stack.stack[i].u.objRef;
|
||||
}
|
||||
|
||||
for (int i = 0; i < rootSize; ++i) {
|
||||
if(rootObjs[i] == NULL) continue;
|
||||
copy(rootObjs[i]);
|
||||
}
|
||||
heapPartRef temp = primary;
|
||||
primary = secondary;
|
||||
secondary = temp;
|
||||
|
||||
}
|
||||
|
||||
void *alloc(size_t size){
|
||||
if(primary->size-primary->freiZeiger < size){
|
||||
runGC();
|
||||
}
|
||||
primary->freiZeiger += size;
|
||||
return (void *) primary->data[primary->freiZeiger - size];
|
||||
}
|
||||
#endif
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3
njvm.c
3
njvm.c
@ -5,7 +5,6 @@
|
||||
#include "stack.c"
|
||||
#include "program.c"
|
||||
#include "codeReader.c"
|
||||
#include "SDA.c"
|
||||
#include "debugMenu.c"
|
||||
#include "bigint.h"
|
||||
#include "record.c"
|
||||
@ -311,7 +310,7 @@ int main(int argc, char *argv[]) {
|
||||
int current = 0;
|
||||
stack.size = &size;
|
||||
stack.current = ¤t;
|
||||
stack.stack = malloc(SIZE * 10024);
|
||||
stack.stack = malloc(SIZE * 1024);
|
||||
|
||||
// Initialize the registery
|
||||
int rSize = 1000;
|
||||
|
||||
2
record.c
2
record.c
@ -32,7 +32,7 @@ void setField(ObjRef arr, int point, ObjRef value){
|
||||
if(0 > point || point > getSize(arr)){
|
||||
printf("Index %i out of bounds for length %i\n",point, getSize(arr));
|
||||
}
|
||||
GET_REFS_PTR(arr)[point] = malloc(8);
|
||||
GET_REFS_PTR(arr)[point] = malloc(20);
|
||||
* (ObjRef *)GET_REFS_PTR(arr)[point]->data = value;
|
||||
}
|
||||
|
||||
|
||||
3
stack.c
3
stack.c
@ -9,8 +9,7 @@
|
||||
#include "stackslot.c"
|
||||
#include "sda.c"
|
||||
|
||||
// SDA
|
||||
struct sda sda;
|
||||
|
||||
|
||||
struct stack {
|
||||
int* size;
|
||||
|
||||
@ -22,7 +22,7 @@ typedef struct {
|
||||
|
||||
ObjRef getIntObj(int val) {
|
||||
ObjRef intObject;
|
||||
unsigned int objSize = sizeof(unsigned int) + sizeof(int);
|
||||
unsigned int objSize = sizeof(ObjRef) + sizeof(int);
|
||||
if ((intObject = malloc(objSize)) == NULL) {
|
||||
perror("malloc");
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user