Path: blob/master/test/hotspot/jtreg/compiler/arraycopy/TestDefaultMethodArrayCloneDeoptC2.java
41152 views
/*1* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 817045526* @summary C2: Access to [].clone from interfaces fails.27* @library /test/lib /28*29* @requires vm.flavor == "server" & !vm.emulatedClient30* @build sun.hotspot.WhiteBox31* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox32* @run main/othervm -Xcomp -Xbatch -Xbootclasspath/a:. -XX:-TieredCompilation -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI33* -XX:CompileCommand=compileonly,*TestDefaultMethodArrayCloneDeoptC2Interface::test34* compiler.arraycopy.TestDefaultMethodArrayCloneDeoptC235*/3637package compiler.arraycopy;3839import sun.hotspot.WhiteBox;40import java.lang.reflect.Method;41import compiler.whitebox.CompilerWhiteBoxTest;42434445interface TestDefaultMethodArrayCloneDeoptC2Interface {46default int[] test(int[] arr) {47return arr.clone();48}4950default TDMACDC2InterfaceTypeTest[] test(TDMACDC2InterfaceTypeTest[] arr) {51return arr.clone();52}5354default TDMACDC2ClassTypeTest[] test(TDMACDC2ClassTypeTest[] arr) {55return arr.clone();56}57}5859public class TestDefaultMethodArrayCloneDeoptC2 implements TestDefaultMethodArrayCloneDeoptC2Interface {60private static final WhiteBox WB = WhiteBox.getWhiteBox();61public static TestDefaultMethodArrayCloneDeoptC2 a = new TestDefaultMethodArrayCloneDeoptC2();6263public static void main(String[] args) throws Exception {64testPrimitiveArr();65testIntfArr();66testClassArr();67}6869public static void testPrimitiveArr() throws Exception {70Method m = TestDefaultMethodArrayCloneDeoptC2Interface.class.getMethod("test", int[].class);71a.test(new int[1]); // Compiled72a.test(new int[1]);73if (!WB.isMethodCompiled(m)) {74WB.enqueueMethodForCompilation(m, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);75}76a.test(new int[1]);77if (!WB.isMethodCompiled(m)) {78throw new Exception("Method should be compiled");79}80}8182public static void testIntfArr() throws Exception {83Method m = TestDefaultMethodArrayCloneDeoptC2Interface.class.getMethod("test", TDMACDC2InterfaceTypeTest[].class);84a.test(new TDMACDC2InterfaceTypeTest[1]); // Compiled, Decompile unloaded85a.test(new TDMACDC2InterfaceTypeTest[1]); // Compiled86a.test(new TDMACDC2InterfaceTypeTest[1]);87if (!WB.isMethodCompiled(m)) {88WB.enqueueMethodForCompilation(m, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);89}90a.test(new TDMACDC2InterfaceTypeTest[1]);91if (!WB.isMethodCompiled(m)) {92throw new Exception("Method should be compiled");93}94}9596public static void testClassArr() throws Exception {97Method m = TestDefaultMethodArrayCloneDeoptC2Interface.class.getMethod("test", TDMACDC2ClassTypeTest[].class);98a.test(new TDMACDC2ClassTypeTest[1]); // Compiled, Decompile unloaded99a.test(new TDMACDC2ClassTypeTest[1]); // Compiled100a.test(new TDMACDC2ClassTypeTest[1]);101if (!WB.isMethodCompiled(m)) {102WB.enqueueMethodForCompilation(m, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);103}104a.test(new TDMACDC2ClassTypeTest[1]);105if (!WB.isMethodCompiled(m)) {106throw new Exception("Method should be compiled");107}108}109}110111interface TDMACDC2InterfaceTypeTest {112}113114class TDMACDC2ClassTypeTest {115}116117118119