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.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65204 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2018-10-20 06:53:00 +00:00
parent d79f72521e
commit b710785f1a
16 changed files with 86 additions and 11 deletions

View File

@ -76,7 +76,7 @@ XCFLAGS = @XCFLAGS@ $(MATHN:yes=-DCANONICALIZATION_FOR_MATHN)
USE_RUBYGEMS = @USE_RUBYGEMS@ USE_RUBYGEMS = @USE_RUBYGEMS@
USE_RUBYGEMS_ = $(USE_RUBYGEMS:yes=) USE_RUBYGEMS_ = $(USE_RUBYGEMS:yes=)
CPPFLAGS = @CPPFLAGS@ $(INCFLAGS) $(USE_RUBYGEMS_:no=-DDISABLE_RUBYGEMS=1) 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_FLAGS = @MJIT_HEADER_FLAGS@
MJIT_HEADER_SUFFIX = MJIT_HEADER_SUFFIX =
MJIT_HEADER_ARCH = MJIT_HEADER_ARCH =

View File

@ -201,7 +201,7 @@ all: $(SHOWFLAGS) main docs
main: $(SHOWFLAGS) exts $(ENCSTATIC:static=lib)encs main: $(SHOWFLAGS) exts $(ENCSTATIC:static=lib)encs
@$(NULLCMD) @$(NULLCMD)
mjit-headers: $(INSTALL_MJIT_HEADER)-mjit-headers mjit-headers: $(ENABLE_MJIT)-mjit-headers
no-mjit-headers: PHONY no-mjit-headers: PHONY
yes-mjit-headers: mjit_config.h PHONY yes-mjit-headers: mjit_config.h PHONY

View File

