Remove obsoleted functions in rjit.c

This commit is contained in:
Takashi Kokubun 2023-03-07 23:44:26 -08:00
parent 4bf037bebd
commit 9ad19069f9
8 changed files with 13 additions and 139 deletions

2
eval.c
View File

@ -257,8 +257,6 @@ rb_ec_cleanup(rb_execution_context_t *ec, enum ruby_tag_type ex)
} }
} }
rjit_finish(true); // We still need ISeqs here, so it's before rb_ec_finalize().
rb_ec_finalize(ec); rb_ec_finalize(ec);
/* unlock again if finalizer took mutexes. */ /* unlock again if finalizer took mutexes. */

2
iseq.c
View File

@ -164,7 +164,7 @@ rb_iseq_free(const rb_iseq_t *iseq)
if (iseq && ISEQ_BODY(iseq)) { if (iseq && ISEQ_BODY(iseq)) {
iseq_clear_ic_references(iseq); iseq_clear_ic_references(iseq);
struct rb_iseq_constant_body *const body = ISEQ_BODY(iseq); struct rb_iseq_constant_body *const body = ISEQ_BODY(iseq);
rjit_free_iseq(iseq); /* Notify RJIT */ rb_rjit_free_iseq(iseq); /* Notify RJIT */
#if USE_YJIT #if USE_YJIT
rb_yjit_iseq_free(body->yjit_payload); rb_yjit_iseq_free(body->yjit_payload);
#endif #endif

View File

@ -3049,7 +3049,6 @@ rb_f_exec(int argc, const VALUE *argv)
execarg_obj = rb_execarg_new(argc, argv, TRUE, FALSE); execarg_obj = rb_execarg_new(argc, argv, TRUE, FALSE);
eargp = rb_execarg_get(execarg_obj); eargp = rb_execarg_get(execarg_obj);
if (rjit_enabled) rjit_finish(false); // avoid leaking resources, and do not leave files. XXX: JIT-ed handle can leak after exec error is rescued.
before_exec(); /* stop timer thread before redirects */ before_exec(); /* stop timer thread before redirects */
rb_protect(rb_execarg_parent_start1, execarg_obj, &state); rb_protect(rb_execarg_parent_start1, execarg_obj, &state);
@ -4244,7 +4243,6 @@ rb_fork_ruby2(struct rb_process_status *status)
while (1) { while (1) {
prefork(); prefork();
if (rjit_enabled) rjit_pause(false); // Don't leave locked mutex to child. Note: child_handler must be enabled to pause RJIT.
disable_child_handler_before_fork(&old); disable_child_handler_before_fork(&old);
before_fork_ruby(); before_fork_ruby();
pid = rb_fork(); pid = rb_fork();
@ -4256,8 +4254,6 @@ rb_fork_ruby2(struct rb_process_status *status)
after_fork_ruby(); after_fork_ruby();
disable_child_handler_fork_parent(&old); /* yes, bad name */ disable_child_handler_fork_parent(&old); /* yes, bad name */
if (rjit_enabled && pid > 0) rjit_resume(); /* child (pid == 0) is cared by rb_thread_atfork */
if (pid >= 0) { /* fork succeed */ if (pid >= 0) { /* fork succeed */
if (pid == 0) rb_thread_atfork(); if (pid == 0) rb_thread_atfork();
return pid; return pid;
@ -7035,11 +7031,10 @@ rb_daemon(int nochdir, int noclose)
{ {
int err = 0; int err = 0;
#ifdef HAVE_DAEMON #ifdef HAVE_DAEMON
if (rjit_enabled) rjit_pause(false); // Don't leave locked mutex to child.
before_fork_ruby(); before_fork_ruby();
err = daemon(nochdir, noclose); err = daemon(nochdir, noclose);
after_fork_ruby(); after_fork_ruby();
rb_thread_atfork(); /* calls rjit_resume() */ rb_thread_atfork();
#else #else
int n; int n;

96
rjit.c
View File

@ -99,15 +99,8 @@ verbose(int level, const char *format, ...)
} }
} }
int
rjit_capture_cc_entries(const struct rb_iseq_constant_body *compiled_iseq, const struct rb_iseq_constant_body *captured_iseq)
{
// TODO: remove this
return 0;
}
void void
rjit_cancel_all(const char *reason) rb_rjit_cancel_all(const char *reason)
{ {
if (!rjit_enabled) if (!rjit_enabled)
return; return;
@ -120,15 +113,9 @@ rjit_cancel_all(const char *reason)
} }
void void
rjit_free_iseq(const rb_iseq_t *iseq) rb_rjit_free_iseq(const rb_iseq_t *iseq)
{ {
// TODO: remove this // TODO: implement this. GC_REFS should remove this iseq's mjit_blocks
}
void
rjit_notify_waitpid(int exit_code)
{
// TODO: remove this function
} }
// RubyVM::RJIT // RubyVM::RJIT
@ -144,49 +131,6 @@ static VALUE rb_cRJITCfpPtr = 0;
// RubyVM::RJIT::Hooks // RubyVM::RJIT::Hooks
static VALUE rb_mRJITHooks = 0; static VALUE rb_mRJITHooks = 0;
void
rb_rjit_add_iseq_to_process(const rb_iseq_t *iseq)
{
// TODO: implement
}
struct rb_rjit_compile_info*
rb_rjit_iseq_compile_info(const struct rb_iseq_constant_body *body)
{
// TODO: remove this
return NULL;
}
void
rb_rjit_recompile_send(const rb_iseq_t *iseq)
{
// TODO: remove this
}
void
rb_rjit_recompile_ivar(const rb_iseq_t *iseq)
{
// TODO: remove this
}
void
rb_rjit_recompile_exivar(const rb_iseq_t *iseq)
{
// TODO: remove this
}
void
rb_rjit_recompile_inlining(const rb_iseq_t *iseq)
{
// TODO: remove this
}
void
rb_rjit_recompile_const(const rb_iseq_t *iseq)
{
// TODO: remove this
}
// Default permitted number of units with a JIT code kept in memory. // Default permitted number of units with a JIT code kept in memory.
#define DEFAULT_MAX_CACHE_SIZE 100 #define DEFAULT_MAX_CACHE_SIZE 100
// A default threshold used to add iseq to JIT. // A default threshold used to add iseq to JIT.
@ -236,34 +180,6 @@ const struct ruby_opt_message rjit_option_messages[] = {
}; };
#undef M #undef M
VALUE
rjit_pause(bool wait_p)
{
// TODO: remove this
return Qtrue;
}
VALUE
rjit_resume(void)
{
// TODO: remove this
return Qnil;
}
void
rjit_child_after_fork(void)
{
// TODO: remove this
}
// Compile ISeq to C code in `f`. It returns true if it succeeds to compile.
bool
rjit_compile(FILE *f, const rb_iseq_t *iseq, const char *funcname, int id)
{
// TODO: implement
return false;
}
//================================================================================ //================================================================================
// //
// New stuff from here // New stuff from here
@ -621,12 +537,6 @@ rjit_init(const struct rjit_options *opts)
#endif #endif
} }
void
rjit_finish(bool close_handle_p)
{
// TODO: implement
}
// Same as `RubyVM::RJIT::C.enabled?`, but this is used before rjit_init. // Same as `RubyVM::RJIT::C.enabled?`, but this is used before rjit_init.
static VALUE static VALUE
rjit_stats_enabled_p(rb_execution_context_t *ec, VALUE self) rjit_stats_enabled_p(rb_execution_context_t *ec, VALUE self)

25
rjit.h
View File

@ -93,18 +93,11 @@ RUBY_EXTERN bool rjit_call_p;
#define rb_rjit_call_threshold() rjit_opts.call_threshold #define rb_rjit_call_threshold() rjit_opts.call_threshold
extern void rb_rjit_compile(const rb_iseq_t *iseq); extern void rb_rjit_compile(const rb_iseq_t *iseq);
extern struct rb_rjit_compile_info* rb_rjit_iseq_compile_info(const struct rb_iseq_constant_body *body);
extern void rb_rjit_recompile_send(const rb_iseq_t *iseq);
extern void rb_rjit_recompile_ivar(const rb_iseq_t *iseq);
extern void rb_rjit_recompile_exivar(const rb_iseq_t *iseq);
extern void rb_rjit_recompile_inlining(const rb_iseq_t *iseq);
extern void rb_rjit_recompile_const(const rb_iseq_t *iseq);
RUBY_SYMBOL_EXPORT_END RUBY_SYMBOL_EXPORT_END
extern void rjit_cancel_all(const char *reason); extern void rb_rjit_cancel_all(const char *reason);
extern bool rjit_compile(FILE *f, const rb_iseq_t *iseq, const char *funcname, int id);
extern void rjit_init(const struct rjit_options *opts); extern void rjit_init(const struct rjit_options *opts);
extern void rjit_free_iseq(const rb_iseq_t *iseq); extern void rb_rjit_free_iseq(const rb_iseq_t *iseq);
extern void rb_rjit_iseq_update_references(struct rb_iseq_constant_body *const body); extern void rb_rjit_iseq_update_references(struct rb_iseq_constant_body *const body);
extern void rjit_mark(void); extern void rjit_mark(void);
extern void rb_rjit_iseq_mark(VALUE rjit_blocks); extern void rb_rjit_iseq_mark(VALUE rjit_blocks);
@ -117,8 +110,6 @@ extern void rb_rjit_constant_state_changed(ID id);
extern void rb_rjit_constant_ic_update(const rb_iseq_t *const iseq, IC ic, unsigned insn_idx); extern void rb_rjit_constant_ic_update(const rb_iseq_t *const iseq, IC ic, unsigned insn_idx);
extern void rb_rjit_tracing_invalidate_all(rb_event_flag_t new_iseq_events); extern void rb_rjit_tracing_invalidate_all(rb_event_flag_t new_iseq_events);
void rjit_child_after_fork(void);
extern void rb_rjit_bop_redefined(int redefined_flag, enum ruby_basic_operators bop); extern void rb_rjit_bop_redefined(int redefined_flag, enum ruby_basic_operators bop);
extern void rb_rjit_before_ractor_spawn(void); extern void rb_rjit_before_ractor_spawn(void);
extern void rb_rjit_tracing_invalidate_all(rb_event_flag_t new_iseq_events); extern void rb_rjit_tracing_invalidate_all(rb_event_flag_t new_iseq_events);
@ -126,18 +117,14 @@ extern void rb_rjit_collect_vm_usage_insn(int insn);
extern bool rjit_enabled; extern bool rjit_enabled;
extern bool rjit_stats_enabled; extern bool rjit_stats_enabled;
VALUE rjit_pause(bool wait_p);
VALUE rjit_resume(void);
void rjit_finish(bool close_handle_p);
# else // USE_RJIT # else // USE_RJIT
static inline void rb_rjit_compile(const rb_iseq_t *iseq){} static inline void rb_rjit_compile(const rb_iseq_t *iseq){}
static inline void rjit_cancel_all(const char *reason){} static inline void rb_rjit_cancel_all(const char *reason){}
static inline void rjit_free_iseq(const rb_iseq_t *iseq){} static inline void rb_rjit_free_iseq(const rb_iseq_t *iseq){}
static inline void rjit_mark(void){} static inline void rjit_mark(void){}
static inline void rjit_child_after_fork(void){}
static inline void rb_rjit_bop_redefined(int redefined_flag, enum ruby_basic_operators bop) {} static inline void rb_rjit_bop_redefined(int redefined_flag, enum ruby_basic_operators bop) {}
static inline void rb_rjit_cme_invalidate(rb_callable_method_entry_t *cme) {} static inline void rb_rjit_cme_invalidate(rb_callable_method_entry_t *cme) {}
@ -152,10 +139,6 @@ static inline void rb_rjit_tracing_invalidate_all(rb_event_flag_t new_iseq_event
#define rb_rjit_call_threshold() UINT_MAX #define rb_rjit_call_threshold() UINT_MAX
static inline VALUE rjit_pause(bool wait_p){ return Qnil; } // unreachable
static inline VALUE rjit_resume(void){ return Qnil; } // unreachable
static inline void rjit_finish(bool close_handle_p){}
static inline void rb_rjit_collect_vm_usage_insn(int insn) {} static inline void rb_rjit_collect_vm_usage_insn(int insn) {}
# endif // USE_RJIT # endif // USE_RJIT

View File

@ -5,13 +5,13 @@ module RubyVM::RJIT
end end
# Stop generating JITed code. # Stop generating JITed code.
def self.pause(wait: true) def self.pause
Primitive.cexpr! 'rjit_pause(RTEST(wait))' # TODO: implement this
end end
# Start generating JITed code again after pause. # Start generating JITed code again after pause.
def self.resume def self.resume
Primitive.cexpr! 'rjit_resume()' # TODO: implement this
end end
if Primitive.rjit_stats_enabled_p if Primitive.rjit_stats_enabled_p

View File

@ -515,18 +515,9 @@ module RubyVM::RJIT # :nodoc: all
rjit_options.new(addr) rjit_options.new(addr)
end end
def rjit_capture_cc_entries(compiled_body, captured_body)
_compiled_body_addr = compiled_body.to_i
_captured_body_addr = captured_body.to_i
Primitive.cstmt! %{
extern int rjit_capture_cc_entries(const struct rb_iseq_constant_body *compiled_iseq, const struct rb_iseq_constant_body *captured_iseq);
return INT2NUM(rjit_capture_cc_entries((struct rb_iseq_constant_body *)NUM2PTR(_compiled_body_addr), (struct rb_iseq_constant_body *)NUM2PTR(_captured_body_addr)));
}
end
def rjit_cancel_all(reason) def rjit_cancel_all(reason)
Primitive.cstmt! %{ Primitive.cstmt! %{
rjit_cancel_all(RSTRING_PTR(reason)); rb_rjit_cancel_all(RSTRING_PTR(reason));
return Qnil; return Qnil;
} }
end end

View File

@ -4642,9 +4642,6 @@ rb_thread_atfork(void)
/* We don't want reproduce CVE-2003-0900. */ /* We don't want reproduce CVE-2003-0900. */
rb_reset_random_seed(); rb_reset_random_seed();
/* For child, starting RJIT worker thread in this place which is safer than immediately after `after_fork_ruby`. */
rjit_child_after_fork();
} }
static void static void