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