Skip to content

Commit 171c496

Browse files
committed
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62530 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent cc777d0 commit 171c496

File tree

6 files changed

+55
-4
lines changed

6 files changed

+55
-4
lines changed

common.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2847,9 +2847,11 @@ version.$(OBJEXT): {$(VPATH)}config.h
28472847
version.$(OBJEXT): {$(VPATH)}defines.h
28482848
version.$(OBJEXT): {$(VPATH)}intern.h
28492849
version.$(OBJEXT): {$(VPATH)}missing.h
2850+
version.$(OBJEXT): {$(VPATH)}mjit.h
28502851
version.$(OBJEXT): {$(VPATH)}st.h
28512852
version.$(OBJEXT): {$(VPATH)}subst.h
28522853
version.$(OBJEXT): {$(VPATH)}version.c
2854+
version.$(OBJEXT): {$(VPATH)}vm_core.h
28532855
vm.$(OBJEXT): $(CCAN_DIR)/check_type/check_type.h
28542856
vm.$(OBJEXT): $(CCAN_DIR)/container_of/container_of.h
28552857
vm.$(OBJEXT): $(CCAN_DIR)/list/list.h

mjit.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,12 +1314,16 @@ system_tmpdir(void)
13141314
/* Minimum value for JIT cache size. */
13151315
#define MIN_CACHE_SIZE 10
13161316

1317+
extern const char ruby_description_with_jit[];
1318+
13171319
/* Initialize MJIT. Start a thread creating the precompiled header and
13181320
processing ISeqs. The function should be called first for using MJIT.
13191321
If everything is successfull, MJIT_INIT_P will be TRUE. */
13201322
void
13211323
mjit_init(struct mjit_options *opts)
13221324
{
1325+
VALUE rb_description;
1326+
13231327
mjit_opts = *opts;
13241328
mjit_init_p = TRUE;
13251329

@@ -1366,6 +1370,11 @@ mjit_init(struct mjit_options *opts)
13661370
rb_id_table_foreach(RCLASS_CONST_TBL(rb_cObject), valid_class_serials_add_i, NULL);
13671371
}
13681372

1373+
/* Overwrites RUBY_DESCRIPTION constant */
1374+
rb_const_remove(rb_cObject, rb_intern("RUBY_DESCRIPTION"));
1375+
rb_description = rb_usascii_str_new_static(ruby_description_with_jit, strlen(ruby_description_with_jit));
1376+
rb_define_global_const("RUBY_DESCRIPTION", rb_obj_freeze(rb_description));
1377+
13691378
/* Initialize worker thread */
13701379
finish_worker_p = FALSE;
13711380
worker_finished = FALSE;

ruby.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,10 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
15061506
const struct rb_block *base_block;
15071507
unsigned int dump = opt->dump & dump_exit_bits;
15081508

