Path: blob/master/test/hotspot/jtreg/vmTestbase/vm/compiler/optimizations/partialpeel/WhileWhile.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 WhileWhile {333435public static void main(String[] args) {36GoldChecker goldChecker = new GoldChecker("WhileWhile");3738for (CompilerTest test : whilewhileTests) {39goldChecker.println(test + " = " + CompilerTestLauncher.launch(test));40}4142goldChecker.check();43}4445private final static int N = 1000;46static int x0 = 232;47static int x1 = 562;48static int x2 = 526;49static int x3 = 774;5051public static final List<CompilerTest<Integer>> whilewhileTests = Arrays.asList(5253//invariant condition54new CompilerTest<Integer>("whilewhile1") {55@Override56public Integer execute(Random random) {57int k = x0 + random.nextInt(1000);58int i = k + x2;59int s = x1;60int j = x2;6162while (i < N + x3) {63i++;64while (j < N) {65j++;66s++;67if (x2 > x1) {68k += j;69}7071}72}7374return s + k;75}76},777879//inner while with condition on outer while counter80new CompilerTest<Integer>("whilewhile2") {81@Override82public Integer execute(Random random) {83int k = x0 + random.nextInt(1000);84int i = k + x2;85int s = x1;86int j = x2;8788while (i < N + x3) {89i++;90while (j < N + i) {91j++;92s++;93if (x2 > x1) {94k += j;95}9697}98}99return s + k;100}101},102103//inner while in if branch104new CompilerTest<Integer>("whilewhile3") {105@Override106public Integer execute(Random random) {107int k = x0 + random.nextInt(1000);108int i = k + x2;109int s = x1;110int j = x2;111112while (i < N + x3) {113i++;114if (i > x2) {115while (j < N + i) {116j++;117s += k;118if (x2 > x1) {119k += j;120}121}122}123}124return s + k;125}126},127128//two inner while129new CompilerTest<Integer>("whilewhile4") {130@Override131public Integer execute(Random random) {132int k = x0 + random.nextInt(1000);133int i = k + x2;134int s = x1;135int j = x2;136137while (i < N + x3) {138i++;139s++;140if (i > x2) {141while (j < N + i) {142j++;143s++;144if (x2 > x1) {145k += j;146}147}148}149150j = x2;151while (j < x2 + x3) {152j++;153if (x2 > x1) {154j += x0;155s++;156k += j;157}158}159}160return s + k;161}162}163);164165}166167168