-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathExeProbeTest.v3
181 lines (153 loc) · 5.39 KB
/
ExeProbeTest.v3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// Copyright 2024 Wizard authors. All rights reserved.
// See LICENSE for details of Apache 2.0 license.
def X_ = TestTiers.addTests([
("gc_CountProbe", test_gc_CountProbe), // intended to trigger GC with intrinsified count probe
("gc_OperandProbe_i_v", test_gc_OperandProbe_i_v), // intended to trigger GC with intrinsified operand probe
("dyn_probe_insert", test_dyn_probe_insert),
("dyn_probe_insert_osr", test_dyn_probe_insert_osr),
("entry_probe0", test_entry_probe0),
("entry_probe1", test_entry_probe1)
]);
def test_force_gc_callback(args: Range<Value>) -> HostResult {
// Allocations and forced GCs help randomize the heap layout to catch bugs in walking interpreter frames
var a = args[0], b = args[1];
var x = [a, b];
Target.forceGC();
var y = [a, b];
Target.forceGC();
var z = [a, b];
Target.forceGC();
if (x[0] != y[0]) return HostResult.Value1(Values.box_i(-1));
if (x[1] != y[1]) return HostResult.Value1(Values.box_i(-2));
if (x[0] != z[0]) return HostResult.Value1(Values.box_i(-3));
if (x[1] != z[1]) return HostResult.Value1(Values.box_i(-4));
return HostResult.Value1(Values.box_i(99 - Values.unbox_i(a) - Values.unbox_i(b)));
}
def test_gc_CountProbe(i: ExeTester) {
var tuning_before = SpcTuning.intrinsifyCountProbe;
SpcTuning.intrinsifyCountProbe = true; // TODO: manual for testing
var count = CountProbe.new();
var sig = i.newSig(SigCache.arr_ii, SigCache.arr_i);
i.sig(sig);
var fd = i.newFunc(sig);
i.module.addImport("", "", fd);
i.imports = [HostFunction.new("test_gcCountProbe_callback", sig, test_force_gc_callback)];
i.code([Opcode.LOCAL_GET.code, 0,
Opcode.LOCAL_GET.code, 1,
Opcode.CALL.code, byte.!(fd.func_index)]);
Instrumentation.insertLocalProbe(i.module, i.func.func_index, 1, count);
i.args_ii(44, 33).assert2_i(22);
i.args_ii(1090909, 0xFAAA0123).assert2_i(88431075);
i.t.assert_eq(2uL, count.count);
SpcTuning.intrinsifyCountProbe = tuning_before;
}
class RecordTosProbe extends OperandProbe_i_v {
var recorded: u32;
def fire_i(val: u32) {
var x = [val, 11u];
Target.forceGC();
var y = [val, 12u];
Target.forceGC();
var z = [val, 13u];
Target.forceGC();
recorded = x[0];
}
}
def test_gc_OperandProbe_i_v(i: ExeTester) {
var tuning_before = SpcTuning.intrinsifyOperandProbe;
SpcTuning.intrinsifyOperandProbe = true; // TODO: manual for testing
var p1 = RecordTosProbe.new(), p2 = RecordTosProbe.new();
i.sig(SigCache.ii_i);
i.code([Opcode.LOCAL_GET.code, 0,
Opcode.LOCAL_GET.code, 1,
Opcode.I32_ADD.code]);
Instrumentation.insertLocalProbe(i.module, i.func.func_index, 3, p1);
Instrumentation.insertLocalProbe(i.module, i.func.func_index, 5, p2);
i.args_ii(44, 33).assert2_i(77);
i.t.assert_eq(44u, p1.recorded);
i.t.assert_eq(33u, p2.recorded);
i.args_ii(1090909, 0xFAAA0123).assert2_i(0xfabaa680);
i.t.assert_eq(1090909u, p1.recorded);
i.t.assert_eq(0xFAAA0123u, p2.recorded);
SpcTuning.intrinsifyOperandProbe = tuning_before;
}
def test_dyn_probe_insert(i: ExeTester) {
var counter = CountProbe.new();
var p1 = ClosureProbe.new(Instrumentation.insertLocalProbe, (i.module, i.func.func_index, 1, counter));
i.sig(SigCache.ii_i);
i.code([Opcode.LOCAL_GET.code, 0,
Opcode.LOCAL_GET.code, 1,
Opcode.I32_ADD.code]);
Instrumentation.insertLocalProbe(i.module, i.func.func_index, 3, p1);
i.args_ii(44, 33).assert2_i(77);
i.t.assert_eq(0u, counter.count);
i.args_ii(55, 33).assert2_i(88);
i.t.assert_eq(1u, counter.count);
i.args_ii(44, 55).assert2_i(99);
i.t.assert_eq(3u, counter.count);
}
def test_dyn_probe_insert_osr(i: ExeTester) {
var counter = CountProbe.new();
var p1 = ClosureProbe.new(Instrumentation.insertLocalProbe, (i.module, i.func.func_index, 3, counter));
i.sig(SigCache.ii_i);
i.code([Opcode.LOCAL_GET.code, 0,
Opcode.LOCAL_GET.code, 1,
Opcode.I32_ADD.code]);
Instrumentation.insertLocalProbe(i.module, i.func.func_index, 1, p1);
i.args_ii(44, 33).assert2_i(77);
i.t.assert_eq(1u, counter.count);
i.args_ii(55, 33).assert2_i(88);
i.t.assert_eq(3u, counter.count);
i.args_ii(44, 55).assert2_i(99);
i.t.assert_eq(6u, counter.count);
}
class TraceProbe2 extends CountProbe {
def fire(dynamicLoc: DynamicLoc) -> Resumption {
Trace.OUT.put2("count = %d, %d", count++, count).ln();
return Resumption.Continue;
}
}
def test_entry_probe0(i: ExeTester) {
var counter = TraceProbe2.new();
i.sig(SigCache.i_i);
i.codev([
Opcode.LOOP.code, BpTypeCode.EmptyBlock.code,
Opcode.I32_CONST.code, 17,
Opcode.LOCAL_GET.code, 0,
Opcode.I32_CONST.code, 1,
Opcode.I32_SUB.code,
Opcode.LOCAL_TEE.code, 0,
Opcode.I32_EQZ.code,
Opcode.BR_IF.code, 1,
Opcode.BR.code, 0,
Opcode.END.code,
Opcode.UNREACHABLE.code
]);
Instrumentation.insertLocalProbe(i.module, i.func.func_index, 0, counter);
i.args_i(5).assert2_i(17);
i.t.assert_eq(1u, counter.count);
i.args_i(5).assert2_i(17);
i.t.assert_eq(2u, counter.count);
}
def test_entry_probe1(i: ExeTester) {
var counter = TraceProbe2.new();
i.sig(SigCache.i_i);
i.codev([
Opcode.LOOP.code, BpTypeCode.EmptyBlock.code,
Opcode.I32_CONST.code, 17,
Opcode.LOCAL_GET.code, 0,
Opcode.I32_CONST.code, 1,
Opcode.I32_SUB.code,
Opcode.LOCAL_TEE.code, 0,
Opcode.I32_EQZ.code,
Opcode.BR_IF.code, 1,
Opcode.BR.code, 0,
Opcode.END.code,
Opcode.UNREACHABLE.code
]);
Instrumentation.insertFuncEntryProbe(i.module, i.func.func_index, counter);
i.args_i(5).assert2_i(17);
i.t.assert_eq(1u, counter.count);
i.args_i(5).assert2_i(17);
i.t.assert_eq(2u, counter.count);
}