1 /* |
1 /* |
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
37 import static jdk.test.lib.Asserts.assertEquals; |
37 import static jdk.test.lib.Asserts.assertEquals; |
38 |
38 |
39 interface I1 { default int m() { return 0; } } |
39 interface I1 { default int m() { return 0; } } |
40 interface I2 extends I1 {} |
40 interface I2 extends I1 {} |
41 |
41 |
|
42 // package access top-level class to avoid problem with RedefineClassHelper |
|
43 // and nested types. |
|
44 class RedefineInterfaceCall_C implements I2 { |
|
45 public int test(I2 i) { |
|
46 return i.m(); // invokeinterface cpCacheEntry |
|
47 } |
|
48 } |
|
49 |
42 public class RedefineInterfaceCall { |
50 public class RedefineInterfaceCall { |
43 |
|
44 public static class C implements I2 { |
|
45 public int test(I2 i) { |
|
46 return i.m(); // invokeinterface cpCacheEntry |
|
47 } |
|
48 } |
|
49 |
51 |
50 static String newI1 = |
52 static String newI1 = |
51 "interface I1 { default int m() { return 1; } }"; |
53 "interface I1 { default int m() { return 1; } }"; |
52 |
54 |
53 static String newC = |
55 static String newC = |
54 "public class RedefineInterfaceCall$C implements I2 { " + |
56 "class RedefineInterfaceCall_C implements I2 { " + |
55 " public int test(I2 i) { " + |
57 " public int test(I2 i) { " + |
56 " return i.m(); " + |
58 " return i.m(); " + |
57 " } " + |
59 " } " + |
58 "} "; |
60 "} "; |
59 |
61 |
60 static int test(I2 i) { |
62 static int test(I2 i) { |
61 return i.m(); // invokeinterface cpCacheEntry |
63 return i.m(); // invokeinterface cpCacheEntry |
62 } |
64 } |
63 |
65 |
64 public static void main(String[] args) throws Exception { |
66 public static void main(String[] args) throws Exception { |
65 C c = new C(); |
67 RedefineInterfaceCall_C c = new RedefineInterfaceCall_C(); |
66 |
68 |
67 assertEquals(test(c), 0); |
69 assertEquals(test(c), 0); |
68 assertEquals(c.test(c), 0); |
70 assertEquals(c.test(c), 0); |
69 |
71 |
70 RedefineClassHelper.redefineClass(C.class, newC); |
72 RedefineClassHelper.redefineClass(RedefineInterfaceCall_C.class, newC); |
71 |
73 |
72 assertEquals(c.test(c), 0); |
74 assertEquals(c.test(c), 0); |
73 |
75 |
74 RedefineClassHelper.redefineClass(I1.class, newI1); |
76 RedefineClassHelper.redefineClass(I1.class, newI1); |
75 |
77 |
76 assertEquals(test(c), 1); |
78 assertEquals(test(c), 1); |
77 assertEquals(c.test(c), 1); |
79 assertEquals(c.test(c), 1); |
78 |
80 |
79 RedefineClassHelper.redefineClass(C.class, newC); |
81 RedefineClassHelper.redefineClass(RedefineInterfaceCall_C.class, newC); |
80 |
82 |
81 assertEquals(c.test(c), 1); |
83 assertEquals(c.test(c), 1); |
82 } |
84 } |
83 } |
85 } |