Nicolas Geoffray | 9fdb31e | 2015-07-01 12:56:46 +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 | public static void main(String[] args) { |
Santiago Aboy Solanes | 13c3ce1 | 2022-12-05 12:05:43 +0000 | [diff] [blame] | 19 | $noinline$testWithNull(new Object[2]); |
| 20 | $noinline$testWithUnknown(new Object[2], new Object()); |
| 21 | $noinline$testWithSame(new Object[2]); |
| 22 | $noinline$testWithSameRTI(); |
Nicolas Geoffray | 9fdb31e | 2015-07-01 12:56:46 +0100 | [diff] [blame] | 23 | } |
| 24 | |
Santiago Aboy Solanes | 13c3ce1 | 2022-12-05 12:05:43 +0000 | [diff] [blame] | 25 | // Known null can eliminate the type check in early stages. |
| 26 | |
| 27 | /// CHECK-START: void Main.$noinline$testWithNull(java.lang.Object[]) instruction_simplifier (before) |
| 28 | /// CHECK: ArraySet needs_type_check:true can_trigger_gc:true |
| 29 | |
| 30 | /// CHECK-START: void Main.$noinline$testWithNull(java.lang.Object[]) instruction_simplifier (after) |
| 31 | /// CHECK: ArraySet needs_type_check:false can_trigger_gc:false |
| 32 | |
| 33 | /// CHECK-START: void Main.$noinline$testWithNull(java.lang.Object[]) disassembly (after) |
| 34 | /// CHECK: ArraySet needs_type_check:false can_trigger_gc:false |
| 35 | public static void $noinline$testWithNull(Object[] o) { |
Nicolas Geoffray | 9fdb31e | 2015-07-01 12:56:46 +0100 | [diff] [blame] | 36 | o[0] = null; |
| 37 | } |
| 38 | |
Santiago Aboy Solanes | 13c3ce1 | 2022-12-05 12:05:43 +0000 | [diff] [blame] | 39 | /// CHECK-START: void Main.$noinline$testWithUnknown(java.lang.Object[], java.lang.Object) disassembly (after) |
| 40 | /// CHECK: ArraySet needs_type_check:true can_trigger_gc:true |
| 41 | public static void $noinline$testWithUnknown(Object[] o, Object obj) { |
Nicolas Geoffray | 9fdb31e | 2015-07-01 12:56:46 +0100 | [diff] [blame] | 42 | o[0] = obj; |
| 43 | } |
| 44 | |
Santiago Aboy Solanes | 13c3ce1 | 2022-12-05 12:05:43 +0000 | [diff] [blame] | 45 | // After GVN we know that we are setting values from the same array so there's no need for a type |
| 46 | // check. |
| 47 | |
| 48 | /// CHECK-START: void Main.$noinline$testWithSame(java.lang.Object[]) instruction_simplifier$after_gvn (before) |
| 49 | /// CHECK: ArraySet needs_type_check:true can_trigger_gc:true |
| 50 | |
| 51 | /// CHECK-START: void Main.$noinline$testWithSame(java.lang.Object[]) instruction_simplifier$after_gvn (after) |
| 52 | /// CHECK: ArraySet needs_type_check:false can_trigger_gc:false |
| 53 | |
| 54 | /// CHECK-START: void Main.$noinline$testWithSame(java.lang.Object[]) disassembly (after) |
| 55 | /// CHECK: ArraySet needs_type_check:false can_trigger_gc:false |
| 56 | public static void $noinline$testWithSame(Object[] o) { |
Nicolas Geoffray | 9fdb31e | 2015-07-01 12:56:46 +0100 | [diff] [blame] | 57 | o[0] = o[1]; |
| 58 | } |
Santiago Aboy Solanes | 13c3ce1 | 2022-12-05 12:05:43 +0000 | [diff] [blame] | 59 | |
| 60 | // We know that the array and the static Object have the same RTI in early stages. No need for a |
| 61 | // type check. |
| 62 | |
| 63 | /// CHECK-START: java.lang.Object[] Main.$noinline$testWithSameRTI() instruction_simplifier (before) |
| 64 | /// CHECK: ArraySet needs_type_check:true can_trigger_gc:true |
| 65 | |
| 66 | /// CHECK-START: java.lang.Object[] Main.$noinline$testWithSameRTI() instruction_simplifier (after) |
| 67 | /// CHECK: ArraySet needs_type_check:false can_trigger_gc:false |
| 68 | |
| 69 | /// CHECK-START: java.lang.Object[] Main.$noinline$testWithSameRTI() disassembly (after) |
| 70 | /// CHECK: ArraySet needs_type_check:false can_trigger_gc:false |
| 71 | public static Object[] $noinline$testWithSameRTI() { |
| 72 | Object[] arr = new Object[1]; |
| 73 | arr[0] = static_obj; |
| 74 | // Return so that LSE doesn't eliminate the ArraySet. |
| 75 | return arr; |
| 76 | } |
| 77 | |
| 78 | static Object static_obj; |
Nicolas Geoffray | 9fdb31e | 2015-07-01 12:56:46 +0100 | [diff] [blame] | 79 | } |