ruby-changes:52990
From: ko1 <ko1@a...>
Date: Sat, 20 Oct 2018 15:53:09 +0900 (JST)
Subject: [ruby-changes:52990] ko1:r65204 (trunk): add disabling MJIT features option.
ko1 2018-10-20 15:53:00 +0900 (Sat, 20 Oct 2018) New Revision: 65204 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65204 Log: add disabling MJIT features option. * configure.ac: introduce new configure option `--enable-mjit` and `--disable-mjit`. Default is "enable". `--disable-mjit` disables all of MJIT features so that `ruby --jit` can't enable MJIT. This option affect a macro `USE_MJIT`. This change remove `--enable/disable-install-mjit-header` option. * Makefile.in: introduce the `ENABLE_MJIT` variable. * common.mk: use `ENABLE_MJIT` option. * internal.h: respect `USE_MJIT`. Same as other *.c, *.h. * test/ruby/test_jit.rb: check `ENABLE_MJIT` key of rbconfg.rb. Modified files: trunk/Makefile.in trunk/common.mk trunk/configure.ac trunk/internal.h trunk/mjit.c trunk/mjit.h trunk/mjit_compile.c trunk/mjit_worker.c trunk/ruby.c trunk/test/ruby/test_jit.rb trunk/thread.c trunk/thread_pthread.c trunk/thread_win32.c trunk/version.c trunk/vm_core.h trunk/vm_trace.c Index: configure.ac =================================================================== --- configure.ac (revision 65203) +++ configure.ac (revision 65204) @@ -3325,10 +3325,16 @@ AC_SUBST(CAPITARGET) https://github.com/ruby/ruby/blob/trunk/configure.ac#L3325 AS_CASE(["$RDOCTARGET:$CAPITARGET"],[nodoc:nodoc],[INSTALLDOC=nodoc],[INSTALLDOC=all]) AC_SUBST(INSTALLDOC) -AC_ARG_ENABLE(install-mjit-header, - AS_HELP_STRING([--disable-install-mjit-header], [do not install MJIT header]), - [INSTALL_MJIT_HEADER=$enableval], [INSTALL_MJIT_HEADER=yes]) -AC_SUBST(INSTALL_MJIT_HEADER) +AC_ARG_ENABLE(mjit, + AS_HELP_STRING([--disable-mjit], [disable MJIT features]), + [ENABLE_MJIT=$enableval + AS_IF([test x"$enable_mjit" = "xyes"], + [AC_DEFINE(USE_MJIT, 1)], + [AC_DEFINE(USE_MJIT, 0)])], + [ENABLE_MJIT=yes + AC_DEFINE(USE_MJIT, 1)]) + +AC_SUBST(ENABLE_MJIT) AC_ARG_ENABLE(install-static-library, AS_HELP_STRING([--disable-install-static-library], [do not install static ruby library]), @@ -3991,7 +3997,7 @@ config_summary "debugflags" "$d https://github.com/ruby/ruby/blob/trunk/configure.ac#L3997 config_summary "warnflags" "$warnflags" config_summary "strip command" "$STRIP" config_summary "install doc" "$install_doc" -config_summary "install MJIT header" "$INSTALL_MJIT_HEADER" +config_summary "enable MJIT" "$ENABLE_MJIT" config_summary "man page type" "$MANTYPE" config_summary "search path" "$search_path" config_summary "static-linked-ext" ${EXTSTATIC:+"yes"} Index: thread_win32.c =================================================================== --- thread_win32.c (revision 65203) +++ thread_win32.c (revision 65204) @@ -811,6 +811,7 @@ native_set_thread_name(rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/thread_win32.c#L811 { } +#if USE_MJIT static unsigned long __stdcall mjit_worker(void *arg) { @@ -833,5 +834,6 @@ rb_thread_create_mjit_thread(void (*work https://github.com/ruby/ruby/blob/trunk/thread_win32.c#L834 w32_resume_thread(thread_id); return TRUE; } +#endif #endif /* THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION */ Index: thread_pthread.c =================================================================== --- thread_pthread.c (revision 65203) +++ thread_pthread.c (revision 65204) @@ -1853,6 +1853,7 @@ rb_nativethread_self(void) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1853 return pthread_self(); } +#if USE_MJIT /* A function that wraps actual worker function, for pthread abstraction. */ static void * mjit_worker(void *arg) @@ -1884,6 +1885,7 @@ rb_thread_create_mjit_thread(void (*work https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1885 pthread_attr_destroy(&attr); return ret; } +#endif int rb_sigwait_fd_get(const rb_thread_t *th) Index: vm_core.h =================================================================== --- vm_core.h (revision 65203) +++ vm_core.h (revision 65204) @@ -458,11 +458,13 @@ struct rb_iseq_constant_body { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L458 unsigned int ci_kw_size; unsigned int stack_max; /* for stack overflow check */ +#if USE_MJIT /* The following fields are MJIT related info. */ VALUE (*jit_func)(struct rb_execution_context_struct *, struct rb_control_frame_struct *); /* function pointer for loaded native code */ long unsigned total_calls; /* number of total calls with `mjit_exec()` */ struct rb_mjit_unit *jit_unit; +#endif char catch_except_p; /* If a frame of this ISeq may catch exception, set TRUE */ }; Index: thread.c =================================================================== --- thread.c (revision 65203) +++ thread.c (revision 65204) @@ -74,6 +74,7 @@ https://github.com/ruby/ruby/blob/trunk/thread.c#L74 #include "internal.h" #include "iseq.h" #include "vm_core.h" +#include "mjit.h" #include "hrtime.h" #ifndef USE_NATIVE_THREAD_PRIORITY @@ -4392,7 +4393,6 @@ terminate_atfork_i(rb_thread_t *th, cons https://github.com/ruby/ruby/blob/trunk/thread.c#L4393 } /* mjit.c */ -void mjit_child_after_fork(void); void rb_fiber_atfork(rb_thread_t *); void rb_thread_atfork(void) Index: common.mk =================================================================== --- common.mk (revision 65203) +++ common.mk (revision 65204) @@ -201,7 +201,7 @@ all: $(SHOWFLAGS) main docs https://github.com/ruby/ruby/blob/trunk/common.mk#L201 main: $(SHOWFLAGS) exts $(ENCSTATIC:static=lib)encs @$(NULLCMD) -mjit-headers: $(INSTALL_MJIT_HEADER)-mjit-headers +mjit-headers: $(ENABLE_MJIT)-mjit-headers no-mjit-headers: PHONY yes-mjit-headers: mjit_config.h PHONY Index: mjit_worker.c =================================================================== --- mjit_worker.c (revision 65203) +++ mjit_worker.c (revision 65204) @@ -72,7 +72,6 @@ https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L72 #define __EXTENSIONS__ 1 #endif -#include "internal.h" #include "vm_core.h" #include "mjit.h" #include "gc.h" Index: Makefile.in =================================================================== --- Makefile.in (revision 65203) +++ Makefile.in (revision 65204) @@ -76,7 +76,7 @@ XCFLAGS = @XCFLAGS@ $(MATHN:yes=-DCANONI https://github.com/ruby/ruby/blob/trunk/Makefile.in#L76 USE_RUBYGEMS = @USE_RUBYGEMS@ USE_RUBYGEMS_ = $(USE_RUBYGEMS:yes=) CPPFLAGS = @CPPFLAGS@ $(INCFLAGS) $(USE_RUBYGEMS_:no=-DDISABLE_RUBYGEMS=1) -INSTALL_MJIT_HEADER = @INSTALL_MJIT_HEADER@ +ENABLE_MJIT = @ENABLE_MJIT@ MJIT_HEADER_FLAGS = @MJIT_HEADER_FLAGS@ MJIT_HEADER_SUFFIX = MJIT_HEADER_ARCH = Index: mjit.c =================================================================== --- mjit.c (revision 65203) +++ mjit.c (revision 65204) @@ -10,6 +10,11 @@ https://github.com/ruby/ruby/blob/trunk/mjit.c#L10 So you can safely use Ruby methods and GC in this file. */ /* To share variables privately, include mjit_worker.c instead of linking. */ + +#include "internal.h" + +#if USE_MJIT + #include "mjit_worker.c" #include "constant.h" @@ -774,3 +779,5 @@ mjit_remove_class_serial(rb_serial_t cla https://github.com/ruby/ruby/blob/trunk/mjit.c#L779 rb_hash_delete_entry(valid_class_serials, LONG2FIX(class_serial)); CRITICAL_SECTION_FINISH(3, "in mjit_remove_class_serial"); } + +#endif Index: mjit.h =================================================================== --- mjit.h (revision 65203) +++ mjit.h (revision 65204) @@ -11,6 +11,8 @@ https://github.com/ruby/ruby/blob/trunk/mjit.h#L11 #include "ruby.h" +#if USE_MJIT + /* Special address values of a function generated from the corresponding iseq by MJIT: */ enum rb_mjit_iseq_func { @@ -125,4 +127,20 @@ mjit_exec(rb_execution_context_t *ec) https://github.com/ruby/ruby/blob/trunk/mjit.h#L127 return func(ec, ec->cfp); } +void mjit_child_after_fork(void); + +#else /* USE_MJIT */ +static inline struct mjit_cont *mjit_cont_new(rb_execution_context_t *ec){return NULL;} +static inline void mjit_cont_free(struct mjit_cont *cont){} +static inline void mjit_finish(void){} +static inline void mjit_gc_start_hook(void){} +static inline void mjit_gc_finish_hook(void){} +static inline void mjit_free_iseq(const rb_iseq_t *iseq){} +static inline void mjit_mark(void){} +static inline void mjit_add_class_serial(rb_serial_t class_serial){} +static inline void mjit_remove_class_serial(rb_serial_t class_serial){} +static inline VALUE mjit_exec(rb_execution_context_t *ec) { return Qundef; /* unreachable */ } +static inline void mjit_child_after_fork(void){} + +#endif /* USE_MJIT */ #endif /* RUBY_MJIT_H */ Index: vm_trace.c =================================================================== --- vm_trace.c (revision 65203) +++ vm_trace.c (revision 65204) @@ -70,7 +70,9 @@ update_global_event_hook(rb_event_flag_t https://github.com/ruby/ruby/blob/trunk/vm_trace.c#L70 if (new_iseq_events & ~enabled_iseq_events) { /* Stop calling all JIT-ed code. Compiling trace insns is not supported for now. */ +#if USE_MJIT mjit_call_p = FALSE; +#endif /* write all ISeqs iff new events are added */ rb_iseq_trace_set_all(new_iseq_events | enabled_iseq_events); Index: internal.h =================================================================== --- internal.h (revision 65203) +++ internal.h (revision 65204) @@ -1403,9 +1403,16 @@ VALUE rb_math_sinh(VALUE); https://github.com/ruby/ruby/blob/trunk/internal.h#L1403 VALUE rb_math_sqrt(VALUE); /* mjit.c */ + +#if USE_MJIT extern int mjit_enabled; VALUE mjit_pause(int wait_p); VALUE mjit_resume(void); +#else +#define mjit_enabled 0 +static inline VALUE mjit_pause(int wait_p){ return Qnil; } /* unreachable */ +static inline VALUE mjit_resume(void){ return Qnil; } /* unreachable */ +#endif /* newline.c */ void Init_newline(void); Index: version.c =================================================================== --- version.c (revision 65203) +++ version.c (revision 65204) @@ -81,17 +81,24 @@ Init_version(void) https://github.com/ruby/ruby/blob/trunk/version.c#L81 rb_define_global_const("RUBY_ENGINE_VERSION", (1 ? version : MKSTR(version))); } +#if USE_MJIT +#define MJIT_OPTS_ON mjit_opts.on +#else +#define MJIT_OPTS_ON 0 +#endif + void Init_ruby_description(void) { VALUE description; - if (mjit_opts.on) { + if (MJIT_OPTS_ON) { description = MKSTR(description_with_jit); } else { description = MKSTR(description); } + /* * The full ruby version string, like <tt>ruby -v</tt> prints */ @@ -102,7 +109,7 @@ Init_ruby_description(void) https://github.com/ruby/ruby/blob/trunk/version.c#L109 void ruby_show_version(void) { - if (mjit_opts.on) { + if (MJIT_OPTS_ON) { PRINT(description_with_jit); } else { Index: mjit_compile.c =================================================================== --- mjit_compile.c (revision 65203) +++ mjit_compile.c (revision 65204) @@ -11,6 +11,9 @@ https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L11 GC (using ZALLOC, xmalloc, xfree, etc.) in this file. */ #include "internal.h" + +#if USE_MJIT + #include "vm_core.h" #include "vm_exec.h" #include "mjit.h" @@ -242,3 +245,5 @@ mjit_compile(FILE *f, const struct rb_is https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L245 free(status.stack_size_for_pos); return status.success; } + +#endif /* USE_MJIT */ \ No newline at end of file Index: ruby.c =================================================================== --- ruby.c (revision 65203) +++ ruby.c (revision 65204) @@ -142,7 +142,9 @@ struct ruby_cmdline_options { https://github.com/ruby/ruby/blob/trunk/ruby.c#L142 VALUE req_list; unsigned int features; unsigned int dump; +#if USE_MJIT struct mjit_options mjit; +#endif int safe_level; int sflag, xflag; unsigned int warning: 1; @@ -948,6 +950,7 @@ set_option_encoding_once(const char *typ https://github.com/ruby/ruby/blob/trunk/ruby.c#L950 #define set_source_encoding_once(opt, e, elen) \ set_option_encoding_once("source", &(opt)->src.enc.name, (e), (elen)) +#if USE_MJIT static void setup_mjit_options(const char *s, struct mjit_options *mjit_opt) { @@ -978,6 +981,7 @@ setup_mjit_options(const char *s, struct https://github.com/ruby/ruby/blob/trunk/ruby.c#L981 "invalid MJIT option `%s' (--help will show valid MJIT options)", s + 1); } } +#endif static long proc_options(long argc, char **argv, ruby_cmdline_options_t *opt, int envopt) @@ -1332,8 +1336,12 @@ proc_options(long argc, char **argv, rub https://github.com/ruby/ruby/blob/trunk/ruby.c#L1336 ruby_verbose = Qtrue; } else if (strncmp("jit", s, 3) == 0) { +#if USE_MJIT opt->features |= FEATURE_BIT(jit); setup_mjit_options(s + 3, &opt->mjit); +#else + rb_warn("MJIT is disabled."); +#endif } else if (strcmp("yydebug", s) == 0) { if (envopt) goto noenvopt_long; @@ -1574,11 +1582,15 @@ process_options(int argc, char **argv, r https://github.com/ruby/ruby/blob/trunk/ruby.c#L1582 if (opt->src.enc.name) rb_warning("-K is specified; it is for 1.8 compatibility and may cause odd behavior"); +#if USE_MJIT if (opt->features & FEATURE_BIT(jit)) { opt->mjit.on = TRUE; /* set mjit.on for ruby_show_version() API and check to call mjit_init() */ } +#endif if (opt->dump & (DUMP_BIT(version) | DUMP_BIT(version_v))) { +#if USE_MJIT mjit_opts.on = opt->mjit.on; /* used by ruby_show_version(). mjit_init() still can't be called here. */ +#endif ruby_show_version(); if (opt->dump & DUMP_BIT(version)) return Qtrue; } @@ -1631,9 +1643,11 @@ process_options(int argc, char **argv, r https://github.com/ruby/ruby/blob/trunk/ruby.c#L1643 ruby_gc_set_params(opt->safe_level); ruby_init_loadpath_safe(opt->safe_level); +#if USE_MJIT if (opt->mjit.on) /* Using TMP_RUBY_PREFIX created by ruby_init_loadpath_safe(). */ mjit_init(&opt->mjit); +#endif Init_ruby_description(); Init_enc(); Index: test/ruby/test_jit.rb =================================================================== --- test/ruby/test_jit.rb (revision 65203) +++ test/ruby/test_jit.rb (revision 65204) @@ -3,6 +3,10 @@ require 'test/unit' https://github.com/ruby/ruby/blob/trunk/test/ruby/test_jit.rb#L3 require 'tmpdir' require_relative '../lib/jit_support' +require 'rbconfig' + +return if RbConfig::CONFIG["ENABLE_MJIT"] == 'no' + # Test for --jit option class TestJIT < Test::Unit::TestCase include JITSupport -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/