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