1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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: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 =

View file

@ -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

View file

@ -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"}

View file

@ -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);

7
mjit.c
View file

@ -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

18
mjit.h
View file

@ -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 */

View file

@ -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 */

View file

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

14
ruby.c
View file

@ -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();

View file

@ -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

View file

@ -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)

View file

@ -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)

View file

@ -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 */

View file

@ -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 {

View file

@ -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 */
};

View file

@ -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);