Path: blob/master/test/hotspot/jtreg/compiler/rangechecks/TestUncommonTrapMerging.java
41152 views
/*1* Copyright (c) 2015, 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 814057426* @summary Verify proper re-execution of checks after merging of uncommon traps27*28* @run main/othervm -Xcomp -XX:-TieredCompilation29* -XX:CompileCommand=compileonly,compiler.rangechecks.TestUncommonTrapMerging::test*30* compiler.rangechecks.TestUncommonTrapMerging Test131* @run main/othervm -XX:CompileCommand=compileonly,compiler.rangechecks.TestUncommonTrapMerging::test*32* compiler.rangechecks.TestUncommonTrapMerging Test233*/3435package compiler.rangechecks;3637public class TestUncommonTrapMerging {3839public static void main(String[] args) throws Throwable {40if (args.length < 1) {41throw new RuntimeException("Not enough arguments!");42}43TestUncommonTrapMerging mytest = new TestUncommonTrapMerging();44String testcase = args[0];45if (testcase.equals("Test1")) {46try {47// '42' should hit the 'arg > 0' check48mytest.test(42);4950} catch (OutOfMemoryError e) {51// expected52}53} else if (testcase.equals("Test2")) {54// Compile test2 with uncommon traps at path 1 and path 255for (int i = 0; i < 100_000; i++) {56mytest.test2(-1, 0);57}5859// Compile test3 which inlines test2 with uncommon traps at60// path 1 and path 2. Because test3 always passes 'value = 1',61// C2 will remove the 'value > 0' check and then merge the two62// uncommon traps.63for (int i = 0; i < 100_000; i++) {64mytest.test3(0);65}6667// This should return through path 268if (!mytest.test3(42)) {69throw new RuntimeException("test2 returned through wrong path!");70}71}72}7374public void test(int arg) throws Throwable {75// The following two checks should not be merged if the76// uncommon trap of the dominating if has 'Reason_unloaded'77// because we need to re-execute both checks after deopt.78if (arg < 0) {79throw new RuntimeException("Should not reach here");80} else if (arg > 0) {81throw new OutOfMemoryError();82}83throw new RuntimeException("Should not reach here");84}8586public boolean test2(int arg, int value) {87if (arg < 0) {88if (value > 0) {89// path 190return false;91}92} else if (arg > 0) {93// path 294return true;95}96// path 397return false;98}99100public boolean test3(int arg) {101int i;102for (i = 0; i < 1; ++i) { }103// i == 1104return test2(arg, i);105}106}107108109