I wrote a simple analysis to try this out, in
extra/chord/analyses/sandbox/LocalVarAnalysis.java. Compile it and run it as
follows on an example:
ant -Dchord.work.dir=../test/bench/elevator
-Dchord.run.analyses=localvar-java run
Then see the localNumbering map, stackNumbering map, and
jq_LocalVarTableEntry array printed to log.txt. The former two are in
joeq.Compiler.Quad.RegisterFactory, and come from joeq's intermediate
representation, while the latter is in joeq.Class.jq_Method, and comes
from bytecode (assuming you compiled the .java files with debug info
to retain the local variable table attribute in the .class files). I
suspect there is a mapping between indices in the localNumbering map
and jq_LocalVarTableEntry[] that you should be able to use.
Here is what is printed to log.txt when I run the above command:
local: // localNumbering map
[java.lang.Object, 4]=R7
[long, 4]=R8
[java.lang.Object, 0]=R0
[long, 2]=R6
[java.lang.Object, 1]=R4
table: // jq_LocalVarTableEntry[]
entry: (startPC=0,length=71,nd=args [Ljava/lang/String;,index=0)
entry: (startPC=11,length=60,nd=building Lelevator/Elevator;,index=1)
entry: (startPC=22,length=49,nd=start J,index=2)
entry: (startPC=42,length=29,nd=end J,index=4)
To see the quad code, run:
ant -Dcp=../test/bench/elevator/classes -Dclass=elevator.Elevator quadcode
Here is what I get:
Control flow graph for main:([Ljava/lang/String;)V@elevator.Elevator:
BB0 (ENTRY) (in: <none>, out: BB2)
BB2 (in: BB0 (ENTRY), out: BB1 (EXIT))
1 NEW T10, elevator.Elevator
2 MOVE_A T11, T10
3 NULL_CHECK T-1, R0
4 BOUNDS_CHECK R0, IConst: 0, T-1
5 ALOAD_A T12, R0, IConst: 0, T-1
7 NULL_CHECK T-1, T11
6 INVOKESTATIC_V
<init>:(Ljava/lang/String;)V@elevator.Elevator, (T11, T12)
8 MOVE_A R4, T10
9 NEW T13, java.util.Date
10 MOVE_A T14, T13
12 NULL_CHECK T-1, T14
11 INVOKESTATIC_V <init>:()V@java.util.Date, (T14)
14 NULL_CHECK T-1, T13
13 INVOKEVIRTUAL_L T15, getTime:()J@java.util.Date, (T13)
15 MOVE_L R6, T15
17 NULL_CHECK T-1, R4
16 INVOKESTATIC_V begin:()V@elevator.Elevator, (R4)
19 NULL_CHECK T-1, R4
18 INVOKESTATIC_V
waitForLiftsToFinishOperation:()V@elevator.Elevator, (R4)
20 NEW T16, java.util.Date
21 MOVE_A T17, T16
23 NULL_CHECK T-1, T17
22 INVOKESTATIC_V <init>:()V@java.util.Date, (T17)
25 NULL_CHECK T-1, T16
24 INVOKEVIRTUAL_L T18, getTime:()J@java.util.Date, (T16)
26 MOVE_L R8, T18
27 GETSTATIC_A T19, .out
28 NEW T20, java.lang.StringBuilder
29 MOVE_A T21, T20
31 NULL_CHECK T-1, T21
30 INVOKESTATIC_V <init>:()V@java.lang.StringBuilder, (T21)
33 MOVE_A T22, AConst: "Time taken in ms : "
34 NULL_CHECK T-1, T20
32 INVOKEVIRTUAL_A T23,
append:(Ljava/lang/String;)Ljava/lang/StringBuilder;@java.lang.StringBuilder,
(T20, T22)
35 SUB_L T9, R8, R6
37 NULL_CHECK T-1, T23
36 INVOKEVIRTUAL_A T24,
append:(J)Ljava/lang/StringBuilder;@java.lang.StringBuilder, (T23,
T9)
39 NULL_CHECK T-1, T24
38 INVOKEVIRTUAL_A T25,
toString:()Ljava/lang/String;@java.lang.StringBuilder, (T24)
41 NULL_CHECK T-1, T19
40 INVOKEVIRTUAL_V
println:(Ljava/lang/String;)V@java.io.PrintStream, (T19, T25)
42 RETURN_V
BB1 (EXIT) (in: BB2, out: <none>)
Exception handlers: []
Register factory: Registers: 26
Look at the names/types of variable names in the java source code
(test/bench/elevator/src/elevator/Elevator.java) and you will see the
mapping:
[java.lang.Object, 0]=R0 corresponds to entry
(startPC=0,length=71,nd=args [Ljava/lang/String;,index=0)
[java.lang.Object, 1]=R4 corresponds to entry
(startPC=11,length=60,nd=building Lelevator/Elevator;,index=1)
[long, 4]=R8 corresponds to entry (startPC=42,length=29,nd=end J,index=4)
[long, 2]=R6 corresponds to entry (startPC=22,length=49,nd=start J,index=2)
In summary, match the integer-valued field in the domain of the
localNumberingMap (values 0,1,4,2 above) to the 'index' field in
jq_LocalVarTableEntry[]. I haven't tried this on other examples, but
I suspect this is correct. Let me know what you find.
Note: I tried this with SSA on (chord.ssa=true); this is default. I
haven't tried to see what happens if you switch SSA off (don't bother
unless you have explicitly set chord.ssa=false).
Original issue reported on code.google.com by mayur.naik on 29 Sep 2010 at 3:04
Original issue reported on code.google.com by
mayur.naik
on 29 Sep 2010 at 3:04