summaryrefslogtreecommitdiffstats
path: root/test/023-many-interfaces/src/ManyInterfaces.java
blob: d69a490f6722dc911e007149d0aa1617e2fc34aa (plain)
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
Initial:
test001: 2039901us  (4079ns per call)
test049: 3346619us  (6693ns per call)
test099: 4687402us  (9374ns per call)
testInst001: 1327216us  (2654ns per use)
testInst049: 1326995us  (2653ns per use)
testInst099: 1327735us  (2655ns per use)

After refactoring cache code: 2871ns per use
After re-refactoring cache code: 2797ns per use

After de-inlining invoke-interface:
test001: 2164873us  (4329ns per call)
test049: 3303884us  (6607ns per call)
test099: 4656718us  (9313ns per call)
testInst001: 1401731us  (2803ns per use)
testInst049: 1401120us  (2802ns per use)
testInst099: 1401298us  (2802ns per use)

After adding caching for invoke-interface:
testIface001: 1909330us  (3818ns per call)
testIface049: 1905204us  (3810ns per call)
testIface099: 1899012us  (3798ns per call)
testVirt001: 1825001us  (3650ns per call)
testVirt049: 1826161us  (3652ns per call)
testVirt099: 1823915us  (3647ns per call)
testInst001: 1393963us  (2787ns per use)
testInst049: 1393163us  (2786ns per use)
testInst099: 1390496us  (2780ns per use)

After repeating each operation 16 times inside the inner loop:
testIface001: 1429472us  (2726ns per call)      * 2382ns
testIface049: 1427847us  (2723ns per call)      * 2396ns
testIface099: 1423707us  (2715ns per call)      * 2387ns
testVirt001: 1277790us  (2437ns per call)       * 2118ns
testVirt049: 1280276us  (2441ns per call)       * 2119ns
testVirt099: 1272640us  (2427ns per call)       * 2118ns
testInst001: 844694us  (1611ns per use)         * 1396ns
testInst049: 845619us  (1612ns per use)         * 1395ns
testInst099: 845526us  (1612ns per use)         * 1394ns
('*' is with dx optimizations enabled)
*/

/**
 * Semi-generated class with many interfaces.
 */
