Граф коммитов

1090 Коммитов

Автор SHA1 Сообщение Дата
nobu 86e2038c27 gc.c: live keys only
* 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
2013-12-12 02:01:18 +00:00
nobu cdc2eeda6a gc.c: simple array for wmap
* gc.c (wmap_finalize, wmap_aset_update): use simple malloced array
  instead of T_ARRAY, to reduce GC pressure.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44119 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-10 08:21:33 +00:00
nobu 27947a449f gc.c: use st_update
* 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
2013-12-10 07:16:08 +00:00
nobu bcdad3299b gc.c: ruby_sized_xrealloc2
* gc.c (ruby_sized_xrealloc2): reallocate from old size.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-10 07:16:06 +00:00
tmm1 40d7c9c18b gc.c: speed up RGENGC_CHECK_MODE by removing unncessary check
* gc.c (reflist_add): revert changes from r44109. it is unnecessary
  after r44113
* gc.c (allrefs_i): fix whitespace
* gc.c (allrefs_roots_i): fix whitespace

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44114 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-10 06:58:48 +00:00
ko1 1b29c00f00 * gc.c (allrefs_add): push obj only if allrefs table doesn't have
obj.
* gc.c (allrefs_roots_i): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44113 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-10 06:47:15 +00:00
ko1 14979f2161 * gc.c (RGENGC_CHECK_MODE): separate checkers to different modes.
* 2: enable generational bits check (for debugging)
  * 3: enable livness check
  * 4: show all references



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44112 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-10 06:44:35 +00:00
nobu 13dee2481b * remove trailing spaces.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44111 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-10 06:26:05 +00:00
ko1 8d4253f7e1 * gc.c (gc_marks_check): disable GC during checking and
restore malloc_increase info.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44110 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-10 06:21:52 +00:00
tmm1 3705007e7a gc.c: build complete object graph for RGENGC_CHECK_MODE
* gc.c (reflist_add): return 0 if reference already exists
	* gc.c (allrefs_add): return 1 on newly added references
	* gc.c (allrefs_i): follow references to construct complete object
	  graph. before this patch, RGENGC_CHECK could fail to verify some WB
	  miss issues. [Bug #9226] [ruby-core:58959]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44109 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-10 05:46:48 +00:00
nobu 0326725b24 gc.c: check arguments first
* 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
2013-12-10 05:17:19 +00:00
nobu 9bd802f556 gc.c: fix WeakMap#inspect
* gc.c (wmap_inspect_i): fix key/value order.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-10 05:02:17 +00:00
tmm1 332decb490 gc.c: fix typo in function name
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44106 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-10 03:25:28 +00:00
tmm1 7170baa878 objspace_dump.c: include object's gc flags in dump
* 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
2013-12-10 02:26:09 +00:00
nobu d2cc188ad5 gc.c: ObjectSpace::WeakMap#size
* gc.c (wmap_size): add ObjectSpace::WeakMap#size and #length.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44093 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-09 07:13:40 +00:00
tmm1 8f77cfb308 gc.c: promote long-lived NODE_CREF objects to oldgen
* include/ruby/ruby.h: add RGENGC_WB_PROTECTED_NODE_CREF setting
  In a large app, this reduces the size of
  remembered_shady_object_count by 80%. [Bug #9225] [ruby-core:58947]
* gc.c (rb_node_newnode): add FL_WB_PROTECTED flag to NODE_CREF
* class.c (rewrite_cref_stack): insert OBJ_WRITE for NODE_CREF
* iseq.c (set_relation): ditto
* iseq.c (rb_iseq_clone): ditto
* vm_eval.c (rb_yield_refine_block): ditto
* vm_insnhelper.c (vm_cref_push): ditto
* vm_insnhelper.h (COPY_CREF): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44059 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-08 02:28:04 +00:00
charliesome 0aada28159 * gc.c (gc_mark_children): use nd_clss and nd_next for code clarity
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44051 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-07 13:01:17 +00:00
ko1 b91e889c34 * gc.c: change oldmalloc meaning.
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
2013-12-06 10:27:02 +00:00
ko1 f09058b877 * gc.c (atomic_sub_nounderflow): not 0 but val itself.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44039 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-06 10:09:38 +00:00
ko1 e4720e1118 * gc.c (rb_objspace_alloc, Init_heap): initialize
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
2013-12-06 09:38:22 +00:00
ko1 2c616737e5 * gc.c (garbage_collect_body): bug fix.
initialize after recording.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44037 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-06 09:34:26 +00:00
ko1 cb62399d90 * gc.c (atomic_sub_nounderflow): added to simplify atomic sub with
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
2013-12-06 08:53:47 +00:00
nobu b9cafaf524 vm_insnhelper.c: rb_get_kwargs
* 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
2013-12-06 08:10:47 +00:00
nobu 761e9c518f gc.c: indent
* gc.c (gc_start_internal): adjust indent.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44032 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-06 07:47:29 +00:00
ko1 0e20c2afa8 * gc.c (gc_start_internal): do not use rb_gc_start() and rb_gc().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44031 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-06 07:22:25 +00:00
ko1 73d6dc252d * gc.c (gc_start_internal, rb_gc): do not need
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
2013-12-06 06:26:02 +00:00
tmm1 e6237c8243 gc.c: add note about experimental nature of new GC.start flags
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44028 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-06 05:32:11 +00:00
tmm1 470c9d844b gc.c: add minor marking and lazy sweeping options to GC.start
* 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
2013-12-06 05:11:51 +00:00
nobu 928c99944b * remove trailing spaces.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44014 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-05 12:49:07 +00:00
tmm1 941e36d3db gc.c: [DOC] minor typo
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44013 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-05 12:34:39 +00:00
ko1 b9cf1033aa * gc.c (gc_info_decode): fix to avoid syntax error on VS2012.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44012 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-05 12:06:59 +00:00
tmm1 4876dd3fb1 gc.c: add GC.latest_gc_info()
* 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
2013-12-05 10:30:38 +00:00
ko1 53035271a8 * gc.c: change function names vm_ prefix to objspace_ prefix.
They are objspace_ functionality.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44006 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-05 08:52:30 +00:00
tmm1 241c1a5459 gc.c: expose GC.stat() to C-api via rb_gc_stat()
* 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
2013-12-05 07:45:13 +00:00
ko1 cda7250de0 * gc.c (vm_malloc_size): added.
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
2013-12-05 04:54:20 +00:00
tmm1 393b9e65e9 gc.c: split GC_END event into GC_END_MARK and GC_END_SWEEP
* 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
2013-12-05 04:26:04 +00:00
nobu c06f12031e gc.c: flush all deferred finalizers
* 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
2013-12-05 01:47:12 +00:00
nobu 3e36402e7f gc.c: rb_gc_set_params
* 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
2013-12-05 01:16:20 +00:00
tmm1 53e0d4666c gc.c: Load GC tuning settings earlier during boot.
* 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
2013-12-05 00:19:13 +00:00
nobu b7c6db94ae gc.c: use malloc_size
* 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
2013-12-03 14:48:20 +00:00
tmm1 084b602d9a * include/ruby/ruby.h (struct RClass): Add wrapper struct around
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
2013-12-03 08:11:07 +00:00
tmm1 d7009f76ef * gc.c: Expose details about last garbage collection via GC.stat.
* 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
2013-11-28 07:40:35 +00:00
ko1 9e733b9091 * gc.c (gc_mark_stacked_objects): check only when check_mode > 0.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43879 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-27 08:56:48 +00:00
tmm1 0094b7bb68 * gc.c (Init_GC): Add new GC::INTERNAL_CONSTANTS for information about
GC heap/page/slot sizing.
* test/ruby/test_gc.rb (class TestGc): test for above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43877 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-27 06:57:14 +00:00
tmm1 23178d1044 * gc.c (gc_page_sweep): Fix compile warning from last commit.
* hash.c (hash_aset_str): Re-use existing variable to avoid
  unnecessary pointer dereferencing.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43876 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-27 06:24:37 +00:00
ko1 da65a3d906 * gc.c (gc_page_sweep): disable debug print.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43875 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-27 06:13:19 +00:00
ko1 5993c141f1 * gc.c (gc_stat): add new information heap_eden_page_length and
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
2013-11-27 06:09:55 +00:00
tmm1 5080a75621 * gc.c: Rename rb_heap_t members:
used -> page_length
    limit -> total_slots

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43868 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-27 01:42:25 +00:00
ko1 2bfd722d80 * internal.h: do not use ruby_sized_xrealloc() and ruby_sized_xfree()
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
2013-11-25 01:13:31 +00:00
ko1 30e88ca8a7 * gc.c: continue to change OLDSPACE -> OLDMALLOC.
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
2013-11-24 19:49:02 +00:00
ko1 a87eaf88a0 * gc.c: change terminlogy "..._num" to "..._slots" about slot opetaion.
* final_num -> final_slots
  * objspace_live_num() -> objspace_live_slots()
  * objspace_limit_num() -> objspace_limit_slots()
  * objspace_free_num() -> objspace_free_slots()



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43836 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-24 19:18:53 +00:00
ko1 f06002208d * gc.c (gc_stat): add internal information.
* 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
2013-11-24 19:08:33 +00:00
ko1 c1382f3ab5 * gc.c: change terminology OLDSPACE -> OLDMALLOC.
(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
2013-11-24 18:13:48 +00:00
nagachika 81f4262e6b * ChangeLog: fix a typo at r43744.
* gc.c (is_mark_stack_empty): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43819 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-23 15:35:04 +00:00
ko1 dbe9e6a5f8 * gc.c: fix gloval variable name.
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
2013-11-23 03:33:10 +00:00
tmm1 3d5bf44cd8 * gc.c: Rename heap_pages_swept_num to heap_pages_swept_slots to clarify meaning (number of slots, not pages).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43809 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-22 23:50:08 +00:00
nobu d87a084929 * gc.c (RUBY_ALIAS_FUNCTION_VOID): fix compile error.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43797 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-22 07:56:29 +00:00
ko1 c91ec25d19 * gc.c (heap_set_increment): accept minumum additional page number.
* 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
2013-11-22 07:40:27 +00:00
nari 9d2f54b3e9 * include/ruby/intern.h (rb_gc_set_params): Deprecate
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
2013-11-22 07:26:55 +00:00
ko1 a6ca9f9fce * vm.c (ruby_vm_destruct): do not use ruby_xfree() after freeing
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
2013-11-22 01:38:08 +00:00
naruse 215a7da2a6 * gc.c: fix build failure on FreeBSD introduced by r43763.
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
2013-11-22 00:05:34 +00:00
ko1 b1529a30e0 * gc.c: RGENGC_CHECK_MODE should be 0.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43766 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-21 13:34:38 +00:00
nobu d1d737ae57 * gc.c: needs malloc.h if malloc_usable_size() is available.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43763 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-21 11:41:16 +00:00
nobu 1a2997b299 gc.c: malloc_usable_size
* gc.c (malloc_usable_size): use _msize() on Windows.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43762 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-21 09:52:09 +00:00
nobu 4305eb8e6c gc.c: malloc_usable_size
* 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
2013-11-21 09:49:05 +00:00
ko1 20fa0c26c9 * gc.c: rename initial_xxx variables to gc_params.xxx.
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
2013-11-21 08:50:40 +00:00
nobu a638a44b48 * remove trailing spaces.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43756 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-21 08:21:05 +00:00
ko1 047cdaca14 * gc.c: enable "RGENGC_ESTIMATE_OLDSPACE" option as default.
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
2013-11-21 08:20:34 +00:00
ko1 5d1d1ed258 * gc.c (gc_marks_check): do not dump all refs.
* gc.c (allrefs_dump_i): fix output format.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43746 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-21 05:07:04 +00:00
nobu 42a8a2cbe7 * remove trailing spaces.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43745 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-21 05:01:05 +00:00
ko1 4c9d6d801b * gc.c: change RGENGC_CHECK_MODE (>= 2) logic.
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
2013-11-21 04:57:37 +00:00
ko1 2127b9cfc7 * gc.c (heap_is_swept_object): use heap_page::before_sweep flag.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43720 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-19 09:52:52 +00:00
ko1 2d00e739ef * gc.c (rb_objspace_reachable_objects_from_root): do major marking.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43719 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-19 09:50:14 +00:00
ko1 301223df95 * gc.c (rb_gc_resurrect): added.
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
2013-11-19 09:48:47 +00:00
ktsj 711a069e0f * gc.c (rb_gcdebug_print_obj_condition): catch up recent changes
to compile on GC_DEBUG.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43637 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-10 14:50:13 +00:00
nobu 24537e1b1c gc.c: finalizer functions
* gc.c (rb_define_finalizer, rb_undefine_finalizer): rename and export
  finalizer functions.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-09 23:03:11 +00:00
ko1 9782d219f3 * gc.c (vm_malloc_increase): sweep immediately on GC due to malloc().
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
2013-11-09 16:35:54 +00:00
nobu 3fdff0501a gc.c: private call
* gc.c (should_be_callable): allow private call since rb_eval_cmd
  calls even private methods.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43621 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-09 15:36:46 +00:00
nobu 7a330ba230 gc.c: should_be_callable
* gc.c (should_be_callable): extract duplicate code.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-09 15:34:30 +00:00
tarui 5d663cc2d3 * gc.c (gc_page_sweep, rgengc_rememberset_mark): Refactoring.
Get bitmaps directly.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43594 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-09 00:23:02 +00:00
tarui ead9dbae1f * gc.c (RVALUE_PROMOTE_INFANT): Refactoring. Remove duplicated nonsense
code.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43593 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-09 00:17:23 +00:00
tarui 76a3e71cfd * gc.c (gc_marks_test): Bugfix. Fix a struct member name for build
with RGENGC_CHECK_MODE.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43592 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-09 00:05:27 +00:00
tarui 0f091bbfb4 * gc.c : Add GC_PROFILE_DETAIL_MEMORY option.
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
2013-11-08 23:59:20 +00:00
nobu 1062dcf4df gc.c: use switch for alternative BUILTIN_TYPE
* gc.c (rb_objspace_call_finalizer): BUILTIN_TYPE is alternative,
  T_DATA object (Thread, Mutex, Fiber) cannot be T_FILE.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-07 18:10:33 +00:00
ko1 bc31909366 * gc.c (vm_malloc_increase): check GVL before gc_rest_sweep().
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
2013-11-07 18:03:12 +00:00
ko1 a6698bc676 * gc.c: modify malloc_limit strategy.
* fix default vaues:
    GC_MALLOC_LIMIT_GROWTH_FACTOR
    GC_MALLOC_LIMIT: 8MB -> 16MB
    GC_MALLOC_LIMIT_MAX: 384MB -> 32MB
  * algorithm of malloc_limit increment.
    if (malloc_increase < malloc_limit) {
      next_malloc_limit = malloc_limit * factor
      if (malloc_limit > malloc_limit_max) {
        malloc_limit = malloc_increase
      }
    }
    This algorithm change malloc_limit from
    16MB -> 32MB slowly.
    If malloc_limit exceeds malloc_limit_max, then
    increase with malloc_increase.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43565 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-07 10:45:01 +00:00
tarui 01a7e7893b * gc.c (gc_before_sweep): Change algorithm of malloc_limit to
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
2013-11-06 12:36:34 +00:00
ko1 3db0e56472 * gc.c: define RGENGC_ESTIMATE_OLDSPACE == 0 if USE_RGENGC is 0.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43546 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-06 00:14:26 +00:00
ko1 8c6157e048 * gc.c (Init_GC): add GC::OPTS to show options.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43544 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-05 22:13:51 +00:00
tarui 3ce802b79c * gc.c (is_live_object): A hidden object may be a live object.
[ruby-dev:47788] [Bug #9072]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43539 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-05 11:15:21 +00:00
nobu 8a9dff36c3 * remove trailing spaces.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43534 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-05 07:48:31 +00:00
ko1 d1674ef67b * gc.c: add support to estimate increase of oldspace memory usage.
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
2013-11-05 04:51:01 +00:00
ko1 5ba523967e * gc.c (GC_MALLOC_LIMIT_MAX): fix default value 512MB -> 384MB.
512MB is huge.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43531 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-04 19:04:06 +00:00
ko1 325d2cfcdf * gc.c: add 3gen GC patch, but disabled as default.
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
2013-11-04 18:59:33 +00:00
ko1 42bd731dc5 * include/ruby/ruby.h: rename FL_OLDGEN to FL_PROMOTED.
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
2013-11-04 15:04:10 +00:00
nobu b9ed44e7c7 gc.c: use boolean
* gc.c (obj_free): use free_immediately as boolean.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43520 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-03 12:40:29 +00:00
nobu 3b320b782f gc.c: suppress warning
* 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
2013-11-03 01:37:22 +00:00
nobu 541dac0b9b gc.c: mark live objects only
* gc.c (wmap_mark_map): mark live objects only, but delete zombies.
  [ruby-dev:47787] [Bug #9069]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-01 14:24:34 +00:00
tarui 21a58208f1 * gc.c (struct heap_page, gc_page_sweep, gc_sweep): Refactoring for
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
2013-11-01 13:47:39 +00:00
tarui 3705b07014 * gc.c (make_deferred): Refactoring. Collect codes which should be
atomic.

	* gc.c (make_io_deferred, obj_free, rb_objspace_call_finalizer,
	  gc_page_sweep): Correspond to the above.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43506 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-01 13:22:54 +00:00
tarui 1726b516d0 * gc.c (typedef struct rb_objspace): Refactoring. Move some members
into profile member.

	* gc.c (newobj_of): Correspond to the above.

	* gc.c (finalize_list): Ditto.

	* gc.c (objspace_live_num): Ditto.

	* gc.c (gc_page_sweep): Ditto.

	* gc.c (rb_gc_force_recycle): Ditto.

	* gc.c (garbage_collect_body): Ditto.

	* gc.c (rb_gc_count): Ditto.

	* gc.c (gc_stat): Ditto.

	* gc.c (gc_prof_set_heap_info): Ditto.

	* gc.c (gc_profile_dump_on): Ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43505 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-01 12:49:49 +00:00
nobu 21ea356a42 gc.c: zombie is not alive
* 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
2013-11-01 08:25:34 +00:00
ko1 c5e08b764e * add RUBY_TYPED_FREE_IMMEDIATELY to data types which only use
safe functions during garbage collection such as xfree().
  On default, T_DATA objects are freed at same points as fianlizers.
  This approach protects issues such as reported by [ruby-dev:35578].
  However, freeing T_DATA objects immediately helps heap usage.
  Most of T_DATA (in other words, most of dfree functions) are safe.
  However, we turned off RUBY_TYPED_FREE_IMMEDIATELY by default
  for safety.
* cont.c: ditto.
* dir.c: ditto.
* encoding.c: ditto.
* enumerator.c: ditto.
* error.c: ditto.
* file.c: ditto.
* gc.c: ditto.
* io.c: ditto.
* iseq.c: ditto.
* marshal.c: ditto.
* parse.y: ditto.
* proc.c: ditto.
* process.c: ditto.
* random.c: ditto.
* thread.c: ditto.
* time.c: ditto.
* transcode.c: ditto.
* variable.c: ditto.
* vm.c: ditto.
* vm_backtrace.c: ditto.
* vm_trace.c: ditto.
* ext/bigdecimal/bigdecimal.c: ditto.
* ext/objspace/objspace.c: ditto.
* ext/stringio/stringio.c: ditto.
* ext/strscan/strscan.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-29 11:16:54 +00:00
ko1 52811ab159 * include/ruby/ruby.h: introduce new flags for T_TYPEDDATA.
* 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
2013-10-29 09:42:45 +00:00
ko1 5aa527fade * gc.c (vm_malloc_increase): decrease it more carefully.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-29 07:49:43 +00:00
ko1 97f0de6d90 * gc.c (heap_page_resurrect): return a page in tomb heap even if
freelist is NULL.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43461 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-29 07:25:45 +00:00
tmm1 29dbed183e * gc.c (gc_profile_total_time): fix off-by-one error in GC::Profiler.total_time.
* test/ruby/test_gc.rb (class TestGc): test for above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43457 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-29 02:11:26 +00:00
ktsj ad367a256e * gc.c: catch up recent changes to compile on GC_DEBUG,
RGENGC_CHECK_MODE.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43434 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-26 10:42:07 +00:00
ko1 b848aad5bf * gc.c (gc_profile_dump_on): use "Page" terminology.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43428 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-26 05:35:43 +00:00
ko1 d03912898e * gc.c (gc_sweep, gc_heap_lazy_sweep): fix measurement code.
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
2013-10-26 04:31:10 +00:00
ko1 286d567bbf * gc.c: tuning parameters.
* 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
2013-10-26 02:46:30 +00:00
ko1 6c458aec30 * gc.c (vm_malloc_increase): do gc_rest_sweep() before GC.
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
2013-10-26 02:34:23 +00:00
tarui 59735e2c61 * gc.c (gc_before_heap_sweep): Restructure code to mean clearly.
heap->freelist is connected to end of list.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43423 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-25 21:37:39 +00:00
ko1 98feb2b9bf * gc.c (gc_before_heap_sweep): fix freelist management.
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
2013-10-25 19:09:14 +00:00
tmm1 b906f0ed17 * gc.c: add new initial_growth_max tuning parameter. [ruby-core:57928] [Bug #9035]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43409 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-23 22:47:29 +00:00
tmm1 dd117ea118 * gc.c: Rename free_min to min_free_slots and free_min_page to max_free_slots. The algorithm for heap growth is:
if (swept_slots < min_free_slots) pages++
    if (swept_slots > max_free_slots) pages--

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43399 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-23 15:05:22 +00:00
ko1 602241142f * gc.c: move increment from heap to heap_pages.
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
2013-10-23 10:16:01 +00:00
ko1 99c4e43d6a * gc.c (heap_pages_free_unused_pages): cast to (int) for size_t
variable `i'.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43396 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-23 08:52:38 +00:00
ko1 69d787ff6d * gc.c: introduce tomb heap.
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
2013-10-23 08:48:54 +00:00
ko1 29ffa2c273 * gc.c (gc_prof_sweep_timer_stop): catch up recent changes
to compile on GC_PROFILE_MORE_DETAIL=1.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43394 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-23 05:22:10 +00:00
ko1 3d85d6edb5 * gc.c (Init_heap): move logics from heap_pages_init() and remove
heap_pages_init().



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43389 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-22 10:54:44 +00:00
ko1 d6fe84b6f3 * gc.c: allow multiple heaps.
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
2013-10-22 10:28:31 +00:00
ko1 f5b15f0e3f * vm_trace.c: exterminate Zombies.
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
2013-10-22 06:24:54 +00:00
nobu 6bf78ee633 gc.c: fix arity
* gc.c (Init_GC): fix arity of key? method.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43361 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-18 23:50:13 +00:00
ko1 14c08fdb88 * gc.c: fix rb_objspace_t.
* 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
2013-10-18 23:33:55 +00:00
nobu ffcf1df1b5 * gc.c (wmap_inspect_i): fix inspect format.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43354 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-18 07:06:43 +00:00
nobu 24b97da7ef * gc.c (wmap_inspect_i): fix callback argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43353 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-18 07:04:42 +00:00
nobu 936b96e9b7 gc.c: ObjectSpace::WeakMap inspection and iteration methods
* gc.c (wmap_inspect, wmap_each, wmap_each_key, wmap_each_value),
  (wmap_keys, wmap_values): add inspection and iteration methods to
  ObjectSpace::WeakMap for debug.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43352 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-18 06:59:14 +00:00
nobu e12799fd31 gc.c: ObjectSpace::WeakMap#key?
* gc.c (wmap_each_i): add ObjectSpace::WeakMap#key? method.

* lib/weakref.rb (WeakRef#weakref_alive): use above method.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43351 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-18 06:59:12 +00:00
ko1 b443d83a77 * gc.c: change terminology of heap.
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
2013-10-18 06:33:36 +00:00
ko1 ee4da732e3 * gc.c (CALC_EXACT_MALLOC_SIZE_CHECK_OLD_SIZE): introduced.
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
2013-10-17 09:51:41 +00:00
ko1 76b06555d0 * gc.c, internal.h: rename ruby_xsizefree/realloc to
rb_sized_free/realloc.
* array.c: catch up these changes.
* string.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43333 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-17 08:41:23 +00:00
ko1 8ac4f421e1 * gc.c, internal.h: add new internal memory mangement functions.
* void *ruby_xsizedrealloc(void *ptr, size_t new_size, size_t old_size)
* void ruby_xsizedfree(void *x, size_t size)
  These functions acccept additional size parameter to calculate more
  accurate malloc_increase parameter which control GC timing.
  [Feature #8985]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43330 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-17 07:57:03 +00:00
ko1 82d06c5ade * gc.c (objspace_each_objects): do not skip empty RVALUEs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43313 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-16 20:41:49 +00:00
tmm1 2370e623c4 * gc.c (gc_mark_roots): rename roots to be categories instead of function names.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43296 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-15 22:33:36 +00:00
nobu 4d94977775 * remove trailing spaces.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43295 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-15 13:12:03 +00:00
ko1 f241016825 * gc.h (rb_objspace_reachable_objects_from_root): added.
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
2013-10-15 10:22:33 +00:00
ko1 52c1331763 * class.c, variable.c, gc.c (rb_class_tbl): removed.
* 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
2013-10-11 18:27:18 +00:00
ko1 9d70a17541 revert r43259 because it is possible to mark miss classes defined in C-exts. Thanks charliesome.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-11 18:03:43 +00:00
ko1 7aecb95637 * class.c, variable.c, gc.c (rb_class_tbl): removed.
rb_class_tbl is no longer used.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-11 17:33:44 +00:00
ko1 432834dd35 * gc.c: use terminology `full_mark' instead of `minor_gc'
in mark functions.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43257 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-11 12:00:35 +00:00
ko1 f6fcb9cc94 * gc.c: use __GNUC__ instead of __GCC__.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43256 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-11 11:46:42 +00:00
ko1 f44b0e5b4f * gc.c, parse.y: support generational Symbol relatetd marking.
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
2013-10-11 11:45:38 +00:00
tmm1 8d9e3cd9c6 gc.c: rename heap.free_num to heap.swept_num
* 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
2013-10-04 10:52:25 +00:00
tmm1 907a03fee5 gc.c: add objspace_free_num and make GC.stat[:heap_free_num] use it
* 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
2013-10-04 10:05:40 +00:00
tmm1 a24705cfa5 gc.c: add rb_objspace.limit
* 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
2013-10-04 10:05:37 +00:00
ko1 fa105e6c20 * gc.c: define gc_profile_record::allocated_size if
CALC_EXACT_MALLOC_SIZE is true.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43130 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-03 09:03:06 +00:00
ko1 8c0033a7b6 * gc.c: relax GC condition due to malloc_limit.
* 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
2013-10-02 09:56:04 +00:00
nobu 6a1a08c945 gc.c: suppress warnings
* gc.c (gc_before_sweep): use PRIuSIZE instead of "%zu" directly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43094 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-30 08:06:20 +00:00
ko1 1d90d0ced9 * gc.c (rb_gc_disable): do rest_sweep() before disable GC.
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
2013-09-30 02:20:28 +00:00