Exemple #1
0
static void
heap_space_init(struct heap_space *heap, size_t size)
{
	if (size < INITIAL_OFFSET)
		size = INITIAL_OFFSET;
	heap_space_alloc(heap, size);
	heap_space_clear(heap);
}
Exemple #2
0
static void
do_gc(void)
{
#ifdef GCTIME
	sml_timer_t b_start, b_end;
	sml_time_t gctime;
#endif /* GCTIME */
#ifdef GCSTAT
	sml_time_t t;
#endif /* GCSTAT */

	STOP_THE_WORLD();

#ifdef GCSTAT
	if (gcstat.verbose >= GCSTAT_VERBOSE_COUNT) {
		stat_notice("---");
		stat_notice("event: start gc");
		stat_notice("trigger: %u", gcstat.last.trigger);
		print_alloc_count();
		print_heap_occupancy();
	}
	clear_last_counts();
#endif /* GCSTAT */

#ifdef GCTIME
	gcstat.gc.count++;
	sml_timer_now(b_start);
#endif /* GCTIME */

	heap_space_unprotect(&sml_heap_to_space);

	DBG(("start gc (%lu/%lu used) %p -> %p",
	     (unsigned long)HEAP_USED(sml_heap_from_space),
	     (unsigned long)HEAP_TOTAL(sml_heap_from_space),
	     sml_heap_from_space.base, sml_heap_to_space.base));

	sml_rootset_enum_ptr(forward, MAJOR);

	DBG(("copying root completed"));

	/* forward objects which are reachable from live objects. */
	forward_region(HEAP_START(sml_heap_to_space));

	sml_malloc_pop_and_mark(forward_deep, MAJOR);

#ifndef FAIR_COMPARISON
	/* check finalization */
	sml_check_finalizer(forward_deep, MAJOR);
#endif /* FAIR_COMPARISON */

	/* clear from-space, and swap two spaces. */
	heap_space_clear(&sml_heap_from_space);
	heap_space_swap();
	heap_space_protect(&sml_heap_to_space);

	/* sweep malloc heap */
	sml_malloc_sweep(MAJOR);

	DBG(("gc finished. remain %lu bytes",
	     (unsigned long)HEAP_USED(sml_heap_from_space)));

#ifdef GCTIME
	sml_timer_now(b_end);
#endif /* GCTIME */

#ifdef GCTIME
	sml_timer_dif(b_start, b_end, gctime);
	sml_time_accum(gctime, gcstat.gc.total_time);
#endif /* GCTIME */
#ifdef GCSTAT
	gcstat.gc.total_copy_bytes += gcstat.last.copy_bytes;
	gcstat.gc.total_copy_count += gcstat.last.copy_count;
	gcstat.gc.total_forward_count += gcstat.last.forward_count;
	if (gcstat.verbose >= GCSTAT_VERBOSE_GC) {
		sml_timer_dif(gcstat.exec_begin, b_start, t);
		stat_notice("time: "TIMEFMT, TIMEARG(t));
		stat_notice("---");
		stat_notice("event: end gc");
		sml_timer_dif(gcstat.exec_begin, b_end, t);
		stat_notice("time: "TIMEFMT, TIMEARG(t));
		stat_notice("duration: "TIMEFMT, TIMEARG(gctime));
		stat_notice("copy: %u", gcstat.last.copy_count);
		stat_notice("forward: %u", gcstat.last.forward_count);
		stat_notice("copy_bytes: %lu",
			    (unsigned long)gcstat.last.copy_bytes);
		print_heap_occupancy();
	}
#endif /* GCSTAT */

	RUN_THE_WORLD();
}
Exemple #3
0
void
sml_heap_init(size_t size, size_t max_size ATTR_UNUSED)
{
#ifdef PRINT_ALLOC_TIME
    arranged = size;

    double st;
    getRusage(st);
#endif /* PRINT_ALLOC_TIME */

    void *stack_bottom;

#ifdef GCSTAT
    {
        const char *env;
        env = getenv("SMLSHARP_GCSTAT_FILE");
        if (env) {
            gcstat.file = fopen(env, "w");
            if (gcstat.file == NULL) {
                perror("sml_heap_init");
                abort();
            }
            stat_notice = gcstat_print;
        }
        env = getenv("SMLSHARP_GCSTAT_VERBOSE");
        if (env)
            gcstat.verbose = strtol(env, NULL, 10);
        else
            gcstat.verbose = GCSTAT_VERBOSE_MAX;
        env = getenv("SMLSHARP_GCSTAT_PROBE");
        if (env) {
            gcstat.probe_threshold = strtol(env, NULL, 10);
            if (gcstat.probe_threshold == 0)
                gcstat.probe_threshold = size;
        } else {
            gcstat.probe_threshold = 2 * 1024 * 1024;
        }
    }
#endif /* GCSTAT */

#ifdef GCTIME
    sml_timer_now(gcstat.exec_begin);
#endif /* GCTIME */

    major_heap.base = xmalloc(size);
    major_heap.size = size;
    heap_space_clear();
    stack_bottom = make_bitmap_information(size);

    if((char *)marking_stack_init(stack_bottom) >= (char *)major_heap.limit)
        sml_fatal(0,"heap size over");

    DBG(("heap space init %p %p %u",major_heap.base,major_heap.limit,major_heap.size));

#ifdef PRINT_ALLOC_TIME
    double en;
    getRusage(en);
    init_time = (en - st);

    fp_at = stderr;
    if(fp_at == NULL) sml_fatal(0,"can not open print alloc file");
    print_info_init();
#endif /* PRINT_ALLOC_TIME */

#ifdef GCSTAT
    {
        unsigned int i;
        stat_notice("---");
        stat_notice("event: init");
        stat_notice("time: 0.0");
        stat_notice("heap_size: %lu", (unsigned long)size);
        stat_notice("config:");
        for (i = 0; i < THE_NUMBER_OF_FIXED_BLOCK; i++)
            stat_notice(" %lu: {size: %lu, num_slots: %lu, bitmap_size: %lu}",
                        (unsigned long)bitmap_info[i].block_size_bytes,
                        (unsigned long)heap_layout[i].total_size,
                        (unsigned long)heap_layout[i].block_counts,
                        (unsigned long)heap_layout[i].bitmap_and_tree_size);
        stat_notice("stack_size: %lu", (unsigned long)marking_stack.size);
        stat_notice("counters:");
        stat_notice(" heap: [fast, find, next, new]");
        stat_notice(" other: [malloc]");
        print_heap_occupancy();
    }
#endif /* GCSTAT */
}