* vm_core.h (rb_thread_struct): aggregate cpu stuff into a struct,
so that a debugger can show its content at once.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44722 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
RUBY_FREE_MIN/RUBY_HEAP_MIN_SLOTS if
RUBY_GC_HEAP_FREE_SLOTS/RUBY_GC_HEAP_INIT_SLOTS are given.
[Bug #9276]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44327 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (heap_get_freeobj_from_next_freepage): replace with
heap_get_freepage(). It returns freeobj instead of freepage.
This is not on hot path.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44287 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (heap_get_freeobj): remove redundant assignment. heap->freelist
is set after the while() loop already.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44282 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
can be OR of multiple reasons.
* gc.c (gc_profile_dump_on): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44278 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c: check objspace->profile.current_record before inserting
profiling record by new macro gc_prof_enabled().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44276 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (gc_finalize_deferred_register): define in prototype style,
instead of old K&R style.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44256 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
internal data structure.
Now this method only checks geneartion (old/young) consistency.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44228 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (gc_info_decode): Use :major_by=>:nofree as fallback reason
when other trigger conditions are present.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44171 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (wmap_mark): disable deletion of dead objects by default,
so that WeakMap can be non-shady.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44149 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (wmap_keys): return keys for live objects only, like as
wmap_values.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44142 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (wmap_aset): use st_update instead of st_lookup and
st_insert.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44118 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (wmap_aset): check if both arguments are able to finalize
before setting finalizers.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44108 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/objspace/objspace_dump.c (dump_object): include fstring flag on
strings. include gc flags (old, remembered, wb_protected) on all objects.
* ext/objspace/objspace_dump.c (Init_objspace_dump): initialize lazy
IDs before first use.
* gc.c (rb_obj_gc_flags): new function to retrieve object flags
* internal.h (RB_OBJ_GC_FLAGS_MAX): maximum flags allowed for one obj
* test/objspace/test_objspace.rb (test_dump_flags): test for above
* test/objspace/test_objspace.rb (test_trace_object_allocations):
resolve name before dump (for rb_class_path_cached)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44105 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Increase oldmalloc_increase with malloc_increase
instead of using obj_memsize_of().
This change will avoid the danger of memory full without major GC.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44040 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
oldmalloc_increase_limit at Init_heap.
rb_objspace_alloc() is not called on some platforms.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44038 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
care about underflow.
* gc.c (objspace_malloc_increase): use it.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44036 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* vm_insnhelper.c (rb_get_kwargs): get keyword argument values from an
option hash, not only checking keys.
* dir.c (dir_initialize): use rb_get_kwargs.
* gc.c (gc_start_internal): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44035 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
heap_pages_free_unused_pages() here.
It was done in after_sweep().
* gc.c (rb_gc): The reason is now GPR_FLAG_CAPI.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44029 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (gc_start_internal): GC.start() now accepts two optional
keyword arguments. These can be used to disable full_mark (minor
mark only) or disable immediate_sweep (use lazy sweep). These new
options are useful for benchmarking GC behavior, or performing minor
GC out-of-band.
* test/ruby/test_gc.rb (class TestGc): tests for new options.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44027 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (struct rb_objspace): rename internal last_collection_flags to
latest_gc_info
* gc.c (gc_latest_collection_info): add GC.latest_gc_info() with similar
behavior to GC.stat()
* gc.c (rb_gc_latest_gc_info): new c-api for above
* gc.c (gc_stat_internal): remove :last_collection_flags from GC.stat
* gc.c (gc_profile_decode_flags): remove GC::Profiler.decode_flags
* include/ruby/intern.h (rb_gc_latest_gc_info): export new c-api
* test/ruby/test_gc.rb (class TestGc): test for new behavior
* NEWS: note about new api
* gc.c (gc_stat_internal): raise TypeError on wrong type
* gc.c (gc_stat): fix error message
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44008 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* include/ruby/intern.h: add rb_gc_stat() for access to GC.stat
variables from c-api
* gc.c (rb_gc_stat): new c-api method. accepts either VALUE hash like
GC.stat, or VALUE symbol key and returns size_t directly. the second
form is useful to avoid allocations, i.e. for usage inside
INTERNAL_EVENT_GC tracepoints.
* gc.c (gc_stat): add GC.stat(:key) to return single value instead of hash
* gc.c (gc_stat_internal): helper method to retrieve single or all stat values
* test/ruby/test_gc.rb (class TestGc): test for new behavior
* NEWS: note about this new api
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44005 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
return malloc_usable_size() if possible.
* gc.c (MALLOC_ALLOCATED_SIZE): add new setting macro to enable
GC.allocated_size.
If platform supports `malloc_usable_size()' (or similar one),
GC.allocated_size can be implemented with this function.
Default is 0.
* gc.c (vm_xmalloc, vm_xrealloc, vm_xfree): use vm_malloc_size()
to detect collect allocated size.
* gc.c (vm_malloc_increase): refactoring.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43998 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* include/ruby/ruby.h: remove INTERNAL_EVENT_GC_END and replace with
two new events: GC_END_MARK and GC_END_SWEEP
* gc.c (gc_after_sweep): emit GC_END_SWEEP after lazy sweep is done
* gc.c (gc_marks_body): emit GC_END_MARK at end of minor/major mark
* ext/-test-/tracepoint/tracepoint.c (struct tracepoint_track): tests
for new events.
* test/-ext-/tracepoint/test_tracepoint.rb (class TestTracepointObj):
ditto.
* NEWS: remove ObjectSpace.after_gc_*_hook. These are only a sample,
and will be removed before ruby 2.1.
* ext/objspace/gc_hook.c: remove ObjectSpace.after_gc_end_hook=
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43997 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (finalize_deferred): flush all deferred finalizers while other
finalizers can get ready to run newly by lazy sweep.
[ruby-core:58833] [Bug #9205]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43994 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (rb_gc_set_params): define as separate function.
RUBY_ALIAS_FUNCTION is for simple alias only, the third parameter
will be ignored on gcc.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43993 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (ruby_gc_set_params): Accept safe_level argument so GC tuning
settings can be applied before rb_safe_level() is available.
* internal.h (rb_gc_set_params): ditto.
* ruby.c (process_options): Apply GC tuning early during boot process
so boot-time allocations can benefit. This also benefits any code
loaded in via `ruby -r`.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43991 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* configure.in: check malloc_size() available on BSD.
* gc.c: use malloc_size() with malloc/malloc.h on BSD.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43983 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
RClass->m_tbl with serial. This prevents double marking method
tables, since many classes/modules can share the same method table.
This improves minor mark time in a large application by 30%.
* internal.h (struct method_table_wrapper): Define new
wrapper struct with additional serial.
* internal.h (RCLASS_M_TBL_INIT): New macro for initializing method
table wrapper and st_table.
* method.h (void rb_sweep_method_entry): Rename rb_free_m_table to
rb_free_m_tbl for consistentcy
* .gdbinit (define rb_method_entry): Update rb_method_entry gdb helper
for new method table structure.
* class.c: Use RCLASS_M_TBL_WRAPPER and
RCLASS_M_TBL_INIT macros.
* class.c (rb_include_class_new): Share WRAPPER between module and
iclass, so serial can prevent double marking.
* eval.c (rb_prepend_module): ditto.
* eval.c (rb_using_refinement): ditto.
* gc.c: Mark and free new wrapper struct.
* gc.c (obj_memsize_of): Count size of additional wrapper struct.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43973 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (gc_stat): Add :last_collection_flags for reason/trigger/type of
last GC run.
* gc.c (gc_prof_sweep_timer_stop): Record HAVE_FINALIZE GPR even
without GC_PROFILE_MORE_DETAIL.
* gc.c (gc_profile_flags): Add GC::Profiler.decode_flags to make sense
of GC.stat[:last_collection_flags]
* test/ruby/test_gc.rb (class TestGc): Test for above.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43893 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
heap_tomb_page_length.
* test/ruby/test_gc.rb: fix to use GC.stat[:heap_eden_page_length]
instead of GC.stat[:heap_length].
This test expects `heap_eden_page_length' (used pages size).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43874 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
if HAVE_MALLOC_USABLE_SIZE (or _WIN32) is defined.
We don't need these function if malloc_usable_size() is available.
* gc.c: catch up this change.
* gc.c: define HAVE_MALLOC_USABLE_SIZE on _WIN32.
* array.c (ary_resize_capa): do not use ruby_sized_xfree() with
local variable to avoid "unused local variable" warning.
This change only has few impact.
* string.c (rb_str_resize): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43839 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
RGENGC_ESTIMATE_OLDSPACE -> RGENGC_ESTIMATE_OLDMALLOC.
* gc.c: add a new major GC reason GPR_FLAG_MAJOR_BY_OLDMALLOC.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43837 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* heap_swept_slot
* malloc_increase
* malloc_limit
* remembered_shady_object
* remembered_shady_object_limit
* old_object
* old_object_limit
* oldmalloc_increase
* oldmalloc_limit
* gc.c (gc_stat): rename names.
* heap_live_num -> heap_live_slot
* heap_free_num -> heap_free_slot
* heap_final_slot -> heap_final_slot
Quote from RDoc of GC.stat():
"The contents of the hash are implementation specific and may
be changed in the future."
* test/ruby/test_gc.rb: catch up this change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43835 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
(oldspace -> oldmalloc for variable names)
OLDSPACE is confusing because it is not includes slots.
To more clearly, rename such as (oldspace_limit -> oldmalloc_limit).
It is clear that it measures (estimates) malloc()'ed size.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43833 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Now we have following environments (and related variable names).
* RUBY_GC_HEAP_INIT_SLOTS
* RUBY_GC_HEAP_FREE_SLOTS
* RUBY_GC_HEAP_GROWTH_FACTOR (new from 2.1)
* RUBY_GC_HEAP_GROWTH_MAX_SLOTS (new from 2.1)
* obsolete
* RUBY_FREE_MIN -> RUBY_GC_HEAP_FREE_SLOTS (from 2.1)
* RUBY_HEAP_MIN_SLOTS -> RUBY_GC_HEAP_INIT_SLOTS (from 2.1)
* RUBY_GC_MALLOC_LIMIT
* RUBY_GC_MALLOC_LIMIT_MAX (new from 2.1)
* RUBY_GC_MALLOC_LIMIT_GROWTH_FACTOR (new from 2.1)
* RUBY_GC_OLDSPACE_LIMIT (new from 2.1)
* RUBY_GC_OLDSPACE_LIMIT_MAX (new from 2.1)
* RUBY_GC_OLDSPACE_LIMIT_GROWTH_FACTOR (new from 2.1)
* test/ruby/test_gc.rb: catch up this change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43811 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (gc_after_sweep): allocate pages to allocate at least
RUBY_HEAP_MIN_SLOTS.
[Bug #9137]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43795 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
rb_gc_set_params because it's only used in ruby internal.
* internal.h (ruby_gc_set_params): Declare rb_gc_set_params's
alias function.
* gc.c: ditto.
* ruby.c: use ruby_gc_set_params.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43794 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
objspace.
* gc.c (ruby_mimfree): added. It is similar to ruby_mimmalloc().
* internal.h: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43771 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
malloc_usable_size() is defined by malloc_np.h on FreeBSD.
* configure.in: check malloc.h and malloc_np.h.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43769 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (vm_xrealloc, vm_xfree): use malloc_usable_size() to obtain old
size if available.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43760 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
They are not only used initial values.
Chikanaga-san: Congratulations on RubyPrize!
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43757 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Without this option, some application consumes huge memory.
(and there are only a few performance down)
Introduced new environment variables:
* RUBY_GC_HEAP_OLDSPACE (default 16MB)
* RUBY_GC_HEAP_OLDSPACE_MAX (default 128 MB)
* RUBY_GC_HEAP_OLDSPACE_GROWTH_FACTOR (default 1.2)
* gc.c (initial_malloc_limit): rename to initial_malloc_limit_min.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43755 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Basically, make an object graph of all of living objects before and
after marking and check status.
[Before marking: check WB sanity]
If there is a non-old object `obj' pointed from old object
(`parent') then `parent' or `obj' should be remembered.
[After marking: check marking miss]
Traversible objects with the object graph should be marked.
(However, this alert about objects pointed by machine context
can be false positive. We only display alert.)
[Implementation memo]
objspace_allrefs() creates an object graph.
The object graph is represented by st_table, key is object (VALUE)
and value is referring objects. Referring objects are stored by
"struct reflist".
* gc.c (init_mark_stack): do not use push_mark_stack_chunk() at init.
This pre-allocation causes failure on is_mark_stask_empty()
without any pushing.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43744 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
rb_fstring() used rb_gc_mark() to avoid freeing used string.
However, rb_gc_mark() set mark bit *and* pushes mark_stack.
rb_gc_resurrect() does only set mark bit if it is before sweeping.
* string.c (rb_fstring): use rb_gc_resurrect.
* internal.h: add decl.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43718 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
To reduce memory usage, sweep as soon as possible.
This behavior is same as Ruby 2.0.0 and before.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43623 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
If GC_PROFILE_MORE_DETAIL && GC_PROFILE_DETAIL_MEMORY,
maxrss, minflt and majflt are added to each profile record.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43591 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
vm_malloc_increase() can be called without GVL.
However, gc_rest_sweep() assumes acquiring GVL.
To avoid this problem, check GVL before gc_rest_sweep().
[Bug #9090]
This workaround introduces possibility to set malloc_limit as
wrong value (*1). However, this may be rare case. So I commit it.
*1: Without rest_sweep() here, gc_rest_sweep() can decrease
malloc_increase due to ruby_sized_xfree().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43574 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
conservative for closing to memory consumption of ruby 2.0.
* gc.c (GC_MALLOC_LIMIT, GC_MALLOC_LIMIT_GROWTH_FACTOR):
Adjust parameters for new algorithm.
Example: make gcbench-rdoc on a pc
time maxrss
2.0.0p343 285.27 281853952
trunk before patch 207.19 690405376
trunk after patch 211.59 312500224
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43558 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This is another approach to solve an issue discussed at r43530.
This feature is diabled as default.
This feature measures an increment of memory consuption by oldgen
objects. It measures memory consumption for each objects when
the object is promoted. However, measurement of memory consumption
is not accurate now. So that this measurement is `estimation'.
To implement this feature, move memsize_of() function from
ext/objspace/objspace.c and expose rb_obj_memsize_of().
Some memsize() functions for T_DATA (T_TYPEDDATA) have problem to
measure memory size, so that we ignores T_DATA objects now.
For example, some functions skip NULL check for pointer.
The macro RGENGC_ESTIMATE_OLDSPACE enables/disables this feature,
and turned off as default.
We need to compare 3gen GC and this feature carefully.
(it is possible to enable both feature)
We need a help to compare them.
* internal.h: expose rb_obj_memsize_of().
* ext/objspace/objspace.c: use rb_obj_memsize_of() function.
* cont.c (fiber_memsize): fix to check NULL.
* variable.c (autoload_memsize): ditto.
* vm.c (vm_memsize): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43532 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
RGenGC is designed as 2 generational GC, young and old generation.
Young objects will be promoted to old objects after one GC.
Old objects are not collect until major (full) GC.
The issue of this approach is some objects can promoted as old
objects accidentally and not freed until major GC.
Major GC is not frequently so short-lived but accidentally becoming
old objects are not freed.
For example, the program "loop{Array.new(1_000_000)}" consumes huge
memories because short lived objects (an array which has 1M
elements) are promoted while GC and they are not freed before major
GC.
To solve this problem, generational GC with more generations
technique is known. This patch implements three generations gen GC.
At first, newly created objects are "Infant" objects.
After surviving one GC, "Infant" objects are promoted to "Young"
objects.
"Young" objects are promoted to "Old" objects after surviving
next GC.
"Infant" and "Young" objects are collected if it is not marked
while minor GC. So that this technique solves this problem.
Representation of generations:
* Infant: !FL_PROMOTED and !oldgen_bitmap [00]
* Young : FL_PROMOTED and !oldgen_bitmap [10]
* Old : FL_PROMOTED and oldgen_bitmap [11]
The macro "RGENGC_THREEGEN" enables/disables this feature, and
turned off as default because there are several problems.
(1) Failed sometimes (Heisenbugs).
(2) Performance down.
Especially on write barriers. We need to detect Young or Old
object by oldgen_bitmap. It is slower than checking flags.
To evaluate this feature on more applications, I commit this patch.
Reports are very welcome.
This patch includes some refactoring (renaming names, etc).
* include/ruby/ruby.h: catch up 3gen GC.
* .gdbinit: fix to show a prompt "[PROMOTED]" for promoted objects.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43530 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This flag represents that "this object is promoted at least once."
* gc.c, debug.c, object.c: catch up this change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43527 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (obj_free): suppress a false shorten-64-to-32 warning,
RUBY_TYPED_FREE_IMMEDIATELY never exceed the limit of int.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43516 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
performance. Add before_sweep condition to heap_page structure.
* gc.c (rb_gc_force_recycle): Use before_sweep member.
* gc.c (heap_is_before_sweep, is_before_sweep): Remove. They has not
already been used.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (is_live_object): finalizer may not run because of lazy-sweep.
[ruby-dev:47786] [Bug #9069]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43502 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* RUBY_TYPED_FREE_IMMEDIATELY: free the data given by DATA_PTR()
with dfree function immediately. Otherwise (default), the data
freed at finalizaton point.
* RUBY_TYPED_WB_PROTECTED: make this object with FL_WB_PROTECT
(not shady).
* gc.c (obj_free): support RUBY_TYPED_FREE_IMMEDIATELY.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43463 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
We only need one sweep time measurement without lazy sweep.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43427 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (GC_MALLOC_LIMIT): change default value to 16MB.
* gc.c (GC_MALLOC_LIMIT_GROWTH_FACTOR): change default value to 2.0.
* gc.c (gc_before_sweep): change decrease ratio of `malloc_limit'
from 1/4 to 1/10.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43425 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
gc_rest_sweep() can reduce malloc_increase, so try it before GC.
Otherwise, malloc_increase can be less than malloc_limit at
gc_before_sweep(). This means that re-calculation of malloc_limit
may be wrong value.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43424 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
After rb_gc_force_recycle() for a object blonging to heap->freelist,
`heap->using_page->freelist' is not null.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43421 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Share `increment' information with heaps.
* gc.c: change ratio of heap_pages_free_min_page
to 0.80.
This change means slow down page freeing speed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43397 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Tomb heap is where zombie objects and ghost (freed slot) lived in.
Separate from other heaps (now there is only eden heap) at sweeping
helps freeing pages more efficiently.
Before this patch, even if there is an empty page at former phase
of sweeping, we can't free it.
Algorithm:
(1) Sweeping all pages in a heap and move empty pages from the
heap to tomb_heap.
(2) Check all exsisting pages and free a page
if all slots of this page are empty and
there is enough empty slots (checking by swept_num)
To introduce this pach, there are several tuning of GC parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43395 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Now, objects are managed by page. And a set of pages is called heap.
This commit supports multiple heaps in the object space.
* Functions heap_* and rb_heap_t manages heap data structure.
* Functions heap_page_* and struct heap_page manage page data
strcuture.
* Functions heap_pagse_* and struct rb_objspace_t::heap_pages
maintains all pages.
For example, pagaes are allocated from the heap_pages.
See https://bugs.ruby-lang.org/projects/ruby-trunk/wiki/GC_design
and https://bugs.ruby-lang.org/attachments/4015/data-heap_structure_with_multiple_heaps.png
for more deitals.
Now, there is only one heap called `eden', which is a space for all
new generated objects.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43388 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
There is a bug that T_ZOMBIE objects are not collected.
Because there is a pass to miss finalizer postponed job
with multi-threading. This patch solve this issue.
* vm_trace.c (rb_postponed_job_register_one): set
RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(th) if another same job
is registered.
There is a possibility to remain a postponed job without
interrupt flag.
* vm_trace.c (rb_postponed_job_register_one): check interrupt
carefully.
* vm_trace.c (rb_postponed_job_register_one): use additional space
to avoid buffer full.
* gc.c (gc_finalize_deferred_register): check failure.
* thread.c (rb_threadptr_execute_interrupts): check
`postponed_job_interrupt' immediately. There is a possibility
to miss this flag.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43383 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* make "struct heap" and move most of variables
in rb_objspace_t::heap.
* rename rb_objspace_t::heap::sorted to
rb_objspace_t::heap_sorted_pages
and make a macro heap_sorted_pages.
* rename rb_objspace_t::heap::range to
rb_objspace_t::heap_range and rename macros
lomem/himem to heap_lomem/heap_himem.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43360 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Change "slot" to "page". "Slot" is a space of RVALUE.
1. "Heap" consists of a set of "heap_page"s (pages).
2. Each "heap_page" has "heap_page_body".
3. "heap_page_body" has RVALUE (a.k.a. "slot") spaces.
4. "sorted" is a sorted array of "heap_page"s, sorted
by address of heap_page_body (for "is_pointer_to_heap").
See https://bugs.ruby-lang.org/attachments/4008/data-heap_structure.png.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43350 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This macro enable checker compare with allocated memory and
declared old_size of sized_xfree and sized_xrealloc.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43336 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This API provides information which objects are root objects.
`category' shows what kind of root objects.
* gc.c (gc_mark_roots): separate from gc_marks_body().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43294 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* vm.c, vm_core.h (rb_vm_add_root_module): added to register as a
defined root module or class.
This guard helps mark miss from defined classes/modules they are
only refered from C's global variables in C-exts.
Basically, it is extension's bug.
Register to hash object VM has.
Marking a hash objects allows generational GC supports.
* gc.c (RGENGC_PRINT_TICK): disable (revert).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43263 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Each symbols has String objects respectively to represent
Symbols.
These objects are marked only when:
* full marking
* new symbols are added
This hack reduce symbols (related strings) marking time.
For example, on my Linux environment, the following code
"20_000_000.times{''}"
with 40k symbols (similar symbol number on Rails 3.2.14 app,
@jugyo tells me) boosts, from 7.3sec to 4.2sec.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43255 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c: rename heap.free_num as heap.swept_num to clarify meaning and
avoid confusion with objspace_free_num().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43140 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (objspace_free_num): new method for available/free slots on
heap. [ruby-core:57633] [Bug #8983]
* gc.c (gc_stat): change heap_free_num definition to use new method.
* test/ruby/test_gc.rb: test for above.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43139 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c: add rb_objspace.limit to keep accurate count of total heap
slots [ruby-core:57633] [Bug #8983]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43138 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (GC_MALLOC_LIMIT_MAX): change default value
(256MB -> 512MB) and permit zero to ignore max value.
* gc.c (vm_malloc_increase, vm_xrealloc): do not cause GC on realloc.
* gc.c (gc_before_sweep): change debug messages.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43119 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This fix may solve a failure of
TestTracepointObj#test_tracks_objspace_events
[test/-ext-/tracepoint/test_tracepoint.rb:43].
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43092 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
RUBY_GC_MALLOC_LIMIT_MAX and RUBY_GC_MALLOC_LIMIT_GROWTH_FACTOR.
See r43067 for details.
* gc.c (rb_gc_set_params): refactoring. And change verbose notation.
Mostly duplicated functions get_envparam_int/double is not cool.
Please rewrite it.
* test/ruby/test_gc.rb: fix a test for this change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43072 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
If you enable RGENGC_PRINT_TICK to 1, then profiling results by RDTSC
(on x86/amd64 environment) are printed at last.
Thanks Yoshii-san.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Now, malloc_limit is increased/decreased by mysterious logic.
This fix simplify malloc_limit increase/decrease logic such as:
if (malloc_increase > malloc_limit) /* so many malloc */
malloc_limit += malloc_limit * (GC_MALLOC_LIMIT_FACTOR-1);
else
malloc_limit -= malloc_limit * (GC_MALLOC_LIMIT_FACTOR-1)/4;
Default value of GC_MALLOC_LIMIT_FACTOR is 1.8.
malloc_limit is bounded by GC_MALLOC_LIMIT_MAX (256MB by default).
This logic runs at before_sweeep(). So there are no effect from
caused by lazy sweep. And we can remove malloc_increase2.
* gc.c (HEAP_MIN_SLOTS, FREE_MIN, HEAP_GROWTH_FACTOR): rename to
GC_HEAP_MIN_SLOTS, GC_FREE_MIN, GC_HEAP_GROWTH_FACTOR respectively.
Check them by `#ifndef' so you can specify these values outside gc.c.
* gc.c (ruby_gc_params_t): add initial_malloc_limit_factor and
initial_malloc_limit_max.
* gc.c (vm_malloc_prepare, vm_xrealloc): use vm_malloc_increase to
add and check malloc_increase.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43067 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (mark_locations_array): disable AddressSanitizer. based on a
patch by halfie (Ruby Guy) at [ruby-core:57372].
[ruby-core:56155] [Bug #8680]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43047 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
RARRAY_RAWPTR(ary) returns (const VALUE *) type pointer and
usecase of this macro is not acquire raw pointer, but acquire
read-only pointer. So we rename to better name.
RSTRUCT_RAWPTR() is also renamed to RSTRUCT_CONST_PTR()
(I expect that nobody use it).
* array.c, compile.c, cont.c, enumerator.c, gc.c, proc.c, random.c,
string.c, struct.c, thread.c, vm_eval.c, vm_insnhelper.c:
catch up this change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43043 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (obj_free): ditto
* internal.h (struct rb_classext_struct): ditto
* method.h (rb_method_entry): remove ent param
* vm_method.c: restore the global method cache. Per class cache tables
turned out to be far too slow.
[ruby-core:57289] [Bug #8930]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43027 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (RVALUE::line): should be VALUE. On some environment
(such as mswin64), `int' introduces alignment mismatch.
* gc.c (newobj_of): add an assertion to check VALUE alignment.
* gc.c (aligned_malloc): `&' is low priority than `=='.
* gc.c: define GC_DEBUG everytime and use it as value 0 or 1.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42624 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
rb_gc_unprotect_logging() which is general version
* include/ruby/ruby.h: add USE_RGENGC_LOGGING_WB_UNPROTECT
to enable.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42151 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This means that this slot doesn't have any free objects.
And store this slot with objspace->heap.using_slot.
* gc.c (gc_before_sweep): restore objspace->freelist
into objspace->heap.using_slot->freelist.
This means that using_slot has free objects which are
pointed from objspace->freelist.
* gc.c (gc_slot_sweep): do not need to clear slot->freelist.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
function to remember an specified object. This api is only
experimental (strongly depend on WB/rgengc strategy).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42062 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
free slot itself at free_heap_slot().
Reproduce-able code is here:
N1 = 100_000; N2 = 1_000_000
N1.times{ary = []; N2.times{ary << ''}}
Maybe this problem is remaining in Ruby 2.0.0.
* gc.c (unlink_heap_slot): remove not working code.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42022 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
(1) The heap is consists of a set of slots.
(2) Each "slot" has a "slot_body".
slot::start and slot::limit specify RVALUE beginning address
and number of RVALUE in a "slot_body".
(3) "slot_body" contains a pointer to slot (slot_body::header::slot)
and an array of RVALUE.
(4) heap::sorted is an array of "slots", sorted by an address of
slot::body.
See https://bugs.ruby-lang.org/projects/ruby-trunk/wiki/GC_design
for more details (figure).
* gc.c: Avoid "heaps" terminology. It is ambiguous.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42021 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
(1) move heaps_header::start and limit to heaps_slot.
(2) remove heaps_header::end which can be calculated by start+limit.
* gc.c: catch up above change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42020 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (objspace): add a new field objspace::freelist, which contains
available RVALUEs.
* gc.c (newobj_of): simply call new function `get_freeobj()'.
get_freeobj() returns objspace::freelist. If objspace::freelist
is not available, refill objspace::freelist with a slot pointed by
objspace::heap::free_slots.
* gc.c (before_gc_sweep): clear objspace::freelist.
* gc.c (slot_sweep): clear slot::freelist.
* gc.c (heaps_prepare_freeslot): renamed to heaps_prepare_freeslot.
* gc.c (unlink_free_heap_slot): remove unused function.
* gc.c (rb_free_const_table): remove unused function.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42005 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (slot_sweep): use `heaps_add_freeslot' instead of
`link_free_heap_slot'.
* gc.c (assign_heap_slot): use local variable `slot' instead of
`heaps'.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42000 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (rb_gc_force_recycle): Add a missing space around a parenthesis.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41660 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
is before sweep?
* gc.c (rb_gc_force_recycle): Have to clear mark bit if object's slot
already ready to mainor sweep.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41633 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (gc_marks_test): Check all WriteBarrier Errors and track them in obj-tree.
* gc.c (rgengc_check_shady): Ditto.
* gc.c (gc_marks): Move 2 funtion calls to gc_marks_test for test initialize.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41607 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (gc_prof_timer_start): Pick out part of new record creation as gc_prof_setup_new_record.
* gc.c (gc_prof_set_malloc_info): Move point of recording allocation size to front of mark.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41594 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
on RGENGC_CHECK_MODE >= 2.
(1) Save bitmaps before marking
(2) Run full marking
(3) On each traceable object,
(a) object was not oldgen (== newly or shady object) &&
(b) parent object was oldgen &&
(c) parent object was not remembered &&
(d) object was not rememberd
then, it should be WB miss.
This idea of this checker is by Masaya Tarui <tarui@ruby-lang.org>.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41564 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
gc_prof_set_heap_info() just after sweeping to calculate
live object number correctly.
(live object number = total generated number (before marking) -
total freed number (after sweeping))
* gc.c (gc_marks): record `oldgen_object_count' into current profile`
record directly.
* gc.c (rgengc_rememberset_mark): same for remembered_normal_objects
and remembered_shady_objects.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41552 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
records (because it points a set of records) and add a field
rb_objspace::profile::current_record to point a current profiling
record.
* gc.c: use above fields.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41551 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
because all of remembered objects are called for gc_mark_children().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41550 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
remembered objects directly instead of pushing on the mark stack.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41549 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
No need to separate major/minor GC.
* gc.c (gc_setup_mark_bits): remove gc_clear_mark_bits() and unify to
this function.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41547 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Use RARRAY_ASET() or RARRAY_PTR_USE() to modify Array objects.
* array.c, gc.c: catch up above changes.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41537 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Introduce the following C APIs:
* RSTRUCT_RAWPTR(st) returns pointer (do WB on your risk).
The type of returned pointer is (const VALUE *).
* RSTRUCT_GET(st, idx) returns idx-th value of struct.
* RSTRUCT_SET(st, idx, v) set idx-th value by v with WB.
And
* RSTRUCT_PTR(st) returns pointer with shady operation.
The type of returned pointer is (VALUE *).
* struct.c, re.c, gc.c, marshal.c: rewrite with above APIs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41534 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
disabled.
* gc.c (gc_marks_test): store oldgen count and shady count
before test marking and restore them after marking.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41526 b2dd03c8-39d4-4d8f-98ff-823fe69b080e