blob: 2f66a74d5de2eba5f28546db88f3f0e2797dc4d5 [file] [log] [blame]
Nicolas Geoffray6db49a72015-04-28 00:52:43 +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
17public class Main {
18 public static void foo(Object o, int a) {
19 Object result = null;
20 if (o instanceof Main) {
21 // The compiler optimizes the type of `o` by introducing
22 // a `HBoundType` in this block.
23 while (a != 3) {
24 if (a == 2) {
25 a++;
26 result = o;
27 continue;
28 } else if (willInline()) {
29 // This block will be detected as dead after inlining.
30 result = new Object();
31 continue;
32 }
33 result = new Object();
34 }
35 // The compiler produces a phi at the back edge for `result`.
36 // Before dead block elimination, the phi has three inputs:
37 // result = (new Object(), new Object(), HBoundType)
38 //
39 // After dead block elimination, the phi has now two inputs:
40 // result = (new Object(), HBoundType)
41 //
42 // Our internal data structure for linking users and inputs expect
43 // the input index stored in that data structure to be the index
44 // in the inputs array. So the index before dead block elimination
45 // of the `HBoundType` would be 2. Dead block elimination must update
46 // that index to be 1.
47 }
48 System.out.println(result.getClass());
49 }
50
51 public static boolean willInline() {
52 return false;
53 }
54
55 public static void main(String[] args) {
56 foo(new Main(), 2);
57 }
58}