summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-20 06:53:00 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-20 06:53:00 +0000
commitb710785f1aaaa06bd5cd2e7a584c24aff20c9ab4 (patch)
tree0f54465ac7315f016a281e371ca90666f0d0e369
parentd79f72521e512a91955881de33be12464b9e3e4e (diff)
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
-rw-r--r--Makefile.in2
-rw-r--r--common.mk2
-rw-r--r--configure.ac16
-rw-r--r--internal.h7
-rw-r--r--mjit.c7
-rw-r--r--mjit.h18
-rw-r--r--mjit_compile.c5
-rw-r--r--mjit_worker.c1
-rw-r--r--ruby.c14
-rw-r--r--test/ruby/test_jit.rb4
-rw-r--r--thread.c2
-rw-r--r--thread_pthread.c2
-rw-r--r--thread_win32.c2
-rw-r--r--version.c11
-rw-r--r--vm_core.h2
-rw-r--r--vm_trace.c2
16 files changed, 86 insertions, 11 deletions
diff --git a/Makefile.in b/Makefile.in
index 393c2e5..d4d8573 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -76,7 +76,7 @@ XCFLAGS = @XCFLAGS@ $(MATHN:yes=-DCANONICALIZATION_FOR_MATHN)
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 =
diff --git a/common.mk b/common.mk
index c3d7aac..2c5ad49 100644
--- a/common.mk
+++ b/common.mk
@@ -201,7 +201,7 @@ all: $(SHOWFLAGS) main docs
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
diff --git a/configure.ac b/configure.ac
index 40b209e..5191a91 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3325,10 +3325,16 @@ AC_SUBST(CAPITARGET)
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" "$debugflags"
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"}
diff --git a/internal.h b/internal.h
index ce7d98a..3f6f5e4 100644
--- a/internal.h
+++ b/internal.h
@@ -1403,9 +1403,16 @@ VALUE rb_math_sinh(VALUE);
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);
diff --git a/mjit.c b/mjit.c
index 6ae68e3..88df66b 100644
--- a/mjit.c
+++ b/mjit.c
@@ -10,6 +10,11 @@
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 class_serial)
rb_hash_delete_entry(valid_class_serials, LONG2FIX(class_serial));
CRITICAL_SECTION_FINISH(3, "in mjit_remove_class_serial");
}
+
+#endif
diff --git a/mjit.h b/mjit.h
index 0efa04a..d502b90 100644
--- a/mjit.h
+++ b/mjit.h
@@ -11,6 +11,8 @@
#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)
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 */
diff --git a/mjit_compile.c b/mjit_compile.c
index b2ece0e..44eb13e 100644
--- a/mjit_compile.c
+++ b/mjit_compile.c
@@ -11,6 +11,9 @@
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_iseq_constant_body *body, const char *func
free(status.stack_size_for_pos);
return status.success;
}
+
+#endif /* USE_MJIT */ \ No newline at end of file
diff --git a/mjit_worker.c b/mjit_worker.c
index d9ca5a2..1865d30 100644
--- a/mjit_worker.c
+++ b/mjit_worker.c
@@ -72,7 +72,6 @@
#define __EXTENSIONS__ 1
#endif
-#include "internal.h"
#include "vm_core.h"
#include "mjit.h"
#include "gc.h"
diff --git a/ruby.c b/ruby.c
index a72a5df..584ecf7 100644
--- a/ruby.c
+++ b/ruby.c
@@ -142,7 +142,9 @@ struct ruby_cmdline_options {
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 *type, VALUE *name, const char *e, long elen
#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 mjit_options *mjit_opt)
"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, ruby_cmdline_options_t *opt, int envopt)
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, ruby_cmdline_options_t *opt)
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, ruby_cmdline_options_t *opt)
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();
diff --git a/test/ruby/test_jit.rb b/test/ruby/test_jit.rb
index 3b18373..81308ec 100644
--- a/test/ruby/test_jit.rb
+++ b/test/ruby/test_jit.rb
@@ -3,6 +3,10 @@ require 'test/unit'
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
diff --git a/thread.c b/thread.c
index c3d1051..c3bfbd7 100644
--- a/thread.c
+++ b/thread.c
@@ -74,6 +74,7 @@
#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, const rb_thread_t *current_th)
}
/* mjit.c */
-void mjit_child_after_fork(void);
void rb_fiber_atfork(rb_thread_t *);
void
rb_thread_atfork(void)
diff --git a/thread_pthread.c b/thread_pthread.c
index b8778ee..368dc04 100644
--- a/thread_pthread.c
+++ b/thread_pthread.c
@@ -1853,6 +1853,7 @@ rb_nativethread_self(void)
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 (*worker_func)(void))
pthread_attr_destroy(&attr);
return ret;
}
+#endif
int
rb_sigwait_fd_get(const rb_thread_t *th)
diff --git a/thread_win32.c b/thread_win32.c
index be3f614..d4db9e3 100644
--- a/thread_win32.c
+++ b/thread_win32.c
@@ -811,6 +811,7 @@ native_set_thread_name(rb_thread_t *th)
{
}
+#if USE_MJIT
static unsigned long __stdcall
mjit_worker(void *arg)
{
@@ -833,5 +834,6 @@ rb_thread_create_mjit_thread(void (*worker_func)(void))
w32_resume_thread(thread_id);
return TRUE;
}
+#endif
#endif /* THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION */
diff --git a/version.c b/version.c
index 36c2f05..3215368 100644
--- a/version.c
+++ b/version.c
@@ -81,17 +81,24 @@ Init_version(void)
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)
void
ruby_show_version(void)
{
- if (mjit_opts.on) {
+ if (MJIT_OPTS_ON) {
PRINT(description_with_jit);
}
else {
diff --git a/vm_core.h b/vm_core.h
index 4443031..34217f7 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -458,11 +458,13 @@ struct rb_iseq_constant_body {
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 */
};
diff --git a/vm_trace.c b/vm_trace.c
index fabb15b..38880d2 100644
--- a/vm_trace.c
+++ b/vm_trace.c
@@ -70,7 +70,9 @@ update_global_event_hook(rb_event_flag_t vm_events)
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);