aboutsummaryrefslogtreecommitdiffstats
path: root/iseq.c
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-27 15:59:02 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-27 15:59:02 +0000
commit1bd40a61900d166126b6b6dbe7c06449207d456e (patch)
treec044b1a92b6349639976dcf864dccf504a01ebc8 /iseq.c
parent799487abb89956781474b6fa39326a2a1b0291fc (diff)
downloadruby-1bd40a61900d166126b6b6dbe7c06449207d456e.tar.gz
Manage AST NODEs out of GC
NODEs in AST are no longer objects managed by GC. This change will remove the restriction imposed by the GC. For example, a NODE can use more than five words (this is my primary purpose; we want to store the position data for each NODE, for coverage library), or even a NODE can have variable length (some kinds of NODEs have unused fields). To do this, however, we need more work, since Ripper still uses T_NODE objects managed by the GC. The life time of NODEs is more obvious than other kinds of objects; they are created at parsing, and they become disused immediately after compilation. This change releases all NODEs by a few `xfree`s after compilation, so performance will be improved a bit. In extreme example, `eval("x=1;" * 10000000)` runs much faster (40 sec. -> 7.8 sec. on my machine). The most important part of this change is `ast_t` struct, which has three contents: (1) NODE buffer (malloc'ed memory), (2) a reference to the root NODE, and (3) an array that contains objects that must be marked during parsing (such as literal objects). Some functions that had received `NODE*` arguments, must now receive `ast_t*`. * node.c, node.h: defines `ast_t` struct and related operations. * gc.c, internal.h: defines `imemo_ast`. * parse.y: makes `parser_params` struct have a reference to `ast_t`. Instead of `rb_node_newnode`, use `rb_ast_newnode` to create a NODE. * iseq.c, load.c, ruby.c, template/prelude.c.tmpl: modifies some functions to handle `ast_t*` instead of `NODE*`. * test/ruby/test_gc.rb: ad-hoc fix for a failed test. The test assumes GC eden is increased at startup by NODE object creation. However, this change now create no NODE object, so GC eden is not necessarily increased. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60485 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'iseq.c')
-rw-r--r--iseq.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/iseq.c b/iseq.c
index 6047d0017d..0de58c4086 100644
--- a/iseq.c
+++ b/iseq.c
@@ -641,9 +641,9 @@ rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE realpath, VALUE line, c
#else
# define INITIALIZED /* volatile */
#endif
- NODE *(*parse)(VALUE vparser, VALUE fname, VALUE file, int start);
+ ast_t *(*parse)(VALUE vparser, VALUE fname, VALUE file, int start);
int ln;
- NODE *INITIALIZED node;
+ ast_t *INITIALIZED ast;
/* safe results first */
make_compile_option(&option, opt);
@@ -659,18 +659,20 @@ rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE realpath, VALUE line, c
{
const VALUE parser = rb_parser_new();
rb_parser_set_context(parser, base_block, FALSE);
- node = (*parse)(parser, file, src, ln);
+ ast = (*parse)(parser, file, src, ln);
}
- if (!node) {
+ if (!ast->root) {
+ rb_ast_dispose(ast);
rb_exc_raise(th->ec->errinfo);
}
else {
INITIALIZED VALUE label = parent ?
parent->body->location.label :
rb_fstring_cstr("<compiled>");
- iseq = rb_iseq_new_with_opt(node, label, file, realpath, line,
+ iseq = rb_iseq_new_with_opt(ast->root, label, file, realpath, line,
parent, type, &option);
+ rb_ast_dispose(ast);
}
return iseq;
@@ -851,8 +853,8 @@ static VALUE
iseqw_s_compile_file(int argc, VALUE *argv, VALUE self)
{
VALUE file, line = INT2FIX(1), opt = Qnil;
- VALUE parser, f, exc = Qnil;
- const NODE *node;
+ VALUE parser, f, exc = Qnil, ret;
+ ast_t *ast;
rb_compile_option_t option;
int i;
@@ -869,18 +871,23 @@ iseqw_s_compile_file(int argc, VALUE *argv, VALUE self)
parser = rb_parser_new();
rb_parser_set_context(parser, NULL, FALSE);
- node = rb_parser_compile_file_path(parser, file, f, NUM2INT(line));
- if (!node) exc = GET_EC()->errinfo;
+ ast = rb_parser_compile_file_path(parser, file, f, NUM2INT(line));
+ if (!ast->root) exc = GET_EC()->errinfo;
rb_io_close(f);
- if (!node) rb_exc_raise(exc);
+ if (!ast->root) {
+ rb_ast_dispose(ast);
+ rb_exc_raise(exc);
+ }
make_compile_option(&option, opt);
- return iseqw_new(rb_iseq_new_with_opt(node, rb_fstring_cstr("<main>"),
- file,
- rb_realpath_internal(Qnil, file, 1),
- line, NULL, ISEQ_TYPE_TOP, &option));
+ ret = iseqw_new(rb_iseq_new_with_opt(ast->root, rb_fstring_cstr("<main>"),
+ file,
+ rb_realpath_internal(Qnil, file, 1),
+ line, NULL, ISEQ_TYPE_TOP, &option));
+ rb_ast_dispose(ast);
+ return ret;
}
/*