summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-09-08 00:02:55 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-09-08 00:02:55 +0000
commitac6ad66d0b6a023357245dbe7d605e793b9448ce (patch)
treed9268f8b3127c7a38b7cc7d071be6b89dd77e786 /gc.c
parent6572bd3ce9bce5199bbebfe78b2b61290b0308a7 (diff)
* gc.c (id2ref): objects which are unmarked but not in sweep_slots
are not dead. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33222 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/gc.c b/gc.c
index e2e3625635..fff33b5217 100644
--- a/gc.c
+++ b/gc.c
@@ -2140,10 +2140,10 @@ 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);
+ while (objspace->heap.sweep_slots) {
+ lazy_sweep(objspace);
+ }
+ after_gc_sweep(objspace);
}
}
@@ -3086,6 +3086,20 @@ rb_gc(void)
free_unused_heaps(objspace);
}
+static inline int
+is_dead_object(rb_objspace_t *objspace, VALUE ptr)
+{
+ struct heaps_slot *slot = objspace->heap.sweep_slots;
+ if (!is_lazy_sweeping(objspace) || (RBASIC(ptr)->flags & FL_MARK))
+ return FALSE;
+ while (slot) {
+ if ((VALUE)slot->slot <= ptr && ptr < (VALUE)(slot->slot + slot->limit))
+ return TRUE;
+ slot = slot->next;
+ }
+ return FALSE;
+}
+
/*
* call-seq:
* ObjectSpace._id2ref(object_id) -> an_object
@@ -3133,7 +3147,7 @@ id2ref(VALUE obj, VALUE objid)
rb_raise(rb_eRangeError, "%p is not id value", p0);
}
if (BUILTIN_TYPE(ptr) == 0 || RBASIC(ptr)->klass == 0 ||
- (is_lazy_sweeping(objspace) && !(RBASIC(ptr)->flags & FL_MARK))) {
+ is_dead_object(objspace, ptr)) {
rb_raise(rb_eRangeError, "%p is recycled object", p0);
}
return (VALUE)ptr;