return 1;
}
+#ifdef TASK
+struct pointerblock *taghead=NULL;
+int tagindex=0;
+
+void enqueuetag(struct ___TagDescriptor___ *ptr) {
+ if (tagindex==NUMPTRS) {
+ struct pointerblock * tmp=malloc(sizeof(struct pointerblock));
+ tmp->next=taghead;
+ taghead=tmp;
+ tagindex=0;
+ }
+ taghead->ptrs[tagindex++]=ptr;
+}
+#endif
+
+
void collect(struct garbagelist * stackptr) {
#ifdef THREADS
needtocollect=1;
tailindex=0;
head=tail=malloc(sizeof(struct pointerblock));
}
+
+#ifdef TASK
+ if (taghead==NULL) {
+ tagindex=0;
+ taghead=malloc(sizeof(struct pointerblock));
+ taghead->next=NULL;
+ }
+#endif
+
/* Check current stack */
#ifdef THREADS
{
struct listitem *listptr=list;
- while(stackptr!=NULL) {
+ while(1) {
#endif
while(stackptr!=NULL) {
listptr->locklist=copy;
stackptr=listptr->stackptr;
listptr=listptr->next;
- }
+ } else
+ break;
}
}
#endif
void * ptr=dequeue();
void *cpy=((void **)ptr)[1];
int type=((int *)cpy)[0];
- int * pointer=pointerarray[type];
+ int * pointer;
+#ifdef TASK
+ if(type==TAGTYPE) {
+ /* Enqueue Tag */
+ /* Nothing is inside */
+ enqueuetag(ptr);
+ continue;
+ }
+#endif
+ pointer=pointerarray[type];
if (pointer==0) {
/* Array of primitives */
/* Do nothing */
}
}
}
+#ifdef TASK
+ fixtags();
+#endif
+
#ifdef THREADS
needtocollect=0;
pthread_mutex_unlock(&gclistlock);
#endif
}
+#ifdef TASK
+void fixtags() {
+ while(taghead!=NULL) {
+ int i;
+ struct pointerblock *tmp=taghead->next;
+ for(i=0;i<tagindex;i++) {
+ struct ___TagDescriptor___ *tagd=taghead->ptrs[i];
+ struct ___Object___ *obj=tagd->flagptr;
+ struct ___TagDescriptor___ *copy=((struct ___TagDescriptor___**)tagd)[1];
+ if (obj->type==-1) {
+ /* Single object case */
+ copy->flagptr=((struct ___Object___**)obj)[1];
+ } else if (obj->type==OBJECTARRAYTYPE) {
+ /* Array case */
+ struct ArrayObject *ao=(struct ArrayObject *) obj;
+ int livecount=0;
+ int j;
+ int k=0;
+ struct ArrayObject *aonew;
+
+ /* Count live objects */
+ for(j=0;j<ao->___cachedCode___;j++) {
+ struct ___Object___ * tobj=ARRAYGET(ao, struct ___Object___ *, j);
+ if (tobj->type==-1)
+ livecount++;
+ }
+
+ livecount=((livecount-1)/OBJECTARRAYINTERVAL+1)*OBJECTARRAYINTERVAL;
+ aonew=(struct ArrayObject *) tomalloc(sizeof(struct ArrayObject)+sizeof(struct ___Object___*)*livecount);
+ aonew->type=OBJECTARRAYTYPE;
+ aonew->___length___=livecount;
+ copy->flagptr=aonew;
+ for(j=0;j<ao->___cachedCode___;j++) {
+ struct ___Object___ * tobj=ARRAYGET(ao, struct ___Object___ *, j);
+ if (tobj->type==-1) {
+ struct ___Object___ * tobjcpy=((struct ___Object___**)tobj)[1];
+ ARRAYSET(aonew, struct ___Object___*, k++,tobjcpy);
+ }
+ }
+ aonew->___cachedCode___=k;
+
+ } else {
+ /* No object live anymore */
+ copy->flagptr=NULL;
+ }
+ }
+ free(taghead);
+ taghead=tmp;
+ tagindex=NUMPTRS;
+ }
+}
+#endif
+
void * curr_heapbase=0;
void * curr_heapptr=0;
void * curr_heapgcpoint=0;
#include<stdio.h>
#include "option.h"
-#define ARRAYSET(array, type, index, value) \
-((type *)(&(& array->___length___)[1]))[index]=value
-
-#define ARRAYGET(array, type, index) \
-((type *)(&(& array->___length___)[1]))[index]
-
extern int classsize[];
jmp_buf error_handler;
int instructioncount;
return 1;
}
-#define TAGARRAYINTERVAL 10
-#define OBJECTARRAYINTERVAL 10
/* This function sets a tag. */
#ifdef PRECISE_GC
}
{
- struct ___Object___ * tagset=tagd->___tagset___;
+ struct ___Object___ * tagset=tagd->flagptr;
if(tagset==NULL) {
- tagd->___tagset___=obj;
+ tagd->flagptr=obj;
} else if (tagset->type!=OBJECTARRAYTYPE) {
#ifdef PRECISE_GC
int ptrarray[]={2, (int) ptr, (int) obj, (int)tagd};
#else
struct ArrayObject * ao=allocate_newarray(OBJECTARRAYTYPE,OBJECTARRAYINTERVAL);
#endif
- ARRAYSET(ao, struct ___Object___ *, 0, tagd->___tagset___);
+ ARRAYSET(ao, struct ___Object___ *, 0, tagd->flagptr);
ARRAYSET(ao, struct ___Object___ *, 1, obj);
ao->___cachedCode___=2;
- tagd->___tagset___=(struct ___Object___ *)ao;
+ tagd->flagptr=(struct ___Object___ *)ao;
} else {
struct ArrayObject *ao=(struct ArrayObject *) tagset;
if (ao->___cachedCode___<ao->___length___) {
struct ArrayObject * aonew=allocate_newarray(&ptrarray,OBJECTARRAYTYPE,OBJECTARRAYINTERVAL+ao->___length___);
obj=(struct ___Object___ *)ptrarray[2];
tagd=(struct ___TagDescriptor___ *)ptrarray[3];
- ao=(struct ArrayObject *)tagd->___tagset___;
+ ao=(struct ArrayObject *)tagd->flagptr;
#else
struct ArrayObject * aonew=allocate_newarray(OBJECTARRAYTYPE,OBJECTARRAYINTERVAL);
#endif
ARRAYSET(aonew, struct ___Object___*, i, ARRAYGET(ao, struct ___Object___*, i));
}
ARRAYSET(aonew, struct ___Object___ *, ao->___cachedCode___, obj);
- tagd->___tagset___=(struct ___Object___ *) ao;
+ tagd->flagptr=(struct ___Object___ *) ao;
}
}
}
}
PROCESSCLEAR:
{
- struct ___Object___ *tagset=tagd->___tagset___;
+ struct ___Object___ *tagset=tagd->flagptr;
if (tagset->type!=OBJECTARRAYTYPE) {
if (tagset==obj)
- tagd->___tagset___=NULL;
+ tagd->flagptr=NULL;
else
printf("ERROR 3 in tagclear\n");
} else {
ARRAYSET(ao, struct ___Object___ *, i, ARRAYGET(ao, struct ___Object___ *, ao->___cachedCode___));
ARRAYSET(ao, struct ___Object___ *, ao->___cachedCode___, NULL);
if (ao->___cachedCode___==0)
- tagd->___tagset___=NULL;
+ tagd->flagptr=NULL;
goto ENDCLEAR;
}
}
} else if (it->numtags>0) {
/* Use tags to locate appropriate objects */
struct ___TagDescriptor___ *tag=objectarray[it->tagbindings[0]];
- struct ___Object___ *objptr=tag->___tagset___;
+ struct ___Object___ *objptr=tag->flagptr;
int i;
if (objptr->type!=OBJECTARRAYTYPE) {
if (it->tagobjindex>0)
int containstag(struct ___Object___ *ptr, struct ___TagDescriptor___ *tag) {
int j;
- struct ___Object___ * objptr=tag->___tagset___;
+ struct ___Object___ * objptr=tag->flagptr;
if (objptr->type==OBJECTARRAYTYPE) {
struct ArrayObject *ao=(struct ArrayObject *)objptr;
for(j=0;j<ao->___cachedCode___;j++) {
} else if (it->numtags>0) {
/* Use tags to locate appropriate objects */
struct ___TagDescriptor___ *tag=objectarray[it->tagbindings[0]];
- struct ___Object___ *objptr=tag->___tagset___;
+ struct ___Object___ *objptr=tag->flagptr;
if (objptr->type!=OBJECTARRAYTYPE) {
it->tagobjindex++;
objectarray[it->slot]=objptr;