Module: GC
- Defined in:
- gc.c
Defined Under Namespace
Modules: Profiler
Constant Summary collapse
- INTERNAL_CONSTANTS =
Internal constants in the garbage collector.
gc_constants- OPTS =
GC build options
opts = rb_ary_new()
Class Method Summary collapse
-
.add_stress_to_class ⇒ Object
Raises NoMemoryError when allocating an instance of the given classes.
-
.auto_compact ⇒ Boolean
Returns whether or not automatic compaction has been enabled.
-
.auto_compact=(flag) ⇒ Object
Updates automatic compaction mode.
-
.compact ⇒ Object
This function compacts objects together in Ruby’s heap.
-
.latest_compact_info ⇒ Hash
Returns information about object moved in the most recent GC compaction.
-
.malloc_allocated_size ⇒ Integer
Returns the size of memory allocated by malloc().
-
.malloc_allocations ⇒ Integer
Returns the number of malloc() allocations.
-
.remove_stress_to_class ⇒ Object
No longer raises NoMemoryError when allocating an instance of the given classes.
-
.verify_compaction_references(*args) ⇒ Object
When !GC_COMPACTION_SUPPORTED, this method is not defined in gc.rb.
-
.verify_internal_consistency ⇒ nil
Verify internal consistency.
Class Method Details
.add_stress_to_class ⇒ Object
Raises NoMemoryError when allocating an instance of the given classes.
14215 14216 14217 14218 14219 14220 14221 14222 14223 14224 14225 |
# File 'gc.c', line 14215 static VALUE rb_gcdebug_add_stress_to_class(int argc, VALUE *argv, VALUE self) { rb_objspace_t *objspace = &rb_objspace; if (!stress_to_class) { set_stress_to_class(rb_ary_hidden_new(argc)); } rb_ary_cat(stress_to_class, argv, argc); return self; } |
.auto_compact ⇒ Boolean
Returns whether or not automatic compaction has been enabled.
11926 11927 11928 11929 11930 |
# File 'gc.c', line 11926 static VALUE gc_get_auto_compact(VALUE _) { return RBOOL(ruby_enable_autocompact); } |
.auto_compact=(flag) ⇒ Object
Updates automatic compaction mode.
When enabled, the compactor will execute on every major collection.
Enabling compaction will degrade performance on major collections.
11895 11896 11897 11898 11899 11900 11901 11902 11903 11904 11905 11906 11907 11908 11909 11910 11911 11912 11913 11914 |
# File 'gc.c', line 11895 static VALUE gc_set_auto_compact(VALUE _, VALUE v) { GC_ASSERT(GC_COMPACTION_SUPPORTED); ruby_enable_autocompact = RTEST(v); #if RGENGC_CHECK_MODE ruby_autocompact_compare_func = NULL; if (SYMBOL_P(v)) { ID id = RB_SYM2ID(v); if (id == rb_intern("empty")) { ruby_autocompact_compare_func = compare_free_slots; } } #endif return v; } |
.compact ⇒ Object
This function compacts objects together in Ruby’s heap. It eliminates unused space (or fragmentation) in the heap by moving objects in to that unused space. This function returns a hash which contains statistics about which objects were moved. See GC.latest_gc_info for details about compaction statistics.
This method is implementation specific and not expected to be implemented in any implementation besides MRI.
To test whether GC compaction is supported, use the idiom:
GC.respond_to?(:compact)
11118 11119 11120 11121 11122 11123 11124 11125 |
# File 'gc.c', line 11118 static VALUE gc_compact(VALUE self) { /* Run GC with compaction enabled */ gc_start_internal(NULL, self, Qtrue, Qtrue, Qtrue, Qtrue); return gc_compact_stats(self); } |
.latest_compact_info ⇒ Hash
Returns information about object moved in the most recent GC compaction.
The returned hash has two keys :considered and :moved. The hash for :considered lists the number of objects that were considered for movement by the compactor, and the :moved hash lists the number of objects that were actually moved. Some objects can’t be moved (maybe they were pinned) so these numbers can be used to calculate compaction efficiency.
11012 11013 11014 11015 11016 11017 11018 11019 11020 11021 11022 11023 11024 11025 11026 11027 11028 11029 11030 11031 11032 11033 11034 11035 11036 11037 11038 11039 11040 11041 11042 11043 11044 11045 11046 11047 |
# File 'gc.c', line 11012 static VALUE gc_compact_stats(VALUE self) { size_t i; rb_objspace_t *objspace = &rb_objspace; VALUE h = rb_hash_new(); VALUE considered = rb_hash_new(); VALUE moved = rb_hash_new(); VALUE moved_up = rb_hash_new(); VALUE moved_down = rb_hash_new(); for (i=0; i<T_MASK; i++) { if (objspace->rcompactor.considered_count_table[i]) { rb_hash_aset(considered, type_sym(i), SIZET2NUM(objspace->rcompactor.considered_count_table[i])); } if (objspace->rcompactor.moved_count_table[i]) { rb_hash_aset(moved, type_sym(i), SIZET2NUM(objspace->rcompactor.moved_count_table[i])); } if (objspace->rcompactor.moved_up_count_table[i]) { rb_hash_aset(moved_up, type_sym(i), SIZET2NUM(objspace->rcompactor.moved_up_count_table[i])); } if (objspace->rcompactor.moved_down_count_table[i]) { rb_hash_aset(moved_down, type_sym(i), SIZET2NUM(objspace->rcompactor.moved_down_count_table[i])); } } rb_hash_aset(h, ID2SYM(rb_intern("considered")), considered); rb_hash_aset(h, ID2SYM(rb_intern("moved")), moved); rb_hash_aset(h, ID2SYM(rb_intern("moved_up")), moved_up); rb_hash_aset(h, ID2SYM(rb_intern("moved_down")), moved_down); return h; } |
.malloc_allocated_size ⇒ Integer
Returns the size of memory allocated by malloc().
Only available if ruby was built with CALC_EXACT_MALLOC_SIZE.
13077 13078 13079 13080 13081 |
# File 'gc.c', line 13077 static VALUE gc_malloc_allocated_size(VALUE self) { return UINT2NUM(rb_objspace.malloc_params.allocated_size); } |
.malloc_allocations ⇒ Integer
Returns the number of malloc() allocations.
Only available if ruby was built with CALC_EXACT_MALLOC_SIZE.
13092 13093 13094 13095 13096 |
# File 'gc.c', line 13092 static VALUE gc_malloc_allocations(VALUE self) { return UINT2NUM(rb_objspace.malloc_params.allocations); } |
.remove_stress_to_class ⇒ Object
No longer raises NoMemoryError when allocating an instance of the given classes.
14235 14236 14237 14238 14239 14240 14241 14242 14243 14244 14245 14246 14247 14248 14249 14250 |
# File 'gc.c', line 14235 static VALUE rb_gcdebug_remove_stress_to_class(int argc, VALUE *argv, VALUE self) { rb_objspace_t *objspace = &rb_objspace; int i; if (stress_to_class) { for (i = 0; i < argc; ++i) { rb_ary_delete_same(stress_to_class, argv[i]); } if (RARRAY_LEN(stress_to_class) == 0) { set_stress_to_class(0); } } return Qnil; } |
.verify_compaction_references(*args) ⇒ Object
When !GC_COMPACTION_SUPPORTED, this method is not defined in gc.rb
489 490 491 492 493 |
# File 'vm_method.c', line 489 VALUE rb_f_notimplement(int argc, const VALUE *argv, VALUE obj, VALUE marker) { rb_f_notimplement_internal(argc, argv, obj); } |
.verify_internal_consistency ⇒ nil
Verify internal consistency.
This method is implementation specific. Now this method checks generational consistency if RGenGC is supported.
8182 8183 8184 8185 8186 8187 |
# File 'gc.c', line 8182 static VALUE gc_verify_internal_consistency_m(VALUE dummy) { gc_verify_internal_consistency(&rb_objspace); return Qnil; } |