SpecialInstructionPaddingTest.smali revision 68564258a316e41cb014f98d2777b5944bf37de3
1.class public LSpecialInstructionPaddingTest;
2.super Ljava/lang/Object;
3.source "InstructionPaddingTest.smali"
4
5.method public constructor <init>()V
6    .registers 1
7    invoke-direct {p0}, Ljava/lang/Object;-><init>()V
8    return-void
9.end method
10
11.method public test()V
12    .registers 2
13    .annotation runtime Lorg/junit/Test;
14    .end annotation
15
16    const v0, 0
17    invoke-static {}, LSpecialInstructionPaddingTest;->paddingTest()I
18    move-result v0
19
20
21
22    const/16 v1, 12
23
24    #the real test is that dalvik loaded and verified this class. This is
25    #mostly just to make sure that the method was actually called
26    invoke-static {v0, v1}, LAssert;->assertEquals(II)V
27
28    return-void
29.end method
30
31.method public static paddingTest()I
32    .registers  2
33
34    const v0, 12
35
36    packed-switch v0, :PackedSwitch
37
38:Label10
39    const v1, 10
40    return v1
41
42:Label11
43    const v1, 11
44    return v1
45
46:Label12
47    const v1, 12
48    return v1
49
50:Label13
51    const v1, 13
52    return v1
53
54    #this nop de-aligns the following packed-switch data
55    #smali should generate another nop before the packed-switch
56    #data to force alignment
57    nop
58
59:PackedSwitch
60    .packed-switch 10
61        :Label10
62        :Label11
63        :Label12
64        :Label13
65    .end packed-switch
66.end method
67
68
69
70.method public test2()V
71    .registers 2
72    .annotation runtime Lorg/junit/Test;
73    .end annotation
74
75    const v0, 0
76    invoke-static {}, LSpecialInstructionPaddingTest;->paddingTest()I
77    move-result v0
78
79
80
81    const/16 v1, 12
82
83    #the real test is that dalvik loaded and verified this class. This is
84    #mostly just to make sure that the method was actually called
85    invoke-static {v0, v1}, LAssert;->assertEquals(II)V
86
87    return-void
88.end method
89
90.method public static paddingTest()I
91    .registers  2
92
93    const v0, 12
94
95    packed-switch v0, :PackedSwitch
96
97    packed-switch v0, :PackedSwitch2
98
99:Label10
100    const v1, 10
101    return v1
102
103:Label11
104    const v1, 11
105    return v1
106
107:Label12
108    const v1, 12
109    return v1
110
111:Label13
112    const v1, 13
113    return v1
114
115:PackedSwitch
116    .packed-switch 10
117        :Label10
118        :Label11
119        :Label12
120        :Label13
121    .end packed-switch
122
123    #this tests out an issue that occurred where the prior packed switch data starts at a byte offset
124    #that is 4 byte aligned but isn't 8 byte aligned, which caused the code to report the size of the
125    #instruction to be 2 bytes more than it should be.
126    #
127    #Normally, if things are working correctly, this nop will cause the following packed-switch data
128    #to be unaligned. But with the above issue, the logic will *think* that the packed switch data
129    #is aligned, and won't output the extra nop to align it, thus causing a verification error.
130    nop
131
132:PackedSwitch2
133    .packed-switch 10
134        :Label10
135        :Label11
136        :Label12
137        :Label13
138    .end packed-switch
139
140
141.end method