diff options
-rw-r--r-- | common.mk | 2 | ||||
-rw-r--r-- | mjit.c | 9 | ||||
-rw-r--r-- | ruby.c | 7 | ||||
-rw-r--r-- | test/ruby/test_rubyoptions.rb | 24 | ||||
-rw-r--r-- | version.c | 11 | ||||
-rw-r--r-- | version.h | 6 |
6 files changed, 55 insertions, 4 deletions
@@ -2847,9 +2847,11 @@ version.$(OBJEXT): {$(VPATH)}config.h version.$(OBJEXT): {$(VPATH)}defines.h version.$(OBJEXT): {$(VPATH)}intern.h version.$(OBJEXT): {$(VPATH)}missing.h +version.$(OBJEXT): {$(VPATH)}mjit.h version.$(OBJEXT): {$(VPATH)}st.h version.$(OBJEXT): {$(VPATH)}subst.h version.$(OBJEXT): {$(VPATH)}version.c +version.$(OBJEXT): {$(VPATH)}vm_core.h vm.$(OBJEXT): $(CCAN_DIR)/check_type/check_type.h vm.$(OBJEXT): $(CCAN_DIR)/container_of/container_of.h vm.$(OBJEXT): $(CCAN_DIR)/list/list.h @@ -1314,12 +1314,16 @@ system_tmpdir(void) /* Minimum value for JIT cache size. */ #define MIN_CACHE_SIZE 10 +extern const char ruby_description_with_jit[]; + /* Initialize MJIT. Start a thread creating the precompiled header and processing ISeqs. The function should be called first for using MJIT. If everything is successfull, MJIT_INIT_P will be TRUE. */ void mjit_init(struct mjit_options *opts) { + VALUE rb_description; + mjit_opts = *opts; mjit_init_p = TRUE; @@ -1366,6 +1370,11 @@ mjit_init(struct mjit_options *opts) rb_id_table_foreach(RCLASS_CONST_TBL(rb_cObject), valid_class_serials_add_i, NULL); } + /* Overwrites RUBY_DESCRIPTION constant */ + rb_const_remove(rb_cObject, rb_intern("RUBY_DESCRIPTION")); + rb_description = rb_usascii_str_new_static(ruby_description_with_jit, strlen(ruby_description_with_jit)); + rb_define_global_const("RUBY_DESCRIPTION", rb_obj_freeze(rb_description)); + /* Initialize worker thread */ finish_worker_p = FALSE; worker_finished = FALSE; @@ -1506,6 +1506,10 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) const struct rb_block *base_block; unsigned int dump = opt->dump & dump_exit_bits; +#ifndef MJIT_FORCE_ENABLE /* to use with: ./configure cppflags="-DMJIT_FORCE_ENABLE" */ + opt->mjit.on = 1; +#endif + if (opt->dump & (DUMP_BIT(usage)|DUMP_BIT(help))) { const char *const progname = (argc > 0 && argv && argv[0] ? argv[0] : @@ -1538,6 +1542,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) rb_warning("-K is specified; it is for 1.8 compatibility and may cause odd behavior"); if (opt->dump & (DUMP_BIT(version) | DUMP_BIT(version_v))) { + mjit_opts.on = opt->mjit.on; /* used by ruby_show_version(). mjit_init() is still not called here. */ ruby_show_version(); if (opt->dump & DUMP_BIT(version)) return Qtrue; } @@ -1590,9 +1595,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) ruby_gc_set_params(opt->safe_level); ruby_init_loadpath_safe(opt->safe_level); -#ifndef MJIT_FORCE_ENABLE /* to use with: ./configure cppflags="-DMJIT_FORCE_ENABLE" */ if (opt->mjit.on) -#endif /* Using TMP_RUBY_PREFIX created by ruby_init_loadpath_safe(). */ mjit_init(&opt->mjit); diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb index 083572ca67..038d0c2db2 100644 --- a/test/ruby/test_rubyoptions.rb +++ b/test/ruby/test_rubyoptions.rb @@ -96,6 +96,15 @@ class TestRubyOptions < Test::Unit::TestCase end private_constant :VERSION_PATTERN + VERSION_PATTERN_WITH_JIT = + case RUBY_ENGINE + when 'jruby' + VERSIN_PATTERN + else + /^ruby #{q[RUBY_VERSION]}(?:[p ]|dev|rc).*? \+JIT \[#{q[RUBY_PLATFORM]}\]$/ + end + private_constant :VERSION_PATTERN_WITH_JIT + def test_verbose assert_in_out_err(["-vve", ""]) do |r, e| assert_match(VERSION_PATTERN, r[0]) @@ -155,7 +164,20 @@ class TestRubyOptions < Test::Unit::TestCase def test_version assert_in_out_err(%w(--version)) do |r, e| assert_match(VERSION_PATTERN, r[0]) - assert_equal(RUBY_DESCRIPTION, r[0]) + if RubyVM::MJIT.enabled? + assert_equal(EnvUtil.invoke_ruby(['-e', 'print RUBY_DESCRIPTION'], '', true).first, r[0]) + else + assert_equal(RUBY_DESCRIPTION, r[0]) + end + assert_equal([], e) + end + assert_in_out_err(%w(--version --jit)) do |r, e| + assert_match(VERSION_PATTERN_WITH_JIT, r[0]) + if RubyVM::MJIT.enabled? + assert_equal(RUBY_DESCRIPTION, r[0]) + else + assert_equal(EnvUtil.invoke_ruby(['--jit', '-e', 'print RUBY_DESCRIPTION'], '', true).first, r[0]) + end assert_equal([], e) end end @@ -11,6 +11,8 @@ #include "ruby/ruby.h" #include "version.h" +#include "vm_core.h" +#include "mjit.h" #include <stdio.h> #ifndef EXIT_SUCCESS @@ -31,6 +33,7 @@ const char ruby_release_date[] = RUBY_RELEASE_DATE; const char ruby_platform[] = RUBY_PLATFORM; const int ruby_patchlevel = RUBY_PATCHLEVEL; const char ruby_description[] = RUBY_DESCRIPTION; +const char ruby_description_with_jit[] = RUBY_DESCRIPTION_WITH_JIT; const char ruby_copyright[] = RUBY_COPYRIGHT; const char ruby_engine[] = "ruby"; @@ -65,6 +68,7 @@ Init_version(void) rb_define_global_const("RUBY_REVISION", MKINT(revision)); /* * The full ruby version string, like <tt>ruby -v</tt> prints' + * This might be overwritten by mjit_init(). */ rb_define_global_const("RUBY_DESCRIPTION", MKSTR(description)); /* @@ -86,7 +90,12 @@ Init_version(void) void ruby_show_version(void) { - PRINT(description); + if (mjit_opts.on) { + PRINT(description_with_jit); + } + else { + PRINT(description); + } #ifdef RUBY_LAST_COMMIT_TITLE fputs("last_commit=" RUBY_LAST_COMMIT_TITLE, stdout); #endif @@ -66,6 +66,12 @@ " ("RUBY_RELEASE_DATE \ RUBY_REVISION_STR") " \ "["RUBY_PLATFORM"]" +# define RUBY_DESCRIPTION_WITH_JIT \ + "ruby "RUBY_VERSION \ + RUBY_PATCHLEVEL_STR \ + " ("RUBY_RELEASE_DATE \ + RUBY_REVISION_STR") +JIT " \ + "["RUBY_PLATFORM"]" # define RUBY_COPYRIGHT \ "ruby - Copyright (C) " \ RUBY_BIRTH_YEAR_STR"-" \ |