summaryrefslogtreecommitdiff
path: root/yjit.h
diff options
context:
space:
mode:
authorAlan Wu <alanwu@ruby-lang.org>2022-04-19 14:40:21 -0400
committerAlan Wu <XrXr@users.noreply.github.com>2022-04-27 11:00:22 -0400
commitf90549cd38518231a6a74432fe1168c943a7cc18 (patch)
treec277bbfab47e230bd549bd5f607f60c3e812a714 /yjit.h
parentf553180a86b71830a1de49dd04874b3880c5c698 (diff)
downloadruby-f90549cd38518231a6a74432fe1168c943a7cc18.tar.gz
Rust YJIT
In December 2021, we opened an [issue] to solicit feedback regarding the porting of the YJIT codebase from C99 to Rust. There were some reservations, but this project was given the go ahead by Ruby core developers and Matz. Since then, we have successfully completed the port of YJIT to Rust. The new Rust version of YJIT has reached parity with the C version, in that it passes all the CRuby tests, is able to run all of the YJIT benchmarks, and performs similarly to the C version (because it works the same way and largely generates the same machine code). We've even incorporated some design improvements, such as a more fine-grained constant invalidation mechanism which we expect will make a big difference in Ruby on Rails applications. Because we want to be careful, YJIT is guarded behind a configure option: ```shell ./configure --enable-yjit # Build YJIT in release mode ./configure --enable-yjit=dev # Build YJIT in dev/debug mode ``` By default, YJIT does not get compiled and cargo/rustc is not required. If YJIT is built in dev mode, then `cargo` is used to fetch development dependencies, but when building in release, `cargo` is not required, only `rustc`. At the moment YJIT requires Rust 1.60.0 or newer. The YJIT command-line options remain mostly unchanged, and more details about the build process are documented in `doc/yjit/yjit.md`. The CI tests have been updated and do not take any more resources than before. The development history of the Rust port is available at the following commit for interested parties: https://github.com/Shopify/ruby/commit/1fd9573d8b4b65219f1c2407f30a0a60e537f8be Our hope is that Rust YJIT will be compiled and included as a part of system packages and compiled binaries of the Ruby 3.2 release. We do not anticipate any major problems as Rust is well supported on every platform which YJIT supports, but to make sure that this process works smoothly, we would like to reach out to those who take care of building systems packages before the 3.2 release is shipped and resolve any issues that may come up. [issue]: https://bugs.ruby-lang.org/issues/18481 Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com> Co-authored-by: Noah Gibbs <the.codefolio.guy@gmail.com> Co-authored-by: Kevin Newton <kddnewton@gmail.com>
Diffstat (limited to 'yjit.h')
-rw-r--r--yjit.h74
1 files changed, 40 insertions, 34 deletions
diff --git a/yjit.h b/yjit.h
index cc1e23d327..a1e3efb330 100644
--- a/yjit.h
+++ b/yjit.h
@@ -22,52 +22,58 @@
# define YJIT_SUPPORTED_P 0
#endif
-struct rb_yjit_options {
- // Enable compilation with YJIT
- bool yjit_enabled;
-
- // Size of the executable memory block to allocate in MiB
- unsigned exec_mem_size;
-
- // Number of method calls after which to start generating code
- // Threshold==1 means compile on first execution
- unsigned call_threshold;
-
- // Generate versions greedily until the limit is hit
- bool greedy_versioning;
-
- // Disable the propagation of type information
- bool no_type_prop;
-
- // Maximum number of versions per block
- // 1 means always create generic versions
- unsigned max_versions;
-
- // Capture and print out stats
- bool gen_stats;
+// Is the output binary going to include YJIT?
+#if USE_MJIT && USE_YJIT && YJIT_SUPPORTED_P
+# define YJIT_BUILD 1
+#else
+# define YJIT_BUILD 0
+#endif
- // Run backend tests
- bool test_backend;
-};
+#if YJIT_BUILD
+// Expose these as declarations since we are building YJIT.
bool rb_yjit_enabled_p(void);
unsigned rb_yjit_call_threshold(void);
-
void rb_yjit_invalidate_all_method_lookup_assumptions(void);
void rb_yjit_method_lookup_change(VALUE klass, ID mid);
-void rb_yjit_cme_invalidate(VALUE cme);
+void rb_yjit_cme_invalidate(rb_callable_method_entry_t *cme);
void rb_yjit_collect_vm_usage_insn(int insn);
void rb_yjit_collect_binding_alloc(void);
void rb_yjit_collect_binding_set(void);
bool rb_yjit_compile_iseq(const rb_iseq_t *iseq, rb_execution_context_t *ec);
-void rb_yjit_init(struct rb_yjit_options *options);
-void rb_yjit_bop_redefined(VALUE klass, const rb_method_entry_t *me, enum ruby_basic_operators bop);
-void rb_yjit_constant_state_changed(void);
-void rb_yjit_iseq_mark(const struct rb_iseq_constant_body *body);
-void rb_yjit_iseq_update_references(const struct rb_iseq_constant_body *body);
-void rb_yjit_iseq_free(const struct rb_iseq_constant_body *body);
+void rb_yjit_init(void);
+void rb_yjit_bop_redefined(int redefined_flag, enum ruby_basic_operators bop);
+void rb_yjit_constant_state_changed(ID id);
+void rb_yjit_iseq_mark(void *payload);
+void rb_yjit_iseq_update_references(void *payload);
+void rb_yjit_iseq_free(void *payload);
void rb_yjit_before_ractor_spawn(void);
void rb_yjit_constant_ic_update(const rb_iseq_t *const iseq, IC ic);
void rb_yjit_tracing_invalidate_all(void);
+#else
+// !YJIT_BUILD
+// In these builds, YJIT could never be turned on. Provide dummy implementations.
+
+static inline bool rb_yjit_enabled_p(void) { return false; }
+static inline unsigned rb_yjit_call_threshold(void) { return UINT_MAX; }
+static inline void rb_yjit_invalidate_all_method_lookup_assumptions(void) {}
+static inline void rb_yjit_method_lookup_change(VALUE klass, ID mid) {}
+static inline void rb_yjit_cme_invalidate(rb_callable_method_entry_t *cme) {}
+static inline void rb_yjit_collect_vm_usage_insn(int insn) {}
+static inline void rb_yjit_collect_binding_alloc(void) {}
+static inline void rb_yjit_collect_binding_set(void) {}
+static inline bool rb_yjit_compile_iseq(const rb_iseq_t *iseq, rb_execution_context_t *ec) { return false; }
+static inline void rb_yjit_init(void) {}
+static inline void rb_yjit_bop_redefined(int redefined_flag, enum ruby_basic_operators bop) {}
+static inline void rb_yjit_constant_state_changed(ID id) {}
+static inline void rb_yjit_iseq_mark(void *payload) {}
+static inline void rb_yjit_iseq_update_references(void *payload) {}
+static inline void rb_yjit_iseq_free(void *payload) {}
+static inline void rb_yjit_before_ractor_spawn(void) {}
+static inline void rb_yjit_constant_ic_update(const rb_iseq_t *const iseq, IC ic) {}
+static inline void rb_yjit_tracing_invalidate_all(void) {}
+
+#endif // #if YJIT_BUILD
+
#endif // #ifndef YJIT_H