Remove dead code and clean up formatting

This commit is contained in:
Justin Ethier 2018-07-18 13:31:02 -04:00
parent 91c67aee8b
commit 37bd321245

68
gc.c
View file

@ -555,7 +555,6 @@ gc_heap *gc_sweep_fixed_size(gc_heap * h, int heap_type, gc_thread_data *thd)
fprintf(stderr, "Heap %d diagnostics:\n", heap_type);
gc_print_stats(orig_heap_ptr);
#endif
//for (; h; prev_h = h, h = h->next) { // All heaps
if (h->data_end != NULL) {
// Special case, bump&pop heap
@ -576,7 +575,7 @@ gc_heap *gc_sweep_fixed_size(gc_heap * h, int heap_type, gc_thread_data *thd)
remaining -= h->block_size;
continue;
}
#if GC_SAFETY_CHECKS
#if GC_SAFETY_CHECKS
if (!is_object_type(p)) {
fprintf(stderr, "sweep: invalid object at %p", p);
exit(1);
@ -585,26 +584,26 @@ gc_heap *gc_sweep_fixed_size(gc_heap * h, int heap_type, gc_thread_data *thd)
fprintf(stderr, "sweep: invalid object tag %d at %p", type_of(p), p);
exit(1);
}
#endif
#endif
if (mark(p) != thd->gc_alloc_color &&
mark(p) != thd->gc_trace_color) { //gc_color_clear)
#if GC_DEBUG_VERBOSE
#if GC_DEBUG_VERBOSE
fprintf(stderr, "sweep is freeing unmarked obj: %p with tag %d\n", p,
type_of(p));
#endif
#endif
// Run finalizers
if (type_of(p) == mutex_tag) {
#if GC_DEBUG_VERBOSE
#if GC_DEBUG_VERBOSE
fprintf(stderr, "pthread_mutex_destroy from sweep\n");
#endif
#endif
if (pthread_mutex_destroy(&(((mutex) p)->lock)) != 0) {
fprintf(stderr, "Error destroying mutex\n");
exit(1);
}
} else if (type_of(p) == cond_var_tag) {
#if GC_DEBUG_VERBOSE
#if GC_DEBUG_VERBOSE
fprintf(stderr, "pthread_cond_destroy from sweep\n");
#endif
#endif
if (pthread_cond_destroy(&(((cond_var) p)->cond)) != 0) {
fprintf(stderr, "Error destroying condition variable\n");
exit(1);
@ -612,9 +611,9 @@ gc_heap *gc_sweep_fixed_size(gc_heap * h, int heap_type, gc_thread_data *thd)
} else if (type_of(p) == bignum_tag) {
// TODO: this is no good if we abandon bignum's on the stack
// in that case the finalizer is never called
#if GC_DEBUG_VERBOSE
#if GC_DEBUG_VERBOSE
fprintf(stderr, "mp_clear from sweep\n");
#endif
#endif
mp_clear(&(((bignum_type *)p)->bn));
}
@ -650,43 +649,11 @@ gc_heap *gc_sweep_fixed_size(gc_heap * h, int heap_type, gc_thread_data *thd)
heap_is_empty = 0;
}
}
// ck_pr_add_ptr(&(thd->cached_heap_free_sizes[heap_type]), heap_freed);
// Free the heap page if possible.
//
// With huge heaps, this becomes more important. one of the huge
// pages only has one object, so it is likely that the page
// will become free at some point and could be reclaimed.
//
// The newly created flag is used to attempt to avoid situtaions
// where a page is allocated because there is not enough free space,
// but then we do a sweep and see it is empty so we free it, and
// so forth. A better solution might be to keep empty heap pages
// off to the side and only free them if there is enough free space
// remaining without them.
//
// Experimenting with only freeing huge heaps
//if (heap_is_empty) {
// printf("heap %d %p is empty\n", h->type, h);
//}
if (heap_is_empty &&
(h->type == HEAP_HUGE || (h->ttl--) <= 0)) {
rv = NULL; // Let caller know heap needs to be freed
}
// if (heap_is_empty && !(h->ttl--)) {
// unsigned int h_size = h->size;
// gc_heap *new_h = gc_heap_free(h, prev_h);
// if (new_h) { // Ensure free succeeded
// h = new_h;
// ck_pr_sub_ptr(&(thd->cached_heap_free_sizes[heap_type] ), h_size);
// thd->cached_heap_total_sizes[heap_type] -= h_size;
// }
// }
// sum_freed += heap_freed;
// heap_freed = 0;
// }
#if GC_DEBUG_SHOW_SWEEP_DIAG
fprintf(stderr, "\nAfter sweep -------------------------\n");
@ -694,8 +661,6 @@ gc_heap *gc_sweep_fixed_size(gc_heap * h, int heap_type, gc_thread_data *thd)
gc_print_stats(orig_heap_ptr);
#endif
// if (sum_freed_ptr)
// *sum_freed_ptr = sum_freed;
return rv;
}
@ -731,9 +696,7 @@ gc_heap *gc_heap_free(gc_heap *page, gc_heap *prev_page)
/**
* @brief Determine if a heap page is empty.
* Note this only works for heaps that are not fixed-size.
* @param h Heap to inspect. The caller should acquire the necessary lock
* on this heap.
* @param h Heap to inspect. The caller should acquire any necessary locks.
* @return A truthy value if the heap is empty, 0 otherwise.
*/
int gc_is_heap_empty(gc_heap *h)
@ -741,7 +704,7 @@ int gc_is_heap_empty(gc_heap *h)
gc_free_list *f;
if (!h) return 0;
if (h->data_end) { // Bump&pop
if (h->data_end) { // Fixed-size bump&pop
return (h->remaining == (h->size - (h->size % h->block_size)));
}
@ -2502,12 +2465,7 @@ void gc_collector()
//clear :
ck_pr_cas_int(&gc_stage, STAGE_RESTING, STAGE_CLEAR_OR_MARKING);
// exchange values of markColor and clearColor
// old_clear = ck_pr_load_8(&gc_color_clear);
// old_mark = ck_pr_load_8(&gc_color_mark);
// while (!ck_pr_cas_8(&gc_color_clear, old_clear, old_mark)) {
// }
// while (!ck_pr_cas_8(&gc_color_mark, old_mark, old_clear)) {
// }
//
// We now increment both so that clear becomes the old mark color and a
// new value is used for the mark color. The old clear color becomes
// purple, indicating any of these objects are garbage