| 77 |
77 |
#ifndef GC_MALLOC_LIMIT
|
| 78 |
78 |
#define GC_MALLOC_LIMIT 8000000
|
| 79 |
79 |
#endif
|
|
80 |
static unsigned int GC_MALLOC_LIMIT_VAL = GC_MALLOC_LIMIT;
|
| 80 |
81 |
|
| 81 |
82 |
#define nomem_error GET_VM()->special_exceptions[ruby_error_nomemory]
|
| 82 |
83 |
|
| ... | ... | |
| 285 |
286 |
#define HEAP_MIN_SLOTS 10000
|
| 286 |
287 |
#define FREE_MIN 4096
|
| 287 |
288 |
|
|
289 |
static unsigned int HEAP_MIN_SLOTS_VAL = HEAP_MIN_SLOTS;
|
|
290 |
|
| 288 |
291 |
struct gc_list {
|
| 289 |
292 |
VALUE *varptr;
|
| 290 |
293 |
struct gc_list *next;
|
| ... | ... | |
| 374 |
377 |
{
|
| 375 |
378 |
rb_objspace_t *objspace = malloc(sizeof(rb_objspace_t));
|
| 376 |
379 |
memset(objspace, 0, sizeof(*objspace));
|
| 377 |
|
malloc_limit = GC_MALLOC_LIMIT;
|
|
380 |
malloc_limit = GC_MALLOC_LIMIT_VAL;
|
| 378 |
381 |
ruby_gc_stress = ruby_initial_gc_stress;
|
| 379 |
382 |
|
| 380 |
383 |
return objspace;
|
| ... | ... | |
| 956 |
959 |
{
|
| 957 |
960 |
size_t add, i;
|
| 958 |
961 |
|
| 959 |
|
add = HEAP_MIN_SLOTS / HEAP_OBJ_LIMIT;
|
|
962 |
add = HEAP_MIN_SLOTS_VAL / HEAP_OBJ_LIMIT;
|
| 960 |
963 |
|
| 961 |
964 |
if (!add) {
|
| 962 |
965 |
add = 1;
|
| ... | ... | |
| 1918 |
1921 |
GC_PROF_SET_MALLOC_INFO;
|
| 1919 |
1922 |
if (malloc_increase > malloc_limit) {
|
| 1920 |
1923 |
malloc_limit += (size_t)((malloc_increase - malloc_limit) * (double)live / (live + freed));
|
| 1921 |
|
if (malloc_limit < GC_MALLOC_LIMIT) malloc_limit = GC_MALLOC_LIMIT;
|
|
1924 |
if (malloc_limit < GC_MALLOC_LIMIT_VAL) malloc_limit = GC_MALLOC_LIMIT_VAL;
|
| 1922 |
1925 |
}
|
| 1923 |
1926 |
malloc_increase = 0;
|
| 1924 |
1927 |
if (freed < free_min) {
|
| ... | ... | |
| 2981 |
2984 |
return UINT2NUM((&rb_objspace)->count);
|
| 2982 |
2985 |
}
|
| 2983 |
2986 |
|
|
2987 |
/*
|
|
2988 |
* call-seq:
|
|
2989 |
* GC.malloc_limit -> Integer
|
|
2990 |
*
|
|
2991 |
* The size of the malloc limit (minimum heap size).
|
|
2992 |
*
|
|
2993 |
* It returns the bare minimum size of the heap.
|
|
2994 |
*/
|
|
2995 |
|
|
2996 |
static VALUE
|
|
2997 |
gc_malloc_limit_get(VALUE self)
|
|
2998 |
{
|
|
2999 |
rb_objspace_t *objspace = &rb_objspace;
|
|
3000 |
return UINT2NUM(malloc_limit);
|
|
3001 |
}
|
|
3002 |
|
|
3003 |
/*
|
|
3004 |
*
|
|
3005 |
* call-seq:
|
|
3006 |
* GC.malloc_limit = integer -> Integer
|
|
3007 |
*
|
|
3008 |
* Updates the size of the malloc limit (minimum heap size).
|
|
3009 |
*
|
|
3010 |
* It returns the new bare minimum size of the heap.
|
|
3011 |
*/
|
|
3012 |
|
|
3013 |
static VALUE
|
|
3014 |
gc_malloc_limit_set(VALUE self, VALUE new_limit)
|
|
3015 |
{
|
|
3016 |
rb_objspace_t *objspace = &rb_objspace;
|
|
3017 |
malloc_limit = GC_MALLOC_LIMIT_VAL = NUM2UINT(new_limit);
|
|
3018 |
return new_limit;
|
|
3019 |
}
|
|
3020 |
|
|
3021 |
/*
|
|
3022 |
* call-seq:
|
|
3023 |
* GC.heap_min_slots -> Integer
|
|
3024 |
*
|
|
3025 |
* The minimum number of slots in each heap slab.
|
|
3026 |
*
|
|
3027 |
* It returns the number of slots to allocate for each heap slab.
|
|
3028 |
*/
|
|
3029 |
|
|
3030 |
static VALUE
|
|
3031 |
gc_heap_min_slots_get(VALUE self)
|
|
3032 |
{
|
|
3033 |
return UINT2NUM(HEAP_MIN_SLOTS_VAL);
|
|
3034 |
}
|
|
3035 |
|
|
3036 |
/*
|
|
3037 |
*
|
|
3038 |
* call-seq:
|
|
3039 |
* GC.heap_min_slots = integer -> Integer
|
|
3040 |
*
|
|
3041 |
* Updates the minimum number of slots in each heap slab.
|
|
3042 |
*
|
|
3043 |
* It returns the new number of slots to allocate for each heap slab.
|
|
3044 |
*/
|
|
3045 |
|
|
3046 |
static VALUE
|
|
3047 |
gc_heap_min_slots_set(VALUE self, VALUE new_num_slots)
|
|
3048 |
{
|
|
3049 |
HEAP_MIN_SLOTS_VAL = NUM2UINT(new_num_slots);
|
|
3050 |
return new_num_slots;
|
|
3051 |
}
|
|
3052 |
|
|
3053 |
|
| 2984 |
3054 |
#if CALC_EXACT_MALLOC_SIZE
|
| 2985 |
3055 |
/*
|
| 2986 |
3056 |
* call-seq:
|
| ... | ... | |
| 3147 |
3217 |
rb_define_singleton_method(rb_mGC, "stress", gc_stress_get, 0);
|
| 3148 |
3218 |
rb_define_singleton_method(rb_mGC, "stress=", gc_stress_set, 1);
|
| 3149 |
3219 |
rb_define_singleton_method(rb_mGC, "count", gc_count, 0);
|
|
3220 |
rb_define_singleton_method(rb_mGC, "malloc_limit", gc_malloc_limit_get, 0);
|
|
3221 |
rb_define_singleton_method(rb_mGC, "malloc_limit=", gc_malloc_limit_set, 1);
|
|
3222 |
rb_define_singleton_method(rb_mGC, "heap_slots", gc_heap_min_slots_get, 0);
|
|
3223 |
rb_define_singleton_method(rb_mGC, "heap_slots=", gc_heap_min_slots_set, 1);
|
| 3150 |
3224 |
rb_define_method(rb_mGC, "garbage_collect", rb_gc_start, 0);
|
| 3151 |
3225 |
|
| 3152 |
3226 |
rb_mProfiler = rb_define_module_under(rb_mGC, "Profiler");
|