Permalink
Browse files

No commit message

  • Loading branch information...
1 parent 2aceed7 commit 942f017bb3778feff2cea2bb2435c93fac2cad87 @skaes committed Apr 1, 2012
Showing with 22 additions and 1 deletion.
  1. +22 −1 gc.c
View
23 gc.c
@@ -248,7 +248,6 @@ getrusage_time(void)
} while(0)
#endif
-
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__CYGWIN__)
#pragma pack(push, 1) /* magic for reducing sizeof(RVALUE): 24 -> 20 */
#endif
@@ -355,6 +354,7 @@ typedef struct rb_objspace {
unsigned LONG_LONG gc_num_allocations;
unsigned long live_objects;
unsigned LONG_LONG allocated_objects;
+ unsigned long heap_slots_live_after_last_gc;
} rb_objspace_t;
#if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
@@ -388,6 +388,7 @@ int *ruby_initial_gc_stress_ptr = &rb_objspace.gc_stress;
#define gc_num_allocations objspace->gc_num_allocations
#define live_objects objspace->live_objects
#define allocated_objects objspace->allocated_objects
+#define heap_slots_live_after_last_gc objspace->heap_slots_live_after_last_gc
#define finalizer_table objspace->final.table
#define deferred_final_list objspace->final.deferred
#define mark_stack objspace->markstack.buffer
@@ -1410,6 +1411,24 @@ rb_gc_time()
#endif
}
+/*
+ * call-seq:
+ * GC.heap_slots_live_after_last_gc => Integer
+ *
+ * Returns the number of heap slots which were live after the last garbage collection.
+ *
+ * GC.heap_slots_live_after_last_gc #=> 231223
+ *
+ */
+VALUE
+rb_gc_heap_slots_live_after_last_gc()
+{
+ rb_objspace_t *objspace = &rb_objspace;
+ return ULONG2NUM(heap_slots_live_after_last_gc);
+}
+
+
+
VALUE rb_mGC;
void
@@ -2616,6 +2635,7 @@ gc_sweep(rb_objspace_t *objspace)
}
during_gc = 0;
live_objects = live;
+ heap_slots_live_after_last_gc = live;
/* log gc stats if requested */
if (do_gc_stats) {
@@ -3961,6 +3981,7 @@ Init_GC(void)
rb_define_singleton_method(rb_mGC, "allocated_size", rb_gc_allocated_size, 0);
rb_define_singleton_method(rb_mGC, "num_allocations", rb_gc_num_allocations, 0);
rb_define_singleton_method(rb_mGC, "heap_slots", rb_gc_heap_slots, 0);
+ rb_define_singleton_method(rb_mGC, "heap_slots_live_after_last_gc", rb_gc_heap_slots_live_after_last_gc, 0);
rb_define_const(rb_mGC, "HEAP_SLOT_SIZE", INT2FIX(sizeof(RVALUE)));
rb_define_singleton_method(rb_mGC, "log", rb_gc_log, 1);

0 comments on commit 942f017

Please sign in to comment.