1 /*
2  * Copyright (C) 2016 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 package android.compilation.cts;
18 
19 import android.app.Activity;
20 import android.os.AsyncTask;
21 
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.List;
25 import java.util.Random;
26 
27 /**
28  * A simple activity which can be subjected to (dex to native) compilation.
29  *
30  * If you change this code, you need to regenerate APK and profile using the
31  * the new code - see instructions in {@code assets/README.txt}.
32  */
33 public class CompilationTargetActivity extends Activity {
34 
35     private AsyncTask<Integer, String, Void> mTask;
36 
37     @Override
onResume()38     protected void onResume() {
39         super.onResume();
40         setTitle("Starting...");
41         mTask = new AsyncTask<Integer, String, Void>() {
42             @Override
43             protected Void doInBackground(Integer... params) {
44                 int numValues = params[0];
45                 int numIter = params[1];
46                 for (int i = 0; i < numIter; i++) {
47                     if (Thread.interrupted()) {
48                         break;
49                     }
50                     publishProgress("Step " + (i+1) + " of " + numIter);
51                     List<Integer> values = makeValues(numValues);
52                     Collections.shuffle(values);
53                     Collections.sort(values);
54                 }
55                 return null;
56             }
57 
58             @Override
59             protected void onProgressUpdate(String... values) {
60                 setTitle(values[0]);
61             }
62 
63             @Override
64             protected void onPostExecute(Void aVoid) {
65                 setTitle("Done");
66             }
67         };
68         mTask.execute(1024, 100 * 1000);
69     }
70 
71     @Override
onPause()72     protected void onPause() {
73         mTask.cancel(/* mayInterruptIfRunning */ true);
74         mTask = null;
75         super.onPause();
76     }
77 
makeValues(int numValues)78     private List<Integer> makeValues(int numValues) {
79         List<Integer> result = new ArrayList<>();
80         Random random = new Random();
81         for (int i = 0; i < numValues; i++) {
82             int v = dispatch(random.nextInt());
83             result.add(v);
84         }
85         return result;
86     }
87 
88     /**
89      * Dispatches to a bunch of simple methods because JIT profiles are only generated for
90      * apps with enough methods (10, as of May 2016).
91      */
dispatch(int i)92     private int dispatch(int i) {
93         int v = Math.abs(i % 100);
94         switch (v) {
95             case 0: return m0();
96             case 1: return m1();
97             case 2: return m2();
98             case 3: return m3();
99             case 4: return m4();
100             case 5: return m5();
101             case 6: return m6();
102             case 7: return m7();
103             case 8: return m8();
104             case 9: return m9();
105             case 10: return m10();
106             case 11: return m11();
107             case 12: return m12();
108             case 13: return m13();
109             case 14: return m14();
110             case 15: return m15();
111             case 16: return m16();
112             case 17: return m17();
113             case 18: return m18();
114             case 19: return m19();
115             case 20: return m20();
116             case 21: return m21();
117             case 22: return m22();
118             case 23: return m23();
119             case 24: return m24();
120             case 25: return m25();
121             case 26: return m26();
122             case 27: return m27();
123             case 28: return m28();
124             case 29: return m29();
125             case 30: return m30();
126             case 31: return m31();
127             case 32: return m32();
128             case 33: return m33();
129             case 34: return m34();
130             case 35: return m35();
131             case 36: return m36();
132             case 37: return m37();
133             case 38: return m38();
134             case 39: return m39();
135             case 40: return m40();
136             case 41: return m41();
137             case 42: return m42();
138             case 43: return m43();
139             case 44: return m44();
140             case 45: return m45();
141             case 46: return m46();
142             case 47: return m47();
143             case 48: return m48();
144             case 49: return m49();
145             case 50: return m50();
146             case 51: return m51();
147             case 52: return m52();
148             case 53: return m53();
149             case 54: return m54();
150             case 55: return m55();
151             case 56: return m56();
152             case 57: return m57();
153             case 58: return m58();
154             case 59: return m59();
155             case 60: return m60();
156             case 61: return m61();
157             case 62: return m62();
158             case 63: return m63();
159             case 64: return m64();
160             case 65: return m65();
161             case 66: return m66();
162             case 67: return m67();
163             case 68: return m68();
164             case 69: return m69();
165             case 70: return m70();
166             case 71: return m71();
167             case 72: return m72();
168             case 73: return m73();
169             case 74: return m74();
170             case 75: return m75();
171             case 76: return m76();
172             case 77: return m77();
173             case 78: return m78();
174             case 79: return m79();
175             case 80: return m80();
176             case 81: return m81();
177             case 82: return m82();
178             case 83: return m83();
179             case 84: return m84();
180             case 85: return m85();
181             case 86: return m86();
182             case 87: return m87();
183             case 88: return m88();
184             case 89: return m89();
185             case 90: return m90();
186             case 91: return m91();
187             case 92: return m92();
188             case 93: return m93();
189             case 94: return m94();
190             case 95: return m95();
191             case 96: return m96();
192             case 97: return m97();
193             case 98: return m98();
194             case 99: return m99();
195             case 100: return m100();
196             case 101: return m101();
197             case 102: return m102();
198             case 103: return m103();
199             case 104: return m104();
200             case 105: return m105();
201             case 106: return m106();
202             case 107: return m107();
203             case 108: return m108();
204             case 109: return m109();
205             case 110: return m110();
206             case 111: return m111();
207             case 112: return m112();
208             case 113: return m113();
209             case 114: return m114();
210             case 115: return m115();
211             case 116: return m116();
212             case 117: return m117();
213             case 118: return m118();
214             case 119: return m119();
215             case 120: return m120();
216             case 121: return m121();
217             case 122: return m122();
218             case 123: return m123();
219             case 124: return m124();
220             case 125: return m125();
221             case 126: return m126();
222             case 127: return m127();
223             case 128: return m128();
224             case 129: return m129();
225             case 130: return m130();
226             case 131: return m131();
227             case 132: return m132();
228             case 133: return m133();
229             case 134: return m134();
230             case 135: return m135();
231             case 136: return m136();
232             case 137: return m137();
233             case 138: return m138();
234             case 139: return m139();
235             case 140: return m140();
236             case 141: return m141();
237             case 142: return m142();
238             case 143: return m143();
239             case 144: return m144();
240             case 145: return m145();
241             case 146: return m146();
242             case 147: return m147();
243             case 148: return m148();
244             case 149: return m149();
245             case 150: return m150();
246             case 151: return m151();
247             case 152: return m152();
248             case 153: return m153();
249             case 154: return m154();
250             case 155: return m155();
251             case 156: return m156();
252             case 157: return m157();
253             case 158: return m158();
254             case 159: return m159();
255             case 160: return m160();
256             case 161: return m161();
257             case 162: return m162();
258             case 163: return m163();
259             case 164: return m164();
260             case 165: return m165();
261             case 166: return m166();
262             case 167: return m167();
263             case 168: return m168();
264             case 169: return m169();
265             case 170: return m170();
266             case 171: return m171();
267             case 172: return m172();
268             case 173: return m173();
269             case 174: return m174();
270             case 175: return m175();
271             case 176: return m176();
272             case 177: return m177();
273             case 178: return m178();
274             case 179: return m179();
275             case 180: return m180();
276             case 181: return m181();
277             case 182: return m182();
278             case 183: return m183();
279             case 184: return m184();
280             case 185: return m185();
281             case 186: return m186();
282             case 187: return m187();
283             case 188: return m188();
284             case 189: return m189();
285             case 190: return m190();
286             case 191: return m191();
287             case 192: return m192();
288             case 193: return m193();
289             case 194: return m194();
290             case 195: return m195();
291             case 196: return m196();
292             case 197: return m197();
293             case 198: return m198();
294             case 199: return m199();
295             default: throw new AssertionError(v + " out of bounds");
296         }
297     }
298 
m0()299     public int m0() { return new Random(0).nextInt(); }
m1()300     public int m1() { return new Random(1).nextInt(); }
m2()301     public int m2() { return new Random(2).nextInt(); }
m3()302     public int m3() { return new Random(3).nextInt(); }
m4()303     public int m4() { return new Random(4).nextInt(); }
m5()304     public int m5() { return new Random(5).nextInt(); }
m6()305     public int m6() { return new Random(6).nextInt(); }
m7()306     public int m7() { return new Random(7).nextInt(); }
m8()307     public int m8() { return new Random(8).nextInt(); }
m9()308     public int m9() { return new Random(9).nextInt(); }
m10()309     public int m10() { return new Random(10).nextInt(); }
m11()310     public int m11() { return new Random(11).nextInt(); }
m12()311     public int m12() { return new Random(12).nextInt(); }
m13()312     public int m13() { return new Random(13).nextInt(); }
m14()313     public int m14() { return new Random(14).nextInt(); }
m15()314     public int m15() { return new Random(15).nextInt(); }
m16()315     public int m16() { return new Random(16).nextInt(); }
m17()316     public int m17() { return new Random(17).nextInt(); }
m18()317     public int m18() { return new Random(18).nextInt(); }
m19()318     public int m19() { return new Random(19).nextInt(); }
m20()319     public int m20() { return new Random(20).nextInt(); }
m21()320     public int m21() { return new Random(21).nextInt(); }
m22()321     public int m22() { return new Random(22).nextInt(); }
m23()322     public int m23() { return new Random(23).nextInt(); }
m24()323     public int m24() { return new Random(24).nextInt(); }
m25()324     public int m25() { return new Random(25).nextInt(); }
m26()325     public int m26() { return new Random(26).nextInt(); }
m27()326     public int m27() { return new Random(27).nextInt(); }
m28()327     public int m28() { return new Random(28).nextInt(); }
m29()328     public int m29() { return new Random(29).nextInt(); }
m30()329     public int m30() { return new Random(30).nextInt(); }
m31()330     public int m31() { return new Random(31).nextInt(); }
m32()331     public int m32() { return new Random(32).nextInt(); }
m33()332     public int m33() { return new Random(33).nextInt(); }
m34()333     public int m34() { return new Random(34).nextInt(); }
m35()334     public int m35() { return new Random(35).nextInt(); }
m36()335     public int m36() { return new Random(36).nextInt(); }
m37()336     public int m37() { return new Random(37).nextInt(); }
m38()337     public int m38() { return new Random(38).nextInt(); }
m39()338     public int m39() { return new Random(39).nextInt(); }
m40()339     public int m40() { return new Random(40).nextInt(); }
m41()340     public int m41() { return new Random(41).nextInt(); }
m42()341     public int m42() { return new Random(42).nextInt(); }
m43()342     public int m43() { return new Random(43).nextInt(); }
m44()343     public int m44() { return new Random(44).nextInt(); }
m45()344     public int m45() { return new Random(45).nextInt(); }
m46()345     public int m46() { return new Random(46).nextInt(); }
m47()346     public int m47() { return new Random(47).nextInt(); }
m48()347     public int m48() { return new Random(48).nextInt(); }
m49()348     public int m49() { return new Random(49).nextInt(); }
m50()349     public int m50() { return new Random(50).nextInt(); }
m51()350     public int m51() { return new Random(51).nextInt(); }
m52()351     public int m52() { return new Random(52).nextInt(); }
m53()352     public int m53() { return new Random(53).nextInt(); }
m54()353     public int m54() { return new Random(54).nextInt(); }
m55()354     public int m55() { return new Random(55).nextInt(); }
m56()355     public int m56() { return new Random(56).nextInt(); }
m57()356     public int m57() { return new Random(57).nextInt(); }
m58()357     public int m58() { return new Random(58).nextInt(); }
m59()358     public int m59() { return new Random(59).nextInt(); }
m60()359     public int m60() { return new Random(60).nextInt(); }
m61()360     public int m61() { return new Random(61).nextInt(); }
m62()361     public int m62() { return new Random(62).nextInt(); }
m63()362     public int m63() { return new Random(63).nextInt(); }
m64()363     public int m64() { return new Random(64).nextInt(); }
m65()364     public int m65() { return new Random(65).nextInt(); }
m66()365     public int m66() { return new Random(66).nextInt(); }
m67()366     public int m67() { return new Random(67).nextInt(); }
m68()367     public int m68() { return new Random(68).nextInt(); }
m69()368     public int m69() { return new Random(69).nextInt(); }
m70()369     public int m70() { return new Random(70).nextInt(); }
m71()370     public int m71() { return new Random(71).nextInt(); }
m72()371     public int m72() { return new Random(72).nextInt(); }
m73()372     public int m73() { return new Random(73).nextInt(); }
m74()373     public int m74() { return new Random(74).nextInt(); }
m75()374     public int m75() { return new Random(75).nextInt(); }
m76()375     public int m76() { return new Random(76).nextInt(); }
m77()376     public int m77() { return new Random(77).nextInt(); }
m78()377     public int m78() { return new Random(78).nextInt(); }
m79()378     public int m79() { return new Random(79).nextInt(); }
m80()379     public int m80() { return new Random(80).nextInt(); }
m81()380     public int m81() { return new Random(81).nextInt(); }
m82()381     public int m82() { return new Random(82).nextInt(); }
m83()382     public int m83() { return new Random(83).nextInt(); }
m84()383     public int m84() { return new Random(84).nextInt(); }
m85()384     public int m85() { return new Random(85).nextInt(); }
m86()385     public int m86() { return new Random(86).nextInt(); }
m87()386     public int m87() { return new Random(87).nextInt(); }
m88()387     public int m88() { return new Random(88).nextInt(); }
m89()388     public int m89() { return new Random(89).nextInt(); }
m90()389     public int m90() { return new Random(90).nextInt(); }
m91()390     public int m91() { return new Random(91).nextInt(); }
m92()391     public int m92() { return new Random(92).nextInt(); }
m93()392     public int m93() { return new Random(93).nextInt(); }
m94()393     public int m94() { return new Random(94).nextInt(); }
m95()394     public int m95() { return new Random(95).nextInt(); }
m96()395     public int m96() { return new Random(96).nextInt(); }
m97()396     public int m97() { return new Random(97).nextInt(); }
m98()397     public int m98() { return new Random(98).nextInt(); }
m99()398     public int m99() { return new Random(99).nextInt(); }
m100()399     public int m100() { return new Random(100).nextInt(); }
m101()400     public int m101() { return new Random(101).nextInt(); }
m102()401     public int m102() { return new Random(102).nextInt(); }
m103()402     public int m103() { return new Random(103).nextInt(); }
m104()403     public int m104() { return new Random(104).nextInt(); }
m105()404     public int m105() { return new Random(105).nextInt(); }
m106()405     public int m106() { return new Random(106).nextInt(); }
m107()406     public int m107() { return new Random(107).nextInt(); }
m108()407     public int m108() { return new Random(108).nextInt(); }
m109()408     public int m109() { return new Random(109).nextInt(); }
m110()409     public int m110() { return new Random(110).nextInt(); }
m111()410     public int m111() { return new Random(111).nextInt(); }
m112()411     public int m112() { return new Random(112).nextInt(); }
m113()412     public int m113() { return new Random(113).nextInt(); }
m114()413     public int m114() { return new Random(114).nextInt(); }
m115()414     public int m115() { return new Random(115).nextInt(); }
m116()415     public int m116() { return new Random(116).nextInt(); }
m117()416     public int m117() { return new Random(117).nextInt(); }
m118()417     public int m118() { return new Random(118).nextInt(); }
m119()418     public int m119() { return new Random(119).nextInt(); }
m120()419     public int m120() { return new Random(120).nextInt(); }
m121()420     public int m121() { return new Random(121).nextInt(); }
m122()421     public int m122() { return new Random(122).nextInt(); }
m123()422     public int m123() { return new Random(123).nextInt(); }
m124()423     public int m124() { return new Random(124).nextInt(); }
m125()424     public int m125() { return new Random(125).nextInt(); }
m126()425     public int m126() { return new Random(126).nextInt(); }
m127()426     public int m127() { return new Random(127).nextInt(); }
m128()427     public int m128() { return new Random(128).nextInt(); }
m129()428     public int m129() { return new Random(129).nextInt(); }
m130()429     public int m130() { return new Random(130).nextInt(); }
m131()430     public int m131() { return new Random(131).nextInt(); }
m132()431     public int m132() { return new Random(132).nextInt(); }
m133()432     public int m133() { return new Random(133).nextInt(); }
m134()433     public int m134() { return new Random(134).nextInt(); }
m135()434     public int m135() { return new Random(135).nextInt(); }
m136()435     public int m136() { return new Random(136).nextInt(); }
m137()436     public int m137() { return new Random(137).nextInt(); }
m138()437     public int m138() { return new Random(138).nextInt(); }
m139()438     public int m139() { return new Random(139).nextInt(); }
m140()439     public int m140() { return new Random(140).nextInt(); }
m141()440     public int m141() { return new Random(141).nextInt(); }
m142()441     public int m142() { return new Random(142).nextInt(); }
m143()442     public int m143() { return new Random(143).nextInt(); }
m144()443     public int m144() { return new Random(144).nextInt(); }
m145()444     public int m145() { return new Random(145).nextInt(); }
m146()445     public int m146() { return new Random(146).nextInt(); }
m147()446     public int m147() { return new Random(147).nextInt(); }
m148()447     public int m148() { return new Random(148).nextInt(); }
m149()448     public int m149() { return new Random(149).nextInt(); }
m150()449     public int m150() { return new Random(150).nextInt(); }
m151()450     public int m151() { return new Random(151).nextInt(); }
m152()451     public int m152() { return new Random(152).nextInt(); }
m153()452     public int m153() { return new Random(153).nextInt(); }
m154()453     public int m154() { return new Random(154).nextInt(); }
m155()454     public int m155() { return new Random(155).nextInt(); }
m156()455     public int m156() { return new Random(156).nextInt(); }
m157()456     public int m157() { return new Random(157).nextInt(); }
m158()457     public int m158() { return new Random(158).nextInt(); }
m159()458     public int m159() { return new Random(159).nextInt(); }
m160()459     public int m160() { return new Random(160).nextInt(); }
m161()460     public int m161() { return new Random(161).nextInt(); }
m162()461     public int m162() { return new Random(162).nextInt(); }
m163()462     public int m163() { return new Random(163).nextInt(); }
m164()463     public int m164() { return new Random(164).nextInt(); }
m165()464     public int m165() { return new Random(165).nextInt(); }
m166()465     public int m166() { return new Random(166).nextInt(); }
m167()466     public int m167() { return new Random(167).nextInt(); }
m168()467     public int m168() { return new Random(168).nextInt(); }
m169()468     public int m169() { return new Random(169).nextInt(); }
m170()469     public int m170() { return new Random(170).nextInt(); }
m171()470     public int m171() { return new Random(171).nextInt(); }
m172()471     public int m172() { return new Random(172).nextInt(); }
m173()472     public int m173() { return new Random(173).nextInt(); }
m174()473     public int m174() { return new Random(174).nextInt(); }
m175()474     public int m175() { return new Random(175).nextInt(); }
m176()475     public int m176() { return new Random(176).nextInt(); }
m177()476     public int m177() { return new Random(177).nextInt(); }
m178()477     public int m178() { return new Random(178).nextInt(); }
m179()478     public int m179() { return new Random(179).nextInt(); }
m180()479     public int m180() { return new Random(180).nextInt(); }
m181()480     public int m181() { return new Random(181).nextInt(); }
m182()481     public int m182() { return new Random(182).nextInt(); }
m183()482     public int m183() { return new Random(183).nextInt(); }
m184()483     public int m184() { return new Random(184).nextInt(); }
m185()484     public int m185() { return new Random(185).nextInt(); }
m186()485     public int m186() { return new Random(186).nextInt(); }
m187()486     public int m187() { return new Random(187).nextInt(); }
m188()487     public int m188() { return new Random(188).nextInt(); }
m189()488     public int m189() { return new Random(189).nextInt(); }
m190()489     public int m190() { return new Random(190).nextInt(); }
m191()490     public int m191() { return new Random(191).nextInt(); }
m192()491     public int m192() { return new Random(192).nextInt(); }
m193()492     public int m193() { return new Random(193).nextInt(); }
m194()493     public int m194() { return new Random(194).nextInt(); }
m195()494     public int m195() { return new Random(195).nextInt(); }
m196()495     public int m196() { return new Random(196).nextInt(); }
m197()496     public int m197() { return new Random(197).nextInt(); }
m198()497     public int m198() { return new Random(198).nextInt(); }
m199()498     public int m199() { return new Random(199).nextInt(); }
499 }
500