@ -3325,10 +3325,16 @@ AC_SUBST(CAPITARGET)
AS_CASE(["$RDOCTARGET:$CAPITARGET"],[nodoc:nodoc],[INSTALLDOC=nodoc],[INSTALLDOC=all]) AS_CASE(["$RDOCTARGET:$CAPITARGET"],[nodoc:nodoc],[INSTALLDOC=nodoc],[INSTALLDOC=all])
AC_SUBST(INSTALLDOC) AC_SUBST(INSTALLDOC)
AC_ARG_ENABLE(install-mjit-header, AC_ARG_ENABLE(mjit,
AS_HELP_STRING([--disable-install-mjit-header], [do not install MJIT header]), AS_HELP_STRING([--disable-mjit], [disable MJIT features]),
[INSTALL_MJIT_HEADER=$enableval], [INSTALL_MJIT_HEADER=yes]) [ENABLE_MJIT=$enableval
AC_SUBST(INSTALL_MJIT_HEADER) 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, AC_ARG_ENABLE(install-static-library,
AS_HELP_STRING([--disable-install-static-library], [do not install static ruby library]), AS_HELP_STRING([--disable-install-static-library], [do not install static ruby library]),
@ -3991,7 +3997,7 @@ config_summary "debugflags" "$debugflags"
config_summary "warnflags" "$warnflags" config_summary "warnflags" "$warnflags"
config_summary "strip command" "$STRIP" config_summary "strip command" "$STRIP"
config_summary "install doc" "$install_doc" 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 "man page type" "$MANTYPE"
config_summary "search path" "$search_path" config_summary "search path" "$search_path"
config_summary "static-linked-ext" ${EXTSTATIC:+"yes"} config_summary "static-linked-ext" ${EXTSTATIC:+"yes"}

View File

@ -1403,9 +1403,16 @@ VALUE rb_math_sinh(VALUE);
VALUE rb_math_sqrt(VALUE); VALUE rb_math_sqrt(VALUE);
/* mjit.c */ /* mjit.c */
#if USE_MJIT
extern int mjit_enabled; extern int mjit_enabled;
VALUE mjit_pause(int wait_p); VALUE mjit_pause(int wait_p);
VALUE mjit_resume(void); 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 */ /* newline.c */
void Init_newline(void); void Init_newline(void);

7
mjit.c
View File

@ -10,6 +10,11 @@
So you can safely use Ruby methods and GC in this file. */ So you can safely use Ruby methods and GC in this file. */
/* To share variables privately, include mjit_worker.c instead of linking. */ /* To share variables privately, include mjit_worker.c instead of linking. */
#include "internal.h"
#if USE_MJIT
#include "mjit_worker.c" #include "mjit_worker.c"
#include "constant.h" #include "constant.h"
@ -774,3 +779,5 @@ mjit_remove_class_serial(rb_serial_t class_serial)
rb_hash_delete_entry(valid_class_serials, LONG2FIX(class_serial)); rb_hash_delete_entry(valid_class_serials, LONG2FIX(class_serial));
CRITICAL_SECTION_FINISH(3, "in mjit_remove_class_serial"); CRITICAL_SECTION_FINISH(3, "in mjit_remove_class_serial");
} }
#endif

18
mjit.h
View File

@ -11,6 +11,8 @@
#include "ruby.h" #include "ruby.h"
#if USE_MJIT
/* Special address values of a function generated from the /* Special address values of a function generated from the
corresponding iseq by MJIT: */ corresponding iseq by MJIT: */
enum rb_mjit_iseq_func { enum rb_mjit_iseq_func {
@ -125,4 +127,20 @@ mjit_exec(rb_execution_context_t *ec)
return func(ec, ec->cfp); 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 */ #endif /* RUBY_MJIT_H */

View File

@ -11,6 +11,9 @@
GC (using ZALLOC, xmalloc, xfree, etc.) in this file. */ GC (using ZALLOC, xmalloc, xfree, etc.) in this file. */
#include "internal.h" #include "internal.h"
#if USE_MJIT
#include "vm_core.h" #include "vm_core.h"
#include "vm_exec.h" #include "vm_exec.h"
#include "mjit.h" #include "mjit.h"
@ -242,3 +245,5 @@ mjit_compile(FILE *f, const struct rb_iseq_constant_body *body, const char *func
free(status.stack_size_for_pos); free(status.stack_size_for_pos);
return status.success; return status.success;
} }
#endif /* USE_MJIT */

View File

@ -72,7 +72,6 @@
#define __EXTENSIONS__ 1 #define __EXTENSIONS__ 1
#endif #endif
#include "internal.h"
#include "vm_core.h" #include "vm_core.h"
#include "mjit.h" #include "mjit.h"
#include "gc.h" #include "gc.h"

14
ruby.c
View File

@ -142,7 +142,9 @@ struct ruby_cmdline_options {
VALUE req_list; VALUE req_list;
unsigned int features; unsigned int features;
unsigned int dump; unsigned int dump;
#if USE_MJIT
struct mjit_options mjit; struct mjit_options mjit;
#endif
int safe_level; int safe_level;
int sflag, xflag; int sflag, xflag;
unsigned int warning: 1; unsigned int warning: 1;
@ -948,6 +950,7 @@ set_option_encoding_once(const char *type, VALUE *name, const char *e, long elen
#define set_source_encoding_once(opt, e, elen) \ #define set_source_encoding_once(opt, e, elen) \
set_option_encoding_once("source", &(opt)->src.enc.name, (e), (elen)) set_option_encoding_once("source", &(opt)->src.enc.name, (e), (elen))
#if USE_MJIT
static void static void
setup_mjit_options(const char *s, struct mjit_options *mjit_opt) setup_mjit_options(const char *s, struct mjit_options *mjit_opt)
{ {
@ -978,6 +981,7 @@ setup_mjit_options(const char *s, struct mjit_options *mjit_opt)
"invalid MJIT option `%s' (--help will show valid MJIT options)", s + 1); "invalid MJIT option `%s' (--help will show valid MJIT options)", s + 1);
} }
} }
#endif
static long static long
proc_options(long argc, char **argv, ruby_cmdline_options_t *opt, int envopt) proc_options(long argc, char **argv, ruby_cmdline_options_t *opt, int envopt)
@ -1332,8 +1336,12 @@ proc_options(long argc, char **argv, ruby_cmdline_options_t *opt, int envopt)
ruby_verbose = Qtrue; ruby_verbose = Qtrue;
} }
else if (strncmp("jit", s, 3) == 0) { else if (strncmp("jit", s, 3) == 0) {
#if USE_MJIT
opt->features |= FEATURE_BIT(jit); opt->features |= FEATURE_BIT(jit);
setup_mjit_options(s + 3, &opt->mjit); setup_mjit_options(s + 3, &opt->mjit);
#else
rb_warn("MJIT is disabled.");
#endif
} }
else if (strcmp("yydebug", s) == 0) { else if (strcmp("yydebug", s) == 0) {
if (envopt) goto noenvopt_long; if (envopt) goto noenvopt_long;
@ -1574,11 +1582,15 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
if (opt->src.enc.name) if (opt->src.enc.name)
rb_warning("-K is specified; it is for 1.8 compatibility and may cause odd behavior"); 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)) { if (opt->features & FEATURE_BIT(jit)) {
opt->mjit.on = TRUE; /* set mjit.on for ruby_show_version() API and check to call mjit_init() */ 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 (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. */ mjit_opts.on = opt->mjit.on; /* used by ruby_show_version(). mjit_init() still can't be called here. */
#endif
ruby_show_version(); ruby_show_version();
if (opt->dump & DUMP_BIT(version)) return Qtrue; if (opt->dump & DUMP_BIT(version)) return Qtrue;
} }
@ -1631,9 +1643,11 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
ruby_gc_set_params(opt->safe_level); ruby_gc_set_params(opt->safe_level);
ruby_init_loadpath_safe(opt->safe_level); ruby_init_loadpath_safe(opt->safe_level);
#if USE_MJIT
if (opt->mjit.on) if (opt->mjit.on)
/* Using TMP_RUBY_PREFIX created by ruby_init_loadpath_safe(). */ /* Using TMP_RUBY_PREFIX created by ruby_init_loadpath_safe(). */
mjit_init(&opt->mjit); mjit_init(&opt->mjit);
#endif
Init_ruby_description(); Init_ruby_description();
Init_enc(); Init_enc();

View File

@ -3,6 +3,10 @@ require 'test/unit'
require 'tmpdir' require 'tmpdir'
require_relative '../lib/jit_support' require_relative '../lib/jit_support'
require 'rbconfig'
return if RbConfig::CONFIG["ENABLE_MJIT"] == 'no'
# Test for --jit option # Test for --jit option
class TestJIT < Test::Unit::TestCase class TestJIT < Test::Unit::TestCase
include JITSupport include JITSupport

View File

@ -74,6 +74,7 @@
#include "internal.h" #include "internal.h"
#include "iseq.h" #include "iseq.h"
#include "vm_core.h" #include "vm_core.h"
#include "mjit.h"
#include "hrtime.h" #include "hrtime.h"
#ifndef USE_NATIVE_THREAD_PRIORITY #ifndef USE_NATIVE_THREAD_PRIORITY
@ -4392,7 +4393,6 @@ terminate_atfork_i(rb_thread_t *th, const rb_thread_t *current_th)
} }
/* mjit.c */ /* mjit.c */
void mjit_child_after_fork(void);
void rb_fiber_atfork(rb_thread_t *); void rb_fiber_atfork(rb_thread_t *);
void void
rb_thread_atfork(void) rb_thread_atfork(void)

