Skip to content

Commit

Permalink
Remove obsoleted functions in rjit.c
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Mar 8, 2023
1 parent 4bf037b commit 9ad1906
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 139 deletions.
2 changes: 0 additions & 2 deletions eval.c
Expand Up @@ -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);

/* unlock again if finalizer took mutexes. */
Expand Down
2 changes: 1 addition & 1 deletion iseq.c
Expand Up @@ -164,7 +164,7 @@ rb_iseq_free(const rb_iseq_t *iseq)
if (iseq && ISEQ_BODY(iseq)) {
iseq_clear_ic_references(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
rb_yjit_iseq_free(body->yjit_payload);
#endif
Expand Down
7 changes: 1 addition & 6 deletions process.c
Expand Up @@ -3049,7 +3049,6 @@ rb_f_exec(int argc, const VALUE *argv)

execarg_obj = rb_execarg_new(argc, argv, TRUE, FALSE);
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 */

rb_protect(rb_execarg_parent_start1, execarg_obj, &state);
Expand Down Expand Up @@ -4244,7 +4243,6 @@ rb_fork_ruby2(struct rb_process_status *status)

while (1) {
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);
before_fork_ruby();
pid = rb_fork();
Expand All @@ -4256,8 +4254,6 @@ rb_fork_ruby2(struct rb_process_status *status)
after_fork_ruby();
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) rb_thread_atfork();
return pid;
Expand Down Expand Up @@ -7035,11 +7031,10 @@ rb_daemon(int nochdir, int noclose)
{
int err = 0;
#ifdef HAVE_DAEMON
if (rjit_enabled) rjit_pause(false); // Don't leave locked mutex to child.
before_fork_ruby();
err = daemon(nochdir, noclose);
after_fork_ruby();
rb_thread_atfork(); /* calls rjit_resume() */
rb_thread_atfork();
#else
int n;

Expand Down
96 changes: 3 additions & 93 deletions rjit.c
Expand Up @@ -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
rjit_cancel_all(const char *reason)
rb_rjit_cancel_all(const char *reason)
{
if (!rjit_enabled)
return;
Expand All @@ -120,15 +113,9 @@ rjit_cancel_all(const char *reason)
}

void
rjit_free_iseq(const rb_iseq_t *iseq)
{
// TODO: remove this
}

void
rjit_notify_waitpid(int exit_code)
rb_rjit_free_iseq(const rb_iseq_t *iseq)
{
// TODO: remove this function
// TODO: implement this. GC_REFS should remove this iseq's mjit_blocks
}

// RubyVM::RJIT
Expand All @@ -144,49 +131,6 @@ static VALUE rb_cRJITCfpPtr = 0;
// RubyVM::RJIT::Hooks
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.
#define DEFAULT_MAX_CACHE_SIZE 100
// A default threshold used to add iseq to JIT.
Expand Down Expand Up @@ -236,34 +180,6 @@ const struct ruby_opt_message rjit_option_messages[] = {
};
#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
Expand Down Expand Up @@ -621,12 +537,6 @@ rjit_init(const struct rjit_options *opts)
#endif
}

void
rjit_finish(bool close_handle_p)
{
// TODO: implement
}

// Same as `RubyVM::RJIT::C.enabled?`, but this is used before rjit_init.
static VALUE
rjit_stats_enabled_p(rb_execution_context_t *ec, VALUE self)
Expand Down
25 changes: 4 additions & 21 deletions rjit.h
Expand Up @@ -93,18 +93,11 @@ RUBY_EXTERN bool rjit_call_p;
#define rb_rjit_call_threshold() rjit_opts.call_threshold

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

extern void rjit_cancel_all(const char *reason);
extern bool rjit_compile(FILE *f, const rb_iseq_t *iseq, const char *funcname, int id);
extern void rb_rjit_cancel_all(const char *reason);
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 rjit_mark(void);
extern void rb_rjit_iseq_mark(VALUE rjit_blocks);
Expand All @@ -117,27 +110,21 @@ 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_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_before_ractor_spawn(void);
extern void rb_rjit_tracing_invalidate_all(rb_event_flag_t new_iseq_events);
extern void rb_rjit_collect_vm_usage_insn(int insn);

extern bool rjit_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

static inline void rb_rjit_compile(const rb_iseq_t *iseq){}

static inline void rjit_cancel_all(const char *reason){}
static inline void rjit_free_iseq(const rb_iseq_t *iseq){}
static inline void rb_rjit_cancel_all(const char *reason){}
static inline void rb_rjit_free_iseq(const rb_iseq_t *iseq){}
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_cme_invalidate(rb_callable_method_entry_t *cme) {}
Expand All @@ -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

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) {}

# endif // USE_RJIT
Expand Down
6 changes: 3 additions & 3 deletions rjit.rb
Expand Up @@ -5,13 +5,13 @@ def self.enabled?
end

# Stop generating JITed code.
def self.pause(wait: true)
Primitive.cexpr! 'rjit_pause(RTEST(wait))'
def self.pause
# TODO: implement this
end

# Start generating JITed code again after pause.
def self.resume
Primitive.cexpr! 'rjit_resume()'
# TODO: implement this
end

if Primitive.rjit_stats_enabled_p
Expand Down
11 changes: 1 addition & 10 deletions rjit_c.rb
Expand Up @@ -515,18 +515,9 @@ def rjit_opts
rjit_options.new(addr)
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)
Primitive.cstmt! %{
rjit_cancel_all(RSTRING_PTR(reason));
rb_rjit_cancel_all(RSTRING_PTR(reason));
return Qnil;
}
end
Expand Down
3 changes: 0 additions & 3 deletions thread.c
Expand Up @@ -4642,9 +4642,6 @@ rb_thread_atfork(void)

/* We don't want reproduce CVE-2003-0900. */
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
Expand Down

0 comments on commit 9ad1906

Please sign in to comment.