1/*
2 * Copyright (C) 2007 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/*
18Initial:
19test001: 2039901us  (4079ns per call)
20test049: 3346619us  (6693ns per call)
21test099: 4687402us  (9374ns per call)
22testInst001: 1327216us  (2654ns per use)
23testInst049: 1326995us  (2653ns per use)
24testInst099: 1327735us  (2655ns per use)
25
26After refactoring cache code: 2871ns per use
27After re-refactoring cache code: 2797ns per use
28
29After de-inlining invoke-interface:
30test001: 2164873us  (4329ns per call)
31test049: 3303884us  (6607ns per call)
32test099: 4656718us  (9313ns per call)
33testInst001: 1401731us  (2803ns per use)
34testInst049: 1401120us  (2802ns per use)
35testInst099: 1401298us  (2802ns per use)
36
37After adding caching for invoke-interface:
38testIface001: 1909330us  (3818ns per call)
39testIface049: 1905204us  (3810ns per call)
40testIface099: 1899012us  (3798ns per call)
41testVirt001: 1825001us  (3650ns per call)
42testVirt049: 1826161us  (3652ns per call)
43testVirt099: 1823915us  (3647ns per call)
44testInst001: 1393963us  (2787ns per use)
45testInst049: 1393163us  (2786ns per use)
46testInst099: 1390496us  (2780ns per use)
47
48After repeating each operation 16 times inside the inner loop:
49testIface001: 1429472us  (2726ns per call)      * 2382ns
50testIface049: 1427847us  (2723ns per call)      * 2396ns
51testIface099: 1423707us  (2715ns per call)      * 2387ns
52testVirt001: 1277790us  (2437ns per call)       * 2118ns
53testVirt049: 1280276us  (2441ns per call)       * 2119ns
54testVirt099: 1272640us  (2427ns per call)       * 2118ns
55testInst001: 844694us  (1611ns per use)         * 1396ns
56testInst049: 845619us  (1612ns per use)         * 1395ns
57testInst099: 845526us  (1612ns per use)         * 1394ns
58('*' is with dx optimizations enabled)
59*/
60
61/**
62 * Semi-generated class with many interfaces.
63 */
64public class ManyInterfaces
65    implements
66        Interface000,
67        Interface001,
68        Interface002,
69        Interface003,
70        Interface004,
71        Interface005,
72        Interface006,
73        Interface007,
74        Interface008,
75        Interface009,
76        Interface010,
77        Interface011,
78        Interface012,
79        Interface013,
80        Interface014,
81        Interface015,
82        Interface016,
83        Interface017,
84        Interface018,
85        Interface019,
86        Interface020,
87        Interface021,
88        Interface022,
89        Interface023,
90        Interface024,
91        Interface025,
92        Interface026,
93        Interface027,
94        Interface028,
95        Interface029,
96        Interface030,
97        Interface031,
98        Interface032,
99        Interface033,
100        Interface034,
101        Interface035,
102        Interface036,
103        Interface037,
104        Interface038,
105        Interface039,
106        Interface040,
107        Interface041,
108        Interface042,
109        Interface043,
110        Interface044,
111        Interface045,
112        Interface046,
113        Interface047,
114        Interface048,
115        Interface049,
116        Interface050,
117        Interface051,
118        Interface052,
119        Interface053,
120        Interface054,
121        Interface055,
122        Interface056,
123        Interface057,
124        Interface058,
125        Interface059,
126        Interface060,
127        Interface061,
128        Interface062,
129        Interface063,
130        Interface064,
131        Interface065,
132        Interface066,
133        Interface067,
134        Interface068,
135        Interface069,
136        Interface070,
137        Interface071,
138        Interface072,
139        Interface073,
140        Interface074,
141        Interface075,
142        Interface076,
143        Interface077,
144        Interface078,
145        Interface079,
146        Interface080,
147        Interface081,
148        Interface082,
149        Interface083,
150        Interface084,
151        Interface085,
152        Interface086,
153        Interface087,
154        Interface088,
155        Interface089,
156        Interface090,
157        Interface091,
158        Interface092,
159        Interface093,
160        Interface094,
161        Interface095,
162        Interface096,
163        Interface097,
164        Interface098,
165        Interface099
166{
167    /** whether to report timing information */
168    private static boolean timing = false;
169
170    /**
171     * Report on a section.
172     */
173    private static void report(String label, long start, long end, int iter,
174            int rept) {
175        if (timing) {
176            System.out.println(label + ": " + (end - start) / 1000 + "us"
177                    + "  (" + (end - start) / (iter*rept) + "ns per call)");
178        } else {
179            System.out.println(label + ": done");
180        }
181    }
182
183    /**
184     * Run tests.
185     *
186     * @param timing whether to print out timing info
187     */
188    public static void run(boolean timing) {
189        ManyInterfaces.timing = timing;
190        ManyInterfaces obj = new ManyInterfaces();
191        Interface001 one;
192        Interface049 forty;
193        Interface099 ninety;
194        long start, end;
195        int iter = 32768;
196        int rept = 16;
197        int i;
198
199        /*
200         * Clear the heap.  The various classes involved should already
201         * be loaded and ready as a result of instantiating ManyInterfaces.
202         */
203        Runtime.getRuntime().gc();
204
205        start = System.nanoTime();
206        testIface001(obj, iter);
207        end = System.nanoTime();
208        report("testIface001", start, end, iter, rept);
209
210        start = System.nanoTime();
211        testIface049(obj, iter);
212        end = System.nanoTime();
213        report("testIface049", start, end, iter, rept);
214
215        start = System.nanoTime();
216        testIface099(obj, iter);
217        end = System.nanoTime();
218        report("testIface099", start, end, iter, rept);
219
220        start = System.nanoTime();
221        testVirt001(obj, iter);
222        end = System.nanoTime();
223        report("testVirt001", start, end, iter, rept);
224
225        start = System.nanoTime();
226        testVirt049(obj, iter);
227        end = System.nanoTime();
228        report("testVirt049", start, end, iter, rept);
229
230        start = System.nanoTime();
231        testVirt099(obj, iter);
232        end = System.nanoTime();
233        report("testVirt099", start, end, iter, rept);
234
235        start = System.nanoTime();
236        testInstance001(obj, iter);
237        end = System.nanoTime();
238        report("testInst001", start, end, iter, rept);
239
240        start = System.nanoTime();
241        testInstance049(obj, iter);
242        end = System.nanoTime();
243        report("testInst049", start, end, iter, rept);
244
245        start = System.nanoTime();
246        testInstance099(obj, iter);
247        end = System.nanoTime();
248        report("testInst099", start, end, iter, rept);
249    }
250
251    public int func001() { return 1; }
252    public int func003() { return 3; }
253    public int func005() { return 5; }
254    public int func007() { return 7; }
255    public int func009() { return 9; }
256    public int func011() { return 11; }
257    public int func013() { return 13; }
258    public int func015() { return 15; }
259    public int func017() { return 17; }
260    public int func019() { return 19; }
261    public int func021() { return 21; }
262    public int func023() { return 23; }
263    public int func025() { return 25; }
264    public int func027() { return 27; }
265    public int func029() { return 29; }
266    public int func031() { return 31; }
267    public int func033() { return 33; }
268    public int func035() { return 35; }
269    public int func037() { return 37; }
270    public int func039() { return 39; }
271    public int func041() { return 41; }
272    public int func043() { return 43; }
273    public int func045() { return 45; }
274    public int func047() { return 47; }
275    public int func049() { return 49; }
276    public int func051() { return 51; }
277    public int func053() { return 53; }
278    public int func055() { return 55; }
279    public int func057() { return 57; }
280    public int func059() { return 59; }
281    public int func061() { return 61; }
282    public int func063() { return 63; }
283    public int func065() { return 65; }
284    public int func067() { return 67; }
285    public int func069() { return 69; }
286    public int func071() { return 71; }
287    public int func073() { return 73; }
288    public int func075() { return 75; }
289    public int func077() { return 77; }
290    public int func079() { return 79; }
291    public int func081() { return 81; }
292    public int func083() { return 83; }
293    public int func085() { return 85; }
294    public int func087() { return 87; }
295    public int func089() { return 89; }
296    public int func091() { return 91; }
297    public int func093() { return 93; }
298    public int func095() { return 95; }
299    public int func097() { return 97; }
300    public int func099() { return 99; }
301
302    static void testIface001(Interface001 iface, int count) {
303        while (count-- != 0) {
304            iface.func001(); iface.func001(); iface.func001(); iface.func001();
305            iface.func001(); iface.func001(); iface.func001(); iface.func001();
306            iface.func001(); iface.func001(); iface.func001(); iface.func001();
307            iface.func001(); iface.func001(); iface.func001(); iface.func001();
308        }
309    }
310
311    static void testIface049(Interface049 iface, int count) {
312        while (count-- != 0) {
313            iface.func049(); iface.func049(); iface.func049(); iface.func049();
314            iface.func049(); iface.func049(); iface.func049(); iface.func049();
315            iface.func049(); iface.func049(); iface.func049(); iface.func049();
316            iface.func049(); iface.func049(); iface.func049(); iface.func049();
317        }
318    }
319
320    static void testIface099(Interface099 iface, int count) {
321        while (count-- != 0) {
322            iface.func099(); iface.func099(); iface.func099(); iface.func099();
323            iface.func099(); iface.func099(); iface.func099(); iface.func099();
324            iface.func099(); iface.func099(); iface.func099(); iface.func099();
325            iface.func099(); iface.func099(); iface.func099(); iface.func099();
326        }
327    }
328
329    static void testVirt001(ManyInterfaces obj, int count) {
330        while (count-- != 0) {
331            obj.func001(); obj.func001(); obj.func001(); obj.func001();
332            obj.func001(); obj.func001(); obj.func001(); obj.func001();
333            obj.func001(); obj.func001(); obj.func001(); obj.func001();
334            obj.func001(); obj.func001(); obj.func001(); obj.func001();
335        }
336    }
337
338    static void testVirt049(ManyInterfaces obj, int count) {
339        while (count-- != 0) {
340            obj.func049(); obj.func049(); obj.func049(); obj.func049();
341            obj.func049(); obj.func049(); obj.func049(); obj.func049();
342            obj.func049(); obj.func049(); obj.func049(); obj.func049();
343            obj.func049(); obj.func049(); obj.func049(); obj.func049();
344        }
345    }
346
347    static void testVirt099(ManyInterfaces obj, int count) {
348        while (count-- != 0) {
349            obj.func099(); obj.func099(); obj.func099(); obj.func099();
350            obj.func099(); obj.func099(); obj.func099(); obj.func099();
351            obj.func099(); obj.func099(); obj.func099(); obj.func099();
352            obj.func099(); obj.func099(); obj.func099(); obj.func099();
353        }
354    }
355
356    static void testInstance001(Object obj, int count) {
357        if (!(obj instanceof Interface001))
358            System.err.println("BAD");
359        while (count-- != 0) {
360            boolean is;
361            is = obj instanceof Interface001;
362            is = obj instanceof Interface001;
363            is = obj instanceof Interface001;
364            is = obj instanceof Interface001;
365            is = obj instanceof Interface001;
366            is = obj instanceof Interface001;
367            is = obj instanceof Interface001;
368            is = obj instanceof Interface001;
369            is = obj instanceof Interface001;
370            is = obj instanceof Interface001;
371            is = obj instanceof Interface001;
372            is = obj instanceof Interface001;
373            is = obj instanceof Interface001;
374            is = obj instanceof Interface001;
375            is = obj instanceof Interface001;
376            is = obj instanceof Interface001;
377        }
378    }
379
380    static void testInstance049(Object obj, int count) {
381        if (!(obj instanceof Interface049))
382            System.err.println("BAD");
383        while (count-- != 0) {
384            boolean is;
385            is = obj instanceof Interface049;
386            is = obj instanceof Interface049;
387            is = obj instanceof Interface049;
388            is = obj instanceof Interface049;
389            is = obj instanceof Interface049;
390            is = obj instanceof Interface049;
391            is = obj instanceof Interface049;
392            is = obj instanceof Interface049;
393            is = obj instanceof Interface049;
394            is = obj instanceof Interface049;
395            is = obj instanceof Interface049;
396            is = obj instanceof Interface049;
397            is = obj instanceof Interface049;
398            is = obj instanceof Interface049;
399            is = obj instanceof Interface049;
400            is = obj instanceof Interface049;
401        }
402    }
403
404    static void testInstance099(Object obj, int count) {
405        if (!(obj instanceof Interface099))
406            System.err.println("BAD");
407        while (count-- != 0) {
408            boolean is;
409            is = obj instanceof Interface099;
410            is = obj instanceof Interface099;
411            is = obj instanceof Interface099;
412            is = obj instanceof Interface099;
413            is = obj instanceof Interface099;
414            is = obj instanceof Interface099;
415            is = obj instanceof Interface099;
416            is = obj instanceof Interface099;
417            is = obj instanceof Interface099;
418            is = obj instanceof Interface099;
419            is = obj instanceof Interface099;
420            is = obj instanceof Interface099;
421            is = obj instanceof Interface099;
422            is = obj instanceof Interface099;
423            is = obj instanceof Interface099;
424            is = obj instanceof Interface099;
425        }
426    }
427}
428