View File

@ -1853,6 +1853,7 @@ rb_nativethread_self(void)
return pthread_self(); return pthread_self();
} }
#if USE_MJIT
/* A function that wraps actual worker function, for pthread abstraction. */ /* A function that wraps actual worker function, for pthread abstraction. */
static void * static void *
mjit_worker(void *arg) mjit_worker(void *arg)
@ -1884,6 +1885,7 @@ rb_thread_create_mjit_thread(void (*worker_func)(void))
pthread_attr_destroy(&attr); pthread_attr_destroy(&attr);
return ret; return ret;
} }
#endif
int int
rb_sigwait_fd_get(const rb_thread_t *th) rb_sigwait_fd_get(const rb_thread_t *th)

View File

@ -811,6 +811,7 @@ native_set_thread_name(rb_thread_t *th)
{ {
} }
#if USE_MJIT
static unsigned long __stdcall static unsigned long __stdcall
mjit_worker(void *arg) mjit_worker(void *arg)
{ {
@ -833,5 +834,6 @@ rb_thread_create_mjit_thread(void (*worker_func)(void))
w32_resume_thread(thread_id); w32_resume_thread(thread_id);
return TRUE; return TRUE;
} }
#endif
#endif /* THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION */ #endif /* THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION */

View File

