diff --git a/GC.c b/GC.c index 40b7e8e..b0c2f5d 100644 --- a/GC.c +++ b/GC.c @@ -27,73 +27,73 @@ struct stack stack; struct stack reg; -heapPartRef primary; -heapPartRef secondary; -unsigned int heapSize; -void initHeap(int size){ - heapSize = 2 * sizeof (unsigned int) + size; - if ((primary = malloc(heapSize)) == NULL) perror("malloc"); - if ((secondary = malloc(heapSize)) == NULL) perror("malloc"); -} - - -// nimmt obj und copier es in den secondary Speicher -void copy(ObjRef obj){ - if(obj->brokenHeart == true) return; - obj->brokenHeart = true; - if (IS_PRIMITIVE(obj)){ - 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((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]; -} +//heapPartRef primary; +//heapPartRef secondary; +//unsigned int heapSize; +//void initHeap(int size){ +// heapSize = 2 * sizeof (unsigned int) + size; +// if ((primary = malloc(heapSize)) == NULL) perror("malloc"); +// if ((secondary = malloc(heapSize)) == NULL) perror("malloc"); +//} +// +// +//// nimmt obj und copier es in den secondary Speicher +//void copy(ObjRef obj){ +// if(obj->brokenHeart == true) return; +// obj->brokenHeart = true; +// if (IS_PRIMITIVE(obj)){ +// 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((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 diff --git a/bigint/build/bin/testbip b/bigint/build/bin/testbip index d0cff75..085ed3a 100755 Binary files a/bigint/build/bin/testbip and b/bigint/build/bin/testbip differ diff --git a/bigint/build/lib/libbigint.a b/bigint/build/lib/libbigint.a index 66f30ba..76ad3c5 100644 Binary files a/bigint/build/lib/libbigint.a and b/bigint/build/lib/libbigint.a differ diff --git a/bigint/src/libbigint.a b/bigint/src/libbigint.a index 66f30ba..76ad3c5 100644 Binary files a/bigint/src/libbigint.a and b/bigint/src/libbigint.a differ diff --git a/bigint/tst/support.c b/bigint/tst/support.c index b036b1e..300fa4e 100644 --- a/bigint/tst/support.c +++ b/bigint/tst/support.c @@ -38,13 +38,13 @@ void fatalError(char *msg) { */ void * newPrimObject(int dataSize) { ObjRef bigObjRef; - - bigObjRef = malloc(sizeof(unsigned int) + - dataSize * sizeof(unsigned char)); + int size = sizeof(unsigned int) + dataSize * sizeof(unsigned char); + bigObjRef = malloc(size); + bigObjRef->size = size; if (bigObjRef == NULL) { fatalError("newPrimObject() got no memory"); } - bigObjRef->size = dataSize; + bigObjRef->size = size; return bigObjRef; } diff --git a/bigint/tst/support.o b/bigint/tst/support.o index dd5174c..f5bd62d 100644 Binary files a/bigint/tst/support.o and b/bigint/tst/support.o differ diff --git a/bigint/tst/testbip b/bigint/tst/testbip index d0cff75..085ed3a 100755 Binary files a/bigint/tst/testbip and b/bigint/tst/testbip differ diff --git a/debugMenu.c b/debugMenu.c index 6f15234..44a1602 100644 --- a/debugMenu.c +++ b/debugMenu.c @@ -18,7 +18,6 @@ void inspect(struct stack s, int fp){ if (input[0] == 'o'){ scanf("%19s",ref); ObjRefContainer container; - container = getRefs(s); for (int i = 0; i<= container.size; i++) { sprintf(refStr, "%p", (void *)&container.refs[i]); if(strcmp(ref, refStr) == 0) printf("Adress exists\n"); diff --git a/njvm.o b/njvm.o index b6ca96d..94e4322 100644 Binary files a/njvm.o and b/njvm.o differ diff --git a/record.c b/record.c index 2a2e34b..8435155 100644 --- a/record.c +++ b/record.c @@ -12,7 +12,7 @@ ObjRef newRecord(int size){ if((record = malloc(objSize)) == NULL){ perror("malloc"); } - record->size = (1 << ((sizeof(int) * 8) - 1)); + record->size = MSB; record->size = record->size + size; for(int i = 0; i < size; i++) { GET_REFS_PTR(record)[i] = NULL; @@ -33,11 +33,14 @@ void setField(ObjRef arr, int point, ObjRef value){ printf("Index %i out of bounds for length %i\n",point, getSize(arr)); } if(IS_PRIMITIVE(value)){ - int size = sizeof(*value); +// printf("Size of value is %i\n", value->size); + int size = value->size; GET_REFS_PTR(arr)[point] = malloc(size); + GET_REFS_PTR(arr)[point]->size = size; }else{ int size = sizeof(*value) + (GET_ELEMENT_COUNT(value) * sizeof(void *)); GET_REFS_PTR(arr)[point] = malloc(size); + GET_REFS_PTR(arr)[point] ->size = size; } * (ObjRef *)GET_REFS_PTR(arr)[point]->data = value; } diff --git a/stack.c b/stack.c index f7927a0..6925d71 100755 --- a/stack.c +++ b/stack.c @@ -39,20 +39,20 @@ void printStack(struct stack stack, int fp) { } } -ObjRefContainer getRefs(struct stack stack){ - ObjRefContainer continer; - int counter = 0; - for (int i = 0; i <= *stack.current; i++) { - if(stack.stack[i].isObjRef == true) counter++; - } - continer.size = counter; - ObjRef *list = (ObjRef *)malloc(counter * sizeof(ObjRef)); - for (int i = 0; i<= *stack.current; i++) - if(stack.stack[i].isObjRef == true) - list[counter--] = stack.stack[i].u.objRef; - continer.refs = list; - return continer; -} +//ObjRefContainer getRefs(struct stack stack){ +// ObjRefContainer continer; +// int counter = 0; +// for (int i = 0; i <= *stack.current; i++) { +// if(stack.stack[i].isObjRef == true) counter++; +// } +// continer.size = counter; +// ObjRef *list = (ObjRef *)malloc(counter * sizeof(ObjRef)); +// for (int i = 0; i<= *stack.current; i++) +// if(stack.stack[i].isObjRef == true) +// list[counter--] = stack.stack[i].u.objRef; +// continer.refs = list; +// return continer; +//} void push(struct stack s, StackSlot value) { if (*s.current >= *s.size) { diff --git a/stackslot.c b/stackslot.c index 24d2140..61dffb7 100644 --- a/stackslot.c +++ b/stackslot.c @@ -6,8 +6,6 @@ #define STACKSLOT typedef int Object; typedef struct ObjRef{ - bool brokenHeart; - struct ObjRef *forward_pointer; unsigned int size; unsigned char data[1]; } *ObjRef; @@ -27,7 +25,7 @@ ObjRef getIntObj(int val) { perror("malloc"); } *(int *) intObject->data = val; - intObject->size = sizeof(int); + intObject->size = objSize; return intObject; } @@ -43,7 +41,7 @@ int getIntValfromStackSlot(StackSlot s) { } void setValIntObj(ObjRef iref, int val) { - iref->size = sizeof(int); + iref->size = sizeof(int)+sizeof(ObjRef); *(int *) iref->data = val; } diff --git a/support.c b/support.c index 8032a60..cdd2d80 100644 --- a/support.c +++ b/support.c @@ -18,7 +18,7 @@ void * newPrimObject(int dataSize) { if (bigObjRef == NULL) { fatalError("newPrimObject() got no memory"); } - bigObjRef->size = dataSize; + bigObjRef->size = sizeof(unsigned int) + dataSize * sizeof(unsigned char); return bigObjRef; } diff --git a/support.o b/support.o index 32abf61..e0fc0d2 100644 Binary files a/support.o and b/support.o differ