Christoffer Quist Adamsen | 722c9f6 | 2018-07-04 16:23:25 +0200 | [diff] [blame] | 1 | // Copyright (c) 2018, the R8 project authors. Please see the AUTHORS file |
| 2 | // for details. All rights reserved. Use of this source code is governed by a |
| 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | |
| 5 | package classmerging; |
| 6 | |
| 7 | public class MergeDefaultMethodIntoClassTest { |
| 8 | |
| 9 | public static void main(String[] args) { |
| 10 | // Note: Important that the static type of [obj] is A, such that the call to f becomes an |
| 11 | // invoke-interface instruction and not invoke-virtual instruction. |
| 12 | A obj = new B(); |
| 13 | obj.f(); |
Christoffer Quist Adamsen | bfdbe60 | 2019-10-18 12:03:31 +0200 | [diff] [blame] | 14 | |
| 15 | // Ensure that the instantiations are not dead code eliminated. |
| 16 | escape(obj); |
| 17 | } |
| 18 | |
| 19 | @NeverInline |
| 20 | static void escape(Object o) { |
| 21 | if (System.currentTimeMillis() < 0) { |
| 22 | System.out.println(o); |
| 23 | } |
Christoffer Quist Adamsen | 722c9f6 | 2018-07-04 16:23:25 +0200 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | public interface A { |
| 27 | default void f() { |
| 28 | System.out.println("In A.f"); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | public static class B implements A {} |
| 33 | } |