Path: blob/master/test/hotspot/jtreg/compiler/arraycopy/TestArrayCopyNoInitDeopt.java
41149 views
/*1* Copyright (c) 2015, 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 807201626* @summary Infinite deoptimization/recompilation cycles in case of arraycopy with tightly coupled allocation27* @requires vm.flavor == "server" & !vm.emulatedClient & !vm.graal.enabled28* @library /test/lib /29* @modules java.base/jdk.internal.misc30* java.management31*32* @build sun.hotspot.WhiteBox33* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox34* @run main/othervm -Xmixed -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI35* -XX:-BackgroundCompilation -XX:-UseOnStackReplacement -XX:TypeProfileLevel=02036* compiler.arraycopy.TestArrayCopyNoInitDeopt37*/3839package compiler.arraycopy;4041import compiler.whitebox.CompilerWhiteBoxTest;42import jdk.test.lib.Platform;43import sun.hotspot.WhiteBox;4445import java.lang.reflect.Method;4647public class TestArrayCopyNoInitDeopt {4849public static int[] m1(Object src) {50if (src == null) return null;51int[] dest = new int[10];52try {53System.arraycopy(src, 0, dest, 0, 10);54} catch (ArrayStoreException npe) {55}56return dest;57}5859static Object m2_src(Object src) {60return src;61}6263public static int[] m2(Object src) {64if (src == null) return null;65src = m2_src(src);66int[] dest = new int[10];67try {68System.arraycopy(src, 0, dest, 0, 10);69} catch (ArrayStoreException npe) {70}71return dest;72}7374private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();75private static final int TIERED_STOP_AT_LEVEL = WHITE_BOX.getIntxVMFlag("TieredStopAtLevel").intValue();7677static boolean deoptimize(Method method, Object src_obj) throws Exception {78for (int i = 0; i < 10; i++) {79method.invoke(null, src_obj);80if (!WHITE_BOX.isMethodCompiled(method)) {81return true;82}83}84return false;85}8687static public void main(String[] args) throws Exception {88if (!Platform.isServer() || Platform.isEmulatedClient()) {89throw new Error("TESTBUG: Not server mode");90}91// Only execute if C2 is available92if (TIERED_STOP_AT_LEVEL == CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION) {93int[] src = new int[10];94Object src_obj = new Object();95Method method_m1 = TestArrayCopyNoInitDeopt.class.getMethod("m1", Object.class);96Method method_m2 = TestArrayCopyNoInitDeopt.class.getMethod("m2", Object.class);9798// Warm up99for (int i = 0; i < 20000; i++) {100m1(src);101}102103// And make sure m1 is compiled by C2104WHITE_BOX.enqueueMethodForCompilation(method_m1, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);105106if (!WHITE_BOX.isMethodCompiled(method_m1)) {107throw new RuntimeException("m1 not compiled");108}109110// should deoptimize for type check111if (!deoptimize(method_m1, src_obj)) {112throw new RuntimeException("m1 not deoptimized");113}114115WHITE_BOX.enqueueMethodForCompilation(method_m1, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);116117if (!WHITE_BOX.isMethodCompiled(method_m1)) {118throw new RuntimeException("m1 not recompiled");119}120121if (deoptimize(method_m1, src_obj)) {122throw new RuntimeException("m1 deoptimized again");123}124125if (WHITE_BOX.getUintxVMFlag("TypeProfileLevel") == 20) {126// Same test as above but with speculative types127128// Warm up & make sure we collect type profiling129for (int i = 0; i < 20000; i++) {130m2(src);131}132133// And make sure m2 is compiled by C2134WHITE_BOX.enqueueMethodForCompilation(method_m2, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);135136if (!WHITE_BOX.isMethodCompiled(method_m2)) {137throw new RuntimeException("m2 not compiled");138}139140// should deoptimize for speculative type check141if (!deoptimize(method_m2, src_obj)) {142throw new RuntimeException("m2 not deoptimized");143}144145WHITE_BOX.enqueueMethodForCompilation(method_m2, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);146147if (!WHITE_BOX.isMethodCompiled(method_m2)) {148throw new RuntimeException("m2 not recompiled");149}150151// should deoptimize for actual type check152if (!deoptimize(method_m2, src_obj)) {153throw new RuntimeException("m2 not deoptimized");154}155156WHITE_BOX.enqueueMethodForCompilation(method_m2, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);157158if (!WHITE_BOX.isMethodCompiled(method_m2)) {159throw new RuntimeException("m2 not recompiled");160}161162if (deoptimize(method_m2, src_obj)) {163throw new RuntimeException("m2 deoptimized again");164}165}166}167}168}169170171