Re: Understanding SNAP

  • From: Raj <rajlistuser@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Mon, 25 Sep 2017 13:35:42 +0530

On Sun, Sep 24, 2017 at 11:26 PM, Peter Cawley <corsix@xxxxxxxxxx> wrote:

Thank you for the detailed explanation, I have some followup questions
while I  am trying to digest this :)

Before I start, Some clarification about the numbers used in IR and Bytecode:

1.  IR instruction number: First column of IR, increments continuously
by one per every instruction.

2. Argument to SLOAD: start at #0 (base frame, or call frame
metadata), #1: first slot in the first frame, starting at function
argument. In luajit wiki, it is defined as "(register 0 in the
bytecode)"

What is the register 0 mentioned here?

3. Instruction operands of IR. eg:  in "0003 xmm7   + num MUL    0002
-3" what does 0002 denote? Is it a reference to a memory
location/register etc, or to an instruction?

On Sun, Sep 24, 2017 at 2:36 PM, Raj <rajlistuser@xxxxxxxxx> wrote:
My attempt is to trace backwards and to find
out what causes the snapshot to be filled up.

Lots of entries in a snapshot just means that there are lots of local
variables (*) whose values have changed since the start of the trace.

Understood.

"x" in this case is local variable number #0 - you can see this
from e.g. cross-referencing "x = x * -3" with "0006  MULVN    0   0
1  ; -3" - the first 0 is the destination slot (x), and the second 0
is the source slot (also x).

Ok. One point I am missing here is the correspondence between 0 in
"0006  MULVN    0   0   1  ; -3" and 0002 in 0003 xmm7   + num MUL
0002  -3" It probably reflects my confusion about the operands of IR
instruction.

SNAP #3 has fewer entries than SNAP #2, as it exits to after the loop
has finished (**), and and therefore all the for-loop variables have
dropped out of scope. SNAP #1 has fewer entries for the same reason:
it exits to after the loop has finished, rather than exiting into the
body of the loop.

SNAP #3 exits after the loop has finished, but did you mean SNAP #1
exits before the loop has finished?

(**) You can't actually tell where a snapshot exits to based on jdump
output - I do wish such information was included in the output.

Can we figure that out by waking backwards from the last trace and
looking at the trace start line?

I'm not sure whether that answers your question, but to be honest, I'm
not quite sure what exactly you were questioning.

Yes, you did answer my question. what I missed what that the for loop
can create three local variables simultaneously and thus two slots are
modified by same instruction.

[P] #define IRSLOAD_PARENT 0x01 /* Coalesce with parent trace. */
[I] #define IRSLOAD_INHERIT 0x20 /* Inherited by exits/side traces. */

SLOADs in traces leading to register coalescing too complex trace has
flag PI. What does it mean by "Coalesce with parent trace"

Also In the original IR

---- TRACE 1 start stdin:1
0006  MULVN    0   0   1  ; -3
0007  FORL     1 => 0006
---- TRACE 1 IR
....              SNAP   #0   [ ---- ]
0001 rbp      int SLOAD  #2    CI
0002 xmm7  >  num SLOAD  #1    T

The SNAP has just one entry, while SLOAD loads #2 and #1. How is this possible?

I am sure I have asked too many questions, its just that this part of
luajit is not very documented and for any one having similar question
in future this thread will be a good reference.

Thanks again for your time and excellent answers.

Raj

Other related posts: