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 { |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 20 | /// CHECK-START: void ClassWithoutFinals.<init>() register (after) |
| 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 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 29 | /// CHECK-START: void ClassWithFinals.<init>(boolean) register (after) |
| 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 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 40 | /// CHECK-START: void ClassWithFinals.<init>() register (after) |
| 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 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 47 | /// CHECK-START: void ClassWithFinals.<init>(int) register (after) |
| 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 { |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 61 | /// CHECK-START: void InheritFromClassWithFinals.<init>() register (after) |
| 62 | /// CHECK: MemoryBarrier kind:StoreStore |
| 63 | /// CHECK-NEXT: ReturnVoid |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 64 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 65 | /// CHECK-START: void InheritFromClassWithFinals.<init>() register (after) |
| 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 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 71 | /// CHECK-START: void InheritFromClassWithFinals.<init>(boolean) register (after) |
| 72 | /// CHECK: InvokeStaticOrDirect |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 73 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 74 | /// CHECK-START: void InheritFromClassWithFinals.<init>(boolean) register (after) |
| 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 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 81 | /// CHECK-START: void InheritFromClassWithFinals.<init>(int) register (after) |
| 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 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 86 | /// CHECK-START: void InheritFromClassWithFinals.<init>(int) register (after) |
| 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 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 99 | /// CHECK-START: void HaveFinalsAndInheritFromClassWithFinals.<init>() register (after) |
| 100 | /// CHECK: MemoryBarrier kind:StoreStore |
| 101 | /// CHECK-NEXT: ReturnVoid |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 102 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 103 | /// CHECK-START: void HaveFinalsAndInheritFromClassWithFinals.<init>() register (after) |
| 104 | /// CHECK-NOT: InvokeStaticOrDirect |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 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 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 110 | /// CHECK-START: void HaveFinalsAndInheritFromClassWithFinals.<init>(boolean) register (after) |
| 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 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 120 | /// CHECK-START: void HaveFinalsAndInheritFromClassWithFinals.<init>(int) register (after) |
| 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 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 126 | /// CHECK-START: void HaveFinalsAndInheritFromClassWithFinals.<init>(int) register (after) |
| 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 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 141 | /// CHECK-START: ClassWithFinals Main.noInlineNoConstructorBarrier() register (after) |
| 142 | /// CHECK: InvokeStaticOrDirect |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 143 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 144 | /// CHECK-START: ClassWithFinals Main.noInlineNoConstructorBarrier() register (after) |
| 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 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 150 | /// CHECK-START: void Main.inlineNew() register (after) |
| 151 | /// CHECK: MemoryBarrier kind:StoreStore |
| 152 | /// CHECK-NEXT: ReturnVoid |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 153 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 154 | /// CHECK-START: void Main.inlineNew() register (after) |
| 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 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 160 | /// CHECK-START: void Main.inlineNew1() register (after) |
| 161 | /// CHECK: MemoryBarrier kind:StoreStore |
| 162 | /// CHECK-NEXT: ReturnVoid |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 163 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 164 | /// CHECK-START: void Main.inlineNew1() register (after) |
| 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 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 170 | /// CHECK-START: void Main.inlineNew2() register (after) |
| 171 | /// CHECK: MemoryBarrier kind:StoreStore |
| 172 | /// CHECK-NEXT: ReturnVoid |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 173 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 174 | /// CHECK-START: void Main.inlineNew2() register (after) |
| 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 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 180 | /// CHECK-START: void Main.inlineNew3() register (after) |
| 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 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 185 | /// CHECK-START: void Main.inlineNew3() register (after) |
| 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 | } |