blob: 3339ef436e14374b0b5c5cc6f55240288f6e1668 [file] [log] [blame]
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17// Note that $opt$ is a marker for the optimizing compiler to ensure
18// it does compile the method.
19
20public class Main {
21
22 public static void expectEquals(int expected, int value) {
23 if (expected != value) {
24 throw new Error("Expected: " + expected + ", found: " + value);
25 }
26 }
27
28 public static void main(String[] args) {
29 int result = $opt$testIfEq1(42);
30 expectEquals(42, result);
31
32 result = $opt$testIfEq2(42);
33 expectEquals(7, result);
34
35 result = $opt$testWhileLoop(42);
36 expectEquals(45, result);
37
38 result = $opt$testDoWhileLoop(42);
39 expectEquals(45, result);
40
41 result = $opt$testForLoop(42);
42 expectEquals(44, result);
43 }
44
45 static int $opt$testIfEq1(int a) {
46 if (a + 1 == 43) {
47 return 42;
48 } else {
49 return 7;
50 }
51 }
52
53 static int $opt$testIfEq2(int a) {
54 if (a + 1 == 41) {
55 return 42;
56 } else {
57 return 7;
58 }
59 }
60
61 static int $opt$testWhileLoop(int a) {
62 while (a++ != 44) {}
63 return a;
64 }
65
66 static int $opt$testDoWhileLoop(int a) {
67 do {
68 } while (a++ != 44);
69 return a;
70 }
71
72 static int $opt$testForLoop(int a) {
73 for (; a != 44; a++) {}
74 return a;
75 }
76}