ruby-changes:50414
From: k0kubun <ko1@a...>
Date: Thu, 22 Feb 2018 23:53:24 +0900 (JST)
Subject: [ruby-changes:50414] k0kubun:r62530 (trunk): version.c: show +JIT when --jit is passed
k0kubun 2018-02-22 23:53:17 +0900 (Thu, 22 Feb 2018) New Revision: 62530 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62530 Log: version.c: show +JIT when --jit is passed in version output. version.h: ditto ruby.c: propagate option for it common.mk: updated dependency for version.c mjit.c: overwrites the RUBY_DESCRIPTION to have +JIT when --jit is passed test/ruby/test_rubyoptions.rb: add test for them Only `ruby --jit -v` will have "+JIT", but this is intentional. This may not be convenient for debugging by ticket with `ruby -v`, but it's convenient for benchmark tools that pass options (--jit) when showing it. At least such behavior is planned for benchmark_driver.gem and this behavior is designed for it. Other benchmark tools are recommended to follow the behavior too if they show version. RUBY_DESCRIPTION might be useful for it too. The position of "+JIT" is changed from original proposal because other platforms like JRuby and TruffleRuby end it with archtecture. It's made similar to JRuby, but it's upper-cased because Matz made approval for "+JIT" in the ticket. Example: $ ruby -v ruby 2.6.0dev (2018-02-22 trunk 62529) [x86_64-linux] $ ruby --jit -v ruby 2.6.0dev (2018-02-22 trunk 62529) +JIT [x86_64-linux] After --jit is made default in the future, this output may be removed. So do not rely on this output if possible. [Feature #14462] Modified files: trunk/common.mk trunk/mjit.c trunk/ruby.c trunk/test/ruby/test_rubyoptions.rb trunk/version.c trunk/version.h Index: ruby.c =================================================================== --- ruby.c (revision 62529) +++ ruby.c (revision 62530) @@ -1506,6 +1506,10 @@ process_options(int argc, char **argv, r https://github.com/ruby/ruby/blob/trunk/ruby.c#L1506 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, r https://github.com/ruby/ruby/blob/trunk/ruby.c#L1542 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, r https://github.com/ruby/ruby/blob/trunk/ruby.c#L1595 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); Index: common.mk =================================================================== --- common.mk (revision 62529) +++ common.mk (revision 62530) @@ -2847,9 +2847,11 @@ version.$(OBJEXT): {$(VPATH)}config.h https://github.com/ruby/ruby/blob/trunk/common.mk#L2847 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 Index: test/ruby/test_rubyoptions.rb =================================================================== --- test/ruby/test_rubyoptions.rb (revision 62529) +++ test/ruby/test_rubyoptions.rb (revision 62530) @@ -96,6 +96,15 @@ class TestRubyOptions < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rubyoptions.rb#L96 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::Test https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rubyoptions.rb#L164 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 Index: version.c =================================================================== --- version.c (revision 62529) +++ version.c (revision 62530) @@ -11,6 +11,8 @@ https://github.com/ruby/ruby/blob/trunk/version.c#L11 #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_RE https://github.com/ruby/ruby/blob/trunk/version.c#L33 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) https://github.com/ruby/ruby/blob/trunk/version.c#L68 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) https://github.com/ruby/ruby/blob/trunk/version.c#L90 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 Index: version.h =================================================================== --- version.h (revision 62529) +++ version.h (revision 62530) @@ -66,6 +66,12 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L66 " ("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"-" \ Index: mjit.c =================================================================== --- mjit.c (revision 62529) +++ mjit.c (revision 62530) @@ -1314,12 +1314,16 @@ system_tmpdir(void) https://github.com/ruby/ruby/blob/trunk/mjit.c#L1314 /* 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) https://github.com/ruby/ruby/blob/trunk/mjit.c#L1370 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; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/