Project

General

Profile

Bug #4547 ยป reflect_ruby_heap_min_slots.patch

authorNari (Narihiro Nakamura), 04/01/2011 05:46 PM

View differences:

gc.c
85 85
static unsigned int initial_heap_min_slots = HEAP_MIN_SLOTS;
86 86
static unsigned int initial_free_min       = FREE_MIN;
87 87

  
88
void
89
rb_gc_set_params(void)
90
{
91
    char *malloc_limit_ptr, *heap_min_slots_ptr, *free_min_ptr;
92

  
93
    if (rb_safe_level() > 0) return;
94

  
95
    malloc_limit_ptr = getenv("RUBY_GC_MALLOC_LIMIT");
96
    if (malloc_limit_ptr != NULL) {
97
	int malloc_limit_i = atoi(malloc_limit_ptr);
98
	printf("malloc_limit=%d (%d)\n", malloc_limit_i, initial_malloc_limit);
99
	if (malloc_limit_i > 0) {
100
	    initial_malloc_limit = malloc_limit_i;
101
	}
102
    }
103

  
104
    heap_min_slots_ptr = getenv("RUBY_HEAP_MIN_SLOTS");
105
    if (heap_min_slots_ptr != NULL) {
106
	int heap_min_slots_i = atoi(heap_min_slots_ptr);
107
	printf("heap_min_slots=%d (%d)\n", heap_min_slots_i, initial_heap_min_slots);
108
	if (heap_min_slots_i > 0) {
109
	    initial_heap_min_slots = heap_min_slots_i;
110
	}
111
    }
112

  
113
    free_min_ptr = getenv("RUBY_FREE_MIN");
114
    if (free_min_ptr != NULL) {
115
	int free_min_i = atoi(free_min_ptr);
116
	printf("free_min=%d (%d)\n", free_min_i, initial_free_min);
117
	if (free_min_i > 0) {
118
	    initial_free_min = free_min_i;
119
	}
120
    }
121
}
122

  
123 88
#define nomem_error GET_VM()->special_exceptions[ruby_error_nomemory]
124 89

  
125 90
#define MARK_STACK_MAX 1024
......
438 403
    return objspace;
439 404
}
440 405

  
406
static void initial_expand_heap(rb_objspace_t *objspace);
407

  
408
void
409
rb_gc_set_params(void)
410
{
411
    char *malloc_limit_ptr, *heap_min_slots_ptr, *free_min_ptr;
412

  
413
    if (rb_safe_level() > 0) return;
414

  
415
    malloc_limit_ptr = getenv("RUBY_GC_MALLOC_LIMIT");
416
    if (malloc_limit_ptr != NULL) {
417
	int malloc_limit_i = atoi(malloc_limit_ptr);
418
	printf("malloc_limit=%d (%d)\n", malloc_limit_i, initial_malloc_limit);
419
	if (malloc_limit_i > 0) {
420
	    initial_malloc_limit = malloc_limit_i;
421
	}
422
    }
423

  
424
    heap_min_slots_ptr = getenv("RUBY_HEAP_MIN_SLOTS");
425
    if (heap_min_slots_ptr != NULL) {
426
	int heap_min_slots_i = atoi(heap_min_slots_ptr);
427
	printf("heap_min_slots=%d (%d)\n", heap_min_slots_i, initial_heap_min_slots);
428
	if (heap_min_slots_i > 0) {
429
	    initial_heap_min_slots = heap_min_slots_i;
430
	}
431
    }
432

  
433
    free_min_ptr = getenv("RUBY_FREE_MIN");
434
    if (free_min_ptr != NULL) {
435
	int free_min_i = atoi(free_min_ptr);
436
	printf("free_min=%d (%d)\n", free_min_i, initial_free_min);
437
	if (free_min_i > 0) {
438
	    initial_free_min = free_min_i;
439
	}
440
    }
441
    initial_expand_heap(&rb_objspace);
442
}
443

  
441 444
static void gc_sweep(rb_objspace_t *);
442 445
static void slot_sweep(rb_objspace_t *, struct heaps_slot *);
443 446
static void gc_clear_mark_on_sweep_slots(rb_objspace_t *);
......
1032 1035
}
1033 1036

  
1034 1037
static void
1035
init_heap(rb_objspace_t *objspace)
1038
add_heap_slots(rb_objspace_t *objspace, int add)
1036 1039
{
1037
    size_t add, i;
1040
    int i;
1038 1041

  
1039
    add = initial_heap_min_slots / HEAP_OBJ_LIMIT;
1040

  
1041
    if (!add) {
1042
    if (add < 1) {
1042 1043
        add = 1;
1043 1044
    }
1044 1045

  
......
1049 1050
    for (i = 0; i < add; i++) {
1050 1051
        assign_heap_slot(objspace);
1051 1052
    }
1053
}
1054

  
1055
static void
1056
init_heap(rb_objspace_t *objspace)
1057
{
1058
    int add;
1059

  
1060
    add = HEAP_MIN_SLOTS / HEAP_OBJ_LIMIT;
1061
    add_heap_slots(objspace, add);
1062

  
1052 1063
    heaps_inc = 0;
1053 1064
    objspace->profile.invoke_time = getrusage_time();
1054 1065
    finalizer_table = st_init_numtable();
1055 1066
}
1056 1067

  
1057 1068
static void
1069
initial_expand_heap(rb_objspace_t *objspace)
1070
{
1071
    int add;
1072

  
1073
    add = ((initial_heap_min_slots / HEAP_OBJ_LIMIT) - heaps_used);
1074
    if (add > 0) {
1075
        add_heap_slots(objspace, add);
1076
    }
1077
}
1078

  
1079
static void
1058 1080
set_heaps_increment(rb_objspace_t *objspace)
1059 1081
{
1060 1082
    size_t next_heaps_length = (size_t)(heaps_used * 1.8);
......
2537 2559
    init_heap(&rb_objspace);
2538 2560
}
2539 2561

  
2540

  
2541 2562
static VALUE
2542 2563
lazy_sweep_enable(void)
2543 2564
{