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