/
runops_cores.c
310 lines (238 loc) · 6.74 KB
/
runops_cores.c
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/*
Copyright (C) 2001-2006, The Perl Foundation.
$Id$
=head1 NAME
src/runops_cores.c - Run Loops
=head1 DESCRIPTION
This file implements the various run loops for the interpreter. A slow
one with bounds checking, tracing and (optional) profiling, and a fast
one without. There's also one which uses computed C<goto>, which enables
the faster dispatch of operations.
=head2 Functions
=over 4
=cut
*/
#include "runops_cores.h"
#include "parrot/embed.h"
#include "trace.h"
#include "interp_guts.h"
#ifdef HAVE_COMPUTED_GOTO
# include "parrot/oplib/core_ops_cg.h"
#endif
/* HEADERIZER HFILE: src/runops_cores.h */
/* HEADERIZER BEGIN: static */
PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
static opcode_t * runops_trace_core(PARROT_INTERP, ARGIN(opcode_t *pc))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
/* HEADERIZER END: static */
/*
=item C<opcode_t * runops_fast_core>
Runs the Parrot operations starting at C<pc> until there are no more
operations.
No bounds checking, profiling or tracing is performed.
=cut
*/
PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
opcode_t *
runops_fast_core(PARROT_INTERP, ARGIN(opcode_t *pc))
{
while (pc) {
DO_OP(pc, interp);
}
return pc;
}
/*
=item C<opcode_t * runops_cgoto_core>
Runs the Parrot operations starting at C<pc> until there are no more
operations, using the computed C<goto> core.
No bounds checking, profiling or tracing is performed.
If computed C<goto> is not available then Parrot exits with exit code 1.
=cut
*/
PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
opcode_t *
runops_cgoto_core(PARROT_INTERP, ARGIN(opcode_t *pc))
{
#ifdef HAVE_COMPUTED_GOTO
pc = cg_core(pc, interp);
return pc;
#else
PIO_eprintf(interp,
"Computed goto unavailable in this configuration.\n");
Parrot_exit(interp, 1);
#endif
}
#ifdef code_start
# undef code_start
#endif
#ifdef code_end
# undef code_end
#endif
#define code_start interp->code->base.data
#define code_end (interp->code->base.data + interp->code->base.size)
/*
=item C<static opcode_t * runops_trace_core>
RT#48260: Not yet documented!!!
=cut
*/
PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
static opcode_t *
runops_trace_core(PARROT_INTERP, ARGIN(opcode_t *pc))
{
static size_t dod, gc;
Arenas * const arena_base = interp->arena_base;
Interp *debugger;
PMC* pio;
dod = arena_base->dod_runs;
gc = arena_base->collect_runs;
if (!interp->debugger) {
PMC *pio;
debugger = interp->debugger =
/*
* using a distinct interpreter for tracing should be ok
* - just in case, make it easy to switch
*/
#if 1
make_interpreter(interp, 0);
#else
interp;
#endif
debugger->lo_var_ptr = interp->lo_var_ptr;
pio = PIO_STDERR(debugger);
if (PIO_isatty(debugger, pio))
PIO_setlinebuf(debugger, pio);
else {
/* this is essential (100 x faster!) and should probably
* be in init/open code */
PIO_setbuf(debugger, pio, 8192);
}
}
else
debugger = interp->debugger;
trace_op(interp, code_start, code_end, pc);
while (pc) {
if (pc < code_start || pc >= code_end) {
real_exception(interp, NULL, 1,
"attempt to access code outside of current code segment");
}
CONTEXT(interp->ctx)->current_pc = pc;
DO_OP(pc, interp);
trace_op(interp, code_start, code_end, pc);
if (dod != arena_base->dod_runs) {
dod = arena_base->dod_runs;
PIO_eprintf(debugger, " DOD\n");
}
if (gc != arena_base->collect_runs) {
gc = arena_base->collect_runs;
PIO_eprintf(debugger, " GC\n");
}
}
pio = PIO_STDERR(debugger);
PIO_flush(debugger, pio);
return pc;
}
/*
=item C<opcode_t * runops_slow_core>
Runs the Parrot operations starting at C<pc> until there are no more
operations, with tracing and bounds checking enabled.
=cut
*/
PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
opcode_t *
runops_slow_core(PARROT_INTERP, ARGIN(opcode_t *pc))
{
if (Interp_trace_TEST(interp, PARROT_TRACE_OPS_FLAG)) {
return runops_trace_core(interp, pc);
}
else if (interp->debugger && interp->debugger->pdb) {
return Parrot_debug(interp->debugger, pc);
}
while (pc) {
if (pc < code_start || pc >= code_end) {
real_exception(interp, NULL, 1,
"attempt to access code outside of current code segment");
}
CONTEXT(interp->ctx)->current_pc = pc;
DO_OP(pc, interp);
}
return pc;
}
/*
=item C<opcode_t * runops_gc_debug_core>
Runs the Parrot operations starting at C<pc> until there are no more
operations, performing a full GC run before each op. This is very slow, but
it's also a very quick way to find GC problems.
=cut
*/
PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
opcode_t *
runops_gc_debug_core(PARROT_INTERP, ARGIN(opcode_t *pc))
{
while (pc) {
if (pc < code_start || pc >= code_end) {
real_exception(interp, NULL, 1,
"attempt to access code outside of current code segment");
}
Parrot_do_dod_run(interp, 0);
CONTEXT(interp->ctx)->current_pc = pc;
DO_OP(pc, interp);
}
return pc;
}
#undef code_start
#undef code_end
/*
=item C<opcode_t * runops_profile_core>
Runs the Parrot operations starting at C<pc> until there are no more
operations, with tracing, bounds checking and profiling enabled.
=cut
*/
PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
opcode_t *
runops_profile_core(PARROT_INTERP, ARGIN(opcode_t *pc))
{
RunProfile * const profile = interp->profile;
const opcode_t old_op = profile->cur_op;
/*
* if we are reentering the runloop:
* - remember old op and calc time till now
*/
if (old_op) {
profile->data[old_op].time +=
Parrot_floatval_time() - profile->starttime;
}
while (pc) {/* && pc >= code_start && pc < code_end) */
opcode_t cur_op;
CONTEXT(interp->ctx)->current_pc = pc;
profile->cur_op = cur_op = *pc + PARROT_PROF_EXTRA;
profile->data[cur_op].numcalls++;
profile->starttime = Parrot_floatval_time();
DO_OP(pc, interp);
/* profile->cur_op may be different, if exception was thrown */
profile->data[profile->cur_op].time +=
Parrot_floatval_time() - profile->starttime;
}
if (old_op) {
/* old opcode continues */
profile->starttime = Parrot_floatval_time();
profile->cur_op = old_op;
}
return pc;
}
/*
=back
*/
/*
* Local variables:
* c-file-style: "parrot"
* End:
* vim: expandtab shiftwidth=4:
*/