172
173
#if defined(DJGPP) || defined(_WIN32_WCE)
173
static unsigned int STACK_LEVEL_MAX = 65535;
174
#elif defined(__human68k__)
175
unsigned int _stacksize = 262144;
176
# define STACK_LEVEL_MAX (_stacksize - 4096)
177
# undef HAVE_GETRLIMIT
178
#elif defined(HAVE_GETRLIMIT) || defined(_WIN32)
179
static unsigned int STACK_LEVEL_MAX = 655300;
174
size_t rb_gc_stack_maxsize = 65535*sizeof(VALUE);
181
# define STACK_LEVEL_MAX 655300
176
size_t rb_gc_stack_maxsize = 655300*sizeof(VALUE);
1249
1277
switch (RANY(obj)->as.basic.flags & T_MASK) {
1251
if (RANY(obj)->as.object.iv_tbl) {
1252
st_free_table(RANY(obj)->as.object.iv_tbl);
1279
if (!(RANY(obj)->as.basic.flags & ROBJECT_EMBED) &&
1280
RANY(obj)->as.object.as.heap.ptr) {
1281
RUBY_CRITICAL(free(RANY(obj)->as.object.as.heap.ptr));
1257
1286
rb_clear_cache_by_class((VALUE)obj);
1258
st_free_table(RANY(obj)->as.klass.m_tbl);
1259
if (RANY(obj)->as.object.iv_tbl) {
1260
st_free_table(RANY(obj)->as.object.iv_tbl);
1287
st_free_table(RCLASS_M_TBL(obj));
1288
if (RCLASS_IV_TBL(obj)) {
1289
st_free_table(RCLASS_IV_TBL(obj));
1291
if (RCLASS_IV_INDEX_TBL(obj)) {
1292
st_free_table(RCLASS_IV_INDEX_TBL(obj));
1294
RUBY_CRITICAL(free(RANY(obj)->as.klass.ptr));
1264
1297
rb_str_free(obj);
1711
1752
if (FL_TEST(p, FL_SINGLETON)) continue;
1713
1754
if (!p->as.basic.klass) continue;
1730
for (i = 0; i < heaps_used; i++) {
1733
p = heaps[i].slot; pend = p + heaps[i].limit;
1734
for (;p < pend; p++) {
1735
if (p->as.basic.flags) {
1741
if (FL_TEST(p, FL_SINGLETON)) continue;
1743
if (!p->as.basic.klass) continue;
1744
if (rb_obj_is_kind_of((VALUE)p, of)) {
1755
if (!of || rb_obj_is_kind_of((VALUE)p, of)) {
1745
1756
rb_yield((VALUE)p);
1937
1947
objid = rb_obj_id(obj); /* make obj into id */
1938
1948
rb_thread_critical = Qtrue;
1950
if (RARRAY_LEN(finalizers) > 0) {
1951
args[1] = rb_obj_freeze(rb_ary_new3(1, objid));
1940
1953
args[2] = (VALUE)rb_safe_level();
1941
1954
for (i=0; i<RARRAY_LEN(finalizers); i++) {
1942
1955
args[0] = RARRAY_PTR(finalizers)[i];
1943
if (!args[1]) args[1] = rb_ary_new3(1, objid);
1944
rb_protect((VALUE(*)(VALUE))run_single_final, (VALUE)args, &status);
1956
rb_protect(run_single_final, (VALUE)args, &status);
1946
1958
if (finalizer_table && st_delete(finalizer_table, (st_data_t*)&obj, &table)) {
1959
if (!args[1] && RARRAY_LEN(table) > 0) {
1960
args[1] = rb_obj_freeze(rb_ary_new3(1, objid));
1947
1962
for (i=0; i<RARRAY_LEN(table); i++) {
1948
1963
VALUE final = RARRAY_PTR(table)[i];
1949
1964
args[0] = RARRAY_PTR(final)[1];
1950
if (!args[1]) args[1] = rb_ary_new3(1, objid);
1951
1965
args[2] = FIX2INT(RARRAY_PTR(final)[0]);
1952
rb_protect((VALUE(*)(VALUE))run_single_final, (VALUE)args, &status);
1966
rb_protect(run_single_final, (VALUE)args, &status);
1955
1969
rb_thread_critical = critical_save;
2159
* ObjectSpace.count_objects([result_hash]) -> hash
2161
* Counts objects for each type.
2163
* It returns a hash as:
2164
* {:TOTAL=>10000, :FREE=>3011, :T_OBJECT=>6, :T_CLASS=>404, ...}
2166
* If the optional argument, result_hash, is given,
2167
* it is overwritten and returned.
2168
* This is intended to avoid probe effect.
2170
* The contents of the returned hash is implementation defined.
2171
* It may be changed in future.
2173
* This method is not expected to work except C Ruby.
2178
count_objects(int argc, VALUE *argv, VALUE os)
2180
long counts[T_MASK+1];
2186
if (rb_scan_args(argc, argv, "01", &hash) == 1) {
2187
if (TYPE(hash) != T_HASH)
2188
rb_raise(rb_eTypeError, "non-hash given");
2191
for (i = 0; i <= T_MASK; i++) {
2195
for (i = 0; i < heaps_used; i++) {
2198
p = heaps[i].slot; pend = p + heaps[i].limit;
2199
for (;p < pend; p++) {
2200
if (p->as.basic.flags) {
2201
counts[BUILTIN_TYPE(p)]++;
2207
total += heaps[i].limit;
2211
hash = rb_hash_new();
2212
rb_hash_aset(hash, ID2SYM(rb_intern("TOTAL")), LONG2NUM(total));
2213
rb_hash_aset(hash, ID2SYM(rb_intern("FREE")), LONG2NUM(freed));
2214
for (i = 0; i <= T_MASK; i++) {
2217
case T_NONE: type = ID2SYM(rb_intern("T_NONE")); break;
2218
case T_NIL: type = ID2SYM(rb_intern("T_NIL")); break;
2219
case T_OBJECT: type = ID2SYM(rb_intern("T_OBJECT")); break;
2220
case T_CLASS: type = ID2SYM(rb_intern("T_CLASS")); break;
2221
case T_ICLASS: type = ID2SYM(rb_intern("T_ICLASS")); break;
2222
case T_MODULE: type = ID2SYM(rb_intern("T_MODULE")); break;
2223
case T_FLOAT: type = ID2SYM(rb_intern("T_FLOAT")); break;
2224
case T_STRING: type = ID2SYM(rb_intern("T_STRING")); break;
2225
case T_REGEXP: type = ID2SYM(rb_intern("T_REGEXP")); break;
2226
case T_ARRAY: type = ID2SYM(rb_intern("T_ARRAY")); break;
2227
case T_FIXNUM: type = ID2SYM(rb_intern("T_FIXNUM")); break;
2228
case T_HASH: type = ID2SYM(rb_intern("T_HASH")); break;
2229
case T_STRUCT: type = ID2SYM(rb_intern("T_STRUCT")); break;
2230
case T_BIGNUM: type = ID2SYM(rb_intern("T_BIGNUM")); break;
2231
case T_FILE: type = ID2SYM(rb_intern("T_FILE")); break;
2232
case T_TRUE: type = ID2SYM(rb_intern("T_TRUE")); break;
2233
case T_FALSE: type = ID2SYM(rb_intern("T_FALSE")); break;
2234
case T_DATA: type = ID2SYM(rb_intern("T_DATA")); break;
2235
case T_MATCH: type = ID2SYM(rb_intern("T_MATCH")); break;
2236
case T_SYMBOL: type = ID2SYM(rb_intern("T_SYMBOL")); break;
2237
case T_VALUES: type = ID2SYM(rb_intern("T_VALUES")); break;
2238
case T_BLOCK: type = ID2SYM(rb_intern("T_BLOCK")); break;
2239
case T_UNDEF: type = ID2SYM(rb_intern("T_UNDEF")); break;
2240
case T_NODE: type = ID2SYM(rb_intern("T_NODE")); break;
2241
default: type = INT2NUM(i); break;
2244
rb_hash_aset(hash, type, LONG2NUM(counts[i]));
2143
2251
* The <code>GC</code> module provides an interface to Ruby's mark and
2144
2252
* sweep garbage collection mechanism. Some of the underlying methods
2145
2253
* are also available via the <code>ObjectSpace</code> module.
2184
2292
rb_define_method(rb_mKernel, "hash", rb_obj_id, 0);
2185
2293
rb_define_method(rb_mKernel, "__id__", rb_obj_id, 0);
2186
2294
rb_define_method(rb_mKernel, "object_id", rb_obj_id, 0);
2296
rb_define_module_function(rb_mObSpace, "count_objects", count_objects, -1);