Skip to content

Commit

Permalink
Explicitly use jl_taggedvalue_t instead of implicitly casting point…
Browse files Browse the repository at this point in the history
…ers.
  • Loading branch information
yuyichao committed Jun 12, 2016
1 parent 527e16e commit 7ac4128
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 72 deletions.
38 changes: 19 additions & 19 deletions src/gc-debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ static arraylist_t bits_save[4];
// freelist in pools
static void clear_mark(int bits)
{
jl_taggedvalue_t *pv;
if (!gc_verifying) {
for (int i = 0; i < 4; i++) {
bits_save[i].len = 0;
Expand All @@ -115,20 +114,21 @@ static void clear_mark(int bits)
v = jl_all_tls_states[i]->heap.big_objects;
while (v != NULL) {
void *gcv = &v->header;
if (!gc_verifying) arraylist_push(&bits_save[gc_bits(gcv)], gcv);
gc_bits(gcv) = bits;
if (!gc_verifying) arraylist_push(&bits_save[v->bits.gc], gcv);
v->bits.gc = bits;
v = v->next;
}
}

v = big_objects_marked;
while (v != NULL) {
void *gcv = &v->header;
if (!gc_verifying) arraylist_push(&bits_save[gc_bits(gcv)], gcv);
gc_bits(gcv) = bits;
if (!gc_verifying) arraylist_push(&bits_save[v->bits.gc], gcv);
v->bits.gc = bits;
v = v->next;
}

jl_taggedvalue_t *pv;
for (int h = 0; h < REGION_COUNT; h++) {
region_t *region = &regions[h];
if (!region->pages)
Expand All @@ -144,8 +144,8 @@ static void clear_mark(int bits)
pv = (jl_taggedvalue_t*)(pg->data + GC_PAGE_OFFSET);
char *lim = (char*)pv + GC_PAGE_SZ - GC_PAGE_OFFSET - pool->osize;
while ((char*)pv <= lim) {
if (!gc_verifying) arraylist_push(&bits_save[gc_bits(pv)], pv);
gc_bits(pv) = bits;
if (!gc_verifying) arraylist_push(&bits_save[pv->bits.gc], pv);
pv->bits.gc = bits;
pv = (jl_taggedvalue_t*)((char*)pv + pool->osize);
}
}
Expand All @@ -159,7 +159,7 @@ static void restore(void)
{
for(int b = 0; b < 4; b++) {
for(int i = 0; i < bits_save[b].len; i++) {
gc_bits(bits_save[b].items[i]) = b;
((jl_taggedvalue_t*)bits_save[b].items[i])->bits.gc = b;
}
}
}
Expand Down Expand Up @@ -221,7 +221,7 @@ void gc_verify(void)
int clean_len = bits_save[GC_CLEAN].len;
for(int i = 0; i < clean_len + bits_save[GC_QUEUED].len; i++) {
jl_taggedvalue_t *v = (jl_taggedvalue_t*)bits_save[i >= clean_len ? GC_QUEUED : GC_CLEAN].items[i >= clean_len ? i - clean_len : i];
if (gc_marked(v)) {
if (gc_marked(v->bits.gc)) {
jl_printf(JL_STDERR, "Error. Early free of %p type :", v);
jl_(jl_typeof(jl_valueof(v)));
jl_printf(JL_STDERR, "val : ");
Expand Down Expand Up @@ -347,7 +347,7 @@ static void gc_scrub_range(char *stack_lo, char *stack_hi)
char *p = *stack_p;
size_t osize;
jl_taggedvalue_t *tag = jl_gc_find_taggedvalue_pool(p, &osize);
if (osize <= sizeof(jl_taggedvalue_t) || !tag || gc_marked(tag))
if (osize <= sizeof(jl_taggedvalue_t) || !tag || gc_marked(tag->bits.gc))
continue;
jl_gc_pagemeta_t *pg = page_metadata(tag);
// Make sure the sweep rebuild the freelist
Expand Down Expand Up @@ -611,7 +611,7 @@ void gc_time_count_big(int old_bits, int bits)
{
big_total++;
big_reset += bits == GC_CLEAN;
big_freed += !(old_bits & GC_MARKED);
big_freed += !gc_marked(old_bits);
}

void gc_time_big_end(void)
Expand All @@ -636,7 +636,7 @@ void gc_time_mallocd_array_start(void)
void gc_time_count_mallocd_array(int bits)
{
mallocd_array_total++;
mallocd_array_freed += !(bits & GC_MARKED);
mallocd_array_freed += !gc_marked(bits);
}

void gc_time_mallocd_array_end(void)
Expand Down Expand Up @@ -735,12 +735,12 @@ static size_t pool_stats(jl_gc_pool_t *p, size_t *pwaste, size_t *np,
char *lim = (char*)v + GC_PAGE_SZ - GC_PAGE_OFFSET - osize;
int i = 0;
while ((char*)v <= lim) {
if (!gc_marked(v)) {
if (!gc_marked(v->bits.gc)) {
nfree++;
}
else {
nused++;
if (gc_bits(v) == GC_MARKED) {
if (v->bits.gc == GC_MARKED) {
nold++;
}
}
Expand Down Expand Up @@ -792,7 +792,7 @@ void gc_stats_big_obj(void)
bigval_t *v = current_heap->big_objects;
size_t nused=0, nbytes=0;
while (v != NULL) {
if (gc_marked(&v->_data)) {
if (gc_marked(v->bits.gc)) {
nused++;
nbytes += v->sz&~3;
}
Expand All @@ -801,7 +801,7 @@ void gc_stats_big_obj(void)
v = big_objects_marked;
size_t nused_old=0, nbytes_old=0;
while (v != NULL) {
if (gc_marked(&v->_data)) {
if (gc_marked(v->bits.gc)) {
nused_old++;
nbytes_old += v->sz&~3;
}
Expand All @@ -810,7 +810,7 @@ void gc_stats_big_obj(void)

mallocarray_t *ma = current_heap->mallocarrays;
while (ma != NULL) {
if (gc_marked(jl_astaggedvalue(ma->a))) {
if (gc_marked(jl_astaggedvalue(ma->a)->bits.gc)) {
nused++;
nbytes += array_nbytes(ma->a);
}
Expand All @@ -834,8 +834,8 @@ static void gc_count_pool_page(jl_gc_pagemeta_t *pg)
char *lim = (char*)v + GC_PAGE_SZ - GC_PAGE_OFFSET - osize;
int has_live = 0;
while ((char*)v <= lim) {
int bits = gc_bits(v);
if (bits & GC_MARKED)
int bits = v->bits.gc;
if (gc_marked(bits))
has_live = 1;
poolobj_sizes[bits] += osize;
v = (jl_taggedvalue_t*)((char*)v + osize);
Expand Down
Loading

0 comments on commit 7ac4128

Please sign in to comment.