1 /* 2 * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package vm.compiler.optimizations.partialpeel; 24 25 import nsk.share.GoldChecker; 26 import vm.compiler.share.CompilerTest; 27 import vm.compiler.share.CompilerTestLauncher; 28 import vm.compiler.share.Random; 29 30 import java.util.Arrays; 31 import java.util.List; 32 33 public class Do { 34 35 36 public static void main(String[] args) { 37 GoldChecker goldChecker = new GoldChecker("Do"); 38 39 for(CompilerTest test: doTests) { 40 goldChecker.println(test + " = " + CompilerTestLauncher.launch(test)); 41 } 42 43 goldChecker.check(); 44 } 45 46 private final static int N = 1000; 47 private final static int x0 = 232; 48 private final static int x1 = 562; 49 private final static int x2 = 526; 50 private final static int x3 = 774; 51 52 public static final List<CompilerTest<Integer>> doTests = Arrays.asList( 53 new CompilerTest<Integer>("do1") { 54 @Override 55 public Integer execute(Random random) { 56 int s = random.nextInt(1000); 57 int i = 0; 58 do { 59 if (s * i > x0) { 60 break; 61 } 62 s++; 63 i++; 64 } while (i < N); 65 return s + i; 66 } 67 }, 68 69 //do + break on sum of inductive vars 70 new CompilerTest<Integer>("do2") { 71 @Override 72 public Integer execute(Random random) { 73 int s = random.nextInt(1000); 74 int i = 0; 75 do { 76 if (s + i > x0) { 77 break; 78 } 79 s++; 80 i++; 81 } while (i < N); 82 return s + i; 83 } 84 }, 85 86 //do + break on shifted inductive vars 87 new CompilerTest<Integer>("do3") { 88 @Override 89 public Integer execute(Random random) { 90 int s = random.nextInt(1000); 91 int i = 0; 92 do { 93 if (x3 + s < x0) { 94 break; 95 } 96 s += i; 97 i++; 98 } while (i < N); 99 return s + i; 100 } 101 }, 102 103 //do + break on shifted inductive vars + invariant condition 104 new CompilerTest<Integer>("do4") { 105 @Override 106 public Integer execute(Random random) { 107 int i = x0 + random.nextInt(1000); 108 int j = x1; 109 int k = x2; 110 111 do { 112 if (x3 + k < x0) { 113 break; 114 } 115 i++; 116 k++; 117 if (x2 > x1) { 118 j += i; 119 k += j; 120 } 121 122 } while (i < N); 123 return k + i; 124 } 125 }, 126 127 //do + break on shifted inductive vars + invariant condition 128 new CompilerTest<Integer>("do5") { 129 @Override 130 public Integer execute(Random random) { 131 int i = x0 + random.nextInt(1000); 132 int j = x1; 133 int k = x2; 134 135 do { 136 if (k < x0) { 137 break; 138 } 139 i++; 140 if (x2 > x1) { 141 j += i; 142 k += j; 143 } 144 145 } while (i < N); 146 return k + i; 147 } 148 }, 149 150 //do + break on hidden inductive vars + invariant condition 151 new CompilerTest<Integer>("do6") { 152 @Override 153 public Integer execute(Random random) { 154 int i = x0; 155 int j = x1 + random.nextInt(1000); 156 int k = x2; 157 158 do { 159 if (k < x0) { 160 break; 161 } 162 i++; 163 k++; 164 if (k > x1) { 165 j += i; 166 k += j + i; 167 } 168 169 } while (i < N); 170 return k + i; 171 } 172 } 173 174 ); 175 }