Skip to content

Commit b1dbcd3

Browse files
committed
YJIT simplify gen_get_iver and gen_set_ivar
The `shape_id` now includes 3 bits for the `heap_id`. It is always non-zero for `T_OBJECT` and always zero for all other types. Hence all these allocator checks are no longer necessary.
1 parent bf3d6a1 commit b1dbcd3

File tree

1 file changed

+4
-32
lines changed

1 file changed

+4
-32
lines changed

yjit/src/codegen.rs

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2848,24 +2848,12 @@ fn gen_get_ivar(
28482848
recv: Opnd,
28492849
recv_opnd: YARVOpnd,
28502850
) -> Option<CodegenStatus> {
2851-
let comptime_val_klass = comptime_receiver.class_of();
2852-
28532851
// If recv isn't already a register, load it.
28542852
let recv = match recv {
28552853
Opnd::InsnOut { .. } => recv,
28562854
_ => asm.load(recv),
28572855
};
28582856

2859-
// Check if the comptime class uses a custom allocator
2860-
let custom_allocator = unsafe { rb_get_alloc_func(comptime_val_klass) };
2861-
let uses_custom_allocator = match custom_allocator {
2862-
Some(alloc_fun) => {
2863-
let allocate_instance = rb_class_allocate_instance as *const u8;
2864-
alloc_fun as *const u8 != allocate_instance
2865-
}
2866-
None => false,
2867-
};
2868-
28692857
// Check if the comptime receiver is a T_OBJECT
28702858
let receiver_t_object = unsafe { RB_TYPE_P(comptime_receiver, RUBY_T_OBJECT) };
28712859
// Use a general C call at the last chain to avoid exits on megamorphic shapes
@@ -2874,12 +2862,9 @@ fn gen_get_ivar(
28742862
gen_counter_incr(jit, asm, Counter::num_getivar_megamorphic);
28752863
}
28762864

2877-
// If the class uses the default allocator, instances should all be T_OBJECT
2878-
// NOTE: This assumes nobody changes the allocator of the class after allocation.
2879-
// Eventually, we can encode whether an object is T_OBJECT or not
2880-
// inside object shapes.
2865+
// NOTE: This assumes T_OBJECT can't ever have the same shape_id as any other type.
28812866
// too-complex shapes can't use index access, so we use rb_ivar_get for them too.
2882-
if !receiver_t_object || uses_custom_allocator || comptime_receiver.shape_too_complex() || megamorphic {
2867+
if !receiver_t_object || comptime_receiver.shape_too_complex() || megamorphic {
28832868
// General case. Call rb_ivar_get().
28842869
// VALUE rb_ivar_get(VALUE obj, ID id)
28852870
asm_comment!(asm, "call rb_ivar_get()");
@@ -3073,8 +3058,6 @@ fn gen_set_ivar(
30733058
recv_opnd: YARVOpnd,
30743059
ic: Option<*const iseq_inline_iv_cache_entry>,
30753060
) -> Option<CodegenStatus> {
3076-
let comptime_val_klass = comptime_receiver.class_of();
3077-
30783061
// If the comptime receiver is frozen, writing an IV will raise an exception
30793062
// and we don't want to JIT code to deal with that situation.
30803063
if comptime_receiver.is_frozen() {
@@ -3084,16 +3067,6 @@ fn gen_set_ivar(
30843067

30853068
let stack_type = asm.ctx.get_opnd_type(StackOpnd(0));
30863069

3087-
// Check if the comptime class uses a custom allocator
3088-
let custom_allocator = unsafe { rb_get_alloc_func(comptime_val_klass) };
3089-
let uses_custom_allocator = match custom_allocator {
3090-
Some(alloc_fun) => {
3091-
let allocate_instance = rb_class_allocate_instance as *const u8;
3092-
alloc_fun as *const u8 != allocate_instance
3093-
}
3094-
None => false,
3095-
};
3096-
30973070
// Check if the comptime receiver is a T_OBJECT
30983071
let receiver_t_object = unsafe { RB_TYPE_P(comptime_receiver, RUBY_T_OBJECT) };
30993072
// Use a general C call at the last chain to avoid exits on megamorphic shapes
@@ -3149,10 +3122,9 @@ fn gen_set_ivar(
31493122
None
31503123
};
31513124

3152-
// If the receiver isn't a T_OBJECT, or uses a custom allocator,
3153-
// then just write out the IV write as a function call.
3125+
// If the receiver isn't a T_OBJECT, then just write out the IV write as a function call.
31543126
// too-complex shapes can't use index access, so we use rb_ivar_get for them too.
3155-
if !receiver_t_object || uses_custom_allocator || shape_too_complex || new_shape_too_complex || megamorphic {
3127+
if !receiver_t_object || shape_too_complex || new_shape_too_complex || megamorphic {
31563128
// The function could raise FrozenError.
31573129
// Note that this modifies REG_SP, which is why we do it first
31583130
jit_prepare_non_leaf_call(jit, asm);

0 commit comments

Comments
 (0)