Calin Juravle | 27df758 | 2015-04-17 19:12:31 +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 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 17 | // TODO: Add more tests after we can inline functions with calls. |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 18 | |
| 19 | class ClassWithoutFinals { |
| 20 | // CHECK-START: void ClassWithoutFinals.<init>() register (after) |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 21 | // CHECK-NOT: MemoryBarrier kind:StoreStore |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 22 | public ClassWithoutFinals() {} |
| 23 | } |
| 24 | |
| 25 | class ClassWithFinals { |
| 26 | public final int x; |
| 27 | public ClassWithFinals obj; |
| 28 | |
| 29 | // CHECK-START: void ClassWithFinals.<init>(boolean) register (after) |
David Brazdil | 7114119 | 2015-05-19 18:29:40 +0100 | [diff] [blame^] | 30 | // CHECK: MemoryBarrier kind:StoreStore |
| 31 | // CHECK-NEXT: ReturnVoid |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 32 | public ClassWithFinals(boolean cond) { |
| 33 | x = 0; |
| 34 | if (cond) { |
| 35 | // avoid inlining |
| 36 | throw new RuntimeException(); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | // CHECK-START: void ClassWithFinals.<init>() register (after) |
David Brazdil | 7114119 | 2015-05-19 18:29:40 +0100 | [diff] [blame^] | 41 | // CHECK: MemoryBarrier kind:StoreStore |
| 42 | // CHECK-NEXT: ReturnVoid |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 43 | public ClassWithFinals() { |
| 44 | x = 0; |
| 45 | } |
| 46 | |
| 47 | // CHECK-START: void ClassWithFinals.<init>(int) register (after) |
David Brazdil | 7114119 | 2015-05-19 18:29:40 +0100 | [diff] [blame^] | 48 | // CHECK: MemoryBarrier kind:StoreStore |
| 49 | // CHECK: MemoryBarrier kind:StoreStore |
| 50 | // CHECK-NEXT: ReturnVoid |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 51 | public ClassWithFinals(int x) { |
| 52 | // This should have two barriers: |
| 53 | // - one for the constructor |
| 54 | // - one for the `new` which should be inlined. |
| 55 | obj = new ClassWithFinals(); |
| 56 | this.x = x; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | class InheritFromClassWithFinals extends ClassWithFinals { |
| 61 | // CHECK-START: void InheritFromClassWithFinals.<init>() register (after) |
David Brazdil | 7114119 | 2015-05-19 18:29:40 +0100 | [diff] [blame^] | 62 | // CHECK: MemoryBarrier kind:StoreStore |
| 63 | // CHECK-NEXT: ReturnVoid |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 64 | |
| 65 | // CHECK-START: void InheritFromClassWithFinals.<init>() register (after) |
David Brazdil | 7114119 | 2015-05-19 18:29:40 +0100 | [diff] [blame^] | 66 | // CHECK-NOT: InvokeStaticOrDirect |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 67 | public InheritFromClassWithFinals() { |
| 68 | // Should inline the super constructor. |
| 69 | } |
| 70 | |
| 71 | // CHECK-START: void InheritFromClassWithFinals.<init>(boolean) register (after) |
David Brazdil | 7114119 | 2015-05-19 18:29:40 +0100 | [diff] [blame^] | 72 | // CHECK: InvokeStaticOrDirect |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 73 | |
| 74 | // CHECK-START: void InheritFromClassWithFinals.<init>(boolean) register (after) |
David Brazdil | 7114119 | 2015-05-19 18:29:40 +0100 | [diff] [blame^] | 75 | // CHECK-NOT: MemoryBarrier kind:StoreStore |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 76 | public InheritFromClassWithFinals(boolean cond) { |
| 77 | super(cond); |
| 78 | // should not inline the super constructor |
| 79 | } |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 80 | |
| 81 | // CHECK-START: void InheritFromClassWithFinals.<init>(int) register (after) |
David Brazdil | 7114119 | 2015-05-19 18:29:40 +0100 | [diff] [blame^] | 82 | // CHECK: MemoryBarrier kind:StoreStore |
| 83 | // CHECK: MemoryBarrier kind:StoreStore |
| 84 | // CHECK: ReturnVoid |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 85 | |
| 86 | // CHECK-START: void InheritFromClassWithFinals.<init>(int) register (after) |
David Brazdil | 7114119 | 2015-05-19 18:29:40 +0100 | [diff] [blame^] | 87 | // CHECK-NOT: InvokeStaticOrDirect |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 88 | public InheritFromClassWithFinals(int unused) { |
| 89 | // Should inline the super constructor and insert a memory barrier. |
| 90 | |
| 91 | // Should inline the new instance call and insert another memory barrier. |
| 92 | new InheritFromClassWithFinals(); |
| 93 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | class HaveFinalsAndInheritFromClassWithFinals extends ClassWithFinals { |
| 97 | final int y; |
| 98 | |
| 99 | // CHECK-START: void HaveFinalsAndInheritFromClassWithFinals.<init>() register (after) |
David Brazdil | 7114119 | 2015-05-19 18:29:40 +0100 | [diff] [blame^] | 100 | // CHECK: MemoryBarrier kind:StoreStore |
| 101 | // CHECK-NEXT: ReturnVoid |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 102 | |
| 103 | // CHECK-START: void HaveFinalsAndInheritFromClassWithFinals.<init>() register (after) |
| 104 | // CHECK-NOT: InvokeStaticOrDirect |
| 105 | public HaveFinalsAndInheritFromClassWithFinals() { |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 106 | // Should inline the super constructor and remove the memory barrier. |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 107 | y = 0; |
| 108 | } |
| 109 | |
| 110 | // CHECK-START: void HaveFinalsAndInheritFromClassWithFinals.<init>(boolean) register (after) |
David Brazdil | 7114119 | 2015-05-19 18:29:40 +0100 | [diff] [blame^] | 111 | // CHECK: InvokeStaticOrDirect |
| 112 | // CHECK: MemoryBarrier kind:StoreStore |
| 113 | // CHECK-NEXT: ReturnVoid |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 114 | public HaveFinalsAndInheritFromClassWithFinals(boolean cond) { |
| 115 | super(cond); |
| 116 | // should not inline the super constructor |
| 117 | y = 0; |
| 118 | } |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 119 | |
| 120 | // CHECK-START: void HaveFinalsAndInheritFromClassWithFinals.<init>(int) register (after) |
David Brazdil | 7114119 | 2015-05-19 18:29:40 +0100 | [diff] [blame^] | 121 | // CHECK: MemoryBarrier kind:StoreStore |
| 122 | // CHECK: MemoryBarrier kind:StoreStore |
| 123 | // CHECK: MemoryBarrier kind:StoreStore |
| 124 | // CHECK-NEXT: ReturnVoid |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 125 | |
| 126 | // CHECK-START: void HaveFinalsAndInheritFromClassWithFinals.<init>(int) register (after) |
David Brazdil | 7114119 | 2015-05-19 18:29:40 +0100 | [diff] [blame^] | 127 | // CHECK-NOT: InvokeStaticOrDirect |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 128 | public HaveFinalsAndInheritFromClassWithFinals(int unused) { |
| 129 | // Should inline the super constructor and keep just one memory barrier. |
| 130 | y = 0; |
| 131 | |
| 132 | // Should inline new instance and keep one barrier. |
| 133 | new HaveFinalsAndInheritFromClassWithFinals(); |
| 134 | // Should inline new instance and keep one barrier. |
| 135 | new InheritFromClassWithFinals(); |
| 136 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | public class Main { |
| 140 | |
| 141 | // CHECK-START: ClassWithFinals Main.noInlineNoConstructorBarrier() register (after) |
David Brazdil | 7114119 | 2015-05-19 18:29:40 +0100 | [diff] [blame^] | 142 | // CHECK: InvokeStaticOrDirect |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 143 | |
| 144 | // CHECK-START: ClassWithFinals Main.noInlineNoConstructorBarrier() register (after) |
David Brazdil | 7114119 | 2015-05-19 18:29:40 +0100 | [diff] [blame^] | 145 | // CHECK-NOT: MemoryBarrier kind:StoreStore |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 146 | public static ClassWithFinals noInlineNoConstructorBarrier() { |
| 147 | return new ClassWithFinals(false); |
| 148 | } |
| 149 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 150 | // CHECK-START: void Main.inlineNew() register (after) |
David Brazdil | 7114119 | 2015-05-19 18:29:40 +0100 | [diff] [blame^] | 151 | // CHECK: MemoryBarrier kind:StoreStore |
| 152 | // CHECK-NEXT: ReturnVoid |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 153 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 154 | // CHECK-START: void Main.inlineNew() register (after) |
David Brazdil | 7114119 | 2015-05-19 18:29:40 +0100 | [diff] [blame^] | 155 | // CHECK-NOT: InvokeStaticOrDirect |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 156 | public static void inlineNew() { |
| 157 | new ClassWithFinals(); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 158 | } |
| 159 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 160 | // CHECK-START: void Main.inlineNew1() register (after) |
David Brazdil | 7114119 | 2015-05-19 18:29:40 +0100 | [diff] [blame^] | 161 | // CHECK: MemoryBarrier kind:StoreStore |
| 162 | // CHECK-NEXT: ReturnVoid |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 163 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 164 | // CHECK-START: void Main.inlineNew1() register (after) |
David Brazdil | 7114119 | 2015-05-19 18:29:40 +0100 | [diff] [blame^] | 165 | // CHECK-NOT: InvokeStaticOrDirect |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 166 | public static void inlineNew1() { |
| 167 | new InheritFromClassWithFinals(); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 168 | } |
| 169 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 170 | // CHECK-START: void Main.inlineNew2() register (after) |
David Brazdil | 7114119 | 2015-05-19 18:29:40 +0100 | [diff] [blame^] | 171 | // CHECK: MemoryBarrier kind:StoreStore |
| 172 | // CHECK-NEXT: ReturnVoid |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 173 | |
| 174 | // CHECK-START: void Main.inlineNew2() register (after) |
David Brazdil | 7114119 | 2015-05-19 18:29:40 +0100 | [diff] [blame^] | 175 | // CHECK-NOT: InvokeStaticOrDirect |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 176 | public static void inlineNew2() { |
| 177 | new HaveFinalsAndInheritFromClassWithFinals(); |
| 178 | } |
| 179 | |
| 180 | // CHECK-START: void Main.inlineNew3() register (after) |
David Brazdil | 7114119 | 2015-05-19 18:29:40 +0100 | [diff] [blame^] | 181 | // CHECK: MemoryBarrier kind:StoreStore |
| 182 | // CHECK: MemoryBarrier kind:StoreStore |
| 183 | // CHECK-NEXT: ReturnVoid |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 184 | |
| 185 | // CHECK-START: void Main.inlineNew3() register (after) |
David Brazdil | 7114119 | 2015-05-19 18:29:40 +0100 | [diff] [blame^] | 186 | // CHECK-NOT: InvokeStaticOrDirect |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 187 | public static void inlineNew3() { |
| 188 | new HaveFinalsAndInheritFromClassWithFinals(); |
| 189 | new HaveFinalsAndInheritFromClassWithFinals(); |
| 190 | } |
| 191 | |
| 192 | public static void main(String[] args) {} |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 193 | } |