Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd7df54b

Browse files
committed
Support EXTENDED_ARG; improve offsets in debug output
Offsets in debug output identifying the start of the traceare now measured in bytes (and the text shows it).Note that there is a pre-existing bug where```./python -Xuops -m test test_builtin```fails. Will debug that later.
1 parent00525f0 commitd7df54b

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

‎Python/ceval.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2728,11 +2728,11 @@ _PyUopExecute(_PyExecutorObject *executor, _PyInterpreterFrame *frame, PyObject
27282728
#endif
27292729

27302730
DPRINTF(3,
2731-
"Entering _PyUopExecute for %s (%s:%d) at offset %ld\n",
2731+
"Entering _PyUopExecute for %s (%s:%d) atbyteoffset %ld\n",
27322732
PyUnicode_AsUTF8(_PyFrame_GetCode(frame)->co_qualname),
27332733
PyUnicode_AsUTF8(_PyFrame_GetCode(frame)->co_filename),
27342734
_PyFrame_GetCode(frame)->co_firstlineno,
2735-
(long)(frame->prev_instr+1-
2735+
2*(long)(frame->prev_instr+1-
27362736
(_Py_CODEUNIT*)_PyFrame_GetCode(frame)->co_code_adaptive));
27372737

27382738
PyThreadState*tstate=_PyThreadState_GET();

‎Python/optimizer.c

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ _PyOptimizer_BackEdge(_PyInterpreterFrame *frame, _Py_CODEUNIT *src, _Py_CODEUNI
181181
}
182182
insert_executor(code,src,index,executor);
183183
assert(frame->prev_instr==src);
184+
frame->prev_instr=dest-1;
184185
returnexecutor->execute(executor,frame,stack_pointer);
185186
jump_to_destination:
186187
frame->prev_instr=dest-1;
@@ -201,7 +202,7 @@ PyUnstable_GetExecutor(PyCodeObject *code, int offset)
201202
}
202203
i+=_PyInstruction_GetLength(code,i);
203204
}
204-
PyErr_SetString(PyExc_ValueError,"no executor at given offset");
205+
PyErr_SetString(PyExc_ValueError,"no executor at givenbyteoffset");
205206
returnNULL;
206207
}
207208

@@ -399,22 +400,28 @@ translate_bytecode_to_trace(
399400
trace_length++;
400401

401402
DPRINTF(4,
402-
"Optimizing %s (%s:%d) at offset %ld\n",
403+
"Optimizing %s (%s:%d) atbyteoffset %ld\n",
403404
PyUnicode_AsUTF8(code->co_qualname),
404405
PyUnicode_AsUTF8(code->co_filename),
405406
code->co_firstlineno,
406-
(long)(instr- (_Py_CODEUNIT*)code->co_code_adaptive));
407+
2*(long)(initial_instr- (_Py_CODEUNIT*)code->co_code_adaptive));
407408

408409
for (;;) {
409410
ADD_TO_TRACE(SAVE_IP, (int)(instr- (_Py_CODEUNIT*)code->co_code_adaptive));
410411
intopcode=instr->op.code;
411412
uint64_toperand=instr->op.arg;
412-
// TODO: EXTENDED_ARG handling
413+
intextras=0;
414+
while (opcode==EXTENDED_ARG) {
415+
instr++;
416+
extras+=1;
417+
opcode=instr->op.code;
418+
operand= (operand <<8) |instr->op.arg;
419+
}
413420
if (opcode==ENTER_EXECUTOR) {
414421
_PyExecutorObject*executor= (_PyExecutorObject*)code->co_executors->executors[operand&255];
415422
opcode=executor->vm_data.opcode;
416423
DPRINTF(2," * ENTER_EXECUTOR -> %s\n",_PyOpcode_OpName[opcode]);
417-
operand=executor->vm_data.oparg;// TODO: EXTENDED_ARG handling
424+
operand=(operand&0xffffff00) |executor->vm_data.oparg;
418425
}
419426
switch (opcode) {
420427
caseLOAD_FAST_LOAD_FAST:
@@ -474,6 +481,15 @@ translate_bytecode_to_trace(
474481
intoffset=expansion->uops[i].offset;
475482
switch (expansion->uops[i].size) {
476483
case0:
484+
if (extras&&OPCODE_HAS_JUMP(opcode)) {
485+
if (opcode==JUMP_BACKWARD_NO_INTERRUPT) {
486+
operand-=extras;
487+
}
488+
else {
489+
assert(opcode!=JUMP_BACKWARD);
490+
operand+=extras;
491+
}
492+
}
477493
break;
478494
case1:
479495
operand=read_u16(&instr[offset].cache);
@@ -512,21 +528,21 @@ translate_bytecode_to_trace(
512528
if (trace_length>3) {
513529
ADD_TO_TRACE(EXIT_TRACE,0);
514530
DPRINTF(1,
515-
"Created a trace for %s (%s:%d) at offset %ld -- length %d\n",
531+
"Created a trace for %s (%s:%d) atbyteoffset %ld -- length %d\n",
516532
PyUnicode_AsUTF8(code->co_qualname),
517533
PyUnicode_AsUTF8(code->co_filename),
518534
code->co_firstlineno,
519-
(long)(instr- (_Py_CODEUNIT*)code->co_code_adaptive),
535+
2*(long)(initial_instr- (_Py_CODEUNIT*)code->co_code_adaptive),
520536
trace_length);
521537
returntrace_length;
522538
}
523539
else {
524540
DPRINTF(4,
525-
"No trace for %s (%s:%d) at offset %ld\n",
541+
"No trace for %s (%s:%d) atbyteoffset %ld\n",
526542
PyUnicode_AsUTF8(code->co_qualname),
527543
PyUnicode_AsUTF8(code->co_filename),
528544
code->co_firstlineno,
529-
(long)(instr- (_Py_CODEUNIT*)code->co_code_adaptive));
545+
2*(long)(initial_instr- (_Py_CODEUNIT*)code->co_code_adaptive));
530546
}
531547
return0;
532548

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp