Path: blob/master/test/hotspot/jtreg/vmTestbase/vm/compiler/optimizations/partialpeel/While.java
41161 views
/*1* Copyright (c) 2012, 2018, 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*/22package vm.compiler.optimizations.partialpeel;2324import nsk.share.GoldChecker;25import vm.compiler.share.CompilerTest;26import vm.compiler.share.CompilerTestLauncher;27import vm.compiler.share.Random;2829import java.util.Arrays;30import java.util.List;3132public class While {33private final static int N = 1000;34static int x0 = 232;35static int x1 = 562;36static int x2 = 526;37static int x3 = 774;3839public static void main(String[] args) {40GoldChecker goldChecker = new GoldChecker("While");4142for(CompilerTest test: whileTests) {43goldChecker.println(test + " = " + CompilerTestLauncher.launch(test));44}4546goldChecker.check();47}4849public static final List<CompilerTest<Integer>> whileTests = Arrays.asList(5051//while + invariant condition52new CompilerTest<Integer>("while1") {53@Override54public Integer execute(Random random) {55int i = x0;56int j = x1;57int k = x2 + random.nextInt(1000);5859while (i < N) {60i++;61if (x2 > x1) {62j += i;63k += j;64}6566}67return k + i;68}69},7071//while + break on shifted inductive vars + invariant condition72new CompilerTest<Integer>("while2") {73@Override74public Integer execute(Random random) {75int i = x0;76int j = x1;77int k = x2 + random.nextInt(1000);7879while (i < N) {80if (x3 + k < x0) {81break;82}83i++;84if (x2 > x1) {85j += i;86k += j + i;87}8889}90return k + i;91}92},9394//while + break on shifted inductive vars + invariant condition95new CompilerTest<Integer>("while3") {96@Override97public Integer execute(Random random) {98int i = x0;99int j = x1;100int k = x2 + random.nextInt(1000);101102while (i < N) {103if (x3 < x0) {104break;105}106i++;107if (x2 > x1) {108x3 += k;109j += i;110k += i;111}112113}114return k + i;115}116},117118//while + break on hidden inductive vars + invariant condition119new CompilerTest<Integer>("while4") {120@Override121public Integer execute(Random random) {122int i = x0;123int j = x1;124int k = x2 + random.nextInt(1000);125126while (i < N) {127if (x3 < x0) {128break;129}130k++;131i++;132if (x2 > x1) {133x3 += k;134j += i;135k += j;136}137138}139return k + i;140}141}142);143144145}146147148