Permalink
Browse files

Merge branch 'master' of git://github.com/skaes/rvm-patchsets

Conflicts:
	README.rdoc
  • Loading branch information...
mpapis committed Apr 9, 2012
2 parents b935714 + 51dc886 commit c606b958309602bdd2c603bf2bfbe6000c3b3655

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,15 @@
diff --git a/eval_error.c b/eval_error.c
index fd06adf..69c3b48 100644
--- a/eval_error.c
+++ b/eval_error.c
@@ -164,8 +164,8 @@ error_print(void)
int skip = eclass == rb_eSysStackError;
#define TRACE_MAX (TRACE_HEAD+TRACE_TAIL+5)
-#define TRACE_HEAD 8
-#define TRACE_TAIL 5
+#define TRACE_HEAD 100
+#define TRACE_TAIL 100
for (i = 1; i < len; i++) {
if (TYPE(ptr[i]) == T_STRING) {
@@ -0,0 +1,68 @@
diff --git a/gc.c b/gc.c
index 74ebec6..8e1501e 100644
--- a/gc.c
+++ b/gc.c
@@ -1326,6 +1326,34 @@ rb_gc_log_file(int argc, VALUE *argv, VALUE self)
}
/*
+ * Called from process.c before a fork. Flushes the gc log file to
+ * avoid writing the buffered output twice (once in the parent, and
+ * once in the child).
+ */
+void
+rb_gc_before_fork()
+{
+ rb_objspace_t *objspace = &rb_objspace;
+ fflush(gc_data_file);
+}
+
+/*
+ * Called from process.c after a fork in the child process. Turns off
+ * logging, disables GC stats and resets all gc counters and timing
+ * information.
+ */
+void
+rb_gc_after_fork()
+{
+ rb_objspace_t *objspace = &rb_objspace;
+ rb_gc_disable_stats();
+ rb_gc_clear_stats();
+ rb_gc_disable_trace();
+ gc_data_file = stderr;
+ rb_iv_set(rb_mGC, GC_LOGFILE_IVAR, Qnil);
+}
+
+/*
* call-seq:
* GC.log String => String
*
diff --git a/include/ruby/intern.h b/include/ruby/intern.h
index 50451f3..3988869 100644
--- a/include/ruby/intern.h
+++ b/include/ruby/intern.h
@@ -431,6 +431,8 @@ void rb_gc_call_finalizer_at_exit(void);
VALUE rb_gc_enable(void);
VALUE rb_gc_disable(void);
VALUE rb_gc_start(void);
+void rb_gc_before_fork _((void));
+void rb_gc_after_fork _((void));
#define Init_stack(addr) ruby_init_stack(addr)
void rb_gc_set_params(void);
/* hash.c */
diff --git a/process.c b/process.c
index 2a16757..8a6013c 100644
--- a/process.c
+++ b/process.c
@@ -2782,9 +2782,11 @@ rb_f_fork(VALUE obj)
rb_pid_t pid;
rb_secure(2);
+ rb_gc_before_fork();
switch (pid = rb_fork(0, 0, 0, Qnil)) {
case 0:
+ rb_gc_after_fork();
rb_thread_atfork();
if (rb_block_given_p()) {
int status;
@@ -0,0 +1,69 @@
diff --git a/gc.c b/gc.c
index 8e1501e..e526125 100644
--- a/gc.c
+++ b/gc.c
@@ -272,7 +272,6 @@ getrusage_time(void)
#define GC_PROF_DEC_LIVE_NUM
#endif
-
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__CYGWIN__)
#pragma pack(push, 1) /* magic for reducing sizeof(RVALUE): 24 -> 20 */
#endif
@@ -403,6 +402,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
@@ -435,6 +435,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
@@ -1543,6 +1544,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
@@ -3233,6 +3252,7 @@ gc_marks(rb_objspace_t *objspace)
GC_PROF_MARK_TIMER_STOP;
live_after_last_mark_phase = objspace->heap.live_num;
+ heap_slots_live_after_last_gc = objspace->heap.live_num;
}
static int
@@ -4456,6 +4476,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,0 +1,76 @@
diff --git a/gc.c b/gc.c
index c53bfd9..e65d0ec 100644
--- a/gc.c
+++ b/gc.c
@@ -464,13 +464,12 @@ rb_gc_set_params(void)
#if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
static void gc_sweep(rb_objspace_t *);
static void slot_sweep(rb_objspace_t *, struct heaps_slot *);
-static void gc_clear_mark_on_sweep_slots(rb_objspace_t *);
+static void rest_sweep(rb_objspace_t *);
void
rb_objspace_free(rb_objspace_t *objspace)
{
- gc_clear_mark_on_sweep_slots(objspace);
- gc_sweep(objspace);
+ rest_sweep(objspace);
if (objspace->profile.record) {
free(objspace->profile.record);
objspace->profile.record = 0;
@@ -2430,28 +2429,6 @@ mark_current_machine_context(rb_objspace_t *objspace, rb_thread_t *th)
}
static void
-gc_clear_mark_on_sweep_slots(rb_objspace_t *objspace)
-{
- struct heaps_slot *scan;
- RVALUE *p, *pend;
-
- if (objspace->heap.sweep_slots) {
- while (heaps_increment(objspace));
- while (objspace->heap.sweep_slots) {
- scan = objspace->heap.sweep_slots;
- p = scan->slot; pend = p + scan->limit;
- while (p < pend) {
- if (p->as.free.flags & FL_MARK && BUILTIN_TYPE(p) != T_ZOMBIE) {
- p->as.basic.flags &= ~FL_MARK;
- }
- p++;
- }
- objspace->heap.sweep_slots = objspace->heap.sweep_slots->next;
- }
- }
-}
-
-static void
gc_marks(rb_objspace_t *objspace)
{
struct gc_list *list;
@@ -2462,8 +2439,6 @@ gc_marks(rb_objspace_t *objspace)
objspace->count++;
- gc_clear_mark_on_sweep_slots(objspace);
-
SET_STACK_END;
init_mark_stack(objspace);
@@ -2520,6 +2495,8 @@ garbage_collect(rb_objspace_t *objspace)
GC_PROF_TIMER_START;
+ rest_sweep(objspace);
+
during_gc++;
gc_marks(objspace);
@@ -3025,7 +3002,7 @@ rb_objspace_call_finalizer(rb_objspace_t *objspace)
size_t i;
/* run finalizers */
- gc_clear_mark_on_sweep_slots(objspace);
+ rest_sweep(objspace);
do {
/* XXX: this loop will make no sense */
Oops, something went wrong.

0 comments on commit c606b95

Please sign in to comment.