@ -81,17 +81,24 @@ Init_version(void)
rb_define_global_const("RUBY_ENGINE_VERSION", (1 ? version : MKSTR(version))); 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 void
Init_ruby_description(void) Init_ruby_description(void)
{ {
VALUE description; VALUE description;
if (mjit_opts.on) { if (MJIT_OPTS_ON) {
description = MKSTR(description_with_jit); description = MKSTR(description_with_jit);
} }
else { else {
description = MKSTR(description); description = MKSTR(description);
} }
/* /*
* The full ruby version string, like <tt>ruby -v</tt> prints * The full ruby version string, like <tt>ruby -v</tt> prints
*/ */
@ -102,7 +109,7 @@ Init_ruby_description(void)
void void
ruby_show_version(void) ruby_show_version(void)
{ {
if (mjit_opts.on) { if (MJIT_OPTS_ON) {
PRINT(description_with_jit); PRINT(description_with_jit);
} }
else { else {

View File

@ -458,11 +458,13 @@ struct rb_iseq_constant_body {
unsigned int ci_kw_size; unsigned int ci_kw_size;
unsigned int stack_max; /* for stack overflow check */ unsigned int stack_max; /* for stack overflow check */
#if USE_MJIT
/* The following fields are MJIT related info. */ /* The following fields are MJIT related info. */
VALUE (*jit_func)(struct rb_execution_context_struct *, VALUE (*jit_func)(struct rb_execution_context_struct *,
struct rb_control_frame_struct *); /* function pointer for loaded native code */ struct rb_control_frame_struct *); /* function pointer for loaded native code */
long unsigned total_calls; /* number of total calls with `mjit_exec()` */ long unsigned total_calls; /* number of total calls with `mjit_exec()` */
struct rb_mjit_unit *jit_unit; struct rb_mjit_unit *jit_unit;
#endif
char catch_except_p; /* If a frame of this ISeq may catch exception, set TRUE */ char catch_except_p; /* If a frame of this ISeq may catch exception, set TRUE */
}; };

View File

@ -70,7 +70,9 @@ update_global_event_hook(rb_event_flag_t vm_events)
if (new_iseq_events & ~enabled_iseq_events) { if (new_iseq_events & ~enabled_iseq_events) {
/* Stop calling all JIT-ed code. Compiling trace insns is not supported for now. */ /* Stop calling all JIT-ed code. Compiling trace insns is not supported for now. */
#if USE_MJIT
mjit_call_p = FALSE; mjit_call_p = FALSE;
#endif
/* write all ISeqs iff new events are added */ /* write all ISeqs iff new events are added */
rb_iseq_trace_set_all(new_iseq_events | enabled_iseq_events); rb_iseq_trace_set_all(new_iseq_events | enabled_iseq_events);