Path: blob/master/test/hotspot/jtreg/compiler/c1/Test8172751.java
41149 views
/*1* Copyright (c) 2017, 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 817275126* @summary OSR compilation at unreachable bci causes C1 crash27*28* @run main/othervm -XX:-BackgroundCompilation compiler.c1.Test817275129*/3031package compiler.c1;3233import java.lang.invoke.MethodHandle;34import java.lang.invoke.MethodHandles;35import java.lang.invoke.MutableCallSite;3637public class Test8172751 {38private static final MethodHandle CONSTANT_TRUE = MethodHandles.constant(boolean.class, true);39private static final MethodHandle CONSTANT_FALSE = MethodHandles.constant(boolean.class, false);40private static final MutableCallSite CALL_SITE = new MutableCallSite(CONSTANT_FALSE);41private static final int LIMIT = 1_000_000;42private static volatile int counter;4344private static boolean doSomething() {45return counter++ < LIMIT;46}4748private static void executeLoop() {49/*50* Start off with executing the first loop, then change the call site51* target so as to switch over to the second loop but continue running52* in the first loop. Eventually, an OSR compilation of the first loop53* is triggered. Yet C1 will not find the OSR entry, since it will54* have optimized out the first loop already during parsing.55*/56if (CALL_SITE.getTarget() == CONSTANT_FALSE) {57int count = 0;58while (doSomething()) {59if (count++ == 1) {60flipSwitch();61}62}63} else {64while (doSomething()) {65}66}67}6869private static void flipSwitch() {70CALL_SITE.setTarget(CONSTANT_TRUE);71}7273public static void main(String[] args) {74executeLoop();75}76}777879