blob: 9924e09f0f38b54ce7d7c165ae46183563ceb649 [file] [log] [blame]
Roland Levillain06b66d02015-07-01 12:47:25 +01001/*
2 * Copyright (C) 2015 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
17class Main {
18 public static void assertIntEquals(int expected, int result) {
19 if (expected != result) {
20 throw new Error("Expected: " + expected + ", found: " + result);
21 }
22 }
23
24 public static void main(String[] args) {
25 Main m = new Main();
26
27 m.$noinline$SetInstanceField();
28 assertIntEquals(123456, m.i);
29
30 $noinline$SetStaticField();
31 assertIntEquals(456789, s);
32 }
33
34 private static boolean doThrow = false;
35
36 private void $noinline$SetInstanceField() {
37 if (doThrow) {
38 // Try defeating inlining.
39 throw new Error();
40 }
41
42 // Set a value than does not fit in a 16-bit (signed) integer.
43 i = 123456;
44 }
45
46 private static void $noinline$SetStaticField() {
47 if (doThrow) {
48 // Try defeating inlining.
49 throw new Error();
50 }
51
52 // Set a value than does not fit in a 16-bit (signed) integer.
53 s = 456789;
54 }
55
56 private int i = 0;
57 private static int s = 0;
58}