Example #1
0
void *
heap_alloc_with_upper(size_t alloc_size)
{
    struct bitmap_info_space *b_info;
    void *obj;

    if(alloc_size > MAX_BLOCK_SIZE) {
#ifdef PRINT_ALLOC_TIME
        obj = sml_obj_malloc(alloc_size);
        if(obj != NULL) {
            count_alloc++;
            count_alloc_another++;
        }
        return obj;
#else /* PRINT_ALLOC_TIME */
        return sml_obj_malloc(alloc_size);
#endif /* PRINT_ALLOC_TIME */
    }

    b_info = MAPPING_HEAP_ALLOC_WITHOUT_UPPER(alloc_size);

    while((bitmap_info + THE_NUMBER_OF_FIXED_BLOCK) > b_info) {

#ifdef PRINT_ALLOC_TIME
        void * tmp_cur;
        unsigned int tmp_mask;

        tmp_cur = b_info->bitmap.cur;
        tmp_mask = b_info->bitmap.mask;
#endif

        if((TEST_BITPTR(b_info->bitmap))&&(search_bitptr(b_info) == -1)) {
            b_info->alloc_bitmap_info++;
            b_info = b_info->alloc_bitmap_info;
            DBG(("upper %p %u",b_info,b_info->block_size_bytes));
        } else {
#ifdef PRINT_ALLOC_TIME
            if((tmp_cur == b_info->bitmap.cur)&&(tmp_mask == b_info->bitmap.mask))
                print_info[b_info - bitmap_info].count_search[0]++;
            print_info[b_info - bitmap_info].count_alloc++;
            count_alloc++;
#endif /* PRINT_ALLOC_TIME */

            obj = b_info->next_obj;
            DBG(("find %u %p %x %p",alloc_size,b_info->bitmap.cur,b_info->bitmap.mask,obj));

            b_info->next_obj = (char *)(b_info->next_obj) + b_info->block_size_bytes;
            //SET_BITPTR(b_info->bitmap);
            SUCC_BITPTR(b_info->bitmap);

            return obj;
        }
    }

    return NULL;
}
Example #2
0
void *
heap_alloc(size_t alloc_size)
{
    struct bitmap_info_space *b_info;
    void *obj;

    if(alloc_size > MAX_BLOCK_SIZE) {
#ifdef PRINT_ALLOC_TIME
        obj = sml_obj_malloc(alloc_size);
        if(obj != NULL) {
            count_alloc++;
            count_alloc_another++;
        }
        return obj;
#else /* PRINT_ALLOC_TIME */
#ifdef GCSTAT
        sml_heap_malloced(alloc_size);
#endif /* GCSTAT */
        return sml_obj_malloc(alloc_size);
#endif /* PRINT_ALLOC_TIME */
    }

    b_info = MAPPING_HEAP_ALLOC(alloc_size);

#ifdef GCSTAT
    if(!TEST_BITPTR(b_info->bitmap))
        sml_heap_fast_alloced(b_info);
#endif /* GCSTAT */

    if(TEST_BITPTR(b_info->bitmap)) {
        if(search_bitptr(b_info) == -1) return NULL;
#ifdef GCSTAT
        sml_heap_find_alloced(b_info);
#endif /* GCSTAT */
    }
#ifdef PRINT_ALLOC_TIME
    else {
        print_info[b_info - bitmap_info].count_search[0]++;
    }
    print_info[b_info - bitmap_info].count_alloc++;
    count_alloc++;
#endif /* PRINT_ALLOC_TIME */

    obj = b_info->next_obj;
    DBG(("find %u %p %x %p",alloc_size,b_info->bitmap.cur,b_info->bitmap.mask,obj));

    b_info->next_obj = (char *)(b_info->next_obj) + b_info->block_size_bytes;
    //SET_BITPTR(b_info->bitmap);
    SUCC_BITPTR(b_info->bitmap);

    return obj;
}
Example #3
0
SML_PRIMITIVE NOINLINE void *
sml_alloc(unsigned int objsize)
{
	/* objsize = payload_size + bitmap_size */
	void *obj;
	size_t inc = HEAP_ROUND_SIZE(OBJ_HEADER_SIZE + objsize);

#ifdef FAIR_COMPARISON
	if (inc > 4096) {
		SAVE_FP();
		return sml_obj_malloc(inc);
	}
#endif /* FAIR_COMPARISON */

	GIANT_LOCK();

	obj = sml_heap_from_space.free;
	if ((size_t)(sml_heap_from_space.limit - (char*)obj) >= inc) {
		sml_heap_from_space.free += inc;
#ifdef GC_STAT
		sml_heap_alloced(inc);
#endif /* GC_STAT */
		GIANT_UNLOCK();
	} else {
		SAVE_FP();
		obj = slow_alloc(inc);
	}

#ifndef FAIR_COMPARISON
	OBJ_HEADER(obj) = 0;
#endif /* FAIR_COMPARISON */
	return obj;
}
Example #4
0
SML_PRIMITIVE void *
sml_alloc(unsigned int objsize, void *frame_pointer)
{
	sml_save_frame_pointer(frame_pointer);
	return sml_obj_malloc(objsize);
}
Example #5
0
SML_PRIMITIVE void *
sml_alloc(unsigned int objsize, void *frame_pointer)
{
	size_t alloc_size;
	unsigned int blocksize_log2;
	struct alloc_ptr *ptr;
	void *obj;


	/* ensure that alloc_size is at least BLOCKSIZE_MIN. */
	alloc_size = ALIGNSIZE(OBJ_HEADER_SIZE + objsize, BLOCKSIZE_MIN);

	if (alloc_size > BLOCKSIZE_MAX) {
		GCSTAT_ALLOC_COUNT(malloc, 0, alloc_size);
		sml_save_frame_pointer(frame_pointer);
		return sml_obj_malloc(alloc_size);
	}

	blocksize_log2 = CEIL_LOG2(alloc_size);
	ASSERT(BLOCKSIZE_MIN_LOG2 <= blocksize_log2
	       && blocksize_log2 <= BLOCKSIZE_MAX_LOG2);

	ptr = &ALLOC_PTR_SET()->alloc_ptr[blocksize_log2];

	if (!BITPTR_TEST(ptr->freebit)) {
		GCSTAT_ALLOC_COUNT(fast, blocksize_log2, alloc_size);
		BITPTR_INC(ptr->freebit);
		obj = ptr->free;
		ptr->free += ptr->blocksize_bytes;
		goto alloced;
	}

	sml_save_frame_pointer(frame_pointer);

	if (ptr->free != NULL) {
		obj = find_bitmap(ptr);
		if (obj) goto alloced;
	}
	obj = find_segment(ptr);
	if (obj) goto alloced;

	GCSTAT_TRIGGER(blocksize_log2);
	do_gc(MAJOR);
	obj = find_segment(ptr);
	if (obj) goto alloced_major;

	extend_heap(heap_space.extend_step);
	obj = find_segment(ptr);
	if (obj) goto alloced_major;

	sml_fatal(0, "heap exceeded: intended to allocate %u bytes.",
		  ptr->blocksize_bytes);

 alloced_major:
	ASSERT(check_newobj(obj));
	/* NOTE: sml_run_finalizer may cause garbage collection. */
	obj = sml_run_finalizer(obj);
	goto finished;
 alloced:
	ASSERT(check_newobj(obj));
 finished:
	OBJ_HEADER(obj) = 0;
	return obj;
}