-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbytecode.txt
More file actions
159 lines (142 loc) · 3.53 KB
/
bytecode.txt
File metadata and controls
159 lines (142 loc) · 3.53 KB
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
Part2: constant variable folding
methodOne();
0: bipush 42
2: istore_1
3: bipush 8
5: istore_2
6: bipush 8
8: istore_3
9: bipush 8
11: istore 4
13: bipush 8
15: istore 5
17: bipush 8
19: istore 6
21: iload_1
22: sipush 764
25: iadd
26: iconst_3
27: imul
28: istore 7
30: iload 7
32: sipush 1234
35: iadd
36: iload_1
37: isub
38: ireturn
methodTwo();
0: dconst_0
1: dstore_1
2: iconst_1
3: istore_3
4: dload_1
5: iload_3
6: i2d
7: dadd
8: dreturn
methodThree();
0: sipush 12345
3: istore_1
4: ldc #2 // int 54321
6: istore_2
7: iload_1
8: iload_2
9: if_icmple 16
12: iconst_1
13: goto 17
16: iconst_0
17: return
optimized:
methodOne();
0: ldc #24 // int 3610
2: ireturn
methodTwo();
0: ldc2_w #27 // double 1.0d
3: dreturn
methodThree();
0: sipush 12345
3: ldc #2 // int 54321
5: if_icmple 12
8: iconst_1
9: goto 13
12: iconst_0
13: ireturn
our constant variable folding:
methodOne();
0: bipush 62
2: istore_1
3: iload_1
4: sipush 764
7: iadd
8: iconst_3
9: imul
10: istore_2
11: iload_2
12: sipush 1234
15: iadd
16: iload_1
17: isub
18: ireturn
methodTwo();
0: ldc2_w #2 // double 0.67d
3: dstore_1
4: iconst_1
5: istore_3
6: dload_1
7: iload_3
8: i2d
9: dadd
10: dreturn
methodThree();
0: sipush 12345
3: istore_1
4: ldc #4 // int 54321
6: istore_2
7: iload_1
8: iload_2
9: if_icmple 16
12: iconst_1
13: goto 17
16: iconst_0
17: ireturn
methodFour();
0: ldc2_w #5 // long 4835783423l
3: lstore_1
4: ldc2_w #7 // long 400000l
7: lstore_3
8: lload_1
9: lload_3
10: ladd
11: lstore 5
13: lload_1
14: lload_3
15: lcmp
16: ifle 23
19: iconst_1
20: goto 24
23: iconst_0
24: ireturn
//part2里面的methods和之间的关联
void optimizeMethod(); => safeInstructionDelete
=> handleStoreInstructions
=> getLastStaskPush
Number getLastStackPush(); => safeInstructionDelete
=> binaryOps
=> convertNumber
=> stackChangingOp
Number[] binaryOps(); => getLastStackPush
Boolean handleStoreInstuctions();
Number convertNumber();
Boolean stackChangingOp();
Void safeInstructionDelete();
storeInstruction
NOP
ArithmeticInstruction
IINC
Load and store (e.g. aload_0, istore)
Arithmetic and logic (e.g. ladd, fcmpl)
Type conversion (e.g. i2b, d2i)
Object creation and manipulation (new, putfield)
Operand stack management (e.g. swap, dup2)
Control transfer (e.g. ifeq, goto)
Method invocation and return (e.g. invokespecial, areturn)