mirror of
https://github.com/ruby/ruby.git
synced 2026-01-26 12:14:51 +00:00
ZJIT: Move jit.rs to ruby.rs and create a shared crate jit
* ruby.rs should hold the main entrypoint to YJIT and ZJIT * The crate jit will hold code shared between them
This commit is contained in:
parent
30f85ce530
commit
f75e1cb362
16
Cargo.lock
generated
16
Cargo.lock
generated
@ -62,11 +62,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "jit"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"yjit",
|
||||
"zjit",
|
||||
]
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
@ -86,6 +82,14 @@ version = "1.21.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
||||
|
||||
[[package]]
|
||||
name = "ruby"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"yjit",
|
||||
"zjit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.3.0"
|
||||
@ -176,6 +180,7 @@ name = "yjit"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"capstone",
|
||||
"jit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -184,4 +189,5 @@ version = "0.0.1"
|
||||
dependencies = [
|
||||
"capstone",
|
||||
"insta",
|
||||
"jit",
|
||||
]
|
||||
|
||||
@ -3,10 +3,10 @@
|
||||
# TODO(alan) notes about rust version requirements. Undecided yet.
|
||||
|
||||
[workspace]
|
||||
members = ["zjit", "yjit"]
|
||||
members = ["zjit", "yjit", "jit"]
|
||||
|
||||
[package]
|
||||
name = "jit"
|
||||
name = "ruby"
|
||||
version = "0.0.0"
|
||||
edition = "2024"
|
||||
rust-version = "1.85.0"
|
||||
@ -18,7 +18,7 @@ zjit = { path = "zjit", optional = true }
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
path = "jit.rs"
|
||||
path = "ruby.rs"
|
||||
|
||||
[features]
|
||||
disasm = ["yjit?/disasm", "zjit?/disasm"]
|
||||
|
||||
@ -4019,9 +4019,9 @@ AS_IF([test x"$JIT_CARGO_SUPPORT" != "xno" -o \( x"$YJIT_SUPPORT" != "xno" -a x"
|
||||
])
|
||||
CARGO_BUILD_ARGS="--profile ${JIT_CARGO_SUPPORT} --features ${rb_cargo_features}"
|
||||
AS_IF([test "${JIT_CARGO_SUPPORT}" = "dev"], [
|
||||
RUST_LIB="target/debug/libjit.a"
|
||||
RUST_LIB="target/debug/libruby.a"
|
||||
], [
|
||||
RUST_LIB="target/${JIT_CARGO_SUPPORT}/libjit.a"
|
||||
RUST_LIB="target/${JIT_CARGO_SUPPORT}/libruby.a"
|
||||
])
|
||||
])
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ CARGO_VERBOSE = $(CARGO_VERBOSE_$(V))
|
||||
# ld: warning: object file (target/debug/libjit.a(<libcapstone object>)) was built for
|
||||
# newer macOS version (15.2) than being linked (15.0)
|
||||
# This limits us to an older set of macOS API in the rust code, but we don't use any.
|
||||
$(RUST_LIB): $(srcdir)/jit.rs
|
||||
$(RUST_LIB): $(srcdir)/ruby.rs
|
||||
$(Q)if [ '$(ZJIT_SUPPORT)' != no -a '$(YJIT_SUPPORT)' != no ]; then \
|
||||
echo 'building YJIT and ZJIT ($(JIT_CARGO_SUPPORT:yes=release) mode)'; \
|
||||
elif [ '$(ZJIT_SUPPORT)' != no ]; then \
|
||||
|
||||
6
jit/Cargo.toml
Normal file
6
jit/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "jit"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
37
jit/src/lib.rs
Normal file
37
jit/src/lib.rs
Normal file
@ -0,0 +1,37 @@
|
||||
//! Shared code between YJIT and ZJIT.
|
||||
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::alloc::{GlobalAlloc, Layout, System};
|
||||
|
||||
#[global_allocator]
|
||||
pub static GLOBAL_ALLOCATOR: StatsAlloc = StatsAlloc { alloc_size: AtomicUsize::new(0) };
|
||||
|
||||
pub struct StatsAlloc {
|
||||
pub alloc_size: AtomicUsize,
|
||||
}
|
||||
|
||||
unsafe impl GlobalAlloc for StatsAlloc {
|
||||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
||||
self.alloc_size.fetch_add(layout.size(), Ordering::SeqCst);
|
||||
unsafe { System.alloc(layout) }
|
||||
}
|
||||
|
||||
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
|
||||
self.alloc_size.fetch_sub(layout.size(), Ordering::SeqCst);
|
||||
unsafe { System.dealloc(ptr, layout) }
|
||||
}
|
||||
|
||||
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
|
||||
self.alloc_size.fetch_add(layout.size(), Ordering::SeqCst);
|
||||
unsafe { System.alloc_zeroed(layout) }
|
||||
}
|
||||
|
||||
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
|
||||
if new_size > layout.size() {
|
||||
self.alloc_size.fetch_add(new_size - layout.size(), Ordering::SeqCst);
|
||||
} else if new_size < layout.size() {
|
||||
self.alloc_size.fetch_sub(layout.size() - new_size, Ordering::SeqCst);
|
||||
}
|
||||
unsafe { System.realloc(ptr, layout, new_size) }
|
||||
}
|
||||
}
|
||||
@ -13,6 +13,7 @@ publish = false # Don't publish to crates.io
|
||||
# No required dependencies to simplify build process. TODO: Link to yet to be
|
||||
# written rationale. Optional For development and testing purposes
|
||||
capstone = { version = "0.13.0", optional = true }
|
||||
jit = { version = "0.1.0", path = "../jit" }
|
||||
|
||||
# NOTE: Development builds select a set of these via configure.ac
|
||||
# For debugging, `make V=1` shows exact cargo invocation.
|
||||
|
||||
@ -9,6 +9,7 @@ publish = false # Don't publish to crates.io
|
||||
# No required dependencies to simplify build process. TODO: Link to yet to be
|
||||
# written rationale. Optional For development and testing purposes
|
||||
capstone = { version = "0.13.0", optional = true }
|
||||
jit = { version = "0.1.0", path = "../jit" }
|
||||
|
||||
[dev-dependencies]
|
||||
insta = "1.43.1"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user