Skip to content

Commit 926c744

Browse files
committed
ZJIT: Enable stats before some tests
Some tests explicitly want to look at their counters.
1 parent 80c2293 commit 926c744

2 files changed

Lines changed: 61 additions & 20 deletions

File tree

zjit/src/hir/opt_tests.rs

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3592,6 +3592,7 @@ mod hir_opt_tests {
35923592

35933593
#[test]
35943594
fn dont_specialize_call_to_iseq_with_rest() {
3595+
enable_zjit_stats();
35953596
eval("
35963597
def foo(*args) = 1
35973598
def test = foo 1
@@ -3607,17 +3608,24 @@ mod hir_opt_tests {
36073608
bb2():
36083609
EntryPoint JIT(0)
36093610
v4:BasicObject = LoadArg :self@0
3611+
IncrCounterPtr
36103612
Jump bb3(v4)
3611-
bb3(v6:BasicObject):
3612-
v11:Fixnum[1] = Const Value(1)
3613-
v13:BasicObject = Send v6, :foo, v11 # SendFallbackReason: Complex argument passing
3613+
bb3(v7:BasicObject):
3614+
IncrCounter zjit_insn_count
3615+
IncrCounter zjit_insn_count
3616+
v14:Fixnum[1] = Const Value(1)
3617+
IncrCounter zjit_insn_count
3618+
IncrCounter complex_arg_pass_param_rest
3619+
v17:BasicObject = Send v7, :foo, v14 # SendFallbackReason: Complex argument passing
3620+
IncrCounter zjit_insn_count
36143621
CheckInterrupts
3615-
Return v13
3622+
Return v17
36163623
");
36173624
}
36183625

36193626
#[test]
36203627
fn dont_specialize_call_to_post_param_iseq() {
3628+
enable_zjit_stats();
36213629
eval("
36223630
def foo(opt=80, post) = post
36233631
def test = foo(10)
@@ -3632,12 +3640,18 @@ mod hir_opt_tests {
36323640
bb2():
36333641
EntryPoint JIT(0)
36343642
v4:BasicObject = LoadArg :self@0
3643+
IncrCounterPtr
36353644
Jump bb3(v4)
3636-
bb3(v6:BasicObject):
3637-
v11:Fixnum[10] = Const Value(10)
3638-
v13:BasicObject = Send v6, :foo, v11 # SendFallbackReason: Complex argument passing
3645+
bb3(v7:BasicObject):
3646+
IncrCounter zjit_insn_count
3647+
IncrCounter zjit_insn_count
3648+
v14:Fixnum[10] = Const Value(10)
3649+
IncrCounter zjit_insn_count
3650+
IncrCounter complex_arg_pass_param_post
3651+
v17:BasicObject = Send v7, :foo, v14 # SendFallbackReason: Complex argument passing
3652+
IncrCounter zjit_insn_count
36393653
CheckInterrupts
3640-
Return v13
3654+
Return v17
36413655
");
36423656
}
36433657

@@ -3908,6 +3922,7 @@ mod hir_opt_tests {
39083922

39093923
#[test]
39103924
fn dont_specialize_call_to_iseq_with_kwrest() {
3925+
enable_zjit_stats();
39113926
eval("
39123927
def foo(**args) = 1
39133928
def test = foo(a: 1)
@@ -3923,12 +3938,18 @@ mod hir_opt_tests {
39233938
bb2():
39243939
EntryPoint JIT(0)
39253940
v4:BasicObject = LoadArg :self@0
3941+
IncrCounterPtr
39263942
Jump bb3(v4)
3927-
bb3(v6:BasicObject):
3928-
v11:Fixnum[1] = Const Value(1)
3929-
v13:BasicObject = Send v6, :foo, v11 # SendFallbackReason: Complex argument passing
3943+
bb3(v7:BasicObject):
3944+
IncrCounter zjit_insn_count
3945+
IncrCounter zjit_insn_count
3946+
v14:Fixnum[1] = Const Value(1)
3947+
IncrCounter zjit_insn_count
3948+
IncrCounter complex_arg_pass_param_kwrest
3949+
v17:BasicObject = Send v7, :foo, v14 # SendFallbackReason: Complex argument passing
3950+
IncrCounter zjit_insn_count
39303951
CheckInterrupts
3931-
Return v13
3952+
Return v17
39323953
");
39333954
}
39343955

@@ -4016,6 +4037,7 @@ mod hir_opt_tests {
40164037

40174038
#[test]
40184039
fn dont_specialize_call_to_iseq_with_call_kwsplat() {
4040+
enable_zjit_stats();
40194041
eval("
40204042
def foo(a:) = a
40214043
def test = foo(**{a: 1})
@@ -4031,18 +4053,25 @@ mod hir_opt_tests {
40314053
bb2():
40324054
EntryPoint JIT(0)
40334055
v4:BasicObject = LoadArg :self@0
4056+
IncrCounterPtr
40344057
Jump bb3(v4)
4035-
bb3(v6:BasicObject):
4036-
v11:HashExact[VALUE(0x1000)] = Const Value(VALUE(0x1000))
4037-
v12:HashExact = HashDup v11
4038-
v14:BasicObject = Send v6, :foo, v12 # SendFallbackReason: Complex argument passing
4058+
bb3(v7:BasicObject):
4059+
IncrCounter zjit_insn_count
4060+
IncrCounter zjit_insn_count
4061+
v14:HashExact[VALUE(0x1000)] = Const Value(VALUE(0x1000))
4062+
v15:HashExact = HashDup v14
4063+
IncrCounter zjit_insn_count
4064+
IncrCounter complex_arg_pass_caller_kw_splat
4065+
v18:BasicObject = Send v7, :foo, v15 # SendFallbackReason: Complex argument passing
4066+
IncrCounter zjit_insn_count
40394067
CheckInterrupts
4040-
Return v14
4068+
Return v18
40414069
");
40424070
}
40434071

40444072
#[test]
40454073
fn dont_specialize_call_to_iseq_with_param_kwrest() {
4074+
enable_zjit_stats();
40464075
eval("
40474076
def foo(**kwargs) = kwargs.keys
40484077
def test = foo
@@ -4058,11 +4087,16 @@ mod hir_opt_tests {
40584087
bb2():
40594088
EntryPoint JIT(0)
40604089
v4:BasicObject = LoadArg :self@0
4090+
IncrCounterPtr
40614091
Jump bb3(v4)
4062-
bb3(v6:BasicObject):
4063-
v11:BasicObject = Send v6, :foo # SendFallbackReason: Complex argument passing
4092+
bb3(v7:BasicObject):
4093+
IncrCounter zjit_insn_count
4094+
IncrCounter zjit_insn_count
4095+
IncrCounter complex_arg_pass_param_kwrest
4096+
v14:BasicObject = Send v7, :foo # SendFallbackReason: Complex argument passing
4097+
IncrCounter zjit_insn_count
40644098
CheckInterrupts
4065-
Return v11
4099+
Return v14
40664100
");
40674101
}
40684102

zjit/src/options.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,13 @@ pub fn set_call_threshold(call_threshold: CallThreshold) {
457457
update_profile_threshold();
458458
}
459459

460+
/// Enable --zjit-stats for testing
461+
#[cfg(test)]
462+
pub fn enable_zjit_stats() {
463+
rb_zjit_prepare_options();
464+
unsafe { OPTIONS.as_mut() }.unwrap().stats = true;
465+
}
466+
460467
/// Print YJIT options for `ruby --help`. `width` is width of option parts, and
461468
/// `columns` is indent width of descriptions.
462469
#[unsafe(no_mangle)]

0 commit comments

Comments
 (0)