Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | public static Object[] getObjectArray() { return null; } |
| 19 | public static long[] getLongArray() { return null; } |
Nicolas Geoffray | b1d9157 | 2016-03-18 16:25:38 +0000 | [diff] [blame^] | 20 | public static Object getNull() { return null; } |
Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 21 | |
| 22 | public static void main(String[] args) { |
| 23 | try { |
| 24 | foo(); |
| 25 | throw new Error("Expected NullPointerException"); |
| 26 | } catch (NullPointerException e) { |
| 27 | // Expected. |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | /// CHECK-START: void Main.foo() load_store_elimination (after) |
| 32 | /// CHECK-DAG: <<Null:l\d+>> NullConstant |
| 33 | /// CHECK-DAG: <<Check:l\d+>> NullCheck [<<Null>>] |
| 34 | /// CHECK-DAG: <<Get1:j\d+>> ArrayGet [<<Check>>,{{i\d+}}] |
| 35 | /// CHECK-DAG: <<Get2:l\d+>> ArrayGet [<<Check>>,{{i\d+}}] |
| 36 | public static void foo() { |
| 37 | longField = getLongArray()[0]; |
| 38 | objectField = getObjectArray()[0]; |
| 39 | } |
| 40 | |
Nicolas Geoffray | b1d9157 | 2016-03-18 16:25:38 +0000 | [diff] [blame^] | 41 | /// CHECK-START: void Main.bar() load_store_elimination (after) |
| 42 | /// CHECK-DAG: <<Null:l\d+>> NullConstant |
| 43 | /// CHECK-DAG: <<BoundType:l\d+>> BoundType [<<Null>>] |
| 44 | /// CHECK-DAG: <<CheckL:l\d+>> NullCheck [<<BoundType>>] |
| 45 | /// CHECK-DAG: <<GetL0:l\d+>> ArrayGet [<<CheckL>>,{{i\d+}}] |
| 46 | /// CHECK-DAG: <<GetL1:l\d+>> ArrayGet [<<CheckL>>,{{i\d+}}] |
| 47 | /// CHECK-DAG: <<GetL2:l\d+>> ArrayGet [<<CheckL>>,{{i\d+}}] |
| 48 | /// CHECK-DAG: <<GetL3:l\d+>> ArrayGet [<<CheckL>>,{{i\d+}}] |
| 49 | /// CHECK-DAG: <<CheckJ:l\d+>> NullCheck [<<Null>>] |
| 50 | /// CHECK-DAG: <<GetJ0:j\d+>> ArrayGet [<<CheckJ>>,{{i\d+}}] |
| 51 | /// CHECK-DAG: <<GetJ1:j\d+>> ArrayGet [<<CheckJ>>,{{i\d+}}] |
| 52 | /// CHECK-DAG: <<GetJ2:j\d+>> ArrayGet [<<CheckJ>>,{{i\d+}}] |
| 53 | /// CHECK-DAG: <<GetJ3:j\d+>> ArrayGet [<<CheckJ>>,{{i\d+}}] |
| 54 | public static void bar() { |
| 55 | // We create multiple accesses that will lead the bounds check |
| 56 | // elimination pass to add a HDeoptimize. Not having the bounds check helped |
| 57 | // the load store elimination think it could merge two ArrayGet with different |
| 58 | // types. |
| 59 | String[] array = ((String[])getNull()); |
| 60 | objectField = array[0]; |
| 61 | objectField = array[1]; |
| 62 | objectField = array[2]; |
| 63 | objectField = array[3]; |
| 64 | long[] longArray = getLongArray(); |
| 65 | longField = longArray[0]; |
| 66 | longField = longArray[1]; |
| 67 | longField = longArray[2]; |
| 68 | longField = longArray[3]; |
| 69 | } |
| 70 | |
Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 71 | public static long longField; |
| 72 | public static Object objectField; |
| 73 | } |