зеркало из https://github.com/github/ruby.git
Unify some confusing macro usages
_MSC_VER used to be the macro to switch JIT compaction. However, sinced4381d2ceb
, the correct macro to switch it was changed from _MSC_VER to _WIN32. As I didn't properly replace all relevant _MSC_VER usages to _WIN32, these macros have been used inconsistently. nobu replaced _WIN32 with USE_HEADER_TRANSFORMATION in5eb446d12f
. Therefore we had USE_HEADER_TRANSFORMATION and _MSC_VER. This commit makes sure such inconsistent _MSC_VER usages will be unified to the new header, also renaming it to USE_JIT_COMPACTION to be more precise about the requirements. The header transformation itself is not quite relevant to places changed in this commit.
This commit is contained in:
Родитель
d645f18f0f
Коммит
27d5af59a3
4
mjit.c
4
mjit.c
|
@ -879,7 +879,7 @@ mjit_resume(void)
|
||||||
return Qtrue;
|
return Qtrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip calling `clean_object_files` for units which currently exist in the list.
|
// Skip calling `clean_temp_files` for units which currently exist in the list.
|
||||||
static void
|
static void
|
||||||
skip_cleaning_object_files(struct rb_mjit_unit_list *list)
|
skip_cleaning_object_files(struct rb_mjit_unit_list *list)
|
||||||
{
|
{
|
||||||
|
@ -887,7 +887,7 @@ skip_cleaning_object_files(struct rb_mjit_unit_list *list)
|
||||||
|
|
||||||
// No mutex for list, assuming MJIT worker does not exist yet since it's immediately after fork.
|
// No mutex for list, assuming MJIT worker does not exist yet since it's immediately after fork.
|
||||||
list_for_each_safe(&list->head, unit, next, unode) {
|
list_for_each_safe(&list->head, unit, next, unode) {
|
||||||
#ifndef _MSC_VER // Actually mswin does not reach here since it doesn't have fork
|
#ifdef USE_JIT_COMPACTION
|
||||||
if (unit->c_file) unit->c_file_inherited_p = true;
|
if (unit->c_file) unit->c_file_inherited_p = true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -137,6 +137,15 @@ typedef intptr_t pid_t;
|
||||||
|
|
||||||
#define MJIT_TMP_PREFIX "_ruby_mjit_"
|
#define MJIT_TMP_PREFIX "_ruby_mjit_"
|
||||||
|
|
||||||
|
// JIT compaction requires the header transformation because linking multiple .o files
|
||||||
|
// doesn't work without having `static` in the same function definitions. We currently
|
||||||
|
// don't support transforming the MJIT header on Windows.
|
||||||
|
#ifndef _WIN32
|
||||||
|
# define USE_JIT_COMPACTION 1
|
||||||
|
#else
|
||||||
|
# define USE_JIT_COMPACTION 0
|
||||||
|
#endif
|
||||||
|
|
||||||
// The unit structure that holds metadata of ISeq for MJIT.
|
// The unit structure that holds metadata of ISeq for MJIT.
|
||||||
struct rb_mjit_unit {
|
struct rb_mjit_unit {
|
||||||
// Unique order number of unit.
|
// Unique order number of unit.
|
||||||
|
@ -144,7 +153,7 @@ struct rb_mjit_unit {
|
||||||
// Dlopen handle of the loaded object file.
|
// Dlopen handle of the loaded object file.
|
||||||
void *handle;
|
void *handle;
|
||||||
rb_iseq_t *iseq;
|
rb_iseq_t *iseq;
|
||||||
#ifndef _MSC_VER
|
#ifdef USE_JIT_COMPACTION
|
||||||
// This value is always set for `compact_all_jit_code`. Also used for lazy deletion.
|
// This value is always set for `compact_all_jit_code`. Also used for lazy deletion.
|
||||||
char *c_file;
|
char *c_file;
|
||||||
// true if it's inherited from parent Ruby process and lazy deletion should be skipped.
|
// true if it's inherited from parent Ruby process and lazy deletion should be skipped.
|
||||||
|
@ -392,7 +401,7 @@ remove_file(const char *filename)
|
||||||
static void
|
static void
|
||||||
clean_temp_files(struct rb_mjit_unit *unit)
|
clean_temp_files(struct rb_mjit_unit *unit)
|
||||||
{
|
{
|
||||||
#ifndef _MSC_VER
|
#ifdef USE_JIT_COMPACTION
|
||||||
if (unit->c_file) {
|
if (unit->c_file) {
|
||||||
char *c_file = unit->c_file;
|
char *c_file = unit->c_file;
|
||||||
|
|
||||||
|
@ -893,16 +902,11 @@ compile_c_to_so(const char *c_file, const char *so_file)
|
||||||
}
|
}
|
||||||
return exit_code == 0;
|
return exit_code == 0;
|
||||||
}
|
}
|
||||||
|
#endif // _MSC_VER
|
||||||
|
|
||||||
|
#if USE_JIT_COMPACTION
|
||||||
static void compile_prelude(FILE *f);
|
static void compile_prelude(FILE *f);
|
||||||
|
|
||||||
# ifndef _WIN32 // This requires header transformation but we don't transform header on Windows for now
|
|
||||||
# define USE_HEADER_TRANSFORMATION 1
|
|
||||||
# else
|
|
||||||
# define USE_HEADER_TRANSFORMATION 0
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# if USE_HEADER_TRANSFORMATION
|
|
||||||
static bool
|
static bool
|
||||||
compile_compact_jit_code(char* c_file)
|
compile_compact_jit_code(char* c_file)
|
||||||
{
|
{
|
||||||
|
@ -925,14 +929,12 @@ compile_compact_jit_code(char* c_file)
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
# endif // USE_HEADER_TRANSFORMATION
|
|
||||||
|
|
||||||
// Compile all cached .c files and build a single .so file. Reload all JIT func from it.
|
// Compile all cached .c files and build a single .so file. Reload all JIT func from it.
|
||||||
// This improves the code locality for better performance in terms of iTLB and iCache.
|
// This improves the code locality for better performance in terms of iTLB and iCache.
|
||||||
static void
|
static void
|
||||||
compact_all_jit_code(void)
|
compact_all_jit_code(void)
|
||||||
{
|
{
|
||||||
# if USE_HEADER_TRANSFORMATION
|
|
||||||
struct rb_mjit_unit *unit, *cur = 0;
|
struct rb_mjit_unit *unit, *cur = 0;
|
||||||
static const char c_ext[] = ".c";
|
static const char c_ext[] = ".c";
|
||||||
static const char so_ext[] = DLEXT;
|
static const char so_ext[] = DLEXT;
|
||||||
|
@ -1000,10 +1002,8 @@ compact_all_jit_code(void)
|
||||||
free(unit);
|
free(unit);
|
||||||
verbose(1, "JIT compaction failure (%.1fms): Failed to compact methods", end_time - start_time);
|
verbose(1, "JIT compaction failure (%.1fms): Failed to compact methods", end_time - start_time);
|
||||||
}
|
}
|
||||||
# endif // USE_HEADER_TRANSFORMATION
|
|
||||||
}
|
}
|
||||||
|
#endif // USE_JIT_COMPACTION
|
||||||
#endif // _MSC_VER
|
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
load_func_from_so(const char *so_file, const char *funcname, struct rb_mjit_unit *unit)
|
load_func_from_so(const char *so_file, const char *funcname, struct rb_mjit_unit *unit)
|
||||||
|
@ -1172,10 +1172,7 @@ convert_unit_to_func(struct rb_mjit_unit *unit)
|
||||||
|
|
||||||
start_time = real_ms_time();
|
start_time = real_ms_time();
|
||||||
success = compile_c_to_so(c_file, so_file);
|
success = compile_c_to_so(c_file, so_file);
|
||||||
#ifdef _MSC_VER
|
#ifdef USE_JIT_COMPACTION
|
||||||
if (!mjit_opts.save_temps)
|
|
||||||
remove_file(c_file);
|
|
||||||
#else
|
|
||||||
if (success) {
|
if (success) {
|
||||||
// Always set c_file for compaction. The value is also used for lazy deletion.
|
// Always set c_file for compaction. The value is also used for lazy deletion.
|
||||||
unit->c_file = strdup(c_file);
|
unit->c_file = strdup(c_file);
|
||||||
|
@ -1185,6 +1182,9 @@ convert_unit_to_func(struct rb_mjit_unit *unit)
|
||||||
}
|
}
|
||||||
if (!mjit_opts.save_temps && unit->c_file == NULL)
|
if (!mjit_opts.save_temps && unit->c_file == NULL)
|
||||||
remove_file(c_file);
|
remove_file(c_file);
|
||||||
|
#else
|
||||||
|
if (!mjit_opts.save_temps)
|
||||||
|
remove_file(c_file);
|
||||||
#endif
|
#endif
|
||||||
end_time = real_ms_time();
|
end_time = real_ms_time();
|
||||||
|
|
||||||
|
@ -1311,7 +1311,7 @@ mjit_worker(void)
|
||||||
}
|
}
|
||||||
CRITICAL_SECTION_FINISH(3, "in jit func replace");
|
CRITICAL_SECTION_FINISH(3, "in jit func replace");
|
||||||
|
|
||||||
#ifndef _MSC_VER
|
#ifdef USE_JIT_COMPACTION
|
||||||
// Combine .o files to one .so and reload all jit_func to improve memory locality.
|
// Combine .o files to one .so and reload all jit_func to improve memory locality.
|
||||||
if (compact_units.length < max_compact_size
|
if (compact_units.length < max_compact_size
|
||||||
&& ((!mjit_opts.wait && unit_queue.length == 0 && active_units.length > 1)
|
&& ((!mjit_opts.wait && unit_queue.length == 0 && active_units.length > 1)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче