aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog12
-rw-r--r--compile.c2
-rw-r--r--iseq.c39
-rw-r--r--iseq.h41
-rw-r--r--test/ruby/test_process.rb4
-rw-r--r--vm_core.h14
6 files changed, 68 insertions, 44 deletions
diff --git a/ChangeLog b/ChangeLog
index cab13e1310..fb1cd6cbe0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+Wed Dec 02 22:57:46 2015 Koichi Sasada <ko1@atdot.net>
+
+ * vm_core.h, iseq.h: remove rb_iseq_t::variable_body.
+ Fields in rb_iseq_t::variable_body are contained by
+ rb_iseq_t::body::mark_ary (hidden Array object).
+
+ Index 0 to 2 of mark_ary are reserved by these objects.
+
+ * iseq.c: catch up this fix.
+
+ * compile.c (rb_iseq_original_iseq): trivial rewrite.
+
Wed Dec 2 17:19:02 2015 Koichi Sasada <ko1@atdot.net>
* iseq.h: introduce ISEQ_ORIGINAL_ISEQ() and
diff --git a/compile.c b/compile.c
index fabba758f6..bb8fe8688c 100644
--- a/compile.c
+++ b/compile.c
@@ -645,7 +645,7 @@ rb_iseq_original_iseq(const rb_iseq_t *iseq) /* cold path */
if (ISEQ_ORIGINAL_ISEQ(iseq)) return ISEQ_ORIGINAL_ISEQ(iseq);
original_code = ISEQ_ORIGINAL_ISEQ_ALLOC(iseq, iseq->body->iseq_size);
- MEMCPY(ISEQ_ORIGINAL_ISEQ(iseq), iseq->body->iseq_encoded, VALUE, iseq->body->iseq_size);
+ MEMCPY(original_code, iseq->body->iseq_encoded, VALUE, iseq->body->iseq_size);
#if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE
{
diff --git a/iseq.c b/iseq.c
index 3a539170a3..667cca5be7 100644
--- a/iseq.c
+++ b/iseq.c
@@ -92,8 +92,6 @@ rb_iseq_free(const rb_iseq_t *iseq)
ruby_xfree((void *)iseq->body->param.keyword);
}
compile_data_free(ISEQ_COMPILE_DATA(iseq));
- ruby_xfree(iseq->variable_body->iseq_);
- ruby_xfree(iseq->variable_body);
ruby_xfree(iseq->body);
}
RUBY_FREE_LEAVE("iseq");
@@ -116,10 +114,6 @@ rb_iseq_mark(const rb_iseq_t *iseq)
RUBY_MARK_UNLESS_NULL(body->location.absolute_path);
}
- if (iseq->variable_body) {
- RUBY_MARK_UNLESS_NULL(ISEQ_COVERAGE(iseq));
- }
-
if (ISEQ_COMPILE_DATA(iseq) != 0) {
const struct iseq_compile_data *const compile_data = ISEQ_COMPILE_DATA(iseq);
@@ -148,19 +142,10 @@ static size_t
iseq_memsize(const rb_iseq_t *iseq)
{
size_t size = 0; /* struct already counted as RVALUE size */
- const struct rb_iseq_variable_body *variable_body;
- const struct rb_iseq_constant_body *body;
+ const struct rb_iseq_constant_body *body = iseq->body;
const struct iseq_compile_data *compile_data;
- variable_body = iseq->variable_body;
- body = iseq->body;
-
- if (variable_body) {
- size += sizeof(struct rb_iseq_variable_body);
- if (variable_body->iseq_ && body) {
- size += body->iseq_size * sizeof(VALUE);
- }
- }
+ /* TODO: should we count original_iseq? */
if (body) {
struct rb_call_info_with_kwarg *ci_kw_entries = (struct rb_call_info_with_kwarg *)&body->ci_entries[body->ci_size];
@@ -220,7 +205,6 @@ iseq_alloc(void)
{
rb_iseq_t *iseq = (rb_iseq_t *)rb_imemo_new(imemo_iseq, 0, 0, 0, 0);
iseq->body = ZALLOC(struct rb_iseq_constant_body);
- iseq->variable_body = ZALLOC(struct rb_iseq_variable_body);
return iseq;
}
@@ -269,11 +253,18 @@ 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);
- }
- rb_ary_push(iseq->body->mark_ary, obj);
+ /* TODO: check dedup */
+ rb_ary_push(ISEQ_MARK_ARY(iseq), obj);
+}
+
+static VALUE
+iseq_mark_ary_create(int flip_cnt)
+{
+ VALUE ary = rb_ary_tmp_new(3);
+ rb_ary_push(ary, Qnil); /* ISEQ_MARK_ARY_COVERAGE */
+ rb_ary_push(ary, INT2FIX(flip_cnt)); /* ISEQ_MARK_ARY_FLIP_CNT */
+ rb_ary_push(ary, Qnil); /* ISEQ_MARK_ARY_ORIGINAL_ISEQ */
+ return ary;
}
static VALUE
@@ -292,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->body->mark_ary, iseq_mark_ary_create(0));
ISEQ_COMPILE_DATA(iseq) = ZALLOC(struct iseq_compile_data);
RB_OBJ_WRITE(iseq, &ISEQ_COMPILE_DATA(iseq)->err_info, Qnil);
diff --git a/iseq.h b/iseq.h
index 73416ab327..2b18d56893 100644
--- a/iseq.h
+++ b/iseq.h
@@ -23,12 +23,43 @@ rb_call_info_kw_arg_bytes(int keyword_len)
return sizeof(struct rb_call_info_kw_arg) + sizeof(VALUE) * (keyword_len - 1);
}
+enum iseq_mark_ary_index {
+ ISEQ_MARK_ARY_COVERAGE = 0,
+ ISEQ_MARK_ARY_FLIP_CNT = 1,
+ ISEQ_MARK_ARY_ORIGINAL_ISEQ = 2,
+};
+
+#define ISEQ_MARK_ARY(iseq) (iseq)->body->mark_ary
+
+#define ISEQ_COVERAGE(iseq) RARRAY_AREF(ISEQ_MARK_ARY(iseq), ISEQ_MARK_ARY_COVERAGE)
+#define ISEQ_COVERAGE_SET(iseq, cov) RARRAY_ASET(ISEQ_MARK_ARY(iseq), ISEQ_MARK_ARY_COVERAGE, cov)
+
+static inline int
+ISEQ_FLIP_CNT_INCREMENT(const rb_iseq_t *iseq)
+{
+ VALUE cntv = RARRAY_AREF(ISEQ_MARK_ARY(iseq), ISEQ_MARK_ARY_FLIP_CNT);
+ int cnt = FIX2INT(cntv);
+ RARRAY_ASET(ISEQ_MARK_ARY(iseq), ISEQ_MARK_ARY_FLIP_CNT, INT2FIX(cnt+1));
+ return cnt;
+}
+
+static inline VALUE *
+ISEQ_ORIGINAL_ISEQ(const rb_iseq_t *iseq)
+{
+ VALUE str = RARRAY_AREF(ISEQ_MARK_ARY(iseq), ISEQ_MARK_ARY_ORIGINAL_ISEQ);
+ if (RTEST(str)) return (VALUE *)RSTRING_PTR(str);
+ return NULL;
+}
+
+static inline VALUE *
+ISEQ_ORIGINAL_ISEQ_ALLOC(const rb_iseq_t *iseq, long size)
+{
+ VALUE str = rb_str_tmp_new(size * sizeof(VALUE));
+ RARRAY_ASET(ISEQ_MARK_ARY(iseq), ISEQ_MARK_ARY_ORIGINAL_ISEQ, str);
+ return (VALUE *)RSTRING_PTR(str);
+}
+
#define ISEQ_COMPILE_DATA(iseq) (iseq)->compile_data_
-#define ISEQ_COVERAGE(iseq) (iseq)->variable_body->coverage_
-#define ISEQ_COVERAGE_SET(iseq, cov) RB_OBJ_WRITE((iseq), &(iseq)->variable_body->coverage_, cov)
-#define ISEQ_FLIP_CNT_INCREMENT(iseq) ((iseq)->variable_body->flip_cnt_++)
-#define ISEQ_ORIGINAL_ISEQ(iseq) (iseq)->variable_body->iseq_
-#define ISEQ_ORIGINAL_ISEQ_ALLOC(iseq, size) (ISEQ_ORIGINAL_ISEQ(iseq) = ALLOC_N(VALUE, size))
RUBY_SYMBOL_EXPORT_BEGIN
diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb
index 755b9c665c..2e120ef9bb 100644
--- a/test/ruby/test_process.rb
+++ b/test/ruby/test_process.rb
@@ -633,9 +633,9 @@ class TestProcess < Test::Unit::TestCase
trap(:USR1) { print "trap\n" }
system("cat", :in => "fifo")
EOS
- sleep 0.5
+ sleep 1
Process.kill(:USR1, io.pid)
- sleep 0.1
+ sleep 1
File.write("fifo", "ok\n")
assert_equal("trap\nok\n", io.read)
}
diff --git a/vm_core.h b/vm_core.h
index 377b6a964e..2343e1154d 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -385,24 +385,14 @@ struct rb_iseq_constant_body {
unsigned int line_info_size;
};
-struct rb_iseq_variable_body {
- const VALUE coverage_; /* coverage array */
-
- rb_num_t flip_cnt_;
-
- /* original iseq, before encoding
- * used for debug/dump (TODO: union with compile_data) */
- VALUE *iseq_;
-};
-
/* T_IMEMO/iseq */
/* typedef rb_iseq_t is in method.h */
struct rb_iseq_struct {
VALUE flags;
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;
+ VALUE reserved1;
+ VALUE reserved2;
};
enum ruby_special_exceptions {