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"
|
2008-03-03 11:27:43 +03:00
|
|
|
#include "ruby/util.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"
|
2007-05-29 19:49:30 +04:00
|
|
|
#include "gc.h"
|
2010-10-26 21:27:32 +04:00
|
|
|
#include "constant.h"
|
1998-01-16 15:13:05 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <setjmp.h>
|
2001-11-19 17:42:45 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#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>
|
|
|
|
#endif
|
|
|
|
|
2004-07-08 14:27:23 +04:00
|
|
|
#if defined _WIN32 || defined __CYGWIN__
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2007-07-14 11:19:59 +04:00
|
|
|
#ifdef HAVE_VALGRIND_MEMCHECK_H
|
|
|
|
# include <valgrind/memcheck.h>
|
|
|
|
# ifndef VALGRIND_MAKE_MEM_DEFINED
|
|
|
|
# define VALGRIND_MAKE_MEM_DEFINED(p, n) VALGRIND_MAKE_READABLE(p, n)
|
|
|
|
# endif
|
2007-08-19 08:34:44 +04:00
|
|
|
# ifndef VALGRIND_MAKE_MEM_UNDEFINED
|
|
|
|
# define VALGRIND_MAKE_MEM_UNDEFINED(p, n) VALGRIND_MAKE_WRITABLE(p, n)
|
|
|
|
# endif
|
2007-07-14 11:19:59 +04:00
|
|
|
#else
|
|
|
|
# define VALGRIND_MAKE_MEM_DEFINED(p, n) /* empty */
|
2007-08-19 08:34:44 +04:00
|
|
|
# define VALGRIND_MAKE_MEM_UNDEFINED(p, n) /* empty */
|
2007-07-14 11:19:59 +04:00
|
|
|
#endif
|
|
|
|
|
* file.c, gc.c, io.c, ruby.h, rubyio.h, win32/win32.h (rb_io_t):
renamed from OpenFile.
* ext/dl/cptr.c, ext/io/wait/wait.c, ext/openssl/ossl.h,
ext/openssl/ossl_bio.c, ext/openssl/ossl_ssl.c, ext/pty/pty.c,
ext/readline/readline.c, ext/socket/socket.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-24 13:30:50 +03:00
|
|
|
int rb_io_fptr_finalize(struct rb_io_t*);
|
1999-01-20 07:59:39 +03:00
|
|
|
|
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
|
|
|
|
2001-02-11 10:12:02 +03:00
|
|
|
/* Make alloca work the best possible way. */
|
2002-10-25 22:39:30 +04:00
|
|
|
#ifdef __GNUC__
|
|
|
|
# ifndef atarist
|
|
|
|
# ifndef alloca
|
|
|
|
# define alloca __builtin_alloca
|
|
|
|
# endif
|
|
|
|
# endif /* atarist */
|
|
|
|
#else
|
|
|
|
# ifdef HAVE_ALLOCA_H
|
2001-02-11 10:12:02 +03:00
|
|
|
# include <alloca.h>
|
2001-03-26 12:57:16 +04:00
|
|
|
# else
|
2006-12-31 18:02:22 +03:00
|
|
|
# ifdef _AIX
|
|
|
|
#pragma alloca
|
|
|
|
# else
|
2001-03-26 12:57:16 +04:00
|
|
|
# ifndef alloca /* predefined by HP cc +Olibcalls */
|
|
|
|
void *alloca ();
|
|
|
|
# endif
|
2002-10-25 22:39:30 +04:00
|
|
|
# endif /* AIX */
|
|
|
|
# endif /* HAVE_ALLOCA_H */
|
|
|
|
#endif /* __GNUC__ */
|
2001-02-11 10:12:02 +03:00
|
|
|
|
2002-10-10 19:26:58 +04:00
|
|
|
#ifndef GC_MALLOC_LIMIT
|
|
|
|
#define GC_MALLOC_LIMIT 8000000
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
|
|
|
#define MARK_STACK_MAX 1024
|
|
|
|
|
2007-06-25 06:44:20 +04:00
|
|
|
int ruby_gc_debug_indent = 0;
|
|
|
|
|
2008-08-11 13:36:57 +04:00
|
|
|
/* for GC profile */
|
|
|
|
#define GC_PROFILE_MORE_DETAIL 0
|
|
|
|
typedef struct gc_profile_record {
|
|
|
|
double gc_time;
|
|
|
|
double gc_mark_time;
|
|
|
|
double gc_sweep_time;
|
|
|
|
double gc_invoke_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;
|
|
|
|
size_t heap_total_objects;
|
|
|
|
size_t heap_use_size;
|
|
|
|
size_t heap_total_size;
|
2009-05-13 18:08:26 +04:00
|
|
|
|
2008-08-11 13:36:57 +04:00
|
|
|
int have_finalize;
|
2010-05-28 15:13:42 +04:00
|
|
|
int is_marked;
|
2009-05-13 18:08:26 +04:00
|
|
|
|
2008-08-11 13:36:57 +04:00
|
|
|
size_t allocate_increase;
|
|
|
|
size_t allocate_limit;
|
|
|
|
} gc_profile_record;
|
|
|
|
|
|
|
|
static double
|
|
|
|
getrusage_time(void)
|
|
|
|
{
|
2008-08-11 15:11:27 +04:00
|
|
|
#ifdef RUSAGE_SELF
|
2008-08-11 13:36:57 +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;
|
2008-08-12 13:55:06 +04:00
|
|
|
#elif defined _WIN32
|
|
|
|
FILETIME creation_time, exit_time, kernel_time, user_time;
|
|
|
|
ULARGE_INTEGER ui;
|
|
|
|
LONG_LONG q;
|
|
|
|
double t;
|
2009-02-22 17:23:33 +03:00
|
|
|
|
2008-08-12 13:55:06 +04:00
|
|
|
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
|
2008-08-14 09:57:58 +04:00
|
|
|
return t;
|
2008-08-11 15:11:27 +04:00
|
|
|
#else
|
|
|
|
return 0.0;
|
|
|
|
#endif
|
2008-08-11 13:36:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define GC_PROF_TIMER_START do {\
|
|
|
|
if (objspace->profile.run) {\
|
|
|
|
if (!objspace->profile.record) {\
|
|
|
|
objspace->profile.size = 1000;\
|
|
|
|
objspace->profile.record = malloc(sizeof(gc_profile_record) * objspace->profile.size);\
|
|
|
|
}\
|
|
|
|
if (count >= 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");\
|
|
|
|
}\
|
|
|
|
MEMZERO(&objspace->profile.record[count], gc_profile_record, 1);\
|
|
|
|
gc_time = getrusage_time();\
|
|
|
|
objspace->profile.record[count].gc_invoke_time = gc_time - objspace->profile.invoke_time;\
|
|
|
|
}\
|
|
|
|
} while(0)
|
|
|
|
|
2010-05-28 15:13:42 +04:00
|
|
|
#define GC_PROF_TIMER_STOP(marked) do {\
|
2008-08-11 13:36:57 +04:00
|
|
|
if (objspace->profile.run) {\
|
|
|
|
gc_time = getrusage_time() - gc_time;\
|
2008-08-11 15:11:27 +04:00
|
|
|
if (gc_time < 0) gc_time = 0;\
|
2008-08-11 13:36:57 +04:00
|
|
|
objspace->profile.record[count].gc_time = gc_time;\
|
2010-05-29 05:12:38 +04:00
|
|
|
objspace->profile.record[count].is_marked = !!(marked);\
|
|
|
|
GC_PROF_SET_HEAP_INFO(objspace->profile.record[count]);\
|
2008-08-11 13:36:57 +04:00
|
|
|
objspace->profile.count++;\
|
|
|
|
}\
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#if GC_PROFILE_MORE_DETAIL
|
2010-05-28 15:13:42 +04:00
|
|
|
#define INIT_GC_PROF_PARAMS double gc_time = 0, sweep_time = 0;\
|
|
|
|
size_t count = objspace->profile.count, total = 0, live = 0
|
2008-08-11 13:36:57 +04:00
|
|
|
|
2010-05-28 15:13:42 +04:00
|
|
|
#define GC_PROF_MARK_TIMER_START double mark_time = 0;\
|
|
|
|
do {\
|
2008-08-11 13:36:57 +04:00
|
|
|
if (objspace->profile.run) {\
|
|
|
|
mark_time = getrusage_time();\
|
|
|
|
}\
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define GC_PROF_MARK_TIMER_STOP do {\
|
|
|
|
if (objspace->profile.run) {\
|
|
|
|
mark_time = getrusage_time() - mark_time;\
|
|
|
|
if (mark_time < 0) mark_time = 0;\
|
2010-05-28 15:13:42 +04:00
|
|
|
objspace->profile.record[objspace->profile.count].gc_mark_time = mark_time;\
|
2008-08-11 13:36:57 +04:00
|
|
|
}\
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define GC_PROF_SWEEP_TIMER_START do {\
|
|
|
|
if (objspace->profile.run) {\
|
|
|
|
sweep_time = getrusage_time();\
|
|
|
|
}\
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define GC_PROF_SWEEP_TIMER_STOP do {\
|
|
|
|
if (objspace->profile.run) {\
|
|
|
|
sweep_time = getrusage_time() - sweep_time;\
|
|
|
|
if (sweep_time < 0) sweep_time = 0;\
|
|
|
|
objspace->profile.record[count].gc_sweep_time = sweep_time;\
|
|
|
|
}\
|
|
|
|
} while(0)
|
|
|
|
#define GC_PROF_SET_MALLOC_INFO do {\
|
|
|
|
if (objspace->profile.run) {\
|
2009-07-07 06:56:57 +04:00
|
|
|
gc_profile_record *record = &objspace->profile.record[objspace->profile.count];\
|
|
|
|
record->allocate_increase = malloc_increase;\
|
|
|
|
record->allocate_limit = malloc_limit; \
|
2008-08-11 13:36:57 +04:00
|
|
|
}\
|
|
|
|
} while(0)
|
2010-05-28 15:13:42 +04:00
|
|
|
#define GC_PROF_SET_HEAP_INFO(record) do {\
|
|
|
|
live = objspace->heap.live_num;\
|
|
|
|
total = heaps_used * HEAP_OBJ_LIMIT;\
|
|
|
|
record.heap_use_slots = heaps_used;\
|
|
|
|
record.heap_live_objects = live;\
|
|
|
|
record.heap_free_objects = total - live;\
|
|
|
|
record.heap_total_objects = total;\
|
|
|
|
record.have_finalize = deferred_final_list ? Qtrue : Qfalse;\
|
|
|
|
record.heap_use_size = live * sizeof(RVALUE);\
|
|
|
|
record.heap_total_size = total * sizeof(RVALUE);\
|
2008-08-11 13:36:57 +04:00
|
|
|
} while(0)
|
2010-05-28 15:13:42 +04:00
|
|
|
#define GC_PROF_INC_LIVE_NUM objspace->heap.live_num++
|
|
|
|
#define GC_PROF_DEC_LIVE_NUM objspace->heap.live_num--
|
2008-08-11 13:36:57 +04:00
|
|
|
#else
|
|
|
|
#define INIT_GC_PROF_PARAMS double gc_time = 0;\
|
2010-05-28 15:13:42 +04:00
|
|
|
size_t count = objspace->profile.count, total = 0, live = 0
|
2008-08-11 13:36:57 +04:00
|
|
|
#define GC_PROF_MARK_TIMER_START
|
|
|
|
#define GC_PROF_MARK_TIMER_STOP
|
|
|
|
#define GC_PROF_SWEEP_TIMER_START
|
|
|
|
#define GC_PROF_SWEEP_TIMER_STOP
|
|
|
|
#define GC_PROF_SET_MALLOC_INFO
|
2010-05-28 15:13:42 +04:00
|
|
|
#define GC_PROF_SET_HEAP_INFO(record) do {\
|
|
|
|
live = objspace->heap.live_num;\
|
|
|
|
total = heaps_used * HEAP_OBJ_LIMIT;\
|
|
|
|
record.heap_total_objects = total;\
|
|
|
|
record.heap_use_size = live * sizeof(RVALUE);\
|
|
|
|
record.heap_total_size = total * sizeof(RVALUE);\
|
2008-08-11 13:36:57 +04:00
|
|
|
} while(0)
|
2010-05-28 15:13:42 +04:00
|
|
|
#define GC_PROF_INC_LIVE_NUM
|
|
|
|
#define GC_PROF_DEC_LIVE_NUM
|
2008-08-11 13:36:57 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
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;
|
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 {
|
2006-12-31 18:02:22 +03:00
|
|
|
void *membase;
|
|
|
|
RVALUE *slot;
|
2009-05-26 09:24:19 +04:00
|
|
|
size_t limit;
|
2010-05-28 15:13:42 +04:00
|
|
|
struct heaps_slot *next;
|
|
|
|
struct heaps_slot *prev;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sorted_heaps_slot {
|
|
|
|
RVALUE *start;
|
|
|
|
RVALUE *end;
|
|
|
|
struct heaps_slot *slot;
|
2008-04-14 07:47:04 +04:00
|
|
|
};
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
#define HEAP_MIN_SLOTS 10000
|
|
|
|
#define FREE_MIN 4096
|
|
|
|
|
2008-04-14 07:47:04 +04:00
|
|
|
struct gc_list {
|
|
|
|
VALUE *varptr;
|
|
|
|
struct gc_list *next;
|
|
|
|
};
|
|
|
|
|
2008-06-08 14:27:06 +04:00
|
|
|
#define CALC_EXACT_MALLOC_SIZE 0
|
|
|
|
|
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;
|
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;
|
|
|
|
struct sorted_heaps_slot *sorted;
|
2008-05-11 09:44:36 +04:00
|
|
|
size_t length;
|
|
|
|
size_t used;
|
2008-04-14 07:47:04 +04:00
|
|
|
RVALUE *freelist;
|
|
|
|
RVALUE *range[2];
|
2008-04-25 13:03:32 +04:00
|
|
|
RVALUE *freed;
|
2010-05-28 15:13:42 +04:00
|
|
|
size_t live_num;
|
|
|
|
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;
|
|
|
|
} flags;
|
|
|
|
struct {
|
|
|
|
st_table *table;
|
|
|
|
RVALUE *deferred;
|
|
|
|
} final;
|
|
|
|
struct {
|
|
|
|
VALUE buffer[MARK_STACK_MAX];
|
|
|
|
VALUE *ptr;
|
|
|
|
int overflow;
|
|
|
|
} markstack;
|
2008-08-11 13:36:57 +04:00
|
|
|
struct {
|
|
|
|
int run;
|
|
|
|
gc_profile_record *record;
|
|
|
|
size_t count;
|
|
|
|
size_t size;
|
|
|
|
double invoke_time;
|
|
|
|
} 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;
|
2008-06-13 19:09:22 +04:00
|
|
|
int gc_stress;
|
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)
|
2008-06-14 02:57:41 +04:00
|
|
|
static int ruby_initial_gc_stress = 0;
|
|
|
|
int *ruby_initial_gc_stress_ptr = &ruby_initial_gc_stress;
|
2008-04-27 07:20:35 +04:00
|
|
|
#else
|
2008-04-14 07:47:04 +04:00
|
|
|
static rb_objspace_t rb_objspace = {{GC_MALLOC_LIMIT}, {HEAP_MIN_SLOTS}};
|
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
|
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 freelist objspace->heap.freelist
|
|
|
|
#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
|
|
|
|
#define finalizer_table objspace->final.table
|
|
|
|
#define deferred_final_list objspace->final.deferred
|
|
|
|
#define mark_stack objspace->markstack.buffer
|
|
|
|
#define mark_stack_ptr objspace->markstack.ptr
|
|
|
|
#define mark_stack_overflow objspace->markstack.overflow
|
|
|
|
#define global_List objspace->global_list
|
2008-06-13 19:09:22 +04:00
|
|
|
#define ruby_gc_stress objspace->gc_stress
|
2008-04-14 07:47:04 +04:00
|
|
|
|
2009-09-18 11:29:17 +04:00
|
|
|
static void rb_objspace_call_finalizer(rb_objspace_t *objspace);
|
|
|
|
|
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));
|
|
|
|
malloc_limit = GC_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;
|
|
|
|
}
|
2009-09-18 11:29:17 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
rb_objspace_free(rb_objspace_t *objspace)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
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) {
|
2010-05-28 15:13:42 +04:00
|
|
|
free(objspace->heap.sorted[i].slot->membase);
|
|
|
|
free(objspace->heap.sorted[i].slot);
|
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;
|
|
|
|
}
|
|
|
|
free(objspace);
|
|
|
|
}
|
2008-06-05 18:41:41 +04:00
|
|
|
#endif
|
2008-04-14 07:47:04 +04:00
|
|
|
|
2008-04-25 13:03:32 +04:00
|
|
|
/* tiny heap size */
|
|
|
|
/* 32KB */
|
|
|
|
/*#define HEAP_SIZE 0x8000 */
|
|
|
|
/* 128KB */
|
|
|
|
/*#define HEAP_SIZE 0x20000 */
|
|
|
|
/* 64KB */
|
|
|
|
/*#define HEAP_SIZE 0x10000 */
|
|
|
|
/* 16KB */
|
|
|
|
#define HEAP_SIZE 0x4000
|
|
|
|
/* 8KB */
|
|
|
|
/*#define HEAP_SIZE 0x2000 */
|
|
|
|
/* 4KB */
|
|
|
|
/*#define HEAP_SIZE 0x1000 */
|
|
|
|
/* 2KB */
|
|
|
|
/*#define HEAP_SIZE 0x800 */
|
|
|
|
|
|
|
|
#define HEAP_OBJ_LIMIT (HEAP_SIZE / sizeof(struct RVALUE))
|
|
|
|
|
2008-11-07 23:47:02 +03:00
|
|
|
extern VALUE rb_cMutex;
|
2006-12-31 18:02:22 +03:00
|
|
|
extern st_table *rb_class_tbl;
|
|
|
|
|
2008-06-13 19:09:22 +04:00
|
|
|
int ruby_disable_gc_stress = 0;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2008-04-27 07:20:35 +04:00
|
|
|
static void run_final(rb_objspace_t *objspace, VALUE obj);
|
|
|
|
static int garbage_collect(rb_objspace_t *objspace);
|
2010-05-28 15:13:42 +04:00
|
|
|
static int gc_lazy_sweep(rb_objspace_t *objspace);
|
1998-01-16 15:13:05 +03: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 *
|
|
|
|
ruby_memerror_body(void *dummy)
|
|
|
|
{
|
|
|
|
rb_memerror();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ruby_memerror(void)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
void
|
|
|
|
rb_memerror(void)
|
|
|
|
{
|
2008-03-12 08:47:10 +03:00
|
|
|
rb_thread_t *th = GET_THREAD();
|
|
|
|
if (!nomem_error ||
|
|
|
|
(rb_thread_raised_p(th, RAISED_NOMEMORY) && rb_safe_level() < 4)) {
|
2002-04-24 08:54:16 +04:00
|
|
|
fprintf(stderr, "[FATAL] failed to allocate memory\n");
|
2008-06-13 09:24:40 +04:00
|
|
|
exit(EXIT_FAILURE);
|
1999-12-14 09:50:43 +03:00
|
|
|
}
|
2008-06-15 13:17:06 +04:00
|
|
|
if (rb_thread_raised_p(th, RAISED_NOMEMORY)) {
|
|
|
|
rb_thread_raised_clear(th);
|
|
|
|
GET_THREAD()->errinfo = nomem_error;
|
|
|
|
JUMP_TAG(TAG_RAISE);
|
|
|
|
}
|
2008-03-12 08:47:10 +03:00
|
|
|
rb_thread_raised_set(th, RAISED_NOMEMORY);
|
2002-04-24 08:54:16 +04:00
|
|
|
rb_exc_raise(nomem_error);
|
1999-12-14 09:50:43 +03:00
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2006-01-10 01:32:55 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* GC.stress -> true or false
|
2006-01-10 01:32:55 +03:00
|
|
|
*
|
|
|
|
* returns current status of GC stress mode.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
gc_stress_get(VALUE self)
|
|
|
|
{
|
2008-06-13 19:09:22 +04:00
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
2007-06-29 11:57:24 +04:00
|
|
|
return ruby_gc_stress ? Qtrue : Qfalse;
|
2006-01-10 01:32:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* GC.stress = bool -> bool
|
2006-01-10 01:32:55 +03:00
|
|
|
*
|
|
|
|
* updates GC stress mode.
|
|
|
|
*
|
|
|
|
* When GC.stress = true, GC is invoked for all GC opportunity:
|
|
|
|
* all memory and object allocation.
|
|
|
|
*
|
|
|
|
* Since it makes Ruby very slow, it is only for debugging.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
2009-03-13 04:42:21 +03:00
|
|
|
gc_stress_set(VALUE self, VALUE flag)
|
2006-01-10 01:32:55 +03:00
|
|
|
{
|
2008-06-13 19:09:22 +04:00
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
2006-01-10 01:32:55 +03:00
|
|
|
rb_secure(2);
|
2009-03-13 04:42:21 +03:00
|
|
|
ruby_gc_stress = RTEST(flag);
|
|
|
|
return flag;
|
2006-01-10 01:32:55 +03:00
|
|
|
}
|
2005-12-12 03:36:54 +03:00
|
|
|
|
2008-08-11 13:36:57 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* GC::Profiler.enable? -> true or false
|
2008-08-11 13:36:57 +04:00
|
|
|
*
|
|
|
|
* returns current status of GC profile mode.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
gc_profile_enable_get(VALUE self)
|
|
|
|
{
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
return objspace->profile.run;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* GC::Profiler.enable -> nil
|
2008-08-11 13:36:57 +04:00
|
|
|
*
|
|
|
|
* updates GC profile mode.
|
|
|
|
* start profiler for GC.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
gc_profile_enable(void)
|
|
|
|
{
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
|
2009-07-18 12:05:32 +04:00
|
|
|
objspace->profile.run = TRUE;
|
2008-08-11 13:36:57 +04:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* GC::Profiler.disable -> nil
|
2008-08-11 13:36:57 +04:00
|
|
|
*
|
|
|
|
* updates GC profile mode.
|
|
|
|
* stop profiler for GC.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
gc_profile_disable(void)
|
|
|
|
{
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
|
2009-07-18 12:05:32 +04:00
|
|
|
objspace->profile.run = FALSE;
|
2008-08-11 13:36:57 +04:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* GC::Profiler.clear -> nil
|
2008-08-11 13:36:57 +04:00
|
|
|
*
|
|
|
|
* clear before profile data.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
gc_profile_clear(void)
|
|
|
|
{
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
MEMZERO(objspace->profile.record, gc_profile_record, objspace->profile.size);
|
|
|
|
objspace->profile.count = 0;
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2009-01-12 06:41:20 +03:00
|
|
|
static void *
|
|
|
|
negative_size_allocation_error_with_gvl(void *ptr)
|
|
|
|
{
|
2009-01-14 16:39:17 +03:00
|
|
|
rb_raise(rb_eNoMemError, "%s", (const char *)ptr);
|
2009-01-12 06:41:20 +03:00
|
|
|
return 0; /* should not be reached */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
negative_size_allocation_error(const char *msg)
|
|
|
|
{
|
|
|
|
if (ruby_thread_has_gvl_p()) {
|
2009-01-14 16:39:17 +03:00
|
|
|
rb_raise(rb_eNoMemError, "%s", msg);
|
2009-01-12 06:41:20 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
|
|
|
gc_with_gvl(void *ptr)
|
|
|
|
{
|
2009-01-15 18:21:43 +03:00
|
|
|
return (void *)(VALUE)garbage_collect((rb_objspace_t *)ptr);
|
2009-01-12 06:41:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
garbage_collect_with_gvl(rb_objspace_t *objspace)
|
|
|
|
{
|
2009-10-27 02:06:39 +03:00
|
|
|
if (dont_gc) return TRUE;
|
2009-01-12 06:41:20 +03:00
|
|
|
if (ruby_thread_has_gvl_p()) {
|
|
|
|
return garbage_collect(objspace);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (ruby_native_thread_p()) {
|
2009-05-26 09:24:19 +04:00
|
|
|
return (int)(VALUE)rb_thread_call_with_gvl(gc_with_gvl, (void *)objspace);
|
2009-01-12 06:41:20 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* no ruby thread */
|
|
|
|
fprintf(stderr, "[FATAL] failed to allocate memory\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-17 13:34:20 +04:00
|
|
|
static void vm_xfree(rb_objspace_t *objspace, void *ptr);
|
|
|
|
|
2008-06-08 14:27:06 +04:00
|
|
|
static void *
|
|
|
|
vm_xmalloc(rb_objspace_t *objspace, size_t size)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
void *mem;
|
|
|
|
|
2009-02-12 17:28:58 +03:00
|
|
|
if ((ssize_t)size < 0) {
|
2009-01-12 06:41:20 +03:00
|
|
|
negative_size_allocation_error("negative allocation size (or too big)");
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
if (size == 0) size = 1;
|
2000-09-25 21:51:29 +04:00
|
|
|
|
2008-06-08 14:27:06 +04:00
|
|
|
#if CALC_EXACT_MALLOC_SIZE
|
|
|
|
size += sizeof(size_t);
|
|
|
|
#endif
|
|
|
|
|
2008-06-13 19:09:22 +04:00
|
|
|
if ((ruby_gc_stress && !ruby_disable_gc_stress) ||
|
|
|
|
(malloc_increase+size) > malloc_limit) {
|
2009-01-12 06:41:20 +03:00
|
|
|
garbage_collect_with_gvl(objspace);
|
2002-10-10 19:26:58 +04:00
|
|
|
}
|
* include/ruby/signal.h: removed.
* common.mk, class.c, eval.c, eval_intern.h, file.c, gc.c, hash.c,
io.c, process.c, signal.c: vm_core.h: ditto.
Some unused external global variables are also removed.
(rb_prohibit_interrupt, rb_trap_immediate, rb_trap_pending,
rb_thread_critical)
* ext/openssl/ossl_ssl.c, ext/openssl/ossl_x509store.c,
ext/readline/readline.c, ext/socket/depend,
ext/socket/socket.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19080 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-03 12:00:05 +04:00
|
|
|
mem = malloc(size);
|
1998-01-16 15:13:05 +03:00
|
|
|
if (!mem) {
|
2009-01-12 06:41:20 +03:00
|
|
|
if (garbage_collect_with_gvl(objspace)) {
|
* include/ruby/signal.h: removed.
* common.mk, class.c, eval.c, eval_intern.h, file.c, gc.c, hash.c,
io.c, process.c, signal.c: vm_core.h: ditto.
Some unused external global variables are also removed.
(rb_prohibit_interrupt, rb_trap_immediate, rb_trap_pending,
rb_thread_critical)
* ext/openssl/ossl_ssl.c, ext/openssl/ossl_x509store.c,
ext/readline/readline.c, ext/socket/depend,
ext/socket/socket.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19080 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-03 12:00:05 +04:00
|
|
|
mem = malloc(size);
|
2005-09-16 17:44:59 +04:00
|
|
|
}
|
1999-12-14 09:50:43 +03:00
|
|
|
if (!mem) {
|
2009-01-12 06:41:20 +03:00
|
|
|
ruby_memerror();
|
1999-12-14 09:50:43 +03:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2008-05-12 10:28:43 +04:00
|
|
|
malloc_increase += size;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2008-06-08 14:27:06 +04:00
|
|
|
#if CALC_EXACT_MALLOC_SIZE
|
|
|
|
objspace->malloc_params.allocated_size += size;
|
|
|
|
objspace->malloc_params.allocations++;
|
|
|
|
((size_t *)mem)[0] = size;
|
|
|
|
mem = (size_t *)mem + 1;
|
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
|
2008-06-08 14:27:06 +04:00
|
|
|
static void *
|
|
|
|
vm_xrealloc(rb_objspace_t *objspace, void *ptr, size_t size)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
void *mem;
|
|
|
|
|
2009-02-12 17:28:58 +03:00
|
|
|
if ((ssize_t)size < 0) {
|
2009-01-12 06:41:20 +03:00
|
|
|
negative_size_allocation_error("negative re-allocation size");
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
2009-11-13 05:09:33 +03:00
|
|
|
if (!ptr) return vm_xmalloc(objspace, size);
|
2009-09-17 13:34:20 +04:00
|
|
|
if (size == 0) {
|
|
|
|
vm_xfree(objspace, ptr);
|
|
|
|
return 0;
|
|
|
|
}
|
2009-01-12 06:41:20 +03:00
|
|
|
if (ruby_gc_stress && !ruby_disable_gc_stress)
|
2009-04-19 09:43:20 +04:00
|
|
|
garbage_collect_with_gvl(objspace);
|
2008-06-08 14:27:06 +04:00
|
|
|
|
|
|
|
#if CALC_EXACT_MALLOC_SIZE
|
|
|
|
size += sizeof(size_t);
|
|
|
|
objspace->malloc_params.allocated_size -= size;
|
|
|
|
ptr = (size_t *)ptr - 1;
|
|
|
|
#endif
|
2008-07-05 11:15:41 +04:00
|
|
|
|
* include/ruby/signal.h: removed.
* common.mk, class.c, eval.c, eval_intern.h, file.c, gc.c, hash.c,
io.c, process.c, signal.c: vm_core.h: ditto.
Some unused external global variables are also removed.
(rb_prohibit_interrupt, rb_trap_immediate, rb_trap_pending,
rb_thread_critical)
* ext/openssl/ossl_ssl.c, ext/openssl/ossl_x509store.c,
ext/readline/readline.c, ext/socket/depend,
ext/socket/socket.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19080 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-03 12:00:05 +04:00
|
|
|
mem = realloc(ptr, size);
|
1998-01-16 15:13:05 +03:00
|
|
|
if (!mem) {
|
2009-01-12 06:41:20 +03:00
|
|
|
if (garbage_collect_with_gvl(objspace)) {
|
* include/ruby/signal.h: removed.
* common.mk, class.c, eval.c, eval_intern.h, file.c, gc.c, hash.c,
io.c, process.c, signal.c: vm_core.h: ditto.
Some unused external global variables are also removed.
(rb_prohibit_interrupt, rb_trap_immediate, rb_trap_pending,
rb_thread_critical)
* ext/openssl/ossl_ssl.c, ext/openssl/ossl_x509store.c,
ext/readline/readline.c, ext/socket/depend,
ext/socket/socket.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19080 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-03 12:00:05 +04:00
|
|
|
mem = realloc(ptr, size);
|
2005-09-16 17:44:59 +04:00
|
|
|
}
|
2001-07-20 19:20:25 +04:00
|
|
|
if (!mem) {
|
2009-01-12 06:41:20 +03:00
|
|
|
ruby_memerror();
|
2001-07-20 19:20:25 +04:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2008-05-12 10:28:43 +04:00
|
|
|
malloc_increase += size;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2008-06-08 14:27:06 +04:00
|
|
|
#if CALC_EXACT_MALLOC_SIZE
|
|
|
|
objspace->malloc_params.allocated_size += size;
|
|
|
|
((size_t *)mem)[0] = size;
|
|
|
|
mem = (size_t *)mem + 1;
|
|
|
|
#endif
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
|
2008-06-08 14:27:06 +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];
|
|
|
|
objspace->malloc_params.allocated_size -= size;
|
|
|
|
objspace->malloc_params.allocations--;
|
|
|
|
#endif
|
|
|
|
|
* include/ruby/signal.h: removed.
* common.mk, class.c, eval.c, eval_intern.h, file.c, gc.c, hash.c,
io.c, process.c, signal.c: vm_core.h: ditto.
Some unused external global variables are also removed.
(rb_prohibit_interrupt, rb_trap_immediate, rb_trap_pending,
rb_thread_critical)
* ext/openssl/ossl_ssl.c, ext/openssl/ossl_x509store.c,
ext/readline/readline.c, ext/socket/depend,
ext/socket/socket.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19080 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-03 12:00:05 +04:00
|
|
|
free(ptr);
|
2008-06-08 14:27:06 +04:00
|
|
|
}
|
|
|
|
|
2005-10-05 20:15:16 +04:00
|
|
|
void *
|
2008-06-08 14:27:06 +04:00
|
|
|
ruby_xmalloc(size_t size)
|
2008-04-27 07:20:35 +04:00
|
|
|
{
|
2008-06-08 14:27:06 +04:00
|
|
|
return vm_xmalloc(&rb_objspace, size);
|
2008-04-27 07:20:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2008-06-08 14:27:06 +04:00
|
|
|
ruby_xmalloc2(size_t n, size_t size)
|
2005-10-05 20:15:16 +04:00
|
|
|
{
|
2005-12-06 10:52:18 +03:00
|
|
|
size_t len = size * n;
|
|
|
|
if (n != 0 && size != len / n) {
|
2008-06-08 14:27:06 +04:00
|
|
|
rb_raise(rb_eArgError, "malloc: possible integer overflow");
|
2005-10-05 20:15:16 +04:00
|
|
|
}
|
2008-06-08 14:27:06 +04:00
|
|
|
return vm_xmalloc(&rb_objspace, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
ruby_xcalloc(size_t n, size_t size)
|
|
|
|
{
|
|
|
|
void *mem = ruby_xmalloc2(n, size);
|
|
|
|
memset(mem, 0, n * size);
|
|
|
|
|
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
ruby_xrealloc(void *ptr, size_t size)
|
|
|
|
{
|
|
|
|
return vm_xrealloc(&rb_objspace, ptr, size);
|
2008-04-27 07:20:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
ruby_xrealloc2(void *ptr, size_t n, size_t size)
|
|
|
|
{
|
2008-06-08 14:27:06 +04:00
|
|
|
size_t len = size * n;
|
|
|
|
if (n != 0 && size != len / n) {
|
|
|
|
rb_raise(rb_eArgError, "realloc: possible integer overflow");
|
|
|
|
}
|
|
|
|
return ruby_xrealloc(ptr, len);
|
2005-10-05 20:15:16 +04:00
|
|
|
}
|
|
|
|
|
2000-02-08 11:54:01 +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
|
|
|
ruby_xfree(void *x)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
2000-11-14 10:10:31 +03:00
|
|
|
if (x)
|
2009-11-13 05:09:33 +03:00
|
|
|
vm_xfree(&rb_objspace, x);
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
|
2003-12-22 09:20:14 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* GC.enable -> true or false
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
2003-12-22 09:20:14 +03:00
|
|
|
* Enables garbage collection, returning <code>true</code> if garbage
|
|
|
|
* collection was previously disabled.
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
2003-12-22 09:20:14 +03:00
|
|
|
* GC.disable #=> false
|
|
|
|
* GC.enable #=> true
|
|
|
|
* GC.enable #=> false
|
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_enable(void)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-04-27 07:20:35 +04:00
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
1998-01-16 15:13:05 +03:00
|
|
|
int old = dont_gc;
|
|
|
|
|
2009-07-18 12:05:32 +04:00
|
|
|
dont_gc = FALSE;
|
2009-07-21 07:45:37 +04:00
|
|
|
return old ? Qtrue : Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-22 09:20:14 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* GC.disable -> true or false
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
2003-12-22 09:20:14 +03:00
|
|
|
* Disables garbage collection, returning <code>true</code> if garbage
|
|
|
|
* collection was already disabled.
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
2003-12-22 09:20:14 +03:00
|
|
|
* GC.disable #=> false
|
|
|
|
* GC.disable #=> true
|
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_disable(void)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-04-27 07:20:35 +04:00
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
1998-01-16 15:13:05 +03:00
|
|
|
int old = dont_gc;
|
|
|
|
|
2009-07-18 12:05:32 +04:00
|
|
|
dont_gc = TRUE;
|
2009-07-21 07:45:37 +04:00
|
|
|
return old ? Qtrue : Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE rb_mGC;
|
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
|
* gc.c, include/ruby/ruby.h: rename rb_register_mark_object()
to rb_gc_register_mark_object().
* eval.c, vm.c: initialize vm->mark_object_ary at
Init_top_self().
* bignum.c, complex.c, encoding.c, ext/win32ole/win32ole.c,
io.c, load.c, marshal.c, rational.c, ruby.c, vm.c:
use rb_gc_register_mark_object() instead of
rb_global_variable() or rb_gc_register_address().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19365 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-15 18:59:14 +04:00
|
|
|
rb_gc_register_mark_object(VALUE obj)
|
* 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
|
|
|
{
|
|
|
|
VALUE ary = GET_THREAD()->vm->mark_object_ary;
|
|
|
|
rb_ary_push(ary, obj);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
rb_gc_register_address(VALUE *addr)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-04-27 07:20:35 +04:00
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
1998-01-16 15:13:05 +03:00
|
|
|
struct gc_list *tmp;
|
|
|
|
|
|
|
|
tmp = ALLOC(struct gc_list);
|
2001-10-31 09:53:22 +03:00
|
|
|
tmp->next = global_List;
|
2000-02-08 11:54:01 +03:00
|
|
|
tmp->varptr = addr;
|
2001-10-31 09:53:22 +03:00
|
|
|
global_List = tmp;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2000-02-08 11:54:01 +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
|
|
|
rb_gc_unregister_address(VALUE *addr)
|
2000-02-08 11:54:01 +03:00
|
|
|
{
|
2008-04-27 07:20:35 +04:00
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
2001-10-31 09:53:22 +03:00
|
|
|
struct gc_list *tmp = global_List;
|
2000-02-08 11:54:01 +03:00
|
|
|
|
|
|
|
if (tmp->varptr == addr) {
|
2001-10-31 09:53:22 +03:00
|
|
|
global_List = tmp->next;
|
* 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
|
|
|
xfree(tmp);
|
2000-02-08 11:54:01 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
while (tmp->next) {
|
|
|
|
if (tmp->next->varptr == addr) {
|
|
|
|
struct gc_list *t = tmp->next;
|
|
|
|
|
|
|
|
tmp->next = tmp->next->next;
|
* 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
|
|
|
xfree(t);
|
2000-02-08 11:54:01 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
tmp = tmp->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-25 13:03:32 +04:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static void
|
2010-05-28 15:13:42 +04:00
|
|
|
allocate_sorted_heaps(rb_objspace_t *objspace, size_t next_heaps_length)
|
2008-04-25 13:03:32 +04:00
|
|
|
{
|
2010-05-28 15:13:42 +04:00
|
|
|
struct sorted_heaps_slot *p;
|
2010-05-29 03:46:44 +04:00
|
|
|
size_t size;
|
2008-04-25 13:03:32 +04:00
|
|
|
|
2010-05-28 15:13:42 +04:00
|
|
|
size = next_heaps_length*sizeof(struct sorted_heaps_slot);
|
* include/ruby/signal.h: removed.
* common.mk, class.c, eval.c, eval_intern.h, file.c, gc.c, hash.c,
io.c, process.c, signal.c: vm_core.h: ditto.
Some unused external global variables are also removed.
(rb_prohibit_interrupt, rb_trap_immediate, rb_trap_pending,
rb_thread_critical)
* ext/openssl/ossl_ssl.c, ext/openssl/ossl_x509store.c,
ext/readline/readline.c, ext/socket/depend,
ext/socket/socket.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19080 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-03 12:00:05 +04:00
|
|
|
|
|
|
|
if (heaps_used > 0) {
|
2010-05-28 15:13:42 +04:00
|
|
|
p = (struct sorted_heaps_slot *)realloc(objspace->heap.sorted, size);
|
|
|
|
if (p) objspace->heap.sorted = p;
|
* include/ruby/signal.h: removed.
* common.mk, class.c, eval.c, eval_intern.h, file.c, gc.c, hash.c,
io.c, process.c, signal.c: vm_core.h: ditto.
Some unused external global variables are also removed.
(rb_prohibit_interrupt, rb_trap_immediate, rb_trap_pending,
rb_thread_critical)
* ext/openssl/ossl_ssl.c, ext/openssl/ossl_x509store.c,
ext/readline/readline.c, ext/socket/depend,
ext/socket/socket.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19080 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-03 12:00:05 +04:00
|
|
|
}
|
|
|
|
else {
|
2010-05-28 15:13:42 +04:00
|
|
|
p = objspace->heap.sorted = (struct sorted_heaps_slot *)malloc(size);
|
* include/ruby/signal.h: removed.
* common.mk, class.c, eval.c, eval_intern.h, file.c, gc.c, hash.c,
io.c, process.c, signal.c: vm_core.h: ditto.
Some unused external global variables are also removed.
(rb_prohibit_interrupt, rb_trap_immediate, rb_trap_pending,
rb_thread_critical)
* ext/openssl/ossl_ssl.c, ext/openssl/ossl_x509store.c,
ext/readline/readline.c, ext/socket/depend,
ext/socket/socket.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19080 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-03 12:00:05 +04:00
|
|
|
}
|
|
|
|
|
2008-08-01 16:36:39 +04:00
|
|
|
if (p == 0) {
|
|
|
|
during_gc = 0;
|
|
|
|
rb_memerror();
|
|
|
|
}
|
2008-05-11 09:44:36 +04:00
|
|
|
heaps_length = next_heaps_length;
|
2008-04-25 13:03:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-08-10 06:40:34 +04:00
|
|
|
assign_heap_slot(rb_objspace_t *objspace)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-03-04 04:21:06 +03:00
|
|
|
RVALUE *p, *pend, *membase;
|
2010-05-28 15:13:42 +04:00
|
|
|
struct heaps_slot *slot;
|
2008-05-11 09:44:36 +04:00
|
|
|
size_t hi, lo, mid;
|
2009-05-26 09:24:19 +04:00
|
|
|
size_t objs;
|
2009-02-22 17:23:33 +03:00
|
|
|
|
2008-04-25 13:03:32 +04:00
|
|
|
objs = HEAP_OBJ_LIMIT;
|
* include/ruby/signal.h: removed.
* common.mk, class.c, eval.c, eval_intern.h, file.c, gc.c, hash.c,
io.c, process.c, signal.c: vm_core.h: ditto.
Some unused external global variables are also removed.
(rb_prohibit_interrupt, rb_trap_immediate, rb_trap_pending,
rb_thread_critical)
* ext/openssl/ossl_ssl.c, ext/openssl/ossl_x509store.c,
ext/readline/readline.c, ext/socket/depend,
ext/socket/socket.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19080 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-03 12:00:05 +04:00
|
|
|
p = (RVALUE*)malloc(HEAP_SIZE);
|
2010-05-28 15:13:42 +04:00
|
|
|
slot = (struct heaps_slot *)malloc(sizeof(struct heaps_slot));
|
|
|
|
MEMZERO((void*)slot, struct heaps_slot, 1);
|
* include/ruby/signal.h: removed.
* common.mk, class.c, eval.c, eval_intern.h, file.c, gc.c, hash.c,
io.c, process.c, signal.c: vm_core.h: ditto.
Some unused external global variables are also removed.
(rb_prohibit_interrupt, rb_trap_immediate, rb_trap_pending,
rb_thread_critical)
* ext/openssl/ossl_ssl.c, ext/openssl/ossl_x509store.c,
ext/readline/readline.c, ext/socket/depend,
ext/socket/socket.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19080 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-03 12:00:05 +04:00
|
|
|
|
2010-05-28 15:13:42 +04:00
|
|
|
if (p == 0 || slot == 0) {
|
2008-08-01 16:36:39 +04:00
|
|
|
during_gc = 0;
|
2008-04-25 13:03:32 +04:00
|
|
|
rb_memerror();
|
2008-08-01 16:36:39 +04:00
|
|
|
}
|
2008-03-04 04:21:06 +03:00
|
|
|
|
2010-05-28 15:13:42 +04:00
|
|
|
slot->next = heaps;
|
|
|
|
if (heaps) heaps->prev = slot;
|
|
|
|
heaps = slot;
|
|
|
|
|
2008-05-12 06:15:55 +04:00
|
|
|
membase = p;
|
|
|
|
if ((VALUE)p % sizeof(RVALUE) != 0) {
|
|
|
|
p = (RVALUE*)((VALUE)p + sizeof(RVALUE) - ((VALUE)p % sizeof(RVALUE)));
|
2009-05-26 09:24:19 +04:00
|
|
|
if ((HEAP_SIZE - HEAP_OBJ_LIMIT * sizeof(RVALUE)) < (size_t)((char*)p - (char*)membase)) {
|
2008-05-12 06:15:55 +04:00
|
|
|
objs--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-04 04:21:06 +03:00
|
|
|
lo = 0;
|
|
|
|
hi = heaps_used;
|
|
|
|
while (lo < hi) {
|
2008-05-12 06:15:55 +04:00
|
|
|
register RVALUE *mid_membase;
|
2008-03-04 04:21:06 +03:00
|
|
|
mid = (lo + hi) / 2;
|
2010-05-28 15:13:42 +04:00
|
|
|
mid_membase = objspace->heap.sorted[mid].slot->membase;
|
2008-05-12 06:15:55 +04:00
|
|
|
if (mid_membase < membase) {
|
2008-03-04 04:21:06 +03:00
|
|
|
lo = mid + 1;
|
|
|
|
}
|
2008-05-12 06:15:55 +04:00
|
|
|
else if (mid_membase > membase) {
|
2008-03-04 04:21:06 +03:00
|
|
|
hi = mid;
|
|
|
|
}
|
|
|
|
else {
|
* compile.c (iseq_compile_each), gc.c (assign_heap_slot),
(gc_mark_children), parse.y (vtable_alloc, vtable_free, vtable_add),
proc.c (proc_to_s), thread.c (terminate_i, rb_thread_terminate_all),
(thread_start_func_2, blocking_region_begin, blocking_region_end),
(rb_thread_kill), thread_pthread.c (native_thread_create),
(ubf_pthread_cond_signal), vm.c (check_env, thread_free), vm_dump.c
(vm_env_dump_raw, vm_stack_dump_each, vm_thread_dump_state),
(vm_call0): use void pointer for %p.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20593 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-12-09 07:33:55 +03:00
|
|
|
rb_bug("same heap slot is allocated: %p at %"PRIuVALUE, (void *)membase, (VALUE)mid);
|
2008-04-25 13:03:32 +04:00
|
|
|
}
|
|
|
|
}
|
2008-03-04 04:21:06 +03:00
|
|
|
if (hi < heaps_used) {
|
2010-05-28 15:13:42 +04:00
|
|
|
MEMMOVE(&objspace->heap.sorted[hi+1], &objspace->heap.sorted[hi], struct sorted_heaps_slot, heaps_used - hi);
|
|
|
|
}
|
|
|
|
objspace->heap.sorted[hi].slot = slot;
|
|
|
|
objspace->heap.sorted[hi].start = p;
|
|
|
|
objspace->heap.sorted[hi].end = (p + objs);
|
|
|
|
heaps->membase = membase;
|
|
|
|
heaps->slot = p;
|
|
|
|
heaps->limit = objs;
|
2010-06-06 08:12:20 +04:00
|
|
|
objspace->heap.free_num += objs;
|
2008-04-25 13:03:32 +04:00
|
|
|
pend = p + objs;
|
1998-01-16 15:13:05 +03:00
|
|
|
if (lomem == 0 || lomem > p) lomem = p;
|
|
|
|
if (himem < pend) himem = pend;
|
2001-07-02 12:46:28 +04:00
|
|
|
heaps_used++;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
while (p < pend) {
|
2001-02-02 14:38:20 +03:00
|
|
|
p->as.free.flags = 0;
|
2009-08-10 06:40:34 +04:00
|
|
|
p->as.free.next = freelist;
|
|
|
|
freelist = p;
|
1998-01-16 15:13:05 +03:00
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
2008-03-03 11:27:43 +03:00
|
|
|
|
2008-04-25 13:03:32 +04:00
|
|
|
static void
|
2008-05-04 21:25:38 +04:00
|
|
|
init_heap(rb_objspace_t *objspace)
|
2008-04-25 13:03:32 +04:00
|
|
|
{
|
2008-05-11 09:44:36 +04:00
|
|
|
size_t add, i;
|
2008-04-25 13:03:32 +04:00
|
|
|
|
2008-05-04 21:25:38 +04:00
|
|
|
add = HEAP_MIN_SLOTS / HEAP_OBJ_LIMIT;
|
2008-04-25 13:03:32 +04:00
|
|
|
|
2009-03-23 08:58:15 +03:00
|
|
|
if (!add) {
|
|
|
|
add = 1;
|
|
|
|
}
|
|
|
|
|
2008-04-25 13:03:32 +04:00
|
|
|
if ((heaps_used + add) > heaps_length) {
|
2010-05-28 15:13:42 +04:00
|
|
|
allocate_sorted_heaps(objspace, heaps_used + add);
|
2008-04-25 13:03:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < add; i++) {
|
2009-08-10 06:40:34 +04:00
|
|
|
assign_heap_slot(objspace);
|
2008-04-25 13:03:32 +04:00
|
|
|
}
|
|
|
|
heaps_inc = 0;
|
2008-08-11 13:36:57 +04:00
|
|
|
objspace->profile.invoke_time = getrusage_time();
|
2010-10-31 18:41:14 +03:00
|
|
|
finalizer_table = st_init_numtable();
|
2008-04-25 13:03:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-04-27 07:20:35 +04:00
|
|
|
set_heaps_increment(rb_objspace_t *objspace)
|
2008-04-25 13:03:32 +04:00
|
|
|
{
|
2009-03-10 08:43:14 +03:00
|
|
|
size_t next_heaps_length = (size_t)(heaps_used * 1.8);
|
2009-03-23 08:58:15 +03:00
|
|
|
|
|
|
|
if (next_heaps_length == heaps_used) {
|
|
|
|
next_heaps_length++;
|
|
|
|
}
|
|
|
|
|
2008-05-11 09:44:36 +04:00
|
|
|
heaps_inc = next_heaps_length - heaps_used;
|
2008-04-25 13:03:32 +04:00
|
|
|
|
2008-05-11 09:44:36 +04:00
|
|
|
if (next_heaps_length > heaps_length) {
|
2010-05-28 15:13:42 +04:00
|
|
|
allocate_sorted_heaps(objspace, next_heaps_length);
|
2008-04-25 13:03:32 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2008-04-27 07:20:35 +04:00
|
|
|
heaps_increment(rb_objspace_t *objspace)
|
2008-04-25 13:03:32 +04:00
|
|
|
{
|
|
|
|
if (heaps_inc > 0) {
|
2009-08-10 06:40:34 +04:00
|
|
|
assign_heap_slot(objspace);
|
2008-04-25 13:03:32 +04:00
|
|
|
heaps_inc--;
|
2009-07-18 12:05:32 +04:00
|
|
|
return TRUE;
|
2008-04-25 13:03:32 +04:00
|
|
|
}
|
2009-07-18 12:05:32 +04:00
|
|
|
return FALSE;
|
2008-04-25 13:03:32 +04:00
|
|
|
}
|
|
|
|
|
2010-11-03 04:01:12 +03:00
|
|
|
int
|
|
|
|
rb_during_gc(void)
|
|
|
|
{
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
return during_gc;
|
|
|
|
}
|
|
|
|
|
2008-07-05 11:15:41 +04:00
|
|
|
#define RANY(o) ((RVALUE*)(o))
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static VALUE
|
2008-04-27 07:20:35 +04:00
|
|
|
rb_newobj_from_heap(rb_objspace_t *objspace)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE obj;
|
2009-02-22 17:23:33 +03:00
|
|
|
|
2008-06-13 19:09:22 +04:00
|
|
|
if ((ruby_gc_stress && !ruby_disable_gc_stress) || !freelist) {
|
2010-05-28 15:13:42 +04:00
|
|
|
if (!gc_lazy_sweep(objspace)) {
|
2008-08-01 16:36:39 +04:00
|
|
|
during_gc = 0;
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_memerror();
|
|
|
|
}
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-08-07 09:05:04 +04:00
|
|
|
obj = (VALUE)freelist;
|
|
|
|
freelist = freelist->as.free.next;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2000-08-09 08:32:24 +04:00
|
|
|
MEMZERO((void*)obj, RVALUE, 1);
|
2003-12-20 19:59:09 +03:00
|
|
|
#ifdef GC_DEBUG
|
2007-06-25 00:33:04 +04:00
|
|
|
RANY(obj)->file = rb_sourcefile();
|
|
|
|
RANY(obj)->line = rb_sourceline();
|
2003-12-20 19:59:09 +03:00
|
|
|
#endif
|
2010-05-28 15:13:42 +04:00
|
|
|
GC_PROF_INC_LIVE_NUM;
|
2008-04-25 13:03:32 +04:00
|
|
|
|
2000-08-07 09:05:04 +04:00
|
|
|
return obj;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
VALUE
|
|
|
|
rb_newobj(void)
|
|
|
|
{
|
2008-04-27 07:20:35 +04:00
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2008-06-30 19:49:13 +04:00
|
|
|
if (during_gc) {
|
|
|
|
dont_gc = 1;
|
|
|
|
during_gc = 0;
|
|
|
|
rb_bug("object allocation during garbage collection phase");
|
|
|
|
}
|
2008-06-18 18:09:33 +04:00
|
|
|
|
2008-04-27 07:20:35 +04:00
|
|
|
return rb_newobj_from_heap(objspace);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 12:12:18 +04:00
|
|
|
NODE*
|
|
|
|
rb_node_newnode(enum node_type type, VALUE a0, VALUE a1, VALUE a2)
|
|
|
|
{
|
|
|
|
NODE *n = (NODE*)rb_newobj();
|
|
|
|
|
|
|
|
n->flags |= T_NODE;
|
|
|
|
nd_set_type(n, type);
|
|
|
|
|
|
|
|
n->u1.value = a0;
|
|
|
|
n->u2.value = a1;
|
|
|
|
n->u3.value = a2;
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +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_data_object_alloc(VALUE klass, void *datap, RUBY_DATA_FUNC dmark, RUBY_DATA_FUNC dfree)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1998-01-16 15:19:22 +03:00
|
|
|
NEWOBJ(data, struct RData);
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
if (klass) Check_Type(klass, T_CLASS);
|
1999-01-20 07:59:39 +03:00
|
|
|
OBJSETUP(data, klass, T_DATA);
|
1998-01-16 15:13:05 +03:00
|
|
|
data->data = datap;
|
|
|
|
data->dfree = dfree;
|
|
|
|
data->dmark = dmark;
|
|
|
|
|
|
|
|
return (VALUE)data;
|
|
|
|
}
|
|
|
|
|
2009-06-17 01:36:50 +04:00
|
|
|
VALUE
|
|
|
|
rb_data_typed_object_alloc(VALUE klass, void *datap, const rb_data_type_t *type)
|
|
|
|
{
|
|
|
|
NEWOBJ(data, struct RTypedData);
|
|
|
|
|
|
|
|
if (klass) Check_Type(klass, T_CLASS);
|
|
|
|
|
|
|
|
OBJSETUP(data, klass, T_DATA);
|
|
|
|
|
|
|
|
data->data = datap;
|
|
|
|
data->typed_flag = 1;
|
|
|
|
data->type = type;
|
|
|
|
|
|
|
|
return (VALUE)data;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
rb_objspace_data_type_memsize(VALUE obj)
|
|
|
|
{
|
2010-08-14 13:01:12 +04:00
|
|
|
if (RTYPEDDATA_P(obj) && RTYPEDDATA_TYPE(obj)->function.dsize) {
|
2010-07-18 11:31:54 +04:00
|
|
|
return RTYPEDDATA_TYPE(obj)->function.dsize(RTYPEDDATA_DATA(obj));
|
2009-06-17 01:36:50 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
rb_objspace_data_type_name(VALUE obj)
|
|
|
|
{
|
|
|
|
if (RTYPEDDATA_P(obj)) {
|
2009-07-08 00:28:27 +04:00
|
|
|
return RTYPEDDATA_TYPE(obj)->wrap_struct_name;
|
2009-06-17 01:36:50 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-14 12:35:20 +04:00
|
|
|
#ifdef __ia64
|
2007-07-14 11:19:59 +04:00
|
|
|
#define SET_STACK_END (SET_MACHINE_STACK_END(&th->machine_stack_end), th->machine_register_stack_end = rb_ia64_bsp())
|
2007-06-14 12:35:20 +04:00
|
|
|
#else
|
2007-07-14 11:19:59 +04:00
|
|
|
#define SET_STACK_END SET_MACHINE_STACK_END(&th->machine_stack_end)
|
2007-06-14 12:35:20 +04:00
|
|
|
#endif
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
#define STACK_START (th->machine_stack_start)
|
|
|
|
#define STACK_END (th->machine_stack_end)
|
2007-12-15 07:09:24 +03:00
|
|
|
#define STACK_LEVEL_MAX (th->machine_stack_maxsize/sizeof(VALUE))
|
2004-12-13 12:57:41 +03:00
|
|
|
|
2008-02-19 12:37:10 +03:00
|
|
|
#if STACK_GROW_DIRECTION < 0
|
* array.c, bignum.c, dln.c, error.c, gc.c, io.c, marshal.c,
numeric.c, pack.c, strftime.c, string.c, thread.c, transcode.c,
transcode_data.h, util.c, variable.c, vm_dump.c,
include/ruby/encoding.h, missing/crypt.c, missing/vsnprintf.c:
suppress VC type warnings. [ruby-core:22726]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-03-12 12:16:15 +03:00
|
|
|
# define STACK_LENGTH (size_t)(STACK_START - STACK_END)
|
2003-06-28 07:29:00 +04:00
|
|
|
#elif STACK_GROW_DIRECTION > 0
|
* array.c, bignum.c, dln.c, error.c, gc.c, io.c, marshal.c,
numeric.c, pack.c, strftime.c, string.c, thread.c, transcode.c,
transcode_data.h, util.c, variable.c, vm_dump.c,
include/ruby/encoding.h, missing/crypt.c, missing/vsnprintf.c:
suppress VC type warnings. [ruby-core:22726]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-03-12 12:16:15 +03:00
|
|
|
# define STACK_LENGTH (size_t)(STACK_END - STACK_START + 1)
|
2001-11-19 08:03:03 +03:00
|
|
|
#else
|
* array.c, bignum.c, dln.c, error.c, gc.c, io.c, marshal.c,
numeric.c, pack.c, strftime.c, string.c, thread.c, transcode.c,
transcode_data.h, util.c, variable.c, vm_dump.c,
include/ruby/encoding.h, missing/crypt.c, missing/vsnprintf.c:
suppress VC type warnings. [ruby-core:22726]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-03-12 12:16:15 +03:00
|
|
|
# define STACK_LENGTH ((STACK_END < STACK_START) ? (size_t)(STACK_START - STACK_END) \
|
|
|
|
: (size_t)(STACK_END - STACK_START + 1))
|
2001-11-19 08:03:03 +03:00
|
|
|
#endif
|
2008-06-14 06:59:19 +04:00
|
|
|
#if !STACK_GROW_DIRECTION
|
|
|
|
int ruby_stack_grow_direction;
|
|
|
|
int
|
2009-04-19 09:43:20 +04:00
|
|
|
ruby_get_stack_grow_direction(volatile VALUE *addr)
|
2003-06-28 07:29:00 +04:00
|
|
|
{
|
2009-02-27 12:01:21 +03:00
|
|
|
VALUE *end;
|
|
|
|
SET_MACHINE_STACK_END(&end);
|
2003-06-28 07:29:00 +04:00
|
|
|
|
2009-02-27 12:01:21 +03:00
|
|
|
if (end > addr) return ruby_stack_grow_direction = 1;
|
2008-06-14 06:59:19 +04:00
|
|
|
return ruby_stack_grow_direction = -1;
|
2003-06-28 07:29:00 +04:00
|
|
|
}
|
|
|
|
#endif
|
2001-11-19 08:03:03 +03:00
|
|
|
|
2003-12-13 12:13:39 +03:00
|
|
|
#define GC_WATER_MARK 512
|
2003-04-09 10:44:34 +04:00
|
|
|
|
2008-08-10 03:56:17 +04:00
|
|
|
size_t
|
* 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
|
|
|
ruby_stack_length(VALUE **p)
|
2001-11-19 08:03:03 +03:00
|
|
|
{
|
2008-03-12 06:52:52 +03:00
|
|
|
rb_thread_t *th = GET_THREAD();
|
|
|
|
SET_STACK_END;
|
|
|
|
if (p) *p = STACK_UPPER(STACK_END, STACK_START, STACK_END);
|
|
|
|
return STACK_LENGTH;
|
2001-11-19 08:03:03 +03:00
|
|
|
}
|
|
|
|
|
2008-11-27 17:55:45 +03:00
|
|
|
static int
|
|
|
|
stack_check(void)
|
2001-11-19 08:03:03 +03:00
|
|
|
{
|
2007-12-15 07:09:24 +03:00
|
|
|
int ret;
|
|
|
|
rb_thread_t *th = GET_THREAD();
|
|
|
|
SET_STACK_END;
|
2008-06-13 09:19:01 +04:00
|
|
|
ret = STACK_LENGTH > STACK_LEVEL_MAX - GC_WATER_MARK;
|
2007-12-15 07:09:24 +03:00
|
|
|
#ifdef __ia64
|
|
|
|
if (!ret) {
|
|
|
|
ret = (VALUE*)rb_ia64_bsp() - th->machine_register_stack_start >
|
2008-06-13 09:19:01 +04:00
|
|
|
th->machine_register_stack_maxsize/sizeof(VALUE) - GC_WATER_MARK;
|
2007-12-15 07:09:24 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return ret;
|
2008-11-27 17:55:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ruby_stack_check(void)
|
|
|
|
{
|
|
|
|
#if defined(POSIX_SIGNAL) && defined(SIGSEGV) && defined(HAVE_SIGALTSTACK)
|
|
|
|
return 0;
|
|
|
|
#else
|
|
|
|
return stack_check();
|
2008-11-27 09:05:07 +03:00
|
|
|
#endif
|
2001-11-19 08:03:03 +03:00
|
|
|
}
|
2001-11-13 11:19:52 +03:00
|
|
|
|
|
|
|
static void
|
2008-04-27 07:20:35 +04:00
|
|
|
init_mark_stack(rb_objspace_t *objspace)
|
2001-11-13 11:19:52 +03:00
|
|
|
{
|
|
|
|
mark_stack_overflow = 0;
|
|
|
|
mark_stack_ptr = mark_stack;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MARK_STACK_EMPTY (mark_stack_ptr == mark_stack)
|
2005-04-30 06:59:44 +04:00
|
|
|
|
2008-04-27 07:20:35 +04:00
|
|
|
static void gc_mark(rb_objspace_t *objspace, VALUE ptr, int lev);
|
|
|
|
static void gc_mark_children(rb_objspace_t *objspace, VALUE ptr, int lev);
|
2003-04-09 10:44:34 +04:00
|
|
|
|
2001-11-13 11:19:52 +03:00
|
|
|
static void
|
2008-04-27 07:20:35 +04:00
|
|
|
gc_mark_all(rb_objspace_t *objspace)
|
2001-11-13 11:19:52 +03:00
|
|
|
{
|
|
|
|
RVALUE *p, *pend;
|
2008-05-11 09:44:36 +04:00
|
|
|
size_t i;
|
2001-11-27 13:00:35 +03:00
|
|
|
|
2008-04-27 07:20:35 +04:00
|
|
|
init_mark_stack(objspace);
|
2001-11-27 13:00:35 +03:00
|
|
|
for (i = 0; i < heaps_used; i++) {
|
2010-05-28 15:13:42 +04:00
|
|
|
p = objspace->heap.sorted[i].start; pend = objspace->heap.sorted[i].end;
|
2001-11-27 13:00:35 +03:00
|
|
|
while (p < pend) {
|
|
|
|
if ((p->as.basic.flags & FL_MARK) &&
|
|
|
|
(p->as.basic.flags != FL_MARK)) {
|
2008-04-27 07:20:35 +04:00
|
|
|
gc_mark_children(objspace, (VALUE)p, 0);
|
2001-11-13 11:19:52 +03:00
|
|
|
}
|
2001-11-27 13:00:35 +03:00
|
|
|
p++;
|
2001-11-13 11:19:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-09 12:27:01 +04:00
|
|
|
static void
|
2008-04-27 07:20:35 +04:00
|
|
|
gc_mark_rest(rb_objspace_t *objspace)
|
2003-04-09 12:27:01 +04:00
|
|
|
{
|
|
|
|
VALUE tmp_arry[MARK_STACK_MAX];
|
|
|
|
VALUE *p;
|
|
|
|
|
|
|
|
p = (mark_stack_ptr - mark_stack) + tmp_arry;
|
2007-09-21 09:51:43 +04:00
|
|
|
MEMCPY(tmp_arry, mark_stack, VALUE, p - tmp_arry);
|
2003-04-09 12:27:01 +04:00
|
|
|
|
2008-04-27 07:20:35 +04:00
|
|
|
init_mark_stack(objspace);
|
2007-09-21 09:51:43 +04:00
|
|
|
while (p != tmp_arry) {
|
2003-04-09 12:27:01 +04:00
|
|
|
p--;
|
2008-04-27 07:20:35 +04:00
|
|
|
gc_mark_children(objspace, *p, 0);
|
2003-04-09 12:27:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-10 13:07:31 +03:00
|
|
|
static inline int
|
2008-04-27 07:20:35 +04:00
|
|
|
is_pointer_to_heap(rb_objspace_t *objspace, void *ptr)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1998-01-16 15:19:22 +03:00
|
|
|
register RVALUE *p = RANY(ptr);
|
2010-05-28 15:13:42 +04:00
|
|
|
register struct sorted_heaps_slot *heap;
|
2008-05-11 09:44:36 +04:00
|
|
|
register size_t hi, lo, mid;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2009-07-18 12:05:32 +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
|
|
|
|
2008-03-03 11:27:43 +03:00
|
|
|
/* check if p looks like a pointer using bsearch*/
|
|
|
|
lo = 0;
|
|
|
|
hi = heaps_used;
|
|
|
|
while (lo < hi) {
|
|
|
|
mid = (lo + hi) / 2;
|
2010-05-28 15:13:42 +04:00
|
|
|
heap = &objspace->heap.sorted[mid];
|
|
|
|
if (heap->start <= p) {
|
|
|
|
if (p < heap->end)
|
2009-07-18 12:05:32 +04:00
|
|
|
return TRUE;
|
2008-03-03 11:27:43 +03:00
|
|
|
lo = mid + 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
hi = mid;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2009-07-18 12:05:32 +04:00
|
|
|
return FALSE;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-04-27 07:20:35 +04:00
|
|
|
mark_locations_array(rb_objspace_t *objspace, register VALUE *x, register long n)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2005-01-07 12:08:19 +03:00
|
|
|
VALUE v;
|
1998-01-16 15:13:05 +03:00
|
|
|
while (n--) {
|
2005-01-07 12:08:19 +03:00
|
|
|
v = *x;
|
2007-07-14 11:19:59 +04:00
|
|
|
VALGRIND_MAKE_MEM_DEFINED(&v, sizeof(v));
|
2008-04-27 07:20:35 +04:00
|
|
|
if (is_pointer_to_heap(objspace, (void *)v)) {
|
|
|
|
gc_mark(objspace, v, 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
x++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-27 07:20:35 +04:00
|
|
|
static void
|
|
|
|
gc_mark_locations(rb_objspace_t *objspace, VALUE *start, VALUE *end)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
long n;
|
|
|
|
|
2008-04-18 12:37:50 +04:00
|
|
|
if (end <= start) return;
|
2003-06-28 07:29:00 +04:00
|
|
|
n = end - start;
|
2008-06-30 19:49:13 +04:00
|
|
|
mark_locations_array(objspace, start, n);
|
2008-04-27 07:20:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_gc_mark_locations(VALUE *start, VALUE *end)
|
|
|
|
{
|
|
|
|
gc_mark_locations(&rb_objspace, start, end);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2008-04-27 07:20:35 +04:00
|
|
|
#define rb_gc_mark_locations(start, end) gc_mark_locations(objspace, start, end)
|
|
|
|
|
|
|
|
struct mark_tbl_arg {
|
|
|
|
rb_objspace_t *objspace;
|
|
|
|
int lev;
|
|
|
|
};
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static int
|
2008-04-27 07:20:35 +04:00
|
|
|
mark_entry(ID key, VALUE value, st_data_t data)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-04-27 07:20:35 +04:00
|
|
|
struct mark_tbl_arg *arg = (void*)data;
|
|
|
|
gc_mark(arg->objspace, value, arg->lev);
|
1998-01-16 15:13:05 +03:00
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2005-10-18 21:35:18 +04:00
|
|
|
static void
|
2008-04-27 07:20:35 +04:00
|
|
|
mark_tbl(rb_objspace_t *objspace, st_table *tbl, int lev)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-04-27 07:20:35 +04:00
|
|
|
struct mark_tbl_arg arg;
|
2010-10-31 18:41:14 +03:00
|
|
|
if (!tbl || tbl->num_entries == 0) return;
|
2008-04-27 07:20:35 +04:00
|
|
|
arg.objspace = objspace;
|
|
|
|
arg.lev = lev;
|
|
|
|
st_foreach(tbl, mark_entry, (st_data_t)&arg);
|
2003-11-28 17:23:33 +03:00
|
|
|
}
|
|
|
|
|
2007-09-26 23:40:49 +04:00
|
|
|
static int
|
2008-04-27 07:20:35 +04:00
|
|
|
mark_key(VALUE key, VALUE value, st_data_t data)
|
2007-09-26 23:40:49 +04:00
|
|
|
{
|
2008-04-27 07:20:35 +04:00
|
|
|
struct mark_tbl_arg *arg = (void*)data;
|
|
|
|
gc_mark(arg->objspace, key, arg->lev);
|
2007-09-26 23:40:49 +04:00
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-04-27 07:20:35 +04:00
|
|
|
mark_set(rb_objspace_t *objspace, st_table *tbl, int lev)
|
2007-09-26 23:40:49 +04:00
|
|
|
{
|
2008-04-27 07:20:35 +04:00
|
|
|
struct mark_tbl_arg arg;
|
2007-09-26 23:40:49 +04:00
|
|
|
if (!tbl) return;
|
2008-04-27 07:20:35 +04:00
|
|
|
arg.objspace = objspace;
|
|
|
|
arg.lev = lev;
|
|
|
|
st_foreach(tbl, mark_key, (st_data_t)&arg);
|
2007-09-26 23:40:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_mark_set(st_table *tbl)
|
|
|
|
{
|
2008-04-27 07:20:35 +04:00
|
|
|
mark_set(&rb_objspace, tbl, 0);
|
2007-09-26 23:40:49 +04:00
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static int
|
2008-04-27 07:20:35 +04:00
|
|
|
mark_keyvalue(VALUE key, VALUE value, st_data_t data)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-04-27 07:20:35 +04:00
|
|
|
struct mark_tbl_arg *arg = (void*)data;
|
|
|
|
gc_mark(arg->objspace, key, arg->lev);
|
|
|
|
gc_mark(arg->objspace, value, arg->lev);
|
1998-01-16 15:13:05 +03:00
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2005-10-18 21:35:18 +04:00
|
|
|
static void
|
2008-04-27 07:20:35 +04:00
|
|
|
mark_hash(rb_objspace_t *objspace, st_table *tbl, int lev)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-04-27 07:20:35 +04:00
|
|
|
struct mark_tbl_arg arg;
|
1998-01-16 15:13:05 +03:00
|
|
|
if (!tbl) return;
|
2008-04-27 07:20:35 +04:00
|
|
|
arg.objspace = objspace;
|
|
|
|
arg.lev = lev;
|
|
|
|
st_foreach(tbl, mark_keyvalue, (st_data_t)&arg);
|
2003-11-28 17:23:33 +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
|
|
|
rb_mark_hash(st_table *tbl)
|
2003-11-28 17:23:33 +03:00
|
|
|
{
|
2008-04-27 07:20:35 +04:00
|
|
|
mark_hash(&rb_objspace, tbl, 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2009-07-15 18:59:41 +04:00
|
|
|
static void
|
|
|
|
mark_method_entry(rb_objspace_t *objspace, const rb_method_entry_t *me, int lev)
|
|
|
|
{
|
2009-08-28 06:45:41 +04:00
|
|
|
const rb_method_definition_t *def = me->def;
|
|
|
|
|
2009-07-15 18:59:41 +04:00
|
|
|
gc_mark(objspace, me->klass, lev);
|
2009-08-28 06:45:41 +04:00
|
|
|
if (!def) return;
|
|
|
|
switch (def->type) {
|
2009-07-15 18:59:41 +04:00
|
|
|
case VM_METHOD_TYPE_ISEQ:
|
2009-08-28 06:45:41 +04:00
|
|
|
gc_mark(objspace, def->body.iseq->self, lev);
|
2009-07-15 18:59:41 +04:00
|
|
|
break;
|
|
|
|
case VM_METHOD_TYPE_BMETHOD:
|
2009-08-28 06:45:41 +04:00
|
|
|
gc_mark(objspace, def->body.proc, lev);
|
2009-07-15 18:59:41 +04:00
|
|
|
break;
|
2010-03-22 14:44:01 +03:00
|
|
|
case VM_METHOD_TYPE_ATTRSET:
|
|
|
|
case VM_METHOD_TYPE_IVAR:
|
|
|
|
gc_mark(objspace, def->body.attr.location, lev);
|
|
|
|
break;
|
2009-07-15 18:59:41 +04:00
|
|
|
default:
|
|
|
|
break; /* ignore */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-05-05 02:27:18 +04:00
|
|
|
rb_mark_method_entry(const rb_method_entry_t *me)
|
2009-07-15 18:59:41 +04:00
|
|
|
{
|
|
|
|
mark_method_entry(&rb_objspace, me, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
mark_method_entry(arg->objspace, me, arg->lev);
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-08-26 10:26:08 +04:00
|
|
|
mark_m_tbl(rb_objspace_t *objspace, st_table *tbl, int lev)
|
|
|
|
{
|
2009-07-15 18:59:41 +04:00
|
|
|
struct mark_tbl_arg arg;
|
|
|
|
if (!tbl) return;
|
|
|
|
arg.objspace = objspace;
|
|
|
|
arg.lev = lev;
|
|
|
|
st_foreach(tbl, mark_method_entry_i, (st_data_t)&arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
free_method_entry_i(ID key, rb_method_entry_t *me, st_data_t data)
|
|
|
|
{
|
2009-08-28 06:45:41 +04:00
|
|
|
rb_free_method_entry(me);
|
2009-07-15 18:59:41 +04:00
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2009-11-14 15:56:16 +03:00
|
|
|
void
|
|
|
|
rb_free_m_table(st_table *tbl)
|
2009-07-15 18:59:41 +04:00
|
|
|
{
|
|
|
|
st_foreach(tbl, free_method_entry_i, 0);
|
2009-09-02 06:37:46 +04:00
|
|
|
st_free_table(tbl);
|
2009-07-15 18:59:41 +04:00
|
|
|
}
|
|
|
|
|
2010-10-26 21:27:32 +04:00
|
|
|
static int
|
|
|
|
mark_const_entry_i(ID key, const rb_const_entry_t *ce, st_data_t data)
|
|
|
|
{
|
|
|
|
struct mark_tbl_arg *arg = (void*)data;
|
|
|
|
gc_mark(arg->objspace, ce->value, arg->lev);
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mark_const_tbl(rb_objspace_t *objspace, st_table *tbl, int lev)
|
|
|
|
{
|
|
|
|
struct mark_tbl_arg arg;
|
|
|
|
if (!tbl) return;
|
|
|
|
arg.objspace = objspace;
|
|
|
|
arg.lev = lev;
|
|
|
|
st_foreach(tbl, mark_const_entry_i, (st_data_t)&arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
free_const_entry_i(ID key, rb_const_entry_t *ce, st_data_t data)
|
|
|
|
{
|
|
|
|
xfree(ce);
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_free_const_table(st_table *tbl)
|
|
|
|
{
|
|
|
|
st_foreach(tbl, free_const_entry_i, 0);
|
|
|
|
st_free_table(tbl);
|
|
|
|
}
|
|
|
|
|
2009-07-15 18:59:41 +04:00
|
|
|
void
|
|
|
|
rb_mark_tbl(st_table *tbl)
|
|
|
|
{
|
|
|
|
mark_tbl(&rb_objspace, tbl, 0);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
rb_gc_mark_maybe(VALUE obj)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-04-27 07:20:35 +04:00
|
|
|
if (is_pointer_to_heap(&rb_objspace, (void *)obj)) {
|
|
|
|
gc_mark(&rb_objspace, obj, 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-28 17:23:33 +03:00
|
|
|
#define GC_LEVEL_MAX 250
|
|
|
|
|
2005-06-19 21:16:14 +04:00
|
|
|
static void
|
2008-04-27 07:20:35 +04:00
|
|
|
gc_mark(rb_objspace_t *objspace, VALUE ptr, int lev)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2003-02-21 03:28:04 +03:00
|
|
|
register RVALUE *obj;
|
2001-11-27 13:00:35 +03:00
|
|
|
|
2003-04-09 12:27:01 +04:00
|
|
|
obj = RANY(ptr);
|
|
|
|
if (rb_special_const_p(ptr)) return; /* special const not marked */
|
|
|
|
if (obj->as.basic.flags == 0) return; /* free cell */
|
2005-06-19 21:16:14 +04:00
|
|
|
if (obj->as.basic.flags & FL_MARK) return; /* already marked */
|
2003-04-09 12:27:01 +04:00
|
|
|
obj->as.basic.flags |= FL_MARK;
|
2010-05-28 15:13:42 +04:00
|
|
|
objspace->heap.live_num++;
|
2003-04-09 12:27:01 +04:00
|
|
|
|
2008-11-27 17:55:45 +03:00
|
|
|
if (lev > GC_LEVEL_MAX || (lev == 0 && stack_check())) {
|
2001-11-27 13:00:35 +03:00
|
|
|
if (!mark_stack_overflow) {
|
2001-11-13 11:19:52 +03:00
|
|
|
if (mark_stack_ptr - mark_stack < MARK_STACK_MAX) {
|
|
|
|
*mark_stack_ptr = ptr;
|
2008-03-12 06:49:55 +03:00
|
|
|
mark_stack_ptr++;
|
2001-11-27 13:00:35 +03:00
|
|
|
}
|
|
|
|
else {
|
2001-11-13 11:19:52 +03:00
|
|
|
mark_stack_overflow = 1;
|
|
|
|
}
|
|
|
|
}
|
2003-02-21 03:28:04 +03:00
|
|
|
return;
|
2001-11-13 11:19:52 +03:00
|
|
|
}
|
2008-04-27 07:20:35 +04:00
|
|
|
gc_mark_children(objspace, ptr, lev+1);
|
2003-11-28 17:23:33 +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
|
|
|
rb_gc_mark(VALUE ptr)
|
2003-11-28 17:23:33 +03:00
|
|
|
{
|
2008-04-27 07:20:35 +04:00
|
|
|
gc_mark(&rb_objspace, ptr, 0);
|
2003-04-09 12:27:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-04-27 07:20:35 +04:00
|
|
|
gc_mark_children(rb_objspace_t *objspace, VALUE ptr, int lev)
|
2003-04-09 12:27:01 +04:00
|
|
|
{
|
|
|
|
register RVALUE *obj = RANY(ptr);
|
|
|
|
|
|
|
|
goto marking; /* skip */
|
2001-11-13 11:19:52 +03:00
|
|
|
|
2003-02-21 03:28:04 +03:00
|
|
|
again:
|
|
|
|
obj = RANY(ptr);
|
|
|
|
if (rb_special_const_p(ptr)) return; /* special const not marked */
|
|
|
|
if (obj->as.basic.flags == 0) return; /* free cell */
|
2005-06-19 21:16:14 +04:00
|
|
|
if (obj->as.basic.flags & FL_MARK) return; /* already marked */
|
2003-02-21 03:28:04 +03:00
|
|
|
obj->as.basic.flags |= FL_MARK;
|
2010-05-28 15:13:42 +04:00
|
|
|
objspace->heap.live_num++;
|
2003-02-21 03:28:04 +03:00
|
|
|
|
2003-04-09 12:27:01 +04:00
|
|
|
marking:
|
1999-01-20 07:59:39 +03:00
|
|
|
if (FL_TEST(obj, FL_EXIVAR)) {
|
2003-02-21 03:28:04 +03:00
|
|
|
rb_mark_generic_ivar(ptr);
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
|
2008-07-27 09:59:32 +04:00
|
|
|
switch (BUILTIN_TYPE(obj)) {
|
1998-01-16 15:13:05 +03:00
|
|
|
case T_NIL:
|
|
|
|
case T_FIXNUM:
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_bug("rb_gc_mark() called for broken object");
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_NODE:
|
|
|
|
switch (nd_type(obj)) {
|
|
|
|
case NODE_IF: /* 1,2,3 */
|
|
|
|
case NODE_FOR:
|
|
|
|
case NODE_ITER:
|
1999-01-20 07:59:39 +03:00
|
|
|
case NODE_WHEN:
|
|
|
|
case NODE_MASGN:
|
|
|
|
case NODE_RESCUE:
|
|
|
|
case NODE_RESBODY:
|
2003-02-19 12:27:49 +03:00
|
|
|
case NODE_CLASS:
|
2006-06-29 18:57:42 +04:00
|
|
|
case NODE_BLOCK_PASS:
|
2008-04-27 07:20:35 +04:00
|
|
|
gc_mark(objspace, (VALUE)obj->as.node.u2.node, lev);
|
1998-01-16 15:13:05 +03:00
|
|
|
/* fall through */
|
|
|
|
case NODE_BLOCK: /* 1,3 */
|
2006-12-31 18:02:22 +03:00
|
|
|
case NODE_OPTBLOCK:
|
1998-01-16 15:13:05 +03:00
|
|
|
case NODE_ARRAY:
|
|
|
|
case NODE_DSTR:
|
|
|
|
case NODE_DXSTR:
|
|
|
|
case NODE_DREGX:
|
|
|
|
case NODE_DREGX_ONCE:
|
1999-01-20 07:59:39 +03:00
|
|
|
case NODE_ENSURE:
|
1998-01-16 15:13:05 +03:00
|
|
|
case NODE_CALL:
|
1999-01-20 07:59:39 +03:00
|
|
|
case NODE_DEFS:
|
|
|
|
case NODE_OP_ASGN1:
|
* parse.y, node.h, compile.c: change node tree structure. a purpose
of this change is to unify argument structure of method and block.
this change prohibits duplicate block parameter name.
new argument infromation:
NODE_ARGS [m: int, o: NODE_OPT_ARG, ->]
NODE_ARGS_AUX [r: ID, b: ID, ->]
NODE_ARGS_AUX [Pst: id, Plen: int, init: NODE*]
optarg information:
NODE_OPT_ARGS [idx, expr, ->]
* vm_macro.def: ditto.
* gc.c: ditto.
* iseq.c: ditto.
* compile.h: fix debug function name.
* test/ripper/test_scanner_events.rb: |_,_,foo| -> |_1,_2,foo|
* test/ruby/test_lambda.rb: disalbe test temporarily.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11840 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-24 05:07:05 +03:00
|
|
|
case NODE_ARGS:
|
2008-04-27 07:20:35 +04:00
|
|
|
gc_mark(objspace, (VALUE)obj->as.node.u1.node, lev);
|
1998-01-16 15:13:05 +03:00
|
|
|
/* fall through */
|
|
|
|
case NODE_SUPER: /* 3 */
|
|
|
|
case NODE_FCALL:
|
1999-01-20 07:59:39 +03:00
|
|
|
case NODE_DEFN:
|
* parse.y, node.h, compile.c: change node tree structure. a purpose
of this change is to unify argument structure of method and block.
this change prohibits duplicate block parameter name.
new argument infromation:
NODE_ARGS [m: int, o: NODE_OPT_ARG, ->]
NODE_ARGS_AUX [r: ID, b: ID, ->]
NODE_ARGS_AUX [Pst: id, Plen: int, init: NODE*]
optarg information:
NODE_OPT_ARGS [idx, expr, ->]
* vm_macro.def: ditto.
* gc.c: ditto.
* iseq.c: ditto.
* compile.h: fix debug function name.
* test/ripper/test_scanner_events.rb: |_,_,foo| -> |_1,_2,foo|
* test/ruby/test_lambda.rb: disalbe test temporarily.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11840 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-24 05:07:05 +03:00
|
|
|
case NODE_ARGS_AUX:
|
2003-02-21 03:28:04 +03:00
|
|
|
ptr = (VALUE)obj->as.node.u3.node;
|
|
|
|
goto again;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2010-02-24 17:28:18 +03:00
|
|
|
case NODE_WHILE: /* 1,2 */
|
1998-01-16 15:13:05 +03:00
|
|
|
case NODE_UNTIL:
|
1999-01-20 07:59:39 +03:00
|
|
|
case NODE_AND:
|
|
|
|
case NODE_OR:
|
|
|
|
case NODE_CASE:
|
|
|
|
case NODE_SCLASS:
|
|
|
|
case NODE_DOT2:
|
|
|
|
case NODE_DOT3:
|
|
|
|
case NODE_FLIP2:
|
|
|
|
case NODE_FLIP3:
|
1998-01-16 15:19:22 +03:00
|
|
|
case NODE_MATCH2:
|
|
|
|
case NODE_MATCH3:
|
1999-01-20 07:59:39 +03:00
|
|
|
case NODE_OP_ASGN_OR:
|
|
|
|
case NODE_OP_ASGN_AND:
|
2003-02-19 12:27:49 +03:00
|
|
|
case NODE_MODULE:
|
2004-10-30 10:56:18 +04:00
|
|
|
case NODE_ALIAS:
|
|
|
|
case NODE_VALIAS:
|
2007-09-21 09:51:43 +04:00
|
|
|
case NODE_ARGSCAT:
|
2008-04-27 07:20:35 +04:00
|
|
|
gc_mark(objspace, (VALUE)obj->as.node.u1.node, lev);
|
1998-01-16 15:13:05 +03:00
|
|
|
/* fall through */
|
2010-02-24 17:28:18 +03:00
|
|
|
case NODE_GASGN: /* 2 */
|
1999-01-20 07:59:39 +03:00
|
|
|
case NODE_LASGN:
|
|
|
|
case NODE_DASGN:
|
2000-02-01 06:12:21 +03:00
|
|
|
case NODE_DASGN_CURR:
|
1999-01-20 07:59:39 +03:00
|
|
|
case NODE_IASGN:
|
2007-02-04 22:17:33 +03:00
|
|
|
case NODE_IASGN2:
|
2000-11-21 17:26:25 +03:00
|
|
|
case NODE_CVASGN:
|
1999-01-20 07:59:39 +03:00
|
|
|
case NODE_COLON3:
|
|
|
|
case NODE_OPT_N:
|
2002-07-26 10:12:39 +04:00
|
|
|
case NODE_EVSTR:
|
2004-10-30 10:56:18 +04:00
|
|
|
case NODE_UNDEF:
|
2006-10-30 06:40:11 +03:00
|
|
|
case NODE_POSTEXE:
|
2003-02-21 03:28:04 +03:00
|
|
|
ptr = (VALUE)obj->as.node.u2.node;
|
|
|
|
goto again;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
case NODE_HASH: /* 1 */
|
|
|
|
case NODE_LIT:
|
|
|
|
case NODE_STR:
|
|
|
|
case NODE_XSTR:
|
|
|
|
case NODE_DEFINED:
|
1998-01-16 15:19:22 +03:00
|
|
|
case NODE_MATCH:
|
1999-01-20 07:59:39 +03:00
|
|
|
case NODE_RETURN:
|
2001-07-02 12:46:28 +04:00
|
|
|
case NODE_BREAK:
|
|
|
|
case NODE_NEXT:
|
1999-01-20 07:59:39 +03:00
|
|
|
case NODE_YIELD:
|
|
|
|
case NODE_COLON2:
|
2003-03-26 10:01:14 +03:00
|
|
|
case NODE_SPLAT:
|
2003-10-06 21:59:53 +04:00
|
|
|
case NODE_TO_ARY:
|
2003-02-21 03:28:04 +03:00
|
|
|
ptr = (VALUE)obj->as.node.u1.node;
|
|
|
|
goto again;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
case NODE_SCOPE: /* 2,3 */
|
2003-02-20 06:35:44 +03:00
|
|
|
case NODE_CDECL:
|
* parse.y, node.h, compile.c: change node tree structure. a purpose
of this change is to unify argument structure of method and block.
this change prohibits duplicate block parameter name.
new argument infromation:
NODE_ARGS [m: int, o: NODE_OPT_ARG, ->]
NODE_ARGS_AUX [r: ID, b: ID, ->]
NODE_ARGS_AUX [Pst: id, Plen: int, init: NODE*]
optarg information:
NODE_OPT_ARGS [idx, expr, ->]
* vm_macro.def: ditto.
* gc.c: ditto.
* iseq.c: ditto.
* compile.h: fix debug function name.
* test/ripper/test_scanner_events.rb: |_,_,foo| -> |_1,_2,foo|
* test/ruby/test_lambda.rb: disalbe test temporarily.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11840 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-24 05:07:05 +03:00
|
|
|
case NODE_OPT_ARG:
|
2008-04-27 07:20:35 +04:00
|
|
|
gc_mark(objspace, (VALUE)obj->as.node.u3.node, lev);
|
2003-02-21 03:28:04 +03:00
|
|
|
ptr = (VALUE)obj->as.node.u2.node;
|
|
|
|
goto again;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
case NODE_ZARRAY: /* - */
|
1999-01-20 07:59:39 +03:00
|
|
|
case NODE_ZSUPER:
|
1998-01-16 15:13:05 +03:00
|
|
|
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:
|
1999-01-20 07:59:39 +03:00
|
|
|
case NODE_REDO:
|
|
|
|
case NODE_RETRY:
|
1998-01-16 15:13:05 +03:00
|
|
|
case NODE_SELF:
|
|
|
|
case NODE_NIL:
|
1999-01-20 07:59:39 +03:00
|
|
|
case NODE_TRUE:
|
|
|
|
case NODE_FALSE:
|
2004-01-22 11:31:33 +03:00
|
|
|
case NODE_ERRINFO:
|
1999-01-20 07:59:39 +03:00
|
|
|
case NODE_BLOCK_ARG:
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
1999-01-20 07:59:39 +03:00
|
|
|
case NODE_ALLOCA:
|
2008-04-27 07:20:35 +04:00
|
|
|
mark_locations_array(objspace,
|
|
|
|
(VALUE*)obj->as.node.u1.value,
|
1999-01-20 07:59:39 +03:00
|
|
|
obj->as.node.u3.cnt);
|
2003-02-21 03:28:04 +03:00
|
|
|
ptr = (VALUE)obj->as.node.u2.node;
|
|
|
|
goto again;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2003-02-21 03:28:04 +03:00
|
|
|
default: /* unlisted NODE */
|
2008-04-27 07:20:35 +04:00
|
|
|
if (is_pointer_to_heap(objspace, obj->as.node.u1.node)) {
|
|
|
|
gc_mark(objspace, (VALUE)obj->as.node.u1.node, lev);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2008-04-27 07:20:35 +04:00
|
|
|
if (is_pointer_to_heap(objspace, obj->as.node.u2.node)) {
|
|
|
|
gc_mark(objspace, (VALUE)obj->as.node.u2.node, lev);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2008-04-27 07:20:35 +04:00
|
|
|
if (is_pointer_to_heap(objspace, obj->as.node.u3.node)) {
|
|
|
|
gc_mark(objspace, (VALUE)obj->as.node.u3.node, lev);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return; /* no need to mark class. */
|
|
|
|
}
|
|
|
|
|
2008-04-27 07:20:35 +04:00
|
|
|
gc_mark(objspace, obj->as.basic.klass, lev);
|
2008-07-27 09:59:32 +04:00
|
|
|
switch (BUILTIN_TYPE(obj)) {
|
1998-01-16 15:13:05 +03:00
|
|
|
case T_ICLASS:
|
|
|
|
case T_CLASS:
|
|
|
|
case T_MODULE:
|
2009-07-15 18:59:41 +04:00
|
|
|
mark_m_tbl(objspace, RCLASS_M_TBL(obj), lev);
|
2008-04-27 07:20:35 +04:00
|
|
|
mark_tbl(objspace, RCLASS_IV_TBL(obj), lev);
|
2010-10-26 21:27:32 +04:00
|
|
|
mark_const_tbl(objspace, RCLASS_CONST_TBL(obj), lev);
|
2007-09-28 10:21:46 +04:00
|
|
|
ptr = RCLASS_SUPER(obj);
|
2003-02-21 03:28:04 +03:00
|
|
|
goto again;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
case T_ARRAY:
|
2002-09-04 13:23:51 +04:00
|
|
|
if (FL_TEST(obj, ELTS_SHARED)) {
|
2008-10-09 09:47:04 +04:00
|
|
|
ptr = obj->as.array.as.heap.aux.shared;
|
2003-02-21 03:28:04 +03:00
|
|
|
goto again;
|
2002-09-04 13:23:51 +04:00
|
|
|
}
|
|
|
|
else {
|
2006-09-02 18:42:08 +04:00
|
|
|
long i, len = RARRAY_LEN(obj);
|
|
|
|
VALUE *ptr = RARRAY_PTR(obj);
|
2002-09-04 13:23:51 +04:00
|
|
|
for (i=0; i < len; i++) {
|
2008-04-27 07:20:35 +04:00
|
|
|
gc_mark(objspace, *ptr++, lev);
|
2002-09-04 13:23:51 +04:00
|
|
|
}
|
2001-11-13 11:19:52 +03:00
|
|
|
}
|
|
|
|
break;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
case T_HASH:
|
2008-04-27 07:20:35 +04:00
|
|
|
mark_hash(objspace, obj->as.hash.ntbl, lev);
|
2003-02-21 03:28:04 +03:00
|
|
|
ptr = obj->as.hash.ifnone;
|
|
|
|
goto again;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
case T_STRING:
|
2001-12-11 06:48:08 +03:00
|
|
|
#define STR_ASSOC FL_USER3 /* copied from string.c */
|
2006-09-02 18:42:08 +04:00
|
|
|
if (FL_TEST(obj, RSTRING_NOEMBED) && FL_ANY(obj, ELTS_SHARED|STR_ASSOC)) {
|
2006-08-31 14:47:44 +04:00
|
|
|
ptr = obj->as.string.as.heap.aux.shared;
|
2003-02-21 03:28:04 +03:00
|
|
|
goto again;
|
2001-11-13 11:19:52 +03:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_DATA:
|
2009-06-17 01:36:50 +04:00
|
|
|
if (RTYPEDDATA_P(obj)) {
|
2010-07-18 11:31:54 +04:00
|
|
|
RUBY_DATA_FUNC mark_func = obj->as.typeddata.type->function.dmark;
|
|
|
|
if (mark_func) (*mark_func)(DATA_PTR(obj));
|
2009-06-17 01:36:50 +04:00
|
|
|
}
|
|
|
|
else {
|
2009-06-17 01:40:42 +04:00
|
|
|
if (obj->as.data.dmark) (*obj->as.data.dmark)(DATA_PTR(obj));
|
2009-06-17 01:36:50 +04:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_OBJECT:
|
2007-09-28 10:21:46 +04:00
|
|
|
{
|
2008-02-25 19:18:18 +03:00
|
|
|
long i, len = ROBJECT_NUMIV(obj);
|
|
|
|
VALUE *ptr = ROBJECT_IVPTR(obj);
|
2007-09-28 10:21:46 +04:00
|
|
|
for (i = 0; i < len; i++) {
|
2008-04-27 07:20:35 +04:00
|
|
|
gc_mark(objspace, *ptr++, lev);
|
2007-09-28 10:21:46 +04:00
|
|
|
}
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_FILE:
|
2008-08-18 16:06:42 +04:00
|
|
|
if (obj->as.file.fptr) {
|
2008-08-23 04:47:54 +04:00
|
|
|
gc_mark(objspace, obj->as.file.fptr->pathv, lev);
|
2008-04-27 07:20:35 +04:00
|
|
|
gc_mark(objspace, obj->as.file.fptr->tied_io_for_writing, lev);
|
2008-09-09 19:02:42 +04:00
|
|
|
gc_mark(objspace, obj->as.file.fptr->writeconv_asciicompat, lev);
|
2008-09-03 22:18:10 +04:00
|
|
|
gc_mark(objspace, obj->as.file.fptr->writeconv_pre_ecopts, lev);
|
|
|
|
gc_mark(objspace, obj->as.file.fptr->encs.ecopts, lev);
|
2008-11-07 23:47:02 +03:00
|
|
|
gc_mark(objspace, obj->as.file.fptr->write_lock, lev);
|
2008-08-18 16:06:42 +04:00
|
|
|
}
|
2007-11-20 06:16:53 +03:00
|
|
|
break;
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
case T_REGEXP:
|
2008-06-28 16:25:45 +04:00
|
|
|
gc_mark(objspace, obj->as.regexp.src, lev);
|
|
|
|
break;
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
case T_FLOAT:
|
|
|
|
case T_BIGNUM:
|
2008-10-06 10:22:11 +04:00
|
|
|
case T_ZOMBIE:
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_MATCH:
|
2008-04-27 07:20:35 +04:00
|
|
|
gc_mark(objspace, obj->as.match.regexp, lev);
|
1998-01-16 15:13:05 +03:00
|
|
|
if (obj->as.match.str) {
|
2003-02-21 03:28:04 +03:00
|
|
|
ptr = obj->as.match.str;
|
|
|
|
goto again;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-03-16 03:23:43 +03:00
|
|
|
case T_RATIONAL:
|
2008-04-27 07:20:35 +04:00
|
|
|
gc_mark(objspace, obj->as.rational.num, lev);
|
|
|
|
gc_mark(objspace, obj->as.rational.den, lev);
|
2008-03-16 03:23:43 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_COMPLEX:
|
2008-04-27 07:20:35 +04:00
|
|
|
gc_mark(objspace, obj->as.complex.real, lev);
|
2008-09-21 02:49:56 +04:00
|
|
|
gc_mark(objspace, obj->as.complex.imag, lev);
|
2008-03-16 03:23:43 +03:00
|
|
|
break;
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
case T_STRUCT:
|
2001-11-13 11:19:52 +03:00
|
|
|
{
|
2006-02-05 17:40:01 +03:00
|
|
|
long len = RSTRUCT_LEN(obj);
|
|
|
|
VALUE *ptr = RSTRUCT_PTR(obj);
|
2001-10-31 09:53:22 +03:00
|
|
|
|
2003-02-21 03:28:04 +03:00
|
|
|
while (len--) {
|
2008-04-27 07:20:35 +04:00
|
|
|
gc_mark(objspace, *ptr++, lev);
|
2003-02-21 03:28:04 +03:00
|
|
|
}
|
2001-11-13 11:19:52 +03:00
|
|
|
}
|
|
|
|
break;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
default:
|
2009-03-13 04:42:21 +03:00
|
|
|
rb_bug("rb_gc_mark(): unknown data type 0x%x(%p) %s",
|
* compile.c (iseq_compile_each), gc.c (assign_heap_slot),
(gc_mark_children), parse.y (vtable_alloc, vtable_free, vtable_add),
proc.c (proc_to_s), thread.c (terminate_i, rb_thread_terminate_all),
(thread_start_func_2, blocking_region_begin, blocking_region_end),
(rb_thread_kill), thread_pthread.c (native_thread_create),
(ubf_pthread_cond_signal), vm.c (check_env, thread_free), vm_dump.c
(vm_env_dump_raw, vm_stack_dump_each, vm_thread_dump_state),
(vm_call0): use void pointer for %p.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20593 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-12-09 07:33:55 +03:00
|
|
|
BUILTIN_TYPE(obj), (void *)obj,
|
2008-04-27 07:20:35 +04:00
|
|
|
is_pointer_to_heap(objspace, obj) ? "corrupted object" : "non object");
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-25 18:48:12 +04:00
|
|
|
static int obj_free(rb_objspace_t *, VALUE);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2008-07-27 09:59:32 +04:00
|
|
|
static inline void
|
2009-08-10 06:40:34 +04:00
|
|
|
add_freelist(rb_objspace_t *objspace, RVALUE *p)
|
2008-07-27 09:59:32 +04:00
|
|
|
{
|
|
|
|
VALGRIND_MAKE_MEM_UNDEFINED((void*)p, sizeof(RVALUE));
|
|
|
|
p->as.free.flags = 0;
|
2009-08-10 06:40:34 +04:00
|
|
|
p->as.free.next = freelist;
|
|
|
|
freelist = p;
|
2008-07-27 09:59:32 +04:00
|
|
|
}
|
|
|
|
|
2004-09-27 16:25:21 +04:00
|
|
|
static void
|
2008-04-27 07:20:35 +04:00
|
|
|
finalize_list(rb_objspace_t *objspace, RVALUE *p)
|
2004-09-27 16:25:21 +04:00
|
|
|
{
|
|
|
|
while (p) {
|
|
|
|
RVALUE *tmp = p->as.free.next;
|
2008-04-27 07:20:35 +04:00
|
|
|
run_final(objspace, (VALUE)p);
|
2004-09-27 16:25:21 +04:00
|
|
|
if (!FL_TEST(p, FL_SINGLETON)) { /* not freeing page */
|
2010-05-28 15:13:42 +04:00
|
|
|
if (objspace->heap.sweep_slots) {
|
|
|
|
p->as.free.flags = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
GC_PROF_DEC_LIVE_NUM;
|
|
|
|
add_freelist(objspace, p);
|
|
|
|
}
|
2004-09-27 16:25:21 +04:00
|
|
|
}
|
2008-07-27 17:08:02 +04:00
|
|
|
else {
|
2010-05-21 13:10:23 +04:00
|
|
|
struct heaps_slot *slot = (struct heaps_slot *)(VALUE)RDATA(p)->dmark;
|
2008-07-27 17:08:02 +04:00
|
|
|
slot->limit--;
|
|
|
|
}
|
2004-09-27 16:25:21 +04:00
|
|
|
p = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-29 07:11:05 +04:00
|
|
|
static void
|
|
|
|
unlink_heap_slot(rb_objspace_t *objspace, struct heaps_slot *slot)
|
|
|
|
{
|
|
|
|
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-07-05 11:15:41 +04:00
|
|
|
static void
|
|
|
|
free_unused_heaps(rb_objspace_t *objspace)
|
2004-09-27 16:25:21 +04:00
|
|
|
{
|
2008-07-05 11:15:41 +04:00
|
|
|
size_t i, j;
|
|
|
|
RVALUE *last = 0;
|
2008-07-02 04:49:10 +04:00
|
|
|
|
2008-07-05 11:15:41 +04:00
|
|
|
for (i = j = 1; j < heaps_used; i++) {
|
2010-05-28 15:13:42 +04:00
|
|
|
if (objspace->heap.sorted[i].slot->limit == 0) {
|
2008-07-05 11:15:41 +04:00
|
|
|
if (!last) {
|
2010-05-28 15:13:42 +04:00
|
|
|
last = objspace->heap.sorted[i].slot->membase;
|
2008-04-25 13:03:32 +04:00
|
|
|
}
|
|
|
|
else {
|
2010-05-28 15:13:42 +04:00
|
|
|
free(objspace->heap.sorted[i].slot->membase);
|
2008-04-25 13:03:32 +04:00
|
|
|
}
|
2010-05-28 15:13:42 +04:00
|
|
|
free(objspace->heap.sorted[i].slot);
|
2008-07-05 11:15:41 +04:00
|
|
|
heaps_used--;
|
2004-09-27 16:25:21 +04:00
|
|
|
}
|
|
|
|
else {
|
2008-07-05 11:15:41 +04:00
|
|
|
if (i != j) {
|
2010-05-28 15:13:42 +04:00
|
|
|
objspace->heap.sorted[j] = objspace->heap.sorted[i];
|
2008-07-05 11:15:41 +04:00
|
|
|
}
|
|
|
|
j++;
|
2004-09-27 16:25:21 +04:00
|
|
|
}
|
|
|
|
}
|
2008-07-05 11:15:41 +04:00
|
|
|
if (last) {
|
|
|
|
if (last < heaps_freed) {
|
|
|
|
free(heaps_freed);
|
|
|
|
heaps_freed = last;
|
2008-04-25 13:03:32 +04:00
|
|
|
}
|
2008-07-05 11:15:41 +04:00
|
|
|
else {
|
|
|
|
free(last);
|
2008-07-02 04:49:10 +04:00
|
|
|
}
|
2008-04-25 13:03:32 +04:00
|
|
|
}
|
2008-07-02 04:49:10 +04:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2008-07-02 04:49:10 +04:00
|
|
|
static void
|
2010-05-28 15:13:42 +04:00
|
|
|
slot_sweep(rb_objspace_t *objspace, struct heaps_slot *sweep_slot)
|
2008-07-02 04:49:10 +04:00
|
|
|
{
|
2010-05-28 15:13:42 +04:00
|
|
|
size_t free_num = 0, final_num = 0;
|
|
|
|
RVALUE *p, *pend;
|
|
|
|
RVALUE *free = freelist, *final = deferred_final_list;
|
|
|
|
int deferred;
|
2008-07-27 09:59:32 +04:00
|
|
|
|
2010-05-28 15:13:42 +04:00
|
|
|
p = sweep_slot->slot; pend = p + sweep_slot->limit;
|
|
|
|
while (p < pend) {
|
|
|
|
if (!(p->as.basic.flags & FL_MARK)) {
|
|
|
|
if (p->as.basic.flags &&
|
|
|
|
((deferred = obj_free(objspace, (VALUE)p)) ||
|
2010-10-31 18:41:14 +03:00
|
|
|
(FL_TEST(p, FL_FINALIZE)))) {
|
2010-05-28 15:13:42 +04:00
|
|
|
if (!deferred) {
|
|
|
|
p->as.free.flags = T_ZOMBIE;
|
|
|
|
RDATA(p)->dfree = 0;
|
|
|
|
}
|
|
|
|
p->as.free.flags |= FL_MARK;
|
|
|
|
p->as.free.next = deferred_final_list;
|
|
|
|
deferred_final_list = p;
|
|
|
|
final_num++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
add_freelist(objspace, p);
|
|
|
|
free_num++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (BUILTIN_TYPE(p) == T_ZOMBIE) {
|
|
|
|
/* objects to be finalized */
|
|
|
|
/* do nothing remain marked */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
RBASIC(p)->flags &= ~FL_MARK;
|
|
|
|
}
|
|
|
|
p++;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2010-05-28 15:13:42 +04:00
|
|
|
if (final_num + free_num == sweep_slot->limit &&
|
|
|
|
objspace->heap.free_num > objspace->heap.do_heap_free) {
|
|
|
|
RVALUE *pp;
|
2008-07-02 04:49:10 +04:00
|
|
|
|
2010-05-28 15:13:42 +04:00
|
|
|
for (pp = deferred_final_list; pp != final; pp = pp->as.free.next) {
|
2010-06-04 04:37:36 +04:00
|
|
|
RDATA(pp)->dmark = (void (*)(void *))(VALUE)sweep_slot;
|
2010-05-28 15:13:42 +04:00
|
|
|
pp->as.free.flags |= FL_SINGLETON; /* freeing page mark */
|
|
|
|
}
|
|
|
|
sweep_slot->limit = final_num;
|
|
|
|
freelist = free; /* cancel this page from freelist */
|
2010-06-29 07:11:05 +04:00
|
|
|
unlink_heap_slot(objspace, sweep_slot);
|
2010-05-28 15:13:42 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
objspace->heap.free_num += free_num;
|
|
|
|
}
|
2010-10-27 23:02:24 +04:00
|
|
|
objspace->heap.final_num += final_num;
|
2010-11-04 14:15:36 +03:00
|
|
|
|
|
|
|
if (deferred_final_list) {
|
|
|
|
RUBY_VM_SET_FINALIZER_INTERRUPT(GET_THREAD());
|
|
|
|
}
|
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
|
|
|
|
ready_to_gc(rb_objspace_t *objspace)
|
|
|
|
{
|
|
|
|
if (dont_gc || during_gc) {
|
|
|
|
if (!freelist) {
|
|
|
|
if (!heaps_increment(objspace)) {
|
|
|
|
set_heaps_increment(objspace);
|
|
|
|
heaps_increment(objspace);
|
|
|
|
}
|
2008-07-05 11:15:41 +04:00
|
|
|
}
|
2010-05-28 15:13:42 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-07-27 17:08:02 +04:00
|
|
|
|
2010-05-28 15:13:42 +04:00
|
|
|
static void
|
2010-06-06 08:12:20 +04:00
|
|
|
before_gc_sweep(rb_objspace_t *objspace)
|
2010-05-28 15:13:42 +04:00
|
|
|
{
|
|
|
|
freelist = 0;
|
|
|
|
objspace->heap.do_heap_free = (size_t)((heaps_used * HEAP_OBJ_LIMIT) * 0.65);
|
2010-06-06 08:12:20 +04:00
|
|
|
objspace->heap.free_min = (size_t)((heaps_used * HEAP_OBJ_LIMIT) * 0.2);
|
|
|
|
if (objspace->heap.free_min < FREE_MIN) {
|
2010-05-28 15:13:42 +04:00
|
|
|
objspace->heap.do_heap_free = heaps_used * HEAP_OBJ_LIMIT;
|
2010-06-06 08:12:20 +04:00
|
|
|
objspace->heap.free_min = FREE_MIN;
|
2003-10-20 06:06:42 +04:00
|
|
|
}
|
2010-05-28 15:13:42 +04:00
|
|
|
objspace->heap.sweep_slots = heaps;
|
|
|
|
objspace->heap.free_num = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
after_gc_sweep(rb_objspace_t *objspace)
|
|
|
|
{
|
|
|
|
rb_thread_t *th = GET_THREAD();
|
2008-08-11 13:36:57 +04:00
|
|
|
GC_PROF_SET_MALLOC_INFO;
|
2010-05-28 15:13:42 +04:00
|
|
|
|
2010-06-06 08:12:20 +04:00
|
|
|
if (objspace->heap.free_num < objspace->heap.free_min) {
|
|
|
|
set_heaps_increment(objspace);
|
|
|
|
heaps_increment(objspace);
|
|
|
|
}
|
|
|
|
|
2008-07-05 11:15:41 +04:00
|
|
|
if (malloc_increase > malloc_limit) {
|
2010-05-28 15:13:42 +04:00
|
|
|
malloc_limit += (size_t)((malloc_increase - malloc_limit) * (double)objspace->heap.live_num / (heaps_used * HEAP_OBJ_LIMIT));
|
2008-07-05 11:15:41 +04:00
|
|
|
if (malloc_limit < GC_MALLOC_LIMIT) malloc_limit = GC_MALLOC_LIMIT;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2008-07-05 11:15:41 +04:00
|
|
|
malloc_increase = 0;
|
2008-07-02 04:49:10 +04:00
|
|
|
|
2010-11-04 14:15:36 +03:00
|
|
|
free_unused_heaps(objspace);
|
2010-05-28 15:13:42 +04:00
|
|
|
|
|
|
|
/* sweep unlinked method entries */
|
|
|
|
if (th->vm->unlinked_method_entry_list) {
|
|
|
|
rb_sweep_method_entry(th->vm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
lazy_sweep(rb_objspace_t *objspace)
|
|
|
|
{
|
2010-06-29 07:11:05 +04:00
|
|
|
struct heaps_slot *next;
|
|
|
|
|
2010-05-28 15:13:42 +04:00
|
|
|
heaps_increment(objspace);
|
|
|
|
while (objspace->heap.sweep_slots) {
|
2010-06-29 07:11:05 +04:00
|
|
|
next = objspace->heap.sweep_slots->next;
|
|
|
|
slot_sweep(objspace, objspace->heap.sweep_slots);
|
|
|
|
objspace->heap.sweep_slots = next;
|
2010-05-28 15:13:42 +04:00
|
|
|
if (freelist) {
|
|
|
|
during_gc = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-10-21 08:18:09 +04:00
|
|
|
static void
|
|
|
|
rest_sweep(rb_objspace_t *objspace)
|
|
|
|
{
|
|
|
|
if (objspace->heap.sweep_slots) {
|
|
|
|
while (objspace->heap.sweep_slots) {
|
|
|
|
lazy_sweep(objspace);
|
|
|
|
}
|
|
|
|
after_gc_sweep(objspace);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-28 15:13:42 +04:00
|
|
|
static void gc_marks(rb_objspace_t *objspace);
|
|
|
|
|
|
|
|
static int
|
|
|
|
gc_lazy_sweep(rb_objspace_t *objspace)
|
|
|
|
{
|
|
|
|
int res;
|
2010-10-21 19:03:56 +04:00
|
|
|
INIT_GC_PROF_PARAMS;
|
2010-05-28 15:13:42 +04:00
|
|
|
|
2010-10-21 08:18:09 +04:00
|
|
|
if (objspace->flags.dont_lazy_sweep)
|
|
|
|
return garbage_collect(objspace);
|
|
|
|
|
2010-05-28 15:13:42 +04:00
|
|
|
|
|
|
|
if (!ready_to_gc(objspace)) return TRUE;
|
|
|
|
|
|
|
|
during_gc++;
|
|
|
|
GC_PROF_TIMER_START;
|
|
|
|
GC_PROF_SWEEP_TIMER_START;
|
|
|
|
|
2010-07-20 10:14:40 +04:00
|
|
|
if (objspace->heap.sweep_slots) {
|
|
|
|
res = lazy_sweep(objspace);
|
|
|
|
if (res) {
|
|
|
|
GC_PROF_SWEEP_TIMER_STOP;
|
|
|
|
GC_PROF_SET_MALLOC_INFO;
|
|
|
|
GC_PROF_TIMER_STOP(Qfalse);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
after_gc_sweep(objspace);
|
2010-05-28 15:13:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gc_marks(objspace);
|
|
|
|
|
2010-06-06 08:12:20 +04:00
|
|
|
before_gc_sweep(objspace);
|
|
|
|
if (objspace->heap.free_min > (heaps_used * HEAP_OBJ_LIMIT - objspace->heap.live_num)) {
|
2010-05-28 15:13:42 +04:00
|
|
|
set_heaps_increment(objspace);
|
|
|
|
}
|
|
|
|
|
|
|
|
GC_PROF_SWEEP_TIMER_START;
|
2010-06-06 08:12:20 +04:00
|
|
|
if(!(res = lazy_sweep(objspace))) {
|
|
|
|
after_gc_sweep(objspace);
|
|
|
|
if(freelist) {
|
|
|
|
res = TRUE;
|
|
|
|
during_gc = 0;
|
|
|
|
}
|
|
|
|
}
|
2010-05-28 15:13:42 +04:00
|
|
|
GC_PROF_SWEEP_TIMER_STOP;
|
|
|
|
|
|
|
|
GC_PROF_TIMER_STOP(Qtrue);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gc_sweep(rb_objspace_t *objspace)
|
|
|
|
{
|
2010-06-29 07:11:05 +04:00
|
|
|
struct heaps_slot *next;
|
|
|
|
|
2010-06-06 08:12:20 +04:00
|
|
|
before_gc_sweep(objspace);
|
2010-05-28 15:13:42 +04:00
|
|
|
|
|
|
|
while (objspace->heap.sweep_slots) {
|
2010-06-29 07:11:05 +04:00
|
|
|
next = objspace->heap.sweep_slots->next;
|
2010-05-28 15:13:42 +04:00
|
|
|
slot_sweep(objspace, objspace->heap.sweep_slots);
|
2010-06-29 07:11:05 +04:00
|
|
|
objspace->heap.sweep_slots = next;
|
2010-05-28 15:13:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
after_gc_sweep(objspace);
|
|
|
|
|
|
|
|
during_gc = 0;
|
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
|
|
|
rb_gc_force_recycle(VALUE p)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-07-05 11:15:41 +04:00
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
2010-05-28 15:13:42 +04:00
|
|
|
GC_PROF_DEC_LIVE_NUM;
|
|
|
|
if (RBASIC(p)->flags & FL_MARK) {
|
|
|
|
RANY(p)->as.free.flags = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
add_freelist(objspace, (RVALUE *)p);
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2008-08-06 15:48:30 +04:00
|
|
|
static inline void
|
|
|
|
make_deferred(RVALUE *p)
|
|
|
|
{
|
2008-08-29 15:22:42 +04:00
|
|
|
p->as.basic.flags = (p->as.basic.flags & ~T_MASK) | T_ZOMBIE;
|
2008-08-06 15:48:30 +04:00
|
|
|
}
|
|
|
|
|
2008-10-01 14:13:57 +04:00
|
|
|
static inline void
|
|
|
|
make_io_deferred(RVALUE *p)
|
|
|
|
{
|
|
|
|
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-07-25 18:48:12 +04:00
|
|
|
static int
|
2008-04-27 07:20:35 +04:00
|
|
|
obj_free(rb_objspace_t *objspace, VALUE obj)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-07-27 09:59:32 +04:00
|
|
|
switch (BUILTIN_TYPE(obj)) {
|
1998-01-16 15:13:05 +03:00
|
|
|
case T_NIL:
|
|
|
|
case T_FIXNUM:
|
|
|
|
case T_TRUE:
|
|
|
|
case T_FALSE:
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_bug("obj_free() called for broken object");
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (FL_TEST(obj, FL_EXIVAR)) {
|
|
|
|
rb_free_generic_ivar((VALUE)obj);
|
2008-08-07 00:06:05 +04:00
|
|
|
FL_UNSET(obj, FL_EXIVAR);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2008-07-27 09:59:32 +04:00
|
|
|
switch (BUILTIN_TYPE(obj)) {
|
1998-01-16 15:13:05 +03:00
|
|
|
case T_OBJECT:
|
2007-09-28 10:21:46 +04:00
|
|
|
if (!(RANY(obj)->as.basic.flags & ROBJECT_EMBED) &&
|
2008-02-25 19:18:18 +03:00
|
|
|
RANY(obj)->as.object.as.heap.ivptr) {
|
* 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
|
|
|
xfree(RANY(obj)->as.object.as.heap.ivptr);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
case T_MODULE:
|
|
|
|
case T_CLASS:
|
2003-07-07 12:28:19 +04:00
|
|
|
rb_clear_cache_by_class((VALUE)obj);
|
2009-11-14 15:56:16 +03:00
|
|
|
rb_free_m_table(RCLASS_M_TBL(obj));
|
2007-09-28 10:21:46 +04:00
|
|
|
if (RCLASS_IV_TBL(obj)) {
|
|
|
|
st_free_table(RCLASS_IV_TBL(obj));
|
|
|
|
}
|
2010-10-26 21:27:21 +04:00
|
|
|
if (RCLASS_CONST_TBL(obj)) {
|
2010-10-26 21:27:32 +04:00
|
|
|
rb_free_const_table(RCLASS_CONST_TBL(obj));
|
2010-10-26 21:27:21 +04:00
|
|
|
}
|
2007-09-28 10:21:46 +04:00
|
|
|
if (RCLASS_IV_INDEX_TBL(obj)) {
|
|
|
|
st_free_table(RCLASS_IV_INDEX_TBL(obj));
|
1998-01-16 15:19:22 +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
|
|
|
xfree(RANY(obj)->as.klass.ptr);
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
case T_STRING:
|
2006-09-27 02:46:16 +04:00
|
|
|
rb_str_free(obj);
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
case T_ARRAY:
|
2006-09-27 02:46:16 +04:00
|
|
|
rb_ary_free(obj);
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
case T_HASH:
|
2007-08-30 03:12:21 +04:00
|
|
|
if (RANY(obj)->as.hash.ntbl) {
|
|
|
|
st_free_table(RANY(obj)->as.hash.ntbl);
|
2000-09-27 07:43:15 +04:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
case T_REGEXP:
|
2000-09-27 07:43:15 +04:00
|
|
|
if (RANY(obj)->as.regexp.ptr) {
|
2005-02-17 17:43:38 +03:00
|
|
|
onig_free(RANY(obj)->as.regexp.ptr);
|
2000-09-27 07:43:15 +04:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
case T_DATA:
|
1999-01-20 07:59:39 +03:00
|
|
|
if (DATA_PTR(obj)) {
|
2009-06-17 01:36:50 +04:00
|
|
|
if (RTYPEDDATA_P(obj)) {
|
2010-07-18 11:31:54 +04:00
|
|
|
RDATA(obj)->dfree = RANY(obj)->as.typeddata.type->function.dfree;
|
2009-06-17 01:36:50 +04:00
|
|
|
}
|
2010-10-12 18:09:27 +04:00
|
|
|
if (RANY(obj)->as.data.dfree == (RUBY_DATA_FUNC)-1) {
|
* 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
|
|
|
xfree(DATA_PTR(obj));
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
else if (RANY(obj)->as.data.dfree) {
|
2008-08-06 15:48:30 +04:00
|
|
|
make_deferred(RANY(obj));
|
|
|
|
return 1;
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
case T_MATCH:
|
2008-02-16 23:08:35 +03:00
|
|
|
if (RANY(obj)->as.match.rmatch) {
|
|
|
|
struct rmatch *rm = RANY(obj)->as.match.rmatch;
|
|
|
|
onig_region_free(&rm->regs, 0);
|
|
|
|
if (rm->char_offset)
|
2008-08-06 15:48:30 +04:00
|
|
|
xfree(rm->char_offset);
|
* 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
|
|
|
xfree(rm);
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
case T_FILE:
|
1999-01-20 07:59:39 +03:00
|
|
|
if (RANY(obj)->as.file.fptr) {
|
2008-10-01 14:13:57 +04:00
|
|
|
make_io_deferred(RANY(obj));
|
2008-08-06 15:48:30 +04:00
|
|
|
return 1;
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
2008-03-16 03:23:43 +03:00
|
|
|
case T_RATIONAL:
|
|
|
|
case T_COMPLEX:
|
|
|
|
break;
|
1998-01-16 15:13:05 +03:00
|
|
|
case T_ICLASS:
|
|
|
|
/* iClass shares table with the module */
|
2010-01-31 07:33:33 +03:00
|
|
|
xfree(RANY(obj)->as.klass.ptr);
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_FLOAT:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_BIGNUM:
|
2007-09-01 16:02:36 +04:00
|
|
|
if (!(RBASIC(obj)->flags & RBIGNUM_EMBED_FLAG) && RBIGNUM_DIGITS(obj)) {
|
* 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
|
|
|
xfree(RBIGNUM_DIGITS(obj));
|
2000-09-27 07:43:15 +04:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
case T_NODE:
|
1999-01-20 07:59:39 +03:00
|
|
|
switch (nd_type(obj)) {
|
|
|
|
case NODE_SCOPE:
|
|
|
|
if (RANY(obj)->as.node.u1.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
|
|
|
xfree(RANY(obj)->as.node.u1.tbl);
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NODE_ALLOCA:
|
* 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
|
|
|
xfree(RANY(obj)->as.node.u1.node);
|
1999-01-20 07:59:39 +03:00
|
|
|
break;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2008-07-25 18:48:12 +04:00
|
|
|
break; /* no need to free iv_tbl */
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
case T_STRUCT:
|
2007-05-29 19:49:30 +04:00
|
|
|
if ((RBASIC(obj)->flags & RSTRUCT_EMBED_LEN_MASK) == 0 &&
|
2006-02-05 17:40:01 +03:00
|
|
|
RANY(obj)->as.rstruct.as.heap.ptr) {
|
* 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
|
|
|
xfree(RANY(obj)->as.rstruct.as.heap.ptr);
|
2000-09-27 07:43:15 +04:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2009-03-13 04:42:21 +03:00
|
|
|
rb_bug("gc_sweep(): unknown data type 0x%x(%p)",
|
2008-07-27 09:59:32 +04:00
|
|
|
BUILTIN_TYPE(obj), (void*)obj);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2008-07-27 09:59:32 +04:00
|
|
|
|
2008-07-25 18:48:12 +04:00
|
|
|
return 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
#define GC_NOTIFY 0
|
|
|
|
|
2007-05-24 06:47:22 +04:00
|
|
|
void rb_vm_mark(void *ptr);
|
|
|
|
|
2009-11-01 02:17:52 +03: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
|
2010-04-14 11:29:04 +04:00
|
|
|
#define GET_STACK_BOUNDS(start, end, appendix) \
|
2009-11-01 02:17:52 +03:00
|
|
|
((STACK_END < STACK_START) ? \
|
|
|
|
(start = STACK_END, end = STACK_START) : (start = STACK_START, end = STACK_END+appendix))
|
|
|
|
#endif
|
|
|
|
|
2010-10-12 18:03:24 +04:00
|
|
|
#define numberof(array) (int)(sizeof(array) / sizeof((array)[0]))
|
|
|
|
|
2007-07-14 11:48:54 +04:00
|
|
|
static void
|
2008-04-27 07:20:35 +04:00
|
|
|
mark_current_machine_context(rb_objspace_t *objspace, rb_thread_t *th)
|
2007-07-14 11:19:59 +04:00
|
|
|
{
|
2010-10-12 18:03:24 +04:00
|
|
|
union {
|
|
|
|
rb_jmp_buf j;
|
|
|
|
VALUE v[sizeof(rb_jmp_buf) / sizeof(VALUE)];
|
|
|
|
} save_regs_gc_mark;
|
2007-07-14 11:19:59 +04:00
|
|
|
VALUE *stack_start, *stack_end;
|
|
|
|
|
2009-10-23 02:28:52 +04:00
|
|
|
FLUSH_REGISTER_WINDOWS;
|
|
|
|
/* This assumes that all registers are saved into the jmp_buf (and stack) */
|
2010-10-12 18:03:24 +04:00
|
|
|
rb_setjmp(save_regs_gc_mark.j);
|
2009-10-23 02:28:52 +04:00
|
|
|
|
2007-07-14 11:19:59 +04:00
|
|
|
SET_STACK_END;
|
2009-11-01 02:17:52 +03:00
|
|
|
GET_STACK_BOUNDS(stack_start, stack_end, 1);
|
2007-07-14 11:19:59 +04:00
|
|
|
|
2010-10-12 18:03:24 +04:00
|
|
|
mark_locations_array(objspace, save_regs_gc_mark.v, numberof(save_regs_gc_mark.v));
|
2007-07-14 11:19:59 +04:00
|
|
|
|
2008-04-18 12:37:50 +04:00
|
|
|
rb_gc_mark_locations(stack_start, stack_end);
|
2007-07-14 11:19:59 +04:00
|
|
|
#ifdef __ia64
|
2008-04-18 12:37:50 +04:00
|
|
|
rb_gc_mark_locations(th->machine_register_stack_start, th->machine_register_stack_end);
|
2007-07-14 11:19:59 +04:00
|
|
|
#endif
|
2008-10-04 17:12:13 +04:00
|
|
|
#if defined(__mc68000__)
|
2007-07-20 11:11:35 +04:00
|
|
|
mark_locations_array((VALUE*)((char*)STACK_END + 2),
|
|
|
|
(STACK_START - STACK_END));
|
2007-07-14 11:19:59 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-10-13 20:32:40 +04:00
|
|
|
void rb_gc_mark_encodings(void);
|
|
|
|
|
2010-05-28 15:13:42 +04:00
|
|
|
static void
|
2010-05-30 10:42:12 +04:00
|
|
|
gc_clear_mark_on_sweep_slots(rb_objspace_t *objspace)
|
2010-05-28 15:13:42 +04:00
|
|
|
{
|
|
|
|
struct heaps_slot *scan;
|
|
|
|
RVALUE *p, *pend;
|
|
|
|
|
|
|
|
if (objspace->heap.sweep_slots) {
|
|
|
|
while (objspace->heap.sweep_slots) {
|
|
|
|
scan = objspace->heap.sweep_slots;
|
|
|
|
p = scan->slot; pend = p + scan->limit;
|
|
|
|
while (p < pend) {
|
2010-05-30 10:42:12 +04:00
|
|
|
if (p->as.free.flags & FL_MARK && BUILTIN_TYPE(p) != T_ZOMBIE) {
|
2010-05-28 15:13:42 +04:00
|
|
|
p->as.basic.flags &= ~FL_MARK;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
objspace->heap.sweep_slots = objspace->heap.sweep_slots->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gc_marks(rb_objspace_t *objspace)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-07-05 11:15:41 +04:00
|
|
|
struct gc_list *list;
|
|
|
|
rb_thread_t *th = GET_THREAD();
|
2010-05-28 15:13:42 +04:00
|
|
|
GC_PROF_MARK_TIMER_START;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2010-05-28 15:13:42 +04:00
|
|
|
objspace->heap.live_num = 0;
|
|
|
|
objspace->count++;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2008-07-02 04:49:10 +04:00
|
|
|
|
2010-05-30 10:42:12 +04:00
|
|
|
gc_clear_mark_on_sweep_slots(objspace);
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2007-02-05 15:21:01 +03:00
|
|
|
SET_STACK_END;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2008-04-27 07:20:35 +04:00
|
|
|
init_mark_stack(objspace);
|
2005-06-19 21:16:14 +04:00
|
|
|
|
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
|
|
|
|
2010-10-31 18:41:14 +03:00
|
|
|
mark_tbl(objspace, finalizer_table, 0);
|
2008-04-27 07:20:35 +04:00
|
|
|
mark_current_machine_context(objspace, th);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2006-09-02 19:05:27 +04:00
|
|
|
rb_gc_mark_symbols();
|
2007-10-13 20:32:40 +04:00
|
|
|
rb_gc_mark_encodings();
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
/* mark protected global variables */
|
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
|
|
|
}
|
1999-11-26 12:07:26 +03:00
|
|
|
rb_mark_end_proc();
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_gc_mark_global_tbl();
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2008-04-27 07:20:35 +04:00
|
|
|
mark_tbl(objspace, rb_class_tbl, 0);
|
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
|
|
|
|
|
|
|
rb_gc_mark_parser();
|
2005-06-19 21:16:14 +04:00
|
|
|
|
2001-11-13 11:19:52 +03:00
|
|
|
/* gc_mark objects whose marking are not completed*/
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 12:12:18 +04:00
|
|
|
while (!MARK_STACK_EMPTY) {
|
|
|
|
if (mark_stack_overflow) {
|
2008-04-27 07:20:35 +04:00
|
|
|
gc_mark_all(objspace);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
else {
|
2008-04-27 07:20:35 +04:00
|
|
|
gc_mark_rest(objspace);
|
2001-10-31 09:53:22 +03:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2008-08-11 13:36:57 +04:00
|
|
|
GC_PROF_MARK_TIMER_STOP;
|
2010-05-28 15:13:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
garbage_collect(rb_objspace_t *objspace)
|
|
|
|
{
|
|
|
|
INIT_GC_PROF_PARAMS;
|
|
|
|
|
|
|
|
if (GC_NOTIFY) printf("start garbage_collect()\n");
|
|
|
|
|
|
|
|
if (!heaps) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!ready_to_gc(objspace)) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GC_PROF_TIMER_START;
|
|
|
|
|
|
|
|
during_gc++;
|
|
|
|
gc_marks(objspace);
|
2005-12-30 12:15:56 +03:00
|
|
|
|
2008-08-11 13:36:57 +04:00
|
|
|
GC_PROF_SWEEP_TIMER_START;
|
2008-07-05 11:15:41 +04:00
|
|
|
gc_sweep(objspace);
|
2008-08-11 13:36:57 +04:00
|
|
|
GC_PROF_SWEEP_TIMER_STOP;
|
2008-04-25 13:03:32 +04:00
|
|
|
|
2010-05-28 15:13:42 +04:00
|
|
|
GC_PROF_TIMER_STOP(Qtrue);
|
2006-12-31 18:02:22 +03:00
|
|
|
if (GC_NOTIFY) printf("end garbage_collect()\n");
|
2009-07-18 12:05:32 +04:00
|
|
|
return TRUE;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2007-12-21 09:16:56 +03:00
|
|
|
int
|
|
|
|
rb_garbage_collect(void)
|
|
|
|
{
|
2008-04-27 07:20:35 +04:00
|
|
|
return garbage_collect(&rb_objspace);
|
2007-12-21 09:16:56 +03:00
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
void
|
* 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
|
|
|
rb_gc_mark_machine_stack(rb_thread_t *th)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2008-04-27 07:20:35 +04:00
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
2009-11-01 02:17:52 +03:00
|
|
|
VALUE *stack_start, *stack_end;
|
|
|
|
|
|
|
|
GET_STACK_BOUNDS(stack_start, stack_end, 0);
|
|
|
|
rb_gc_mark_locations(stack_start, stack_end);
|
2007-06-14 12:35:20 +04:00
|
|
|
#ifdef __ia64
|
|
|
|
rb_gc_mark_locations(th->machine_register_stack_start, th->machine_register_stack_end);
|
|
|
|
#endif
|
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;
|
|
|
|
}
|
|
|
|
|
2008-06-09 04:54:23 +04:00
|
|
|
#undef Init_stack
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
void
|
2009-04-19 09:43:20 +04:00
|
|
|
Init_stack(volatile VALUE *addr)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-04-14 07:52:27 +04:00
|
|
|
ruby_init_stack(addr);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-22 09:20:14 +03:00
|
|
|
/*
|
|
|
|
* Document-class: ObjectSpace
|
|
|
|
*
|
|
|
|
* The <code>ObjectSpace</code> module contains a number of routines
|
|
|
|
* that interact with the garbage collection facility and allow you to
|
|
|
|
* traverse all living objects with an iterator.
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
2003-12-22 09:20:14 +03:00
|
|
|
* <code>ObjectSpace</code> also provides support for object
|
|
|
|
* finalizers, procs that will be called when a specific object is
|
|
|
|
* about to be destroyed by garbage collection.
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
2003-12-22 09:20:14 +03:00
|
|
|
* include ObjectSpace
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
|
|
|
*
|
2003-12-22 09:20:14 +03:00
|
|
|
* a = "A"
|
|
|
|
* b = "B"
|
|
|
|
* c = "C"
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
|
|
|
*
|
2003-12-22 09:20:14 +03:00
|
|
|
* define_finalizer(a, proc {|id| puts "Finalizer one on #{id}" })
|
|
|
|
* define_finalizer(a, proc {|id| puts "Finalizer two on #{id}" })
|
|
|
|
* define_finalizer(b, proc {|id| puts "Finalizer three on #{id}" })
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
2003-12-22 09:20:14 +03:00
|
|
|
* <em>produces:</em>
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
2003-12-22 09:20:14 +03:00
|
|
|
* Finalizer three on 537763470
|
|
|
|
* Finalizer one on 537763480
|
|
|
|
* Finalizer two on 537763480
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
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_heap(void)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-05-04 21:25:38 +04:00
|
|
|
init_heap(&rb_objspace);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2010-10-21 08:18:09 +04:00
|
|
|
|
|
|
|
static VALUE
|
|
|
|
lazy_sweep_enable(void)
|
|
|
|
{
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
|
|
|
|
objspace->flags.dont_lazy_sweep = FALSE;
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2010-10-21 18:56:55 +04:00
|
|
|
typedef int each_obj_callback(void *, void *, size_t, void *);
|
|
|
|
|
|
|
|
struct each_obj_args {
|
|
|
|
each_obj_callback *callback;
|
|
|
|
void *data;
|
|
|
|
};
|
|
|
|
|
2010-10-21 08:18:09 +04:00
|
|
|
static VALUE
|
|
|
|
objspace_each_objects(VALUE arg)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
RVALUE *membase = 0;
|
|
|
|
RVALUE *pstart, *pend;
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
2010-10-21 18:56:55 +04:00
|
|
|
struct each_obj_args *args = (struct each_obj_args *)arg;
|
2010-10-21 08:18:09 +04:00
|
|
|
volatile VALUE v;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < heaps_used) {
|
|
|
|
while (0 < i && (uintptr_t)membase < (uintptr_t)objspace->heap.sorted[i-1].slot->membase)
|
|
|
|
i--;
|
|
|
|
while (i < heaps_used && (uintptr_t)objspace->heap.sorted[i].slot->membase <= (uintptr_t)membase )
|
|
|
|
i++;
|
|
|
|
if (heaps_used <= i)
|
|
|
|
break;
|
|
|
|
membase = objspace->heap.sorted[i].slot->membase;
|
|
|
|
|
|
|
|
pstart = objspace->heap.sorted[i].slot->slot;
|
|
|
|
pend = pstart + objspace->heap.sorted[i].slot->limit;
|
|
|
|
|
|
|
|
for (; pstart != pend; pstart++) {
|
|
|
|
if (pstart->as.basic.flags) {
|
|
|
|
v = (VALUE)pstart; /* acquire to save this object */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pstart != pend) {
|
2010-10-21 18:56:55 +04:00
|
|
|
if ((*args->callback)(pstart, pend, sizeof(RVALUE), args->data)) {
|
2010-10-21 18:52:02 +04:00
|
|
|
break;
|
2010-10-21 08:18:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2009-06-17 01:07:26 +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) {
|
2009-11-03 20:46:28 +03:00
|
|
|
* if (RBASIC(v)->flags) { // liveness check
|
2009-06-17 01:07:26 +04:00
|
|
|
* // 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
|
2010-10-21 18:56:55 +04:00
|
|
|
rb_objspace_each_objects(each_obj_callback *callback, void *data)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2010-10-21 18:56:55 +04:00
|
|
|
struct each_obj_args args;
|
2009-06-17 01:07:26 +04:00
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
2008-06-05 17:52:02 +04:00
|
|
|
|
2010-10-21 08:18:09 +04:00
|
|
|
rest_sweep(objspace);
|
|
|
|
objspace->flags.dont_lazy_sweep = TRUE;
|
2009-06-17 01:07:26 +04:00
|
|
|
|
2010-10-21 18:56:55 +04:00
|
|
|
args.callback = callback;
|
|
|
|
args.data = data;
|
|
|
|
rb_ensure(objspace_each_objects, (VALUE)&args, lazy_sweep_enable, Qnil);
|
2009-06-17 01:07:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
struct os_each_struct {
|
|
|
|
size_t num;
|
|
|
|
VALUE of;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
os_obj_of_i(void *vstart, void *vend, size_t stride, void *data)
|
|
|
|
{
|
|
|
|
struct os_each_struct *oes = (struct os_each_struct *)data;
|
|
|
|
RVALUE *p = (RVALUE *)vstart, *pend = (RVALUE *)vend;
|
|
|
|
volatile VALUE v;
|
|
|
|
|
|
|
|
for (; p != pend; p++) {
|
2009-06-17 01:15:15 +04:00
|
|
|
if (p->as.basic.flags) {
|
|
|
|
switch (BUILTIN_TYPE(p)) {
|
|
|
|
case T_NONE:
|
|
|
|
case T_ICLASS:
|
|
|
|
case T_NODE:
|
|
|
|
case T_ZOMBIE:
|
|
|
|
continue;
|
|
|
|
case T_CLASS:
|
2009-06-17 01:07:26 +04:00
|
|
|
if (FL_TEST(p, FL_SINGLETON))
|
|
|
|
continue;
|
2009-06-17 01:15:15 +04:00
|
|
|
default:
|
|
|
|
if (!p->as.basic.klass) continue;
|
|
|
|
v = (VALUE)p;
|
2009-06-17 01:07:26 +04:00
|
|
|
if (!oes->of || rb_obj_is_kind_of(v, oes->of)) {
|
2009-06-17 01:15:15 +04:00
|
|
|
rb_yield(v);
|
2009-06-17 01:07:26 +04:00
|
|
|
oes->num++;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-06-17 01:15:15 +04:00
|
|
|
}
|
2009-06-17 01:07:26 +04:00
|
|
|
|
|
|
|
return 0;
|
2009-06-17 01:15:15 +04:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2009-06-17 01:07:26 +04:00
|
|
|
static VALUE
|
|
|
|
os_obj_of(VALUE of)
|
|
|
|
{
|
|
|
|
struct os_each_struct oes;
|
|
|
|
|
|
|
|
oes.num = 0;
|
|
|
|
oes.of = of;
|
|
|
|
rb_objspace_each_objects(os_obj_of_i, &oes);
|
|
|
|
return SIZET2NUM(oes.num);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-22 09:20:14 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* ObjectSpace.each_object([module]) {|obj| ... } -> fixnum
|
|
|
|
* ObjectSpace.each_object([module]) -> an_enumerator
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
2003-12-22 09:20:14 +03:00
|
|
|
* 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.
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
2010-05-13 09:49:55 +04:00
|
|
|
* If no block is given, an enumerator is returned instead.
|
|
|
|
*
|
2003-12-22 09:20:14 +03:00
|
|
|
* a = 102.7
|
|
|
|
* b = 95 # Won't be returned
|
|
|
|
* c = 12345678987654321
|
|
|
|
* count = ObjectSpace.each_object(Numeric) {|x| p x }
|
|
|
|
* puts "Total count: #{count}"
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
2003-12-22 09:20:14 +03:00
|
|
|
* <em>produces:</em>
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
2003-12-22 09:20:14 +03:00
|
|
|
* 12345678987654321
|
|
|
|
* 102.7
|
|
|
|
* 2.71828182845905
|
|
|
|
* 3.14159265358979
|
|
|
|
* 2.22044604925031e-16
|
|
|
|
* 1.7976931348623157e+308
|
|
|
|
* 2.2250738585072e-308
|
|
|
|
* Total count: 7
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
2003-12-22 09:20:14 +03:00
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
2007-12-28 07:07:33 +03:00
|
|
|
os_each_obj(int argc, VALUE *argv, VALUE os)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
VALUE of;
|
|
|
|
|
2003-03-26 10:01:14 +03:00
|
|
|
rb_secure(4);
|
2008-03-05 08:22:17 +03:00
|
|
|
if (argc == 0) {
|
2007-09-23 04:05:07 +04:00
|
|
|
of = 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2008-03-05 08:22:17 +03:00
|
|
|
else {
|
|
|
|
rb_scan_args(argc, argv, "01", &of);
|
|
|
|
}
|
2007-12-28 07:07:33 +03:00
|
|
|
RETURN_ENUMERATOR(os, 1, &of);
|
2009-06-17 01:07:26 +04:00
|
|
|
return os_obj_of(of);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-22 09:20:14 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ObjectSpace.undefine_finalizer(obj)
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
2003-12-22 09:20:14 +03:00
|
|
|
* Removes all finalizers for <i>obj</i>.
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
2003-12-22 09:20:14 +03:00
|
|
|
*/
|
|
|
|
|
2000-07-15 17:37:03 +04:00
|
|
|
static 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
|
|
|
undefine_final(VALUE os, VALUE obj)
|
2000-07-15 17:37:03 +04:00
|
|
|
{
|
2008-04-27 07:20:35 +04:00
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
2010-10-31 18:41:14 +03:00
|
|
|
st_data_t data = obj;
|
* array.c, gc.c, hash.c, object.c, string.c, struct.c,
transcode.c, variable.c, vm.c, vm_insnhelper.c, vm_method.c:
replace calls to rb_error_frozen() with rb_check_frozen(). a
patch from Run Paint Run Run at [ruby-core:32014]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29583 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-10-24 12:14:05 +04:00
|
|
|
rb_check_frozen(obj);
|
2010-10-31 18:41:14 +03:00
|
|
|
st_delete(finalizer_table, &data, 0);
|
2009-02-11 12:11:48 +03:00
|
|
|
FL_UNSET(obj, FL_FINALIZE);
|
2000-07-15 17:37:03 +04:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2003-12-22 09:20:14 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ObjectSpace.define_finalizer(obj, aProc=proc())
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
|
|
|
* Adds <i>aProc</i> as a finalizer, to be called after <i>obj</i>
|
|
|
|
* was destroyed.
|
|
|
|
*
|
2003-12-22 09:20:14 +03:00
|
|
|
*/
|
|
|
|
|
2000-07-15 17:37:03 +04:00
|
|
|
static 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
|
|
|
define_final(int argc, VALUE *argv, VALUE os)
|
2000-07-15 17:37:03 +04:00
|
|
|
{
|
2008-04-27 07:20:35 +04:00
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
2003-06-06 13:44:22 +04:00
|
|
|
VALUE obj, block, table;
|
* compile.c (iseq_build_body), error.c (set_syserr, get_syserr),
(syserr_initialize), gc.c (define_final, rb_gc_copy_finalizer),
(run_final), hash.c (rb_hash_aref, rb_hash_lookup2),
(rb_hash_fetch_m, rb_hash_clear, rb_hash_aset, eql_i),
iseq.c (iseq_load, iseq_data_to_ary), marshal.c (r_symlink),
thread.c (rb_thread_local_aref),
variable.c (generic_ivar_remove, ivar_get, rb_const_get_0),
(rb_cvar_get), vm.c (rb_vm_check_redefinition_opt_method),
vm_insnhelper.c (vm_get_ev_const), vm_method.c (remove_method),
ext/iconv/iconv.c (map_charset): use st_data_t.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-10-12 18:47:23 +04:00
|
|
|
st_data_t data;
|
2000-07-15 17:37:03 +04:00
|
|
|
|
2003-06-06 13:44:22 +04:00
|
|
|
rb_scan_args(argc, argv, "11", &obj, &block);
|
* array.c, gc.c, hash.c, object.c, string.c, struct.c,
transcode.c, variable.c, vm.c, vm_insnhelper.c, vm_method.c:
replace calls to rb_error_frozen() with rb_check_frozen(). a
patch from Run Paint Run Run at [ruby-core:32014]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29583 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-10-24 12:14:05 +04:00
|
|
|
rb_check_frozen(obj);
|
2000-07-15 17:37:03 +04:00
|
|
|
if (argc == 1) {
|
2003-06-16 11:14:50 +04:00
|
|
|
block = rb_block_proc();
|
2000-07-15 17:37:03 +04:00
|
|
|
}
|
2003-06-07 19:34:31 +04:00
|
|
|
else if (!rb_respond_to(block, rb_intern("call"))) {
|
|
|
|
rb_raise(rb_eArgError, "wrong type argument %s (should be callable)",
|
2003-06-06 13:44:22 +04:00
|
|
|
rb_obj_classname(block));
|
2000-07-15 17:37:03 +04:00
|
|
|
}
|
2009-01-22 06:18:16 +03:00
|
|
|
if (!FL_ABLE(obj)) {
|
|
|
|
rb_raise(rb_eArgError, "cannot define finalizer for %s",
|
|
|
|
rb_obj_classname(obj));
|
|
|
|
}
|
|
|
|
RBASIC(obj)->flags |= FL_FINALIZE;
|
2000-07-15 17:37:03 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
block = rb_ary_new3(2, INT2FIX(rb_safe_level()), block);
|
2009-01-22 06:18:16 +03:00
|
|
|
OBJ_FREEZE(block);
|
2004-06-29 05:31:37 +04:00
|
|
|
|
* compile.c (iseq_build_body), error.c (set_syserr, get_syserr),
(syserr_initialize), gc.c (define_final, rb_gc_copy_finalizer),
(run_final), hash.c (rb_hash_aref, rb_hash_lookup2),
(rb_hash_fetch_m, rb_hash_clear, rb_hash_aset, eql_i),
iseq.c (iseq_load, iseq_data_to_ary), marshal.c (r_symlink),
thread.c (rb_thread_local_aref),
variable.c (generic_ivar_remove, ivar_get, rb_const_get_0),
(rb_cvar_get), vm.c (rb_vm_check_redefinition_opt_method),
vm_insnhelper.c (vm_get_ev_const), vm_method.c (remove_method),
ext/iconv/iconv.c (map_charset): use st_data_t.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-10-12 18:47:23 +04:00
|
|
|
if (st_lookup(finalizer_table, obj, &data)) {
|
|
|
|
table = (VALUE)data;
|
2003-06-06 13:44:22 +04:00
|
|
|
rb_ary_push(table, block);
|
2000-07-15 17:37:03 +04:00
|
|
|
}
|
|
|
|
else {
|
2009-01-22 06:18:16 +03:00
|
|
|
table = rb_ary_new3(1, block);
|
|
|
|
RBASIC(table)->klass = 0;
|
|
|
|
st_add_direct(finalizer_table, obj, table);
|
2000-07-15 17:37:03 +04:00
|
|
|
}
|
2003-06-06 13:44:22 +04:00
|
|
|
return block;
|
2000-07-15 17:37:03 +04:00
|
|
|
}
|
|
|
|
|
2002-12-04 10:39:32 +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
|
|
|
rb_gc_copy_finalizer(VALUE dest, VALUE obj)
|
2002-12-04 10:39:32 +03:00
|
|
|
{
|
2008-04-27 07:20:35 +04:00
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
2002-12-04 10:39:32 +03:00
|
|
|
VALUE table;
|
* compile.c (iseq_build_body), error.c (set_syserr, get_syserr),
(syserr_initialize), gc.c (define_final, rb_gc_copy_finalizer),
(run_final), hash.c (rb_hash_aref, rb_hash_lookup2),
(rb_hash_fetch_m, rb_hash_clear, rb_hash_aset, eql_i),
iseq.c (iseq_load, iseq_data_to_ary), marshal.c (r_symlink),
thread.c (rb_thread_local_aref),
variable.c (generic_ivar_remove, ivar_get, rb_const_get_0),
(rb_cvar_get), vm.c (rb_vm_check_redefinition_opt_method),
vm_insnhelper.c (vm_get_ev_const), vm_method.c (remove_method),
ext/iconv/iconv.c (map_charset): use st_data_t.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-10-12 18:47:23 +04:00
|
|
|
st_data_t data;
|
2002-12-04 10:39:32 +03:00
|
|
|
|
|
|
|
if (!FL_TEST(obj, FL_FINALIZE)) return;
|
* compile.c (iseq_build_body), error.c (set_syserr, get_syserr),
(syserr_initialize), gc.c (define_final, rb_gc_copy_finalizer),
(run_final), hash.c (rb_hash_aref, rb_hash_lookup2),
(rb_hash_fetch_m, rb_hash_clear, rb_hash_aset, eql_i),
iseq.c (iseq_load, iseq_data_to_ary), marshal.c (r_symlink),
thread.c (rb_thread_local_aref),
variable.c (generic_ivar_remove, ivar_get, rb_const_get_0),
(rb_cvar_get), vm.c (rb_vm_check_redefinition_opt_method),
vm_insnhelper.c (vm_get_ev_const), vm_method.c (remove_method),
ext/iconv/iconv.c (map_charset): use st_data_t.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-10-12 18:47:23 +04:00
|
|
|
if (st_lookup(finalizer_table, obj, &data)) {
|
|
|
|
table = (VALUE)data;
|
2002-12-04 10:39:32 +03:00
|
|
|
st_insert(finalizer_table, dest, table);
|
|
|
|
}
|
2004-10-27 13:29:26 +04:00
|
|
|
FL_SET(dest, FL_FINALIZE);
|
2002-12-04 10:39:32 +03:00
|
|
|
}
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
static VALUE
|
2007-09-21 09:51:43 +04:00
|
|
|
run_single_final(VALUE arg)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
2007-09-21 09:51:43 +04:00
|
|
|
VALUE *args = (VALUE *)arg;
|
2004-06-29 05:31:37 +04:00
|
|
|
rb_eval_cmd(args[0], args[1], (int)args[2]);
|
1999-08-13 09:45:20 +04:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static void
|
2010-02-16 15:34:09 +03:00
|
|
|
run_finalizer(rb_objspace_t *objspace, VALUE obj, VALUE objid, VALUE table)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2002-08-21 19:47:54 +04:00
|
|
|
long i;
|
2008-07-27 09:59:32 +04:00
|
|
|
int status;
|
2010-02-16 15:34:09 +03:00
|
|
|
VALUE args[3];
|
|
|
|
|
|
|
|
args[1] = 0;
|
|
|
|
args[2] = (VALUE)rb_safe_level();
|
|
|
|
if (!args[1] && RARRAY_LEN(table) > 0) {
|
|
|
|
args[1] = rb_obj_freeze(rb_ary_new3(1, objid));
|
|
|
|
}
|
|
|
|
for (i=0; i<RARRAY_LEN(table); i++) {
|
|
|
|
VALUE final = RARRAY_PTR(table)[i];
|
|
|
|
args[0] = RARRAY_PTR(final)[1];
|
|
|
|
args[2] = FIX2INT(RARRAY_PTR(final)[0]);
|
|
|
|
rb_protect(run_single_final, (VALUE)args, &status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
run_final(rb_objspace_t *objspace, VALUE obj)
|
|
|
|
{
|
* compile.c (iseq_build_body), error.c (set_syserr, get_syserr),
(syserr_initialize), gc.c (define_final, rb_gc_copy_finalizer),
(run_final), hash.c (rb_hash_aref, rb_hash_lookup2),
(rb_hash_fetch_m, rb_hash_clear, rb_hash_aset, eql_i),
iseq.c (iseq_load, iseq_data_to_ary), marshal.c (r_symlink),
thread.c (rb_thread_local_aref),
variable.c (generic_ivar_remove, ivar_get, rb_const_get_0),
(rb_cvar_get), vm.c (rb_vm_check_redefinition_opt_method),
vm_insnhelper.c (vm_get_ev_const), vm_method.c (remove_method),
ext/iconv/iconv.c (map_charset): use st_data_t.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-10-12 18:47:23 +04:00
|
|
|
VALUE objid;
|
2009-06-17 01:36:50 +04:00
|
|
|
RUBY_DATA_FUNC free_func = 0;
|
* compile.c (iseq_build_body), error.c (set_syserr, get_syserr),
(syserr_initialize), gc.c (define_final, rb_gc_copy_finalizer),
(run_final), hash.c (rb_hash_aref, rb_hash_lookup2),
(rb_hash_fetch_m, rb_hash_clear, rb_hash_aset, eql_i),
iseq.c (iseq_load, iseq_data_to_ary), marshal.c (r_symlink),
thread.c (rb_thread_local_aref),
variable.c (generic_ivar_remove, ivar_get, rb_const_get_0),
(rb_cvar_get), vm.c (rb_vm_check_redefinition_opt_method),
vm_insnhelper.c (vm_get_ev_const), vm_method.c (remove_method),
ext/iconv/iconv.c (map_charset): use st_data_t.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-10-12 18:47:23 +04:00
|
|
|
st_data_t key, table;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2010-10-28 18:34:06 +04:00
|
|
|
objspace->heap.final_num--;
|
|
|
|
|
2005-06-19 09:09:32 +04:00
|
|
|
objid = rb_obj_id(obj); /* make obj into id */
|
2008-08-07 00:06:05 +04:00
|
|
|
RBASIC(obj)->klass = 0;
|
2008-07-27 09:59:32 +04:00
|
|
|
|
2009-06-17 01:36:50 +04:00
|
|
|
if (RTYPEDDATA_P(obj)) {
|
2010-07-18 11:31:54 +04:00
|
|
|
free_func = RTYPEDDATA_TYPE(obj)->function.dfree;
|
2009-06-17 01:36:50 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
free_func = RDATA(obj)->dfree;
|
|
|
|
}
|
|
|
|
if (free_func) {
|
|
|
|
(*free_func)(DATA_PTR(obj));
|
2008-07-25 18:48:12 +04:00
|
|
|
}
|
2008-07-27 09:59:32 +04:00
|
|
|
|
* compile.c (iseq_build_body), error.c (set_syserr, get_syserr),
(syserr_initialize), gc.c (define_final, rb_gc_copy_finalizer),
(run_final), hash.c (rb_hash_aref, rb_hash_lookup2),
(rb_hash_fetch_m, rb_hash_clear, rb_hash_aset, eql_i),
iseq.c (iseq_load, iseq_data_to_ary), marshal.c (r_symlink),
thread.c (rb_thread_local_aref),
variable.c (generic_ivar_remove, ivar_get, rb_const_get_0),
(rb_cvar_get), vm.c (rb_vm_check_redefinition_opt_method),
vm_insnhelper.c (vm_get_ev_const), vm_method.c (remove_method),
ext/iconv/iconv.c (map_charset): use st_data_t.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-10-12 18:47:23 +04:00
|
|
|
key = (st_data_t)obj;
|
2010-10-31 18:41:14 +03:00
|
|
|
if (st_delete(finalizer_table, &key, &table)) {
|
* compile.c (iseq_build_body), error.c (set_syserr, get_syserr),
(syserr_initialize), gc.c (define_final, rb_gc_copy_finalizer),
(run_final), hash.c (rb_hash_aref, rb_hash_lookup2),
(rb_hash_fetch_m, rb_hash_clear, rb_hash_aset, eql_i),
iseq.c (iseq_load, iseq_data_to_ary), marshal.c (r_symlink),
thread.c (rb_thread_local_aref),
variable.c (generic_ivar_remove, ivar_get, rb_const_get_0),
(rb_cvar_get), vm.c (rb_vm_check_redefinition_opt_method),
vm_insnhelper.c (vm_get_ev_const), vm_method.c (remove_method),
ext/iconv/iconv.c (map_charset): use st_data_t.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-10-12 18:47:23 +04:00
|
|
|
run_finalizer(objspace, obj, objid, (VALUE)table);
|
2000-07-15 17:37:03 +04:00
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
|
2008-04-27 07:20:35 +04:00
|
|
|
static void
|
2008-10-01 14:13:57 +04:00
|
|
|
finalize_deferred(rb_objspace_t *objspace)
|
2004-09-27 16:25:21 +04:00
|
|
|
{
|
|
|
|
RVALUE *p = deferred_final_list;
|
|
|
|
deferred_final_list = 0;
|
2008-07-27 09:59:32 +04:00
|
|
|
|
2004-09-27 16:25:21 +04:00
|
|
|
if (p) {
|
2008-04-27 07:20:35 +04:00
|
|
|
finalize_list(objspace, p);
|
2004-09-27 16:25:21 +04:00
|
|
|
}
|
2008-10-01 14:13:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gc_finalize_deferred(rb_objspace_t *objspace)
|
|
|
|
{
|
|
|
|
finalize_deferred(objspace);
|
2008-07-05 11:15:41 +04:00
|
|
|
free_unused_heaps(objspace);
|
2004-09-27 16:25:21 +04:00
|
|
|
}
|
|
|
|
|
2008-04-27 07:20:35 +04:00
|
|
|
void
|
|
|
|
rb_gc_finalize_deferred(void)
|
|
|
|
{
|
|
|
|
gc_finalize_deferred(&rb_objspace);
|
|
|
|
}
|
|
|
|
|
2008-06-30 13:57:07 +04:00
|
|
|
static int
|
|
|
|
chain_finalized_object(st_data_t key, st_data_t val, st_data_t arg)
|
|
|
|
{
|
|
|
|
RVALUE *p = (RVALUE *)key, **final_list = (RVALUE **)arg;
|
2010-02-16 16:10:39 +03:00
|
|
|
if ((p->as.basic.flags & (FL_FINALIZE|FL_MARK)) == FL_FINALIZE) {
|
2008-08-29 15:22:42 +04:00
|
|
|
if (BUILTIN_TYPE(p) != T_ZOMBIE) {
|
|
|
|
p->as.free.flags = FL_MARK | T_ZOMBIE; /* remain marked */
|
2008-07-27 09:59:32 +04:00
|
|
|
RDATA(p)->dfree = 0;
|
|
|
|
}
|
2008-06-30 13:57:07 +04:00
|
|
|
p->as.free.next = *final_list;
|
|
|
|
*final_list = p;
|
|
|
|
}
|
2010-02-16 15:34:09 +03:00
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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;
|
2010-05-29 19:10:01 +04:00
|
|
|
return ST_CONTINUE;
|
2008-06-30 13:57:07 +04:00
|
|
|
}
|
|
|
|
|
1998-01-16 15:19:22 +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
|
|
|
rb_gc_call_finalizer_at_exit(void)
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
2009-09-18 11:29:17 +04:00
|
|
|
rb_objspace_call_finalizer(&rb_objspace);
|
|
|
|
}
|
|
|
|
|
2010-10-31 18:41:14 +03:00
|
|
|
static void
|
2009-09-18 11:29:17 +04:00
|
|
|
rb_objspace_call_finalizer(rb_objspace_t *objspace)
|
|
|
|
{
|
1998-01-16 15:19:22 +03:00
|
|
|
RVALUE *p, *pend;
|
2008-10-01 16:36:38 +04:00
|
|
|
RVALUE *final_list = 0;
|
2008-05-11 09:44:36 +04:00
|
|
|
size_t i;
|
1998-01-16 15:19:22 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
/* run finalizers */
|
2010-10-31 18:41:14 +03:00
|
|
|
gc_clear_mark_on_sweep_slots(objspace);
|
|
|
|
|
|
|
|
do {
|
|
|
|
/* XXX: this loop will make no sense */
|
|
|
|
/* because mark will not be removed */
|
|
|
|
finalize_deferred(objspace);
|
|
|
|
mark_tbl(objspace, finalizer_table, 0);
|
|
|
|
st_foreach(finalizer_table, chain_finalized_object,
|
|
|
|
(st_data_t)&deferred_final_list);
|
|
|
|
} while (deferred_final_list);
|
|
|
|
/* 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;
|
|
|
|
run_finalizer(objspace, curr->obj, rb_obj_id(curr->obj), curr->table);
|
|
|
|
st_delete(finalizer_table, (st_data_t*)&curr->obj, 0);
|
|
|
|
list = curr->next;
|
|
|
|
xfree(curr);
|
2008-08-06 16:25:47 +04:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
2010-10-31 18:41:14 +03:00
|
|
|
|
2008-06-30 13:57:07 +04:00
|
|
|
/* finalizers are part of garbage collection */
|
|
|
|
during_gc++;
|
2010-10-31 18:41:14 +03:00
|
|
|
|
2003-08-01 18:57:48 +04:00
|
|
|
/* run data object's finalizers */
|
2004-04-07 10:30:15 +04:00
|
|
|
for (i = 0; i < heaps_used; i++) {
|
2010-05-28 15:13:42 +04:00
|
|
|
p = objspace->heap.sorted[i].start; pend = objspace->heap.sorted[i].end;
|
1998-01-16 15:19:22 +03:00
|
|
|
while (p < pend) {
|
|
|
|
if (BUILTIN_TYPE(p) == T_DATA &&
|
2004-04-07 06:51:05 +04:00
|
|
|
DATA_PTR(p) && RANY(p)->as.data.dfree &&
|
2008-11-07 23:47:02 +03:00
|
|
|
RANY(p)->as.basic.klass != rb_cThread && RANY(p)->as.basic.klass != rb_cMutex) {
|
2001-02-02 14:38:20 +03:00
|
|
|
p->as.free.flags = 0;
|
2009-07-07 12:00:44 +04:00
|
|
|
if (RTYPEDDATA_P(p)) {
|
2010-07-18 11:31:54 +04:00
|
|
|
RDATA(p)->dfree = RANY(p)->as.typeddata.type->function.dfree;
|
2009-07-07 12:00:44 +04:00
|
|
|
}
|
2010-10-12 18:09:27 +04:00
|
|
|
if (RANY(p)->as.data.dfree == (RUBY_DATA_FUNC)-1) {
|
* 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
|
|
|
xfree(DATA_PTR(p));
|
2003-03-23 13:55:39 +03:00
|
|
|
}
|
|
|
|
else if (RANY(p)->as.data.dfree) {
|
2008-10-01 14:13:57 +04:00
|
|
|
make_deferred(RANY(p));
|
2008-10-01 16:36:38 +04:00
|
|
|
RANY(p)->as.free.next = final_list;
|
|
|
|
final_list = p;
|
2003-03-23 13:55:39 +03:00
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
else if (BUILTIN_TYPE(p) == T_FILE) {
|
2008-10-01 14:13:57 +04:00
|
|
|
if (RANY(p)->as.file.fptr) {
|
|
|
|
make_io_deferred(RANY(p));
|
2008-10-01 16:36:38 +04:00
|
|
|
RANY(p)->as.free.next = final_list;
|
|
|
|
final_list = p;
|
2004-04-07 06:51:05 +04:00
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
2006-02-13 07:53:22 +03:00
|
|
|
during_gc = 0;
|
2008-10-01 16:36:38 +04:00
|
|
|
if (final_list) {
|
|
|
|
finalize_list(objspace, final_list);
|
|
|
|
}
|
2010-10-31 18:41:14 +03:00
|
|
|
|
|
|
|
st_free_table(finalizer_table);
|
|
|
|
finalizer_table = 0;
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
|
2008-04-27 07:20:35 +04:00
|
|
|
void
|
|
|
|
rb_gc(void)
|
|
|
|
{
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
2008-07-02 04:49:10 +04:00
|
|
|
garbage_collect(objspace);
|
2008-07-05 11:15:41 +04:00
|
|
|
gc_finalize_deferred(objspace);
|
2008-04-27 07:20:35 +04:00
|
|
|
}
|
|
|
|
|
2003-12-22 09:20:14 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ObjectSpace._id2ref(object_id) -> an_object
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
2003-12-22 09:20:14 +03:00
|
|
|
* 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.
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
2003-12-22 09:20:14 +03:00
|
|
|
* s = "I am a string" #=> "I am a string"
|
|
|
|
* r = ObjectSpace._id2ref(s.object_id) #=> "I am a string"
|
|
|
|
* r == s #=> true
|
2005-06-19 21:16:14 +04:00
|
|
|
*
|
2003-12-22 09:20:14 +03:00
|
|
|
*/
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
static VALUE
|
2006-03-02 08:22:30 +03:00
|
|
|
id2ref(VALUE obj, VALUE objid)
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
2005-07-27 11:27:19 +04:00
|
|
|
#if SIZEOF_LONG == SIZEOF_VOIDP
|
|
|
|
#define NUM2PTR(x) NUM2ULONG(x)
|
|
|
|
#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
|
|
|
|
#define NUM2PTR(x) NUM2ULL(x)
|
|
|
|
#endif
|
2008-04-27 07:20:35 +04:00
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
2005-07-27 11:27:19 +04:00
|
|
|
VALUE ptr;
|
|
|
|
void *p0;
|
1998-01-16 15:19:22 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_secure(4);
|
2006-03-02 08:22:30 +03:00
|
|
|
ptr = NUM2PTR(objid);
|
2005-07-27 11:27:19 +04:00
|
|
|
p0 = (void *)ptr;
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (ptr == Qtrue) return Qtrue;
|
|
|
|
if (ptr == Qfalse) return Qfalse;
|
|
|
|
if (ptr == Qnil) return Qnil;
|
2001-03-21 06:41:45 +03:00
|
|
|
if (FIXNUM_P(ptr)) return (VALUE)ptr;
|
2006-03-04 09:28:51 +03:00
|
|
|
ptr = objid ^ FIXNUM_FLAG; /* unset FIXNUM_FLAG */
|
2006-03-02 08:22:30 +03:00
|
|
|
|
2006-03-04 09:28:51 +03:00
|
|
|
if ((ptr % sizeof(RVALUE)) == (4 << 2)) {
|
|
|
|
ID symid = ptr / sizeof(RVALUE);
|
2006-03-02 08:22:30 +03:00
|
|
|
if (rb_id2name(symid) == 0)
|
2007-06-25 15:19:11 +04:00
|
|
|
rb_raise(rb_eRangeError, "%p is not symbol id value", p0);
|
2006-12-31 18:02:22 +03:00
|
|
|
return ID2SYM(symid);
|
2001-03-21 06:41:45 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2008-04-27 07:20:35 +04:00
|
|
|
if (!is_pointer_to_heap(objspace, (void *)ptr) ||
|
* vm.c, insns.def, eval.c, vm_insnhelper.c: fix CREF handling.
VM value stack frame of block contains cref information.
(dfp[-1] points CREF)
* compile.c, eval_intern.h, eval_method.c, load.c, proc.c,
vm_dump.h, vm_core.h: ditto.
* include/ruby/ruby.h, gc.c: remove T_VALUES because of above
changes.
* bootstraptest/test_eval.rb, test_knownbug.rb: move solved test.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16468 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-05-19 07:08:50 +04:00
|
|
|
BUILTIN_TYPE(ptr) > T_FIXNUM || BUILTIN_TYPE(ptr) == T_ICLASS) {
|
2005-07-27 11:27:19 +04:00
|
|
|
rb_raise(rb_eRangeError, "%p is not id value", p0);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
2003-08-22 12:09:58 +04:00
|
|
|
if (BUILTIN_TYPE(ptr) == 0 || RBASIC(ptr)->klass == 0) {
|
2005-07-27 11:27:19 +04:00
|
|
|
rb_raise(rb_eRangeError, "%p is recycled object", p0);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
return (VALUE)ptr;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2006-03-02 08:22:30 +03:00
|
|
|
/*
|
|
|
|
* Document-method: __id__
|
|
|
|
* Document-method: object_id
|
|
|
|
*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* obj.__id__ -> fixnum
|
|
|
|
* obj.object_id -> fixnum
|
2008-03-12 06:49:55 +03:00
|
|
|
*
|
2006-03-02 08:22:30 +03:00
|
|
|
* Returns an integer identifier for <i>obj</i>. The same number will
|
|
|
|
* be returned on all calls to <code>id</code> for a given object, and
|
|
|
|
* no two active objects will share an id.
|
|
|
|
* <code>Object#object_id</code> is a different concept from the
|
|
|
|
* <code>:name</code> notation, which returns the symbol id of
|
|
|
|
* <code>name</code>. Replaces the deprecated <code>Object#id</code>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* obj.hash -> fixnum
|
2008-03-12 06:49:55 +03:00
|
|
|
*
|
2006-03-02 08:22:30 +03:00
|
|
|
* Generates a <code>Fixnum</code> 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 class
|
|
|
|
* <code>Hash</code>. Any hash value that exceeds the capacity of a
|
|
|
|
* <code>Fixnum</code> will be truncated before being used.
|
|
|
|
*/
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_obj_id(VALUE obj)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* 32-bit VALUE space
|
|
|
|
* MSB ------------------------ LSB
|
|
|
|
* false 00000000000000000000000000000000
|
|
|
|
* true 00000000000000000000000000000010
|
|
|
|
* nil 00000000000000000000000000000100
|
|
|
|
* undef 00000000000000000000000000000110
|
|
|
|
* symbol ssssssssssssssssssssssss00001110
|
2007-06-28 06:32:25 +04:00
|
|
|
* object oooooooooooooooooooooooooooooo00 = 0 (mod sizeof(RVALUE))
|
2006-03-02 08:22:30 +03:00
|
|
|
* fixnum fffffffffffffffffffffffffffffff1
|
|
|
|
*
|
|
|
|
* object_id space
|
|
|
|
* LSB
|
|
|
|
* false 00000000000000000000000000000000
|
|
|
|
* true 00000000000000000000000000000010
|
|
|
|
* nil 00000000000000000000000000000100
|
|
|
|
* undef 00000000000000000000000000000110
|
2007-06-28 06:32:25 +04:00
|
|
|
* symbol 000SSSSSSSSSSSSSSSSSSSSSSSSSSS0 S...S % A = 4 (S...S = s...s * A + 4)
|
2006-03-02 08:22:30 +03:00
|
|
|
* 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
|
|
|
|
*/
|
2010-06-07 22:30:42 +04:00
|
|
|
if (SYMBOL_P(obj)) {
|
2006-12-31 18:02:22 +03:00
|
|
|
return (SYM2ID(obj) * sizeof(RVALUE) + (4 << 2)) | FIXNUM_FLAG;
|
|
|
|
}
|
2006-03-02 08:22:30 +03:00
|
|
|
if (SPECIAL_CONST_P(obj)) {
|
2007-06-28 06:32:25 +04:00
|
|
|
return LONG2NUM((SIGNED_VALUE)obj);
|
2006-03-02 08:22:30 +03:00
|
|
|
}
|
2007-06-28 06:32:25 +04:00
|
|
|
return (VALUE)((SIGNED_VALUE)obj|FIXNUM_FLAG);
|
2006-03-02 08:22:30 +03:00
|
|
|
}
|
|
|
|
|
2008-05-31 18:03:23 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-11-03 18:09:10 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ObjectSpace.count_objects([result_hash]) -> hash
|
|
|
|
*
|
|
|
|
* Counts objects for each type.
|
|
|
|
*
|
2007-11-04 02:13:57 +03:00
|
|
|
* It returns a hash as:
|
|
|
|
* {:TOTAL=>10000, :FREE=>3011, :T_OBJECT=>6, :T_CLASS=>404, ...}
|
2007-11-03 18:09:10 +03:00
|
|
|
*
|
|
|
|
* If the optional argument, result_hash, is given,
|
|
|
|
* it is overwritten and returned.
|
|
|
|
* This is intended to avoid probe effect.
|
|
|
|
*
|
|
|
|
* The contents of the returned hash is implementation defined.
|
|
|
|
* It may be changed in future.
|
|
|
|
*
|
|
|
|
* This method is not expected to work except C Ruby.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
count_objects(int argc, VALUE *argv, VALUE os)
|
|
|
|
{
|
2008-04-27 07:20:35 +04:00
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
2008-05-11 09:44:36 +04:00
|
|
|
size_t counts[T_MASK+1];
|
|
|
|
size_t freed = 0;
|
|
|
|
size_t total = 0;
|
|
|
|
size_t i;
|
2007-11-03 18:09:10 +03:00
|
|
|
VALUE hash;
|
|
|
|
|
|
|
|
if (rb_scan_args(argc, argv, "01", &hash) == 1) {
|
|
|
|
if (TYPE(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;
|
|
|
|
|
2010-05-28 15:13:42 +04:00
|
|
|
p = objspace->heap.sorted[i].start; pend = objspace->heap.sorted[i].end;
|
2007-11-03 18:09:10 +03:00
|
|
|
for (;p < pend; p++) {
|
|
|
|
if (p->as.basic.flags) {
|
|
|
|
counts[BUILTIN_TYPE(p)]++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
freed++;
|
|
|
|
}
|
|
|
|
}
|
2010-05-28 15:13:42 +04:00
|
|
|
total += objspace->heap.sorted[i].slot->limit;
|
2007-11-03 18:09:10 +03:00
|
|
|
}
|
|
|
|
|
2008-06-06 10:05:44 +04:00
|
|
|
if (hash == Qnil) {
|
2007-11-03 18:09:10 +03:00
|
|
|
hash = rb_hash_new();
|
2008-06-06 10:05:44 +04:00
|
|
|
}
|
|
|
|
else if (!RHASH_EMPTY_P(hash)) {
|
|
|
|
st_foreach(RHASH_TBL(hash), set_zero, hash);
|
|
|
|
}
|
2008-05-11 09:44:36 +04:00
|
|
|
rb_hash_aset(hash, ID2SYM(rb_intern("TOTAL")), SIZET2NUM(total));
|
|
|
|
rb_hash_aset(hash, ID2SYM(rb_intern("FREE")), SIZET2NUM(freed));
|
2008-08-11 13:36:57 +04:00
|
|
|
|
2007-11-03 18:09:10 +03:00
|
|
|
for (i = 0; i <= T_MASK; i++) {
|
|
|
|
VALUE type;
|
|
|
|
switch (i) {
|
2008-04-26 12:42:34 +04:00
|
|
|
#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);
|
2008-08-29 15:22:42 +04:00
|
|
|
COUNT_TYPE(T_ZOMBIE);
|
2008-04-26 12:42:34 +04:00
|
|
|
#undef COUNT_TYPE
|
2007-11-03 18:09:10 +03:00
|
|
|
default: type = INT2NUM(i); break;
|
|
|
|
}
|
|
|
|
if (counts[i])
|
2008-05-11 09:44:36 +04:00
|
|
|
rb_hash_aset(hash, type, SIZET2NUM(counts[i]));
|
2007-11-03 18:09:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
2008-04-27 10:28:08 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* GC.count -> Integer
|
|
|
|
*
|
2009-11-03 20:46:28 +03:00
|
|
|
* The number of times GC occurred.
|
2008-04-27 10:28:08 +04:00
|
|
|
*
|
2009-11-03 20:46:28 +03:00
|
|
|
* It returns the number of times GC occurred since the process started.
|
2008-04-27 10:28:08 +04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
gc_count(VALUE self)
|
|
|
|
{
|
|
|
|
return UINT2NUM((&rb_objspace)->count);
|
|
|
|
}
|
|
|
|
|
2010-10-27 23:02:24 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* GC.stat -> Hash
|
|
|
|
*
|
|
|
|
* Return information about GC.
|
|
|
|
*
|
|
|
|
* It returns the hash includes information about internal statistisc
|
|
|
|
* about GC such as: {:count => 42, ...}
|
|
|
|
*
|
|
|
|
* The contents of the returned hash is implementation defined.
|
|
|
|
* It may be changed in future.
|
|
|
|
*
|
|
|
|
* This method is not expected to work except C Ruby.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
gc_stat(int argc, VALUE *argv, VALUE self)
|
|
|
|
{
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
VALUE hash;
|
|
|
|
|
|
|
|
if (rb_scan_args(argc, argv, "01", &hash) == 1) {
|
|
|
|
if (TYPE(hash) != T_HASH)
|
|
|
|
rb_raise(rb_eTypeError, "non-hash given");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hash == Qnil) {
|
|
|
|
hash = rb_hash_new();
|
|
|
|
}
|
|
|
|
|
|
|
|
rest_sweep(objspace);
|
|
|
|
|
|
|
|
rb_hash_aset(hash, ID2SYM(rb_intern("count")), SIZET2NUM(objspace->count));
|
|
|
|
|
|
|
|
/* implementation dependent counters */
|
|
|
|
rb_hash_aset(hash, ID2SYM(rb_intern("heap_used")), SIZET2NUM(objspace->heap.used));
|
|
|
|
rb_hash_aset(hash, ID2SYM(rb_intern("heap_length")), SIZET2NUM(objspace->heap.length));
|
|
|
|
rb_hash_aset(hash, ID2SYM(rb_intern("heap_increment")), SIZET2NUM(objspace->heap.increment));
|
|
|
|
rb_hash_aset(hash, ID2SYM(rb_intern("heap_live_num")), SIZET2NUM(objspace->heap.live_num));
|
|
|
|
rb_hash_aset(hash, ID2SYM(rb_intern("heap_free_num")), SIZET2NUM(objspace->heap.free_num));
|
|
|
|
rb_hash_aset(hash, ID2SYM(rb_intern("heap_final_num")), SIZET2NUM(objspace->heap.final_num));
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-08 14:27:06 +04:00
|
|
|
#if CALC_EXACT_MALLOC_SIZE
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* GC.malloc_allocated_size -> Integer
|
|
|
|
*
|
|
|
|
* The allocated size by malloc().
|
|
|
|
*
|
|
|
|
* It returns the allocated size by malloc().
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
gc_malloc_allocated_size(VALUE self)
|
|
|
|
{
|
|
|
|
return UINT2NUM((&rb_objspace)->malloc_params.allocated_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* GC.malloc_allocations -> Integer
|
|
|
|
*
|
|
|
|
* The number of allocated memory object by malloc().
|
|
|
|
*
|
|
|
|
* It returns the number of allocated memory object by malloc().
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
gc_malloc_allocations(VALUE self)
|
|
|
|
{
|
|
|
|
return UINT2NUM((&rb_objspace)->malloc_params.allocations);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i =0; i < objspace->profile.count; i++) {
|
|
|
|
prof = rb_hash_new();
|
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));
|
2010-05-28 15:13:42 +04:00
|
|
|
rb_hash_aset(prof, ID2SYM(rb_intern("GC_IS_MARKED")), objspace->profile.record[i].is_marked);
|
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));
|
2008-08-11 13:36:57 +04:00
|
|
|
rb_hash_aset(prof, ID2SYM(rb_intern("HAVE_FINALIZE")), objspace->profile.record[i].have_finalize);
|
|
|
|
#endif
|
|
|
|
rb_ary_push(gc_profile, prof);
|
|
|
|
}
|
|
|
|
|
|
|
|
return gc_profile;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* GC::Profiler.result -> string
|
|
|
|
*
|
|
|
|
* Report profile data to string.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2008-08-11 13:36:57 +04:00
|
|
|
* It returns a string 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
|
|
|
|
*/
|
|
|
|
|
2008-09-04 14:47:39 +04:00
|
|
|
static VALUE
|
2008-08-11 13:36:57 +04:00
|
|
|
gc_profile_result(void)
|
|
|
|
{
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
2008-09-04 14:47:39 +04:00
|
|
|
VALUE record;
|
2008-08-12 11:24:30 +04:00
|
|
|
VALUE result;
|
2010-05-28 15:13:42 +04:00
|
|
|
int i, index;
|
2009-02-22 17:23:33 +03:00
|
|
|
|
2008-09-04 14:47:39 +04:00
|
|
|
record = gc_profile_record_get();
|
2008-08-12 11:24:30 +04:00
|
|
|
if (objspace->profile.run && objspace->profile.count) {
|
|
|
|
result = rb_sprintf("GC %d invokes.\n", NUM2INT(gc_count(0)));
|
2010-08-16 15:31:58 +04:00
|
|
|
index = 1;
|
2008-08-11 15:11:27 +04:00
|
|
|
rb_str_cat2(result, "Index Invoke Time(sec) Use Size(byte) Total Size(byte) Total Object GC Time(ms)\n");
|
2008-08-12 11:24:30 +04:00
|
|
|
for (i = 0; i < (int)RARRAY_LEN(record); i++) {
|
2008-08-11 13:36:57 +04:00
|
|
|
VALUE r = RARRAY_PTR(record)[i];
|
2010-05-28 15:13:42 +04:00
|
|
|
#if !GC_PROFILE_MORE_DETAIL
|
|
|
|
if (rb_hash_aref(r, ID2SYM(rb_intern("GC_IS_MARKED")))) {
|
|
|
|
#endif
|
2010-08-16 15:31:54 +04:00
|
|
|
rb_str_catf(result, "%5d %19.3f %20"PRIuSIZE" %20"PRIuSIZE" %20"PRIuSIZE" %30.20f\n",
|
2010-05-28 15:13:42 +04:00
|
|
|
index++, NUM2DBL(rb_hash_aref(r, ID2SYM(rb_intern("GC_INVOKE_TIME")))),
|
2010-08-16 15:31:54 +04:00
|
|
|
(size_t)NUM2SIZET(rb_hash_aref(r, ID2SYM(rb_intern("HEAP_USE_SIZE")))),
|
|
|
|
(size_t)NUM2SIZET(rb_hash_aref(r, ID2SYM(rb_intern("HEAP_TOTAL_SIZE")))),
|
|
|
|
(size_t)NUM2SIZET(rb_hash_aref(r, ID2SYM(rb_intern("HEAP_TOTAL_OBJECTS")))),
|
2009-08-10 06:40:34 +04:00
|
|
|
NUM2DBL(rb_hash_aref(r, ID2SYM(rb_intern("GC_TIME"))))*1000);
|
2010-05-28 15:13:42 +04:00
|
|
|
#if !GC_PROFILE_MORE_DETAIL
|
|
|
|
}
|
|
|
|
#endif
|
2008-08-11 13:36:57 +04:00
|
|
|
}
|
|
|
|
#if GC_PROFILE_MORE_DETAIL
|
2008-08-12 11:02:04 +04:00
|
|
|
rb_str_cat2(result, "\n\n");
|
|
|
|
rb_str_cat2(result, "More detail.\n");
|
2009-08-10 06:40:34 +04:00
|
|
|
rb_str_cat2(result, "Index Allocate Increase Allocate Limit Use Slot Have Finalize Mark Time(ms) Sweep Time(ms)\n");
|
2010-08-16 15:31:58 +04:00
|
|
|
index = 1;
|
2008-08-11 15:11:27 +04:00
|
|
|
for (i = 0; i < (int)RARRAY_LEN(record); i++) {
|
2008-08-11 13:36:57 +04:00
|
|
|
VALUE r = RARRAY_PTR(record)[i];
|
2010-08-16 15:31:54 +04:00
|
|
|
rb_str_catf(result, "%5d %17"PRIuSIZE" %17"PRIuSIZE" %9"PRIuSIZE" %14s %25.20f %25.20f\n",
|
|
|
|
index++, (size_t)NUM2SIZET(rb_hash_aref(r, ID2SYM(rb_intern("ALLOCATE_INCREASE")))),
|
|
|
|
(size_t)NUM2SIZET(rb_hash_aref(r, ID2SYM(rb_intern("ALLOCATE_LIMIT")))),
|
|
|
|
(size_t)NUM2SIZET(rb_hash_aref(r, ID2SYM(rb_intern("HEAP_USE_SLOTS")))),
|
2008-08-11 15:11:27 +04:00
|
|
|
rb_hash_aref(r, ID2SYM(rb_intern("HAVE_FINALIZE")))? "true" : "false",
|
2008-10-25 15:10:39 +04:00
|
|
|
NUM2DBL(rb_hash_aref(r, ID2SYM(rb_intern("GC_MARK_TIME"))))*1000,
|
2009-08-10 06:40:34 +04:00
|
|
|
NUM2DBL(rb_hash_aref(r, ID2SYM(rb_intern("GC_SWEEP_TIME"))))*1000);
|
2008-08-11 13:36:57 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2008-08-12 11:24:30 +04:00
|
|
|
else {
|
|
|
|
result = rb_str_new2("");
|
|
|
|
}
|
2008-08-11 13:36:57 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* GC::Profiler.report
|
|
|
|
*
|
|
|
|
* GC::Profiler.result display
|
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);
|
|
|
|
}
|
|
|
|
rb_io_write(out, gc_profile_result());
|
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2010-03-04 07:51:43 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* GC::Profiler.total_time -> float
|
|
|
|
*
|
|
|
|
* return total time that GC used. (msec)
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
gc_profile_total_time(VALUE self)
|
|
|
|
{
|
|
|
|
double time = 0;
|
|
|
|
rb_objspace_t *objspace = &rb_objspace;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (objspace->profile.run && objspace->profile.count) {
|
|
|
|
for (i = 0; i < objspace->profile.count; i++) {
|
|
|
|
time += objspace->profile.record[i].gc_time;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return DBL2NUM(time);
|
|
|
|
}
|
|
|
|
|
2010-05-28 15:13:42 +04:00
|
|
|
|
2003-12-22 09:20:14 +03:00
|
|
|
/*
|
|
|
|
* The <code>GC</code> module provides an interface to Ruby's mark and
|
|
|
|
* sweep garbage collection mechanism. Some of the underlying methods
|
|
|
|
* are also available via the <code>ObjectSpace</code> module.
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE rb_mObSpace;
|
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);
|
|
|
|
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
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_mObSpace = rb_define_module("ObjectSpace");
|
|
|
|
rb_define_module_function(rb_mObSpace, "each_object", os_each_obj, -1);
|
2001-01-29 08:10:42 +03:00
|
|
|
rb_define_module_function(rb_mObSpace, "garbage_collect", rb_gc_start, 0);
|
2000-07-15 17:37:03 +04:00
|
|
|
|
|
|
|
rb_define_module_function(rb_mObSpace, "define_finalizer", define_final, -1);
|
|
|
|
rb_define_module_function(rb_mObSpace, "undefine_finalizer", undefine_final, 1);
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_module_function(rb_mObSpace, "_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
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_define_method(rb_mKernel, "__id__", rb_obj_id, 0);
|
|
|
|
rb_define_method(rb_mKernel, "object_id", rb_obj_id, 0);
|
2007-11-03 18:09:10 +03:00
|
|
|
|
|
|
|
rb_define_module_function(rb_mObSpace, "count_objects", count_objects, -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
|
|
|
}
|