Skip to content
Snippets Groups Projects
Commit b51e6d18 authored by Fredrik Hübinette (Hubbe)'s avatar Fredrik Hübinette (Hubbe)
Browse files

locate_references added for debugging perposes

Rev: src/gc.c:1.28
parent 091f7892
Branches
Tags
No related merge requests found
...@@ -378,21 +378,43 @@ INT32 gc_check(void *a) ...@@ -378,21 +378,43 @@ INT32 gc_check(void *a)
return getmark(a)->refs++; return getmark(a)->refs++;
} }
int gc_is_referenced(void *a) static void init_gc(void)
{ {
struct marker *m; INT32 tmp3;
m=getmark(a); /* init hash , hashsize will be a prime between num_objects/8 and
#ifdef DEBUG * num_objects/4, this will assure that no re-hashing is needed.
if(m->refs + m->xrefs > *(INT32 *)a) */
tmp3=my_log2(num_objects);
if(!d_flag) tmp3-=2;
if(tmp3<0) tmp3=0;
if(tmp3>=(long)NELEM(hashprimes)) tmp3=NELEM(hashprimes)-1;
hashsize=hashprimes[tmp3];
hash=(struct marker **)xalloc(sizeof(struct marker **)*hashsize);
MEMSET((char *)hash,0,sizeof(struct marker **)*hashsize);
markers_left_in_chunk=0;
}
static void exit_gc(void)
{ {
INT32 refs=m->refs; struct marker_chunk *m;
INT32 xrefs=m->xrefs; /* Free hash table */
TYPE_T t=attempt_to_identify(a); free((char *)hash);
while((m=chunk))
{
chunk=m->next;
free((char *)m);
}
}
fprintf(stderr,"**Something has %ld references, while gc() found %ld + %ld external.\n",(long)*(INT32 *)a,(long)refs,(long)xrefs); void locate_references(void *a)
describe_something(a, t); {
if(!in_gc)
init_gc();
fprintf(stderr,"**Looking for references:\n"); fprintf(stderr,"**Looking for references:\n");
check_for=a; check_for=a;
found_where=" in an array"; found_where=" in an array";
...@@ -416,6 +438,26 @@ int gc_is_referenced(void *a) ...@@ -416,6 +438,26 @@ int gc_is_referenced(void *a)
found_where=""; found_where="";
check_for=0; check_for=0;
if(!in_gc)
exit_gc();
}
int gc_is_referenced(void *a)
{
struct marker *m;
m=getmark(a);
#ifdef DEBUG
if(m->refs + m->xrefs > *(INT32 *)a)
{
INT32 refs=m->refs;
INT32 xrefs=m->xrefs;
TYPE_T t=attempt_to_identify(a);
fprintf(stderr,"**Something has %ld references, while gc() found %ld + %ld external.\n",(long)*(INT32 *)a,(long)refs,(long)xrefs);
describe_something(a, t);
locate_references(a);
fatal("Ref counts are wrong (has %d, found %d + %d external)\n", fatal("Ref counts are wrong (has %d, found %d + %d external)\n",
*(INT32 *)a, *(INT32 *)a,
refs, refs,
...@@ -474,8 +516,7 @@ int gc_do_free(void *a) ...@@ -474,8 +516,7 @@ int gc_do_free(void *a)
void do_gc(void) void do_gc(void)
{ {
double tmp; double tmp;
INT32 tmp2,tmp3; INT32 tmp2;
struct marker_chunk *m;
double multiplier; double multiplier;
if(in_gc) return; if(in_gc) return;
...@@ -507,19 +548,7 @@ void do_gc(void) ...@@ -507,19 +548,7 @@ void do_gc(void)
objects_freed += (double) num_objects; objects_freed += (double) num_objects;
/* init hash , hashsize will be a prime between num_objects/8 and init_gc();
* num_objects/4, this will assure that no re-hashing is needed.
*/
tmp3=my_log2(num_objects);
if(!d_flag) tmp3-=2;
if(tmp3<0) tmp3=0;
if(tmp3>=(long)NELEM(hashprimes)) tmp3=NELEM(hashprimes)-1;
hashsize=hashprimes[tmp3];
hash=(struct marker **)xalloc(sizeof(struct marker **)*hashsize);
MEMSET((char *)hash,0,sizeof(struct marker **)*hashsize);
markers_left_in_chunk=0;
/* First we count internal references */ /* First we count internal references */
gc_check_all_arrays(); gc_check_all_arrays();
...@@ -546,14 +575,7 @@ void do_gc(void) ...@@ -546,14 +575,7 @@ void do_gc(void)
gc_free_all_unreferenced_programs(); gc_free_all_unreferenced_programs();
gc_free_all_unreferenced_objects(); gc_free_all_unreferenced_objects();
exit_gc();
/* Free hash table */
free((char *)hash);
while((m=chunk))
{
chunk=m->next;
free((char *)m);
}
destruct_objects_to_destruct(); destruct_objects_to_destruct();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment