|
1 /* |
|
2 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
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 |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 |
|
24 /* |
|
25 * @test |
|
26 * @bug 8225325 |
|
27 * @summary Add tests for redefining a class' private method during resolution of the bootstrap specifier |
|
28 * @library /test/lib |
|
29 * @modules java.base/jdk.internal.misc |
|
30 * @modules java.compiler |
|
31 * java.instrument |
|
32 * jdk.jartool/sun.tools.jar |
|
33 * @compile ../NamedBuffer.java |
|
34 * @compile redef/Xost.java |
|
35 * @run main RedefineClassHelper |
|
36 * @run main/othervm -javaagent:redefineagent.jar -Xlog:redefine+class*=trace RedefineInterfaceMethods |
|
37 */ |
|
38 |
|
39 class Host { |
|
40 static void log(String msg) { System.out.println(msg); } |
|
41 |
|
42 static interface B { |
|
43 int ORIGINAL_RETURN = 1; |
|
44 int NEW_RETURN = 2; |
|
45 |
|
46 private int privateMethod() { |
|
47 Runnable race1 = () -> log("Hello from inside privateMethod"); |
|
48 race1.run(); |
|
49 return ORIGINAL_RETURN; |
|
50 } |
|
51 |
|
52 public default int defaultMethod(String p) { |
|
53 log(p + "from interface B's defaultMethod"); |
|
54 return privateMethod(); |
|
55 } |
|
56 } |
|
57 |
|
58 static class Impl implements B { |
|
59 } |
|
60 } |
|
61 |
|
62 public class RedefineInterfaceMethods { |
|
63 private static byte[] bytesForHostClass(char replace) throws Throwable { |
|
64 return NamedBuffer.bytesForHostClass(replace, "Host$B"); |
|
65 } |
|
66 |
|
67 public static void main(String[] args) throws Throwable { |
|
68 Host.Impl impl = new Host.Impl(); |
|
69 |
|
70 int res = impl.defaultMethod("Hello "); |
|
71 if (res != Host.B.ORIGINAL_RETURN) |
|
72 throw new Error("defaultMethod returned " + res + |
|
73 " expected " + Host.B.ORIGINAL_RETURN); |
|
74 |
|
75 byte[] buf = bytesForHostClass('X'); |
|
76 RedefineClassHelper.redefineClass(Host.B.class, buf); |
|
77 |
|
78 res = impl.defaultMethod("Goodbye "); |
|
79 if (res != Host.B.NEW_RETURN) |
|
80 throw new Error("defaultMethod returned " + res + |
|
81 " expected " + Host.B.NEW_RETURN); |
|
82 } |
|
83 } |