From 2830fba454cd85586fda0ecd2d1fceb76e98a5da Mon Sep 17 00:00:00 2001
From: Eric Wong <e@80x24.org>
Date: Thu, 13 Aug 2015 21:40:34 +0000
Subject: [PATCH] iseq: move iseq->body->mark_ary to iseq->mark_ary

Having an unused dummy field is ugly and wasteful.  mark_ary was
chosen here since it is often touched at a different point in
execution (GC) than during normal execution of the iseq code.

The GC performance impact is is probably immeasurable given
RGenGC, and rb_location_t still resides in the body for marking
(however on a different cache line than mark_ary was).

Overall, this should not make a real difference today since most
mallocs give 2 word alignment for compliance and compatibility,
but it should allow us more room to make future modifications to
rb_iseq_constant_body without using more space.
---
 iseq.c    | 13 +++++++------
 vm_core.h |  3 +--
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/iseq.c b/iseq.c
index 9b32c0a..38bd84d 100644
--- a/iseq.c
+++ b/iseq.c
@@ -104,10 +104,11 @@ rb_iseq_mark(const rb_iseq_t *iseq)
 
     RUBY_GC_INFO("%s @ %s\n", RSTRING_PTR(iseq->body->location.label), RSTRING_PTR(iseq->body->location.path));
 
+    RUBY_MARK_UNLESS_NULL(iseq->mark_ary);
+
     if (iseq->body) {
 	const struct rb_iseq_constant_body *body = iseq->body;
 
-	RUBY_MARK_UNLESS_NULL(body->mark_ary);
 	rb_gc_mark(body->location.label);
 	rb_gc_mark(body->location.base_label);
 	rb_gc_mark(body->location.path);
@@ -259,11 +260,11 @@ set_relation(rb_iseq_t *iseq, const rb_iseq_t *piseq)
 void
 rb_iseq_add_mark_object(const rb_iseq_t *iseq, VALUE obj)
 {
-    if (!RTEST(iseq->body->mark_ary)) {
-	RB_OBJ_WRITE(iseq, &iseq->body->mark_ary, rb_ary_tmp_new(3));
-	RBASIC_CLEAR_CLASS(iseq->body->mark_ary);
+    if (!RTEST(iseq->mark_ary)) {
+	RB_OBJ_WRITE(iseq, &iseq->mark_ary, rb_ary_tmp_new(3));
+	RBASIC_CLEAR_CLASS(iseq->mark_ary);
     }
-    rb_ary_push(iseq->body->mark_ary, obj);
+    rb_ary_push(iseq->mark_ary, obj);
 }
 
 static VALUE
@@ -282,7 +283,7 @@ prepare_iseq_build(rb_iseq_t *iseq,
     if (iseq != iseq->body->local_iseq) {
 	RB_OBJ_WRITE(iseq, &iseq->body->location.base_label, iseq->body->local_iseq->body->location.label);
     }
-    RB_OBJ_WRITE(iseq, &iseq->body->mark_ary, 0);
+    RB_OBJ_WRITE(iseq, &iseq->mark_ary, 0);
 
     iseq->compile_data = ZALLOC(struct iseq_compile_data);
     RB_OBJ_WRITE(iseq, &iseq->compile_data->err_info, Qnil);
diff --git a/vm_core.h b/vm_core.h
index cad0e09..b0187bb 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -343,7 +343,6 @@ struct rb_iseq_constant_body {
 
     union iseq_inline_storage_entry *is_entries;
     rb_call_info_t *callinfo_entries;
-    const VALUE mark_ary;     /* Array: includes operands which should be GC marked */
 
     unsigned int local_table_size;
     unsigned int is_size;
@@ -368,7 +367,7 @@ struct rb_iseq_struct {
     struct iseq_compile_data *compile_data; /* used at compile time */
     struct rb_iseq_constant_body *body;
     struct rb_iseq_variable_body *variable_body;
-    VALUE dummy2;
+    const VALUE mark_ary;     /* Array: includes operands which should be GC marked */
 };
 
 enum ruby_special_exceptions {
-- 
EW

