Skip to content

Commit 59e96af

Browse files
committed
Move gc_fastpath.rs to codegen/gc_fastpath.rs
1 parent 349fe16 commit 59e96af

3 files changed

Lines changed: 19 additions & 11 deletions

File tree

zjit/src/codegen.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
33
#![allow(clippy::let_and_return)]
44

5+
mod gc_fastpath;
6+
57
use std::cell::{Cell, RefCell};
68
use std::rc::Rc;
79
use std::ffi::{c_int, c_long, c_void};
@@ -48,7 +50,7 @@ const PC_POISON: Option<*const VALUE> = if cfg!(feature = "runtime_checks") {
4850
};
4951

5052
/// Ephemeral code generation state
51-
pub(crate) struct JITState {
53+
struct JITState {
5254
/// ISEQ version that is being compiled, which will be used by PatchPoint
5355
version: IseqVersionRef,
5456

@@ -93,7 +95,7 @@ impl JITState {
9395
}
9496

9597
/// Find or create a label for a given BlockId
96-
pub(crate) fn get_label(&mut self, asm: &mut Assembler, lir_block_id: lir::BlockId, hir_block_id: BlockId) -> Target {
98+
fn get_label(&mut self, asm: &mut Assembler, lir_block_id: lir::BlockId, hir_block_id: BlockId) -> Target {
9799
// Extend labels vector if the requested index is out of bounds
98100
if lir_block_id.0 >= self.labels.len() {
99101
self.labels.resize(lir_block_id.0 + 1, None);
@@ -137,7 +139,7 @@ macro_rules! define_split_jumps {
137139
($($name:ident => $insn:ident),+ $(,)?) => {
138140
impl Assembler {
139141
$(
140-
pub(crate) fn $name(&mut self, jit: &mut JITState, target: Target) {
142+
fn $name(&mut self, jit: &mut JITState, target: Target) {
141143
self.split_block_jump(jit, |asm, target| asm.push_insn(lir::Insn::$insn(target)), target);
142144
}
143145
)+
@@ -1862,7 +1864,7 @@ fn gen_new_array(
18621864
let flags = (RUBY_T_ARRAY as u64) | (RARRAY_EMBED_FLAG as u64);
18631865
let klass = unsafe { rb_cArray };
18641866

1865-
crate::gc_fastpath::gc_fast_path_new_obj(jit, asm, alloc_size, flags, klass, |asm| {
1867+
gc_fastpath::gc_fast_path_new_obj(jit, asm, alloc_size, flags, klass, |asm| {
18661868
asm_ccall!(asm, rb_ec_ary_new_from_values, EC, 0i64.into(), Opnd::UImm(0))
18671869
})
18681870
}
Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
use std::ffi::c_void;
22

33
use crate::backend::lir::{self, Assembler, EC, Opnd, Target, asm_comment};
4-
use crate::codegen::JITState;
54
use crate::cruby::{
65
RB_GC_ZJIT_FASTPATH_DEFAULT, RB_GC_ZJIT_FASTPATH_MMTK,
76
RUBY_OFFSET_EC_THREAD_PTR, RUBY_OFFSET_RBASIC_FLAGS, RUBY_OFFSET_RBASIC_KLASS,
87
RUBY_OFFSET_THREAD_RACTOR, VALUE, VALUE_BITS, rb_zjit_offset_ractor_newobj_cache,
98
};
9+
use super::JITState;
1010

1111
#[repr(C)]
1212
#[derive(Clone, Copy)]
13-
pub(crate) struct RbGcZjitDefaultNewObjFastpath {
13+
struct RbGcZjitDefaultNewObjFastpath {
1414
cursor_offset: usize,
1515
jit_cursor_end_offset: usize,
1616
slot_size: usize,
@@ -20,7 +20,7 @@ pub(crate) struct RbGcZjitDefaultNewObjFastpath {
2020

2121
#[repr(C)]
2222
#[derive(Clone, Copy)]
23-
pub(crate) struct RbGcZjitMmtkNewObjFastpath {
23+
struct RbGcZjitMmtkNewObjFastpath {
2424
objspace: *const c_void,
2525
objspace_total_allocated_objects_offset: usize,
2626
ractor_cache_mutator_offset: usize,
@@ -63,12 +63,12 @@ unsafe extern "C" {
6363
) -> bool;
6464
}
6565

66-
pub(crate) enum PreparedNewObjFastpath {
66+
enum PreparedNewObjFastpath {
6767
Default(RbGcZjitDefaultNewObjFastpath),
6868
Mmtk(RbGcZjitMmtkNewObjFastpath),
6969
}
7070

71-
pub(crate) fn gc_fast_path_new_obj(
71+
pub(super) fn gc_fast_path_new_obj(
7272
jit: &mut JITState,
7373
asm: &mut Assembler,
7474
alloc_size: usize,
@@ -141,7 +141,7 @@ fn prepare_new_obj_fastpath(alloc_size: usize, flags: u64, klass: VALUE) -> Opti
141141
}
142142
}
143143

144-
pub(crate) fn emit_new_obj_fastpath(
144+
fn emit_new_obj_fastpath(
145145
jit: &mut JITState,
146146
asm: &mut Assembler,
147147
prepared: &PreparedNewObjFastpath,
@@ -162,6 +162,10 @@ pub(crate) fn emit_new_obj_fastpath(
162162
}
163163
}
164164

165+
/* This function implements the GC fast path for the default GC. It implements
166+
* the fast path defined in function ractor_cache_allocate_slot (but not the
167+
* medium path in ractor_cache_advance_region). It also implements newobj_init
168+
* to write the flags and klass in the object. */
165169
fn emit_default_new_obj_fastpath(
166170
jit: &mut JITState,
167171
asm: &mut Assembler,
@@ -199,6 +203,9 @@ fn emit_default_new_obj_fastpath(
199203
Some(cursor)
200204
}
201205

206+
/* This function implements the GC fast path for MMTk. It implements the fast
207+
* path defined in function rb_mmtk_alloc_fast_path, as well as writing the
208+
* flags and klass into the object. */
202209
fn emit_mmtk_new_obj_fastpath(
203210
jit: &mut JITState,
204211
asm: &mut Assembler,

zjit/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ mod cruby_methods;
1616
mod hir;
1717
mod hir_type;
1818
mod hir_effect;
19-
mod gc_fastpath;
2019
mod codegen;
2120
mod stats;
2221
mod cast;

0 commit comments

Comments
 (0)