1509+
#ifndef MJIT_FORCE_ENABLE /* to use with: ./configure cppflags="-DMJIT_FORCE_ENABLE" */
1510+
opt->mjit.on = 1;
1511+
#endif
1512+
15091513
if (opt->dump & (DUMP_BIT(usage)|DUMP_BIT(help))) {
15101514
const char *const progname =
15111515
(argc > 0 && argv && argv[0] ? argv[0] :
@@ -1538,6 +1542,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
15381542
rb_warning("-K is specified; it is for 1.8 compatibility and may cause odd behavior");
15391543

15401544
if (opt->dump & (DUMP_BIT(version) | DUMP_BIT(version_v))) {
1545+
mjit_opts.on = opt->mjit.on; /* used by ruby_show_version(). mjit_init() is still not called here. */
15411546
ruby_show_version();
15421547
if (opt->dump & DUMP_BIT(version)) return Qtrue;
15431548
}
@@ -1590,9 +1595,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
15901595
ruby_gc_set_params(opt->safe_level);
15911596
ruby_init_loadpath_safe(opt->safe_level);
15921597

1593-
#ifndef MJIT_FORCE_ENABLE /* to use with: ./configure cppflags="-DMJIT_FORCE_ENABLE" */
15941598
if (opt->mjit.on)
1595-
#endif
15961599
/* Using TMP_RUBY_PREFIX created by ruby_init_loadpath_safe(). */
15971600
mjit_init(&opt->mjit);
15981601

test/ruby/test_rubyoptions.rb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ def test_debug
9696
end
9797
private_constant :VERSION_PATTERN
9898

99+
VERSION_PATTERN_WITH_JIT =
100+
case RUBY_ENGINE
101+
when 'jruby'
102+
VERSIN_PATTERN
103+
else
104+
/^ruby #{q[RUBY_VERSION]}(?:[p ]|dev|rc).*? \+JIT \[#{q[RUBY_PLATFORM]}\]$/
105+
end
106+
private_constant :VERSION_PATTERN_WITH_JIT
107+
99108
def test_verbose
100109
assert_in_out_err(["-vve", ""]) do |r, e|
101110
assert_match(VERSION_PATTERN, r[0])
@@ -155,7 +164,20 @@ def test_kanji
155164
def test_version
156165
assert_in_out_err(%w(--version)) do |r, e|
157166
assert_match(VERSION_PATTERN, r[0])
158-
assert_equal(RUBY_DESCRIPTION, r[0])
167+
if RubyVM::MJIT.enabled?
168+
assert_equal(EnvUtil.invoke_ruby(['-e', 'print RUBY_DESCRIPTION'], '', true).first, r[0])
169+
else
170+
assert_equal(RUBY_DESCRIPTION, r[0])
171+
end
172+
assert_equal([], e)
173+
end
174+
assert_in_out_err(%w(--version --jit)) do |r, e|
175+
assert_match(VERSION_PATTERN_WITH_JIT, r[0])
176+
if RubyVM::MJIT.enabled?
177+
assert_equal(RUBY_DESCRIPTION, r[0])
178+
else
179+
assert_equal(EnvUtil.invoke_ruby(['--jit', '-e', 'print RUBY_DESCRIPTION'], '', true).first, r[0])
180+
end
159181
assert_equal([], e)
160182
end
161183
end

version.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
#include "ruby/ruby.h"
1313
#include "version.h"
14+
#include "vm_core.h"
15+
#include "mjit.h"
1416
#include <stdio.h>
1517

1618
#ifndef EXIT_SUCCESS
@@ -31,6 +33,7 @@ const char ruby_release_date[] = RUBY_RELEASE_DATE;
3133
const char ruby_platform[] = RUBY_PLATFORM;
3234
const int ruby_patchlevel = RUBY_PATCHLEVEL;
3335
const char ruby_description[] = RUBY_DESCRIPTION;
36+
const char ruby_description_with_jit[] = RUBY_DESCRIPTION_WITH_JIT;
3437
const char ruby_copyright[] = RUBY_COPYRIGHT;
3538
const char ruby_engine[] = "ruby";
3639

@@ -65,6 +68,7 @@ Init_version(void)
6568
rb_define_global_const("RUBY_REVISION", MKINT(revision));
6669
/*
6770
* The full ruby version string, like <tt>ruby -v</tt> prints'
71+
* This might be overwritten by mjit_init().
6872
*/
6973
rb_define_global_const("RUBY_DESCRIPTION", MKSTR(description));
7074
/*
@@ -86,7 +90,12 @@ Init_version(void)
8690
void
8791
ruby_show_version(void)
8892
{
89-
PRINT(description);
93+
if (mjit_opts.on) {
94+
PRINT(description_with_jit);
95+
}
96+
else {
97+
PRINT(description);
98+
}
9099
#ifdef RUBY_LAST_COMMIT_TITLE
91100
fputs("last_commit=" RUBY_LAST_COMMIT_TITLE, stdout);
92101
#endif

version.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@
6666
" ("RUBY_RELEASE_DATE \
6767
RUBY_REVISION_STR") " \
6868
"["RUBY_PLATFORM"]"
69+
# define RUBY_DESCRIPTION_WITH_JIT \
70+
"ruby "RUBY_VERSION \
71+
RUBY_PATCHLEVEL_STR \
72+
" ("RUBY_RELEASE_DATE \
73+
RUBY_REVISION_STR") +JIT " \
74+
"["RUBY_PLATFORM"]"
6975
# define RUBY_COPYRIGHT \
7076
"ruby - Copyright (C) " \
7177
RUBY_BIRTH_YEAR_STR"-" \

0 commit comments

Comments
 (0)