Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame^] | 1 | /* |
| 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 | |
| 17 | public class Main { |
| 18 | |
| 19 | private static int willInline(int a, int b) { |
| 20 | return a & b; |
| 21 | } |
| 22 | |
| 23 | static int[] a = new int[4]; |
| 24 | static int field = 42; |
| 25 | |
| 26 | public static void main(String[] args) throws Exception { |
| 27 | // The order of optimizations that would lead to the problem was: |
| 28 | // 1) Inlining of `willInline`. |
| 29 | // 2) Bounds check elimination inserting a deopt at a[0] and removing the HBoundsCheck. |
| 30 | // 3) Instruction simplifier simpilifying the inlined willInline to just `field`. |
| 31 | // |
| 32 | // At this point, if the environment of the HDeoptimization instruction was |
| 33 | // just a pointer to the one in a[0], the uses lists would have not been updated |
| 34 | // and the HBoundsCheck being dead code after the HDeoptimization, the simplifcation |
| 35 | // at step 3) would not updated that environment. |
| 36 | int inEnv = willInline(field, field); |
| 37 | int doAdds = a[0] + a[1] + a[2] + a[3]; |
| 38 | |
| 39 | if (inEnv != 42) { |
| 40 | throw new Error("Expected 42"); |
| 41 | } |
| 42 | |
| 43 | if (doAdds != 0) { |
| 44 | throw new Error("Expected 0"); |
| 45 | } |
| 46 | } |
| 47 | } |