Christoffer Quist Adamsen | c655d26 | 2018-09-18 16:32:53 +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 SyntheticBridgeSignaturesTest { |
| 8 | |
| 9 | // If A is merged into ASub first, then the synthetic bridge for "void A.m(B)" will originally |
| 10 | // get the signature "void ASub.m(B)". Otherwise, if B is merged into BSub first, then the |
| 11 | // synthetic bridge will get the signature "void BSub.m(A)". In either case, it is important that |
| 12 | // the signatures of the bridge methods are updated after all classes have been merged vertically. |
| 13 | public static void main(String[] args) { |
| 14 | ASub a = new ASub(); |
| 15 | BSub b = new BSub(); |
| 16 | a.m(b); |
| 17 | b.m(a); |
Christoffer Quist Adamsen | bfdbe60 | 2019-10-18 12:03:31 +0200 | [diff] [blame] | 18 | |
| 19 | // Ensure that the instantiations are not dead code eliminated. |
| 20 | escape(a); |
| 21 | escape(b); |
| 22 | } |
| 23 | |
| 24 | @NeverInline |
| 25 | static void escape(Object o) { |
| 26 | if (System.currentTimeMillis() < 0) { |
| 27 | System.out.println(o); |
| 28 | } |
Christoffer Quist Adamsen | c655d26 | 2018-09-18 16:32:53 +0200 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | private static class A { |
| 32 | |
| 33 | public void m(B object) { |
| 34 | System.out.println("In A.m()"); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | private static class ASub extends A {} |
| 39 | |
| 40 | private static class B { |
| 41 | |
| 42 | public void m(A object) { |
| 43 | System.out.println("In B.m()"); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | private static class BSub extends B {} |
| 48 | } |