blob: 5ebf3d1eb4190b744e908a79114f036c132017f6 [file] [log] [blame]
Nicolas Geoffray9437b782015-03-25 10:08:51 +00001/*
2* Copyright (C) 2015 The Android Open Source Project
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*/
16
17// Add a class that will be the first entry in the dex cache, to
18// avoid having the OtherDex and Main classes share the same cache index.
19class AAA {
20}
21
22public class Main {
23
24 // CHECK-START: void Main.inlineEmptyMethod() inliner (before)
David Brazdilc2c48ff2015-05-15 14:24:31 +010025 // CHECK-DAG: <<Invoke:v\d+>> InvokeStaticOrDirect
Nicolas Geoffray9437b782015-03-25 10:08:51 +000026 // CHECK-DAG: ReturnVoid
27
28 // CHECK-START: void Main.inlineEmptyMethod() inliner (after)
29 // CHECK-NOT: InvokeStaticOrDirect
30
31 public static void inlineEmptyMethod() {
32 OtherDex.emptyMethod();
33 }
34
35 // CHECK-START: int Main.inlineReturnIntMethod() inliner (before)
David Brazdilc2c48ff2015-05-15 14:24:31 +010036 // CHECK-DAG: <<Invoke:i\d+>> InvokeStaticOrDirect
37 // CHECK-DAG: Return [ <<Invoke>> ]
Nicolas Geoffray9437b782015-03-25 10:08:51 +000038
39 // CHECK-START: int Main.inlineReturnIntMethod() inliner (after)
40 // CHECK-NOT: InvokeStaticOrDirect
41
42 // CHECK-START: int Main.inlineReturnIntMethod() inliner (after)
David Brazdilc2c48ff2015-05-15 14:24:31 +010043 // CHECK-DAG: <<Const38:i\d+>> IntConstant 38
44 // CHECK-DAG: Return [ <<Const38>> ]
Nicolas Geoffray9437b782015-03-25 10:08:51 +000045
46 public static int inlineReturnIntMethod() {
47 return OtherDex.returnIntMethod();
48 }
49
50 // CHECK-START: int Main.dontInlineOtherDexStatic() inliner (before)
David Brazdilc2c48ff2015-05-15 14:24:31 +010051 // CHECK-DAG: <<Invoke:i\d+>> InvokeStaticOrDirect
52 // CHECK-DAG: Return [ <<Invoke>> ]
Nicolas Geoffray9437b782015-03-25 10:08:51 +000053
54 // CHECK-START: int Main.dontInlineOtherDexStatic() inliner (after)
David Brazdilc2c48ff2015-05-15 14:24:31 +010055 // CHECK-DAG: <<Invoke:i\d+>> InvokeStaticOrDirect
56 // CHECK-DAG: Return [ <<Invoke>> ]
Nicolas Geoffray9437b782015-03-25 10:08:51 +000057
58 public static int dontInlineOtherDexStatic() {
59 return OtherDex.returnOtherDexStatic();
60 }
61
62 // CHECK-START: int Main.inlineMainStatic() inliner (before)
David Brazdilc2c48ff2015-05-15 14:24:31 +010063 // CHECK-DAG: <<Invoke:i\d+>> InvokeStaticOrDirect
64 // CHECK-DAG: Return [ <<Invoke>> ]
Nicolas Geoffray9437b782015-03-25 10:08:51 +000065
66 // CHECK-START: int Main.inlineMainStatic() inliner (after)
67 // CHECK-NOT: InvokeStaticOrDirect
68
69 // CHECK-START: int Main.inlineMainStatic() inliner (after)
David Brazdilc2c48ff2015-05-15 14:24:31 +010070 // CHECK-DAG: <<Static:i\d+>> StaticFieldGet
71 // CHECK-DAG: Return [ <<Static>> ]
Nicolas Geoffray9437b782015-03-25 10:08:51 +000072
73 public static int inlineMainStatic() {
74 return OtherDex.returnMainStatic();
75 }
76
77 // CHECK-START: int Main.dontInlineRecursiveCall() inliner (before)
David Brazdilc2c48ff2015-05-15 14:24:31 +010078 // CHECK-DAG: <<Invoke:i\d+>> InvokeStaticOrDirect
79 // CHECK-DAG: Return [ <<Invoke>> ]
Nicolas Geoffray9437b782015-03-25 10:08:51 +000080
81 // CHECK-START: int Main.dontInlineRecursiveCall() inliner (after)
David Brazdilc2c48ff2015-05-15 14:24:31 +010082 // CHECK-DAG: <<Invoke:i\d+>> InvokeStaticOrDirect
83 // CHECK-DAG: Return [ <<Invoke>> ]
Nicolas Geoffray9437b782015-03-25 10:08:51 +000084
85 public static int dontInlineRecursiveCall() {
86 return OtherDex.recursiveCall();
87 }
88
89 // CHECK-START: java.lang.String Main.dontInlineReturnString() inliner (before)
David Brazdilc2c48ff2015-05-15 14:24:31 +010090 // CHECK-DAG: <<Invoke:l\d+>> InvokeStaticOrDirect
91 // CHECK-DAG: Return [ <<Invoke>> ]
Nicolas Geoffray9437b782015-03-25 10:08:51 +000092
93 // CHECK-START: java.lang.String Main.dontInlineReturnString() inliner (after)
David Brazdilc2c48ff2015-05-15 14:24:31 +010094 // CHECK-DAG: <<Invoke:l\d+>> InvokeStaticOrDirect
95 // CHECK-DAG: Return [ <<Invoke>> ]
Nicolas Geoffray9437b782015-03-25 10:08:51 +000096
97 public static String dontInlineReturnString() {
98 return OtherDex.returnString();
99 }
100
101 // CHECK-START: java.lang.Class Main.dontInlineOtherDexClass() inliner (before)
David Brazdilc2c48ff2015-05-15 14:24:31 +0100102 // CHECK-DAG: <<Invoke:l\d+>> InvokeStaticOrDirect
103 // CHECK-DAG: Return [ <<Invoke>> ]
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000104
105 // CHECK-START: java.lang.Class Main.dontInlineOtherDexClass() inliner (after)
David Brazdilc2c48ff2015-05-15 14:24:31 +0100106 // CHECK-DAG: <<Invoke:l\d+>> InvokeStaticOrDirect
107 // CHECK-DAG: Return [ <<Invoke>> ]
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000108
109 public static Class dontInlineOtherDexClass() {
110 return OtherDex.returnOtherDexClass();
111 }
112
113 // CHECK-START: java.lang.Class Main.inlineMainClass() inliner (before)
David Brazdilc2c48ff2015-05-15 14:24:31 +0100114 // CHECK-DAG: <<Invoke:l\d+>> InvokeStaticOrDirect
115 // CHECK-DAG: Return [ <<Invoke>> ]
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000116
117 // CHECK-START: java.lang.Class Main.inlineMainClass() inliner (after)
118 // CHECK-NOT: InvokeStaticOrDirect
119
120 // CHECK-START: java.lang.Class Main.inlineMainClass() inliner (after)
David Brazdilc2c48ff2015-05-15 14:24:31 +0100121 // CHECK-DAG: <<Class:l\d+>> LoadClass
122 // CHECK-DAG: Return [ <<Class>> ]
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000123
124 public static Class inlineMainClass() {
125 return OtherDex.returnMainClass();
126 }
127
128 // CHECK-START: java.lang.Class Main.dontInlineOtherDexClassStaticCall() inliner (before)
David Brazdilc2c48ff2015-05-15 14:24:31 +0100129 // CHECK-DAG: <<Invoke:l\d+>> InvokeStaticOrDirect
130 // CHECK-DAG: Return [ <<Invoke>> ]
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000131
132 // CHECK-START: java.lang.Class Main.dontInlineOtherDexClassStaticCall() inliner (after)
David Brazdilc2c48ff2015-05-15 14:24:31 +0100133 // CHECK-DAG: <<Invoke:l\d+>> InvokeStaticOrDirect
134 // CHECK-DAG: Return [ <<Invoke>> ]
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000135
136 public static Class dontInlineOtherDexClassStaticCall() {
137 return OtherDex.returnOtherDexClassStaticCall();
138 }
139
140 // CHECK-START: java.lang.Class Main.inlineOtherDexCallingMain() inliner (before)
David Brazdilc2c48ff2015-05-15 14:24:31 +0100141 // CHECK-DAG: <<Invoke:l\d+>> InvokeStaticOrDirect
142 // CHECK-DAG: Return [ <<Invoke>> ]
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000143
144 // CHECK-START: java.lang.Class Main.inlineOtherDexCallingMain() inliner (after)
145 // CHECK-NOT: InvokeStaticOrDirect
146
147 // CHECK-START: java.lang.Class Main.inlineOtherDexCallingMain() inliner (after)
David Brazdilc2c48ff2015-05-15 14:24:31 +0100148 // CHECK-DAG: <<Class:l\d+>> LoadClass
149 // CHECK-DAG: Return [ <<Class>> ]
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000150
151 public static Class inlineOtherDexCallingMain() {
152 return OtherDex.returnOtherDexCallingMain();
153 }
154
155 public static Class getOtherClass() {
156 return Main.class;
157 }
158
159 public static void main(String[] args) {
160 inlineEmptyMethod();
161 if (inlineReturnIntMethod() != 38) {
162 throw new Error("Expected 38");
163 }
164
165 if (dontInlineOtherDexStatic() != 1) {
166 throw new Error("Expected 1");
167 }
168
169 if (inlineMainStatic() != 42) {
170 throw new Error("Expected 42");
171 }
172
173 if (dontInlineReturnString() != "OtherDex") {
174 throw new Error("Expected OtherDex");
175 }
176
177 if (dontInlineOtherDexClass() != OtherDex.class) {
178 throw new Error("Expected " + OtherDex.class);
179 }
180
181 if (dontInlineOtherDexClassStaticCall() != OtherDex.class) {
182 throw new Error("Expected " + OtherDex.class);
183 }
184
185 if (inlineMainClass() != Main.class) {
186 throw new Error("Expected " + Main.class);
187 }
188
189 if (inlineOtherDexCallingMain() != Main.class) {
190 throw new Error("Expected " + Main.class);
191 }
192 }
193
194 // Reference the AAA class to ensure it is in the dex cache.
195 public static Class<?> cls = AAA.class;
196
197 // Add a field that will be the first entry in the dex cache, to
198 // avoid having the OtherDex.myStatic and Main.myStatic fields
199 // share the same cache index.
200 public static int aaa = 32;
201 public static int myStatic = 42;
202}