mjit_worker.c: resurrect more static declarations

and remove old mjit_ prefixes again.

mjit.c: ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64292 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
k0kubun 2018-08-11 10:05:56 +00:00
Родитель cfe7f7ca7e
Коммит 3d2e7b6158
2 изменённых файлов: 51 добавлений и 69 удалений

60
mjit.c
Просмотреть файл

@ -17,16 +17,6 @@
extern int rb_thread_create_mjit_thread(void (*worker_func)(void));
#ifndef _MSC_VER
/* Name of the header file. */
extern char *mjit_header_file;
#endif
#ifdef _WIN32
/* Linker option to enable libruby. */
extern char *mjit_libruby_pathflag;
#endif
/* Make and return copy of STR in the heap. */
#define get_string ruby_strdup
@ -58,12 +48,12 @@ mjit_gc_start_hook(void)
if (!mjit_enabled)
return;
CRITICAL_SECTION_START(4, "mjit_gc_start_hook");
while (mjit_in_jit) {
while (in_jit) {
verbose(4, "Waiting wakeup from a worker for GC");
rb_native_cond_wait(&mjit_client_wakeup, &mjit_engine_mutex);
verbose(4, "Getting wakeup from a worker for GC");
}
mjit_in_gc = TRUE;
in_gc = TRUE;
CRITICAL_SECTION_FINISH(4, "mjit_gc_start_hook");
}
@ -75,7 +65,7 @@ mjit_gc_finish_hook(void)
if (!mjit_enabled)
return;
CRITICAL_SECTION_START(4, "mjit_gc_finish_hook");
mjit_in_gc = FALSE;
in_gc = FALSE;
verbose(4, "Sending wakeup signal to workers after GC");
rb_native_cond_broadcast(&mjit_gc_wakeup);
CRITICAL_SECTION_FINISH(4, "mjit_gc_finish_hook");
@ -119,10 +109,6 @@ free_list(struct rb_mjit_unit_list *list)
}
}
extern enum pch_status_t mjit_pch_status;
extern int mjit_stop_worker_p;
extern int mjit_worker_stopped;
/* MJIT info related to an existing continutaion. */
struct mjit_cont {
rb_execution_context_t *ec; /* continuation ec */
@ -295,7 +281,7 @@ mjit_add_iseq_to_process(const rb_iseq_t *iseq)
{
struct rb_mjit_unit_node *node;
if (!mjit_enabled || mjit_pch_status == PCH_FAILED)
if (!mjit_enabled || pch_status == PCH_FAILED)
return;
iseq->body->jit_func = (mjit_func_t)NOT_READY_JIT_ISEQ_FUNC;
@ -329,7 +315,7 @@ mjit_get_iseq_func(struct rb_iseq_constant_body *body)
tv.tv_usec = 1000;
while (body->jit_func == (mjit_func_t)NOT_READY_JIT_ISEQ_FUNC) {
tries++;
if (tries / 1000 > MJIT_WAIT_TIMEOUT_SECONDS || mjit_pch_status == PCH_FAILED) {
if (tries / 1000 > MJIT_WAIT_TIMEOUT_SECONDS || pch_status == PCH_FAILED) {
CRITICAL_SECTION_START(3, "in mjit_get_iseq_func to set jit_func");
body->jit_func = (mjit_func_t)NOT_COMPILED_JIT_ISEQ_FUNC; /* JIT worker seems dead. Give up. */
CRITICAL_SECTION_FINISH(3, "in mjit_get_iseq_func to set jit_func");
@ -348,7 +334,7 @@ mjit_get_iseq_func(struct rb_iseq_constant_body *body)
extern VALUE ruby_archlibdir_path, ruby_prefix_path;
/* Initialize mjit_header_file, pch_file, mjit_libruby_pathflag. Return TRUE on success. */
/* Initialize header_file, pch_file, libruby_pathflag. Return TRUE on success. */
static int
init_header_filename(void)
{
@ -389,13 +375,13 @@ init_header_filename(void)
static const char header_name[] = MJIT_MIN_HEADER_NAME;
const size_t header_name_len = sizeof(header_name) - 1;
mjit_header_file = xmalloc(baselen + header_name_len + 1);
p = append_str2(mjit_header_file, basedir, baselen);
header_file = xmalloc(baselen + header_name_len + 1);
p = append_str2(header_file, basedir, baselen);
p = append_str2(p, header_name, header_name_len + 1);
if ((fd = rb_cloexec_open(mjit_header_file, O_RDONLY, 0)) < 0) {
verbose(1, "Cannot access header file: %s", mjit_header_file);
xfree(mjit_header_file);
mjit_header_file = NULL;
if ((fd = rb_cloexec_open(header_file, O_RDONLY, 0)) < 0) {
verbose(1, "Cannot access header file: %s", header_file);
xfree(header_file);
header_file = NULL;
return FALSE;
}
(void)close(fd);
@ -426,7 +412,7 @@ init_header_filename(void)
basedir_val = ruby_archlibdir_path;
basedir = StringValuePtr(basedir_val);
baselen = RSTRING_LEN(basedir_val);
mjit_libruby_pathflag = p = xmalloc(libpathflag_len + baselen + 1);
libruby_pathflag = p = xmalloc(libpathflag_len + baselen + 1);
p = append_str(p, libpathflag);
p = append_str2(p, basedir, baselen);
*p = '\0';
@ -550,8 +536,8 @@ start_worker(void)
{
extern void mjit_worker(void);
mjit_stop_worker_p = FALSE;
mjit_worker_stopped = FALSE;
stop_worker_p = FALSE;
worker_stopped = FALSE;
if (!rb_thread_create_mjit_thread(mjit_worker)) {
mjit_enabled = FALSE;
@ -588,9 +574,9 @@ mjit_init(struct mjit_options *opts)
/* Initialize variables for compilation */
#ifdef _MSC_VER
mjit_pch_status = PCH_SUCCESS; /* has prebuilt precompiled header */
pch_status = PCH_SUCCESS; /* has prebuilt precompiled header */
#else
mjit_pch_status = PCH_NOT_READY;
pch_status = PCH_NOT_READY;
#endif
cc_path = CC_PATH;
@ -633,8 +619,8 @@ stop_worker(void)
{
rb_execution_context_t *ec = GET_EC();
mjit_stop_worker_p = TRUE;
while (!mjit_worker_stopped) {
stop_worker_p = TRUE;
while (!worker_stopped) {
verbose(3, "Sending cancel signal to worker");
CRITICAL_SECTION_START(3, "in stop_worker");
rb_native_cond_broadcast(&mjit_worker_wakeup);
@ -650,7 +636,7 @@ mjit_pause(int wait_p)
if (!mjit_enabled) {
rb_raise(rb_eRuntimeError, "MJIT is not enabled");
}
if (mjit_worker_stopped) {
if (worker_stopped) {
return Qfalse;
}
@ -679,7 +665,7 @@ mjit_resume(void)
if (!mjit_enabled) {
rb_raise(rb_eRuntimeError, "MJIT is not enabled");
}
if (!mjit_worker_stopped) {
if (!worker_stopped) {
return Qfalse;
}
@ -706,7 +692,7 @@ mjit_finish(void)
threads can produce temp files. And even if the temp files are
removed, the used C compiler still complaint about their
absence. So wait for a clean finish of the threads. */
while (mjit_pch_status == PCH_NOT_READY) {
while (pch_status == PCH_NOT_READY) {
verbose(3, "Waiting wakeup from make_pch");
rb_native_cond_wait(&mjit_pch_wakeup, &mjit_engine_mutex);
}
@ -725,7 +711,7 @@ mjit_finish(void)
if (!mjit_opts.save_temps)
remove_file(pch_file);
xfree(mjit_header_file); mjit_header_file = NULL;
xfree(header_file); header_file = NULL;
#endif
xfree(tmp_dir); tmp_dir = NULL;
xfree(pch_file); pch_file = NULL;

Просмотреть файл

@ -153,8 +153,6 @@ struct rb_mjit_unit_list {
int length; /* the list length */
};
enum pch_status_t {PCH_NOT_READY, PCH_FAILED, PCH_SUCCESS};
extern void rb_native_mutex_lock(rb_nativethread_lock_t *lock);
extern void rb_native_mutex_unlock(rb_nativethread_lock_t *lock);
extern void rb_native_mutex_initialize(rb_nativethread_lock_t *lock);
@ -202,9 +200,13 @@ static rb_nativethread_cond_t mjit_worker_wakeup;
/* A thread conditional to wake up workers if at the end of GC. */
static rb_nativethread_cond_t mjit_gc_wakeup;
/* True when GC is working. */
static int mjit_in_gc;
static int in_gc;
/* True when JIT is working. */
static int mjit_in_jit;
static int in_jit;
/* Set to TRUE to stop worker. */
static int stop_worker_p;
/* Set to TRUE if worker is stopped. */
static int worker_stopped;
/* Path of "/tmp", which can be changed to $TMP in MinGW. */
static char *tmp_dir;
@ -212,23 +214,22 @@ static char *tmp_dir;
This is used to invalidate obsoleted CALL_CACHE. */
static VALUE valid_class_serials;
/* --- Defined in the client thread before starting MJIT threads: --- */
/* Used C compiler path. */
const char *cc_path;
static const char *cc_path;
/* Name of the precompiled header file. */
char *pch_file;
static char *pch_file;
/* Status of the precompiled header creation. The status is
shared by the workers and the pch thread. */
enum pch_status_t mjit_pch_status;
static enum {PCH_NOT_READY, PCH_FAILED, PCH_SUCCESS} pch_status;
#ifndef _MSC_VER
/* Name of the header file. */
char *mjit_header_file;
static char *header_file;
#endif
#ifdef _WIN32
/* Linker option to enable libruby. */
char *mjit_libruby_pathflag;
static char *libruby_pathflag;
#endif
#include "mjit_config.h"
@ -656,7 +657,7 @@ static int
compile_c_to_so(const char *c_file, const char *so_file)
{
int exit_code;
const char *files[] = { NULL, NULL, NULL, NULL, "-link", mjit_libruby_pathflag, NULL };
const char *files[] = { NULL, NULL, NULL, NULL, "-link", libruby_pathflag, NULL };
char **args;
char *p;
@ -728,7 +729,7 @@ make_pch(void)
char **args;
int len = sizeof(rest_args) / sizeof(const char *);
rest_args[len - 2] = mjit_header_file;
rest_args[len - 2] = header_file;
rest_args[len - 3] = pch_file;
verbose(2, "Creating precompiled header");
args = form_args(3, CC_COMMON_ARGS, CC_CODEFLAG_ARGS, rest_args);
@ -736,7 +737,7 @@ make_pch(void)
if (mjit_opts.warnings || mjit_opts.verbose)
fprintf(stderr, "MJIT warning: making precompiled header failed on forming args\n");
CRITICAL_SECTION_START(3, "in make_pch");
mjit_pch_status = PCH_FAILED;
pch_status = PCH_FAILED;
CRITICAL_SECTION_FINISH(3, "in make_pch");
return;
}
@ -746,11 +747,11 @@ make_pch(void)
CRITICAL_SECTION_START(3, "in make_pch");
if (exit_code == 0) {
mjit_pch_status = PCH_SUCCESS;
pch_status = PCH_SUCCESS;
} else {
if (mjit_opts.warnings || mjit_opts.verbose)
fprintf(stderr, "MJIT warning: Making precompiled header failed on compilation. Stopping MJIT worker...\n");
mjit_pch_status = PCH_FAILED;
pch_status = PCH_FAILED;
}
/* wakeup `mjit_finish` */
rb_native_cond_broadcast(&mjit_pch_wakeup);
@ -796,7 +797,7 @@ link_o_to_so(const char **o_files, const char *so_file)
const char *options[] = {
"-o", NULL,
# ifdef _WIN32
mjit_libruby_pathflag,
libruby_pathflag,
# endif
NULL
};
@ -1031,11 +1032,11 @@ convert_unit_to_func(struct rb_mjit_unit *unit)
/* wait until mjit_gc_finish_hook is called */
CRITICAL_SECTION_START(3, "before mjit_compile to wait GC finish");
while (mjit_in_gc) {
while (in_gc) {
verbose(3, "Waiting wakeup from GC");
rb_native_cond_wait(&mjit_gc_wakeup, &mjit_engine_mutex);
}
mjit_in_jit = TRUE;
in_jit = TRUE;
CRITICAL_SECTION_FINISH(3, "before mjit_compile to wait GC finish");
{
@ -1050,7 +1051,7 @@ convert_unit_to_func(struct rb_mjit_unit *unit)
/* release blocking mjit_gc_start_hook */
CRITICAL_SECTION_START(3, "after mjit_compile to wakeup client for GC");
mjit_in_jit = FALSE;
in_jit = FALSE;
verbose(3, "Sending wakeup signal to client in a mjit-worker for GC");
rb_native_cond_signal(&mjit_client_wakeup);
CRITICAL_SECTION_FINISH(3, "in worker to wakeup client for GC");
@ -1106,11 +1107,6 @@ convert_unit_to_func(struct rb_mjit_unit *unit)
return (mjit_func_t)func;
}
/* Set to TRUE to stop worker. */
int mjit_stop_worker_p;
/* Set to TRUE if worker is stopped. */
int mjit_worker_stopped;
/* The function implementing a worker. It is executed in a separate
thread by rb_thread_create_mjit_thread. It compiles precompiled header
and then compiles requested ISeqs. */
@ -1118,27 +1114,27 @@ void
mjit_worker(void)
{
#ifndef _MSC_VER
if (mjit_pch_status == PCH_NOT_READY) {
if (pch_status == PCH_NOT_READY) {
make_pch();
}
#endif
if (mjit_pch_status == PCH_FAILED) {
if (pch_status == PCH_FAILED) {
mjit_enabled = FALSE;
CRITICAL_SECTION_START(3, "in worker to update mjit_worker_stopped");
mjit_worker_stopped = TRUE;
CRITICAL_SECTION_START(3, "in worker to update worker_stopped");
worker_stopped = TRUE;
verbose(3, "Sending wakeup signal to client in a mjit-worker");
rb_native_cond_signal(&mjit_client_wakeup);
CRITICAL_SECTION_FINISH(3, "in worker to update mjit_worker_stopped");
CRITICAL_SECTION_FINISH(3, "in worker to update worker_stopped");
return; /* TODO: do the same thing in the latter half of mjit_finish */
}
/* main worker loop */
while (!mjit_stop_worker_p) {
while (!stop_worker_p) {
struct rb_mjit_unit_node *node;
/* wait until unit is available */
CRITICAL_SECTION_START(3, "in worker dequeue");
while ((unit_queue.head == NULL || active_units.length > mjit_opts.max_cache_size) && !mjit_stop_worker_p) {
while ((unit_queue.head == NULL || active_units.length > mjit_opts.max_cache_size) && !stop_worker_p) {
rb_native_cond_wait(&mjit_worker_wakeup, &mjit_engine_mutex);
verbose(3, "Getting wakeup from client");
}
@ -1167,5 +1163,5 @@ mjit_worker(void)
}
/* To keep mutex unlocked when it is destroyed by mjit_finish, don't wrap CRITICAL_SECTION here. */
mjit_worker_stopped = TRUE;
worker_stopped = TRUE;
}