2000-05-01 13:42:38 +04:00
|
|
|
/**********************************************************************
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
gc.c -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
created at: Tue Oct 5 09:44:46 JST 1993
|
|
|
|
|
* encoding.c: provide basic features for M17N.
* parse.y: encoding aware parsing.
* parse.y (pragma_encoding): encoding specification pragma.
* parse.y (rb_intern3): encoding specified symbols.
* string.c (rb_str_length): length based on characters.
for older behavior, bytesize method added.
* string.c (rb_str_index_m): index based on characters. rindex as
well.
* string.c (succ_char): encoding aware succeeding string.
* string.c (rb_str_reverse): reverse based on characters.
* string.c (rb_str_inspect): encoding aware string description.
* string.c (rb_str_upcase_bang): encoding aware case conversion.
downcase, capitalize, swapcase as well.
* string.c (rb_str_tr_bang): tr based on characters. delete,
squeeze, tr_s, count as well.
* string.c (rb_str_split_m): split based on characters.
* string.c (rb_str_each_line): encoding aware each_line.
* string.c (rb_str_each_char): added. iteration based on
characters.
* string.c (rb_str_strip_bang): encoding aware whitespace
stripping. lstrip, rstrip as well.
* string.c (rb_str_justify): encoding aware justifying (ljust,
rjust, center).
* string.c (str_encoding): get encoding attribute from a string.
* re.c (rb_reg_initialize): encoding aware regular expression
* sprintf.c (rb_str_format): formatting (i.e. length count) based
on characters.
* io.c (rb_io_getc): getc to return one-character string.
for older behavior, getbyte method added.
* ext/stringio/stringio.c (strio_getc): ditto.
* io.c (rb_io_ungetc): allow pushing arbitrary string at the
current reading point.
* ext/stringio/stringio.c (strio_ungetc): ditto.
* ext/strscan/strscan.c: encoding support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-25 07:29:39 +04:00
|
|
|
Copyright (C) 1993-2007 Yukihiro Matsumoto
|
2000-05-01 13:42:38 +04:00
|
|
|
Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
|
2000-05-09 08:53:16 +04:00
|
|
|
Copyright (C) 2000 Information-technology Promotion Agency, Japan
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-05-01 13:42:38 +04:00
|
|
|
**********************************************************************/
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2007-06-10 07:06:15 +04:00
|
|
|
#include "ruby/ruby.h"
|
|
|
|
#include "ruby/st.h"
|
|
|
|
#include "ruby/re.h"
|
2007-11-20 06:16:53 +03:00
|
|
|
#include "ruby/io.h"
|
2012-07-10 17:57:11 +04:00
|
|
|
#include "ruby/thread.h"
|
2008-03-03 11:27:43 +03:00
|
|
|
#include "ruby/util.h"
|
2013-05-27 01:30:44 +04:00
|
|
|
#include "ruby/debug.h"
|
2008-03-12 08:47:10 +03:00
|
|
|
#include "eval_intern.h"
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 08:25:46 +04:00
|
|
|
#include "vm_core.h"
|
2011-05-18 17:41:54 +04:00
|
|
|
#include "internal.h"
|
2007-05-29 19:49:30 +04:00
|
|
|
#include "gc.h"
|
2010-10-26 21:27:32 +04:00
|
|
|
#include "constant.h"
|
2012-11-09 20:05:07 +04:00
|
|
|
#include "ruby_atomic.h"
|
* probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.
* compile.c (rb_insns_name): allowing DTrace probes to access
instruction sequence name.
* Makefile.in: translate probes.d file to appropriate header file.
* common.mk: declare dependencies on the DTrace header.
* configure.in: add a test for existence of DTrace.
* eval.c (setup_exception): add a probe for when an exception is
raised.
* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
end.
* hash.c (empty_hash_alloc): Add a probe for hash allocation.
* insns.def: Add probes for function entry and return.
* internal.h: function declaration for compile.c change.
* load.c (rb_f_load): add probes for `load` entry and exit, require
entry and exit, and wrapping search_required for load path search.
* object.c (rb_obj_alloc): added a probe for general object creation.
* parse.y (yycompile0): added a probe around parse and compile phase.
* string.c (empty_str_alloc, str_new): DTrace probes for string
allocation.
* test/dtrace/*: tests for DTrace probes.
* vm.c (vm_invoke_proc): add probes for function return on exception
raise, hash create, and instruction sequence execution.
* vm_core.h: add probe declarations for function entry and exit.
* vm_dump.c: add probes header file.
* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
function entry and return.
* vm_exec.c: expose instruction number to instruction name function.
* vm_insnshelper.c: add function entry and exit probes for cfunc
methods.
* vm_insnhelper.h: vm usage information is always collected, so
uncomment the functions.
12 19:14:50 2012 Akinori MUSHA <knu@iDaemons.org>
* configure.in (isinf, isnan): isinf() and isnan() are macros on
DragonFly which cannot be found by AC_REPLACE_FUNCS(). This
workaround enforces the fact that they exist on DragonFly.
12 15:59:38 2012 Shugo Maeda <shugo@ruby-lang.org>
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
vm_insnhelper.c (vm_search_method): revert r37616 because it's too
slow. [ruby-dev:46477]
* test/ruby/test_refinement.rb (test_inline_method_cache): skip
the test until the bug is fixed efficiently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-13 01:52:12 +04:00
|
|
|
#include "probes.h"
|
1998-01-16 15:13:05 +03:00
|
|
|
#include <stdio.h>
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#include <stdarg.h>
|
1998-01-16 15:13:05 +03:00
|
|
|
#include <setjmp.h>
|
2001-11-19 17:42:45 +03:00
|
|
|
#include <sys/types.h>
|
2012-01-07 18:02:23 +04:00
|
|
|
#include <assert.h>
|
2001-11-19 17:42:45 +03:00
|
|
|
|
|
|
|
#ifdef HAVE_SYS_TIME_H
|
|
|
|
#include <sys/time.h>
|
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2001-11-19 08:03:03 +03:00
|
|
|
#ifdef HAVE_SYS_RESOURCE_H
|
|
|
|
#include <sys/resource.h>
|
2012-05-17 06:48:59 +04:00
|
|
|
#endif
|
|
|
|
#if defined(__native_client__) && defined(NACL_NEWLIB)
|
|
|
|
# include "nacl/resource.h"
|
|
|
|
# undef HAVE_POSIX_MEMALIGN
|
|
|
|
# undef HAVE_MEMALIGN
|
|
|
|
|
2001-11-19 08:03:03 +03:00
|
|
|
#endif
|
|
|
|
|
2004-07-08 14:27:23 +04:00
|
|
|
#if defined _WIN32 || defined __CYGWIN__
|
|
|
|
#include <windows.h>
|
2012-01-09 02:50:59 +04:00
|
|
|
#elif defined(HAVE_POSIX_MEMALIGN)
|
|
|
|
#elif defined(HAVE_MEMALIGN)
|
2012-01-07 19:13:37 +04:00
|
|
|
#include <malloc.h>
|
|
|
|
#endif
|
|
|
|
|
2007-07-14 11:19:59 +04:00
|
|
|
#ifdef HAVE_VALGRIND_MEMCHECK_H
|
|
|
|
# include <valgrind/memcheck.h>
|
|
|
|
# ifndef VALGRIND_MAKE_MEM_DEFINED
|
2010-12-14 14:32:59 +03:00
|
|
|
# define VALGRIND_MAKE_MEM_DEFINED(p, n) VALGRIND_MAKE_READABLE((p), (n))
|
2007-07-14 11:19:59 +04:00
|
|
|
# endif
|
2007-08-19 08:34:44 +04:00
|
|
|
# ifndef VALGRIND_MAKE_MEM_UNDEFINED
|
2010-12-14 14:32:59 +03:00
|
|
|
# define VALGRIND_MAKE_MEM_UNDEFINED(p, n) VALGRIND_MAKE_WRITABLE((p), (n))
|
2007-08-19 08:34:44 +04:00
|
|
|
# endif
|
2007-07-14 11:19:59 +04:00
|
|
|
#else
|
2012-12-01 13:30:24 +04:00
|
|
|
# define VALGRIND_MAKE_MEM_DEFINED(p, n) 0
|
|
|
|
# define VALGRIND_MAKE_MEM_UNDEFINED(p, n) 0
|
2007-07-14 11:19:59 +04:00
|
|
|
#endif
|
|
|
|
|
2008-03-31 21:58:41 +04:00
|
|
|
#define rb_setjmp(env) RUBY_SETJMP(env)
|
|
|
|
#define rb_jmp_buf rb_jmpbuf_t
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2013-05-17 12:35:26 +04:00
|
|
|
#if defined(HAVE_RB_GC_GUARDED_PTR) && HAVE_RB_GC_GUARDED_PTR
|
|
|
|
volatile VALUE *
|
|
|
|
rb_gc_guarded_ptr(volatile VALUE *ptr)
|
|
|
|
{
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-10-10 19:26:58 +04:00
|
|
|
#ifndef GC_MALLOC_LIMIT
|
|
|
|
#define GC_MALLOC_LIMIT 8000000
|
|
|
|
#endif
|
2011-03-07 11:39:39 +03:00
|
|
|
#define HEAP_MIN_SLOTS 10000
|
|
|
|
#define FREE_MIN 4096
|
2013-03-13 18:52:00 +04:00
|
|
|
#define HEAP_GROWTH_FACTOR 1.8
|
2011-03-07 11:39:39 +03:00
|
|
|
|
2011-10-21 17:02:19 +04:00
|
|
|
typedef struct {
|
|
|
|
unsigned int initial_malloc_limit;
|
|
|
|
unsigned int initial_heap_min_slots;
|
|
|
|
unsigned int initial_free_min;
|
2013-03-13 18:52:00 +04:00
|
|
|
double initial_growth_factor;
|
2011-06-12 04:32:32 +04:00
|
|
|
#if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
|
2013-06-19 02:45:41 +04:00
|
|
|
VALUE gc_stress;
|
2011-06-12 04:32:32 +04:00
|
|
|
#endif
|
2011-10-21 17:02:19 +04:00
|
|
|
} ruby_gc_params_t;
|
|
|
|
|
2011-11-28 07:38:52 +04:00
|
|
|
static ruby_gc_params_t initial_params = {
|
2011-10-21 17:02:19 +04:00
|
|
|
GC_MALLOC_LIMIT,
|
|
|
|
HEAP_MIN_SLOTS,
|
|
|
|
FREE_MIN,
|
2013-03-13 18:52:00 +04:00
|
|
|
HEAP_GROWTH_FACTOR,
|
2011-10-21 17:02:19 +04:00
|
|
|
#if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
|
|
|
|
FALSE,
|
|
|
|
#endif
|
|
|
|
};
|
2011-03-07 11:39:39 +03:00
|
|
|
|
2008-06-15 13:17:06 +04:00
|
|
|
#define nomem_error GET_VM()->special_exceptions[ruby_error_nomemory]
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2013-06-19 10:11:15 +04:00
|
|
|
void rb_gcdebug_print_obj_condition(VALUE obj);
|
|
|
|
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#if USE_RGENGC
|
|
|
|
/* RGENGC_DEBUG:
|
2013-05-22 03:09:22 +04:00
|
|
|
* 1: basic information
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
* 2: remember set operation
|
|
|
|
* 3: mark
|
2013-05-14 05:54:48 +04:00
|
|
|
* 4:
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
* 5: sweep
|
|
|
|
*/
|
|
|
|
#ifndef RGENGC_DEBUG
|
|
|
|
#define RGENGC_DEBUG 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* RGENGC_CHECK_MODE
|
2013-05-15 12:07:30 +04:00
|
|
|
* 0: disable all assertions
|
|
|
|
* 1: enable assertions (to debug RGenGC)
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
* 2: enable bits check (for debugging)
|
2013-06-19 02:04:30 +04:00
|
|
|
* 3: show all references
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
*/
|
|
|
|
#ifndef RGENGC_CHECK_MODE
|
|
|
|
#define RGENGC_CHECK_MODE 0
|
|
|
|
#endif
|
|
|
|
|
2013-05-15 12:07:30 +04:00
|
|
|
/* RGENGC_PROFILE
|
|
|
|
* 0: disable RGenGC profiling
|
|
|
|
* 1: enable profiling for basic information
|
|
|
|
* 2: enable profiling for each types
|
|
|
|
*/
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#ifndef RGENGC_PROFILE
|
|
|
|
#define RGENGC_PROFILE 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#else /* USE_RGENGC */
|
|
|
|
#define RGENGC_DEBUG 0
|
|
|
|
#define RGENGC_CHECK_MODE 0
|
|
|
|
#define RGENGC_PROFILE 0
|
|
|
|
#endif
|
|
|
|
|
2011-09-10 03:34:05 +04:00
|
|
|
#ifndef GC_PROFILE_MORE_DETAIL
|
2013-05-29 19:10:28 +04:00
|
|
|
#define GC_PROFILE_MORE_DETAIL 1
|
2011-09-10 03:34:05 +04:00
|
|
|
#endif
|
2013-03-24 08:53:44 +04:00
|
|
|
#ifndef GC_ENABLE_LAZY_SWEEP
|
|
|
|
#define GC_ENABLE_LAZY_SWEEP 1
|
|
|
|
#endif
|
2013-06-16 00:18:11 +04:00
|
|
|
#ifndef CALC_EXACT_MALLOC_SIZE
|
|
|
|
#define CALC_EXACT_MALLOC_SIZE 0
|
|
|
|
#endif
|
2011-09-10 03:34:05 +04:00
|
|
|
|
2013-05-21 12:19:07 +04:00
|
|
|
typedef enum {
|
|
|
|
GPR_FLAG_NONE = 0x00,
|
|
|
|
GPR_FLAG_MINOR = 0x01, /* not major gc */
|
|
|
|
GPR_FLAG_HAVE_FINALIZE = 0x02,
|
|
|
|
|
|
|
|
/* reason */
|
|
|
|
GPR_FLAG_NEWOBJ = 0x04,
|
|
|
|
GPR_FLAG_MALLOC = 0x08,
|
|
|
|
GPR_FLAG_METHOD = 0x10,
|
|
|
|
GPR_FLAG_CAPI = 0x20,
|
2013-06-18 17:37:09 +04:00
|
|
|
GPR_FLAG_STRESS = 0x40
|
2013-05-21 12:19:07 +04:00
|
|
|
} gc_profile_record_flag;
|
|
|
|
|
2008-08-11 13:36:57 +04:00
|
|
|
typedef struct gc_profile_record {
|
2013-05-21 12:19:07 +04:00
|
|
|
int flags;
|
|
|
|
|
2008-08-11 13:36:57 +04:00
|
|
|
double gc_time;
|
2012-10-31 13:22:37 +04:00
|
|
|
double gc_invoke_time;
|
|
|
|
|
|
|
|
size_t heap_total_objects;
|
|
|
|
size_t heap_use_size;
|
|
|
|
size_t heap_total_size;
|
|
|
|
|
|
|
|
#if GC_PROFILE_MORE_DETAIL
|
2008-08-11 13:36:57 +04:00
|
|
|
double gc_mark_time;
|
|
|
|
double gc_sweep_time;
|
2009-05-13 18:08:26 +04:00
|
|
|
|
2008-08-11 13:36:57 +04:00
|
|
|
size_t heap_use_slots;
|
|
|
|
size_t heap_live_objects;
|
|
|
|
size_t heap_free_objects;
|
2009-05-13 18:08:26 +04:00
|
|
|
|
2008-08-11 13:36:57 +04:00
|
|
|
size_t allocate_increase;
|
|
|
|
size_t allocate_limit;
|
2013-06-16 00:18:11 +04:00
|
|
|
#if CALC_EXACT_MALLOC_SIZE
|
|
|
|
size_t allocated_size;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
double prepare_time;
|
|
|
|
size_t removing_objects;
|
|
|
|
size_t empty_objects;
|
2012-10-31 13:22:37 +04:00
|
|
|
#endif
|
2008-08-11 13:36:57 +04:00
|
|
|
} gc_profile_record;
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__CYGWIN__)
|
|
|
|
#pragma pack(push, 1) /* magic for reducing sizeof(RVALUE): 24 -> 20 */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct RVALUE {
|
|
|
|
union {
|
|
|
|
struct {
|
2007-06-25 15:20:45 +04:00
|
|
|
VALUE flags; /* always 0 for freed obj */
|
2006-12-31 18:02:22 +03:00
|
|
|
struct RVALUE *next;
|
|
|
|
} free;
|
|
|
|
struct RBasic basic;
|
|
|
|
struct RObject object;
|
|
|
|
struct RClass klass;
|
|
|
|
struct RFloat flonum;
|
|
|
|
struct RString string;
|
|
|
|
struct RArray array;
|
|
|
|
struct RRegexp regexp;
|
|
|
|
struct RHash hash;
|
|
|
|
struct RData data;
|
2009-06-17 01:36:50 +04:00
|
|
|
struct RTypedData typeddata;
|
2006-12-31 18:02:22 +03:00
|
|
|
struct RStruct rstruct;
|
|
|
|
struct RBignum bignum;
|
|
|
|
struct RFile file;
|
|
|
|
struct RNode node;
|
|
|
|
struct RMatch match;
|
2008-03-16 03:23:43 +03:00
|
|
|
struct RRational rational;
|
|
|
|
struct RComplex complex;
|
2013-05-15 14:26:22 +04:00
|
|
|
struct {
|
|
|
|
struct RBasic basic;
|
|
|
|
VALUE v1;
|
|
|
|
VALUE v2;
|
|
|
|
VALUE v3;
|
|
|
|
} values;
|
2006-12-31 18:02:22 +03:00
|
|
|
} as;
|
|
|
|
#ifdef GC_DEBUG
|
2009-06-15 13:06:16 +04:00
|
|
|
const char *file;
|
2006-12-31 18:02:22 +03:00
|
|
|
int line;
|
|
|
|
#endif
|
|
|
|
} RVALUE;
|
|
|
|
|
|
|
|
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__CYGWIN__)
|
|
|
|
#pragma pack(pop)
|
|
|
|
#endif
|
|
|
|
|
2008-04-14 07:47:04 +04:00
|
|
|
struct heaps_slot {
|
2012-11-10 19:04:27 +04:00
|
|
|
struct heaps_header *header;
|
2012-01-07 18:02:23 +04:00
|
|
|
RVALUE *freelist;
|
2010-05-28 15:13:42 +04:00
|
|
|
struct heaps_slot *next;
|
|
|
|
struct heaps_slot *prev;
|
2012-01-07 18:02:23 +04:00
|
|
|
struct heaps_slot *free_next;
|
2010-05-28 15:13:42 +04:00
|
|
|
};
|
|
|
|
|
2012-01-09 15:58:12 +04:00
|
|
|
struct heaps_header {
|
|
|
|
struct heaps_slot *base;
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
uintptr_t *mark_bits;
|
|
|
|
#if USE_RGENGC
|
|
|
|
uintptr_t *rememberset_bits;
|
2013-06-07 06:28:03 +04:00
|
|
|
uintptr_t *oldgen_bits;
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#endif
|
2010-05-28 15:13:42 +04:00
|
|
|
RVALUE *start;
|
|
|
|
RVALUE *end;
|
2012-11-10 19:04:27 +04:00
|
|
|
size_t limit;
|
2008-04-14 07:47:04 +04:00
|
|
|
};
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2012-01-07 18:02:23 +04:00
|
|
|
struct heaps_free_bitmap {
|
|
|
|
struct heaps_free_bitmap *next;
|
|
|
|
};
|
|
|
|
|
2008-04-14 07:47:04 +04:00
|
|
|
struct gc_list {
|
|
|
|
VALUE *varptr;
|
|
|
|
struct gc_list *next;
|
|
|
|
};
|
|
|
|
|
2012-10-03 16:30:21 +04:00
|
|
|
#define STACK_CHUNK_SIZE 500
|
|
|
|
|
|
|
|
typedef struct stack_chunk {
|
|
|
|
VALUE data[STACK_CHUNK_SIZE];
|
|
|
|
struct stack_chunk *next;
|
|
|
|
} stack_chunk_t;
|
|
|
|
|
|
|
|
typedef struct mark_stack {
|
|
|
|
stack_chunk_t *chunk;
|
|
|
|
stack_chunk_t *cache;
|
|
|
|
size_t index;
|
|
|
|
size_t limit;
|
|
|
|
size_t cache_size;
|
|
|
|
size_t unused_cache_size;
|
|
|
|
} mark_stack_t;
|
|
|
|
|
2008-04-27 07:20:35 +04:00
|
|
|
typedef struct rb_objspace {
|
2008-04-14 07:47:04 +04:00
|
|
|
struct {
|
2008-05-12 10:28:43 +04:00
|
|
|
size_t limit;
|
|
|
|
size_t increase;
|
2013-06-16 00:53:01 +04:00
|
|
|
size_t increase2;
|
2008-06-08 14:27:06 +04:00
|
|
|
#if CALC_EXACT_MALLOC_SIZE
|
|
|
|
size_t allocated_size;
|
|
|
|
size_t allocations;
|
|
|
|
#endif
|
|
|
|
} malloc_params;
|
2008-04-14 07:47:04 +04:00
|
|
|
struct {
|
2008-05-11 09:44:36 +04:00
|
|
|
size_t increment;
|
2008-04-14 07:47:04 +04:00
|
|
|
struct heaps_slot *ptr;
|
2010-05-28 15:13:42 +04:00
|
|
|
struct heaps_slot *sweep_slots;
|
2012-01-07 18:02:23 +04:00
|
|
|
struct heaps_slot *free_slots;
|
2012-11-10 19:04:27 +04:00
|
|
|
struct heaps_header **sorted;
|
2008-05-11 09:44:36 +04:00
|
|
|
size_t length;
|
|
|
|
size_t used;
|
2012-01-07 18:02:23 +04:00
|
|
|
struct heaps_free_bitmap *free_bitmap;
|
2008-04-14 07:47:04 +04:00
|
|
|
RVALUE *range[2];
|
2012-11-10 19:04:27 +04:00
|
|
|
struct heaps_header *freed;
|
2010-05-28 15:13:42 +04:00
|
|
|
size_t free_num;
|
2010-06-06 08:12:20 +04:00
|
|
|
size_t free_min;
|
2010-10-27 23:02:24 +04:00
|
|
|
size_t final_num;
|
2010-05-28 15:13:42 +04:00
|
|
|
size_t do_heap_free;
|
2008-04-14 07:47:04 +04:00
|
|
|
} heap;
|
|
|
|
struct {
|
|
|
|
int dont_gc;
|
2010-10-21 08:18:09 +04:00
|
|
|
int dont_lazy_sweep;
|
2008-04-14 07:47:04 +04:00
|
|
|
int during_gc;
|
2011-09-29 20:54:14 +04:00
|
|
|
rb_atomic_t finalizing;
|
2008-04-14 07:47:04 +04:00
|
|
|
} flags;
|
|
|
|
struct {
|
|
|
|
st_table *table;
|
|
|
|
RVALUE *deferred;
|
|
|
|
} final;
|
2012-10-03 16:30:21 +04:00
|
|
|
mark_stack_t mark_stack;
|
2008-08-11 13:36:57 +04:00
|
|
|
struct {
|
|
|
|
int run;
|
|
|
|
gc_profile_record *record;
|
2013-05-13 20:34:25 +04:00
|
|
|
size_t next_index;
|
2008-08-11 13:36:57 +04:00
|
|
|
size_t size;
|
2013-05-21 12:19:07 +04:00
|
|
|
|
2013-06-16 00:18:11 +04:00
|
|
|
#if GC_PROFILE_MORE_DETAIL
|
|
|
|
double prepare_time;
|
|
|
|
#endif
|
2008-08-11 13:36:57 +04:00
|
|
|
double invoke_time;
|
2013-05-13 20:34:25 +04:00
|
|
|
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#if USE_RGENGC
|
|
|
|
size_t minor_gc_count;
|
|
|
|
size_t major_gc_count;
|
|
|
|
#ifdef RGENGC_PROFILE
|
2013-06-07 05:17:19 +04:00
|
|
|
size_t generated_normal_object_count;
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
size_t generated_shady_object_count;
|
|
|
|
size_t shade_operation_count;
|
2013-05-26 21:27:42 +04:00
|
|
|
size_t promote_operation_count;
|
2013-06-07 05:17:19 +04:00
|
|
|
size_t remembered_normal_object_count;
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
size_t remembered_shady_object_count;
|
2013-05-15 12:07:30 +04:00
|
|
|
#if RGENGC_PROFILE >= 2
|
2013-06-18 06:27:37 +04:00
|
|
|
size_t generated_normal_object_count_types[RUBY_T_MASK];
|
2013-05-15 12:07:30 +04:00
|
|
|
size_t generated_shady_object_count_types[RUBY_T_MASK];
|
2013-05-26 20:43:21 +04:00
|
|
|
size_t shade_operation_count_types[RUBY_T_MASK];
|
2013-05-26 21:27:42 +04:00
|
|
|
size_t promote_operation_count_types[RUBY_T_MASK];
|
2013-06-07 05:17:19 +04:00
|
|
|
size_t remembered_normal_object_count_types[RUBY_T_MASK];
|
2013-05-26 20:43:21 +04:00
|
|
|
size_t remembered_shady_object_count_types[RUBY_T_MASK];
|
2013-05-15 12:07:30 +04:00
|
|
|
#endif
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#endif /* RGENGC_PROFILE */
|
|
|
|
#endif /* USE_RGENGC */
|
|
|
|
|
2013-05-13 20:34:25 +04:00
|
|
|
#if GC_PROFILE_MORE_DETAIL
|
|
|
|
double gc_sweep_start_time; /* temporary profiling space */
|
|
|
|
#endif
|
2008-08-11 13:36:57 +04:00
|
|
|
} profile;
|
2008-04-14 07:47:04 +04:00
|
|
|
struct gc_list *global_list;
|
2010-10-27 23:02:24 +04:00
|
|
|
size_t count;
|
2012-11-29 09:05:19 +04:00
|
|
|
size_t total_allocated_object_num;
|
|
|
|
size_t total_freed_object_num;
|
2013-05-27 04:21:02 +04:00
|
|
|
rb_event_flag_t hook_events; /* this place may be affinity with memory cache */
|
2013-06-19 02:45:41 +04:00
|
|
|
VALUE gc_stress;
|
2012-10-05 12:14:09 +04:00
|
|
|
|
|
|
|
struct mark_func_data_struct {
|
2012-10-24 04:04:56 +04:00
|
|
|
void *data;
|
|
|
|
void (*mark_func)(VALUE v, void *data);
|
2012-10-05 12:14:09 +04:00
|
|
|
} *mark_func_data;
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
|
|
|
|
struct {
|
|
|
|
int during_minor_gc;
|
|
|
|
int parent_object_is_promoted;
|
|
|
|
|
|
|
|
/* for check mode */
|
|
|
|
VALUE parent_object;
|
|
|
|
VALUE interesting_object;
|
|
|
|
|
2013-05-24 14:21:04 +04:00
|
|
|
int need_major_gc;
|
|
|
|
size_t remembered_shady_object_count;
|
|
|
|
size_t remembered_shady_object_limit;
|
|
|
|
size_t oldgen_object_count;
|
|
|
|
size_t oldgen_object_limit;
|
|
|
|
} rgengc;
|
2008-04-14 07:47:04 +04:00
|
|
|
} rb_objspace_t;
|
|
|
|
|
2008-04-27 07:20:35 +04:00
|
|
|
#if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
|
|
|
|
#define rb_objspace (*GET_VM()->objspace)
|
2011-10-21 17:02:19 +04:00
|
|
|
#define ruby_initial_gc_stress initial_params.gc_stress
|
2013-06-19 02:45:41 +04:00
|
|
|
VALUE *ruby_initial_gc_stress_ptr = &ruby_initial_gc_stress;
|
2008-04-27 07:20:35 +04:00
|
|
|
#else
|
2012-07-28 19:34:44 +04:00
|
|
|
static rb_objspace_t rb_objspace = {{GC_MALLOC_LIMIT}};
|
2008-06-14 02:57:41 +04:00
|
|
|
int *ruby_initial_gc_stress_ptr = &rb_objspace.gc_stress;
|
2008-04-27 07:20:35 +04:00
|
|
|
#endif
|
2008-06-08 14:27:06 +04:00
|
|
|
#define malloc_limit objspace->malloc_params.limit
|
|
|
|
#define malloc_increase objspace->malloc_params.increase
|
2013-06-16 00:53:01 +04:00
|
|
|
#define malloc_increase2 objspace->malloc_params.increase2
|
2013-06-16 00:18:11 +04:00
|
|
|
#define malloc_allocated_size objspace->malloc_params.allocated_size
|
2008-04-14 07:47:04 +04:00
|
|
|
#define heaps objspace->heap.ptr
|
|
|
|
#define heaps_length objspace->heap.length
|
|
|
|
#define heaps_used objspace->heap.used
|
|
|
|
#define lomem objspace->heap.range[0]
|
|
|
|
#define himem objspace->heap.range[1]
|
2008-04-25 13:03:32 +04:00
|
|
|
#define heaps_inc objspace->heap.increment
|
|
|
|
#define heaps_freed objspace->heap.freed
|
2008-04-14 07:47:04 +04:00
|
|
|
#define dont_gc objspace->flags.dont_gc
|
|
|
|
#define during_gc objspace->flags.during_gc
|
2011-09-29 20:54:14 +04:00
|
|
|
#define finalizing objspace->flags.finalizing
|
2008-04-14 07:47:04 +04:00
|
|
|
#define finalizer_table objspace->final.table
|
|
|
|
#define deferred_final_list objspace->final.deferred
|
|
|
|
#define global_List objspace->global_list
|
2008-06-13 19:09:22 +04:00
|
|
|
#define ruby_gc_stress objspace->gc_stress
|
2011-10-21 17:02:19 +04:00
|
|
|
#define initial_malloc_limit initial_params.initial_malloc_limit
|
|
|
|
#define initial_heap_min_slots initial_params.initial_heap_min_slots
|
|
|
|
#define initial_free_min initial_params.initial_free_min
|
2013-03-13 18:52:00 +04:00
|
|
|
#define initial_growth_factor initial_params.initial_growth_factor
|
2008-04-14 07:47:04 +04:00
|
|
|
|
2011-09-08 02:33:14 +04:00
|
|
|
#define is_lazy_sweeping(objspace) ((objspace)->heap.sweep_slots != 0)
|
|
|
|
|
2012-12-20 11:43:54 +04:00
|
|
|
#if SIZEOF_LONG == SIZEOF_VOIDP
|
|
|
|
# define nonspecial_obj_id(obj) (VALUE)((SIGNED_VALUE)(obj)|FIXNUM_FLAG)
|
2012-12-22 08:25:18 +04:00
|
|
|
# define obj_id_to_ref(objid) ((objid) ^ FIXNUM_FLAG) /* unset FIXNUM_FLAG */
|
2012-12-20 11:43:54 +04:00
|
|
|
#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
|
|
|
|
# define nonspecial_obj_id(obj) LL2NUM((SIGNED_VALUE)(obj) / 2)
|
2012-12-22 08:25:18 +04:00
|
|
|
# define obj_id_to_ref(objid) (FIXNUM_P(objid) ? \
|
|
|
|
((objid) ^ FIXNUM_FLAG) : (NUM2PTR(objid) << 1))
|
2012-12-20 11:43:54 +04:00
|
|
|
#else
|
|
|
|
# error not supported
|
|
|
|
#endif
|
2011-09-29 15:09:48 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
#define RANY(o) ((RVALUE*)(o))
|
|
|
|
#define has_free_object (objspace->heap.free_slots && objspace->heap.free_slots->freelist)
|
|
|
|
|
2012-01-09 15:58:12 +04:00
|
|
|
#define HEAP_HEADER(p) ((struct heaps_header *)(p))
|
2012-08-05 14:39:37 +04:00
|
|
|
#define GET_HEAP_HEADER(x) (HEAP_HEADER((uintptr_t)(x) & ~(HEAP_ALIGN_MASK)))
|
|
|
|
#define GET_HEAP_SLOT(x) (GET_HEAP_HEADER(x)->base)
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#define GET_HEAP_MARK_BITS(x) (GET_HEAP_HEADER(x)->mark_bits)
|
|
|
|
#define GET_HEAP_REMEMBERSET_BITS(x) (GET_HEAP_HEADER(x)->rememberset_bits)
|
2013-06-07 06:28:03 +04:00
|
|
|
#define GET_HEAP_OLDGEN_BITS(x) (GET_HEAP_HEADER(x)->oldgen_bits)
|
2012-08-05 14:39:37 +04:00
|
|
|
#define NUM_IN_SLOT(p) (((uintptr_t)(p) & HEAP_ALIGN_MASK)/sizeof(RVALUE))
|
2012-10-04 11:23:41 +04:00
|
|
|
#define BITMAP_INDEX(p) (NUM_IN_SLOT(p) / (sizeof(uintptr_t) * CHAR_BIT))
|
|
|
|
#define BITMAP_OFFSET(p) (NUM_IN_SLOT(p) & ((sizeof(uintptr_t) * CHAR_BIT)-1))
|
2013-06-07 06:25:19 +04:00
|
|
|
#define BITMAP_BIT(p) ((uintptr_t)1 << BITMAP_OFFSET(p))
|
|
|
|
/* Marking */
|
|
|
|
#define MARKED_IN_BITMAP(bits, p) (bits[BITMAP_INDEX(p)] & BITMAP_BIT(p))
|
|
|
|
#define MARK_IN_BITMAP(bits, p) (bits[BITMAP_INDEX(p)] = bits[BITMAP_INDEX(p)] | BITMAP_BIT(p))
|
|
|
|
#define CLEAR_IN_BITMAP(bits, p) (bits[BITMAP_INDEX(p)] = bits[BITMAP_INDEX(p)] & ~BITMAP_BIT(p))
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
|
|
|
|
#ifndef HEAP_ALIGN_LOG
|
|
|
|
/* default tiny heap size: 16KB */
|
|
|
|
#define HEAP_ALIGN_LOG 14
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define CEILDIV(i, mod) (((i) + (mod) - 1)/(mod))
|
|
|
|
|
2012-10-04 11:23:41 +04:00
|
|
|
enum {
|
|
|
|
HEAP_ALIGN = (1UL << HEAP_ALIGN_LOG),
|
|
|
|
HEAP_ALIGN_MASK = (~(~0UL << HEAP_ALIGN_LOG)),
|
|
|
|
REQUIRED_SIZE_BY_MALLOC = (sizeof(size_t) * 5),
|
|
|
|
HEAP_SIZE = (HEAP_ALIGN - REQUIRED_SIZE_BY_MALLOC),
|
|
|
|
HEAP_OBJ_LIMIT = (unsigned int)((HEAP_SIZE - sizeof(struct heaps_header))/sizeof(struct RVALUE)),
|
|
|
|
HEAP_BITMAP_LIMIT = CEILDIV(CEILDIV(HEAP_SIZE, sizeof(struct RVALUE)), sizeof(uintptr_t) * CHAR_BIT)
|
|
|
|
};
|
2012-08-05 14:39:37 +04:00
|
|
|
|
|
|
|
int ruby_gc_debug_indent = 0;
|
|
|
|
VALUE rb_mGC;
|
|
|
|
extern st_table *rb_class_tbl;
|
|
|
|
int ruby_disable_gc_stress = 0;
|
2012-01-07 18:02:23 +04:00
|
|
|
|
2009-09-18 11:29:17 +04:00
|
|
|
static void rb_objspace_call_finalizer(rb_objspace_t *objspace);
|
2012-03-13 07:37:06 +04:00
|
|
|
static VALUE define_final0(VALUE obj, VALUE block);
|
|
|
|
VALUE rb_define_final(VALUE obj, VALUE block);
|
|
|
|
VALUE rb_undefine_final(VALUE obj);
|
2012-08-05 14:39:37 +04:00
|
|
|
static void run_final(rb_objspace_t *objspace, VALUE obj);
|
|
|
|
static void initial_expand_heap(rb_objspace_t *objspace);
|
|
|
|
|
|
|
|
static void negative_size_allocation_error(const char *);
|
|
|
|
static void *aligned_malloc(size_t, size_t);
|
|
|
|
static void aligned_free(void *);
|
|
|
|
|
2012-10-03 16:30:21 +04:00
|
|
|
static void init_mark_stack(mark_stack_t *stack);
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static VALUE lazy_sweep_enable(void);
|
2013-05-22 03:09:22 +04:00
|
|
|
static int garbage_collect(rb_objspace_t *, int full_mark, int immediate_sweep, int reason);
|
|
|
|
static int garbage_collect_body(rb_objspace_t *, int full_mark, int immediate_sweep, int reason);
|
2012-10-24 08:29:53 +04:00
|
|
|
static int gc_prepare_free_objects(rb_objspace_t *);
|
2012-10-03 16:30:21 +04:00
|
|
|
static void mark_tbl(rb_objspace_t *, st_table *);
|
2012-08-05 16:12:45 +04:00
|
|
|
static void rest_sweep(rb_objspace_t *);
|
2012-10-04 11:31:31 +04:00
|
|
|
static void gc_mark_stacked_objects(rb_objspace_t *);
|
2012-08-05 14:39:37 +04:00
|
|
|
|
2013-06-17 06:54:25 +04:00
|
|
|
static void gc_mark(rb_objspace_t *objspace, VALUE ptr);
|
|
|
|
static void gc_mark_maybe(rb_objspace_t *objspace, VALUE ptr);
|
|
|
|
static void gc_mark_children(rb_objspace_t *objspace, VALUE ptr);
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static double getrusage_time(void);
|
2013-05-21 12:19:07 +04:00
|
|
|
static inline void gc_prof_timer_start(rb_objspace_t *, int reason);
|
2013-05-21 12:21:59 +04:00
|
|
|
static inline void gc_prof_timer_stop(rb_objspace_t *);
|
2012-08-05 14:39:37 +04:00
|
|
|
static inline void gc_prof_mark_timer_start(rb_objspace_t *);
|
|
|
|
static inline void gc_prof_mark_timer_stop(rb_objspace_t *);
|
2013-05-13 20:34:25 +04:00
|
|
|
static inline void gc_prof_sweep_slot_timer_start(rb_objspace_t *);
|
|
|
|
static inline void gc_prof_sweep_slot_timer_stop(rb_objspace_t *);
|
2012-08-05 14:39:37 +04:00
|
|
|
static inline void gc_prof_set_malloc_info(rb_objspace_t *);
|
|
|
|
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
static const char *obj_type_name(VALUE obj);
|
|
|
|
|
|
|
|
#if USE_RGENGC
|
|
|
|
static int rgengc_remembered(rb_objspace_t *objspace, VALUE obj);
|
|
|
|
static void rgengc_remember(rb_objspace_t *objspace, VALUE obj);
|
2013-06-07 06:32:57 +04:00
|
|
|
static void rgengc_mark_and_rememberset_clear(rb_objspace_t *objspace);
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
static size_t rgengc_rememberset_mark(rb_objspace_t *objspace);
|
|
|
|
|
|
|
|
#define FL_TEST2(x,f) ((RGENGC_CHECK_MODE && SPECIAL_CONST_P(x)) ? (rb_bug("FL_TEST2: SPECIAL_CONST"), 0) : FL_TEST_RAW((x),(f)))
|
|
|
|
#define FL_SET2(x,f) do {if (RGENGC_CHECK_MODE && SPECIAL_CONST_P(x)) rb_bug("FL_SET2: SPECIAL_CONST"); RBASIC(x)->flags |= (f);} while (0)
|
|
|
|
#define FL_UNSET2(x,f) do {if (RGENGC_CHECK_MODE && SPECIAL_CONST_P(x)) rb_bug("FL_UNSET2: SPECIAL_CONST"); RBASIC(x)->flags &= ~(f);} while (0)
|
|
|
|
|
2013-06-07 05:17:19 +04:00
|
|
|
#define RVALUE_SHADY(x) (!FL_TEST2((x), FL_WB_PROTECTED))
|
2013-06-07 06:28:03 +04:00
|
|
|
#define RVALUE_PROMOTED_FROM_BITMAP(x) MARKED_IN_BITMAP(GET_HEAP_OLDGEN_BITS(x),x)
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
|
2013-06-19 18:34:11 +04:00
|
|
|
static inline int
|
|
|
|
RVALUE_PROMOTED(VALUE obj)
|
|
|
|
{
|
|
|
|
int result = FL_TEST2((obj), FL_OLDGEN);
|
|
|
|
|
|
|
|
if (RGENGC_CHECK_MODE > 0) {
|
|
|
|
int bitmap_result = RVALUE_PROMOTED_FROM_BITMAP(obj);
|
|
|
|
if (!result != !bitmap_result) rb_bug("RVALUE_PROMOTED: %p (%s) flag %d but bitmap is %d\n",
|
|
|
|
(void *)obj, obj_type_name(obj), !!result, !!bitmap_result);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-05-26 21:27:42 +04:00
|
|
|
static inline void
|
|
|
|
RVALUE_PROMOTE(VALUE obj)
|
|
|
|
{
|
2013-06-07 06:28:03 +04:00
|
|
|
MARK_IN_BITMAP(GET_HEAP_OLDGEN_BITS(obj), obj);
|
2013-05-26 21:27:42 +04:00
|
|
|
FL_SET2(obj, FL_OLDGEN);
|
|
|
|
#if RGENGC_PROFILE >= 1
|
|
|
|
{
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
objspace->profile.promote_operation_count++;
|
|
|
|
#if RGENGC_PROFILE >= 2
|
|
|
|
objspace->profile.promote_operation_count_types[BUILTIN_TYPE(obj)]++;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2013-06-07 06:28:03 +04:00
|
|
|
|
2013-06-10 12:15:31 +04:00
|
|
|
static inline void
|
|
|
|
RVALUE_DEMOTE(VALUE obj)
|
|
|
|
{
|
|
|
|
FL_UNSET2(obj, FL_OLDGEN);
|
|
|
|
CLEAR_IN_BITMAP(GET_HEAP_OLDGEN_BITS(obj), obj);
|
|
|
|
}
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#endif
|
|
|
|
|
2013-06-16 00:18:11 +04:00
|
|
|
static inline gc_profile_record *
|
|
|
|
gc_prof_record(rb_objspace_t *objspace)
|
|
|
|
{
|
|
|
|
size_t index = objspace->profile.next_index - 1;
|
|
|
|
return &objspace->profile.record[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
static void
|
|
|
|
rgengc_report_body(int level, rb_objspace_t *objspace, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
if (level <= RGENGC_DEBUG) {
|
|
|
|
char buf[1024];
|
|
|
|
FILE *out = stderr;
|
|
|
|
va_list args;
|
|
|
|
const char *status = " ";
|
|
|
|
|
|
|
|
if (during_gc) {
|
|
|
|
status = objspace->rgengc.during_minor_gc ? "-" : "+";
|
|
|
|
}
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
vsnprintf(buf, 1024, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
fprintf(out, "%s|", status);
|
|
|
|
fputs(buf, out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define rgengc_report if (RGENGC_DEBUG) rgengc_report_body
|
2012-08-05 14:39:37 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
--------------------------- ObjectSpace -----------------------------
|
|
|
|
*/
|
2009-09-18 11:29:17 +04:00
|
|
|
|
2008-06-05 18:41:41 +04:00
|
|
|
#if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
|
2008-04-14 07:47:04 +04:00
|
|
|
rb_objspace_t *
|
|
|
|
rb_objspace_alloc(void)
|
|
|
|
{
|
2008-04-27 07:20:35 +04:00
|
|
|
rb_objspace_t *objspace = malloc(sizeof(rb_objspace_t));
|
2008-04-14 07:47:04 +04:00
|
|
|
memset(objspace, 0, sizeof(*objspace));
|
2011-03-07 11:39:39 +03:00
|
|
|
malloc_limit = initial_malloc_limit;
|
2008-06-14 02:57:41 +04:00
|
|
|
ruby_gc_stress = ruby_initial_gc_stress;
|
2008-04-25 13:03:32 +04:00
|
|
|
|
2008-04-14 07:47:04 +04:00
|
|
|
return objspace;
|
|
|
|
}
|
2011-10-21 17:01:37 +04:00
|
|
|
#endif
|
2009-09-18 11:29:17 +04:00
|
|
|
|
2011-10-21 17:01:37 +04:00
|
|
|
#if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
|
2012-10-03 17:23:30 +04:00
|
|
|
static void free_stack_chunks(mark_stack_t *);
|
2010-12-03 06:53:21 +03:00
|
|
|
|
2009-09-18 11:29:17 +04:00
|
|
|
void
|
|
|
|
rb_objspace_free(rb_objspace_t *objspace)
|
|
|
|
{
|
2012-02-21 13:35:07 +04:00
|
|
|
rest_sweep(objspace);
|
2013-05-22 09:21:06 +04:00
|
|
|
|
2009-09-18 11:29:17 +04:00
|
|
|
if (objspace->profile.record) {
|
|
|
|
free(objspace->profile.record);
|
|
|
|
objspace->profile.record = 0;
|
|
|
|
}
|
|
|
|
if (global_List) {
|
|
|
|
struct gc_list *list, *next;
|
|
|
|
for (list = global_List; list; list = next) {
|
|
|
|
next = list->next;
|
2012-01-09 01:02:08 +04:00
|
|
|
xfree(list);
|
2009-09-18 11:29:17 +04:00
|
|
|
}
|
|
|
|
}
|
2012-01-07 18:02:23 +04:00
|
|
|
if (objspace->heap.free_bitmap) {
|
|
|
|
struct heaps_free_bitmap *list, *next;
|
|
|
|
for (list = objspace->heap.free_bitmap; list; list = next) {
|
|
|
|
next = list->next;
|
|
|
|
free(list);
|
|
|
|
}
|
|
|
|
}
|
2010-05-28 15:13:42 +04:00
|
|
|
if (objspace->heap.sorted) {
|
* compile.c, cont.c, gc.c, insns.def, iseq.c, iseq.h, process.c,
thread.c, vm.c, vm_core.h, vm_dump.c, vm_eval.c,
vm_insnhelper.c, vm_method.c, template/insns_info.inc.tmpl,
tool/instruction.rb: fixed types.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-09-22 00:58:26 +04:00
|
|
|
size_t i;
|
2009-09-18 11:29:17 +04:00
|
|
|
for (i = 0; i < heaps_used; ++i) {
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
free(objspace->heap.sorted[i]->mark_bits);
|
|
|
|
#if USE_RGENGC
|
|
|
|
free(objspace->heap.sorted[i]->rememberset_bits);
|
2013-06-07 06:28:03 +04:00
|
|
|
free(objspace->heap.sorted[i]->oldgen_bits);
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#endif
|
2012-11-10 19:04:27 +04:00
|
|
|
aligned_free(objspace->heap.sorted[i]);
|
2009-09-18 11:29:17 +04:00
|
|
|
}
|
2010-05-28 15:13:42 +04:00
|
|
|
free(objspace->heap.sorted);
|
2009-09-18 11:29:17 +04:00
|
|
|
heaps_used = 0;
|
|
|
|
heaps = 0;
|
|
|
|
}
|
2012-10-03 16:30:21 +04:00
|
|
|
free_stack_chunks(&objspace->mark_stack);
|
2009-09-18 11:29:17 +04:00
|
|
|
free(objspace);
|
|
|
|
}
|
2008-06-05 18:41:41 +04:00
|
|
|
#endif
|
2008-04-14 07:47:04 +04:00
|
|
|
|
2002-04-24 08:54:16 +04:00
|
|
|
void
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_global_variable(VALUE *var)
|
1999-12-14 09:50:43 +03:00
|
|
|
{
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_gc_register_address(var);
|
|
|
|
}
|
2000-12-29 05:47:07 +03:00
|
|
|
|
2009-01-12 06:41:20 +03:00
|
|
|
static void
|
2012-08-05 14:39:37 +04:00
|
|
|
allocate_sorted_heaps(rb_objspace_t *objspace, size_t next_heaps_length)
|
2009-01-12 06:41:20 +03:00
|
|
|
{
|
2012-11-10 19:04:27 +04:00
|
|
|
struct heaps_header **p;
|
2012-08-05 14:39:37 +04:00
|
|
|
struct heaps_free_bitmap *bits;
|
|
|
|
size_t size, add, i;
|
|
|
|
|
2012-11-10 19:04:27 +04:00
|
|
|
size = next_heaps_length*sizeof(struct heaps_header *);
|
2012-08-05 14:39:37 +04:00
|
|
|
add = next_heaps_length - heaps_used;
|
|
|
|
|
|
|
|
if (heaps_used > 0) {
|
2012-11-10 19:04:27 +04:00
|
|
|
p = (struct heaps_header **)realloc(objspace->heap.sorted, size);
|
2012-08-05 14:39:37 +04:00
|
|
|
if (p) objspace->heap.sorted = p;
|
2009-01-12 06:41:20 +03:00
|
|
|
}
|
|
|
|
else {
|
2012-11-10 19:04:27 +04:00
|
|
|
p = objspace->heap.sorted = (struct heaps_header **)malloc(size);
|
2009-01-12 06:41:20 +03:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if (p == 0) {
|
|
|
|
during_gc = 0;
|
|
|
|
rb_memerror();
|
1999-12-14 09:50:43 +03:00
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
|
2013-06-07 06:28:03 +04:00
|
|
|
for (i = 0; i < add * (USE_RGENGC ? 3 : 1) /* mark bits and rememberset bits and oldgen bits */; i++) {
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
bits = (struct heaps_free_bitmap *)malloc(HEAP_BITMAP_LIMIT * sizeof(uintptr_t));
|
2012-08-05 14:39:37 +04:00
|
|
|
if (bits == 0) {
|
|
|
|
during_gc = 0;
|
|
|
|
rb_memerror();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bits->next = objspace->heap.free_bitmap;
|
|
|
|
objspace->heap.free_bitmap = bits;
|
2008-06-15 13:17:06 +04:00
|
|
|
}
|
1999-12-14 09:50:43 +03:00
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static void
|
|
|
|
link_free_heap_slot(rb_objspace_t *objspace, struct heaps_slot *slot)
|
2006-01-10 01:32:55 +03:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
slot->free_next = objspace->heap.free_slots;
|
|
|
|
objspace->heap.free_slots = slot;
|
2006-01-10 01:32:55 +03:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static void
|
|
|
|
unlink_free_heap_slot(rb_objspace_t *objspace, struct heaps_slot *slot)
|
2006-01-10 01:32:55 +03:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
objspace->heap.free_slots = slot->free_next;
|
|
|
|
slot->free_next = NULL;
|
2006-01-10 01:32:55 +03:00
|
|
|
}
|
2005-12-12 03:36:54 +03:00
|
|
|
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
static uintptr_t *
|
|
|
|
alloc_bitmap(rb_objspace_t *objspace)
|
|
|
|
{
|
|
|
|
uintptr_t *bits = (uintptr_t *)objspace->heap.free_bitmap;
|
|
|
|
assert(objspace->heap.free_bitmap != NULL);
|
|
|
|
objspace->heap.free_bitmap = objspace->heap.free_bitmap->next;
|
|
|
|
memset(bits, 0, HEAP_BITMAP_LIMIT * sizeof(uintptr_t));
|
|
|
|
return bits;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_bitmap(rb_objspace_t *objspace, uintptr_t *bits)
|
|
|
|
{
|
|
|
|
((struct heaps_free_bitmap *)(bits))->next = objspace->heap.free_bitmap;
|
|
|
|
objspace->heap.free_bitmap = (struct heaps_free_bitmap *)bits;
|
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static void
|
|
|
|
assign_heap_slot(rb_objspace_t *objspace)
|
2008-08-11 13:36:57 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
RVALUE *p, *pend, *membase;
|
|
|
|
struct heaps_slot *slot;
|
|
|
|
size_t hi, lo, mid;
|
|
|
|
size_t objs;
|
2008-08-11 13:36:57 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
objs = HEAP_OBJ_LIMIT;
|
|
|
|
p = (RVALUE*)aligned_malloc(HEAP_ALIGN, HEAP_SIZE);
|
|
|
|
if (p == 0) {
|
|
|
|
during_gc = 0;
|
|
|
|
rb_memerror();
|
2009-01-12 06:41:20 +03:00
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
slot = (struct heaps_slot *)malloc(sizeof(struct heaps_slot));
|
|
|
|
if (slot == 0) {
|
|
|
|
aligned_free(p);
|
|
|
|
during_gc = 0;
|
|
|
|
rb_memerror();
|
2009-01-12 06:41:20 +03:00
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
MEMZERO((void*)slot, struct heaps_slot, 1);
|
2009-01-12 06:41:20 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
slot->next = heaps;
|
|
|
|
if (heaps) heaps->prev = slot;
|
|
|
|
heaps = slot;
|
2009-01-12 06:41:20 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
membase = p;
|
|
|
|
p = (RVALUE*)((VALUE)p + sizeof(struct heaps_header));
|
|
|
|
if ((VALUE)p % sizeof(RVALUE) != 0) {
|
|
|
|
p = (RVALUE*)((VALUE)p + sizeof(RVALUE) - ((VALUE)p % sizeof(RVALUE)));
|
|
|
|
objs = (HEAP_SIZE - (size_t)((VALUE)p - (VALUE)membase))/sizeof(RVALUE);
|
2009-01-12 06:41:20 +03:00
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
|
|
|
|
lo = 0;
|
|
|
|
hi = heaps_used;
|
|
|
|
while (lo < hi) {
|
|
|
|
register RVALUE *mid_membase;
|
|
|
|
mid = (lo + hi) / 2;
|
2012-11-10 19:04:27 +04:00
|
|
|
mid_membase = (RVALUE *)objspace->heap.sorted[mid];
|
2012-08-05 14:39:37 +04:00
|
|
|
if (mid_membase < membase) {
|
|
|
|
lo = mid + 1;
|
|
|
|
}
|
|
|
|
else if (mid_membase > membase) {
|
|
|
|
hi = mid;
|
2009-01-12 06:41:20 +03:00
|
|
|
}
|
|
|
|
else {
|
2012-08-05 14:39:37 +04:00
|
|
|
rb_bug("same heap slot is allocated: %p at %"PRIuVALUE, (void *)membase, (VALUE)mid);
|
2009-01-12 06:41:20 +03:00
|
|
|
}
|
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
if (hi < heaps_used) {
|
2012-11-10 19:04:27 +04:00
|
|
|
MEMMOVE(&objspace->heap.sorted[hi+1], &objspace->heap.sorted[hi], struct heaps_header*, heaps_used - hi);
|
|
|
|
}
|
|
|
|
heaps->header = (struct heaps_header *)membase;
|
|
|
|
objspace->heap.sorted[hi] = heaps->header;
|
|
|
|
objspace->heap.sorted[hi]->start = p;
|
|
|
|
objspace->heap.sorted[hi]->end = (p + objs);
|
|
|
|
objspace->heap.sorted[hi]->base = heaps;
|
|
|
|
objspace->heap.sorted[hi]->limit = objs;
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
objspace->heap.sorted[hi]->mark_bits = alloc_bitmap(objspace);
|
|
|
|
#if USE_RGENGC
|
|
|
|
objspace->heap.sorted[hi]->rememberset_bits = alloc_bitmap(objspace);
|
2013-06-07 06:28:03 +04:00
|
|
|
objspace->heap.sorted[hi]->oldgen_bits = alloc_bitmap(objspace);
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#endif
|
2012-08-05 14:39:37 +04:00
|
|
|
pend = p + objs;
|
|
|
|
if (lomem == 0 || lomem > p) lomem = p;
|
|
|
|
if (himem < pend) himem = pend;
|
|
|
|
heaps_used++;
|
2009-01-12 06:41:20 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
while (p < pend) {
|
|
|
|
p->as.free.flags = 0;
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
rgengc_report(3, objspace, "assign_heap_slot: %p (%s) is added to freelist\n", p, obj_type_name((VALUE)p));
|
2012-08-05 14:39:37 +04:00
|
|
|
p->as.free.next = heaps->freelist;
|
|
|
|
heaps->freelist = p;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
link_free_heap_slot(objspace, heaps);
|
|
|
|
}
|
2009-09-17 13:34:20 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static void
|
|
|
|
add_heap_slots(rb_objspace_t *objspace, size_t add)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
size_t i;
|
|
|
|
size_t next_heaps_length;
|
2000-09-25 21:51:29 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
next_heaps_length = heaps_used + add;
|
2008-06-08 14:27:06 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if (next_heaps_length > heaps_length) {
|
|
|
|
allocate_sorted_heaps(objspace, next_heaps_length);
|
|
|
|
heaps_length = next_heaps_length;
|
2002-10-10 19:26:58 +04:00
|
|
|
}
|
2011-06-15 18:35:46 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
for (i = 0; i < add; i++) {
|
|
|
|
assign_heap_slot(objspace);
|
|
|
|
}
|
|
|
|
heaps_inc = 0;
|
2011-05-22 13:26:46 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static void
|
|
|
|
init_heap(rb_objspace_t *objspace)
|
2011-05-22 13:26:46 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
add_heap_slots(objspace, HEAP_MIN_SLOTS / HEAP_OBJ_LIMIT);
|
2012-10-04 18:48:02 +04:00
|
|
|
init_mark_stack(&objspace->mark_stack);
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
#ifdef USE_SIGALTSTACK
|
|
|
|
{
|
|
|
|
/* altstack of another threads are allocated in another place */
|
|
|
|
rb_thread_t *th = GET_THREAD();
|
|
|
|
void *tmp = th->altstack;
|
2012-12-15 18:20:12 +04:00
|
|
|
th->altstack = malloc(rb_sigaltstack_size());
|
2012-08-05 14:39:37 +04:00
|
|
|
free(tmp); /* free previously allocated area */
|
|
|
|
}
|
2008-06-08 14:27:06 +04:00
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
objspace->profile.invoke_time = getrusage_time();
|
|
|
|
finalizer_table = st_init_numtable();
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static void
|
|
|
|
initial_expand_heap(rb_objspace_t *objspace)
|
2011-05-22 13:26:46 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
size_t min_size = initial_heap_min_slots / HEAP_OBJ_LIMIT;
|
2011-05-22 13:26:46 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if (min_size > heaps_used) {
|
|
|
|
add_heap_slots(objspace, min_size - heaps_used);
|
|
|
|
}
|
2011-05-22 13:26:46 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static void
|
|
|
|
set_heaps_increment(rb_objspace_t *objspace)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2013-03-13 18:52:00 +04:00
|
|
|
size_t next_heaps_length = (size_t)(heaps_used * initial_growth_factor);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if (next_heaps_length == heaps_used) {
|
|
|
|
next_heaps_length++;
|
2009-09-17 13:34:20 +04:00
|
|
|
}
|
2008-06-08 14:27:06 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
heaps_inc = next_heaps_length - heaps_used;
|
2008-07-05 11:15:41 +04:00
|
|
|
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
rgengc_report(5, objspace, "set_heaps_increment: heaps_length: %d, next_heaps_length: %d, heaps_inc: %d\n",
|
|
|
|
heaps_length, next_heaps_length, heaps_inc);
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if (next_heaps_length > heaps_length) {
|
|
|
|
allocate_sorted_heaps(objspace, next_heaps_length);
|
|
|
|
heaps_length = next_heaps_length;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static int
|
|
|
|
heaps_increment(rb_objspace_t *objspace)
|
2008-06-08 14:27:06 +04:00
|
|
|
{
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
rgengc_report(5, objspace, "heaps_increment: heaps_inc: %d\n", heaps_inc);
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if (heaps_inc > 0) {
|
|
|
|
assign_heap_slot(objspace);
|
|
|
|
heaps_inc--;
|
|
|
|
return TRUE;
|
2012-01-11 18:09:10 +04:00
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-06-08 14:27:06 +04:00
|
|
|
|
2013-05-27 04:21:02 +04:00
|
|
|
void
|
|
|
|
rb_objspace_set_event_hook(const rb_event_flag_t event)
|
|
|
|
{
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
objspace->hook_events = event & RUBY_INTERNAL_EVENT_OBJSPACE_MASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gc_event_hook_body(rb_objspace_t *objspace, const rb_event_flag_t event, VALUE data)
|
|
|
|
{
|
|
|
|
rb_thread_t *th = GET_THREAD();
|
|
|
|
EXEC_EVENT_HOOK(th, event, th->cfp->self, 0, 0, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define gc_event_hook(objspace, event, data) do { \
|
|
|
|
if (UNLIKELY((objspace)->hook_events & (event))) { \
|
|
|
|
gc_event_hook_body((objspace), (event), (data)); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
2012-10-20 10:57:51 +04:00
|
|
|
static VALUE
|
2013-05-15 14:26:22 +04:00
|
|
|
newobj_of(VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v3)
|
2008-04-27 07:20:35 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
VALUE obj;
|
2008-04-27 07:20:35 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if (UNLIKELY(during_gc)) {
|
|
|
|
dont_gc = 1;
|
|
|
|
during_gc = 0;
|
|
|
|
rb_bug("object allocation during garbage collection phase");
|
2005-10-05 20:15:16 +04:00
|
|
|
}
|
2008-06-08 14:27:06 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if (UNLIKELY(ruby_gc_stress && !ruby_disable_gc_stress)) {
|
2013-05-22 03:09:22 +04:00
|
|
|
if (!garbage_collect(objspace, FALSE, FALSE, GPR_FLAG_NEWOBJ)) {
|
2012-08-05 14:39:37 +04:00
|
|
|
during_gc = 0;
|
|
|
|
rb_memerror();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (UNLIKELY(!has_free_object)) {
|
2012-10-24 08:29:53 +04:00
|
|
|
if (!gc_prepare_free_objects(objspace)) {
|
2012-08-05 14:39:37 +04:00
|
|
|
during_gc = 0;
|
|
|
|
rb_memerror();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
obj = (VALUE)objspace->heap.free_slots->freelist;
|
|
|
|
objspace->heap.free_slots->freelist = RANY(obj)->as.free.next;
|
|
|
|
if (objspace->heap.free_slots->freelist == NULL) {
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
unlink_free_heap_slot(objspace, objspace->heap.free_slots);
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
|
|
|
|
2013-05-15 14:26:22 +04:00
|
|
|
/* OBJSETUP */
|
|
|
|
RBASIC(obj)->flags = flags;
|
|
|
|
RBASIC_SET_CLASS(obj, klass);
|
* safe.c (rb_set_safe_level, safe_setter): raise an ArgumentError
when $SAFE is set to 4. $SAFE=4 is now obsolete.
[ruby-core:55222] [Feature #8468]
* object.c (rb_obj_untrusted, rb_obj_untrust, rb_obj_trust):
Kernel#untrusted?, untrust, and trust are now deprecated.
Their behavior is same as tainted?, taint, and untaint,
respectively.
* include/ruby/ruby.h (OBJ_UNTRUSTED, OBJ_UNTRUST): OBJ_UNTRUSTED()
and OBJ_UNTRUST() are aliases of OBJ_TAINTED() and OBJ_TAINT(),
respectively.
* array.c, class.c, debug.c, dir.c, encoding.c, error.c, eval.c,
ext/curses/curses.c, ext/dbm/dbm.c, ext/dl/cfunc.c,
ext/dl/cptr.c, ext/dl/dl.c, ext/etc/etc.c, ext/fiddle/fiddle.c,
ext/fiddle/pointer.c, ext/gdbm/gdbm.c, ext/readline/readline.c,
ext/sdbm/init.c, ext/socket/ancdata.c, ext/socket/basicsocket.c,
ext/socket/socket.c, ext/socket/udpsocket.c,
ext/stringio/stringio.c, ext/syslog/syslog.c, ext/tk/tcltklib.c,
ext/win32ole/win32ole.c, file.c, gc.c, hash.c, io.c, iseq.c,
load.c, marshal.c, object.c, proc.c, process.c, random.c, re.c,
safe.c, string.c, thread.c, transcode.c, variable.c,
vm_insnhelper.c, vm_method.c, vm_trace.c: remove code for
$SAFE=4.
* test/dl/test_dl2.rb, test/erb/test_erb.rb,
test/readline/test_readline.rb,
test/readline/test_readline_history.rb, test/ruby/test_alias.rb,
test/ruby/test_array.rb, test/ruby/test_dir.rb,
test/ruby/test_encoding.rb, test/ruby/test_env.rb,
test/ruby/test_eval.rb, test/ruby/test_exception.rb,
test/ruby/test_file_exhaustive.rb, test/ruby/test_hash.rb,
test/ruby/test_io.rb, test/ruby/test_method.rb,
test/ruby/test_module.rb, test/ruby/test_object.rb,
test/ruby/test_pack.rb, test/ruby/test_rand.rb,
test/ruby/test_regexp.rb, test/ruby/test_settracefunc.rb,
test/ruby/test_struct.rb, test/ruby/test_thread.rb,
test/ruby/test_time.rb: remove tests for $SAFE=4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-12 18:20:51 +04:00
|
|
|
if (rb_safe_level() >= 3) FL_SET((obj), FL_TAINT);
|
2013-05-15 14:26:22 +04:00
|
|
|
RANY(obj)->as.values.v1 = v1;
|
|
|
|
RANY(obj)->as.values.v2 = v2;
|
|
|
|
RANY(obj)->as.values.v3 = v3;
|
|
|
|
|
|
|
|
#ifdef GC_DEBUG
|
|
|
|
RANY(obj)->file = rb_sourcefile();
|
|
|
|
RANY(obj)->line = rb_sourceline();
|
|
|
|
#endif
|
|
|
|
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#if RGENGC_PROFILE
|
2013-06-18 06:27:37 +04:00
|
|
|
if (flags & FL_WB_PROTECTED) {
|
|
|
|
objspace->profile.generated_normal_object_count++;
|
|
|
|
#if RGENGC_PROFILE >= 2
|
|
|
|
objspace->profile.generated_normal_object_count_types[BUILTIN_TYPE(obj)]++;
|
|
|
|
#endif
|
|
|
|
}
|
2013-05-15 12:07:30 +04:00
|
|
|
else {
|
|
|
|
objspace->profile.generated_shady_object_count++;
|
|
|
|
#if RGENGC_PROFILE >= 2
|
|
|
|
objspace->profile.generated_shady_object_count_types[BUILTIN_TYPE(obj)]++;
|
|
|
|
#endif
|
|
|
|
}
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
rgengc_report(5, objspace, "newobj: %p (%s)\n", (void *)obj, obj_type_name(obj));
|
|
|
|
|
|
|
|
#if USE_RGENGC && RGENGC_CHECK_MODE
|
|
|
|
if (RVALUE_PROMOTED(obj)) rb_bug("newobj: %p (%s) is promoted.\n", (void *)obj, obj_type_name(obj));
|
|
|
|
if (rgengc_remembered(objspace, (VALUE)obj)) rb_bug("newobj: %p (%s) is remembered.\n", (void *)obj, obj_type_name(obj));
|
|
|
|
#endif
|
|
|
|
|
2013-05-27 04:21:02 +04:00
|
|
|
objspace->total_allocated_object_num++;
|
|
|
|
gc_event_hook(objspace, RUBY_INTERNAL_EVENT_NEWOBJ, obj);
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
return obj;
|
2011-05-22 13:26:46 +04:00
|
|
|
}
|
2008-06-08 14:27:06 +04:00
|
|
|
|
2012-10-20 10:57:51 +04:00
|
|
|
VALUE
|
|
|
|
rb_newobj(void)
|
|
|
|
{
|
2013-05-15 14:26:22 +04:00
|
|
|
return newobj_of(0, T_NONE, 0, 0, 0);
|
2012-10-20 10:57:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_newobj_of(VALUE klass, VALUE flags)
|
|
|
|
{
|
2013-05-15 14:26:22 +04:00
|
|
|
return newobj_of(klass, flags, 0, 0, 0);
|
2012-10-20 10:57:51 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
NODE*
|
|
|
|
rb_node_newnode(enum node_type type, VALUE a0, VALUE a1, VALUE a2)
|
2011-05-22 13:26:46 +04:00
|
|
|
{
|
2013-05-15 22:07:12 +04:00
|
|
|
NODE *n = (NODE *)newobj_of(0, T_NODE, a0, a1, a2);
|
2012-08-05 14:39:37 +04:00
|
|
|
nd_set_type(n, type);
|
|
|
|
return n;
|
2011-05-22 13:26:46 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
VALUE
|
|
|
|
rb_data_object_alloc(VALUE klass, void *datap, RUBY_DATA_FUNC dmark, RUBY_DATA_FUNC dfree)
|
2011-05-22 13:26:46 +04:00
|
|
|
{
|
2013-05-13 10:25:33 +04:00
|
|
|
if (klass) Check_Type(klass, T_CLASS);
|
2013-05-15 14:26:22 +04:00
|
|
|
return newobj_of(klass, T_DATA, (VALUE)dmark, (VALUE)dfree, (VALUE)datap);
|
2008-06-08 14:27:06 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
VALUE
|
|
|
|
rb_data_typed_object_alloc(VALUE klass, void *datap, const rb_data_type_t *type)
|
2008-06-08 14:27:06 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
if (klass) Check_Type(klass, T_CLASS);
|
2013-06-19 10:26:01 +04:00
|
|
|
return newobj_of(klass, T_DATA | type->flags, (VALUE)type, (VALUE)1, (VALUE)datap);
|
2008-04-27 07:20:35 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
size_t
|
|
|
|
rb_objspace_data_type_memsize(VALUE obj)
|
2008-04-27 07:20:35 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
if (RTYPEDDATA_P(obj) && RTYPEDDATA_TYPE(obj)->function.dsize) {
|
|
|
|
return RTYPEDDATA_TYPE(obj)->function.dsize(RTYPEDDATA_DATA(obj));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
2008-06-08 14:27:06 +04:00
|
|
|
}
|
2005-10-05 20:15:16 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
const char *
|
|
|
|
rb_objspace_data_type_name(VALUE obj)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
if (RTYPEDDATA_P(obj)) {
|
|
|
|
return RTYPEDDATA_TYPE(obj)->wrap_struct_name;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static inline int
|
|
|
|
is_pointer_to_heap(rb_objspace_t *objspace, void *ptr)
|
2012-01-10 07:49:10 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
register RVALUE *p = RANY(ptr);
|
2012-11-10 19:04:27 +04:00
|
|
|
register struct heaps_header *heap;
|
2012-08-05 14:39:37 +04:00
|
|
|
register size_t hi, lo, mid;
|
2003-12-22 09:20:14 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if (p < lomem || p > himem) return FALSE;
|
|
|
|
if ((VALUE)p % sizeof(RVALUE) != 0) return FALSE;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
/* check if p looks like a pointer using bsearch*/
|
|
|
|
lo = 0;
|
|
|
|
hi = heaps_used;
|
|
|
|
while (lo < hi) {
|
|
|
|
mid = (lo + hi) / 2;
|
2012-11-10 19:04:27 +04:00
|
|
|
heap = objspace->heap.sorted[mid];
|
2012-08-05 14:39:37 +04:00
|
|
|
if (heap->start <= p) {
|
|
|
|
if (p < heap->end)
|
|
|
|
return TRUE;
|
|
|
|
lo = mid + 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
hi = mid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static int
|
|
|
|
free_method_entry_i(ID key, rb_method_entry_t *me, st_data_t data)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
if (!me->mark) {
|
|
|
|
rb_free_method_entry(me);
|
|
|
|
}
|
|
|
|
return ST_CONTINUE;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
* array.c, bignum.c, cont.c, dir.c, dln.c, encoding.c, enumerator.c,
enumerator.c (enumerator_allocate), eval_jump.c, file.c, hash.c,
io.c, load.c, pack.c, proc.c, random.c, re.c, ruby.c, st.c,
string.c, thread.c, thread_pthread.c, time.c, util.c, variable.c,
vm.c, gc.c:
allocated memory objects by xmalloc (ruby_xmalloc) should be
freed by xfree (ruby_xfree).
* ext/curses/curses.c, ext/dbm/dbm.c, ext/digest/digest.c,
ext/gdbm/gdbm.c, ext/json/ext/parser/parser.c,
ext/json/ext/parser/unicode.c, ext/openssl/ossl_cipher.c,
ext/openssl/ossl_hmac.c, ext/openssl/ossl_pkey_ec.c,
ext/sdbm/init.c, ext/strscan/strscan.c, ext/zlib/zlib.c:
ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17017 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-08 14:01:40 +04:00
|
|
|
void
|
2012-08-05 14:39:37 +04:00
|
|
|
rb_free_m_table(st_table *tbl)
|
* array.c, bignum.c, cont.c, dir.c, dln.c, encoding.c, enumerator.c,
enumerator.c (enumerator_allocate), eval_jump.c, file.c, hash.c,
io.c, load.c, pack.c, proc.c, random.c, re.c, ruby.c, st.c,
string.c, thread.c, thread_pthread.c, time.c, util.c, variable.c,
vm.c, gc.c:
allocated memory objects by xmalloc (ruby_xmalloc) should be
freed by xfree (ruby_xfree).
* ext/curses/curses.c, ext/dbm/dbm.c, ext/digest/digest.c,
ext/gdbm/gdbm.c, ext/json/ext/parser/parser.c,
ext/json/ext/parser/unicode.c, ext/openssl/ossl_cipher.c,
ext/openssl/ossl_hmac.c, ext/openssl/ossl_pkey_ec.c,
ext/sdbm/init.c, ext/strscan/strscan.c, ext/zlib/zlib.c:
ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17017 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-08 14:01:40 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
st_foreach(tbl, free_method_entry_i, 0);
|
|
|
|
st_free_table(tbl);
|
* array.c, bignum.c, cont.c, dir.c, dln.c, encoding.c, enumerator.c,
enumerator.c (enumerator_allocate), eval_jump.c, file.c, hash.c,
io.c, load.c, pack.c, proc.c, random.c, re.c, ruby.c, st.c,
string.c, thread.c, thread_pthread.c, time.c, util.c, variable.c,
vm.c, gc.c:
allocated memory objects by xmalloc (ruby_xmalloc) should be
freed by xfree (ruby_xfree).
* ext/curses/curses.c, ext/dbm/dbm.c, ext/digest/digest.c,
ext/gdbm/gdbm.c, ext/json/ext/parser/parser.c,
ext/json/ext/parser/unicode.c, ext/openssl/ossl_cipher.c,
ext/openssl/ossl_hmac.c, ext/openssl/ossl_pkey_ec.c,
ext/sdbm/init.c, ext/strscan/strscan.c, ext/zlib/zlib.c:
ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17017 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-08 14:01:40 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static int
|
|
|
|
free_const_entry_i(ID key, rb_const_entry_t *ce, st_data_t data)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
xfree(ce);
|
|
|
|
return ST_CONTINUE;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2000-02-08 11:54:01 +03:00
|
|
|
void
|
2012-08-05 14:39:37 +04:00
|
|
|
rb_free_const_table(st_table *tbl)
|
2000-02-08 11:54:01 +03:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
st_foreach(tbl, free_const_entry_i, 0);
|
|
|
|
st_free_table(tbl);
|
|
|
|
}
|
2000-02-08 11:54:01 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static int obj_free(rb_objspace_t *, VALUE);
|
2000-02-08 11:54:01 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static inline struct heaps_slot *
|
|
|
|
add_slot_local_freelist(rb_objspace_t *objspace, RVALUE *p)
|
2012-01-07 18:02:23 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
struct heaps_slot *slot;
|
2012-01-07 18:02:23 +04:00
|
|
|
|
2012-12-01 13:30:24 +04:00
|
|
|
(void)VALGRIND_MAKE_MEM_UNDEFINED((void*)p, sizeof(RVALUE));
|
2012-08-05 14:39:37 +04:00
|
|
|
p->as.free.flags = 0;
|
|
|
|
slot = GET_HEAP_SLOT(p);
|
|
|
|
p->as.free.next = slot->freelist;
|
|
|
|
slot->freelist = p;
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
rgengc_report(3, objspace, "add_slot_local_freelist: %p (%s) is added to freelist\n", p, obj_type_name((VALUE)p));
|
2012-01-07 18:02:23 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
return slot;
|
2012-01-07 18:02:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-08-05 14:39:37 +04:00
|
|
|
unlink_heap_slot(rb_objspace_t *objspace, struct heaps_slot *slot)
|
2012-01-07 18:02:23 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
if (slot->prev)
|
|
|
|
slot->prev->next = slot->next;
|
|
|
|
if (slot->next)
|
|
|
|
slot->next->prev = slot->prev;
|
|
|
|
if (heaps == slot)
|
|
|
|
heaps = slot->next;
|
|
|
|
if (objspace->heap.sweep_slots == slot)
|
|
|
|
objspace->heap.sweep_slots = slot->next;
|
|
|
|
slot->prev = NULL;
|
|
|
|
slot->next = NULL;
|
2008-04-25 13:03:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-08-05 14:39:37 +04:00
|
|
|
free_unused_heaps(rb_objspace_t *objspace)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
size_t i, j;
|
2012-11-10 19:04:27 +04:00
|
|
|
struct heaps_header *last = 0;
|
2008-05-12 06:15:55 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
for (i = j = 1; j < heaps_used; i++) {
|
2012-11-10 19:04:27 +04:00
|
|
|
if (objspace->heap.sorted[i]->limit == 0) {
|
|
|
|
struct heaps_header* h = objspace->heap.sorted[i];
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
free_bitmap(objspace, h->mark_bits);
|
|
|
|
#if USE_RGENGC
|
|
|
|
free_bitmap(objspace, h->rememberset_bits);
|
2013-06-07 06:28:03 +04:00
|
|
|
free_bitmap(objspace, h->oldgen_bits);
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#endif
|
2012-08-05 14:39:37 +04:00
|
|
|
if (!last) {
|
2012-11-10 19:04:27 +04:00
|
|
|
last = objspace->heap.sorted[i];
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
|
|
|
else {
|
2012-11-10 19:04:27 +04:00
|
|
|
aligned_free(objspace->heap.sorted[i]);
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
|
|
|
heaps_used--;
|
2008-03-04 04:21:06 +03:00
|
|
|
}
|
|
|
|
else {
|
2012-08-05 14:39:37 +04:00
|
|
|
if (i != j) {
|
|
|
|
objspace->heap.sorted[j] = objspace->heap.sorted[i];
|
|
|
|
}
|
|
|
|
j++;
|
2008-04-25 13:03:32 +04:00
|
|
|
}
|
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
if (last) {
|
|
|
|
if (last < heaps_freed) {
|
|
|
|
aligned_free(heaps_freed);
|
|
|
|
heaps_freed = last;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aligned_free(last);
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
static inline void
|
|
|
|
make_deferred(RVALUE *p)
|
2008-04-25 13:03:32 +04:00
|
|
|
{
|
2013-06-19 02:26:57 +04:00
|
|
|
p->as.basic.flags = T_ZOMBIE;
|
2011-06-11 14:51:51 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static inline void
|
|
|
|
make_io_deferred(RVALUE *p)
|
2011-06-11 14:51:51 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
rb_io_t *fptr = p->as.file.fptr;
|
|
|
|
make_deferred(p);
|
|
|
|
p->as.data.dfree = (void (*)(void*))rb_io_fptr_finalize;
|
|
|
|
p->as.data.data = fptr;
|
2008-04-25 13:03:32 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static int
|
|
|
|
obj_free(rb_objspace_t *objspace, VALUE obj)
|
2011-06-11 14:51:51 +04:00
|
|
|
{
|
2013-05-27 14:28:25 +04:00
|
|
|
gc_event_hook(objspace, RUBY_INTERNAL_EVENT_FREEOBJ, obj);
|
2013-05-27 04:21:02 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
switch (BUILTIN_TYPE(obj)) {
|
|
|
|
case T_NIL:
|
|
|
|
case T_FIXNUM:
|
|
|
|
case T_TRUE:
|
|
|
|
case T_FALSE:
|
|
|
|
rb_bug("obj_free() called for broken object");
|
|
|
|
break;
|
|
|
|
}
|
2011-06-11 14:51:51 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if (FL_TEST(obj, FL_EXIVAR)) {
|
|
|
|
rb_free_generic_ivar((VALUE)obj);
|
|
|
|
FL_UNSET(obj, FL_EXIVAR);
|
2011-06-11 14:51:51 +04:00
|
|
|
}
|
|
|
|
|
2013-06-07 06:28:03 +04:00
|
|
|
#if USE_RGENGC
|
|
|
|
if (MARKED_IN_BITMAP(GET_HEAP_OLDGEN_BITS(obj),obj))
|
|
|
|
CLEAR_IN_BITMAP(GET_HEAP_OLDGEN_BITS(obj),obj);
|
|
|
|
#endif
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
switch (BUILTIN_TYPE(obj)) {
|
|
|
|
case T_OBJECT:
|
|
|
|
if (!(RANY(obj)->as.basic.flags & ROBJECT_EMBED) &&
|
|
|
|
RANY(obj)->as.object.as.heap.ivptr) {
|
|
|
|
xfree(RANY(obj)->as.object.as.heap.ivptr);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case T_MODULE:
|
|
|
|
case T_CLASS:
|
|
|
|
rb_clear_cache_by_class((VALUE)obj);
|
|
|
|
if (RCLASS_M_TBL(obj)) {
|
|
|
|
rb_free_m_table(RCLASS_M_TBL(obj));
|
|
|
|
}
|
|
|
|
if (RCLASS_IV_TBL(obj)) {
|
|
|
|
st_free_table(RCLASS_IV_TBL(obj));
|
|
|
|
}
|
|
|
|
if (RCLASS_CONST_TBL(obj)) {
|
|
|
|
rb_free_const_table(RCLASS_CONST_TBL(obj));
|
|
|
|
}
|
|
|
|
if (RCLASS_IV_INDEX_TBL(obj)) {
|
|
|
|
st_free_table(RCLASS_IV_INDEX_TBL(obj));
|
|
|
|
}
|
|
|
|
xfree(RANY(obj)->as.klass.ptr);
|
|
|
|
break;
|
|
|
|
case T_STRING:
|
|
|
|
rb_str_free(obj);
|
|
|
|
break;
|
|
|
|
case T_ARRAY:
|
|
|
|
rb_ary_free(obj);
|
|
|
|
break;
|
|
|
|
case T_HASH:
|
|
|
|
if (RANY(obj)->as.hash.ntbl) {
|
|
|
|
st_free_table(RANY(obj)->as.hash.ntbl);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case T_REGEXP:
|
|
|
|
if (RANY(obj)->as.regexp.ptr) {
|
|
|
|
onig_free(RANY(obj)->as.regexp.ptr);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case T_DATA:
|
|
|
|
if (DATA_PTR(obj)) {
|
|
|
|
if (RTYPEDDATA_P(obj)) {
|
|
|
|
RDATA(obj)->dfree = RANY(obj)->as.typeddata.type->function.dfree;
|
|
|
|
}
|
|
|
|
if (RANY(obj)->as.data.dfree == (RUBY_DATA_FUNC)-1) {
|
|
|
|
xfree(DATA_PTR(obj));
|
|
|
|
}
|
|
|
|
else if (RANY(obj)->as.data.dfree) {
|
|
|
|
make_deferred(RANY(obj));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case T_MATCH:
|
|
|
|
if (RANY(obj)->as.match.rmatch) {
|
|
|
|
struct rmatch *rm = RANY(obj)->as.match.rmatch;
|
|
|
|
onig_region_free(&rm->regs, 0);
|
|
|
|
if (rm->char_offset)
|
|
|
|
xfree(rm->char_offset);
|
|
|
|
xfree(rm);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case T_FILE:
|
|
|
|
if (RANY(obj)->as.file.fptr) {
|
|
|
|
make_io_deferred(RANY(obj));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case T_RATIONAL:
|
|
|
|
case T_COMPLEX:
|
|
|
|
break;
|
|
|
|
case T_ICLASS:
|
|
|
|
/* iClass shares table with the module */
|
|
|
|
xfree(RANY(obj)->as.klass.ptr);
|
|
|
|
break;
|
2009-03-23 08:58:15 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
case T_FLOAT:
|
|
|
|
break;
|
2009-03-23 08:58:15 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
case T_BIGNUM:
|
|
|
|
if (!(RBASIC(obj)->flags & RBIGNUM_EMBED_FLAG) && RBIGNUM_DIGITS(obj)) {
|
|
|
|
xfree(RBIGNUM_DIGITS(obj));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case T_NODE:
|
|
|
|
switch (nd_type(obj)) {
|
|
|
|
case NODE_SCOPE:
|
|
|
|
if (RANY(obj)->as.node.u1.tbl) {
|
|
|
|
xfree(RANY(obj)->as.node.u1.tbl);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NODE_ARGS:
|
|
|
|
if (RANY(obj)->as.node.u3.args) {
|
|
|
|
xfree(RANY(obj)->as.node.u3.args);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NODE_ALLOCA:
|
|
|
|
xfree(RANY(obj)->as.node.u1.node);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break; /* no need to free iv_tbl */
|
2008-04-25 13:03:32 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
case T_STRUCT:
|
|
|
|
if ((RBASIC(obj)->flags & RSTRUCT_EMBED_LEN_MASK) == 0 &&
|
|
|
|
RANY(obj)->as.rstruct.as.heap.ptr) {
|
|
|
|
xfree(RANY(obj)->as.rstruct.as.heap.ptr);
|
|
|
|
}
|
|
|
|
break;
|
2008-04-25 13:03:32 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
default:
|
|
|
|
rb_bug("gc_sweep(): unknown data type 0x%x(%p) 0x%"PRIxVALUE,
|
|
|
|
BUILTIN_TYPE(obj), (void*)obj, RBASIC(obj)->flags);
|
2008-04-25 13:03:32 +04:00
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
|
|
|
|
return 0;
|
2008-04-25 13:03:32 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
void
|
|
|
|
Init_heap(void)
|
2010-11-03 04:01:12 +03:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
init_heap(&rb_objspace);
|
2010-11-03 04:01:12 +03:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
typedef int each_obj_callback(void *, void *, size_t, void *);
|
2008-07-05 11:15:41 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
struct each_obj_args {
|
|
|
|
each_obj_callback *callback;
|
|
|
|
void *data;
|
|
|
|
};
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
objspace_each_objects(VALUE arg)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
size_t i;
|
|
|
|
RVALUE *membase = 0;
|
|
|
|
RVALUE *pstart, *pend;
|
2010-11-04 15:06:08 +03:00
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
2012-08-05 14:39:37 +04:00
|
|
|
struct each_obj_args *args = (struct each_obj_args *)arg;
|
|
|
|
volatile VALUE v;
|
2009-02-22 17:23:33 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
i = 0;
|
|
|
|
while (i < heaps_used) {
|
2012-11-10 19:04:27 +04:00
|
|
|
while (0 < i && (uintptr_t)membase < (uintptr_t)objspace->heap.sorted[i-1])
|
2012-08-05 14:39:37 +04:00
|
|
|
i--;
|
2012-11-10 19:04:27 +04:00
|
|
|
while (i < heaps_used && (uintptr_t)objspace->heap.sorted[i] <= (uintptr_t)membase)
|
2012-08-05 14:39:37 +04:00
|
|
|
i++;
|
|
|
|
if (heaps_used <= i)
|
|
|
|
break;
|
2012-11-10 19:04:27 +04:00
|
|
|
membase = (RVALUE *)objspace->heap.sorted[i];
|
2010-11-04 15:06:08 +03:00
|
|
|
|
2012-11-10 19:04:27 +04:00
|
|
|
pstart = objspace->heap.sorted[i]->start;
|
|
|
|
pend = pstart + objspace->heap.sorted[i]->limit;
|
2010-11-04 15:06:08 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
for (; pstart != pend; pstart++) {
|
|
|
|
if (pstart->as.basic.flags) {
|
|
|
|
v = (VALUE)pstart; /* acquire to save this object */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pstart != pend) {
|
|
|
|
if ((*args->callback)(pstart, pend, sizeof(RVALUE), args->data)) {
|
|
|
|
break;
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
RB_GC_GUARD(v);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
return Qnil;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
/*
|
|
|
|
* rb_objspace_each_objects() is special C API to walk through
|
|
|
|
* Ruby object space. This C API is too difficult to use it.
|
|
|
|
* To be frank, you should not use it. Or you need to read the
|
|
|
|
* source code of this function and understand what this function does.
|
|
|
|
*
|
|
|
|
* 'callback' will be called several times (the number of heap slot,
|
|
|
|
* at current implementation) with:
|
|
|
|
* vstart: a pointer to the first living object of the heap_slot.
|
|
|
|
* vend: a pointer to next to the valid heap_slot area.
|
|
|
|
* stride: a distance to next VALUE.
|
|
|
|
*
|
|
|
|
* If callback() returns non-zero, the iteration will be stopped.
|
|
|
|
*
|
|
|
|
* This is a sample callback code to iterate liveness objects:
|
|
|
|
*
|
|
|
|
* int
|
|
|
|
* sample_callback(void *vstart, void *vend, int stride, void *data) {
|
|
|
|
* VALUE v = (VALUE)vstart;
|
|
|
|
* for (; v != (VALUE)vend; v += stride) {
|
|
|
|
* if (RBASIC(v)->flags) { // liveness check
|
|
|
|
* // do something with live object 'v'
|
|
|
|
* }
|
|
|
|
* return 0; // continue to iteration
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* Note: 'vstart' is not a top of heap_slot. This point the first
|
|
|
|
* living object to grasp at least one object to avoid GC issue.
|
|
|
|
* This means that you can not walk through all Ruby object slot
|
|
|
|
* including freed object slot.
|
|
|
|
*
|
|
|
|
* Note: On this implementation, 'stride' is same as sizeof(RVALUE).
|
|
|
|
* However, there are possibilities to pass variable values with
|
|
|
|
* 'stride' with some reasons. You must use stride instead of
|
|
|
|
* use some constant value in the iteration.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
rb_objspace_each_objects(each_obj_callback *callback, void *data)
|
|
|
|
{
|
|
|
|
struct each_obj_args args;
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
2009-06-17 01:36:50 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
rest_sweep(objspace);
|
|
|
|
objspace->flags.dont_lazy_sweep = TRUE;
|
2009-06-17 01:36:50 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
args.callback = callback;
|
|
|
|
args.data = data;
|
|
|
|
rb_ensure(objspace_each_objects, (VALUE)&args, lazy_sweep_enable, Qnil);
|
2009-06-17 01:36:50 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
struct os_each_struct {
|
|
|
|
size_t num;
|
|
|
|
VALUE of;
|
|
|
|
};
|
2009-06-17 01:36:50 +04:00
|
|
|
|
2012-10-05 12:14:09 +04:00
|
|
|
static int
|
|
|
|
internal_object_p(VALUE obj)
|
|
|
|
{
|
|
|
|
RVALUE *p = (RVALUE *)obj;
|
|
|
|
|
|
|
|
if (p->as.basic.flags) {
|
|
|
|
switch (BUILTIN_TYPE(p)) {
|
|
|
|
case T_NONE:
|
|
|
|
case T_ICLASS:
|
|
|
|
case T_NODE:
|
|
|
|
case T_ZOMBIE:
|
|
|
|
break;
|
|
|
|
case T_CLASS:
|
|
|
|
if (FL_TEST(p, FL_SINGLETON))
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (!p->as.basic.klass) break;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-10-24 04:04:56 +04:00
|
|
|
int
|
|
|
|
rb_objspace_internal_object_p(VALUE obj)
|
|
|
|
{
|
|
|
|
return internal_object_p(obj);
|
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static int
|
|
|
|
os_obj_of_i(void *vstart, void *vend, size_t stride, void *data)
|
2009-06-17 01:36:50 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
struct os_each_struct *oes = (struct os_each_struct *)data;
|
|
|
|
RVALUE *p = (RVALUE *)vstart, *pend = (RVALUE *)vend;
|
2009-06-17 01:36:50 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
for (; p != pend; p++) {
|
2012-10-05 12:14:09 +04:00
|
|
|
volatile VALUE v = (VALUE)p;
|
|
|
|
if (!internal_object_p(v)) {
|
|
|
|
if (!oes->of || rb_obj_is_kind_of(v, oes->of)) {
|
|
|
|
rb_yield(v);
|
|
|
|
oes->num++;
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-06-14 12:35:20 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2004-12-13 12:57:41 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static VALUE
|
|
|
|
os_obj_of(VALUE of)
|
2003-06-28 07:29:00 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
struct os_each_struct oes;
|
2003-06-28 07:29:00 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
oes.num = 0;
|
|
|
|
oes.of = of;
|
|
|
|
rb_objspace_each_objects(os_obj_of_i, &oes);
|
|
|
|
return SIZET2NUM(oes.num);
|
2003-06-28 07:29:00 +04:00
|
|
|
}
|
2001-11-19 08:03:03 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ObjectSpace.each_object([module]) {|obj| ... } -> fixnum
|
|
|
|
* ObjectSpace.each_object([module]) -> an_enumerator
|
|
|
|
*
|
|
|
|
* Calls the block once for each living, nonimmediate object in this
|
|
|
|
* Ruby process. If <i>module</i> is specified, calls the block
|
|
|
|
* for only those classes or modules that match (or are a subclass of)
|
|
|
|
* <i>module</i>. Returns the number of objects found. Immediate
|
|
|
|
* objects (<code>Fixnum</code>s, <code>Symbol</code>s
|
|
|
|
* <code>true</code>, <code>false</code>, and <code>nil</code>) are
|
|
|
|
* never returned. In the example below, <code>each_object</code>
|
|
|
|
* returns both the numbers we defined and several constants defined in
|
|
|
|
* the <code>Math</code> module.
|
|
|
|
*
|
|
|
|
* If no block is given, an enumerator is returned instead.
|
|
|
|
*
|
|
|
|
* a = 102.7
|
|
|
|
* b = 95 # Won't be returned
|
|
|
|
* c = 12345678987654321
|
|
|
|
* count = ObjectSpace.each_object(Numeric) {|x| p x }
|
|
|
|
* puts "Total count: #{count}"
|
|
|
|
*
|
|
|
|
* <em>produces:</em>
|
|
|
|
*
|
|
|
|
* 12345678987654321
|
|
|
|
* 102.7
|
|
|
|
* 2.71828182845905
|
|
|
|
* 3.14159265358979
|
|
|
|
* 2.22044604925031e-16
|
|
|
|
* 1.7976931348623157e+308
|
|
|
|
* 2.2250738585072e-308
|
|
|
|
* Total count: 7
|
|
|
|
*
|
|
|
|
*/
|
2003-04-09 10:44:34 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static VALUE
|
|
|
|
os_each_obj(int argc, VALUE *argv, VALUE os)
|
2001-11-19 08:03:03 +03:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
VALUE of;
|
2001-11-19 08:03:03 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if (argc == 0) {
|
|
|
|
of = 0;
|
2007-12-15 07:09:24 +03:00
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
else {
|
|
|
|
rb_scan_args(argc, argv, "01", &of);
|
|
|
|
}
|
|
|
|
RETURN_ENUMERATOR(os, 1, &of);
|
|
|
|
return os_obj_of(of);
|
2008-11-27 17:55:45 +03:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ObjectSpace.undefine_finalizer(obj)
|
|
|
|
*
|
|
|
|
* Removes all finalizers for <i>obj</i>.
|
|
|
|
*
|
|
|
|
*/
|
2011-07-07 18:59:09 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static VALUE
|
|
|
|
undefine_final(VALUE os, VALUE obj)
|
2008-11-27 17:55:45 +03:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
return rb_undefine_final(obj);
|
2001-11-19 08:03:03 +03:00
|
|
|
}
|
2001-11-13 11:19:52 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
VALUE
|
|
|
|
rb_undefine_final(VALUE obj)
|
2001-11-13 11:19:52 +03:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
st_data_t data = obj;
|
|
|
|
rb_check_frozen(obj);
|
|
|
|
st_delete(finalizer_table, &data, 0);
|
|
|
|
FL_UNSET(obj, FL_FINALIZE);
|
|
|
|
return obj;
|
2001-11-13 11:19:52 +03:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ObjectSpace.define_finalizer(obj, aProc=proc())
|
|
|
|
*
|
|
|
|
* Adds <i>aProc</i> as a finalizer, to be called after <i>obj</i>
|
|
|
|
* was destroyed.
|
|
|
|
*
|
|
|
|
*/
|
2003-04-09 10:44:34 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static VALUE
|
|
|
|
define_final(int argc, VALUE *argv, VALUE os)
|
2001-11-13 11:19:52 +03:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
VALUE obj, block;
|
2001-11-27 13:00:35 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
rb_scan_args(argc, argv, "11", &obj, &block);
|
|
|
|
rb_check_frozen(obj);
|
|
|
|
if (argc == 1) {
|
|
|
|
block = rb_block_proc();
|
|
|
|
}
|
|
|
|
else if (!rb_respond_to(block, rb_intern("call"))) {
|
|
|
|
rb_raise(rb_eArgError, "wrong type argument %s (should be callable)",
|
|
|
|
rb_obj_classname(block));
|
2001-11-13 11:19:52 +03:00
|
|
|
}
|
* probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.
* compile.c (rb_insns_name): allowing DTrace probes to access
instruction sequence name.
* Makefile.in: translate probes.d file to appropriate header file.
* common.mk: declare dependencies on the DTrace header.
* configure.in: add a test for existence of DTrace.
* eval.c (setup_exception): add a probe for when an exception is
raised.
* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
end.
* hash.c (empty_hash_alloc): Add a probe for hash allocation.
* insns.def: Add probes for function entry and return.
* internal.h: function declaration for compile.c change.
* load.c (rb_f_load): add probes for `load` entry and exit, require
entry and exit, and wrapping search_required for load path search.
* object.c (rb_obj_alloc): added a probe for general object creation.
* parse.y (yycompile0): added a probe around parse and compile phase.
* string.c (empty_str_alloc, str_new): DTrace probes for string
allocation.
* test/dtrace/*: tests for DTrace probes.
* vm.c (vm_invoke_proc): add probes for function return on exception
raise, hash create, and instruction sequence execution.
* vm_core.h: add probe declarations for function entry and exit.
* vm_dump.c: add probes header file.
* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
function entry and return.
* vm_exec.c: expose instruction number to instruction name function.
* vm_insnshelper.c: add function entry and exit probes for cfunc
methods.
* vm_insnhelper.h: vm usage information is always collected, so
uncomment the functions.
12 19:14:50 2012 Akinori MUSHA <knu@iDaemons.org>
* configure.in (isinf, isnan): isinf() and isnan() are macros on
DragonFly which cannot be found by AC_REPLACE_FUNCS(). This
workaround enforces the fact that they exist on DragonFly.
12 15:59:38 2012 Shugo Maeda <shugo@ruby-lang.org>
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
vm_insnhelper.c (vm_search_method): revert r37616 because it's too
slow. [ruby-dev:46477]
* test/ruby/test_refinement.rb (test_inline_method_cache): skip
the test until the bug is fixed efficiently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-13 01:52:12 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
return define_final0(obj, block);
|
2001-11-13 11:19:52 +03:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static VALUE
|
|
|
|
define_final0(VALUE obj, VALUE block)
|
2003-04-09 12:27:01 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
VALUE table;
|
|
|
|
st_data_t data;
|
2003-04-09 12:27:01 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if (!FL_ABLE(obj)) {
|
|
|
|
rb_raise(rb_eArgError, "cannot define finalizer for %s",
|
|
|
|
rb_obj_classname(obj));
|
2003-04-09 12:27:01 +04:00
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
RBASIC(obj)->flags |= FL_FINALIZE;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
block = rb_ary_new3(2, INT2FIX(rb_safe_level()), block);
|
|
|
|
OBJ_FREEZE(block);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if (st_lookup(finalizer_table, obj, &data)) {
|
|
|
|
table = (VALUE)data;
|
|
|
|
rb_ary_push(table, block);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
else {
|
|
|
|
table = rb_ary_new3(1, block);
|
* include/ruby/ruby.h: constify RBasic::klass and add
RBASIC_CLASS(obj) macro which returns a class of `obj'.
This change is a part of RGENGC branch [ruby-trunk - Feature #8339].
* object.c: add new function rb_obj_reveal().
This function reveal interal (hidden) object by rb_obj_hide().
Note that do not change class before and after hiding.
Only permitted example is:
klass = RBASIC_CLASS(obj);
rb_obj_hide(obj);
....
rb_obj_reveal(obj, klass);
TODO: API design. rb_obj_reveal() should be replaced with others.
TODO: modify constified variables using cast may be harmful for
compiler's analysis and optimizaton.
Any idea to prohibt inserting RBasic::klass directly?
If rename RBasic::klass and force to use RBASIC_CLASS(obj),
then all codes such as `RBASIC(obj)->klass' will be
compilation error. Is it acceptable? (We have similar
experience at Ruby 1.9,
for example "RARRAY(ary)->ptr" to "RARRAY_PTR(ary)".
* internal.h: add some macros.
* RBASIC_CLEAR_CLASS(obj) clear RBasic::klass to make it internal
object.
* RBASIC_SET_CLASS(obj, cls) set RBasic::klass.
* RBASIC_SET_CLASS_RAW(obj, cls) same as RBASIC_SET_CLASS
without write barrier (planned).
* RCLASS_SET_SUPER(a, b) set super class of a.
* array.c, class.c, compile.c, encoding.c, enum.c, error.c, eval.c,
file.c, gc.c, hash.c, io.c, iseq.c, marshal.c, object.c,
parse.y, proc.c, process.c, random.c, ruby.c, sprintf.c,
string.c, thread.c, transcode.c, vm.c, vm_eval.c, win32/file.c:
Use above macros and functions to access RBasic::klass.
* ext/coverage/coverage.c, ext/readline/readline.c,
ext/socket/ancdata.c, ext/socket/init.c,
* ext/zlib/zlib.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40691 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 14:49:11 +04:00
|
|
|
RBASIC_CLEAR_CLASS(table);
|
2012-08-05 14:39:37 +04:00
|
|
|
st_add_direct(finalizer_table, obj, table);
|
|
|
|
}
|
|
|
|
return block;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
VALUE
|
|
|
|
rb_define_final(VALUE obj, VALUE block)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
rb_check_frozen(obj);
|
|
|
|
if (!rb_respond_to(block, rb_intern("call"))) {
|
|
|
|
rb_raise(rb_eArgError, "wrong type argument %s (should be callable)",
|
|
|
|
rb_obj_classname(block));
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
return define_final0(obj, block);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
void
|
|
|
|
rb_gc_copy_finalizer(VALUE dest, VALUE obj)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
VALUE table;
|
|
|
|
st_data_t data;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if (!FL_TEST(obj, FL_FINALIZE)) return;
|
|
|
|
if (st_lookup(finalizer_table, obj, &data)) {
|
|
|
|
table = (VALUE)data;
|
|
|
|
st_insert(finalizer_table, dest, table);
|
|
|
|
}
|
|
|
|
FL_SET(dest, FL_FINALIZE);
|
2008-04-27 07:20:35 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static VALUE
|
|
|
|
run_single_final(VALUE arg)
|
2008-04-27 07:20:35 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
VALUE *args = (VALUE *)arg;
|
|
|
|
rb_eval_cmd(args[0], args[1], (int)args[2]);
|
|
|
|
return Qnil;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static void
|
|
|
|
run_finalizer(rb_objspace_t *objspace, VALUE obj, VALUE table)
|
|
|
|
{
|
|
|
|
long i;
|
|
|
|
int status;
|
|
|
|
VALUE args[3];
|
|
|
|
VALUE objid = nonspecial_obj_id(obj);
|
2008-04-27 07:20:35 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if (RARRAY_LEN(table) > 0) {
|
|
|
|
args[1] = rb_obj_freeze(rb_ary_new3(1, objid));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
args[1] = 0;
|
|
|
|
}
|
2008-04-27 07:20:35 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
args[2] = (VALUE)rb_safe_level();
|
|
|
|
for (i=0; i<RARRAY_LEN(table); i++) {
|
2013-05-13 13:56:22 +04:00
|
|
|
VALUE final = RARRAY_AREF(table, i);
|
|
|
|
args[0] = RARRAY_AREF(final, 1);
|
|
|
|
args[2] = FIX2INT(RARRAY_AREF(final, 0));
|
2012-08-05 14:39:37 +04:00
|
|
|
status = 0;
|
|
|
|
rb_protect(run_single_final, (VALUE)args, &status);
|
|
|
|
if (status)
|
|
|
|
rb_set_errinfo(Qnil);
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2005-10-18 21:35:18 +04:00
|
|
|
static void
|
2012-08-05 14:39:37 +04:00
|
|
|
run_final(rb_objspace_t *objspace, VALUE obj)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
RUBY_DATA_FUNC free_func = 0;
|
|
|
|
st_data_t key, table;
|
|
|
|
|
|
|
|
objspace->heap.final_num--;
|
|
|
|
|
* include/ruby/ruby.h: constify RBasic::klass and add
RBASIC_CLASS(obj) macro which returns a class of `obj'.
This change is a part of RGENGC branch [ruby-trunk - Feature #8339].
* object.c: add new function rb_obj_reveal().
This function reveal interal (hidden) object by rb_obj_hide().
Note that do not change class before and after hiding.
Only permitted example is:
klass = RBASIC_CLASS(obj);
rb_obj_hide(obj);
....
rb_obj_reveal(obj, klass);
TODO: API design. rb_obj_reveal() should be replaced with others.
TODO: modify constified variables using cast may be harmful for
compiler's analysis and optimizaton.
Any idea to prohibt inserting RBasic::klass directly?
If rename RBasic::klass and force to use RBASIC_CLASS(obj),
then all codes such as `RBASIC(obj)->klass' will be
compilation error. Is it acceptable? (We have similar
experience at Ruby 1.9,
for example "RARRAY(ary)->ptr" to "RARRAY_PTR(ary)".
* internal.h: add some macros.
* RBASIC_CLEAR_CLASS(obj) clear RBasic::klass to make it internal
object.
* RBASIC_SET_CLASS(obj, cls) set RBasic::klass.
* RBASIC_SET_CLASS_RAW(obj, cls) same as RBASIC_SET_CLASS
without write barrier (planned).
* RCLASS_SET_SUPER(a, b) set super class of a.
* array.c, class.c, compile.c, encoding.c, enum.c, error.c, eval.c,
file.c, gc.c, hash.c, io.c, iseq.c, marshal.c, object.c,
parse.y, proc.c, process.c, random.c, ruby.c, sprintf.c,
string.c, thread.c, transcode.c, vm.c, vm_eval.c, win32/file.c:
Use above macros and functions to access RBasic::klass.
* ext/coverage/coverage.c, ext/readline/readline.c,
ext/socket/ancdata.c, ext/socket/init.c,
* ext/zlib/zlib.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40691 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 14:49:11 +04:00
|
|
|
RBASIC_CLEAR_CLASS(obj);
|
2012-08-05 14:39:37 +04:00
|
|
|
|
|
|
|
if (RTYPEDDATA_P(obj)) {
|
|
|
|
free_func = RTYPEDDATA_TYPE(obj)->function.dfree;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
free_func = RDATA(obj)->dfree;
|
|
|
|
}
|
|
|
|
if (free_func) {
|
|
|
|
(*free_func)(DATA_PTR(obj));
|
|
|
|
}
|
|
|
|
|
|
|
|
key = (st_data_t)obj;
|
|
|
|
if (st_delete(finalizer_table, &key, &table)) {
|
|
|
|
run_finalizer(objspace, obj, (VALUE)table);
|
|
|
|
}
|
2003-11-28 17:23:33 +03:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static void
|
|
|
|
finalize_list(rb_objspace_t *objspace, RVALUE *p)
|
2007-09-26 23:40:49 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
while (p) {
|
|
|
|
RVALUE *tmp = p->as.free.next;
|
|
|
|
run_final(objspace, (VALUE)p);
|
2013-03-18 19:30:02 +04:00
|
|
|
objspace->total_freed_object_num++;
|
2012-08-05 14:39:37 +04:00
|
|
|
if (!FL_TEST(p, FL_SINGLETON)) { /* not freeing page */
|
|
|
|
add_slot_local_freelist(objspace, p);
|
2013-03-18 19:30:02 +04:00
|
|
|
objspace->heap.free_num++;
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
struct heaps_slot *slot = (struct heaps_slot *)(VALUE)RDATA(p)->dmark;
|
2012-11-10 19:04:27 +04:00
|
|
|
slot->header->limit--;
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
|
|
|
p = tmp;
|
|
|
|
}
|
2007-09-26 23:40:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-08-05 14:39:37 +04:00
|
|
|
finalize_deferred(rb_objspace_t *objspace)
|
2007-09-26 23:40:49 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
RVALUE *p = deferred_final_list;
|
|
|
|
deferred_final_list = 0;
|
|
|
|
|
|
|
|
if (p) {
|
|
|
|
finalize_list(objspace, p);
|
|
|
|
}
|
2007-09-26 23:40:49 +04:00
|
|
|
}
|
|
|
|
|
2013-05-27 01:30:44 +04:00
|
|
|
static void
|
|
|
|
gc_finalize_deferred(void *dmy)
|
2007-09-26 23:40:49 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
if (ATOMIC_EXCHANGE(finalizing, 1)) return;
|
|
|
|
finalize_deferred(objspace);
|
|
|
|
ATOMIC_SET(finalizing, 0);
|
2007-09-26 23:40:49 +04:00
|
|
|
}
|
|
|
|
|
2013-05-27 01:30:44 +04:00
|
|
|
/* TODO: to keep compatibility, maybe unused. */
|
|
|
|
void
|
|
|
|
rb_gc_finalize_deferred(void)
|
|
|
|
{
|
|
|
|
gc_finalize_deferred(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gc_finalize_deferred_register()
|
|
|
|
{
|
|
|
|
rb_postponed_job_register_one(0, gc_finalize_deferred, 0);
|
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
struct force_finalize_list {
|
|
|
|
VALUE obj;
|
|
|
|
VALUE table;
|
|
|
|
struct force_finalize_list *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
force_chain_object(st_data_t key, st_data_t val, st_data_t arg)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
struct force_finalize_list **prev = (struct force_finalize_list **)arg;
|
|
|
|
struct force_finalize_list *curr = ALLOC(struct force_finalize_list);
|
|
|
|
curr->obj = key;
|
|
|
|
curr->table = val;
|
|
|
|
curr->next = *prev;
|
|
|
|
*prev = curr;
|
|
|
|
return ST_CONTINUE;
|
2003-11-28 17:23:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-05 14:39:37 +04:00
|
|
|
rb_gc_call_finalizer_at_exit(void)
|
2003-11-28 17:23:33 +03:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
rb_objspace_call_finalizer(&rb_objspace);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2009-07-15 18:59:41 +04:00
|
|
|
static void
|
2012-08-05 14:39:37 +04:00
|
|
|
rb_objspace_call_finalizer(rb_objspace_t *objspace)
|
2009-07-15 18:59:41 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
RVALUE *p, *pend;
|
|
|
|
RVALUE *final_list = 0;
|
|
|
|
size_t i;
|
2009-08-28 06:45:41 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
rest_sweep(objspace);
|
2009-07-15 18:59:41 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if (ATOMIC_EXCHANGE(finalizing, 1)) return;
|
2009-07-15 18:59:41 +04:00
|
|
|
|
2012-10-05 13:21:41 +04:00
|
|
|
/* run finalizers */
|
2012-11-30 02:56:02 +04:00
|
|
|
finalize_deferred(objspace);
|
|
|
|
assert(deferred_final_list == 0);
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
/* force to run finalizer */
|
|
|
|
while (finalizer_table->num_entries) {
|
|
|
|
struct force_finalize_list *list = 0;
|
|
|
|
st_foreach(finalizer_table, force_chain_object, (st_data_t)&list);
|
|
|
|
while (list) {
|
|
|
|
struct force_finalize_list *curr = list;
|
|
|
|
st_data_t obj = (st_data_t)curr->obj;
|
|
|
|
run_finalizer(objspace, curr->obj, curr->table);
|
|
|
|
st_delete(finalizer_table, &obj, 0);
|
|
|
|
list = curr->next;
|
|
|
|
xfree(curr);
|
|
|
|
}
|
|
|
|
}
|
2009-07-15 18:59:41 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
/* finalizers are part of garbage collection */
|
|
|
|
during_gc++;
|
2009-07-15 18:59:41 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
/* run data object's finalizers */
|
|
|
|
for (i = 0; i < heaps_used; i++) {
|
2012-11-10 19:04:27 +04:00
|
|
|
p = objspace->heap.sorted[i]->start; pend = p + objspace->heap.sorted[i]->limit;
|
2012-08-05 14:39:37 +04:00
|
|
|
while (p < pend) {
|
|
|
|
if (BUILTIN_TYPE(p) == T_DATA &&
|
|
|
|
DATA_PTR(p) && RANY(p)->as.data.dfree &&
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
!rb_obj_is_thread((VALUE)p) &&
|
|
|
|
!rb_obj_is_mutex((VALUE)p) &&
|
2012-08-05 14:39:37 +04:00
|
|
|
!rb_obj_is_fiber((VALUE)p)) {
|
|
|
|
p->as.free.flags = 0;
|
|
|
|
if (RTYPEDDATA_P(p)) {
|
|
|
|
RDATA(p)->dfree = RANY(p)->as.typeddata.type->function.dfree;
|
|
|
|
}
|
|
|
|
if (RANY(p)->as.data.dfree == (RUBY_DATA_FUNC)-1) {
|
|
|
|
xfree(DATA_PTR(p));
|
|
|
|
}
|
|
|
|
else if (RANY(p)->as.data.dfree) {
|
|
|
|
make_deferred(RANY(p));
|
|
|
|
RANY(p)->as.free.next = final_list;
|
|
|
|
final_list = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (BUILTIN_TYPE(p) == T_FILE) {
|
|
|
|
if (RANY(p)->as.file.fptr) {
|
|
|
|
make_io_deferred(RANY(p));
|
|
|
|
RANY(p)->as.free.next = final_list;
|
|
|
|
final_list = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
during_gc = 0;
|
|
|
|
if (final_list) {
|
|
|
|
finalize_list(objspace, final_list);
|
2012-03-18 12:17:39 +04:00
|
|
|
}
|
2009-07-15 18:59:41 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
st_free_table(finalizer_table);
|
|
|
|
finalizer_table = 0;
|
|
|
|
ATOMIC_SET(finalizing, 0);
|
2010-10-26 21:27:32 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static inline int
|
|
|
|
is_id_value(rb_objspace_t *objspace, VALUE ptr)
|
2010-10-26 21:27:32 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
if (!is_pointer_to_heap(objspace, (void *)ptr)) return FALSE;
|
|
|
|
if (BUILTIN_TYPE(ptr) > T_FIXNUM) return FALSE;
|
|
|
|
if (BUILTIN_TYPE(ptr) == T_ICLASS) return FALSE;
|
|
|
|
return TRUE;
|
2010-10-26 21:27:32 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static inline int
|
2012-11-22 19:03:46 +04:00
|
|
|
is_swept_object(rb_objspace_t *objspace, VALUE ptr)
|
2010-10-26 21:27:32 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
struct heaps_slot *slot = objspace->heap.sweep_slots;
|
2012-11-22 19:03:46 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
while (slot) {
|
2012-11-10 19:04:27 +04:00
|
|
|
if ((VALUE)slot->header->start <= ptr && ptr < (VALUE)(slot->header->end))
|
2012-11-22 19:03:46 +04:00
|
|
|
return FALSE;
|
2012-08-05 14:39:37 +04:00
|
|
|
slot = slot->next;
|
|
|
|
}
|
2012-11-22 19:03:46 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
is_dead_object(rb_objspace_t *objspace, VALUE ptr)
|
|
|
|
{
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
if (!is_lazy_sweeping(objspace) || MARKED_IN_BITMAP(GET_HEAP_MARK_BITS(ptr), ptr))
|
2012-11-22 19:03:46 +04:00
|
|
|
return FALSE;
|
|
|
|
if (!is_swept_object(objspace, ptr))
|
|
|
|
return TRUE;
|
2012-08-05 14:39:37 +04:00
|
|
|
return FALSE;
|
2010-10-26 21:27:32 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static inline int
|
|
|
|
is_live_object(rb_objspace_t *objspace, VALUE ptr)
|
2010-10-26 21:27:32 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
if (BUILTIN_TYPE(ptr) == 0) return FALSE;
|
|
|
|
if (RBASIC(ptr)->klass == 0) return FALSE;
|
|
|
|
if (is_dead_object(objspace, ptr)) return FALSE;
|
|
|
|
return TRUE;
|
2010-10-26 21:27:32 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ObjectSpace._id2ref(object_id) -> an_object
|
|
|
|
*
|
|
|
|
* Converts an object id to a reference to the object. May not be
|
|
|
|
* called on an object id passed as a parameter to a finalizer.
|
|
|
|
*
|
|
|
|
* s = "I am a string" #=> "I am a string"
|
|
|
|
* r = ObjectSpace._id2ref(s.object_id) #=> "I am a string"
|
|
|
|
* r == s #=> true
|
|
|
|
*
|
|
|
|
*/
|
2009-07-15 18:59:41 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static VALUE
|
|
|
|
id2ref(VALUE obj, VALUE objid)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
#if SIZEOF_LONG == SIZEOF_VOIDP
|
|
|
|
#define NUM2PTR(x) NUM2ULONG(x)
|
|
|
|
#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
|
|
|
|
#define NUM2PTR(x) NUM2ULL(x)
|
|
|
|
#endif
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
VALUE ptr;
|
|
|
|
void *p0;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
ptr = NUM2PTR(objid);
|
|
|
|
p0 = (void *)ptr;
|
2012-03-13 07:37:06 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if (ptr == Qtrue) return Qtrue;
|
|
|
|
if (ptr == Qfalse) return Qfalse;
|
|
|
|
if (ptr == Qnil) return Qnil;
|
|
|
|
if (FIXNUM_P(ptr)) return (VALUE)ptr;
|
2012-08-23 11:22:40 +04:00
|
|
|
if (FLONUM_P(ptr)) return (VALUE)ptr;
|
2012-12-22 08:25:18 +04:00
|
|
|
ptr = obj_id_to_ref(objid);
|
2001-11-27 13:00:35 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if ((ptr % sizeof(RVALUE)) == (4 << 2)) {
|
|
|
|
ID symid = ptr / sizeof(RVALUE);
|
|
|
|
if (rb_id2name(symid) == 0)
|
|
|
|
rb_raise(rb_eRangeError, "%p is not symbol id value", p0);
|
|
|
|
return ID2SYM(symid);
|
|
|
|
}
|
2003-04-09 12:27:01 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if (!is_id_value(objspace, ptr)) {
|
|
|
|
rb_raise(rb_eRangeError, "%p is not id value", p0);
|
2001-11-13 11:19:52 +03:00
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
if (!is_live_object(objspace, ptr)) {
|
|
|
|
rb_raise(rb_eRangeError, "%p is recycled object", p0);
|
|
|
|
}
|
|
|
|
return (VALUE)ptr;
|
2003-11-28 17:23:33 +03:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
/*
|
|
|
|
* Document-method: __id__
|
|
|
|
* Document-method: object_id
|
|
|
|
*
|
|
|
|
* call-seq:
|
2012-11-29 12:15:53 +04:00
|
|
|
* obj.__id__ -> integer
|
|
|
|
* obj.object_id -> integer
|
2012-08-05 14:39:37 +04:00
|
|
|
*
|
2012-11-29 12:15:53 +04:00
|
|
|
* Returns an integer identifier for +obj+.
|
|
|
|
*
|
|
|
|
* The same number will be returned on all calls to +id+ for a given object,
|
|
|
|
* and no two active objects will share an id.
|
|
|
|
*
|
|
|
|
* Object#object_id is a different concept from the +:name+ notation, which
|
|
|
|
* returns the symbol id of +name+.
|
|
|
|
*
|
|
|
|
* Replaces the deprecated Object#id.
|
2012-08-05 14:39:37 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* obj.hash -> fixnum
|
|
|
|
*
|
2012-11-29 12:15:53 +04:00
|
|
|
* Generates a Fixnum hash value for this object.
|
|
|
|
*
|
|
|
|
* This function must have the property that <code>a.eql?(b)</code> implies
|
|
|
|
* <code>a.hash == b.hash</code>.
|
|
|
|
*
|
|
|
|
* The hash value is used by Hash class.
|
|
|
|
*
|
|
|
|
* Any hash value that exceeds the capacity of a Fixnum will be truncated
|
|
|
|
* before being used.
|
2012-08-05 14:39:37 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_obj_id(VALUE obj)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* 32-bit VALUE space
|
|
|
|
* MSB ------------------------ LSB
|
|
|
|
* false 00000000000000000000000000000000
|
|
|
|
* true 00000000000000000000000000000010
|
|
|
|
* nil 00000000000000000000000000000100
|
|
|
|
* undef 00000000000000000000000000000110
|
|
|
|
* symbol ssssssssssssssssssssssss00001110
|
|
|
|
* object oooooooooooooooooooooooooooooo00 = 0 (mod sizeof(RVALUE))
|
|
|
|
* fixnum fffffffffffffffffffffffffffffff1
|
|
|
|
*
|
|
|
|
* object_id space
|
|
|
|
* LSB
|
|
|
|
* false 00000000000000000000000000000000
|
|
|
|
* true 00000000000000000000000000000010
|
|
|
|
* nil 00000000000000000000000000000100
|
|
|
|
* undef 00000000000000000000000000000110
|
|
|
|
* symbol 000SSSSSSSSSSSSSSSSSSSSSSSSSSS0 S...S % A = 4 (S...S = s...s * A + 4)
|
|
|
|
* object oooooooooooooooooooooooooooooo0 o...o % A = 0
|
|
|
|
* fixnum fffffffffffffffffffffffffffffff1 bignum if required
|
|
|
|
*
|
|
|
|
* where A = sizeof(RVALUE)/4
|
|
|
|
*
|
|
|
|
* sizeof(RVALUE) is
|
|
|
|
* 20 if 32-bit, double is 4-byte aligned
|
|
|
|
* 24 if 32-bit, double is 8-byte aligned
|
|
|
|
* 40 if 64-bit
|
|
|
|
*/
|
|
|
|
if (SYMBOL_P(obj)) {
|
|
|
|
return (SYM2ID(obj) * sizeof(RVALUE) + (4 << 2)) | FIXNUM_FLAG;
|
|
|
|
}
|
2012-08-23 11:22:40 +04:00
|
|
|
else if (FLONUM_P(obj)) {
|
|
|
|
#if SIZEOF_LONG == SIZEOF_VOIDP
|
|
|
|
return LONG2NUM((SIGNED_VALUE)obj);
|
|
|
|
#else
|
|
|
|
return LL2NUM((SIGNED_VALUE)obj);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else if (SPECIAL_CONST_P(obj)) {
|
|
|
|
return LONG2NUM((SIGNED_VALUE)obj);
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
|
|
|
return nonspecial_obj_id(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
set_zero(st_data_t key, st_data_t val, st_data_t arg)
|
|
|
|
{
|
|
|
|
VALUE k = (VALUE)key;
|
|
|
|
VALUE hash = (VALUE)arg;
|
|
|
|
rb_hash_aset(hash, k, INT2FIX(0));
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ObjectSpace.count_objects([result_hash]) -> hash
|
|
|
|
*
|
|
|
|
* Counts objects for each type.
|
|
|
|
*
|
2012-11-29 12:15:53 +04:00
|
|
|
* It returns a hash, such as:
|
|
|
|
* {
|
|
|
|
* :TOTAL=>10000,
|
|
|
|
* :FREE=>3011,
|
|
|
|
* :T_OBJECT=>6,
|
|
|
|
* :T_CLASS=>404,
|
|
|
|
* # ...
|
|
|
|
* }
|
2012-08-05 14:39:37 +04:00
|
|
|
*
|
2012-11-29 12:15:53 +04:00
|
|
|
* The contents of the returned hash are implementation specific.
|
2012-08-05 14:39:37 +04:00
|
|
|
* It may be changed in future.
|
|
|
|
*
|
2012-11-29 12:15:53 +04:00
|
|
|
* If the optional argument +result_hash+ is given,
|
|
|
|
* it is overwritten and returned. This is intended to avoid probe effect.
|
|
|
|
*
|
|
|
|
* This method is only expected to work on C Ruby.
|
2012-08-05 14:39:37 +04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
count_objects(int argc, VALUE *argv, VALUE os)
|
|
|
|
{
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
size_t counts[T_MASK+1];
|
|
|
|
size_t freed = 0;
|
|
|
|
size_t total = 0;
|
|
|
|
size_t i;
|
|
|
|
VALUE hash;
|
|
|
|
|
|
|
|
if (rb_scan_args(argc, argv, "01", &hash) == 1) {
|
|
|
|
if (!RB_TYPE_P(hash, T_HASH))
|
|
|
|
rb_raise(rb_eTypeError, "non-hash given");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i <= T_MASK; i++) {
|
|
|
|
counts[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < heaps_used; i++) {
|
|
|
|
RVALUE *p, *pend;
|
|
|
|
|
2012-11-10 19:04:27 +04:00
|
|
|
p = objspace->heap.sorted[i]->start; pend = p + objspace->heap.sorted[i]->limit;
|
2012-08-05 14:39:37 +04:00
|
|
|
for (;p < pend; p++) {
|
|
|
|
if (p->as.basic.flags) {
|
|
|
|
counts[BUILTIN_TYPE(p)]++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
freed++;
|
|
|
|
}
|
|
|
|
}
|
2012-11-10 19:04:27 +04:00
|
|
|
total += objspace->heap.sorted[i]->limit;
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hash == Qnil) {
|
|
|
|
hash = rb_hash_new();
|
|
|
|
}
|
|
|
|
else if (!RHASH_EMPTY_P(hash)) {
|
2013-05-26 20:19:04 +04:00
|
|
|
st_foreach(RHASH_TBL_RAW(hash), set_zero, hash);
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
|
|
|
rb_hash_aset(hash, ID2SYM(rb_intern("TOTAL")), SIZET2NUM(total));
|
|
|
|
rb_hash_aset(hash, ID2SYM(rb_intern("FREE")), SIZET2NUM(freed));
|
|
|
|
|
|
|
|
for (i = 0; i <= T_MASK; i++) {
|
|
|
|
VALUE type;
|
|
|
|
switch (i) {
|
|
|
|
#define COUNT_TYPE(t) case (t): type = ID2SYM(rb_intern(#t)); break;
|
|
|
|
COUNT_TYPE(T_NONE);
|
|
|
|
COUNT_TYPE(T_OBJECT);
|
|
|
|
COUNT_TYPE(T_CLASS);
|
|
|
|
COUNT_TYPE(T_MODULE);
|
|
|
|
COUNT_TYPE(T_FLOAT);
|
|
|
|
COUNT_TYPE(T_STRING);
|
|
|
|
COUNT_TYPE(T_REGEXP);
|
|
|
|
COUNT_TYPE(T_ARRAY);
|
|
|
|
COUNT_TYPE(T_HASH);
|
|
|
|
COUNT_TYPE(T_STRUCT);
|
|
|
|
COUNT_TYPE(T_BIGNUM);
|
|
|
|
COUNT_TYPE(T_FILE);
|
|
|
|
COUNT_TYPE(T_DATA);
|
|
|
|
COUNT_TYPE(T_MATCH);
|
|
|
|
COUNT_TYPE(T_COMPLEX);
|
|
|
|
COUNT_TYPE(T_RATIONAL);
|
|
|
|
COUNT_TYPE(T_NIL);
|
|
|
|
COUNT_TYPE(T_TRUE);
|
|
|
|
COUNT_TYPE(T_FALSE);
|
|
|
|
COUNT_TYPE(T_SYMBOL);
|
|
|
|
COUNT_TYPE(T_FIXNUM);
|
|
|
|
COUNT_TYPE(T_UNDEF);
|
|
|
|
COUNT_TYPE(T_NODE);
|
|
|
|
COUNT_TYPE(T_ICLASS);
|
|
|
|
COUNT_TYPE(T_ZOMBIE);
|
|
|
|
#undef COUNT_TYPE
|
|
|
|
default: type = INT2NUM(i); break;
|
|
|
|
}
|
|
|
|
if (counts[i])
|
|
|
|
rb_hash_aset(hash, type, SIZET2NUM(counts[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
------------------------ Garbage Collection ------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Sweeping */
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
lazy_sweep_enable(void)
|
|
|
|
{
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
|
|
|
|
objspace->flags.dont_lazy_sweep = FALSE;
|
|
|
|
return Qnil;
|
|
|
|
}
|
2003-04-09 12:27:01 +04:00
|
|
|
|
2013-06-07 06:49:53 +04:00
|
|
|
#if !USE_RGENGC
|
2003-04-09 12:27:01 +04:00
|
|
|
static void
|
2012-08-05 14:39:37 +04:00
|
|
|
gc_clear_slot_bits(struct heaps_slot *slot)
|
2003-04-09 12:27:01 +04:00
|
|
|
{
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
memset(slot->header->mark_bits, 0, HEAP_BITMAP_LIMIT * sizeof(uintptr_t));
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
2013-06-07 06:49:53 +04:00
|
|
|
#else
|
2013-06-07 06:32:57 +04:00
|
|
|
static void
|
|
|
|
gc_setup_mark_bits(struct heaps_slot *slot)
|
2012-11-29 09:05:19 +04:00
|
|
|
{
|
2013-06-07 06:32:57 +04:00
|
|
|
memcpy(slot->header->mark_bits, slot->header->oldgen_bits, HEAP_BITMAP_LIMIT * sizeof(uintptr_t));
|
2012-11-29 09:05:19 +04:00
|
|
|
}
|
2013-06-07 06:32:57 +04:00
|
|
|
#endif
|
2012-11-29 09:05:19 +04:00
|
|
|
|
2013-06-07 06:32:57 +04:00
|
|
|
static size_t
|
|
|
|
objspace_live_num(rb_objspace_t *objspace)
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
{
|
2013-06-07 06:32:57 +04:00
|
|
|
return objspace->total_allocated_object_num - objspace->total_freed_object_num;
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
slot_sweep_body(rb_objspace_t *objspace, struct heaps_slot *sweep_slot, const int during_minor_gc)
|
2012-08-05 14:39:37 +04:00
|
|
|
{
|
2013-06-07 06:32:57 +04:00
|
|
|
int i;
|
2012-11-29 09:05:19 +04:00
|
|
|
size_t empty_num = 0, freed_num = 0, final_num = 0;
|
2013-06-07 06:32:57 +04:00
|
|
|
RVALUE *p, *pend,*offset;
|
2012-08-05 14:39:37 +04:00
|
|
|
RVALUE *final = deferred_final_list;
|
|
|
|
int deferred;
|
2013-06-07 06:32:57 +04:00
|
|
|
uintptr_t *bits, bitset;
|
2013-06-16 00:18:11 +04:00
|
|
|
#if GC_PROFILE_MORE_DETAIL
|
|
|
|
gc_profile_record *record=NULL;
|
|
|
|
#endif
|
2001-11-13 11:19:52 +03:00
|
|
|
|
2013-06-16 00:18:11 +04:00
|
|
|
#if GC_PROFILE_MORE_DETAIL
|
|
|
|
if (objspace->profile.run) {
|
|
|
|
record = gc_prof_record(objspace);
|
|
|
|
}
|
|
|
|
#endif
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
rgengc_report(3, objspace, "slot_sweep_body: start.\n");
|
|
|
|
|
2012-11-10 19:04:27 +04:00
|
|
|
p = sweep_slot->header->start; pend = p + sweep_slot->header->limit;
|
2013-06-07 06:32:57 +04:00
|
|
|
offset = p - NUM_IN_SLOT(p);
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
bits = GET_HEAP_MARK_BITS(p);
|
|
|
|
|
2013-06-07 06:32:57 +04:00
|
|
|
/* create guard : fill 1 out-of-range */
|
|
|
|
bits[BITMAP_INDEX(p)] |= BITMAP_BIT(p)-1;
|
|
|
|
bits[BITMAP_INDEX(pend)] |= ~(BITMAP_BIT(pend) - 1);
|
|
|
|
|
2013-06-07 06:52:42 +04:00
|
|
|
for (i=0; i < HEAP_BITMAP_LIMIT; i++) {
|
2013-06-07 06:32:57 +04:00
|
|
|
bitset = ~bits[i];
|
2013-06-07 06:52:42 +04:00
|
|
|
if (bitset) {
|
2013-06-07 06:32:57 +04:00
|
|
|
p = offset + i * (sizeof(uintptr_t) * CHAR_BIT);
|
|
|
|
do {
|
|
|
|
if ((bitset & 1) && BUILTIN_TYPE(p) != T_ZOMBIE) {
|
|
|
|
if (p->as.basic.flags) {
|
2013-06-16 00:18:11 +04:00
|
|
|
#if GC_PROFILE_MORE_DETAIL
|
2013-06-19 02:26:57 +04:00
|
|
|
if(record) record->removing_objects++;
|
2013-06-16 00:18:11 +04:00
|
|
|
#endif
|
2013-06-07 06:32:57 +04:00
|
|
|
rgengc_report(3, objspace, "slot_sweep_body: free %p (%s)\n", p, obj_type_name((VALUE)p));
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#if USE_RGENGC && RGENGC_CHECK_MODE
|
2013-06-19 18:34:11 +04:00
|
|
|
if (objspace->rgengc.during_minor_gc && RVALUE_PROMOTED((VALUE)p)) rb_bug("slot_sweep_body: %p (%s) is promoted.\n", p, obj_type_name((VALUE)p));
|
2013-06-07 06:32:57 +04:00
|
|
|
if (rgengc_remembered(objspace, (VALUE)p)) rb_bug("slot_sweep_body: %p (%s) is remembered.\n", p, obj_type_name((VALUE)p));
|
|
|
|
#endif
|
2013-06-19 02:26:57 +04:00
|
|
|
if ((deferred = obj_free(objspace, (VALUE)p)) || (FL_TEST(p, FL_FINALIZE))) {
|
2013-06-07 06:32:57 +04:00
|
|
|
if (!deferred) {
|
|
|
|
p->as.free.flags = T_ZOMBIE;
|
|
|
|
RDATA(p)->dfree = 0;
|
|
|
|
}
|
|
|
|
p->as.free.next = deferred_final_list;
|
|
|
|
deferred_final_list = p;
|
|
|
|
assert(BUILTIN_TYPE(p) == T_ZOMBIE);
|
|
|
|
final_num++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
(void)VALGRIND_MAKE_MEM_UNDEFINED((void*)p, sizeof(RVALUE));
|
|
|
|
p->as.free.flags = 0;
|
|
|
|
p->as.free.next = sweep_slot->freelist;
|
|
|
|
sweep_slot->freelist = p;
|
|
|
|
rgengc_report(3, objspace, "slot_sweep_body: %p (%s) is added to freelist\n", p, obj_type_name((VALUE)p));
|
|
|
|
freed_num++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2013-06-16 00:18:11 +04:00
|
|
|
#if GC_PROFILE_MORE_DETAIL
|
|
|
|
if(record)
|
|
|
|
record->empty_objects++;
|
|
|
|
#endif
|
2013-06-07 06:32:57 +04:00
|
|
|
empty_num++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
bitset >>= 1;
|
|
|
|
} while (bitset);
|
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
2013-06-07 06:32:57 +04:00
|
|
|
#if USE_RGENGC
|
|
|
|
gc_setup_mark_bits(sweep_slot);
|
|
|
|
#else
|
2012-08-05 14:39:37 +04:00
|
|
|
gc_clear_slot_bits(sweep_slot);
|
2013-06-07 06:32:57 +04:00
|
|
|
#endif
|
|
|
|
|
2012-11-29 09:05:19 +04:00
|
|
|
if (final_num + freed_num + empty_num == sweep_slot->header->limit &&
|
2012-08-05 14:39:37 +04:00
|
|
|
objspace->heap.free_num > objspace->heap.do_heap_free) {
|
|
|
|
RVALUE *pp;
|
2003-02-21 03:28:04 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
for (pp = deferred_final_list; pp != final; pp = pp->as.free.next) {
|
|
|
|
RDATA(pp)->dmark = (void (*)(void *))(VALUE)sweep_slot;
|
|
|
|
pp->as.free.flags |= FL_SINGLETON; /* freeing page mark */
|
|
|
|
}
|
2012-11-10 19:04:27 +04:00
|
|
|
sweep_slot->header->limit = final_num;
|
2012-08-05 14:39:37 +04:00
|
|
|
unlink_heap_slot(objspace, sweep_slot);
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
else {
|
2012-11-29 09:05:19 +04:00
|
|
|
if (freed_num + empty_num > 0) {
|
2012-08-05 14:39:37 +04:00
|
|
|
link_free_heap_slot(objspace, sweep_slot);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sweep_slot->free_next = NULL;
|
|
|
|
}
|
2012-11-29 09:05:19 +04:00
|
|
|
objspace->heap.free_num += freed_num + empty_num;
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
2013-03-18 19:30:02 +04:00
|
|
|
objspace->total_freed_object_num += freed_num;
|
2012-08-05 14:39:37 +04:00
|
|
|
objspace->heap.final_num += final_num;
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if (deferred_final_list && !finalizing) {
|
|
|
|
rb_thread_t *th = GET_THREAD();
|
|
|
|
if (th) {
|
2013-05-27 01:30:44 +04:00
|
|
|
gc_finalize_deferred_register();
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
|
|
|
}
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
|
|
|
|
rgengc_report(3, objspace, "slot_sweep_body: end.\n");
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#if USE_RGENGC
|
|
|
|
static void
|
|
|
|
slot_sweep_minor(rb_objspace_t *objspace, struct heaps_slot *sweep_slot)
|
|
|
|
{
|
|
|
|
slot_sweep_body(objspace, sweep_slot, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
slot_sweep_major(rb_objspace_t *objspace, struct heaps_slot *sweep_slot)
|
|
|
|
{
|
|
|
|
slot_sweep_body(objspace, sweep_slot, FALSE);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-05-13 20:34:25 +04:00
|
|
|
static void
|
|
|
|
slot_sweep(rb_objspace_t *objspace, struct heaps_slot *sweep_slot)
|
|
|
|
{
|
2013-05-22 03:09:22 +04:00
|
|
|
rgengc_report(1, objspace, "slot_sweep: start\n");
|
2013-05-13 20:34:25 +04:00
|
|
|
gc_prof_sweep_slot_timer_start(objspace);
|
2013-05-21 11:52:03 +04:00
|
|
|
{
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#if USE_RGENGC
|
2013-05-21 11:52:03 +04:00
|
|
|
if (objspace->rgengc.during_minor_gc) {
|
|
|
|
slot_sweep_minor(objspace, sweep_slot);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
slot_sweep_major(objspace, sweep_slot);
|
|
|
|
}
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#else
|
2013-05-21 11:52:03 +04:00
|
|
|
slot_sweep_body(objspace, sweep_slot, FALSE);
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#endif
|
2013-05-21 11:52:03 +04:00
|
|
|
}
|
2013-05-13 20:34:25 +04:00
|
|
|
gc_prof_sweep_slot_timer_stop(objspace);
|
2013-05-22 03:09:22 +04:00
|
|
|
rgengc_report(1, objspace, "slot_sweep: end\n");
|
2013-05-13 20:34:25 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static int
|
|
|
|
ready_to_gc(rb_objspace_t *objspace)
|
|
|
|
{
|
|
|
|
if (dont_gc || during_gc) {
|
|
|
|
if (!has_free_object) {
|
|
|
|
if (!heaps_increment(objspace)) {
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
set_heaps_increment(objspace);
|
2012-08-05 14:39:37 +04:00
|
|
|
heaps_increment(objspace);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2013-06-05 10:27:43 +04:00
|
|
|
#if defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ == 4
|
2013-06-07 08:25:20 +04:00
|
|
|
__attribute__((noinline))
|
2013-06-05 10:27:43 +04:00
|
|
|
#endif
|
2012-08-05 14:39:37 +04:00
|
|
|
static void
|
|
|
|
before_gc_sweep(rb_objspace_t *objspace)
|
|
|
|
{
|
2013-05-22 03:09:22 +04:00
|
|
|
rgengc_report(1, objspace, "before_gc_sweep\n");
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
objspace->heap.do_heap_free = (size_t)((heaps_used * HEAP_OBJ_LIMIT) * 0.65);
|
|
|
|
objspace->heap.free_min = (size_t)((heaps_used * HEAP_OBJ_LIMIT) * 0.2);
|
|
|
|
if (objspace->heap.free_min < initial_free_min) {
|
|
|
|
objspace->heap.free_min = initial_free_min;
|
2013-03-18 13:03:07 +04:00
|
|
|
if (objspace->heap.do_heap_free < initial_free_min)
|
|
|
|
objspace->heap.do_heap_free = initial_free_min;
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
|
|
|
objspace->heap.sweep_slots = heaps;
|
|
|
|
objspace->heap.free_num = 0;
|
|
|
|
objspace->heap.free_slots = NULL;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2013-06-16 00:53:01 +04:00
|
|
|
malloc_increase2 += ATOMIC_SIZE_EXCHANGE(malloc_increase,0);
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
/* sweep unlinked method entries */
|
|
|
|
if (GET_VM()->unlinked_method_entry_list) {
|
|
|
|
rb_sweep_method_entry(GET_VM());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
after_gc_sweep(rb_objspace_t *objspace)
|
|
|
|
{
|
|
|
|
size_t inc;
|
|
|
|
|
2013-05-22 03:09:22 +04:00
|
|
|
rgengc_report(1, objspace, "after_gc_sweep\n");
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
gc_prof_set_malloc_info(objspace);
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
rgengc_report(5, objspace, "after_gc_sweep: objspace->heap.free_num: %d, objspace->heap.free_min: %d\n",
|
|
|
|
objspace->heap.free_num, objspace->heap.free_min);
|
2013-05-22 03:09:22 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if (objspace->heap.free_num < objspace->heap.free_min) {
|
2013-05-25 12:11:04 +04:00
|
|
|
set_heaps_increment(objspace);
|
|
|
|
heaps_increment(objspace);
|
|
|
|
|
|
|
|
if (objspace->rgengc.remembered_shady_object_count + objspace->rgengc.oldgen_object_count > (heaps_length * HEAP_OBJ_LIMIT) / 2) {
|
2013-05-24 14:21:04 +04:00
|
|
|
/* if [oldgen]+[remembered shady] > [all object count]/2, then do major GC */
|
2013-05-24 10:52:38 +04:00
|
|
|
objspace->rgengc.need_major_gc = TRUE;
|
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inc = ATOMIC_SIZE_EXCHANGE(malloc_increase, 0);
|
2013-06-16 00:53:01 +04:00
|
|
|
inc += malloc_increase2;
|
|
|
|
malloc_increase2 = 0;
|
2013-05-22 03:09:22 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if (inc > malloc_limit) {
|
2012-11-29 09:05:19 +04:00
|
|
|
malloc_limit +=
|
2013-05-13 21:02:50 +04:00
|
|
|
(size_t)((inc - malloc_limit) * (double)objspace_live_num(objspace) / (heaps_used * HEAP_OBJ_LIMIT));
|
2012-08-05 14:39:37 +04:00
|
|
|
if (malloc_limit < initial_malloc_limit) malloc_limit = initial_malloc_limit;
|
|
|
|
}
|
|
|
|
|
|
|
|
free_unused_heaps(objspace);
|
2013-05-27 19:40:27 +04:00
|
|
|
|
|
|
|
gc_event_hook(objspace, RUBY_INTERNAL_EVENT_GC_END, 0 /* TODO: pass minor/immediate flag? */);
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
lazy_sweep(rb_objspace_t *objspace)
|
|
|
|
{
|
|
|
|
struct heaps_slot *next;
|
|
|
|
|
|
|
|
heaps_increment(objspace);
|
|
|
|
while (objspace->heap.sweep_slots) {
|
|
|
|
next = objspace->heap.sweep_slots->next;
|
|
|
|
slot_sweep(objspace, objspace->heap.sweep_slots);
|
|
|
|
objspace->heap.sweep_slots = next;
|
2013-05-13 21:02:50 +04:00
|
|
|
|
|
|
|
if (!next) after_gc_sweep(objspace);
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if (has_free_object) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rest_sweep(rb_objspace_t *objspace)
|
|
|
|
{
|
|
|
|
if (objspace->heap.sweep_slots) {
|
2013-05-22 09:21:06 +04:00
|
|
|
during_gc++;
|
2012-08-05 14:39:37 +04:00
|
|
|
while (objspace->heap.sweep_slots) {
|
|
|
|
lazy_sweep(objspace);
|
|
|
|
}
|
2013-05-22 09:21:06 +04:00
|
|
|
during_gc = 0;
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
static void
|
2013-05-22 03:09:22 +04:00
|
|
|
gc_sweep(rb_objspace_t *objspace, int immediate_sweep)
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
{
|
2013-05-22 03:09:22 +04:00
|
|
|
if (immediate_sweep) {
|
|
|
|
struct heaps_slot *next;
|
|
|
|
before_gc_sweep(objspace);
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
|
2013-05-22 03:09:22 +04:00
|
|
|
while (objspace->heap.sweep_slots) {
|
|
|
|
next = objspace->heap.sweep_slots->next;
|
|
|
|
slot_sweep(objspace, objspace->heap.sweep_slots);
|
|
|
|
objspace->heap.sweep_slots = next;
|
|
|
|
}
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
|
2013-05-22 03:09:22 +04:00
|
|
|
after_gc_sweep(objspace);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
before_gc_sweep(objspace);
|
|
|
|
lazy_sweep(objspace);
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
}
|
|
|
|
|
2013-05-22 03:09:22 +04:00
|
|
|
if (!has_free_object) {
|
2013-05-24 10:52:38 +04:00
|
|
|
/* there is no free after slot_sweep() */
|
2013-05-22 03:09:22 +04:00
|
|
|
set_heaps_increment(objspace);
|
2013-05-24 10:52:38 +04:00
|
|
|
if (!heaps_increment(objspace)) { /* can't allocate additional free objects */
|
2013-05-22 03:09:22 +04:00
|
|
|
during_gc = 0;
|
|
|
|
rb_memerror();
|
|
|
|
}
|
|
|
|
}
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
|
|
|
|
static int
|
2012-10-24 08:29:53 +04:00
|
|
|
gc_prepare_free_objects(rb_objspace_t *objspace)
|
2012-08-05 14:39:37 +04:00
|
|
|
{
|
2013-03-24 08:53:44 +04:00
|
|
|
if (!GC_ENABLE_LAZY_SWEEP || objspace->flags.dont_lazy_sweep) {
|
2013-03-24 08:20:32 +04:00
|
|
|
if (heaps_increment(objspace)) {
|
2013-03-24 09:13:54 +04:00
|
|
|
return TRUE;
|
2013-03-24 08:20:32 +04:00
|
|
|
}
|
|
|
|
else {
|
2013-05-22 03:09:22 +04:00
|
|
|
return garbage_collect(objspace, FALSE, TRUE, GPR_FLAG_NEWOBJ);
|
2013-03-24 08:20:32 +04:00
|
|
|
}
|
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
|
|
|
|
if (!ready_to_gc(objspace)) return TRUE;
|
|
|
|
|
|
|
|
during_gc++;
|
|
|
|
|
|
|
|
if (objspace->heap.sweep_slots) {
|
2013-05-22 03:09:22 +04:00
|
|
|
if (lazy_sweep(objspace)) {
|
2013-05-22 09:21:06 +04:00
|
|
|
during_gc = 0;
|
2013-05-22 03:09:22 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (heaps_increment(objspace)) {
|
2013-05-22 03:09:22 +04:00
|
|
|
during_gc = 0;
|
2012-08-05 14:39:37 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2013-06-16 00:18:11 +04:00
|
|
|
#if GC_PROFILE_MORE_DETAIL
|
|
|
|
objspace->profile.prepare_time = 0;
|
|
|
|
#endif
|
2013-05-22 03:09:22 +04:00
|
|
|
return garbage_collect_body(objspace, 0, 0, GPR_FLAG_NEWOBJ);
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
2012-08-02 15:34:19 +04:00
|
|
|
|
2012-10-03 16:30:21 +04:00
|
|
|
/* Marking stack */
|
|
|
|
|
|
|
|
static void push_mark_stack(mark_stack_t *, VALUE);
|
|
|
|
static int pop_mark_stack(mark_stack_t *, VALUE *);
|
|
|
|
static void shrink_stack_chunk_cache(mark_stack_t *stack);
|
|
|
|
|
|
|
|
static stack_chunk_t *
|
|
|
|
stack_chunk_alloc(void)
|
|
|
|
{
|
|
|
|
stack_chunk_t *res;
|
|
|
|
|
|
|
|
res = malloc(sizeof(stack_chunk_t));
|
|
|
|
if (!res)
|
|
|
|
rb_memerror();
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
is_mark_stask_empty(mark_stack_t *stack)
|
|
|
|
{
|
|
|
|
return stack->chunk == NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_stack_chunk_cache(mark_stack_t *stack, stack_chunk_t *chunk)
|
|
|
|
{
|
|
|
|
chunk->next = stack->cache;
|
|
|
|
stack->cache = chunk;
|
|
|
|
stack->cache_size++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shrink_stack_chunk_cache(mark_stack_t *stack)
|
|
|
|
{
|
|
|
|
stack_chunk_t *chunk;
|
|
|
|
|
|
|
|
if (stack->unused_cache_size > (stack->cache_size/2)) {
|
|
|
|
chunk = stack->cache;
|
|
|
|
stack->cache = stack->cache->next;
|
|
|
|
stack->cache_size--;
|
|
|
|
free(chunk);
|
|
|
|
}
|
|
|
|
stack->unused_cache_size = stack->cache_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
push_mark_stack_chunk(mark_stack_t *stack)
|
|
|
|
{
|
|
|
|
stack_chunk_t *next;
|
|
|
|
|
|
|
|
assert(stack->index == stack->limit);
|
|
|
|
if (stack->cache_size > 0) {
|
|
|
|
next = stack->cache;
|
|
|
|
stack->cache = stack->cache->next;
|
|
|
|
stack->cache_size--;
|
|
|
|
if (stack->unused_cache_size > stack->cache_size)
|
|
|
|
stack->unused_cache_size = stack->cache_size;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
next = stack_chunk_alloc();
|
|
|
|
}
|
|
|
|
next->next = stack->chunk;
|
|
|
|
stack->chunk = next;
|
|
|
|
stack->index = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pop_mark_stack_chunk(mark_stack_t *stack)
|
|
|
|
{
|
|
|
|
stack_chunk_t *prev;
|
|
|
|
|
|
|
|
prev = stack->chunk->next;
|
|
|
|
assert(stack->index == 0);
|
|
|
|
add_stack_chunk_cache(stack, stack->chunk);
|
|
|
|
stack->chunk = prev;
|
|
|
|
stack->index = stack->limit;
|
|
|
|
}
|
|
|
|
|
2012-10-03 17:23:30 +04:00
|
|
|
#if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
|
2012-10-03 16:30:21 +04:00
|
|
|
static void
|
|
|
|
free_stack_chunks(mark_stack_t *stack)
|
|
|
|
{
|
|
|
|
stack_chunk_t *chunk = stack->chunk;
|
|
|
|
stack_chunk_t *next = NULL;
|
|
|
|
|
|
|
|
while (chunk != NULL) {
|
|
|
|
next = chunk->next;
|
|
|
|
free(chunk);
|
|
|
|
chunk = next;
|
|
|
|
}
|
|
|
|
}
|
2012-10-03 17:23:30 +04:00
|
|
|
#endif
|
2012-10-03 16:30:21 +04:00
|
|
|
|
|
|
|
static void
|
|
|
|
push_mark_stack(mark_stack_t *stack, VALUE data)
|
|
|
|
{
|
|
|
|
if (stack->index == stack->limit) {
|
|
|
|
push_mark_stack_chunk(stack);
|
|
|
|
}
|
|
|
|
stack->chunk->data[stack->index++] = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pop_mark_stack(mark_stack_t *stack, VALUE *data)
|
|
|
|
{
|
|
|
|
if (is_mark_stask_empty(stack)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (stack->index == 1) {
|
|
|
|
*data = stack->chunk->data[--stack->index];
|
|
|
|
pop_mark_stack_chunk(stack);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
*data = stack->chunk->data[--stack->index];
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_mark_stack(mark_stack_t *stack)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
push_mark_stack_chunk(stack);
|
|
|
|
stack->limit = STACK_CHUNK_SIZE;
|
|
|
|
|
2012-12-29 16:22:04 +04:00
|
|
|
for (i=0; i < 4; i++) {
|
2012-10-03 16:30:21 +04:00
|
|
|
add_stack_chunk_cache(stack, stack_chunk_alloc());
|
|
|
|
}
|
|
|
|
stack->unused_cache_size = stack->cache_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
#ifdef __ia64
|
|
|
|
#define SET_STACK_END (SET_MACHINE_STACK_END(&th->machine_stack_end), th->machine_register_stack_end = rb_ia64_bsp())
|
|
|
|
#else
|
|
|
|
#define SET_STACK_END SET_MACHINE_STACK_END(&th->machine_stack_end)
|
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
#define STACK_START (th->machine_stack_start)
|
|
|
|
#define STACK_END (th->machine_stack_end)
|
|
|
|
#define STACK_LEVEL_MAX (th->machine_stack_maxsize/sizeof(VALUE))
|
2007-11-20 06:16:53 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
#if STACK_GROW_DIRECTION < 0
|
|
|
|
# define STACK_LENGTH (size_t)(STACK_START - STACK_END)
|
|
|
|
#elif STACK_GROW_DIRECTION > 0
|
|
|
|
# define STACK_LENGTH (size_t)(STACK_END - STACK_START + 1)
|
|
|
|
#else
|
|
|
|
# define STACK_LENGTH ((STACK_END < STACK_START) ? (size_t)(STACK_START - STACK_END) \
|
|
|
|
: (size_t)(STACK_END - STACK_START + 1))
|
|
|
|
#endif
|
|
|
|
#if !STACK_GROW_DIRECTION
|
|
|
|
int ruby_stack_grow_direction;
|
|
|
|
int
|
|
|
|
ruby_get_stack_grow_direction(volatile VALUE *addr)
|
|
|
|
{
|
|
|
|
VALUE *end;
|
|
|
|
SET_MACHINE_STACK_END(&end);
|
2008-06-28 16:25:45 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if (end > addr) return ruby_stack_grow_direction = 1;
|
|
|
|
return ruby_stack_grow_direction = -1;
|
|
|
|
}
|
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
size_t
|
|
|
|
ruby_stack_length(VALUE **p)
|
|
|
|
{
|
|
|
|
rb_thread_t *th = GET_THREAD();
|
|
|
|
SET_STACK_END;
|
|
|
|
if (p) *p = STACK_UPPER(STACK_END, STACK_START, STACK_END);
|
|
|
|
return STACK_LENGTH;
|
|
|
|
}
|
2008-03-16 03:23:43 +03:00
|
|
|
|
2012-10-03 16:30:21 +04:00
|
|
|
#if !(defined(POSIX_SIGNAL) && defined(SIGSEGV) && defined(HAVE_SIGALTSTACK))
|
2012-08-05 14:39:37 +04:00
|
|
|
static int
|
|
|
|
stack_check(int water_mark)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
rb_thread_t *th = GET_THREAD();
|
|
|
|
SET_STACK_END;
|
|
|
|
ret = STACK_LENGTH > STACK_LEVEL_MAX - water_mark;
|
|
|
|
#ifdef __ia64
|
|
|
|
if (!ret) {
|
|
|
|
ret = (VALUE*)rb_ia64_bsp() - th->machine_register_stack_start >
|
|
|
|
th->machine_register_stack_maxsize/sizeof(VALUE) - water_mark;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
2012-10-03 16:30:21 +04:00
|
|
|
#endif
|
2008-03-16 03:23:43 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
#define STACKFRAME_FOR_CALL_CFUNC 512
|
|
|
|
|
|
|
|
int
|
|
|
|
ruby_stack_check(void)
|
|
|
|
{
|
|
|
|
#if defined(POSIX_SIGNAL) && defined(SIGSEGV) && defined(HAVE_SIGALTSTACK)
|
|
|
|
return 0;
|
|
|
|
#else
|
|
|
|
return stack_check(STACKFRAME_FOR_CALL_CFUNC);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mark_locations_array(rb_objspace_t *objspace, register VALUE *x, register long n)
|
|
|
|
{
|
|
|
|
VALUE v;
|
|
|
|
while (n--) {
|
|
|
|
v = *x;
|
2013-06-17 06:54:25 +04:00
|
|
|
gc_mark_maybe(objspace, v);
|
2012-08-05 14:39:37 +04:00
|
|
|
x++;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static void
|
|
|
|
gc_mark_locations(rb_objspace_t *objspace, VALUE *start, VALUE *end)
|
|
|
|
{
|
|
|
|
long n;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if (end <= start) return;
|
|
|
|
n = end - start;
|
|
|
|
mark_locations_array(objspace, start, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_gc_mark_locations(VALUE *start, VALUE *end)
|
2008-07-27 09:59:32 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
gc_mark_locations(&rb_objspace, start, end);
|
|
|
|
}
|
2012-01-07 18:02:23 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
#define rb_gc_mark_locations(start, end) gc_mark_locations(objspace, (start), (end))
|
2012-01-07 18:02:23 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
struct mark_tbl_arg {
|
|
|
|
rb_objspace_t *objspace;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
mark_entry(st_data_t key, st_data_t value, st_data_t data)
|
|
|
|
{
|
|
|
|
struct mark_tbl_arg *arg = (void*)data;
|
2012-10-03 16:30:21 +04:00
|
|
|
gc_mark(arg->objspace, (VALUE)value);
|
2012-08-05 14:39:37 +04:00
|
|
|
return ST_CONTINUE;
|
2008-07-27 09:59:32 +04:00
|
|
|
}
|
|
|
|
|
2004-09-27 16:25:21 +04:00
|
|
|
static void
|
2012-10-03 16:30:21 +04:00
|
|
|
mark_tbl(rb_objspace_t *objspace, st_table *tbl)
|
2004-09-27 16:25:21 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
struct mark_tbl_arg arg;
|
|
|
|
if (!tbl || tbl->num_entries == 0) return;
|
|
|
|
arg.objspace = objspace;
|
|
|
|
st_foreach(tbl, mark_entry, (st_data_t)&arg);
|
2004-09-27 16:25:21 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static int
|
|
|
|
mark_key(st_data_t key, st_data_t value, st_data_t data)
|
2010-06-29 07:11:05 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
struct mark_tbl_arg *arg = (void*)data;
|
2012-10-03 16:30:21 +04:00
|
|
|
gc_mark(arg->objspace, (VALUE)key);
|
2012-08-05 14:39:37 +04:00
|
|
|
return ST_CONTINUE;
|
2010-06-29 07:11:05 +04:00
|
|
|
}
|
|
|
|
|
2008-07-05 11:15:41 +04:00
|
|
|
static void
|
2012-10-03 16:30:21 +04:00
|
|
|
mark_set(rb_objspace_t *objspace, st_table *tbl)
|
2004-09-27 16:25:21 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
struct mark_tbl_arg arg;
|
|
|
|
if (!tbl) return;
|
|
|
|
arg.objspace = objspace;
|
|
|
|
st_foreach(tbl, mark_key, (st_data_t)&arg);
|
|
|
|
}
|
2008-07-02 04:49:10 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
void
|
|
|
|
rb_mark_set(st_table *tbl)
|
|
|
|
{
|
2012-10-03 16:30:21 +04:00
|
|
|
mark_set(&rb_objspace, tbl);
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mark_keyvalue(st_data_t key, st_data_t value, st_data_t data)
|
|
|
|
{
|
|
|
|
struct mark_tbl_arg *arg = (void*)data;
|
2012-10-03 16:30:21 +04:00
|
|
|
gc_mark(arg->objspace, (VALUE)key);
|
|
|
|
gc_mark(arg->objspace, (VALUE)value);
|
2012-08-05 14:39:37 +04:00
|
|
|
return ST_CONTINUE;
|
2008-07-02 04:49:10 +04:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-01-07 18:02:23 +04:00
|
|
|
static void
|
2012-10-03 16:30:21 +04:00
|
|
|
mark_hash(rb_objspace_t *objspace, st_table *tbl)
|
2012-01-07 18:02:23 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
struct mark_tbl_arg arg;
|
|
|
|
if (!tbl) return;
|
|
|
|
arg.objspace = objspace;
|
|
|
|
st_foreach(tbl, mark_keyvalue, (st_data_t)&arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_mark_hash(st_table *tbl)
|
|
|
|
{
|
2012-10-03 16:30:21 +04:00
|
|
|
mark_hash(&rb_objspace, tbl);
|
2012-01-07 18:02:23 +04:00
|
|
|
}
|
|
|
|
|
2008-07-02 04:49:10 +04:00
|
|
|
static void
|
2012-10-03 16:30:21 +04:00
|
|
|
mark_method_entry(rb_objspace_t *objspace, const rb_method_entry_t *me)
|
2008-07-02 04:49:10 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
const rb_method_definition_t *def = me->def;
|
2008-07-27 09:59:32 +04:00
|
|
|
|
2012-10-03 16:30:21 +04:00
|
|
|
gc_mark(objspace, me->klass);
|
* revised r37993 to avoid SEGV/ILL in tests. In r37993, a method
entry with VM_METHOD_TYPE_REFINED holds only the original method
definition, so ci->me is set to a method entry allocated in the
stack, and it causes SEGV/ILL. In this commit, a method entry
with VM_METHOD_TYPE_REFINED holds the whole original method entry.
Furthermore, rb_thread_mark() is changed to mark cfp->klass to
avoid GC for iclasses created by copy_refinement_iclass().
* vm_method.c (rb_method_entry_make): add a method entry with
VM_METHOD_TYPE_REFINED to the class refined by the refinement if
the target module is a refinement. When a method entry with
VM_METHOD_TYPE_UNDEF is invoked by vm_call_method(), a method with
the same name is searched in refinements. If such a method is
found, the method is invoked. Otherwise, the original method in
the refined class (rb_method_definition_t::body.orig_me) is
invoked. This change is made to simplify the normal method lookup
and to improve the performance of normal method calls.
* vm_method.c (EXPR1, search_method, rb_method_entry),
vm_eval.c (rb_call0, rb_search_method_entry): do not use
refinements for method lookup.
* vm_insnhelper.c (vm_call_method): search methods in refinements if
ci->me is VM_METHOD_TYPE_REFINED. If the method is called by
super (i.e., ci->call == vm_call_super_method), skip the same
method entry as the current method to avoid infinite call of the
same method.
* class.c (include_modules_at): add a refined method entry for each
method defined in a module included in a refinement.
* class.c (rb_prepend_module): set an empty table to
RCLASS_M_TBL(klass) to add refined method entries, because
refinements should have priority over prepended modules.
* proc.c (mnew): use rb_method_entry_with_refinements() to get
a refined method.
* vm.c (rb_thread_mark): mark cfp->klass for iclasses created by
copy_refinement_iclass().
* vm.c (Init_VM), cont.c (fiber_init): initialize th->cfp->klass.
* test/ruby/test_refinement.rb (test_inline_method_cache): do not skip
the test because it should pass successfully.
* test/ruby/test_refinement.rb (test_redefine_refined_method): new
test for the case a refined method is redefined.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38236 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-06 17:08:41 +04:00
|
|
|
again:
|
2012-08-05 14:39:37 +04:00
|
|
|
if (!def) return;
|
|
|
|
switch (def->type) {
|
|
|
|
case VM_METHOD_TYPE_ISEQ:
|
2012-10-03 16:30:21 +04:00
|
|
|
gc_mark(objspace, def->body.iseq->self);
|
2012-08-05 14:39:37 +04:00
|
|
|
break;
|
|
|
|
case VM_METHOD_TYPE_BMETHOD:
|
2012-10-03 16:30:21 +04:00
|
|
|
gc_mark(objspace, def->body.proc);
|
2012-08-05 14:39:37 +04:00
|
|
|
break;
|
|
|
|
case VM_METHOD_TYPE_ATTRSET:
|
|
|
|
case VM_METHOD_TYPE_IVAR:
|
2012-10-03 16:30:21 +04:00
|
|
|
gc_mark(objspace, def->body.attr.location);
|
2012-08-05 14:39:37 +04:00
|
|
|
break;
|
* revised r37993 to avoid SEGV/ILL in tests. In r37993, a method
entry with VM_METHOD_TYPE_REFINED holds only the original method
definition, so ci->me is set to a method entry allocated in the
stack, and it causes SEGV/ILL. In this commit, a method entry
with VM_METHOD_TYPE_REFINED holds the whole original method entry.
Furthermore, rb_thread_mark() is changed to mark cfp->klass to
avoid GC for iclasses created by copy_refinement_iclass().
* vm_method.c (rb_method_entry_make): add a method entry with
VM_METHOD_TYPE_REFINED to the class refined by the refinement if
the target module is a refinement. When a method entry with
VM_METHOD_TYPE_UNDEF is invoked by vm_call_method(), a method with
the same name is searched in refinements. If such a method is
found, the method is invoked. Otherwise, the original method in
the refined class (rb_method_definition_t::body.orig_me) is
invoked. This change is made to simplify the normal method lookup
and to improve the performance of normal method calls.
* vm_method.c (EXPR1, search_method, rb_method_entry),
vm_eval.c (rb_call0, rb_search_method_entry): do not use
refinements for method lookup.
* vm_insnhelper.c (vm_call_method): search methods in refinements if
ci->me is VM_METHOD_TYPE_REFINED. If the method is called by
super (i.e., ci->call == vm_call_super_method), skip the same
method entry as the current method to avoid infinite call of the
same method.
* class.c (include_modules_at): add a refined method entry for each
method defined in a module included in a refinement.
* class.c (rb_prepend_module): set an empty table to
RCLASS_M_TBL(klass) to add refined method entries, because
refinements should have priority over prepended modules.
* proc.c (mnew): use rb_method_entry_with_refinements() to get
a refined method.
* vm.c (rb_thread_mark): mark cfp->klass for iclasses created by
copy_refinement_iclass().
* vm.c (Init_VM), cont.c (fiber_init): initialize th->cfp->klass.
* test/ruby/test_refinement.rb (test_inline_method_cache): do not skip
the test because it should pass successfully.
* test/ruby/test_refinement.rb (test_redefine_refined_method): new
test for the case a refined method is redefined.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38236 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-06 17:08:41 +04:00
|
|
|
case VM_METHOD_TYPE_REFINED:
|
|
|
|
if (def->body.orig_me) {
|
|
|
|
def = def->body.orig_me->def;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
break;
|
2012-08-05 14:39:37 +04:00
|
|
|
default:
|
|
|
|
break; /* ignore */
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
2008-07-02 04:49:10 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
void
|
|
|
|
rb_mark_method_entry(const rb_method_entry_t *me)
|
|
|
|
{
|
2012-10-03 16:30:21 +04:00
|
|
|
mark_method_entry(&rb_objspace, me);
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
2010-11-04 14:15:36 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static int
|
|
|
|
mark_method_entry_i(ID key, const rb_method_entry_t *me, st_data_t data)
|
|
|
|
{
|
|
|
|
struct mark_tbl_arg *arg = (void*)data;
|
2012-10-03 16:30:21 +04:00
|
|
|
mark_method_entry(arg->objspace, me);
|
2012-08-05 14:39:37 +04:00
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-10-03 16:30:21 +04:00
|
|
|
mark_m_tbl(rb_objspace_t *objspace, st_table *tbl)
|
2012-08-05 14:39:37 +04:00
|
|
|
{
|
|
|
|
struct mark_tbl_arg arg;
|
|
|
|
if (!tbl) return;
|
|
|
|
arg.objspace = objspace;
|
|
|
|
st_foreach(tbl, mark_method_entry_i, (st_data_t)&arg);
|
2010-05-28 15:13:42 +04:00
|
|
|
}
|
2008-07-05 11:15:41 +04:00
|
|
|
|
2010-05-28 15:13:42 +04:00
|
|
|
static int
|
2012-08-05 14:39:37 +04:00
|
|
|
mark_const_entry_i(ID key, const rb_const_entry_t *ce, st_data_t data)
|
2010-05-28 15:13:42 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
struct mark_tbl_arg *arg = (void*)data;
|
2012-10-03 16:30:21 +04:00
|
|
|
gc_mark(arg->objspace, ce->value);
|
|
|
|
gc_mark(arg->objspace, ce->file);
|
2012-08-05 14:39:37 +04:00
|
|
|
return ST_CONTINUE;
|
2010-05-28 15:13:42 +04:00
|
|
|
}
|
2008-07-27 17:08:02 +04:00
|
|
|
|
2010-05-28 15:13:42 +04:00
|
|
|
static void
|
2012-10-03 16:30:21 +04:00
|
|
|
mark_const_tbl(rb_objspace_t *objspace, st_table *tbl)
|
2010-05-28 15:13:42 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
struct mark_tbl_arg arg;
|
|
|
|
if (!tbl) return;
|
|
|
|
arg.objspace = objspace;
|
|
|
|
st_foreach(tbl, mark_const_entry_i, (st_data_t)&arg);
|
2010-05-28 15:13:42 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
#if STACK_GROW_DIRECTION < 0
|
|
|
|
#define GET_STACK_BOUNDS(start, end, appendix) ((start) = STACK_END, (end) = STACK_START)
|
|
|
|
#elif STACK_GROW_DIRECTION > 0
|
|
|
|
#define GET_STACK_BOUNDS(start, end, appendix) ((start) = STACK_START, (end) = STACK_END+(appendix))
|
|
|
|
#else
|
|
|
|
#define GET_STACK_BOUNDS(start, end, appendix) \
|
|
|
|
((STACK_END < STACK_START) ? \
|
|
|
|
((start) = STACK_END, (end) = STACK_START) : ((start) = STACK_START, (end) = STACK_END+(appendix)))
|
|
|
|
#endif
|
|
|
|
|
2010-05-28 15:13:42 +04:00
|
|
|
static void
|
2012-08-05 14:39:37 +04:00
|
|
|
mark_current_machine_context(rb_objspace_t *objspace, rb_thread_t *th)
|
2010-05-28 15:13:42 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
union {
|
|
|
|
rb_jmp_buf j;
|
|
|
|
VALUE v[sizeof(rb_jmp_buf) / sizeof(VALUE)];
|
|
|
|
} save_regs_gc_mark;
|
|
|
|
VALUE *stack_start, *stack_end;
|
2010-05-28 15:13:42 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
FLUSH_REGISTER_WINDOWS;
|
|
|
|
/* This assumes that all registers are saved into the jmp_buf (and stack) */
|
|
|
|
rb_setjmp(save_regs_gc_mark.j);
|
2010-06-06 08:12:20 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
GET_STACK_BOUNDS(stack_start, stack_end, 1);
|
2008-07-02 04:49:10 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
mark_locations_array(objspace, save_regs_gc_mark.v, numberof(save_regs_gc_mark.v));
|
|
|
|
|
|
|
|
rb_gc_mark_locations(stack_start, stack_end);
|
|
|
|
#ifdef __ia64
|
|
|
|
rb_gc_mark_locations(th->machine_register_stack_start, th->machine_register_stack_end);
|
|
|
|
#endif
|
|
|
|
#if defined(__mc68000__)
|
|
|
|
mark_locations_array(objspace, (VALUE*)((char*)STACK_END + 2),
|
|
|
|
(STACK_START - STACK_END));
|
|
|
|
#endif
|
2010-05-28 15:13:42 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
void
|
|
|
|
rb_gc_mark_machine_stack(rb_thread_t *th)
|
2010-05-28 15:13:42 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
VALUE *stack_start, *stack_end;
|
2010-06-29 07:11:05 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
GET_STACK_BOUNDS(stack_start, stack_end, 0);
|
|
|
|
rb_gc_mark_locations(stack_start, stack_end);
|
|
|
|
#ifdef __ia64
|
|
|
|
rb_gc_mark_locations(th->machine_register_stack_start, th->machine_register_stack_end);
|
|
|
|
#endif
|
2010-05-28 15:13:42 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
void
|
|
|
|
rb_mark_tbl(st_table *tbl)
|
2010-10-21 08:18:09 +04:00
|
|
|
{
|
2012-10-03 16:30:21 +04:00
|
|
|
mark_tbl(&rb_objspace, tbl);
|
2010-10-21 08:18:09 +04:00
|
|
|
}
|
|
|
|
|
2013-06-17 06:54:25 +04:00
|
|
|
static void
|
|
|
|
gc_mark_maybe(rb_objspace_t *objspace, VALUE obj)
|
|
|
|
{
|
|
|
|
(void)VALGRIND_MAKE_MEM_DEFINED(&obj, sizeof(obj));
|
2013-06-18 06:17:59 +04:00
|
|
|
if (is_pointer_to_heap(objspace, (void *)obj)) {
|
|
|
|
int type = BUILTIN_TYPE(obj);
|
|
|
|
if (type != T_ZOMBIE && type != T_NONE) {
|
|
|
|
gc_mark(objspace, obj);
|
|
|
|
}
|
2013-06-17 06:54:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
void
|
|
|
|
rb_gc_mark_maybe(VALUE obj)
|
|
|
|
{
|
2013-06-17 06:54:25 +04:00
|
|
|
gc_mark_maybe(&rb_objspace, obj);
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
2010-05-28 15:13:42 +04:00
|
|
|
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
static int
|
|
|
|
gc_marked(rb_objspace_t *objspace, VALUE ptr)
|
|
|
|
{
|
|
|
|
register uintptr_t *bits = GET_HEAP_MARK_BITS(ptr);
|
|
|
|
if (MARKED_IN_BITMAP(bits, ptr)) return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-05-28 15:13:42 +04:00
|
|
|
static int
|
2012-08-05 14:39:37 +04:00
|
|
|
gc_mark_ptr(rb_objspace_t *objspace, VALUE ptr)
|
2010-05-28 15:13:42 +04:00
|
|
|
{
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
register uintptr_t *bits = GET_HEAP_MARK_BITS(ptr);
|
|
|
|
if (gc_marked(objspace, ptr)) return 0;
|
2012-08-05 14:39:37 +04:00
|
|
|
MARK_IN_BITMAP(bits, ptr);
|
|
|
|
return 1;
|
|
|
|
}
|
2010-05-28 15:13:42 +04:00
|
|
|
|
2012-10-05 12:14:09 +04:00
|
|
|
static int
|
2013-06-17 06:54:25 +04:00
|
|
|
markable_object_p(rb_objspace_t *objspace, VALUE obj)
|
2012-10-05 12:14:09 +04:00
|
|
|
{
|
2013-06-18 06:17:59 +04:00
|
|
|
if (rb_special_const_p(obj)) return 0; /* special const is not markable */
|
|
|
|
|
|
|
|
if (RGENGC_CHECK_MODE) {
|
|
|
|
if (!is_pointer_to_heap(objspace, (void *)obj)) rb_bug("markable_object_p: %p is not pointer to heap", (void *)obj);
|
|
|
|
if (BUILTIN_TYPE(obj) == T_NONE) rb_bug("markable_object_p: %p is T_NONE", (void *)obj);
|
|
|
|
if (BUILTIN_TYPE(obj) == T_ZOMBIE) rb_bug("markable_object_p: %p is T_ZOMBIE", (void *)obj);
|
|
|
|
}
|
|
|
|
|
2012-10-05 12:14:09 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-10-24 04:04:56 +04:00
|
|
|
int
|
|
|
|
rb_objspace_markable_object_p(VALUE obj)
|
|
|
|
{
|
2013-06-18 06:17:59 +04:00
|
|
|
return markable_object_p(&rb_objspace, obj);
|
2012-10-24 04:04:56 +04:00
|
|
|
}
|
|
|
|
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
static const char *
|
2013-05-15 12:07:30 +04:00
|
|
|
type_name(int type, VALUE obj)
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
{
|
2013-05-15 12:07:30 +04:00
|
|
|
switch (type) {
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#define TYPE_NAME(t) case (t): return #t;
|
|
|
|
TYPE_NAME(T_NONE);
|
|
|
|
TYPE_NAME(T_OBJECT);
|
|
|
|
TYPE_NAME(T_CLASS);
|
|
|
|
TYPE_NAME(T_MODULE);
|
|
|
|
TYPE_NAME(T_FLOAT);
|
|
|
|
TYPE_NAME(T_STRING);
|
|
|
|
TYPE_NAME(T_REGEXP);
|
|
|
|
TYPE_NAME(T_ARRAY);
|
|
|
|
TYPE_NAME(T_HASH);
|
|
|
|
TYPE_NAME(T_STRUCT);
|
|
|
|
TYPE_NAME(T_BIGNUM);
|
|
|
|
TYPE_NAME(T_FILE);
|
|
|
|
TYPE_NAME(T_MATCH);
|
|
|
|
TYPE_NAME(T_COMPLEX);
|
|
|
|
TYPE_NAME(T_RATIONAL);
|
|
|
|
TYPE_NAME(T_NIL);
|
|
|
|
TYPE_NAME(T_TRUE);
|
|
|
|
TYPE_NAME(T_FALSE);
|
|
|
|
TYPE_NAME(T_SYMBOL);
|
|
|
|
TYPE_NAME(T_FIXNUM);
|
|
|
|
TYPE_NAME(T_UNDEF);
|
|
|
|
TYPE_NAME(T_NODE);
|
|
|
|
TYPE_NAME(T_ICLASS);
|
|
|
|
TYPE_NAME(T_ZOMBIE);
|
|
|
|
case T_DATA:
|
2013-05-15 12:07:30 +04:00
|
|
|
if (obj && rb_objspace_data_type_name(obj)) {
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
return rb_objspace_data_type_name(obj);
|
|
|
|
}
|
|
|
|
return "T_DATA";
|
|
|
|
#undef TYPE_NAME
|
|
|
|
}
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
|
2013-05-15 12:07:30 +04:00
|
|
|
static const char *
|
|
|
|
obj_type_name(VALUE obj)
|
|
|
|
{
|
|
|
|
return type_name(TYPE(obj), obj);
|
|
|
|
}
|
|
|
|
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
static void
|
|
|
|
rgengc_check_shady(rb_objspace_t *objspace, VALUE obj)
|
|
|
|
{
|
|
|
|
#if USE_RGENGC
|
|
|
|
if (RGENGC_CHECK_MODE > 1) {
|
|
|
|
if (objspace->rgengc.interesting_object == obj) {
|
|
|
|
if (FIXNUM_P(objspace->rgengc.parent_object)) {
|
2013-06-19 02:04:30 +04:00
|
|
|
fprintf(stderr, "rgengc_check_shady: !!! %p (%s) is pointed at line %d\n",
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
(void *)obj, obj_type_name(obj), FIX2INT(objspace->rgengc.parent_object));
|
|
|
|
}
|
|
|
|
else {
|
2013-06-19 02:04:30 +04:00
|
|
|
fprintf(stderr, "rgengc_check_shady: !!! %p (%s) is pointed by %p (%s)\n",
|
|
|
|
(void *)obj, obj_type_name(obj),
|
|
|
|
(void *)objspace->rgengc.parent_object, obj_type_name(objspace->rgengc.parent_object));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RGENGC_CHECK_MODE == 3) {
|
|
|
|
if (objspace->rgengc.interesting_object) {
|
|
|
|
if (FIXNUM_P(objspace->rgengc.parent_object)) {
|
|
|
|
fprintf(stderr, "rgengc_check_shady: [line %d] -> %p (%s)\n",
|
|
|
|
FIX2INT(objspace->rgengc.parent_object), (void *)obj, obj_type_name(obj));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "rgengc_check_shady: %p (%s) -> %p (%s)\n",
|
|
|
|
(void *)objspace->rgengc.parent_object, obj_type_name(objspace->rgengc.parent_object),
|
|
|
|
(void *)obj, obj_type_name(obj));
|
|
|
|
}
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (objspace->rgengc.parent_object_is_promoted &&
|
|
|
|
RVALUE_SHADY(obj) && !rgengc_remembered(objspace, obj)) {
|
|
|
|
rgengc_remember(objspace, obj);
|
2013-05-24 14:21:04 +04:00
|
|
|
if (objspace->rgengc.during_minor_gc == FALSE) { /* major/full GC */
|
|
|
|
objspace->rgengc.remembered_shady_object_count++;
|
|
|
|
}
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static void
|
2012-10-03 16:30:21 +04:00
|
|
|
gc_mark(rb_objspace_t *objspace, VALUE ptr)
|
2012-08-05 14:39:37 +04:00
|
|
|
{
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
if (!markable_object_p(objspace, ptr)) return;
|
2010-05-28 15:13:42 +04:00
|
|
|
|
2012-10-05 12:14:09 +04:00
|
|
|
if (LIKELY(objspace->mark_func_data == 0)) {
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
rgengc_check_shady(objspace, ptr);
|
2012-10-05 12:14:09 +04:00
|
|
|
if (!gc_mark_ptr(objspace, ptr)) return; /* already marked */
|
|
|
|
push_mark_stack(&objspace->mark_stack, ptr);
|
|
|
|
}
|
|
|
|
else {
|
2012-10-24 04:04:56 +04:00
|
|
|
objspace->mark_func_data->mark_func(ptr, objspace->mark_func_data->data);
|
2012-10-05 12:14:09 +04:00
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
2010-05-28 15:13:42 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
void
|
|
|
|
rb_gc_mark(VALUE ptr)
|
|
|
|
{
|
2012-10-03 16:30:21 +04:00
|
|
|
gc_mark(&rb_objspace, ptr);
|
2010-05-28 15:13:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-10-03 16:30:21 +04:00
|
|
|
gc_mark_children(rb_objspace_t *objspace, VALUE ptr)
|
2010-05-28 15:13:42 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
register RVALUE *obj = RANY(ptr);
|
2010-06-29 07:11:05 +04:00
|
|
|
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
if (RGENGC_CHECK_MODE > 1) objspace->rgengc.parent_object = (VALUE)ptr;
|
|
|
|
|
2012-10-04 11:23:41 +04:00
|
|
|
goto marking; /* skip */
|
2010-05-28 15:13:42 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
again:
|
2012-10-05 12:14:09 +04:00
|
|
|
if (LIKELY(objspace->mark_func_data == 0)) {
|
|
|
|
obj = RANY(ptr);
|
2012-10-06 04:50:12 +04:00
|
|
|
if (!markable_object_p(objspace, ptr)) return;
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
rgengc_check_shady(objspace, ptr);
|
2012-10-05 12:14:09 +04:00
|
|
|
if (!gc_mark_ptr(objspace, ptr)) return; /* already marked */
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
if (RGENGC_CHECK_MODE > 1) objspace->rgengc.parent_object = (VALUE)ptr;
|
2012-10-05 12:14:09 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
gc_mark(objspace, ptr);
|
|
|
|
return;
|
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#if USE_RGENGC
|
2013-06-19 18:34:11 +04:00
|
|
|
if (RGENGC_CHECK_MODE && RVALUE_SHADY(obj) && RVALUE_PROMOTED((VALUE)obj)) {
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
rb_bug("gc_mark_children: (0) %p (%s) is shady and promoted.\n", (void *)obj, obj_type_name((VALUE)obj));
|
|
|
|
}
|
|
|
|
#endif /* USE_RGENGC */
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
marking:
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
|
|
|
|
#if USE_RGENGC
|
2013-05-22 03:09:22 +04:00
|
|
|
if (LIKELY(objspace->mark_func_data == 0)) {
|
2013-06-19 18:34:11 +04:00
|
|
|
if (RGENGC_CHECK_MODE && RVALUE_SHADY(obj) && RVALUE_PROMOTED((VALUE)obj)) {
|
2013-05-22 03:09:22 +04:00
|
|
|
rb_bug("gc_mark_children: (1) %p (%s) is shady and promoted.\n", (void *)obj, obj_type_name((VALUE)obj));
|
|
|
|
}
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
|
2013-05-22 03:09:22 +04:00
|
|
|
/* minor/major common */
|
2013-06-07 05:17:19 +04:00
|
|
|
if (!RVALUE_SHADY(obj)) {
|
2013-06-07 06:28:03 +04:00
|
|
|
if (!RVALUE_PROMOTED((VALUE)obj)) {
|
|
|
|
RVALUE_PROMOTE((VALUE)obj); /* non-shady object can be promoted to OLDGEN object */
|
|
|
|
rgengc_report(3, objspace, "gc_mark_children: promote %p (%s).\n", (void *)obj, obj_type_name((VALUE)obj));
|
|
|
|
}
|
2013-05-22 03:09:22 +04:00
|
|
|
objspace->rgengc.parent_object_is_promoted = TRUE;
|
2013-05-24 14:21:04 +04:00
|
|
|
objspace->rgengc.oldgen_object_count++;
|
2013-05-22 03:09:22 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
rgengc_report(3, objspace, "gc_mark_children: do not promote shady %p (%s).\n", (void *)obj, obj_type_name((VALUE)obj));
|
|
|
|
objspace->rgengc.parent_object_is_promoted = FALSE;
|
|
|
|
}
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
|
2013-06-19 18:34:11 +04:00
|
|
|
if (RGENGC_CHECK_MODE && RVALUE_SHADY(obj) && RVALUE_PROMOTED((VALUE)obj)) {
|
2013-05-22 03:09:22 +04:00
|
|
|
rb_bug("gc_mark_children: (2) %p (%s) is shady and promoted.\n", (void *)obj, obj_type_name((VALUE)obj));
|
|
|
|
}
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
}
|
|
|
|
#endif /* USE_RGENGC */
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if (FL_TEST(obj, FL_EXIVAR)) {
|
|
|
|
rb_mark_generic_ivar(ptr);
|
2010-05-28 15:13:42 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
switch (BUILTIN_TYPE(obj)) {
|
|
|
|
case T_NIL:
|
|
|
|
case T_FIXNUM:
|
|
|
|
rb_bug("rb_gc_mark() called for broken object");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_NODE:
|
|
|
|
switch (nd_type(obj)) {
|
|
|
|
case NODE_IF: /* 1,2,3 */
|
|
|
|
case NODE_FOR:
|
|
|
|
case NODE_ITER:
|
|
|
|
case NODE_WHEN:
|
|
|
|
case NODE_MASGN:
|
|
|
|
case NODE_RESCUE:
|
|
|
|
case NODE_RESBODY:
|
|
|
|
case NODE_CLASS:
|
|
|
|
case NODE_BLOCK_PASS:
|
2012-10-04 11:23:41 +04:00
|
|
|
gc_mark(objspace, (VALUE)obj->as.node.u2.node);
|
2012-08-05 14:39:37 +04:00
|
|
|
/* fall through */
|
|
|
|
case NODE_BLOCK: /* 1,3 */
|
|
|
|
case NODE_ARRAY:
|
|
|
|
case NODE_DSTR:
|
|
|
|
case NODE_DXSTR:
|
|
|
|
case NODE_DREGX:
|
|
|
|
case NODE_DREGX_ONCE:
|
|
|
|
case NODE_ENSURE:
|
|
|
|
case NODE_CALL:
|
|
|
|
case NODE_DEFS:
|
|
|
|
case NODE_OP_ASGN1:
|
2012-10-04 11:23:41 +04:00
|
|
|
gc_mark(objspace, (VALUE)obj->as.node.u1.node);
|
2012-08-05 14:39:37 +04:00
|
|
|
/* fall through */
|
|
|
|
case NODE_SUPER: /* 3 */
|
|
|
|
case NODE_FCALL:
|
|
|
|
case NODE_DEFN:
|
|
|
|
case NODE_ARGS_AUX:
|
2012-10-04 11:23:41 +04:00
|
|
|
ptr = (VALUE)obj->as.node.u3.node;
|
|
|
|
goto again;
|
2010-05-28 15:13:42 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
case NODE_WHILE: /* 1,2 */
|
|
|
|
case NODE_UNTIL:
|
|
|
|
case NODE_AND:
|
|
|
|
case NODE_OR:
|
|
|
|
case NODE_CASE:
|
|
|
|
case NODE_SCLASS:
|
|
|
|
case NODE_DOT2:
|
|
|
|
case NODE_DOT3:
|
|
|
|
case NODE_FLIP2:
|
|
|
|
case NODE_FLIP3:
|
|
|
|
case NODE_MATCH2:
|
|
|
|
case NODE_MATCH3:
|
|
|
|
case NODE_OP_ASGN_OR:
|
|
|
|
case NODE_OP_ASGN_AND:
|
|
|
|
case NODE_MODULE:
|
|
|
|
case NODE_ALIAS:
|
|
|
|
case NODE_VALIAS:
|
|
|
|
case NODE_ARGSCAT:
|
2012-10-04 11:23:41 +04:00
|
|
|
gc_mark(objspace, (VALUE)obj->as.node.u1.node);
|
2012-08-05 14:39:37 +04:00
|
|
|
/* fall through */
|
|
|
|
case NODE_GASGN: /* 2 */
|
|
|
|
case NODE_LASGN:
|
|
|
|
case NODE_DASGN:
|
|
|
|
case NODE_DASGN_CURR:
|
|
|
|
case NODE_IASGN:
|
|
|
|
case NODE_IASGN2:
|
|
|
|
case NODE_CVASGN:
|
|
|
|
case NODE_COLON3:
|
|
|
|
case NODE_OPT_N:
|
|
|
|
case NODE_EVSTR:
|
|
|
|
case NODE_UNDEF:
|
|
|
|
case NODE_POSTEXE:
|
2012-10-04 11:23:41 +04:00
|
|
|
ptr = (VALUE)obj->as.node.u2.node;
|
|
|
|
goto again;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
case NODE_HASH: /* 1 */
|
|
|
|
case NODE_LIT:
|
|
|
|
case NODE_STR:
|
|
|
|
case NODE_XSTR:
|
|
|
|
case NODE_DEFINED:
|
|
|
|
case NODE_MATCH:
|
|
|
|
case NODE_RETURN:
|
|
|
|
case NODE_BREAK:
|
|
|
|
case NODE_NEXT:
|
|
|
|
case NODE_YIELD:
|
|
|
|
case NODE_COLON2:
|
|
|
|
case NODE_SPLAT:
|
|
|
|
case NODE_TO_ARY:
|
2012-10-04 11:23:41 +04:00
|
|
|
ptr = (VALUE)obj->as.node.u1.node;
|
|
|
|
goto again;
|
2012-01-07 18:02:23 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
case NODE_SCOPE: /* 2,3 */
|
|
|
|
case NODE_CDECL:
|
|
|
|
case NODE_OPT_ARG:
|
2012-10-04 11:23:41 +04:00
|
|
|
gc_mark(objspace, (VALUE)obj->as.node.u3.node);
|
|
|
|
ptr = (VALUE)obj->as.node.u2.node;
|
|
|
|
goto again;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
case NODE_ARGS: /* custom */
|
|
|
|
{
|
|
|
|
struct rb_args_info *args = obj->as.node.u3.args;
|
|
|
|
if (args) {
|
2012-10-03 16:30:21 +04:00
|
|
|
if (args->pre_init) gc_mark(objspace, (VALUE)args->pre_init);
|
|
|
|
if (args->post_init) gc_mark(objspace, (VALUE)args->post_init);
|
|
|
|
if (args->opt_args) gc_mark(objspace, (VALUE)args->opt_args);
|
|
|
|
if (args->kw_args) gc_mark(objspace, (VALUE)args->kw_args);
|
|
|
|
if (args->kw_rest_arg) gc_mark(objspace, (VALUE)args->kw_rest_arg);
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
|
|
|
}
|
2012-10-04 11:23:41 +04:00
|
|
|
ptr = (VALUE)obj->as.node.u2.node;
|
|
|
|
goto again;
|
2008-08-06 15:48:30 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
case NODE_ZARRAY: /* - */
|
|
|
|
case NODE_ZSUPER:
|
|
|
|
case NODE_VCALL:
|
|
|
|
case NODE_GVAR:
|
|
|
|
case NODE_LVAR:
|
|
|
|
case NODE_DVAR:
|
|
|
|
case NODE_IVAR:
|
|
|
|
case NODE_CVAR:
|
|
|
|
case NODE_NTH_REF:
|
|
|
|
case NODE_BACK_REF:
|
|
|
|
case NODE_REDO:
|
|
|
|
case NODE_RETRY:
|
|
|
|
case NODE_SELF:
|
|
|
|
case NODE_NIL:
|
|
|
|
case NODE_TRUE:
|
|
|
|
case NODE_FALSE:
|
|
|
|
case NODE_ERRINFO:
|
|
|
|
case NODE_BLOCK_ARG:
|
|
|
|
break;
|
|
|
|
case NODE_ALLOCA:
|
|
|
|
mark_locations_array(objspace,
|
|
|
|
(VALUE*)obj->as.node.u1.value,
|
|
|
|
obj->as.node.u3.cnt);
|
2012-10-04 11:23:41 +04:00
|
|
|
gc_mark(objspace, (VALUE)obj->as.node.u2.node);
|
2012-10-03 16:30:21 +04:00
|
|
|
break;
|
2008-10-01 14:13:57 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
case NODE_CREF:
|
2012-10-08 18:02:46 +04:00
|
|
|
gc_mark(objspace, obj->as.node.nd_refinements);
|
2012-10-04 11:23:41 +04:00
|
|
|
gc_mark(objspace, (VALUE)obj->as.node.u1.node);
|
|
|
|
ptr = (VALUE)obj->as.node.u3.node;
|
|
|
|
goto again;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
default: /* unlisted NODE */
|
2013-06-17 06:54:25 +04:00
|
|
|
gc_mark_maybe(objspace, (VALUE)obj->as.node.u1.node);
|
|
|
|
gc_mark_maybe(objspace, (VALUE)obj->as.node.u2.node);
|
|
|
|
gc_mark_maybe(objspace, (VALUE)obj->as.node.u3.node);
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
|
|
|
return; /* no need to mark class. */
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2012-10-03 16:30:21 +04:00
|
|
|
gc_mark(objspace, obj->as.basic.klass);
|
2008-07-27 09:59:32 +04:00
|
|
|
switch (BUILTIN_TYPE(obj)) {
|
2012-08-05 14:39:37 +04:00
|
|
|
case T_ICLASS:
|
1998-01-16 15:13:05 +03:00
|
|
|
case T_CLASS:
|
2012-08-05 14:39:37 +04:00
|
|
|
case T_MODULE:
|
2012-10-03 16:30:21 +04:00
|
|
|
mark_m_tbl(objspace, RCLASS_M_TBL(obj));
|
2012-08-05 14:39:37 +04:00
|
|
|
if (!RCLASS_EXT(obj)) break;
|
2012-10-04 11:23:41 +04:00
|
|
|
mark_tbl(objspace, RCLASS_IV_TBL(obj));
|
|
|
|
mark_const_tbl(objspace, RCLASS_CONST_TBL(obj));
|
* include/ruby/ruby.h: constify RBasic::klass and add
RBASIC_CLASS(obj) macro which returns a class of `obj'.
This change is a part of RGENGC branch [ruby-trunk - Feature #8339].
* object.c: add new function rb_obj_reveal().
This function reveal interal (hidden) object by rb_obj_hide().
Note that do not change class before and after hiding.
Only permitted example is:
klass = RBASIC_CLASS(obj);
rb_obj_hide(obj);
....
rb_obj_reveal(obj, klass);
TODO: API design. rb_obj_reveal() should be replaced with others.
TODO: modify constified variables using cast may be harmful for
compiler's analysis and optimizaton.
Any idea to prohibt inserting RBasic::klass directly?
If rename RBasic::klass and force to use RBASIC_CLASS(obj),
then all codes such as `RBASIC(obj)->klass' will be
compilation error. Is it acceptable? (We have similar
experience at Ruby 1.9,
for example "RARRAY(ary)->ptr" to "RARRAY_PTR(ary)".
* internal.h: add some macros.
* RBASIC_CLEAR_CLASS(obj) clear RBasic::klass to make it internal
object.
* RBASIC_SET_CLASS(obj, cls) set RBasic::klass.
* RBASIC_SET_CLASS_RAW(obj, cls) same as RBASIC_SET_CLASS
without write barrier (planned).
* RCLASS_SET_SUPER(a, b) set super class of a.
* array.c, class.c, compile.c, encoding.c, enum.c, error.c, eval.c,
file.c, gc.c, hash.c, io.c, iseq.c, marshal.c, object.c,
parse.y, proc.c, process.c, random.c, ruby.c, sprintf.c,
string.c, thread.c, transcode.c, vm.c, vm_eval.c, win32/file.c:
Use above macros and functions to access RBasic::klass.
* ext/coverage/coverage.c, ext/readline/readline.c,
ext/socket/ancdata.c, ext/socket/init.c,
* ext/zlib/zlib.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40691 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 14:49:11 +04:00
|
|
|
ptr = RCLASS_SUPER((VALUE)obj);
|
2012-10-04 11:23:41 +04:00
|
|
|
goto again;
|
2012-08-05 14:39:37 +04:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
case T_ARRAY:
|
2012-08-05 14:39:37 +04:00
|
|
|
if (FL_TEST(obj, ELTS_SHARED)) {
|
2012-10-04 11:23:41 +04:00
|
|
|
ptr = obj->as.array.as.heap.aux.shared;
|
|
|
|
goto again;
|
2000-09-27 07:43:15 +04:00
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
else {
|
|
|
|
long i, len = RARRAY_LEN(obj);
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
VALUE *ptr = RARRAY_RAWPTR(obj);
|
2012-08-05 14:39:37 +04:00
|
|
|
for (i=0; i < len; i++) {
|
2012-10-04 11:23:41 +04:00
|
|
|
gc_mark(objspace, *ptr++);
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
2012-08-05 14:39:37 +04:00
|
|
|
|
|
|
|
case T_HASH:
|
2012-10-03 16:30:21 +04:00
|
|
|
mark_hash(objspace, obj->as.hash.ntbl);
|
2012-10-04 11:23:41 +04:00
|
|
|
ptr = obj->as.hash.ifnone;
|
|
|
|
goto again;
|
2012-08-05 14:39:37 +04:00
|
|
|
|
|
|
|
case T_STRING:
|
|
|
|
#define STR_ASSOC FL_USER3 /* copied from string.c */
|
|
|
|
if (FL_TEST(obj, RSTRING_NOEMBED) && FL_ANY(obj, ELTS_SHARED|STR_ASSOC)) {
|
2012-10-04 11:23:41 +04:00
|
|
|
ptr = obj->as.string.as.heap.aux.shared;
|
|
|
|
goto again;
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
2012-08-05 14:39:37 +04:00
|
|
|
|
|
|
|
case T_DATA:
|
|
|
|
if (RTYPEDDATA_P(obj)) {
|
|
|
|
RUBY_DATA_FUNC mark_func = obj->as.typeddata.type->function.dmark;
|
|
|
|
if (mark_func) (*mark_func)(DATA_PTR(obj));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (obj->as.data.dmark) (*obj->as.data.dmark)(DATA_PTR(obj));
|
|
|
|
}
|
2008-03-16 03:23:43 +03:00
|
|
|
break;
|
2012-08-05 14:39:37 +04:00
|
|
|
|
|
|
|
case T_OBJECT:
|
|
|
|
{
|
|
|
|
long i, len = ROBJECT_NUMIV(obj);
|
|
|
|
VALUE *ptr = ROBJECT_IVPTR(obj);
|
|
|
|
for (i = 0; i < len; i++) {
|
2012-10-04 11:23:41 +04:00
|
|
|
gc_mark(objspace, *ptr++);
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
case T_FILE:
|
|
|
|
if (obj->as.file.fptr) {
|
2012-10-03 16:30:21 +04:00
|
|
|
gc_mark(objspace, obj->as.file.fptr->pathv);
|
|
|
|
gc_mark(objspace, obj->as.file.fptr->tied_io_for_writing);
|
|
|
|
gc_mark(objspace, obj->as.file.fptr->writeconv_asciicompat);
|
|
|
|
gc_mark(objspace, obj->as.file.fptr->writeconv_pre_ecopts);
|
|
|
|
gc_mark(objspace, obj->as.file.fptr->encs.ecopts);
|
|
|
|
gc_mark(objspace, obj->as.file.fptr->write_lock);
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_REGEXP:
|
2012-10-03 16:30:21 +04:00
|
|
|
ptr = obj->as.regexp.src;
|
|
|
|
goto again;
|
2012-08-05 14:39:37 +04:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
case T_FLOAT:
|
2012-08-05 14:39:37 +04:00
|
|
|
case T_BIGNUM:
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
case T_MATCH:
|
2012-10-04 11:23:41 +04:00
|
|
|
gc_mark(objspace, obj->as.match.regexp);
|
2012-08-05 14:39:37 +04:00
|
|
|
if (obj->as.match.str) {
|
2012-10-04 11:23:41 +04:00
|
|
|
ptr = obj->as.match.str;
|
|
|
|
goto again;
|
2000-09-27 07:43:15 +04:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
2012-08-05 14:39:37 +04:00
|
|
|
|
|
|
|
case T_RATIONAL:
|
2012-10-04 11:23:41 +04:00
|
|
|
gc_mark(objspace, obj->as.rational.num);
|
|
|
|
ptr = obj->as.rational.den;
|
|
|
|
goto again;
|
2012-08-05 14:39:37 +04:00
|
|
|
|
|
|
|
case T_COMPLEX:
|
2012-10-04 11:23:41 +04:00
|
|
|
gc_mark(objspace, obj->as.complex.real);
|
|
|
|
ptr = obj->as.complex.imag;
|
|
|
|
goto again;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
case T_STRUCT:
|
2012-08-05 14:39:37 +04:00
|
|
|
{
|
|
|
|
long len = RSTRUCT_LEN(obj);
|
|
|
|
VALUE *ptr = RSTRUCT_PTR(obj);
|
|
|
|
|
|
|
|
while (len--) {
|
2012-10-04 11:23:41 +04:00
|
|
|
gc_mark(objspace, *ptr++);
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
2000-09-27 07:43:15 +04:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2013-06-19 10:11:15 +04:00
|
|
|
#ifdef GC_DEBUG
|
|
|
|
rb_gcdebug_print_obj_condition((VALUE)obj);
|
|
|
|
#endif
|
|
|
|
if (BUILTIN_TYPE(obj) == T_NONE) rb_bug("rb_gc_mark(): %p is T_NONE", (void *)obj);
|
|
|
|
if (BUILTIN_TYPE(obj) == T_ZOMBIE) rb_bug("rb_gc_mark(): %p is T_ZOMBIE", (void *)obj);
|
2012-08-05 14:39:37 +04:00
|
|
|
rb_bug("rb_gc_mark(): unknown data type 0x%x(%p) %s",
|
|
|
|
BUILTIN_TYPE(obj), (void *)obj,
|
|
|
|
is_pointer_to_heap(objspace, obj) ? "corrupted object" : "non object");
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-04 11:31:31 +04:00
|
|
|
static void
|
|
|
|
gc_mark_stacked_objects(rb_objspace_t *objspace)
|
|
|
|
{
|
|
|
|
mark_stack_t *mstack = &objspace->mark_stack;
|
|
|
|
VALUE obj = 0;
|
|
|
|
|
|
|
|
if (!mstack->index) return;
|
|
|
|
while (pop_mark_stack(mstack, &obj)) {
|
|
|
|
gc_mark_children(objspace, obj);
|
|
|
|
}
|
|
|
|
shrink_stack_chunk_cache(mstack);
|
|
|
|
}
|
|
|
|
|
2010-05-28 15:13:42 +04:00
|
|
|
static void
|
2013-06-19 18:59:35 +04:00
|
|
|
gc_marks_body(rb_objspace_t *objspace, rb_thread_t *th, int minor_gc)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-07-05 11:15:41 +04:00
|
|
|
struct gc_list *list;
|
2012-10-24 05:39:45 +04:00
|
|
|
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
/* start marking */
|
|
|
|
rgengc_report(1, objspace, "gc_marks_body: start.\n");
|
2012-10-04 11:31:31 +04:00
|
|
|
|
2013-06-19 18:59:35 +04:00
|
|
|
objspace->rgengc.parent_object_is_promoted = FALSE;
|
|
|
|
objspace->rgengc.parent_object = Qundef;
|
|
|
|
objspace->rgengc.during_minor_gc = minor_gc;
|
|
|
|
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#if USE_RGENGC
|
|
|
|
if (objspace->rgengc.during_minor_gc) {
|
|
|
|
objspace->profile.minor_gc_count++;
|
2013-05-24 14:21:04 +04:00
|
|
|
objspace->rgengc.remembered_shady_object_count = rgengc_rememberset_mark(objspace);
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
objspace->profile.major_gc_count++;
|
2013-06-07 06:32:57 +04:00
|
|
|
rgengc_mark_and_rememberset_clear(objspace);
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
}
|
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2007-02-05 15:21:01 +03:00
|
|
|
SET_STACK_END;
|
2007-05-24 06:47:22 +04:00
|
|
|
th->vm->self ? rb_gc_mark(th->vm->self) : rb_vm_mark(th->vm);
|
2006-01-10 13:50:17 +03:00
|
|
|
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
if (RGENGC_CHECK_MODE > 1) objspace->rgengc.parent_object = INT2FIX(__LINE__);
|
2012-10-03 16:30:21 +04:00
|
|
|
mark_tbl(objspace, finalizer_table);
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
|
|
|
|
if (RGENGC_CHECK_MODE > 1) objspace->rgengc.parent_object = INT2FIX(__LINE__);
|
2008-04-27 07:20:35 +04:00
|
|
|
mark_current_machine_context(objspace, th);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
if (RGENGC_CHECK_MODE > 1) objspace->rgengc.parent_object = INT2FIX(__LINE__);
|
2006-09-02 19:05:27 +04:00
|
|
|
rb_gc_mark_symbols();
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
|
|
|
|
if (RGENGC_CHECK_MODE > 1) objspace->rgengc.parent_object = INT2FIX(__LINE__);
|
2007-10-13 20:32:40 +04:00
|
|
|
rb_gc_mark_encodings();
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
/* mark protected global variables */
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
if (RGENGC_CHECK_MODE > 1) objspace->rgengc.parent_object = INT2FIX(__LINE__);
|
2001-10-31 09:53:22 +03:00
|
|
|
for (list = global_List; list; list = list->next) {
|
2003-04-21 12:17:18 +04:00
|
|
|
rb_gc_mark_maybe(*list->varptr);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
|
|
|
|
if (RGENGC_CHECK_MODE > 1) objspace->rgengc.parent_object = INT2FIX(__LINE__);
|
1999-11-26 12:07:26 +03:00
|
|
|
rb_mark_end_proc();
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
|
|
|
|
if (RGENGC_CHECK_MODE > 1) objspace->rgengc.parent_object = INT2FIX(__LINE__);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_gc_mark_global_tbl();
|
1998-01-16 15:13:05 +03:00
|
|
|
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
if (RGENGC_CHECK_MODE > 1) objspace->rgengc.parent_object = INT2FIX(__LINE__);
|
2012-10-03 16:30:21 +04:00
|
|
|
mark_tbl(objspace, rb_class_tbl);
|
1999-01-20 07:59:39 +03:00
|
|
|
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
if (RGENGC_CHECK_MODE > 1) objspace->rgengc.parent_object = INT2FIX(__LINE__);
|
1999-01-20 07:59:39 +03:00
|
|
|
/* mark generic instance variables for special constants */
|
|
|
|
rb_mark_generic_ivar_tbl();
|
2002-09-06 00:00:52 +04:00
|
|
|
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
if (RGENGC_CHECK_MODE > 1) objspace->rgengc.parent_object = INT2FIX(__LINE__);
|
2002-09-06 00:00:52 +04:00
|
|
|
rb_gc_mark_parser();
|
2005-06-19 21:16:14 +04:00
|
|
|
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
if (RGENGC_CHECK_MODE > 1) objspace->rgengc.parent_object = INT2FIX(__LINE__);
|
2011-07-25 18:29:28 +04:00
|
|
|
rb_gc_mark_unlinked_live_method_entries(th->vm);
|
|
|
|
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
if (RGENGC_CHECK_MODE > 1) objspace->rgengc.parent_object = Qundef;
|
|
|
|
|
2012-10-03 16:30:21 +04:00
|
|
|
/* marking-loop */
|
2012-10-04 11:31:31 +04:00
|
|
|
gc_mark_stacked_objects(objspace);
|
2012-10-03 16:30:21 +04:00
|
|
|
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
/* cleanup */
|
|
|
|
rgengc_report(1, objspace, "gc_marks_body: end.\n");
|
|
|
|
}
|
|
|
|
|
2013-06-19 18:59:35 +04:00
|
|
|
static uintptr_t *
|
|
|
|
gc_store_bitmaps(rb_objspace_t *objspace)
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
{
|
2013-06-19 18:59:35 +04:00
|
|
|
uintptr_t *stored_bitmaps = (uintptr_t *)malloc((HEAP_BITMAP_LIMIT * sizeof(uintptr_t)) * heaps_used * 3);
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
size_t i;
|
|
|
|
|
2013-06-19 18:59:35 +04:00
|
|
|
if (stored_bitmaps == 0) rb_bug("gc_store_bitmaps: not enough memory to test.\n");
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
|
2013-06-19 18:59:35 +04:00
|
|
|
for (i=0; i<heaps_used; i++) {
|
|
|
|
memcpy(&stored_bitmaps[(3*i+0)*HEAP_BITMAP_LIMIT], objspace->heap.sorted[i]->mark_bits, sizeof(uintptr_t) * HEAP_BITMAP_LIMIT);
|
|
|
|
memcpy(&stored_bitmaps[(3*i+1)*HEAP_BITMAP_LIMIT], objspace->heap.sorted[i]->rememberset_bits, sizeof(uintptr_t) * HEAP_BITMAP_LIMIT);
|
|
|
|
memcpy(&stored_bitmaps[(3*i+2)*HEAP_BITMAP_LIMIT], objspace->heap.sorted[i]->oldgen_bits, sizeof(uintptr_t) * HEAP_BITMAP_LIMIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
return stored_bitmaps;
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
}
|
|
|
|
|
2013-06-19 18:59:35 +04:00
|
|
|
static void
|
|
|
|
gc_restore_bitmaps(rb_objspace_t *objspace, uintptr_t *stored_bitmaps)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
for (i=0; i<heaps_used; i++) {
|
2013-06-19 18:59:35 +04:00
|
|
|
uintptr_t *oldgen_bits = objspace->heap.sorted[i]->oldgen_bits;
|
|
|
|
RVALUE *p = objspace->heap.sorted[i]->start;
|
|
|
|
RVALUE *pend = p + objspace->heap.sorted[i]->limit;
|
|
|
|
|
|
|
|
/* restore bitmaps */
|
|
|
|
memcpy(objspace->heap.sorted[i]->mark_bits, &stored_bitmaps[(3*i+0)*HEAP_BITMAP_LIMIT], sizeof(uintptr_t) * HEAP_BITMAP_LIMIT);
|
|
|
|
memcpy(objspace->heap.sorted[i]->rememberset_bits, &stored_bitmaps[(3*i+1)*HEAP_BITMAP_LIMIT], sizeof(uintptr_t) * HEAP_BITMAP_LIMIT);
|
|
|
|
memcpy(objspace->heap.sorted[i]->oldgen_bits, &stored_bitmaps[(3*i+2)*HEAP_BITMAP_LIMIT], sizeof(uintptr_t) * HEAP_BITMAP_LIMIT);
|
|
|
|
|
|
|
|
|
|
|
|
/* resotre oldgen bits */
|
|
|
|
while (p < pend) {
|
|
|
|
if (MARKED_IN_BITMAP(oldgen_bits, p)) FL_SET2(p, FL_OLDGEN);
|
|
|
|
else FL_UNSET2(p, FL_OLDGEN);
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gc_free_stored_bitmaps(rb_objspace_t *objspace, uintptr_t *stored_bitmaps)
|
|
|
|
{
|
|
|
|
free(stored_bitmaps);
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
}
|
|
|
|
|
2013-06-19 18:59:35 +04:00
|
|
|
static void
|
|
|
|
gc_marks_test(rb_objspace_t *objspace, rb_thread_t *th, uintptr_t *before_stored_bitmaps)
|
|
|
|
{
|
|
|
|
#if USE_RGENGC
|
|
|
|
uintptr_t *stored_bitmaps = gc_store_bitmaps(objspace);
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
rgengc_report(1, objspace, "gc_marks_test: test-full-gc\n");
|
|
|
|
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
/* run major (full) gc with temporary mark/rememberset */
|
2013-06-19 18:59:35 +04:00
|
|
|
gc_marks_body(objspace, th, FALSE);
|
|
|
|
objspace->rgengc.during_minor_gc = TRUE;
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
|
2013-06-19 18:59:35 +04:00
|
|
|
/* check */
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
for (i=0; i<heaps_used; i++) {
|
2013-06-19 18:59:35 +04:00
|
|
|
uintptr_t *minor_mark_bits = &stored_bitmaps[(3*i+0)*HEAP_BITMAP_LIMIT];
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
uintptr_t *major_mark_bits = objspace->heap.sorted[i]->mark_bits;
|
|
|
|
RVALUE *p = objspace->heap.sorted[i]->start;
|
|
|
|
RVALUE *pend = p + objspace->heap.sorted[i]->limit;
|
|
|
|
|
|
|
|
while (p < pend) {
|
|
|
|
if (MARKED_IN_BITMAP(major_mark_bits, p) && /* should be lived */
|
2013-06-19 18:59:35 +04:00
|
|
|
!MARKED_IN_BITMAP(minor_mark_bits, p)) {
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
fprintf(stderr, "gc_marks_test: %p (%s) is living, but not marked && not promoted.\n", p, obj_type_name((VALUE)p));
|
|
|
|
objspace->rgengc.interesting_object = (VALUE)p;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
2013-06-19 02:04:30 +04:00
|
|
|
|
|
|
|
if (objspace->rgengc.interesting_object) {
|
|
|
|
fprintf(stderr, "!!! restart minor gc\n");
|
2013-06-19 18:59:35 +04:00
|
|
|
gc_restore_bitmaps(objspace, before_stored_bitmaps);
|
|
|
|
gc_marks_body(objspace, th, FALSE);
|
|
|
|
|
2013-06-19 02:04:30 +04:00
|
|
|
fprintf(stderr, "!!! restart major gc\n");
|
2013-06-19 18:59:35 +04:00
|
|
|
gc_restore_bitmaps(objspace, before_stored_bitmaps);
|
|
|
|
gc_marks_body(objspace, th, TRUE);
|
2013-06-19 02:04:30 +04:00
|
|
|
rb_bug("gc_marks_test (again): %p (%s) is living, but not marked && not promoted.\n",
|
|
|
|
(void *)objspace->rgengc.interesting_object, obj_type_name((VALUE)objspace->rgengc.interesting_object));
|
|
|
|
}
|
2013-06-19 18:59:35 +04:00
|
|
|
else {
|
|
|
|
gc_restore_bitmaps(objspace, stored_bitmaps);
|
|
|
|
gc_free_stored_bitmaps(objspace, stored_bitmaps);
|
|
|
|
}
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gc_marks(rb_objspace_t *objspace, int minor_gc)
|
|
|
|
{
|
|
|
|
struct mark_func_data_struct *prev_mark_func_data;
|
|
|
|
rb_thread_t *th = GET_THREAD();
|
|
|
|
|
|
|
|
gc_prof_mark_timer_start(objspace);
|
2013-05-21 11:52:03 +04:00
|
|
|
{
|
|
|
|
/* setup marking */
|
|
|
|
prev_mark_func_data = objspace->mark_func_data;
|
|
|
|
objspace->mark_func_data = 0;
|
2013-05-24 14:21:04 +04:00
|
|
|
|
|
|
|
if (minor_gc == FALSE) { /* major/full GC */
|
|
|
|
objspace->rgengc.remembered_shady_object_count = 0;
|
|
|
|
objspace->rgengc.oldgen_object_count = 0;
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
|
2013-06-19 18:59:35 +04:00
|
|
|
gc_marks_body(objspace, th, FALSE);
|
2013-05-24 14:21:04 +04:00
|
|
|
|
|
|
|
/* Do full GC if old/remembered_shady object counts is greater than counts two times at last full GC counts */
|
|
|
|
objspace->rgengc.remembered_shady_object_limit = objspace->rgengc.remembered_shady_object_count * 2;
|
|
|
|
objspace->rgengc.oldgen_object_limit = objspace->rgengc.oldgen_object_count * 2;
|
|
|
|
}
|
|
|
|
else { /* minor GC */
|
2013-06-19 18:59:35 +04:00
|
|
|
if (RGENGC_CHECK_MODE > 1) {
|
|
|
|
uintptr_t *before_mark_stored_bitmaps = gc_store_bitmaps(objspace);
|
|
|
|
gc_marks_body(objspace, th, TRUE);
|
|
|
|
gc_marks_test(objspace, th, before_mark_stored_bitmaps);
|
|
|
|
gc_free_stored_bitmaps(objspace, before_mark_stored_bitmaps);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gc_marks_body(objspace, th, FALSE);
|
2013-05-24 14:21:04 +04:00
|
|
|
}
|
2013-05-21 11:52:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
objspace->mark_func_data = prev_mark_func_data;
|
|
|
|
}
|
|
|
|
gc_prof_mark_timer_stop(objspace);
|
2010-05-28 15:13:42 +04:00
|
|
|
}
|
|
|
|
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
/* RGENGC */
|
|
|
|
|
|
|
|
#if USE_RGENGC
|
|
|
|
|
|
|
|
/* bit operations */
|
|
|
|
|
|
|
|
static int
|
|
|
|
rgengc_remembersetbits_get(rb_objspace_t *objspace, VALUE obj)
|
|
|
|
{
|
|
|
|
uintptr_t *bits = GET_HEAP_REMEMBERSET_BITS(obj);
|
|
|
|
return MARKED_IN_BITMAP(bits, obj) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rgengc_remembersetbits_set(rb_objspace_t *objspace, VALUE obj)
|
|
|
|
{
|
|
|
|
uintptr_t *bits = GET_HEAP_REMEMBERSET_BITS(obj);
|
|
|
|
MARK_IN_BITMAP(bits, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* wb, etc */
|
|
|
|
|
|
|
|
static void
|
|
|
|
rgengc_remember(rb_objspace_t *objspace, VALUE obj)
|
|
|
|
{
|
2013-06-19 02:12:39 +04:00
|
|
|
rgengc_report(2, objspace, "rgengc_remember: %p (%s, %s) %s\n", (void *)obj, obj_type_name(obj),
|
2013-06-07 05:17:19 +04:00
|
|
|
RVALUE_SHADY(obj) ? "shady" : "non-shady",
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
rgengc_remembersetbits_get(objspace, obj) ? "was already remembered" : "is remembered now");
|
|
|
|
|
2013-06-19 02:07:09 +04:00
|
|
|
#if RGENGC_CHECK_MODE > 0
|
|
|
|
{
|
|
|
|
switch (BUILTIN_TYPE(obj)) {
|
|
|
|
case T_NONE:
|
|
|
|
case T_ZOMBIE:
|
|
|
|
rb_bug("rgengc_remember: should not remember %p (%s)\n",
|
|
|
|
(void *)obj, obj_type_name(obj));
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
if (RGENGC_PROFILE) {
|
|
|
|
if (!rgengc_remembered(objspace, obj)) {
|
2013-06-07 05:17:19 +04:00
|
|
|
if (!RVALUE_SHADY(obj)) {
|
|
|
|
objspace->profile.remembered_normal_object_count++;
|
2013-05-26 20:43:21 +04:00
|
|
|
#if RGENGC_PROFILE >= 2
|
2013-06-07 05:17:19 +04:00
|
|
|
objspace->profile.remembered_normal_object_count_types[BUILTIN_TYPE(obj)]++;
|
2013-05-26 20:43:21 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
objspace->profile.remembered_shady_object_count++;
|
|
|
|
#if RGENGC_PROFILE >= 2
|
|
|
|
objspace->profile.remembered_shady_object_count_types[BUILTIN_TYPE(obj)]++;
|
|
|
|
#endif
|
|
|
|
}
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rgengc_remembersetbits_set(objspace, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
rgengc_remembered(rb_objspace_t *objspace, VALUE obj)
|
|
|
|
{
|
|
|
|
int result = rgengc_remembersetbits_get(objspace, obj);
|
|
|
|
rgengc_report(6, objspace, "gc_remembered: %p (%s) => %d\n", (void *)obj, obj_type_name(obj), result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
rgengc_rememberset_mark(rb_objspace_t *objspace)
|
|
|
|
{
|
2013-06-05 19:57:12 +04:00
|
|
|
size_t i, j;
|
2013-06-19 02:12:39 +04:00
|
|
|
size_t shady_object_count = 0, clear_count = 0;
|
2013-06-05 19:57:12 +04:00
|
|
|
RVALUE *p, *offset;
|
|
|
|
uintptr_t *bits, bitset;
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
|
|
|
|
for (i=0; i<heaps_used; i++) {
|
2013-06-05 19:57:12 +04:00
|
|
|
p = objspace->heap.sorted[i]->start;
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
bits = GET_HEAP_REMEMBERSET_BITS(p);
|
|
|
|
|
2013-06-05 19:57:12 +04:00
|
|
|
offset = p - NUM_IN_SLOT(p);
|
|
|
|
|
2013-06-07 06:52:42 +04:00
|
|
|
for (j=0; j < HEAP_BITMAP_LIMIT; j++) {
|
|
|
|
if (bits[j]) {
|
2013-06-05 19:57:12 +04:00
|
|
|
p = offset + j * (sizeof(uintptr_t) * CHAR_BIT);
|
|
|
|
bitset = bits[j];
|
2013-06-07 06:32:57 +04:00
|
|
|
do {
|
2013-06-05 19:57:12 +04:00
|
|
|
if (bitset & 1) {
|
2013-06-07 06:32:57 +04:00
|
|
|
gc_mark_ptr(objspace, (VALUE)p);
|
|
|
|
push_mark_stack(&objspace->mark_stack, (VALUE) p);
|
2013-06-05 19:57:12 +04:00
|
|
|
rgengc_report(2, objspace, "rgengc_rememberset_mark: mark %p (%s)\n", p, obj_type_name((VALUE)p));
|
2013-06-05 20:01:05 +04:00
|
|
|
|
2013-06-07 05:17:19 +04:00
|
|
|
if (!RVALUE_SHADY(p)) {
|
2013-06-05 19:57:12 +04:00
|
|
|
rgengc_report(2, objspace, "rgengc_rememberset_mark: clear %p (%s)\n", p, obj_type_name((VALUE)p));
|
|
|
|
CLEAR_IN_BITMAP(bits, p);
|
2013-06-19 02:12:39 +04:00
|
|
|
clear_count++;
|
2013-06-05 19:57:12 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
shady_object_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p++;
|
2013-06-07 06:32:57 +04:00
|
|
|
bitset >>= 1;
|
|
|
|
} while (bitset);
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-19 02:12:39 +04:00
|
|
|
rgengc_report(2, objspace, "rgengc_rememberset_mark: clear_count: %"PRIdSIZE", shady_object_count: %"PRIdSIZE"\n", clear_count, shady_object_count);
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
|
2013-05-24 14:21:04 +04:00
|
|
|
return shady_object_count;
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-06-07 06:32:57 +04:00
|
|
|
rgengc_mark_and_rememberset_clear(rb_objspace_t *objspace)
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i=0; i<heaps_used; i++) {
|
2013-06-07 06:32:57 +04:00
|
|
|
memset(objspace->heap.sorted[i]->mark_bits, 0, HEAP_BITMAP_LIMIT * sizeof(uintptr_t));
|
|
|
|
memset(objspace->heap.sorted[i]->rememberset_bits, 0, HEAP_BITMAP_LIMIT * sizeof(uintptr_t));
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RGENGC: APIs */
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_gc_writebarrier(VALUE a, VALUE b)
|
|
|
|
{
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
|
|
|
|
if (RGENGC_CHECK_MODE) {
|
|
|
|
if (!RVALUE_PROMOTED(a)) rb_bug("rb_gc_wb: referer object %p (%s) is not promoted.\n", (void *)a, obj_type_name(a));
|
|
|
|
if (RVALUE_PROMOTED(b)) rb_bug("rb_gc_wb: refered object %p (%s) is promoted.\n", (void *)b, obj_type_name(b));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rgengc_remembered(objspace, a)) {
|
|
|
|
rgengc_report(2, objspace, "rb_gc_wb: %p (%s) -> %p (%s)\n",
|
|
|
|
(void *)a, obj_type_name(a), (void *)b, obj_type_name(b));
|
|
|
|
rgengc_remember(objspace, a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_gc_giveup_promoted_writebarrier(VALUE obj)
|
|
|
|
{
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
|
|
|
|
if (RGENGC_CHECK_MODE) {
|
|
|
|
if (!RVALUE_PROMOTED(obj)) rb_bug("rb_gc_giveup_promoted_writebarrier: called on non-promoted object");
|
2013-06-07 05:17:19 +04:00
|
|
|
if (!RVALUE_SHADY(obj)) rb_bug("rb_gc_giveup_promoted_writebarrier: called on non-shady object");
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
rgengc_report(2, objspace, "rb_gc_giveup_writebarrier: %p (%s)%s\n", (void *)obj, obj_type_name(obj),
|
|
|
|
rgengc_remembered(objspace, obj) ? " (already remembered)" : "");
|
|
|
|
|
|
|
|
/* need to sweep all slots before demote */
|
|
|
|
/* TODO: check delayed sweeping slot or not
|
|
|
|
* if delayed sweepling slot, then mark it
|
|
|
|
* else demote simple
|
|
|
|
*/
|
|
|
|
rest_sweep(objspace);
|
|
|
|
|
|
|
|
RVALUE_DEMOTE(obj);
|
|
|
|
rgengc_remember(objspace, obj);
|
|
|
|
|
|
|
|
#if RGENGC_PROFILE
|
|
|
|
objspace->profile.shade_operation_count++;
|
2013-05-26 20:43:21 +04:00
|
|
|
#if RGENGC_PROFILE >= 2
|
|
|
|
objspace->profile.shade_operation_count_types[BUILTIN_TYPE(obj)]++;
|
|
|
|
#endif /* RGENGC_PROFILE >= 2 */
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* USE_RGENGC */
|
|
|
|
|
|
|
|
/* RGENGC analysis information */
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_obj_rgengc_writebarrier_protected_p(VALUE obj)
|
|
|
|
{
|
|
|
|
return OBJ_WB_PROTECTED(obj) ? Qtrue : Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_obj_rgengc_promoted_p(VALUE obj)
|
|
|
|
{
|
|
|
|
return OBJ_PROMOTED(obj) ? Qtrue : Qfalse;
|
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
/* GC */
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_gc_force_recycle(VALUE p)
|
|
|
|
{
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
struct heaps_slot *slot;
|
|
|
|
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#if USE_RGENGC
|
|
|
|
CLEAR_IN_BITMAP(GET_HEAP_REMEMBERSET_BITS(p), p);
|
2013-06-19 18:30:13 +04:00
|
|
|
CLEAR_IN_BITMAP(GET_HEAP_OLDGEN_BITS(p), p);
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#endif
|
|
|
|
|
2013-03-18 19:30:02 +04:00
|
|
|
objspace->total_freed_object_num++;
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
if (MARKED_IN_BITMAP(GET_HEAP_MARK_BITS(p), p)) {
|
2012-08-05 14:39:37 +04:00
|
|
|
add_slot_local_freelist(objspace, (RVALUE *)p);
|
|
|
|
}
|
|
|
|
else {
|
2012-11-29 09:05:19 +04:00
|
|
|
objspace->heap.free_num++;
|
2012-08-05 14:39:37 +04:00
|
|
|
slot = add_slot_local_freelist(objspace, (RVALUE *)p);
|
|
|
|
if (slot->free_next == NULL) {
|
|
|
|
link_free_heap_slot(objspace, slot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_gc_register_mark_object(VALUE obj)
|
|
|
|
{
|
|
|
|
VALUE ary = GET_THREAD()->vm->mark_object_ary;
|
|
|
|
rb_ary_push(ary, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_gc_register_address(VALUE *addr)
|
|
|
|
{
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
struct gc_list *tmp;
|
|
|
|
|
|
|
|
tmp = ALLOC(struct gc_list);
|
|
|
|
tmp->next = global_List;
|
|
|
|
tmp->varptr = addr;
|
|
|
|
global_List = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_gc_unregister_address(VALUE *addr)
|
|
|
|
{
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
struct gc_list *tmp = global_List;
|
|
|
|
|
|
|
|
if (tmp->varptr == addr) {
|
|
|
|
global_List = tmp->next;
|
|
|
|
xfree(tmp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
while (tmp->next) {
|
|
|
|
if (tmp->next->varptr == addr) {
|
|
|
|
struct gc_list *t = tmp->next;
|
|
|
|
|
|
|
|
tmp->next = tmp->next->next;
|
|
|
|
xfree(t);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tmp = tmp->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GC_NOTIFY 0
|
|
|
|
|
2010-05-28 15:13:42 +04:00
|
|
|
static int
|
2013-05-22 03:09:22 +04:00
|
|
|
garbage_collect_body(rb_objspace_t *objspace, int full_mark, int immediate_sweep, int reason)
|
2010-05-28 15:13:42 +04:00
|
|
|
{
|
2013-05-22 03:09:22 +04:00
|
|
|
int minor_gc;
|
2010-05-28 15:13:42 +04:00
|
|
|
|
2013-05-22 03:09:22 +04:00
|
|
|
if (ruby_gc_stress && !ruby_disable_gc_stress) {
|
2013-05-24 10:52:38 +04:00
|
|
|
minor_gc = FALSE;
|
2013-05-22 03:09:22 +04:00
|
|
|
immediate_sweep = TRUE;
|
2013-06-19 01:35:40 +04:00
|
|
|
|
|
|
|
if (FIXNUM_P(ruby_gc_stress)) {
|
2013-06-19 02:49:19 +04:00
|
|
|
int flag = FIX2INT(ruby_gc_stress);
|
2013-06-19 01:35:40 +04:00
|
|
|
|
|
|
|
if (flag & 0x01) minor_gc = TRUE;
|
|
|
|
if (flag & 0x02) immediate_sweep = FALSE;
|
|
|
|
}
|
2010-05-28 15:13:42 +04:00
|
|
|
}
|
2013-05-22 03:09:22 +04:00
|
|
|
else {
|
|
|
|
if (full_mark) {
|
|
|
|
minor_gc = FALSE;
|
|
|
|
}
|
|
|
|
else {
|
2013-05-24 14:21:04 +04:00
|
|
|
if (objspace->rgengc.need_major_gc ||
|
|
|
|
objspace->rgengc.remembered_shady_object_count > objspace->rgengc.remembered_shady_object_limit ||
|
|
|
|
objspace->rgengc.oldgen_object_count > objspace->rgengc.oldgen_object_limit) {
|
|
|
|
|
2013-05-24 10:52:38 +04:00
|
|
|
objspace->rgengc.need_major_gc = FALSE;
|
|
|
|
minor_gc = FALSE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
minor_gc = TRUE;
|
|
|
|
}
|
2013-05-22 03:09:22 +04:00
|
|
|
}
|
2010-05-28 15:13:42 +04:00
|
|
|
}
|
|
|
|
|
2013-05-27 21:46:20 +04:00
|
|
|
if (!GC_ENABLE_LAZY_SWEEP || objspace->flags.dont_lazy_sweep) {
|
2013-05-22 03:09:22 +04:00
|
|
|
immediate_sweep = TRUE;
|
|
|
|
}
|
2012-02-21 13:35:07 +04:00
|
|
|
|
2013-05-27 21:46:20 +04:00
|
|
|
if (GC_NOTIFY) fprintf(stderr, "start garbage_collect(%d, %d, %d)\n", full_mark, immediate_sweep, reason);
|
2013-06-19 18:59:35 +04:00
|
|
|
objspace->count++;
|
2013-05-27 04:21:02 +04:00
|
|
|
gc_event_hook(objspace, RUBY_INTERNAL_EVENT_GC_START, 0 /* TODO: pass minor/immediate flag? */);
|
|
|
|
|
2013-05-22 03:09:22 +04:00
|
|
|
gc_prof_timer_start(objspace, reason | (minor_gc ? GPR_FLAG_MINOR : 0));
|
2013-05-21 11:52:03 +04:00
|
|
|
{
|
2013-05-22 03:09:22 +04:00
|
|
|
assert(during_gc > 0);
|
|
|
|
gc_marks(objspace, minor_gc);
|
|
|
|
gc_sweep(objspace, immediate_sweep);
|
|
|
|
during_gc = 0;
|
2013-05-21 11:52:03 +04:00
|
|
|
}
|
2013-05-21 12:21:59 +04:00
|
|
|
gc_prof_timer_stop(objspace);
|
2013-05-21 11:52:03 +04:00
|
|
|
|
2013-05-27 21:46:20 +04:00
|
|
|
if (GC_NOTIFY) fprintf(stderr, "end garbage_collect()\n");
|
2009-07-18 12:05:32 +04:00
|
|
|
return TRUE;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2013-05-22 03:09:22 +04:00
|
|
|
static int
|
|
|
|
garbage_collect(rb_objspace_t *objspace, int full_mark, int immediate_sweep, int reason)
|
|
|
|
{
|
|
|
|
if (!heaps) {
|
|
|
|
during_gc = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!ready_to_gc(objspace)) {
|
|
|
|
during_gc = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-06-16 00:18:11 +04:00
|
|
|
#if GC_PROFILE_MORE_DETAIL
|
|
|
|
objspace->profile.prepare_time = getrusage_time();
|
|
|
|
#endif
|
2013-05-22 03:09:22 +04:00
|
|
|
rest_sweep(objspace);
|
2013-06-16 00:18:11 +04:00
|
|
|
#if GC_PROFILE_MORE_DETAIL
|
|
|
|
objspace->profile.prepare_time = getrusage_time() - objspace->profile.prepare_time;
|
|
|
|
#endif
|
2013-05-22 03:09:22 +04:00
|
|
|
|
|
|
|
during_gc++;
|
|
|
|
|
|
|
|
return garbage_collect_body(objspace, full_mark, immediate_sweep, reason);
|
|
|
|
}
|
|
|
|
|
2013-05-21 12:19:07 +04:00
|
|
|
struct objspace_and_reason {
|
|
|
|
rb_objspace_t *objspace;
|
|
|
|
int reason;
|
2013-05-22 03:09:22 +04:00
|
|
|
int full_mark;
|
|
|
|
int immediate_sweep;
|
2013-05-21 12:19:07 +04:00
|
|
|
};
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static void *
|
|
|
|
gc_with_gvl(void *ptr)
|
|
|
|
{
|
2013-05-21 12:19:07 +04:00
|
|
|
struct objspace_and_reason *oar = (struct objspace_and_reason *)ptr;
|
2013-05-22 03:09:22 +04:00
|
|
|
return (void *)(VALUE)garbage_collect(oar->objspace, oar->full_mark, oar->immediate_sweep, oar->reason);
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-05-22 03:09:22 +04:00
|
|
|
garbage_collect_with_gvl(rb_objspace_t *objspace, int full_mark, int immediate_sweep, int reason)
|
2012-08-05 14:39:37 +04:00
|
|
|
{
|
|
|
|
if (dont_gc) return TRUE;
|
|
|
|
if (ruby_thread_has_gvl_p()) {
|
2013-05-22 03:09:22 +04:00
|
|
|
return garbage_collect(objspace, full_mark, immediate_sweep, reason);
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (ruby_native_thread_p()) {
|
2013-05-21 12:19:07 +04:00
|
|
|
struct objspace_and_reason oar;
|
|
|
|
oar.objspace = objspace;
|
|
|
|
oar.reason = reason;
|
2013-05-22 03:09:22 +04:00
|
|
|
oar.full_mark = full_mark;
|
|
|
|
oar.immediate_sweep = immediate_sweep;
|
2013-05-21 12:19:07 +04:00
|
|
|
return (int)(VALUE)rb_thread_call_with_gvl(gc_with_gvl, (void *)&oar);
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* no ruby thread */
|
|
|
|
fprintf(stderr, "[FATAL] failed to allocate memory\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-21 09:16:56 +03:00
|
|
|
int
|
|
|
|
rb_garbage_collect(void)
|
|
|
|
{
|
2013-05-22 03:09:22 +04:00
|
|
|
return garbage_collect(&rb_objspace, TRUE, TRUE, GPR_FLAG_CAPI);
|
2007-12-21 09:16:56 +03:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
#undef Init_stack
|
2009-11-01 02:17:52 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
void
|
|
|
|
Init_stack(volatile VALUE *addr)
|
|
|
|
{
|
|
|
|
ruby_init_stack(addr);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2003-12-22 09:20:14 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* GC.start -> nil
|
|
|
|
* gc.garbage_collect -> nil
|
|
|
|
* ObjectSpace.garbage_collect -> nil
|
2003-12-22 09:20:14 +03:00
|
|
|
*
|
|
|
|
* Initiates garbage collection, unless manually disabled.
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
2003-12-22 09:20:14 +03:00
|
|
|
*/
|
|
|
|
|
2001-01-29 08:10:42 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_gc_start(void)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_gc();
|
1998-01-16 15:13:05 +03:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-05 14:39:37 +04:00
|
|
|
rb_gc(void)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
2013-05-22 03:09:22 +04:00
|
|
|
garbage_collect(objspace, TRUE, TRUE, GPR_FLAG_METHOD);
|
2012-08-05 14:39:37 +04:00
|
|
|
if (!finalizing) finalize_deferred(objspace);
|
|
|
|
free_unused_heaps(objspace);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
rb_during_gc(void)
|
|
|
|
{
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
return during_gc;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2013-05-26 20:43:21 +04:00
|
|
|
#if RGENGC_PROFILE >= 2
|
|
|
|
static void
|
2013-05-26 21:27:42 +04:00
|
|
|
gc_count_add_each_types(VALUE hash, const char *name, const size_t *types)
|
2013-05-26 20:43:21 +04:00
|
|
|
{
|
|
|
|
VALUE result = rb_hash_new();
|
|
|
|
int i;
|
|
|
|
for (i=0; i<T_MASK; i++) {
|
|
|
|
const char *type = type_name(i, 0);
|
|
|
|
rb_hash_aset(result, ID2SYM(rb_intern(type)), SIZET2NUM(types[i]));
|
|
|
|
}
|
|
|
|
rb_hash_aset(hash, ID2SYM(rb_intern(name)), result);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-05-27 14:01:45 +04:00
|
|
|
size_t
|
|
|
|
rb_gc_count(void)
|
|
|
|
{
|
|
|
|
return rb_objspace.count;
|
|
|
|
}
|
|
|
|
|
2003-12-22 09:20:14 +03:00
|
|
|
/*
|
2012-08-05 14:39:37 +04:00
|
|
|
* call-seq:
|
|
|
|
* GC.count -> Integer
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
2012-08-05 14:39:37 +04:00
|
|
|
* The number of times GC occurred.
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
2012-08-05 14:39:37 +04:00
|
|
|
* It returns the number of times GC occurred since the process started.
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
2003-12-22 09:20:14 +03:00
|
|
|
*/
|
|
|
|
|
2010-10-21 08:18:09 +04:00
|
|
|
static VALUE
|
2012-08-05 14:39:37 +04:00
|
|
|
gc_count(VALUE self)
|
2010-10-21 08:18:09 +04:00
|
|
|
{
|
2013-05-27 14:01:45 +04:00
|
|
|
return SIZET2NUM(rb_gc_count());
|
2010-10-21 08:18:09 +04:00
|
|
|
}
|
|
|
|
|
2009-06-17 01:07:26 +04:00
|
|
|
/*
|
2012-08-05 14:39:37 +04:00
|
|
|
* call-seq:
|
|
|
|
* GC.stat -> Hash
|
2009-06-17 01:07:26 +04:00
|
|
|
*
|
2012-08-05 14:39:37 +04:00
|
|
|
* Returns a Hash containing information about the GC.
|
2009-06-17 01:07:26 +04:00
|
|
|
*
|
2012-08-05 14:39:37 +04:00
|
|
|
* The hash includes information about internal statistics about GC such as:
|
2009-06-17 01:07:26 +04:00
|
|
|
*
|
2012-11-29 12:15:53 +04:00
|
|
|
* {
|
|
|
|
* :count=>0,
|
|
|
|
* :heap_used=>12,
|
|
|
|
* :heap_length=>12,
|
|
|
|
* :heap_increment=>0,
|
|
|
|
* :heap_live_num=>7539,
|
|
|
|
* :heap_free_num=>88,
|
|
|
|
* :heap_final_num=>0,
|
|
|
|
* :total_allocated_object=>7630,
|
|
|
|
* :total_freed_object=>88
|
|
|
|
* }
|
2009-06-17 01:07:26 +04:00
|
|
|
*
|
2012-11-29 12:15:53 +04:00
|
|
|
* The contents of the hash are implementation specific and may be changed in
|
2012-08-05 14:39:37 +04:00
|
|
|
* the future.
|
2009-06-17 01:07:26 +04:00
|
|
|
*
|
2012-08-05 14:39:37 +04:00
|
|
|
* This method is only expected to work on C Ruby.
|
2009-06-17 01:07:26 +04:00
|
|
|
*
|
|
|
|
*/
|
2012-08-05 14:39:37 +04:00
|
|
|
|
|
|
|
static VALUE
|
|
|
|
gc_stat(int argc, VALUE *argv, VALUE self)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2009-06-17 01:07:26 +04:00
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
2012-08-05 14:39:37 +04:00
|
|
|
VALUE hash;
|
2012-11-29 09:29:22 +04:00
|
|
|
static VALUE sym_count;
|
|
|
|
static VALUE sym_heap_used, sym_heap_length, sym_heap_increment;
|
|
|
|
static VALUE sym_heap_live_num, sym_heap_free_num, sym_heap_final_num;
|
|
|
|
static VALUE sym_total_allocated_object, sym_total_freed_object;
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#if USE_RGENGC
|
|
|
|
static VALUE sym_minor_gc_count, sym_major_gc_count;
|
|
|
|
#if RGENGC_PROFILE
|
2013-06-07 05:17:19 +04:00
|
|
|
static VALUE sym_generated_normal_object_count, sym_generated_shady_object_count;
|
2013-05-26 21:27:42 +04:00
|
|
|
static VALUE sym_shade_operation_count, sym_promote_operation_count;
|
2013-06-07 05:17:19 +04:00
|
|
|
static VALUE sym_remembered_normal_object_count, sym_remembered_shady_object_count;
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#endif /* RGENGC_PROFILE */
|
|
|
|
#endif /* USE_RGENGC */
|
|
|
|
|
2012-11-29 09:29:22 +04:00
|
|
|
if (sym_count == 0) {
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#define S(s) sym_##s = ID2SYM(rb_intern_const(#s))
|
|
|
|
S(count);
|
|
|
|
S(heap_used);
|
|
|
|
S(heap_length);
|
|
|
|
S(heap_increment);
|
|
|
|
S(heap_live_num);
|
|
|
|
S(heap_free_num);
|
|
|
|
S(heap_final_num);
|
|
|
|
S(total_allocated_object);
|
|
|
|
S(total_freed_object);
|
|
|
|
#if USE_RGENGC
|
|
|
|
S(minor_gc_count);
|
|
|
|
S(major_gc_count);
|
|
|
|
#if RGENGC_PROFILE
|
2013-06-07 05:17:19 +04:00
|
|
|
S(generated_normal_object_count);
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
S(generated_shady_object_count);
|
|
|
|
S(shade_operation_count);
|
2013-05-26 21:27:42 +04:00
|
|
|
S(promote_operation_count);
|
2013-06-07 05:17:19 +04:00
|
|
|
S(remembered_normal_object_count);
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
S(remembered_shady_object_count);
|
|
|
|
#endif /* USE_RGENGC */
|
|
|
|
#endif /* RGENGC_PROFILE */
|
|
|
|
#undef S
|
2012-11-29 09:29:22 +04:00
|
|
|
}
|
2008-06-05 17:52:02 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if (rb_scan_args(argc, argv, "01", &hash) == 1) {
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
if (!RB_TYPE_P(hash, T_HASH)) {
|
|
|
|
rb_raise(rb_eTypeError, "non-hash given");
|
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
}
|
2009-06-17 01:07:26 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if (hash == Qnil) {
|
|
|
|
hash = rb_hash_new();
|
2009-06-17 01:15:15 +04:00
|
|
|
}
|
2009-06-17 01:07:26 +04:00
|
|
|
|
2012-11-29 09:29:22 +04:00
|
|
|
rb_hash_aset(hash, sym_count, SIZET2NUM(objspace->count));
|
2012-08-05 14:39:37 +04:00
|
|
|
/* implementation dependent counters */
|
2012-11-29 09:29:22 +04:00
|
|
|
rb_hash_aset(hash, sym_heap_used, SIZET2NUM(objspace->heap.used));
|
|
|
|
rb_hash_aset(hash, sym_heap_length, SIZET2NUM(objspace->heap.length));
|
|
|
|
rb_hash_aset(hash, sym_heap_increment, SIZET2NUM(objspace->heap.increment));
|
|
|
|
rb_hash_aset(hash, sym_heap_live_num, SIZET2NUM(objspace_live_num(objspace)));
|
|
|
|
rb_hash_aset(hash, sym_heap_free_num, SIZET2NUM(objspace->heap.free_num));
|
|
|
|
rb_hash_aset(hash, sym_heap_final_num, SIZET2NUM(objspace->heap.final_num));
|
|
|
|
rb_hash_aset(hash, sym_total_allocated_object, SIZET2NUM(objspace->total_allocated_object_num));
|
|
|
|
rb_hash_aset(hash, sym_total_freed_object, SIZET2NUM(objspace->total_freed_object_num));
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#if USE_RGENGC
|
|
|
|
rb_hash_aset(hash, sym_minor_gc_count, SIZET2NUM(objspace->profile.minor_gc_count));
|
|
|
|
rb_hash_aset(hash, sym_major_gc_count, SIZET2NUM(objspace->profile.major_gc_count));
|
|
|
|
#if RGENGC_PROFILE
|
2013-06-07 05:17:19 +04:00
|
|
|
rb_hash_aset(hash, sym_generated_normal_object_count, SIZET2NUM(objspace->profile.generated_normal_object_count));
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
rb_hash_aset(hash, sym_generated_shady_object_count, SIZET2NUM(objspace->profile.generated_shady_object_count));
|
|
|
|
rb_hash_aset(hash, sym_shade_operation_count, SIZET2NUM(objspace->profile.shade_operation_count));
|
2013-05-26 21:27:42 +04:00
|
|
|
rb_hash_aset(hash, sym_promote_operation_count, SIZET2NUM(objspace->profile.promote_operation_count));
|
2013-06-07 05:17:19 +04:00
|
|
|
rb_hash_aset(hash, sym_remembered_normal_object_count, SIZET2NUM(objspace->profile.remembered_normal_object_count));
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
rb_hash_aset(hash, sym_remembered_shady_object_count, SIZET2NUM(objspace->profile.remembered_shady_object_count));
|
2013-05-15 12:07:30 +04:00
|
|
|
#if RGENGC_PROFILE >= 2
|
|
|
|
{
|
2013-06-18 06:27:37 +04:00
|
|
|
gc_count_add_each_types(hash, "generated_normal_object_count_types", objspace->profile.generated_normal_object_count_types);
|
2013-05-26 20:43:21 +04:00
|
|
|
gc_count_add_each_types(hash, "generated_shady_object_count_types", objspace->profile.generated_shady_object_count_types);
|
|
|
|
gc_count_add_each_types(hash, "shade_operation_count_types", objspace->profile.shade_operation_count_types);
|
2013-05-26 21:27:42 +04:00
|
|
|
gc_count_add_each_types(hash, "promote_operation_count_types", objspace->profile.promote_operation_count_types);
|
2013-06-07 05:17:19 +04:00
|
|
|
gc_count_add_each_types(hash, "remembered_normal_object_count_types", objspace->profile.remembered_normal_object_count_types);
|
2013-05-26 20:43:21 +04:00
|
|
|
gc_count_add_each_types(hash, "remembered_shady_object_count_types", objspace->profile.remembered_shady_object_count_types);
|
2013-05-15 12:07:30 +04:00
|
|
|
}
|
|
|
|
#endif
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
#endif /* RGENGC_PROFILE */
|
|
|
|
#endif /* USE_RGENGC */
|
2012-11-29 09:29:22 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
return hash;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-22 09:20:14 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2013-06-19 15:53:07 +04:00
|
|
|
* GC.stress -> fixnum, true or false
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
2012-11-29 12:15:53 +04:00
|
|
|
* Returns current status of GC stress mode.
|
2003-12-22 09:20:14 +03:00
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
2012-08-05 14:39:37 +04:00
|
|
|
gc_stress_get(VALUE self)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
2013-06-19 15:53:07 +04:00
|
|
|
return ruby_gc_stress;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-22 09:20:14 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2012-08-05 14:39:37 +04:00
|
|
|
* GC.stress = bool -> bool
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
2012-08-05 14:39:37 +04:00
|
|
|
* Updates the GC stress mode.
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
2012-11-29 12:15:53 +04:00
|
|
|
* When stress mode is enabled, the GC is invoked at every GC opportunity:
|
2012-08-05 14:39:37 +04:00
|
|
|
* all memory and object allocations.
|
|
|
|
*
|
2012-11-29 12:15:53 +04:00
|
|
|
* Enabling stress mode will degrade performance, it is only for debugging.
|
2003-12-22 09:20:14 +03:00
|
|
|
*/
|
|
|
|
|
2000-07-15 17:37:03 +04:00
|
|
|
static VALUE
|
2012-08-05 14:39:37 +04:00
|
|
|
gc_stress_set(VALUE self, VALUE flag)
|
2012-03-13 07:37:06 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
rb_secure(2);
|
2013-06-19 01:35:40 +04:00
|
|
|
ruby_gc_stress = FIXNUM_P(flag) ? flag : (RTEST(flag) ? Qtrue : Qfalse);
|
2012-08-05 14:39:37 +04:00
|
|
|
return flag;
|
2012-03-13 07:37:06 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* GC.enable -> true or false
|
|
|
|
*
|
2012-11-29 12:15:53 +04:00
|
|
|
* Enables garbage collection, returning +true+ if garbage
|
2012-08-05 14:39:37 +04:00
|
|
|
* collection was previously disabled.
|
|
|
|
*
|
|
|
|
* GC.disable #=> false
|
|
|
|
* GC.enable #=> true
|
|
|
|
* GC.enable #=> false
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-03-13 07:37:06 +04:00
|
|
|
VALUE
|
2012-08-05 14:39:37 +04:00
|
|
|
rb_gc_enable(void)
|
2000-07-15 17:37:03 +04:00
|
|
|
{
|
2008-04-27 07:20:35 +04:00
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
2012-08-05 14:39:37 +04:00
|
|
|
int old = dont_gc;
|
|
|
|
|
|
|
|
dont_gc = FALSE;
|
|
|
|
return old ? Qtrue : Qfalse;
|
2000-07-15 17:37:03 +04:00
|
|
|
}
|
|
|
|
|
2003-12-22 09:20:14 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2012-08-05 14:39:37 +04:00
|
|
|
* GC.disable -> true or false
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
2012-11-29 12:15:53 +04:00
|
|
|
* Disables garbage collection, returning +true+ if garbage
|
2012-08-05 14:39:37 +04:00
|
|
|
* collection was already disabled.
|
|
|
|
*
|
|
|
|
* GC.disable #=> false
|
|
|
|
* GC.disable #=> true
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
2003-12-22 09:20:14 +03:00
|
|
|
*/
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
VALUE
|
|
|
|
rb_gc_disable(void)
|
2000-07-15 17:37:03 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
int old = dont_gc;
|
2000-07-15 17:37:03 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
dont_gc = TRUE;
|
|
|
|
return old ? Qtrue : Qfalse;
|
2012-03-13 07:37:06 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
void
|
|
|
|
rb_gc_set_params(void)
|
2012-03-13 07:37:06 +04:00
|
|
|
{
|
2013-03-13 18:52:00 +04:00
|
|
|
char *malloc_limit_ptr, *heap_min_slots_ptr, *free_min_ptr, *growth_factor_ptr;
|
2000-07-15 17:37:03 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if (rb_safe_level() > 0) return;
|
2004-06-29 05:31:37 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
malloc_limit_ptr = getenv("RUBY_GC_MALLOC_LIMIT");
|
|
|
|
if (malloc_limit_ptr != NULL) {
|
|
|
|
int malloc_limit_i = atoi(malloc_limit_ptr);
|
|
|
|
if (RTEST(ruby_verbose))
|
|
|
|
fprintf(stderr, "malloc_limit=%d (%d)\n",
|
|
|
|
malloc_limit_i, initial_malloc_limit);
|
|
|
|
if (malloc_limit_i > 0) {
|
|
|
|
initial_malloc_limit = malloc_limit_i;
|
|
|
|
}
|
2000-07-15 17:37:03 +04:00
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
|
|
|
|
heap_min_slots_ptr = getenv("RUBY_HEAP_MIN_SLOTS");
|
|
|
|
if (heap_min_slots_ptr != NULL) {
|
|
|
|
int heap_min_slots_i = atoi(heap_min_slots_ptr);
|
|
|
|
if (RTEST(ruby_verbose))
|
|
|
|
fprintf(stderr, "heap_min_slots=%d (%d)\n",
|
|
|
|
heap_min_slots_i, initial_heap_min_slots);
|
|
|
|
if (heap_min_slots_i > 0) {
|
|
|
|
initial_heap_min_slots = heap_min_slots_i;
|
|
|
|
initial_expand_heap(&rb_objspace);
|
|
|
|
}
|
2000-07-15 17:37:03 +04:00
|
|
|
}
|
|
|
|
|
2013-03-13 18:52:00 +04:00
|
|
|
growth_factor_ptr = getenv("RUBY_HEAP_SLOTS_GROWTH_FACTOR");
|
|
|
|
if (growth_factor_ptr != NULL) {
|
|
|
|
double growth_factor_f = strtod(growth_factor_ptr, NULL);
|
|
|
|
if (RTEST(ruby_verbose))
|
|
|
|
fprintf(stderr, "heap_slots_growth_factor=%f (%f)\n",
|
|
|
|
growth_factor_f, initial_growth_factor);
|
|
|
|
if (growth_factor_f > 1) {
|
|
|
|
initial_growth_factor = growth_factor_f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
free_min_ptr = getenv("RUBY_FREE_MIN");
|
|
|
|
if (free_min_ptr != NULL) {
|
|
|
|
int free_min_i = atoi(free_min_ptr);
|
|
|
|
if (RTEST(ruby_verbose))
|
|
|
|
fprintf(stderr, "free_min=%d (%d)\n", free_min_i, initial_free_min);
|
|
|
|
if (free_min_i > 0) {
|
|
|
|
initial_free_min = free_min_i;
|
|
|
|
}
|
2012-03-13 07:37:06 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-24 04:04:56 +04:00
|
|
|
void
|
|
|
|
rb_objspace_reachable_objects_from(VALUE obj, void (func)(VALUE, void *), void *data)
|
2012-10-05 12:14:09 +04:00
|
|
|
{
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
|
|
|
|
if (markable_object_p(objspace, obj)) {
|
|
|
|
struct mark_func_data_struct mfd;
|
2012-10-24 04:04:56 +04:00
|
|
|
mfd.mark_func = func;
|
|
|
|
mfd.data = data;
|
2012-10-05 12:14:09 +04:00
|
|
|
objspace->mark_func_data = &mfd;
|
|
|
|
gc_mark_children(objspace, obj);
|
|
|
|
objspace->mark_func_data = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
/*
|
|
|
|
------------------------ Extended allocator ------------------------
|
|
|
|
*/
|
2002-12-04 10:39:32 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static void vm_xfree(rb_objspace_t *objspace, void *ptr);
|
2002-12-04 10:39:32 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static void *
|
|
|
|
negative_size_allocation_error_with_gvl(void *ptr)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
rb_raise(rb_eNoMemError, "%s", (const char *)ptr);
|
|
|
|
return 0; /* should not be reached */
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static void
|
2012-08-05 14:39:37 +04:00
|
|
|
negative_size_allocation_error(const char *msg)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
if (ruby_thread_has_gvl_p()) {
|
|
|
|
rb_raise(rb_eNoMemError, "%s", msg);
|
2010-02-16 15:34:09 +03:00
|
|
|
}
|
2010-11-04 14:46:26 +03:00
|
|
|
else {
|
2012-08-05 14:39:37 +04:00
|
|
|
if (ruby_native_thread_p()) {
|
|
|
|
rb_thread_call_with_gvl(negative_size_allocation_error_with_gvl, (void *)msg);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "[FATAL] %s\n", msg);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2010-02-16 15:34:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static void *
|
|
|
|
ruby_memerror_body(void *dummy)
|
2010-02-16 15:34:09 +03:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
rb_memerror();
|
|
|
|
return 0;
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
|
2008-04-27 07:20:35 +04:00
|
|
|
static void
|
2012-08-05 14:39:37 +04:00
|
|
|
ruby_memerror(void)
|
2008-06-30 13:57:07 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
if (ruby_thread_has_gvl_p()) {
|
|
|
|
rb_memerror();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (ruby_native_thread_p()) {
|
|
|
|
rb_thread_call_with_gvl(ruby_memerror_body, 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* no ruby thread */
|
|
|
|
fprintf(stderr, "[FATAL] failed to allocate memory\n");
|
|
|
|
exit(EXIT_FAILURE);
|
2008-07-27 09:59:32 +04:00
|
|
|
}
|
2008-06-30 13:57:07 +04:00
|
|
|
}
|
2010-02-16 15:34:09 +03:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
void
|
|
|
|
rb_memerror(void)
|
2010-02-16 15:34:09 +03:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
rb_thread_t *th = GET_THREAD();
|
|
|
|
if (!nomem_error ||
|
|
|
|
(rb_thread_raised_p(th, RAISED_NOMEMORY) && rb_safe_level() < 4)) {
|
|
|
|
fprintf(stderr, "[FATAL] failed to allocate memory\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
if (rb_thread_raised_p(th, RAISED_NOMEMORY)) {
|
|
|
|
rb_thread_raised_clear(th);
|
|
|
|
GET_THREAD()->errinfo = nomem_error;
|
|
|
|
JUMP_TAG(TAG_RAISE);
|
|
|
|
}
|
|
|
|
rb_thread_raised_set(th, RAISED_NOMEMORY);
|
|
|
|
rb_exc_raise(nomem_error);
|
2008-06-30 13:57:07 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static void *
|
|
|
|
aligned_malloc(size_t alignment, size_t size)
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
void *res;
|
|
|
|
|
|
|
|
#if defined __MINGW32__
|
|
|
|
res = __mingw_aligned_malloc(size, alignment);
|
|
|
|
#elif defined _WIN32 && !defined __CYGWIN__
|
2013-03-31 01:08:30 +04:00
|
|
|
void *_aligned_malloc(size_t, size_t);
|
2012-08-05 14:39:37 +04:00
|
|
|
res = _aligned_malloc(size, alignment);
|
|
|
|
#elif defined(HAVE_POSIX_MEMALIGN)
|
|
|
|
if (posix_memalign(&res, alignment, size) == 0) {
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#elif defined(HAVE_MEMALIGN)
|
|
|
|
res = memalign(alignment, size);
|
|
|
|
#else
|
|
|
|
char* aligned;
|
|
|
|
res = malloc(alignment + size + sizeof(void*));
|
|
|
|
aligned = (char*)res + alignment + sizeof(void*);
|
|
|
|
aligned -= ((VALUE)aligned & (alignment - 1));
|
|
|
|
((void**)aligned)[-1] = res;
|
|
|
|
res = (void*)aligned;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(_DEBUG) || defined(GC_DEBUG)
|
|
|
|
/* alignment must be a power of 2 */
|
|
|
|
assert((alignment - 1) & alignment == 0);
|
|
|
|
assert(alignment % sizeof(void*) == 0);
|
|
|
|
#endif
|
|
|
|
return res;
|
2009-09-18 11:29:17 +04:00
|
|
|
}
|
|
|
|
|
2010-10-31 18:41:14 +03:00
|
|
|
static void
|
2012-08-05 14:39:37 +04:00
|
|
|
aligned_free(void *ptr)
|
2009-09-18 11:29:17 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
#if defined __MINGW32__
|
|
|
|
__mingw_aligned_free(ptr);
|
|
|
|
#elif defined _WIN32 && !defined __CYGWIN__
|
|
|
|
_aligned_free(ptr);
|
|
|
|
#elif defined(HAVE_MEMALIGN) || defined(HAVE_POSIX_MEMALIGN)
|
|
|
|
free(ptr);
|
|
|
|
#else
|
|
|
|
free(((void**)ptr)[-1]);
|
|
|
|
#endif
|
|
|
|
}
|
2011-09-29 20:54:14 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static inline size_t
|
|
|
|
vm_malloc_prepare(rb_objspace_t *objspace, size_t size)
|
|
|
|
{
|
|
|
|
if ((ssize_t)size < 0) {
|
|
|
|
negative_size_allocation_error("negative allocation size (or too big)");
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
if (size == 0) size = 1;
|
2010-10-31 18:41:14 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
#if CALC_EXACT_MALLOC_SIZE
|
|
|
|
size += sizeof(size_t);
|
|
|
|
#endif
|
2010-10-31 18:41:14 +03:00
|
|
|
|
2013-06-16 00:53:01 +04:00
|
|
|
ATOMIC_SIZE_ADD(malloc_increase, size);
|
2012-08-05 14:39:37 +04:00
|
|
|
if ((ruby_gc_stress && !ruby_disable_gc_stress) ||
|
2013-06-16 00:53:01 +04:00
|
|
|
malloc_increase > malloc_limit) {
|
2013-05-22 03:09:22 +04:00
|
|
|
garbage_collect_with_gvl(objspace, 0, 0, GPR_FLAG_MALLOC);
|
2008-10-01 16:36:38 +04:00
|
|
|
}
|
2010-10-31 18:41:14 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
return size;
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static inline void *
|
|
|
|
vm_malloc_fixup(rb_objspace_t *objspace, void *mem, size_t size)
|
2008-04-27 07:20:35 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
#if CALC_EXACT_MALLOC_SIZE
|
|
|
|
ATOMIC_SIZE_ADD(objspace->malloc_params.allocated_size, size);
|
|
|
|
ATOMIC_SIZE_INC(objspace->malloc_params.allocations);
|
|
|
|
((size_t *)mem)[0] = size;
|
|
|
|
mem = (size_t *)mem + 1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return mem;
|
2011-09-29 15:10:46 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
#define TRY_WITH_GC(alloc) do { \
|
|
|
|
if (!(alloc) && \
|
2013-05-22 03:09:22 +04:00
|
|
|
(!garbage_collect_with_gvl(objspace, 1, 1, GPR_FLAG_MALLOC) || /* full mark && immediate sweep */ \
|
2012-08-05 14:39:37 +04:00
|
|
|
!(alloc))) { \
|
|
|
|
ruby_memerror(); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
static void *
|
|
|
|
vm_xmalloc(rb_objspace_t *objspace, size_t size)
|
2011-09-08 04:02:55 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
void *mem;
|
|
|
|
|
|
|
|
size = vm_malloc_prepare(objspace, size);
|
|
|
|
TRY_WITH_GC(mem = malloc(size));
|
|
|
|
return vm_malloc_fixup(objspace, mem, size);
|
2011-09-08 04:02:55 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static void *
|
|
|
|
vm_xrealloc(rb_objspace_t *objspace, void *ptr, size_t size)
|
2011-09-29 15:10:46 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
void *mem;
|
|
|
|
#if CALC_EXACT_MALLOC_SIZE
|
|
|
|
size_t oldsize;
|
|
|
|
#endif
|
2011-09-29 15:10:46 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if ((ssize_t)size < 0) {
|
|
|
|
negative_size_allocation_error("negative re-allocation size");
|
|
|
|
}
|
2013-01-05 00:05:42 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
if (!ptr) return vm_xmalloc(objspace, size);
|
2013-01-05 00:05:42 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The behavior of realloc(ptr, 0) is implementation defined.
|
|
|
|
* Therefore we don't use realloc(ptr, 0) for portability reason.
|
|
|
|
* see http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_400.htm
|
|
|
|
*/
|
2012-08-05 14:39:37 +04:00
|
|
|
if (size == 0) {
|
|
|
|
vm_xfree(objspace, ptr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (ruby_gc_stress && !ruby_disable_gc_stress)
|
2013-05-22 03:09:22 +04:00
|
|
|
garbage_collect_with_gvl(objspace, 0, 0, GPR_FLAG_MALLOC);
|
2003-12-22 09:20:14 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
#if CALC_EXACT_MALLOC_SIZE
|
|
|
|
size += sizeof(size_t);
|
|
|
|
ptr = (size_t *)ptr - 1;
|
|
|
|
oldsize = ((size_t *)ptr)[0];
|
2005-07-27 11:27:19 +04:00
|
|
|
#endif
|
1998-01-16 15:19:22 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
mem = realloc(ptr, size);
|
|
|
|
if (!mem) {
|
2013-05-22 03:09:22 +04:00
|
|
|
if (garbage_collect_with_gvl(objspace, 1, 1, GPR_FLAG_MALLOC)) {
|
2012-08-05 14:39:37 +04:00
|
|
|
mem = realloc(ptr, size);
|
|
|
|
}
|
|
|
|
if (!mem) {
|
|
|
|
ruby_memerror();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ATOMIC_SIZE_ADD(malloc_increase, size);
|
2005-07-27 11:27:19 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
#if CALC_EXACT_MALLOC_SIZE
|
|
|
|
ATOMIC_SIZE_ADD(objspace->malloc_params.allocated_size, size - oldsize);
|
|
|
|
((size_t *)mem)[0] = size;
|
|
|
|
mem = (size_t *)mem + 1;
|
|
|
|
#endif
|
2006-03-02 08:22:30 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
return mem;
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static void
|
|
|
|
vm_xfree(rb_objspace_t *objspace, void *ptr)
|
|
|
|
{
|
|
|
|
#if CALC_EXACT_MALLOC_SIZE
|
|
|
|
size_t size;
|
|
|
|
ptr = ((size_t *)ptr) - 1;
|
|
|
|
size = ((size_t*)ptr)[0];
|
|
|
|
if (size) {
|
|
|
|
ATOMIC_SIZE_SUB(objspace->malloc_params.allocated_size, size);
|
|
|
|
ATOMIC_SIZE_DEC(objspace->malloc_params.allocations);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
free(ptr);
|
|
|
|
}
|
2006-03-02 08:22:30 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
void *
|
|
|
|
ruby_xmalloc(size_t size)
|
|
|
|
{
|
|
|
|
return vm_xmalloc(&rb_objspace, size);
|
|
|
|
}
|
2006-03-02 08:22:30 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static inline size_t
|
|
|
|
xmalloc2_size(size_t n, size_t size)
|
2006-03-02 08:22:30 +03:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
size_t len = size * n;
|
|
|
|
if (n != 0 && size != len / n) {
|
|
|
|
rb_raise(rb_eArgError, "malloc: possible integer overflow");
|
2006-03-02 08:22:30 +03:00
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
return len;
|
2006-03-02 08:22:30 +03:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
void *
|
|
|
|
ruby_xmalloc2(size_t n, size_t size)
|
2008-05-31 18:03:23 +04:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
return vm_xmalloc(&rb_objspace, xmalloc2_size(n, size));
|
2008-05-31 18:03:23 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static void *
|
|
|
|
vm_xcalloc(rb_objspace_t *objspace, size_t count, size_t elsize)
|
2007-11-03 18:09:10 +03:00
|
|
|
{
|
2012-08-05 14:39:37 +04:00
|
|
|
void *mem;
|
|
|
|
size_t size;
|
2007-11-03 18:09:10 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
size = xmalloc2_size(count, elsize);
|
|
|
|
size = vm_malloc_prepare(objspace, size);
|
2007-11-03 18:09:10 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
TRY_WITH_GC(mem = calloc(1, size));
|
|
|
|
return vm_malloc_fixup(objspace, mem, size);
|
|
|
|
}
|
2007-11-03 18:09:10 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
void *
|
|
|
|
ruby_xcalloc(size_t n, size_t size)
|
|
|
|
{
|
|
|
|
return vm_xcalloc(&rb_objspace, n, size);
|
|
|
|
}
|
2007-11-03 18:09:10 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
void *
|
|
|
|
ruby_xrealloc(void *ptr, size_t size)
|
|
|
|
{
|
|
|
|
return vm_xrealloc(&rb_objspace, ptr, size);
|
|
|
|
}
|
2008-08-11 13:36:57 +04:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
void *
|
|
|
|
ruby_xrealloc2(void *ptr, size_t n, size_t size)
|
|
|
|
{
|
|
|
|
size_t len = size * n;
|
|
|
|
if (n != 0 && size != len / n) {
|
|
|
|
rb_raise(rb_eArgError, "realloc: possible integer overflow");
|
2007-11-03 18:09:10 +03:00
|
|
|
}
|
2012-08-05 14:39:37 +04:00
|
|
|
return ruby_xrealloc(ptr, len);
|
|
|
|
}
|
2007-11-03 18:09:10 +03:00
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
void
|
|
|
|
ruby_xfree(void *x)
|
|
|
|
{
|
|
|
|
if (x)
|
|
|
|
vm_xfree(&rb_objspace, x);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Mimic ruby_xmalloc, but need not rb_objspace.
|
|
|
|
* should return pointer suitable for ruby_xfree
|
|
|
|
*/
|
|
|
|
void *
|
|
|
|
ruby_mimmalloc(size_t size)
|
|
|
|
{
|
|
|
|
void *mem;
|
|
|
|
#if CALC_EXACT_MALLOC_SIZE
|
|
|
|
size += sizeof(size_t);
|
|
|
|
#endif
|
|
|
|
mem = malloc(size);
|
|
|
|
#if CALC_EXACT_MALLOC_SIZE
|
|
|
|
/* set 0 for consistency of allocated_size/allocations */
|
|
|
|
((size_t *)mem)[0] = 0;
|
|
|
|
mem = (size_t *)mem + 1;
|
|
|
|
#endif
|
|
|
|
return mem;
|
2007-11-03 18:09:10 +03:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
#if CALC_EXACT_MALLOC_SIZE
|
2012-03-13 07:37:06 +04:00
|
|
|
/*
|
2012-08-05 14:39:37 +04:00
|
|
|
* call-seq:
|
|
|
|
* GC.malloc_allocated_size -> Integer
|
2012-03-13 07:37:06 +04:00
|
|
|
*
|
2012-11-29 12:15:53 +04:00
|
|
|
* Returns the size of memory allocated by malloc().
|
|
|
|
*
|
|
|
|
* Only available if ruby was built with +CALC_EXACT_MALLOC_SIZE+.
|
2012-08-05 14:39:37 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
gc_malloc_allocated_size(VALUE self)
|
|
|
|
{
|
|
|
|
return UINT2NUM(rb_objspace.malloc_params.allocated_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* GC.malloc_allocations -> Integer
|
|
|
|
*
|
2012-11-29 12:15:53 +04:00
|
|
|
* Returns the number of malloc() allocations.
|
|
|
|
*
|
|
|
|
* Only available if ruby was built with +CALC_EXACT_MALLOC_SIZE+.
|
2012-03-13 07:37:06 +04:00
|
|
|
*/
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
static VALUE
|
|
|
|
gc_malloc_allocations(VALUE self)
|
|
|
|
{
|
|
|
|
return UINT2NUM(rb_objspace.malloc_params.allocations);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
------------------------------ WeakMap ------------------------------
|
|
|
|
*/
|
|
|
|
|
2012-03-13 07:37:06 +04:00
|
|
|
struct weakmap {
|
|
|
|
st_table *obj2wmap; /* obj -> [ref,...] */
|
|
|
|
st_table *wmap2obj; /* ref -> obj */
|
|
|
|
VALUE final;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
wmap_mark_map(st_data_t key, st_data_t val, st_data_t arg)
|
|
|
|
{
|
|
|
|
gc_mark_ptr((rb_objspace_t *)arg, (VALUE)val);
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
wmap_mark(void *ptr)
|
|
|
|
{
|
|
|
|
struct weakmap *w = ptr;
|
2013-06-10 11:12:14 +04:00
|
|
|
if (w->obj2wmap) st_foreach(w->obj2wmap, wmap_mark_map, (st_data_t)&rb_objspace);
|
2012-03-13 07:37:06 +04:00
|
|
|
rb_gc_mark(w->final);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
wmap_free_map(st_data_t key, st_data_t val, st_data_t arg)
|
|
|
|
{
|
|
|
|
rb_ary_resize((VALUE)val, 0);
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
wmap_free(void *ptr)
|
|
|
|
{
|
|
|
|
struct weakmap *w = ptr;
|
|
|
|
st_foreach(w->obj2wmap, wmap_free_map, 0);
|
|
|
|
st_free_table(w->obj2wmap);
|
|
|
|
st_free_table(w->wmap2obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t rb_ary_memsize(VALUE ary);
|
|
|
|
static int
|
|
|
|
wmap_memsize_map(st_data_t key, st_data_t val, st_data_t arg)
|
|
|
|
{
|
|
|
|
*(size_t *)arg += rb_ary_memsize((VALUE)val);
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
wmap_memsize(const void *ptr)
|
|
|
|
{
|
|
|
|
size_t size;
|
|
|
|
const struct weakmap *w = ptr;
|
|
|
|
if (!w) return 0;
|
|
|
|
size = sizeof(*w);
|
|
|
|
size += st_memsize(w->obj2wmap);
|
|
|
|
size += st_memsize(w->wmap2obj);
|
|
|
|
st_foreach(w->obj2wmap, wmap_memsize_map, (st_data_t)&size);
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const rb_data_type_t weakmap_type = {
|
|
|
|
"weakmap",
|
|
|
|
{
|
|
|
|
wmap_mark,
|
|
|
|
wmap_free,
|
|
|
|
wmap_memsize,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
wmap_allocate(VALUE klass)
|
|
|
|
{
|
|
|
|
struct weakmap *w;
|
|
|
|
VALUE obj = TypedData_Make_Struct(klass, struct weakmap, &weakmap_type, w);
|
|
|
|
w->obj2wmap = st_init_numtable();
|
|
|
|
w->wmap2obj = st_init_numtable();
|
|
|
|
w->final = rb_obj_method(obj, ID2SYM(rb_intern("finalize")));
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-03-29 18:50:20 +04:00
|
|
|
wmap_final_func(st_data_t *key, st_data_t *value, st_data_t arg, int existing)
|
2012-03-13 07:37:06 +04:00
|
|
|
{
|
2012-11-24 16:26:57 +04:00
|
|
|
VALUE wmap, ary;
|
2012-03-29 11:36:12 +04:00
|
|
|
if (!existing) return ST_STOP;
|
2012-11-24 16:26:57 +04:00
|
|
|
wmap = (VALUE)arg, ary = (VALUE)*value;
|
2012-11-25 17:39:26 +04:00
|
|
|
rb_ary_delete_same(ary, wmap);
|
2012-03-13 07:37:06 +04:00
|
|
|
if (!RARRAY_LEN(ary)) return ST_DELETE;
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2012-11-24 16:26:57 +04:00
|
|
|
wmap_finalize(VALUE self, VALUE objid)
|
2012-03-13 07:37:06 +04:00
|
|
|
{
|
2012-11-24 16:26:57 +04:00
|
|
|
st_data_t orig, wmap, data;
|
|
|
|
VALUE obj, rids;
|
2012-03-13 07:37:06 +04:00
|
|
|
long i;
|
|
|
|
struct weakmap *w;
|
|
|
|
|
|
|
|
TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w);
|
2012-11-24 16:26:54 +04:00
|
|
|
/* Get reference from object id. */
|
2012-12-22 08:25:18 +04:00
|
|
|
obj = obj_id_to_ref(objid);
|
2012-03-13 07:37:06 +04:00
|
|
|
|
2012-11-24 16:26:54 +04:00
|
|
|
/* obj is original referenced object and/or weak reference. */
|
2012-11-24 16:26:57 +04:00
|
|
|
orig = (st_data_t)obj;
|
|
|
|
if (st_delete(w->obj2wmap, &orig, &data)) {
|
2012-03-13 07:37:06 +04:00
|
|
|
rids = (VALUE)data;
|
|
|
|
for (i = 0; i < RARRAY_LEN(rids); ++i) {
|
2013-05-13 13:56:22 +04:00
|
|
|
wmap = (st_data_t)RARRAY_AREF(rids, i);
|
2012-11-24 16:26:57 +04:00
|
|
|
st_delete(w->wmap2obj, &wmap, NULL);
|
2012-03-13 07:37:06 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-24 16:26:57 +04:00
|
|
|
wmap = (st_data_t)obj;
|
|
|
|
if (st_delete(w->wmap2obj, &wmap, &orig)) {
|
|
|
|
wmap = (st_data_t)obj;
|
|
|
|
st_update(w->obj2wmap, orig, wmap_final_func, wmap);
|
2012-03-13 07:37:06 +04:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2012-11-29 12:15:53 +04:00
|
|
|
/* Creates a weak reference from the given key to the given value */
|
2012-03-13 07:37:06 +04:00
|
|
|
static VALUE
|
|
|
|
wmap_aset(VALUE self, VALUE wmap, VALUE orig)
|
|
|
|
{
|
|
|
|
st_data_t data;
|
|
|
|
VALUE rids;
|
|
|
|
struct weakmap *w;
|
|
|
|
|
|
|
|
TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w);
|
|
|
|
rb_define_final(orig, w->final);
|
|
|
|
rb_define_final(wmap, w->final);
|
|
|
|
if (st_lookup(w->obj2wmap, (st_data_t)orig, &data)) {
|
|
|
|
rids = (VALUE)data;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rids = rb_ary_tmp_new(1);
|
|
|
|
st_insert(w->obj2wmap, (st_data_t)orig, (st_data_t)rids);
|
|
|
|
}
|
2012-11-24 16:26:54 +04:00
|
|
|
rb_ary_push(rids, wmap);
|
2012-03-13 07:37:06 +04:00
|
|
|
st_insert(w->wmap2obj, (st_data_t)wmap, (st_data_t)orig);
|
|
|
|
return nonspecial_obj_id(orig);
|
|
|
|
}
|
|
|
|
|
2012-11-29 12:15:53 +04:00
|
|
|
/* Retrieves a weakly referenced object with the given key */
|
2012-03-13 07:37:06 +04:00
|
|
|
static VALUE
|
|
|
|
wmap_aref(VALUE self, VALUE wmap)
|
|
|
|
{
|
|
|
|
st_data_t data;
|
|
|
|
VALUE obj;
|
|
|
|
struct weakmap *w;
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
|
|
|
|
TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w);
|
|
|
|
if (!st_lookup(w->wmap2obj, (st_data_t)wmap, &data)) return Qnil;
|
|
|
|
obj = (VALUE)data;
|
|
|
|
if (!is_id_value(objspace, obj)) return Qnil;
|
|
|
|
if (!is_live_object(objspace, obj)) return Qnil;
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2008-06-08 14:27:06 +04:00
|
|
|
|
2012-08-04 18:12:12 +04:00
|
|
|
/*
|
|
|
|
------------------------------ GC profiler ------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline void gc_prof_set_heap_info(rb_objspace_t *, gc_profile_record *);
|
2012-11-21 17:15:10 +04:00
|
|
|
#define GC_PROFILE_RECORD_DEFAULT_SIZE 100
|
2012-08-04 18:12:12 +04:00
|
|
|
|
|
|
|
static double
|
|
|
|
getrusage_time(void)
|
|
|
|
{
|
2012-12-05 18:53:16 +04:00
|
|
|
#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_PROCESS_CPUTIME_ID)
|
|
|
|
struct timespec ts;
|
|
|
|
|
|
|
|
if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts) == 0) {
|
|
|
|
return ts.tv_sec + ts.tv_nsec * 1e-9;
|
|
|
|
}
|
|
|
|
return 0.0;
|
|
|
|
#elif defined RUSAGE_SELF
|
2012-08-04 18:12:12 +04:00
|
|
|
struct rusage usage;
|
|
|
|
struct timeval time;
|
|
|
|
getrusage(RUSAGE_SELF, &usage);
|
|
|
|
time = usage.ru_utime;
|
|
|
|
return time.tv_sec + time.tv_usec * 1e-6;
|
|
|
|
#elif defined _WIN32
|
|
|
|
FILETIME creation_time, exit_time, kernel_time, user_time;
|
|
|
|
ULARGE_INTEGER ui;
|
|
|
|
LONG_LONG q;
|
|
|
|
double t;
|
|
|
|
|
|
|
|
if (GetProcessTimes(GetCurrentProcess(),
|
|
|
|
&creation_time, &exit_time, &kernel_time, &user_time) == 0)
|
|
|
|
{
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
memcpy(&ui, &user_time, sizeof(FILETIME));
|
|
|
|
q = ui.QuadPart / 10L;
|
|
|
|
t = (DWORD)(q % 1000000L) * 1e-6;
|
|
|
|
q /= 1000000L;
|
|
|
|
#ifdef __GNUC__
|
|
|
|
t += q;
|
|
|
|
#else
|
|
|
|
t += (double)(DWORD)(q >> 16) * (1 << 16);
|
|
|
|
t += (DWORD)q & ~(~0 << 16);
|
|
|
|
#endif
|
|
|
|
return t;
|
|
|
|
#else
|
|
|
|
return 0.0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-05-13 20:34:25 +04:00
|
|
|
|
2012-08-04 18:12:12 +04:00
|
|
|
static inline void
|
2013-05-21 12:19:07 +04:00
|
|
|
gc_prof_timer_start(rb_objspace_t *objspace, int reason)
|
2012-08-04 18:12:12 +04:00
|
|
|
{
|
|
|
|
if (objspace->profile.run) {
|
2013-05-13 20:34:25 +04:00
|
|
|
size_t index = objspace->profile.next_index;
|
|
|
|
gc_profile_record *record;
|
2012-08-04 18:12:12 +04:00
|
|
|
|
2013-05-21 12:19:07 +04:00
|
|
|
/* create new record */
|
2013-05-13 20:34:25 +04:00
|
|
|
objspace->profile.next_index++;
|
|
|
|
|
|
|
|
if (!objspace->profile.record) {
|
|
|
|
objspace->profile.size = GC_PROFILE_RECORD_DEFAULT_SIZE;
|
|
|
|
objspace->profile.record = malloc(sizeof(gc_profile_record) * objspace->profile.size);
|
|
|
|
}
|
|
|
|
if (index >= objspace->profile.size) {
|
|
|
|
objspace->profile.size += 1000;
|
|
|
|
objspace->profile.record = realloc(objspace->profile.record, sizeof(gc_profile_record) * objspace->profile.size);
|
|
|
|
}
|
|
|
|
if (!objspace->profile.record) {
|
|
|
|
rb_bug("gc_profile malloc or realloc miss");
|
|
|
|
}
|
|
|
|
record = gc_prof_record(objspace);
|
|
|
|
MEMZERO(record, gc_profile_record, 1);
|
|
|
|
|
2013-06-16 00:18:11 +04:00
|
|
|
#if GC_PROFILE_MORE_DETAIL
|
|
|
|
record->prepare_time = objspace->profile.prepare_time;
|
|
|
|
#endif
|
2013-05-13 20:34:25 +04:00
|
|
|
record->gc_time = getrusage_time();
|
|
|
|
record->gc_invoke_time = record->gc_time - objspace->profile.invoke_time;
|
2013-05-21 12:19:07 +04:00
|
|
|
record->flags = reason | ((ruby_gc_stress && !ruby_disable_gc_stress) ? GPR_FLAG_STRESS : 0);
|
2012-08-04 18:12:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2013-05-21 12:21:59 +04:00
|
|
|
gc_prof_timer_stop(rb_objspace_t *objspace)
|
2012-08-04 18:12:12 +04:00
|
|
|
{
|
|
|
|
if (objspace->profile.run) {
|
|
|
|
double gc_time = 0;
|
2013-05-13 20:34:25 +04:00
|
|
|
gc_profile_record *record = gc_prof_record(objspace);
|
2012-08-04 18:12:12 +04:00
|
|
|
|
|
|
|
gc_time = getrusage_time() - record->gc_time;
|
|
|
|
if (gc_time < 0) gc_time = 0;
|
2013-05-21 12:19:07 +04:00
|
|
|
|
2012-08-04 18:12:12 +04:00
|
|
|
record->gc_time = gc_time;
|
|
|
|
gc_prof_set_heap_info(objspace, record);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
gc_prof_mark_timer_start(rb_objspace_t *objspace)
|
|
|
|
{
|
* probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.
* compile.c (rb_insns_name): allowing DTrace probes to access
instruction sequence name.
* Makefile.in: translate probes.d file to appropriate header file.
* common.mk: declare dependencies on the DTrace header.
* configure.in: add a test for existence of DTrace.
* eval.c (setup_exception): add a probe for when an exception is
raised.
* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
end.
* hash.c (empty_hash_alloc): Add a probe for hash allocation.
* insns.def: Add probes for function entry and return.
* internal.h: function declaration for compile.c change.
* load.c (rb_f_load): add probes for `load` entry and exit, require
entry and exit, and wrapping search_required for load path search.
* object.c (rb_obj_alloc): added a probe for general object creation.
* parse.y (yycompile0): added a probe around parse and compile phase.
* string.c (empty_str_alloc, str_new): DTrace probes for string
allocation.
* test/dtrace/*: tests for DTrace probes.
* vm.c (vm_invoke_proc): add probes for function return on exception
raise, hash create, and instruction sequence execution.
* vm_core.h: add probe declarations for function entry and exit.
* vm_dump.c: add probes header file.
* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
function entry and return.
* vm_exec.c: expose instruction number to instruction name function.
* vm_insnshelper.c: add function entry and exit probes for cfunc
methods.
* vm_insnhelper.h: vm usage information is always collected, so
uncomment the functions.
12 19:14:50 2012 Akinori MUSHA <knu@iDaemons.org>
* configure.in (isinf, isnan): isinf() and isnan() are macros on
DragonFly which cannot be found by AC_REPLACE_FUNCS(). This
workaround enforces the fact that they exist on DragonFly.
12 15:59:38 2012 Shugo Maeda <shugo@ruby-lang.org>
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
vm_insnhelper.c (vm_search_method): revert r37616 because it's too
slow. [ruby-dev:46477]
* test/ruby/test_refinement.rb (test_inline_method_cache): skip
the test until the bug is fixed efficiently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-13 01:52:12 +04:00
|
|
|
if (RUBY_DTRACE_GC_MARK_BEGIN_ENABLED()) {
|
|
|
|
RUBY_DTRACE_GC_MARK_BEGIN();
|
|
|
|
}
|
2013-06-15 21:06:15 +04:00
|
|
|
#if GC_PROFILE_MORE_DETAIL
|
2012-08-04 18:12:12 +04:00
|
|
|
if (objspace->profile.run) {
|
2013-05-13 20:34:25 +04:00
|
|
|
gc_prof_record(objspace)->gc_mark_time = getrusage_time();
|
2012-08-04 18:12:12 +04:00
|
|
|
}
|
2013-06-15 21:06:15 +04:00
|
|
|
#endif
|
2012-08-04 18:12:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
gc_prof_mark_timer_stop(rb_objspace_t *objspace)
|
|
|
|
{
|
* probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.
* compile.c (rb_insns_name): allowing DTrace probes to access
instruction sequence name.
* Makefile.in: translate probes.d file to appropriate header file.
* common.mk: declare dependencies on the DTrace header.
* configure.in: add a test for existence of DTrace.
* eval.c (setup_exception): add a probe for when an exception is
raised.
* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
end.
* hash.c (empty_hash_alloc): Add a probe for hash allocation.
* insns.def: Add probes for function entry and return.
* internal.h: function declaration for compile.c change.
* load.c (rb_f_load): add probes for `load` entry and exit, require
entry and exit, and wrapping search_required for load path search.
* object.c (rb_obj_alloc): added a probe for general object creation.
* parse.y (yycompile0): added a probe around parse and compile phase.
* string.c (empty_str_alloc, str_new): DTrace probes for string
allocation.
* test/dtrace/*: tests for DTrace probes.
* vm.c (vm_invoke_proc): add probes for function return on exception
raise, hash create, and instruction sequence execution.
* vm_core.h: add probe declarations for function entry and exit.
* vm_dump.c: add probes header file.
* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
function entry and return.
* vm_exec.c: expose instruction number to instruction name function.
* vm_insnshelper.c: add function entry and exit probes for cfunc
methods.
* vm_insnhelper.h: vm usage information is always collected, so
uncomment the functions.
12 19:14:50 2012 Akinori MUSHA <knu@iDaemons.org>
* configure.in (isinf, isnan): isinf() and isnan() are macros on
DragonFly which cannot be found by AC_REPLACE_FUNCS(). This
workaround enforces the fact that they exist on DragonFly.
12 15:59:38 2012 Shugo Maeda <shugo@ruby-lang.org>
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
vm_insnhelper.c (vm_search_method): revert r37616 because it's too
slow. [ruby-dev:46477]
* test/ruby/test_refinement.rb (test_inline_method_cache): skip
the test until the bug is fixed efficiently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-13 01:52:12 +04:00
|
|
|
if (RUBY_DTRACE_GC_MARK_END_ENABLED()) {
|
|
|
|
RUBY_DTRACE_GC_MARK_END();
|
|
|
|
}
|
2013-06-15 21:06:15 +04:00
|
|
|
#if GC_PROFILE_MORE_DETAIL
|
2012-08-04 18:12:12 +04:00
|
|
|
if (objspace->profile.run) {
|
|
|
|
double mark_time = 0;
|
2013-05-13 20:34:25 +04:00
|
|
|
gc_profile_record *record = gc_prof_record(objspace);
|
2012-08-04 18:12:12 +04:00
|
|
|
|
2013-05-13 20:34:25 +04:00
|
|
|
mark_time = getrusage_time() - record->gc_mark_time;
|
2012-08-04 18:12:12 +04:00
|
|
|
if (mark_time < 0) mark_time = 0;
|
2013-05-13 20:34:25 +04:00
|
|
|
record->gc_mark_time = mark_time;
|
2012-08-04 18:12:12 +04:00
|
|
|
}
|
2013-06-15 21:06:15 +04:00
|
|
|
#endif
|
2012-08-04 18:12:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2013-05-13 20:34:25 +04:00
|
|
|
gc_prof_sweep_slot_timer_start(rb_objspace_t *objspace)
|
2012-08-04 18:12:12 +04:00
|
|
|
{
|
* probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.
* compile.c (rb_insns_name): allowing DTrace probes to access
instruction sequence name.
* Makefile.in: translate probes.d file to appropriate header file.
* common.mk: declare dependencies on the DTrace header.
* configure.in: add a test for existence of DTrace.
* eval.c (setup_exception): add a probe for when an exception is
raised.
* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
end.
* hash.c (empty_hash_alloc): Add a probe for hash allocation.
* insns.def: Add probes for function entry and return.
* internal.h: function declaration for compile.c change.
* load.c (rb_f_load): add probes for `load` entry and exit, require
entry and exit, and wrapping search_required for load path search.
* object.c (rb_obj_alloc): added a probe for general object creation.
* parse.y (yycompile0): added a probe around parse and compile phase.
* string.c (empty_str_alloc, str_new): DTrace probes for string
allocation.
* test/dtrace/*: tests for DTrace probes.
* vm.c (vm_invoke_proc): add probes for function return on exception
raise, hash create, and instruction sequence execution.
* vm_core.h: add probe declarations for function entry and exit.
* vm_dump.c: add probes header file.
* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
function entry and return.
* vm_exec.c: expose instruction number to instruction name function.
* vm_insnshelper.c: add function entry and exit probes for cfunc
methods.
* vm_insnhelper.h: vm usage information is always collected, so
uncomment the functions.
12 19:14:50 2012 Akinori MUSHA <knu@iDaemons.org>
* configure.in (isinf, isnan): isinf() and isnan() are macros on
DragonFly which cannot be found by AC_REPLACE_FUNCS(). This
workaround enforces the fact that they exist on DragonFly.
12 15:59:38 2012 Shugo Maeda <shugo@ruby-lang.org>
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
vm_insnhelper.c (vm_search_method): revert r37616 because it's too
slow. [ruby-dev:46477]
* test/ruby/test_refinement.rb (test_inline_method_cache): skip
the test until the bug is fixed efficiently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-13 01:52:12 +04:00
|
|
|
if (RUBY_DTRACE_GC_SWEEP_BEGIN_ENABLED()) {
|
|
|
|
RUBY_DTRACE_GC_SWEEP_BEGIN();
|
|
|
|
}
|
2013-06-15 21:06:15 +04:00
|
|
|
#if GC_PROFILE_MORE_DETAIL
|
2012-08-04 18:12:12 +04:00
|
|
|
if (objspace->profile.run) {
|
2013-05-13 20:34:25 +04:00
|
|
|
objspace->profile.gc_sweep_start_time = getrusage_time();
|
2012-08-04 18:12:12 +04:00
|
|
|
}
|
2013-06-15 21:06:15 +04:00
|
|
|
#endif
|
2012-08-04 18:12:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2013-05-13 20:34:25 +04:00
|
|
|
gc_prof_sweep_slot_timer_stop(rb_objspace_t *objspace)
|
2012-08-04 18:12:12 +04:00
|
|
|
{
|
* probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.
* compile.c (rb_insns_name): allowing DTrace probes to access
instruction sequence name.
* Makefile.in: translate probes.d file to appropriate header file.
* common.mk: declare dependencies on the DTrace header.
* configure.in: add a test for existence of DTrace.
* eval.c (setup_exception): add a probe for when an exception is
raised.
* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
end.
* hash.c (empty_hash_alloc): Add a probe for hash allocation.
* insns.def: Add probes for function entry and return.
* internal.h: function declaration for compile.c change.
* load.c (rb_f_load): add probes for `load` entry and exit, require
entry and exit, and wrapping search_required for load path search.
* object.c (rb_obj_alloc): added a probe for general object creation.
* parse.y (yycompile0): added a probe around parse and compile phase.
* string.c (empty_str_alloc, str_new): DTrace probes for string
allocation.
* test/dtrace/*: tests for DTrace probes.
* vm.c (vm_invoke_proc): add probes for function return on exception
raise, hash create, and instruction sequence execution.
* vm_core.h: add probe declarations for function entry and exit.
* vm_dump.c: add probes header file.
* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
function entry and return.
* vm_exec.c: expose instruction number to instruction name function.
* vm_insnshelper.c: add function entry and exit probes for cfunc
methods.
* vm_insnhelper.h: vm usage information is always collected, so
uncomment the functions.
12 19:14:50 2012 Akinori MUSHA <knu@iDaemons.org>
* configure.in (isinf, isnan): isinf() and isnan() are macros on
DragonFly which cannot be found by AC_REPLACE_FUNCS(). This
workaround enforces the fact that they exist on DragonFly.
12 15:59:38 2012 Shugo Maeda <shugo@ruby-lang.org>
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
vm_insnhelper.c (vm_search_method): revert r37616 because it's too
slow. [ruby-dev:46477]
* test/ruby/test_refinement.rb (test_inline_method_cache): skip
the test until the bug is fixed efficiently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-13 01:52:12 +04:00
|
|
|
if (RUBY_DTRACE_GC_SWEEP_END_ENABLED()) {
|
|
|
|
RUBY_DTRACE_GC_SWEEP_END();
|
|
|
|
}
|
2013-06-15 21:06:15 +04:00
|
|
|
#if GC_PROFILE_MORE_DETAIL
|
2012-08-04 18:12:12 +04:00
|
|
|
if (objspace->profile.run) {
|
|
|
|
double sweep_time = 0;
|
2013-05-13 20:34:25 +04:00
|
|
|
gc_profile_record *record = gc_prof_record(objspace);
|
2012-08-04 18:12:12 +04:00
|
|
|
|
2013-05-13 20:34:25 +04:00
|
|
|
sweep_time = getrusage_time() - objspace->profile.gc_sweep_start_time;
|
|
|
|
if (sweep_time < 0) sweep_time = 0;
|
2013-05-21 11:52:03 +04:00
|
|
|
record->gc_sweep_time += sweep_time;
|
2013-05-21 12:19:07 +04:00
|
|
|
|
|
|
|
if (deferred_final_list) record->flags |= GPR_FLAG_HAVE_FINALIZE;
|
2012-08-04 18:12:12 +04:00
|
|
|
}
|
2013-06-15 21:06:15 +04:00
|
|
|
#endif
|
2012-08-04 18:12:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
gc_prof_set_malloc_info(rb_objspace_t *objspace)
|
|
|
|
{
|
2013-06-15 21:06:15 +04:00
|
|
|
#if GC_PROFILE_MORE_DETAIL
|
2012-08-04 18:12:12 +04:00
|
|
|
if (objspace->profile.run) {
|
2013-05-13 20:34:25 +04:00
|
|
|
gc_profile_record *record = gc_prof_record(objspace);
|
2013-06-16 00:53:01 +04:00
|
|
|
record->allocate_increase = malloc_increase + malloc_increase2;
|
2013-05-13 20:34:25 +04:00
|
|
|
record->allocate_limit = malloc_limit;
|
2013-06-16 00:18:11 +04:00
|
|
|
#if CALC_EXACT_MALLOC_SIZE
|
|
|
|
record->allocated_size = malloc_allocated_size;
|
|
|
|
#endif
|
2012-08-04 18:12:12 +04:00
|
|
|
}
|
2013-06-15 21:06:15 +04:00
|
|
|
#endif
|
2012-08-04 18:12:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
gc_prof_set_heap_info(rb_objspace_t *objspace, gc_profile_record *record)
|
|
|
|
{
|
2013-05-13 20:34:25 +04:00
|
|
|
size_t live = objspace_live_num(objspace);
|
2012-08-04 18:12:12 +04:00
|
|
|
size_t total = heaps_used * HEAP_OBJ_LIMIT;
|
|
|
|
|
2013-06-15 21:06:15 +04:00
|
|
|
#if GC_PROFILE_MORE_DETAIL
|
2012-08-04 18:12:12 +04:00
|
|
|
record->heap_use_slots = heaps_used;
|
|
|
|
record->heap_live_objects = live;
|
|
|
|
record->heap_free_objects = total - live;
|
2013-06-15 21:06:15 +04:00
|
|
|
#endif
|
2012-08-04 18:12:12 +04:00
|
|
|
record->heap_total_objects = total;
|
|
|
|
record->heap_use_size = live * sizeof(RVALUE);
|
|
|
|
record->heap_total_size = total * sizeof(RVALUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* GC::Profiler.clear -> nil
|
|
|
|
*
|
|
|
|
* Clears the GC profiler data.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
gc_profile_clear(void)
|
|
|
|
{
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
2012-11-21 17:15:10 +04:00
|
|
|
|
|
|
|
if (GC_PROFILE_RECORD_DEFAULT_SIZE * 2 < objspace->profile.size) {
|
|
|
|
objspace->profile.size = GC_PROFILE_RECORD_DEFAULT_SIZE * 2;
|
|
|
|
objspace->profile.record = realloc(objspace->profile.record, sizeof(gc_profile_record) * objspace->profile.size);
|
|
|
|
if (!objspace->profile.record) {
|
|
|
|
rb_memerror();
|
|
|
|
}
|
|
|
|
}
|
2012-08-04 18:12:12 +04:00
|
|
|
MEMZERO(objspace->profile.record, gc_profile_record, objspace->profile.size);
|
2013-05-13 20:34:25 +04:00
|
|
|
objspace->profile.next_index = 0;
|
2012-08-04 18:12:12 +04:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2013-05-21 12:19:07 +04:00
|
|
|
static VALUE
|
|
|
|
gc_profile_flags(int flags)
|
|
|
|
{
|
|
|
|
VALUE result = rb_ary_new();
|
|
|
|
rb_ary_push(result, ID2SYM(rb_intern(flags & GPR_FLAG_MINOR ? "minor_gc" : "major_gc")));
|
|
|
|
if (flags & GPR_FLAG_HAVE_FINALIZE) rb_ary_push(result, ID2SYM(rb_intern("HAVE_FINALIZE")));
|
|
|
|
if (flags & GPR_FLAG_NEWOBJ) rb_ary_push(result, ID2SYM(rb_intern("CAUSED_BY_NEWOBJ")));
|
|
|
|
if (flags & GPR_FLAG_MALLOC) rb_ary_push(result, ID2SYM(rb_intern("CAUSED_BY_MALLOC")));
|
|
|
|
if (flags & GPR_FLAG_METHOD) rb_ary_push(result, ID2SYM(rb_intern("CAUSED_BY_METHOD")));
|
|
|
|
if (flags & GPR_FLAG_STRESS) rb_ary_push(result, ID2SYM(rb_intern("CAUSED_BY_STRESS")));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-09-08 07:57:41 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2012-11-29 12:15:53 +04:00
|
|
|
* GC::Profiler.raw_data -> [Hash, ...]
|
2011-09-08 07:57:41 +04:00
|
|
|
*
|
|
|
|
* Returns an Array of individual raw profile data Hashes ordered
|
2012-11-29 12:15:53 +04:00
|
|
|
* from earliest to latest by +:GC_INVOKE_TIME+.
|
|
|
|
*
|
|
|
|
* For example:
|
2011-09-08 07:57:41 +04:00
|
|
|
*
|
2012-11-29 12:15:53 +04:00
|
|
|
* [
|
|
|
|
* {
|
|
|
|
* :GC_TIME=>1.3000000000000858e-05,
|
|
|
|
* :GC_INVOKE_TIME=>0.010634999999999999,
|
|
|
|
* :HEAP_USE_SIZE=>289640,
|
|
|
|
* :HEAP_TOTAL_SIZE=>588960,
|
|
|
|
* :HEAP_TOTAL_OBJECTS=>14724,
|
|
|
|
* :GC_IS_MARKED=>false
|
|
|
|
* },
|
|
|
|
* # ...
|
2011-09-08 07:57:41 +04:00
|
|
|
* ]
|
|
|
|
*
|
|
|
|
* The keys mean:
|
|
|
|
*
|
2012-11-29 12:15:53 +04:00
|
|
|
* +:GC_TIME+::
|
|
|
|
* Time elapsed in seconds for this GC run
|
|
|
|
* +:GC_INVOKE_TIME+::
|
|
|
|
* Time elapsed in seconds from startup to when the GC was invoked
|
|
|
|
* +:HEAP_USE_SIZE+::
|
|
|
|
* Total bytes of heap used
|
|
|
|
* +:HEAP_TOTAL_SIZE+::
|
|
|
|
* Total size of heap in bytes
|
|
|
|
* +:HEAP_TOTAL_OBJECTS+::
|
|
|
|
* Total number of objects
|
|
|
|
* +:GC_IS_MARKED+::
|
|
|
|
* Returns +true+ if the GC is in mark phase
|
|
|
|
*
|
|
|
|
* If ruby was built with +GC_PROFILE_MORE_DETAIL+, you will also have access
|
|
|
|
* to the following hash keys:
|
|
|
|
*
|
|
|
|
* +:GC_MARK_TIME+::
|
|
|
|
* +:GC_SWEEP_TIME+::
|
|
|
|
* +:ALLOCATE_INCREASE+::
|
|
|
|
* +:ALLOCATE_LIMIT+::
|
|
|
|
* +:HEAP_USE_SLOTS+::
|
|
|
|
* +:HEAP_LIVE_OBJECTS+::
|
|
|
|
* +:HEAP_FREE_OBJECTS+::
|
|
|
|
* +:HAVE_FINALIZE+::
|
2011-09-08 07:57:41 +04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-09-04 14:47:39 +04:00
|
|
|
static VALUE
|
2008-08-11 13:36:57 +04:00
|
|
|
gc_profile_record_get(void)
|
|
|
|
{
|
|
|
|
VALUE prof;
|
|
|
|
VALUE gc_profile = rb_ary_new();
|
|
|
|
size_t i;
|
|
|
|
rb_objspace_t *objspace = (&rb_objspace);
|
2009-02-22 17:23:33 +03:00
|
|
|
|
2008-08-11 13:36:57 +04:00
|
|
|
if (!objspace->profile.run) {
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2013-05-13 20:34:25 +04:00
|
|
|
for (i =0; i < objspace->profile.next_index; i++) {
|
2008-08-11 13:36:57 +04:00
|
|
|
prof = rb_hash_new();
|
2013-05-21 12:19:07 +04:00
|
|
|
rb_hash_aset(prof, ID2SYM(rb_intern("GC_FLAGS")), gc_profile_flags(objspace->profile.record[i].flags));
|
2008-09-05 22:24:21 +04:00
|
|
|
rb_hash_aset(prof, ID2SYM(rb_intern("GC_TIME")), DBL2NUM(objspace->profile.record[i].gc_time));
|
|
|
|
rb_hash_aset(prof, ID2SYM(rb_intern("GC_INVOKE_TIME")), DBL2NUM(objspace->profile.record[i].gc_invoke_time));
|
2010-08-16 15:31:54 +04:00
|
|
|
rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_USE_SIZE")), SIZET2NUM(objspace->profile.record[i].heap_use_size));
|
|
|
|
rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_TOTAL_SIZE")), SIZET2NUM(objspace->profile.record[i].heap_total_size));
|
|
|
|
rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_TOTAL_OBJECTS")), SIZET2NUM(objspace->profile.record[i].heap_total_objects));
|
2013-05-21 12:21:59 +04:00
|
|
|
rb_hash_aset(prof, ID2SYM(rb_intern("GC_IS_MARKED")), Qtrue);
|
2008-08-11 13:36:57 +04:00
|
|
|
#if GC_PROFILE_MORE_DETAIL
|
2008-09-05 22:24:21 +04:00
|
|
|
rb_hash_aset(prof, ID2SYM(rb_intern("GC_MARK_TIME")), DBL2NUM(objspace->profile.record[i].gc_mark_time));
|
|
|
|
rb_hash_aset(prof, ID2SYM(rb_intern("GC_SWEEP_TIME")), DBL2NUM(objspace->profile.record[i].gc_sweep_time));
|
2010-08-16 15:31:54 +04:00
|
|
|
rb_hash_aset(prof, ID2SYM(rb_intern("ALLOCATE_INCREASE")), SIZET2NUM(objspace->profile.record[i].allocate_increase));
|
|
|
|
rb_hash_aset(prof, ID2SYM(rb_intern("ALLOCATE_LIMIT")), SIZET2NUM(objspace->profile.record[i].allocate_limit));
|
|
|
|
rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_USE_SLOTS")), SIZET2NUM(objspace->profile.record[i].heap_use_slots));
|
|
|
|
rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_LIVE_OBJECTS")), SIZET2NUM(objspace->profile.record[i].heap_live_objects));
|
|
|
|
rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_FREE_OBJECTS")), SIZET2NUM(objspace->profile.record[i].heap_free_objects));
|
2013-05-21 12:19:07 +04:00
|
|
|
rb_hash_aset(prof, ID2SYM(rb_intern("HAVE_FINALIZE")), (objspace->profile.record[i].flags & GPR_FLAG_HAVE_FINALIZE) ? Qtrue : Qfalse);
|
2008-08-11 13:36:57 +04:00
|
|
|
#endif
|
|
|
|
rb_ary_push(gc_profile, prof);
|
|
|
|
}
|
|
|
|
|
|
|
|
return gc_profile;
|
|
|
|
}
|
|
|
|
|
2012-10-27 18:36:22 +04:00
|
|
|
static void
|
|
|
|
gc_profile_dump_on(VALUE out, VALUE (*append)(VALUE, VALUE))
|
2008-08-11 13:36:57 +04:00
|
|
|
{
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
2013-05-22 11:50:20 +04:00
|
|
|
size_t count = objspace->profile.next_index;
|
2009-02-22 17:23:33 +03:00
|
|
|
|
2013-05-22 11:50:20 +04:00
|
|
|
if (objspace->profile.run && count /* > 1 */) {
|
|
|
|
size_t i;
|
2013-05-21 11:27:32 +04:00
|
|
|
const gc_profile_record *record;
|
|
|
|
|
2012-10-29 07:19:38 +04:00
|
|
|
append(out, rb_sprintf("GC %"PRIuSIZE" invokes.\n", objspace->count));
|
2012-10-27 18:36:22 +04:00
|
|
|
append(out, rb_str_new_cstr("Index Invoke Time(sec) Use Size(byte) Total Size(byte) Total Object GC Time(ms)\n"));
|
2013-05-21 11:27:32 +04:00
|
|
|
|
2012-10-27 18:36:22 +04:00
|
|
|
for (i = 0; i < count; i++) {
|
2013-05-21 11:27:32 +04:00
|
|
|
record = &objspace->profile.record[i];
|
2013-05-22 11:50:20 +04:00
|
|
|
append(out, rb_sprintf("%5"PRIdSIZE" %19.3f %20"PRIuSIZE" %20"PRIuSIZE" %20"PRIuSIZE" %30.20f\n",
|
|
|
|
i+1, record->gc_invoke_time, record->heap_use_size,
|
2013-05-21 12:19:07 +04:00
|
|
|
record->heap_total_size, record->heap_total_objects, record->gc_time*1000));
|
2008-08-11 13:36:57 +04:00
|
|
|
}
|
|
|
|
#if GC_PROFILE_MORE_DETAIL
|
2012-10-27 18:36:22 +04:00
|
|
|
append(out, rb_str_new_cstr("\n\n" \
|
2013-05-21 11:27:32 +04:00
|
|
|
"More detail.\n" \
|
2013-06-16 00:18:11 +04:00
|
|
|
"Prepare Time = Previously GC's rest sweep time\n"
|
|
|
|
"Index Flags Allocate Inc. Allocate Limit"
|
|
|
|
#if CALC_EXACT_MALLOC_SIZE
|
|
|
|
" Allocated Size"
|
|
|
|
#endif
|
|
|
|
" Use Slot Mark Time(ms) Sweep Time(ms) Prepare Time(ms) Removing Obj. Empty Obj.\n"));
|
2012-10-27 18:36:22 +04:00
|
|
|
for (i = 0; i < count; i++) {
|
2013-05-21 11:52:03 +04:00
|
|
|
record = &objspace->profile.record[i];
|
2013-06-16 00:18:11 +04:00
|
|
|
append(out, rb_sprintf("%5"PRIdSIZE" %c/%c/%6s%c %13"PRIuSIZE" %15"PRIuSIZE
|
|
|
|
#if CALC_EXACT_MALLOC_SIZE
|
|
|
|
" %15"PRIuSIZE
|
|
|
|
#endif
|
|
|
|
" %9"PRIuSIZE" %17.12f %17.12f %17.12f %14"PRIuSIZE" %11"PRIuSIZE" \n",
|
2013-05-22 11:50:20 +04:00
|
|
|
i+1,
|
2013-05-21 12:19:07 +04:00
|
|
|
(record->flags & GPR_FLAG_MINOR) ? '-' : '+',
|
|
|
|
(record->flags & GPR_FLAG_HAVE_FINALIZE) ? 'F' : '.',
|
|
|
|
(record->flags & GPR_FLAG_NEWOBJ) ? "NEWOBJ" :
|
|
|
|
(record->flags & GPR_FLAG_MALLOC) ? "MALLOC" :
|
|
|
|
(record->flags & GPR_FLAG_METHOD) ? "METHOD" :
|
2013-06-16 00:18:11 +04:00
|
|
|
(record->flags & GPR_FLAG_CAPI) ? "CAPI__" : "??????",
|
2013-05-21 12:19:07 +04:00
|
|
|
(record->flags & GPR_FLAG_STRESS) ? '!' : ' ',
|
|
|
|
record->allocate_increase, record->allocate_limit,
|
2013-06-16 00:18:11 +04:00
|
|
|
#if CALC_EXACT_MALLOC_SIZE
|
|
|
|
record->allocated_size,
|
|
|
|
#endif
|
2013-05-21 12:19:07 +04:00
|
|
|
record->heap_use_slots,
|
2013-06-16 00:18:11 +04:00
|
|
|
record->gc_mark_time*1000, record->gc_sweep_time*1000,
|
|
|
|
record->prepare_time*1000,
|
|
|
|
record->removing_objects,
|
|
|
|
record->empty_objects
|
|
|
|
));
|
2008-08-11 13:36:57 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-27 18:36:22 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2012-11-29 12:15:53 +04:00
|
|
|
* GC::Profiler.result -> String
|
2012-10-27 18:36:22 +04:00
|
|
|
*
|
|
|
|
* Returns a profile data report such as:
|
|
|
|
*
|
|
|
|
* GC 1 invokes.
|
|
|
|
* Index Invoke Time(sec) Use Size(byte) Total Size(byte) Total Object GC time(ms)
|
|
|
|
* 1 0.012 159240 212940 10647 0.00000000000001530000
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
gc_profile_result(void)
|
|
|
|
{
|
|
|
|
VALUE str = rb_str_buf_new(0);
|
|
|
|
gc_profile_dump_on(str, rb_str_buf_append);
|
|
|
|
return str;
|
|
|
|
}
|
2008-08-11 13:36:57 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* GC::Profiler.report
|
2012-11-29 12:15:53 +04:00
|
|
|
* GC::Profiler.report(io)
|
2008-08-11 13:36:57 +04:00
|
|
|
*
|
2012-11-29 12:15:53 +04:00
|
|
|
* Writes the GC::Profiler.result to <tt>$stdout</tt> or the given IO object.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2008-08-11 13:36:57 +04:00
|
|
|
*/
|
|
|
|
|
2008-09-04 14:47:39 +04:00
|
|
|
static VALUE
|
2008-08-11 13:36:57 +04:00
|
|
|
gc_profile_report(int argc, VALUE *argv, VALUE self)
|
|
|
|
{
|
|
|
|
VALUE out;
|
|
|
|
|
|
|
|
if (argc == 0) {
|
|
|
|
out = rb_stdout;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_scan_args(argc, argv, "01", &out);
|
|
|
|
}
|
2012-10-27 18:36:22 +04:00
|
|
|
gc_profile_dump_on(out, rb_io_write);
|
2008-08-11 13:36:57 +04:00
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2010-03-04 07:51:43 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2012-11-29 12:15:53 +04:00
|
|
|
* GC::Profiler.total_time -> float
|
2010-03-04 07:51:43 +03:00
|
|
|
*
|
2012-10-20 15:36:46 +04:00
|
|
|
* The total time used for garbage collection in seconds
|
2010-03-04 07:51:43 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
gc_profile_total_time(VALUE self)
|
|
|
|
{
|
|
|
|
double time = 0;
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
size_t i;
|
2013-05-13 20:34:25 +04:00
|
|
|
size_t count = objspace->profile.next_index - 1;
|
2010-03-04 07:51:43 +03:00
|
|
|
|
2013-05-13 20:34:25 +04:00
|
|
|
if (objspace->profile.run && count > 0) {
|
|
|
|
for (i = 0; i < count; i++) {
|
2010-03-04 07:51:43 +03:00
|
|
|
time += objspace->profile.record[i].gc_time;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return DBL2NUM(time);
|
|
|
|
}
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2012-11-29 12:15:53 +04:00
|
|
|
* GC::Profiler.enabled? -> true or false
|
2012-08-05 14:39:37 +04:00
|
|
|
*
|
|
|
|
* The current status of GC profile mode.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
gc_profile_enable_get(VALUE self)
|
|
|
|
{
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
return objspace->profile.run ? Qtrue : Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2012-11-29 12:15:53 +04:00
|
|
|
* GC::Profiler.enable -> nil
|
2012-08-05 14:39:37 +04:00
|
|
|
*
|
|
|
|
* Starts the GC profiler.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
gc_profile_enable(void)
|
|
|
|
{
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
2013-05-29 19:10:28 +04:00
|
|
|
rest_sweep(objspace);
|
2012-08-05 14:39:37 +04:00
|
|
|
objspace->profile.run = TRUE;
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2012-11-29 12:15:53 +04:00
|
|
|
* GC::Profiler.disable -> nil
|
2012-08-05 14:39:37 +04:00
|
|
|
*
|
|
|
|
* Stops the GC profiler.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
gc_profile_disable(void)
|
|
|
|
{
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
|
|
|
|
objspace->profile.run = FALSE;
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2012-11-22 19:03:46 +04:00
|
|
|
#ifdef GC_DEBUG
|
|
|
|
|
|
|
|
/*
|
|
|
|
------------------------------ DEBUG ------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_gcdebug_print_obj_condition(VALUE obj)
|
|
|
|
{
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
|
|
|
|
if (is_pointer_to_heap(objspace, (void *)obj)) {
|
|
|
|
fprintf(stderr, "pointer to heap?: true\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "pointer to heap?: false\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fprintf(stderr, "marked?: %s\n",
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
MARKED_IN_BITMAP(GET_HEAP_MARK_BITS(obj), obj) ? "true" : "false");
|
2012-11-22 19:03:46 +04:00
|
|
|
if (is_lazy_sweeping(objspace)) {
|
|
|
|
fprintf(stderr, "lazy sweeping?: true\n");
|
|
|
|
fprintf(stderr, "swept?: %s\n",
|
|
|
|
is_swept_object(objspace, obj) ? "done" : "not yet");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "lazy sweeping?: false\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
gcdebug_sential(VALUE obj, VALUE name)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "WARNING: object %s(%p) is inadvertently collected\n", (char *)name, (void *)obj);
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_gcdebug_sentinel(VALUE obj, const char *name)
|
|
|
|
{
|
|
|
|
rb_define_final(obj, rb_proc_new(gcdebug_sential, (VALUE)name));
|
|
|
|
}
|
|
|
|
#endif /* GC_DEBUG */
|
|
|
|
|
|
|
|
|
2012-08-05 14:39:37 +04:00
|
|
|
/*
|
2013-06-17 12:44:56 +04:00
|
|
|
* Document-module: ObjectSpace
|
2012-08-05 14:39:37 +04:00
|
|
|
*
|
2012-11-29 12:15:53 +04:00
|
|
|
* The ObjectSpace module contains a number of routines
|
2012-08-05 14:39:37 +04:00
|
|
|
* that interact with the garbage collection facility and allow you to
|
|
|
|
* traverse all living objects with an iterator.
|
|
|
|
*
|
2012-11-29 12:15:53 +04:00
|
|
|
* ObjectSpace also provides support for object finalizers, procs that will be
|
|
|
|
* called when a specific object is about to be destroyed by garbage
|
|
|
|
* collection.
|
2012-08-05 14:39:37 +04:00
|
|
|
*
|
|
|
|
* a = "A"
|
|
|
|
* b = "B"
|
|
|
|
*
|
2013-06-17 12:39:39 +04:00
|
|
|
* ObjectSpace.define_finalizer(a, proc {|id| puts "Finalizer one on #{id}" })
|
|
|
|
* ObjectSpace.define_finalizer(b, proc {|id| puts "Finalizer two on #{id}" })
|
2012-08-05 14:39:37 +04:00
|
|
|
*
|
2012-11-29 12:15:53 +04:00
|
|
|
* _produces:_
|
2012-08-05 14:39:37 +04:00
|
|
|
*
|
2013-06-17 12:39:39 +04:00
|
|
|
* Finalizer two on 537763470
|
2012-08-05 14:39:37 +04:00
|
|
|
* Finalizer one on 537763480
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Document-class: ObjectSpace::WeakMap
|
|
|
|
*
|
2012-11-29 12:15:53 +04:00
|
|
|
* An ObjectSpace::WeakMap object holds references to
|
2013-02-23 11:06:10 +04:00
|
|
|
* any objects, but those objects can get garbage collected.
|
2012-12-02 11:45:17 +04:00
|
|
|
*
|
|
|
|
* This class is mostly used internally by WeakRef, please use
|
|
|
|
* +lib/weakref.rb+ for the public interface.
|
2012-08-05 14:39:37 +04:00
|
|
|
*/
|
|
|
|
|
2011-07-08 04:18:39 +04:00
|
|
|
/* Document-class: GC::Profiler
|
|
|
|
*
|
|
|
|
* The GC profiler provides access to information on GC runs including time,
|
|
|
|
* length and object space size.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
*
|
|
|
|
* GC::Profiler.enable
|
|
|
|
*
|
|
|
|
* require 'rdoc/rdoc'
|
|
|
|
*
|
2012-11-29 12:15:53 +04:00
|
|
|
* GC::Profiler.report
|
2011-07-08 04:18:39 +04:00
|
|
|
*
|
|
|
|
* GC::Profiler.disable
|
|
|
|
*
|
|
|
|
* See also GC.count, GC.malloc_allocated_size and GC.malloc_allocations
|
|
|
|
*/
|
2010-05-28 15:13:42 +04:00
|
|
|
|
2003-12-22 09:20:14 +03:00
|
|
|
/*
|
2012-11-29 12:15:53 +04:00
|
|
|
* The GC module provides an interface to Ruby's mark and
|
|
|
|
* sweep garbage collection mechanism.
|
|
|
|
*
|
|
|
|
* Some of the underlying methods are also available via the ObjectSpace
|
|
|
|
* module.
|
2011-07-08 04:18:39 +04:00
|
|
|
*
|
|
|
|
* You may obtain information about the operation of the GC through
|
|
|
|
* GC::Profiler.
|
2003-12-22 09:20:14 +03:00
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
Init_GC(void)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2013-06-18 16:59:02 +04:00
|
|
|
VALUE rb_mObjSpace;
|
2008-08-11 13:36:57 +04:00
|
|
|
VALUE rb_mProfiler;
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
rb_mGC = rb_define_module("GC");
|
2001-01-29 08:10:42 +03:00
|
|
|
rb_define_singleton_method(rb_mGC, "start", rb_gc_start, 0);
|
|
|
|
rb_define_singleton_method(rb_mGC, "enable", rb_gc_enable, 0);
|
|
|
|
rb_define_singleton_method(rb_mGC, "disable", rb_gc_disable, 0);
|
2006-01-10 01:32:55 +03:00
|
|
|
rb_define_singleton_method(rb_mGC, "stress", gc_stress_get, 0);
|
|
|
|
rb_define_singleton_method(rb_mGC, "stress=", gc_stress_set, 1);
|
2008-04-27 10:28:08 +04:00
|
|
|
rb_define_singleton_method(rb_mGC, "count", gc_count, 0);
|
2010-10-27 23:02:24 +04:00
|
|
|
rb_define_singleton_method(rb_mGC, "stat", gc_stat, -1);
|
2001-01-29 08:10:42 +03:00
|
|
|
rb_define_method(rb_mGC, "garbage_collect", rb_gc_start, 0);
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2008-08-11 13:36:57 +04:00
|
|
|
rb_mProfiler = rb_define_module_under(rb_mGC, "Profiler");
|
|
|
|
rb_define_singleton_method(rb_mProfiler, "enabled?", gc_profile_enable_get, 0);
|
|
|
|
rb_define_singleton_method(rb_mProfiler, "enable", gc_profile_enable, 0);
|
2011-09-08 07:57:41 +04:00
|
|
|
rb_define_singleton_method(rb_mProfiler, "raw_data", gc_profile_record_get, 0);
|
2008-08-11 13:36:57 +04:00
|
|
|
rb_define_singleton_method(rb_mProfiler, "disable", gc_profile_disable, 0);
|
|
|
|
rb_define_singleton_method(rb_mProfiler, "clear", gc_profile_clear, 0);
|
|
|
|
rb_define_singleton_method(rb_mProfiler, "result", gc_profile_result, 0);
|
|
|
|
rb_define_singleton_method(rb_mProfiler, "report", gc_profile_report, -1);
|
2010-03-04 07:51:43 +03:00
|
|
|
rb_define_singleton_method(rb_mProfiler, "total_time", gc_profile_total_time, 0);
|
2008-08-11 13:36:57 +04:00
|
|
|
|
2013-06-18 16:59:02 +04:00
|
|
|
rb_mObjSpace = rb_define_module("ObjectSpace");
|
|
|
|
rb_define_module_function(rb_mObjSpace, "each_object", os_each_obj, -1);
|
|
|
|
rb_define_module_function(rb_mObjSpace, "garbage_collect", rb_gc_start, 0);
|
2000-07-15 17:37:03 +04:00
|
|
|
|
2013-06-18 16:59:02 +04:00
|
|
|
rb_define_module_function(rb_mObjSpace, "define_finalizer", define_final, -1);
|
|
|
|
rb_define_module_function(rb_mObjSpace, "undefine_finalizer", undefine_final, 1);
|
2000-07-15 17:37:03 +04:00
|
|
|
|
2013-06-18 16:59:02 +04:00
|
|
|
rb_define_module_function(rb_mObjSpace, "_id2ref", id2ref, 1);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2008-07-03 02:02:58 +04:00
|
|
|
nomem_error = rb_exc_new3(rb_eNoMemError,
|
|
|
|
rb_obj_freeze(rb_str_new2("failed to allocate memory")));
|
2008-06-15 13:17:06 +04:00
|
|
|
OBJ_TAINT(nomem_error);
|
|
|
|
OBJ_FREEZE(nomem_error);
|
2006-03-02 08:22:30 +03:00
|
|
|
|
2010-12-17 16:25:19 +03:00
|
|
|
rb_define_method(rb_cBasicObject, "__id__", rb_obj_id, 0);
|
2010-12-22 08:38:41 +03:00
|
|
|
rb_define_method(rb_mKernel, "object_id", rb_obj_id, 0);
|
2007-11-03 18:09:10 +03:00
|
|
|
|
2013-06-18 16:59:02 +04:00
|
|
|
rb_define_module_function(rb_mObjSpace, "count_objects", count_objects, -1);
|
2008-06-08 14:27:06 +04:00
|
|
|
|
2012-03-13 07:37:06 +04:00
|
|
|
{
|
2013-06-18 16:59:02 +04:00
|
|
|
VALUE rb_cWeakMap = rb_define_class_under(rb_mObjSpace, "WeakMap", rb_cObject);
|
2012-03-13 07:37:06 +04:00
|
|
|
rb_define_alloc_func(rb_cWeakMap, wmap_allocate);
|
|
|
|
rb_define_method(rb_cWeakMap, "[]=", wmap_aset, 2);
|
|
|
|
rb_define_method(rb_cWeakMap, "[]", wmap_aref, 1);
|
|
|
|
rb_define_private_method(rb_cWeakMap, "finalize", wmap_finalize, 1);
|
|
|
|
}
|
|
|
|
|
2008-06-08 14:27:06 +04:00
|
|
|
#if CALC_EXACT_MALLOC_SIZE
|
|
|
|
rb_define_singleton_method(rb_mGC, "malloc_allocated_size", gc_malloc_allocated_size, 0);
|
|
|
|
rb_define_singleton_method(rb_mGC, "malloc_allocations", gc_malloc_allocations, 0);
|
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|