|
1 /* |
|
2 * Copyright (c) 2017, 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 8170455 |
|
27 * @summary C2: Access to [].clone from interfaces fails. |
|
28 * @library /test/lib / |
|
29 * |
|
30 * @requires vm.flavor == "server" & !vm.emulatedClient |
|
31 * @build sun.hotspot.WhiteBox |
|
32 * @run driver ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission |
|
33 * @run main/othervm -Xcomp -Xbatch -Xbootclasspath/a:. -XX:-TieredCompilation -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI |
|
34 * -XX:CompileCommand=compileonly,*TestDefaultMethodArrayCloneDeoptC2Interface::test |
|
35 * compiler.arraycopy.TestDefaultMethodArrayCloneDeoptC2 |
|
36 */ |
|
37 |
|
38 package compiler.arraycopy; |
|
39 |
|
40 import sun.hotspot.WhiteBox; |
|
41 import java.lang.reflect.Method; |
|
42 import compiler.whitebox.CompilerWhiteBoxTest; |
|
43 |
|
44 |
|
45 |
|
46 interface TestDefaultMethodArrayCloneDeoptC2Interface { |
|
47 default int[] test(int[] arr) { |
|
48 return arr.clone(); |
|
49 } |
|
50 |
|
51 default TDMACDC2InterfaceTypeTest[] test(TDMACDC2InterfaceTypeTest[] arr) { |
|
52 return arr.clone(); |
|
53 } |
|
54 |
|
55 default TDMACDC2ClassTypeTest[] test(TDMACDC2ClassTypeTest[] arr) { |
|
56 return arr.clone(); |
|
57 } |
|
58 } |
|
59 |
|
60 public class TestDefaultMethodArrayCloneDeoptC2 implements TestDefaultMethodArrayCloneDeoptC2Interface { |
|
61 private static final WhiteBox WB = WhiteBox.getWhiteBox(); |
|
62 public static TestDefaultMethodArrayCloneDeoptC2 a = new TestDefaultMethodArrayCloneDeoptC2(); |
|
63 |
|
64 public static void main(String[] args) throws Exception { |
|
65 testPrimitiveArr(); |
|
66 testIntfArr(); |
|
67 testClassArr(); |
|
68 } |
|
69 |
|
70 public static void testPrimitiveArr() throws Exception { |
|
71 Method m = TestDefaultMethodArrayCloneDeoptC2Interface.class.getMethod("test", int[].class); |
|
72 a.test(new int[1]); // Compiled |
|
73 a.test(new int[1]); |
|
74 if (!WB.isMethodCompiled(m)) { |
|
75 WB.enqueueMethodForCompilation(m, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION); |
|
76 } |
|
77 a.test(new int[1]); |
|
78 if (!WB.isMethodCompiled(m)) { |
|
79 throw new Exception("Method should be compiled"); |
|
80 } |
|
81 } |
|
82 |
|
83 public static void testIntfArr() throws Exception { |
|
84 Method m = TestDefaultMethodArrayCloneDeoptC2Interface.class.getMethod("test", TDMACDC2InterfaceTypeTest[].class); |
|
85 a.test(new TDMACDC2InterfaceTypeTest[1]); // Compiled, Decompile unloaded |
|
86 a.test(new TDMACDC2InterfaceTypeTest[1]); // Compiled |
|
87 a.test(new TDMACDC2InterfaceTypeTest[1]); |
|
88 if (!WB.isMethodCompiled(m)) { |
|
89 WB.enqueueMethodForCompilation(m, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION); |
|
90 } |
|
91 a.test(new TDMACDC2InterfaceTypeTest[1]); |
|
92 if (!WB.isMethodCompiled(m)) { |
|
93 throw new Exception("Method should be compiled"); |
|
94 } |
|
95 } |
|
96 |
|
97 public static void testClassArr() throws Exception { |
|
98 Method m = TestDefaultMethodArrayCloneDeoptC2Interface.class.getMethod("test", TDMACDC2ClassTypeTest[].class); |
|
99 a.test(new TDMACDC2ClassTypeTest[1]); // Compiled, Decompile unloaded |
|
100 a.test(new TDMACDC2ClassTypeTest[1]); // Compiled |
|
101 a.test(new TDMACDC2ClassTypeTest[1]); |
|
102 if (!WB.isMethodCompiled(m)) { |
|
103 WB.enqueueMethodForCompilation(m, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION); |
|
104 } |
|
105 a.test(new TDMACDC2ClassTypeTest[1]); |
|
106 if (!WB.isMethodCompiled(m)) { |
|
107 throw new Exception("Method should be compiled"); |
|
108 } |
|
109 } |
|
110 } |
|
111 |
|
112 interface TDMACDC2InterfaceTypeTest { |
|
113 } |
|
114 |
|
115 class TDMACDC2ClassTypeTest { |
|
116 } |
|
117 |