public class ManyInterfaces
    implements
        Interface000,
        Interface001,
        Interface002,
        Interface003,
        Interface004,
        Interface005,
        Interface006,
        Interface007,
        Interface008,
        Interface009,
        Interface010,
        Interface011,
        Interface012,
        Interface013,
        Interface014,
        Interface015,
        Interface016,
        Interface017,
        Interface018,
        Interface019,
        Interface020,
        Interface021,
        Interface022,
        Interface023,
        Interface024,
        Interface025,
        Interface026,
        Interface027,
        Interface028,
        Interface029,
        Interface030,
        Interface031,
        Interface032,
        Interface033,
        Interface034,
        Interface035,
        Interface036,
        Interface037,
        Interface038,
        Interface039,
        Interface040,
        Interface041,
        Interface042,
        Interface043,
        Interface044,
        Interface045,
        Interface046,
        Interface047,
        Interface048,
        Interface049,
        Interface050,
        Interface051,
        Interface052,
        Interface053,
        Interface054,
        Interface055,
        Interface056,
        Interface057,
        Interface058,
        Interface059,
        Interface060,
        Interface061,
        Interface062,
        Interface063,
        Interface064,
        Interface065,
        Interface066,
        Interface067,
        Interface068,
        Interface069,
        Interface070,
        Interface071,
        Interface072,
        Interface073,
        Interface074,
        Interface075,
        Interface076,
        Interface077,
        Interface078,
        Interface079,
        Interface080,
        Interface081,
        Interface082,
        Interface083,
        Interface084,
        Interface085,
        Interface086,
        Interface087,
        Interface088,
        Interface089,
        Interface090,
        Interface091,
        Interface092,
        Interface093,
        Interface094,
        Interface095,
        Interface096,
        Interface097,
        Interface098,
        Interface099
{
    /** whether to report timing information */
    private static boolean timing = false;

    /**
     * Report on a section.
     */
    private static void report(String label, long start, long end, int iter,
            int rept) {
        if (timing) {
            System.out.println(label + ": " + (end - start) / 1000 + "us"
                    + "  (" + (end - start) / (iter*rept) + "ns per call)");
        } else {
            System.out.println(label + ": done");
        }
    }

    /**
     * Run tests.
     *
     * @param timing whether to print out timing info
     */
    public static void run(boolean timing) {
        ManyInterfaces.timing = timing;
        ManyInterfaces obj = new ManyInterfaces();
        Interface001 one;
        Interface049 forty;
        Interface099 ninety;
        long start, end;
        int iter = 32768;
        int rept = 16;
        int i;

        /*
         * Clear the heap.  The various classes involved should already
         * be loaded and ready as a result of instantiating ManyInterfaces.
         */
        Runtime.getRuntime().gc();

        start = System.nanoTime();
        testIface001(obj, iter);
        end = System.nanoTime();
        report("testIface001", start, end, iter, rept);

        start = System.nanoTime();
        testIface049(obj, iter);
        end = System.nanoTime();
        report("testIface049", start, end, iter, rept);

        start = System.nanoTime();
        testIface099(obj, iter);
        end = System.nanoTime();
        report("testIface099", start, end, iter, rept);

        start = System.nanoTime();
        testVirt001(obj, iter);
        end = System.nanoTime();
        report("testVirt001", start, end, iter, rept);

        start = System.nanoTime();
        testVirt049(obj, iter);
        end = System.nanoTime();
        report("testVirt049", start, end, iter, rept);

        start = System.nanoTime();
        testVirt099(obj, iter);
        end = System.nanoTime();
        report("testVirt099", start, end, iter, rept);

        start = System.nanoTime();
        testInstance001(obj, iter);
        end = System.nanoTime();
        report("testInst001", start, end, iter, rept);

        start = System.nanoTime();
        testInstance049(obj, iter);
        end = System.nanoTime();
        report("testInst049", start, end, iter, rept);

        start = System.nanoTime();
        testInstance099(obj, iter);
        end = System.nanoTime();
        report("testInst099", start, end, iter, rept);
    }

    public int func001() { return 1; }
    public int func003() { return 3; }
    public int func005() { return 5; }
    public int func007() { return 7; }
    public int func009() { return 9; }
    public int func011() { return 11; }
    public int func013() { return 13; }
    public int func015() { return 15; }
    public int func017() { return 17; }
    public int func019() { return 19; }
    public int func021() { return 21; }
    public int func023() { return 23; }
    public int func025() { return 25; }
    public int func027() { return 27; }
    public int func029() { return 29; }
    public int func031() { return 31; }
    public int func033() { return 33; }
    public int func035() { return 35; }
    public int func037() { return 37; }
    public int func039() { return 39; }
    public int func041() { return 41; }
    public int func043() { return 43; }
    public int func045() { return 45; }
    public int func047() { return 47; }
    public int func049() { return 49; }
    public int func051() { return 51; }
    public int func053() { return 53; }
    public int func055() { return 55; }
    public int func057() { return 57; }
    public int func059() { return 59; }
    public int func061() { return 61; }
    public int func063() { return 63; }
    public int func065() { return 65; }
    public int func067() { return 67; }
    public int func069() { return 69; }
    public int func071() { return 71; }
    public int func073() { return 73; }
    public int func075() { return 75; }
    public int func077() { return 77; }
    public int func079() { return 79; }
    public int func081() { return 81; }
    public int func083() { return 83; }
    public int func085() { return 85; }
    public int func087() { return 87; }
    public int func089() { return 89; }
    public int func091() { return 91; }
    public int func093() { return 93; }
    public int func095() { return 95; }
    public int func097() { return 97; }
    public int func099() { return 99; }

    static void testIface001(Interface001 iface, int count) {
        while (count-- != 0) {
            iface.func001(); iface.func001(); iface.func001(); iface.func001();
            iface.func001(); iface.func001(); iface.func001(); iface.func001();
            iface.func001(); iface.func001(); iface.func001(); iface.func001();
            iface.func001(); iface.func001(); iface.func001(); iface.func001();
        }
    }

    static void testIface049(Interface049 iface, int count) {
        while (count-- != 0) {
            iface.func049(); iface.func049(); iface.func049(); iface.func049();
            iface.func049(); iface.func049(); iface.func049(); iface.func049();
            iface.func049(); iface.func049(); iface.func049(); iface.func049();
            iface.func049(); iface.func049(); iface.func049(); iface.func049();
        }
    }

    static void testIface099(Interface099 iface, int count) {
        while (count-- != 0) {
            iface.func099(); iface.func099(); iface.func099(); iface.func099();
            iface.func099(); iface.func099(); iface.func099(); iface.func099();
            iface.func099(); iface.func099(); iface.func099(); iface.func099();
            iface.func099(); iface.func099(); iface.func099(); iface.func099();
        }
    }

    static void testVirt001(ManyInterfaces obj, int count) {
        while (count-- != 0) {
            obj.func001(); obj.func001(); obj.func001(); obj.func001();
            obj.func001(); obj.func001(); obj.func001(); obj.func001();
            obj.func001(); obj.func001(); obj.func001(); obj.func001();
            obj.func001(); obj.func001(); obj.func001(); obj.func001();
        }
    }

    static void testVirt049(ManyInterfaces obj, int count) {
        while (count-- != 0) {
            obj.func049(); obj.func049(); obj.func049(); obj.func049();
            obj.func049(); obj.func049(); obj.func049(); obj.func049();
            obj.func049(); obj.func049(); obj.func049(); obj.func049();
            obj.func049(); obj.func049(); obj.func049(); obj.func049();
        }
    }

    static void testVirt099(ManyInterfaces obj, int count) {
        while (count-- != 0) {
            obj.func099(); obj.func099(); obj.func099(); obj.func099();
            obj.func099(); obj.func099(); obj.func099(); obj.func099();
            obj.func099(); obj.func099(); obj.func099(); obj.func099();
            obj.func099(); obj.func099(); obj.func099(); obj.func099();
        }
    }

    static void testInstance001(Object obj, int count) {
        if (!(obj instanceof Interface001))
            System.err.println("BAD");
        while (count-- != 0) {
            boolean is;
            is = obj instanceof Interface001;
            is = obj instanceof Interface001;
            is = obj instanceof Interface001;
            is = obj instanceof Interface001;
            is = obj instanceof Interface001;
            is = obj instanceof Interface001;
            is = obj instanceof Interface001;
            is = obj instanceof Interface001;
            is = obj instanceof Interface001;
            is = obj instanceof Interface001;
            is = obj instanceof Interface001;
            is = obj instanceof Interface001;
            is = obj instanceof Interface001;
            is = obj instanceof Interface001;
            is = obj instanceof Interface001;
            is = obj instanceof Interface001;
        }
    }

    static void testInstance049(Object obj, int count) {
        if (!(obj instanceof Interface049))
            System.err.println("BAD");
        while (count-- != 0) {
            boolean is;
            is = obj instanceof Interface049;
            is = obj instanceof Interface049;
            is = obj instanceof Interface049;
            is = obj instanceof Interface049;
            is = obj instanceof Interface049;
            is = obj instanceof Interface049;
            is = obj instanceof Interface049;
            is = obj instanceof Interface049;
            is = obj instanceof Interface049;
            is = obj instanceof Interface049;
            is = obj instanceof Interface049;
            is = obj instanceof Interface049;
            is = obj instanceof Interface049;
            is = obj instanceof Interface049;
            is = obj instanceof Interface049;
            is = obj instanceof Interface049;
        }
    }

    static void testInstance099(Object obj, int count) {
        if (!(obj instanceof Interface099))
            System.err.println("BAD");
        while (count-- != 0) {
            boolean is;
            is = obj instanceof Interface099;
            is = obj instanceof Interface099;
            is = obj instanceof Interface099;
            is = obj instanceof Interface099;
            is = obj instanceof Interface099;
            is = obj instanceof Interface099;
            is = obj instanceof Interface099;
            is = obj instanceof Interface099;
            is = obj instanceof Interface099;
            is = obj instanceof Interface099;
            is = obj instanceof Interface099;
            is = obj instanceof Interface099;
            is = obj instanceof Interface099;
            is = obj instanceof Interface099;
            is = obj instanceof Interface099;
            is = obj instanceof Interface099;
        }
    }
}