Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +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 | |
| 19 | /* |
| 20 | * Ensure an inlined static invoke explicitly triggers the |
| 21 | * initialization check of the called method's declaring class, and |
| 22 | * that the corresponding load class instruction does not get |
| 23 | * removed before register allocation & code generation. |
| 24 | */ |
| 25 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 26 | /// CHECK-START: void Main.invokeStaticInlined() builder (after) |
| 27 | /// CHECK-DAG: <<LoadClass:l\d+>> LoadClass gen_clinit_check:false |
| 28 | /// CHECK-DAG: <<ClinitCheck:l\d+>> ClinitCheck [<<LoadClass>>] |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 29 | /// CHECK-DAG: InvokeStaticOrDirect [{{[ij]\d+}},<<ClinitCheck>>] |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 30 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 31 | /// CHECK-START: void Main.invokeStaticInlined() inliner (after) |
| 32 | /// CHECK-DAG: <<LoadClass:l\d+>> LoadClass gen_clinit_check:false |
| 33 | /// CHECK-DAG: <<ClinitCheck:l\d+>> ClinitCheck [<<LoadClass>>] |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 34 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 35 | /// CHECK-START: void Main.invokeStaticInlined() inliner (after) |
| 36 | /// CHECK-NOT: InvokeStaticOrDirect |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 37 | |
| 38 | // The following checks ensure the clinit check instruction added by |
| 39 | // the builder is pruned by the PrepareForRegisterAllocation, while |
| 40 | // the load class instruction is preserved. As the control flow |
| 41 | // graph is not dumped after (nor before) this step, we check the |
| 42 | // CFG as it is before the next pass (liveness analysis) instead. |
| 43 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 44 | /// CHECK-START: void Main.invokeStaticInlined() liveness (before) |
| 45 | /// CHECK-DAG: LoadClass gen_clinit_check:true |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 46 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 47 | /// CHECK-START: void Main.invokeStaticInlined() liveness (before) |
| 48 | /// CHECK-NOT: ClinitCheck |
| 49 | /// CHECK-NOT: InvokeStaticOrDirect |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 50 | |
| 51 | static void invokeStaticInlined() { |
| 52 | ClassWithClinit1.$opt$inline$StaticMethod(); |
| 53 | } |
| 54 | |
| 55 | static class ClassWithClinit1 { |
| 56 | static { |
| 57 | System.out.println("Main$ClassWithClinit1's static initializer"); |
| 58 | } |
| 59 | |
| 60 | static void $opt$inline$StaticMethod() { |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | /* |
| 65 | * Ensure a non-inlined static invoke eventually has an implicit |
| 66 | * initialization check of the called method's declaring class. |
| 67 | */ |
| 68 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 69 | /// CHECK-START: void Main.invokeStaticNotInlined() builder (after) |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 70 | /// CHECK: <<LoadClass:l\d+>> LoadClass gen_clinit_check:false |
| 71 | /// CHECK: <<ClinitCheck:l\d+>> ClinitCheck [<<LoadClass>>] |
| 72 | /// CHECK: InvokeStaticOrDirect [{{[ij]\d+}},<<ClinitCheck>>] |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 73 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 74 | /// CHECK-START: void Main.invokeStaticNotInlined() inliner (after) |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 75 | /// CHECK: <<LoadClass:l\d+>> LoadClass gen_clinit_check:false |
| 76 | /// CHECK: <<ClinitCheck:l\d+>> ClinitCheck [<<LoadClass>>] |
| 77 | /// CHECK: InvokeStaticOrDirect [{{([ij]\d+,)?}}<<ClinitCheck>>] |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 78 | |
| 79 | // The following checks ensure the clinit check and load class |
| 80 | // instructions added by the builder are pruned by the |
| 81 | // PrepareForRegisterAllocation. As the control flow graph is not |
| 82 | // dumped after (nor before) this step, we check the CFG as it is |
| 83 | // before the next pass (liveness analysis) instead. |
| 84 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 85 | /// CHECK-START: void Main.invokeStaticNotInlined() liveness (before) |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 86 | /// CHECK: InvokeStaticOrDirect clinit_check:implicit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 87 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 88 | /// CHECK-START: void Main.invokeStaticNotInlined() liveness (before) |
| 89 | /// CHECK-NOT: LoadClass |
| 90 | /// CHECK-NOT: ClinitCheck |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 91 | |
| 92 | static void invokeStaticNotInlined() { |
Guillaume "Vermeille" Sanchez | e918d38 | 2015-06-03 15:32:41 +0100 | [diff] [blame] | 93 | ClassWithClinit2.$noinline$staticMethod(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | static class ClassWithClinit2 { |
| 97 | static { |
| 98 | System.out.println("Main$ClassWithClinit2's static initializer"); |
| 99 | } |
| 100 | |
| 101 | static boolean doThrow = false; |
| 102 | |
Guillaume "Vermeille" Sanchez | e918d38 | 2015-06-03 15:32:41 +0100 | [diff] [blame] | 103 | static void $noinline$staticMethod() { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 104 | if (doThrow) { |
| 105 | // Try defeating inlining. |
| 106 | throw new Error(); |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | /* |
| 112 | * Ensure an inlined call to a static method whose declaring class |
| 113 | * is statically known to have been initialized does not require an |
| 114 | * explicit clinit check. |
| 115 | */ |
| 116 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 117 | /// CHECK-START: void Main$ClassWithClinit3.invokeStaticInlined() builder (after) |
| 118 | /// CHECK-DAG: InvokeStaticOrDirect |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 119 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 120 | /// CHECK-START: void Main$ClassWithClinit3.invokeStaticInlined() builder (after) |
| 121 | /// CHECK-NOT: LoadClass |
| 122 | /// CHECK-NOT: ClinitCheck |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 123 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 124 | /// CHECK-START: void Main$ClassWithClinit3.invokeStaticInlined() inliner (after) |
| 125 | /// CHECK-NOT: LoadClass |
| 126 | /// CHECK-NOT: ClinitCheck |
| 127 | /// CHECK-NOT: InvokeStaticOrDirect |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 128 | |
| 129 | static class ClassWithClinit3 { |
| 130 | static void invokeStaticInlined() { |
| 131 | // The invocation of invokeStaticInlined triggers the |
| 132 | // initialization of ClassWithClinit3, meaning that the |
| 133 | // hereinbelow call to $opt$inline$StaticMethod does not need a |
| 134 | // clinit check. |
| 135 | $opt$inline$StaticMethod(); |
| 136 | } |
| 137 | |
| 138 | static { |
| 139 | System.out.println("Main$ClassWithClinit3's static initializer"); |
| 140 | } |
| 141 | |
| 142 | static void $opt$inline$StaticMethod() { |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | /* |
| 147 | * Ensure an non-inlined call to a static method whose declaring |
| 148 | * class is statically known to have been initialized does not |
| 149 | * require an explicit clinit check. |
| 150 | */ |
| 151 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 152 | /// CHECK-START: void Main$ClassWithClinit4.invokeStaticNotInlined() builder (after) |
| 153 | /// CHECK-DAG: InvokeStaticOrDirect |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 154 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 155 | /// CHECK-START: void Main$ClassWithClinit4.invokeStaticNotInlined() builder (after) |
| 156 | /// CHECK-NOT: LoadClass |
| 157 | /// CHECK-NOT: ClinitCheck |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 158 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 159 | /// CHECK-START: void Main$ClassWithClinit4.invokeStaticNotInlined() inliner (after) |
| 160 | /// CHECK-DAG: InvokeStaticOrDirect |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 161 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 162 | /// CHECK-START: void Main$ClassWithClinit4.invokeStaticNotInlined() inliner (after) |
| 163 | /// CHECK-NOT: LoadClass |
| 164 | /// CHECK-NOT: ClinitCheck |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 165 | |
| 166 | static class ClassWithClinit4 { |
| 167 | static void invokeStaticNotInlined() { |
| 168 | // The invocation of invokeStaticNotInlined triggers the |
| 169 | // initialization of ClassWithClinit4, meaning that the |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 170 | // call to staticMethod below does not need a clinit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 171 | // check. |
Guillaume "Vermeille" Sanchez | e918d38 | 2015-06-03 15:32:41 +0100 | [diff] [blame] | 172 | $noinline$staticMethod(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | static { |
| 176 | System.out.println("Main$ClassWithClinit4's static initializer"); |
| 177 | } |
| 178 | |
| 179 | static boolean doThrow = false; |
| 180 | |
Guillaume "Vermeille" Sanchez | e918d38 | 2015-06-03 15:32:41 +0100 | [diff] [blame] | 181 | static void $noinline$staticMethod() { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 182 | if (doThrow) { |
| 183 | // Try defeating inlining. |
| 184 | throw new Error(); |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | |
Roland Levillain | 5f02c6c | 2015-04-24 19:14:22 +0100 | [diff] [blame] | 189 | /* |
| 190 | * Ensure an inlined call to a static method whose declaring class |
| 191 | * is a super class of the caller's class does not require an |
| 192 | * explicit clinit check. |
| 193 | */ |
| 194 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 195 | /// CHECK-START: void Main$SubClassOfClassWithClinit5.invokeStaticInlined() builder (after) |
| 196 | /// CHECK-DAG: InvokeStaticOrDirect |
Roland Levillain | 5f02c6c | 2015-04-24 19:14:22 +0100 | [diff] [blame] | 197 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 198 | /// CHECK-START: void Main$SubClassOfClassWithClinit5.invokeStaticInlined() builder (after) |
| 199 | /// CHECK-NOT: LoadClass |
| 200 | /// CHECK-NOT: ClinitCheck |
Roland Levillain | 5f02c6c | 2015-04-24 19:14:22 +0100 | [diff] [blame] | 201 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 202 | /// CHECK-START: void Main$SubClassOfClassWithClinit5.invokeStaticInlined() inliner (after) |
| 203 | /// CHECK-NOT: LoadClass |
| 204 | /// CHECK-NOT: ClinitCheck |
| 205 | /// CHECK-NOT: InvokeStaticOrDirect |
Roland Levillain | 5f02c6c | 2015-04-24 19:14:22 +0100 | [diff] [blame] | 206 | |
| 207 | static class ClassWithClinit5 { |
| 208 | static void $opt$inline$StaticMethod() { |
| 209 | } |
| 210 | |
| 211 | static { |
| 212 | System.out.println("Main$ClassWithClinit5's static initializer"); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | static class SubClassOfClassWithClinit5 extends ClassWithClinit5 { |
| 217 | static void invokeStaticInlined() { |
| 218 | ClassWithClinit5.$opt$inline$StaticMethod(); |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | /* |
| 223 | * Ensure an non-inlined call to a static method whose declaring |
| 224 | * class is a super class of the caller's class does not require an |
| 225 | * explicit clinit check. |
| 226 | */ |
| 227 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 228 | /// CHECK-START: void Main$SubClassOfClassWithClinit6.invokeStaticNotInlined() builder (after) |
| 229 | /// CHECK-DAG: InvokeStaticOrDirect |
Roland Levillain | 5f02c6c | 2015-04-24 19:14:22 +0100 | [diff] [blame] | 230 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 231 | /// CHECK-START: void Main$SubClassOfClassWithClinit6.invokeStaticNotInlined() builder (after) |
| 232 | /// CHECK-NOT: LoadClass |
| 233 | /// CHECK-NOT: ClinitCheck |
Roland Levillain | 5f02c6c | 2015-04-24 19:14:22 +0100 | [diff] [blame] | 234 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 235 | /// CHECK-START: void Main$SubClassOfClassWithClinit6.invokeStaticNotInlined() inliner (after) |
| 236 | /// CHECK-DAG: InvokeStaticOrDirect |
Roland Levillain | 5f02c6c | 2015-04-24 19:14:22 +0100 | [diff] [blame] | 237 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 238 | /// CHECK-START: void Main$SubClassOfClassWithClinit6.invokeStaticNotInlined() inliner (after) |
| 239 | /// CHECK-NOT: LoadClass |
| 240 | /// CHECK-NOT: ClinitCheck |
Roland Levillain | 5f02c6c | 2015-04-24 19:14:22 +0100 | [diff] [blame] | 241 | |
| 242 | static class ClassWithClinit6 { |
| 243 | static boolean doThrow = false; |
| 244 | |
Guillaume "Vermeille" Sanchez | e918d38 | 2015-06-03 15:32:41 +0100 | [diff] [blame] | 245 | static void $noinline$staticMethod() { |
Roland Levillain | 5f02c6c | 2015-04-24 19:14:22 +0100 | [diff] [blame] | 246 | if (doThrow) { |
| 247 | // Try defeating inlining. |
| 248 | throw new Error(); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | static { |
| 253 | System.out.println("Main$ClassWithClinit6's static initializer"); |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | static class SubClassOfClassWithClinit6 extends ClassWithClinit6 { |
| 258 | static void invokeStaticNotInlined() { |
Guillaume "Vermeille" Sanchez | e918d38 | 2015-06-03 15:32:41 +0100 | [diff] [blame] | 259 | ClassWithClinit6.$noinline$staticMethod(); |
Roland Levillain | 5f02c6c | 2015-04-24 19:14:22 +0100 | [diff] [blame] | 260 | } |
| 261 | } |
| 262 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 263 | |
| 264 | /* |
| 265 | * Verify that if we have a static call immediately after the load class |
| 266 | * we don't do generate a clinit check. |
| 267 | */ |
| 268 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 269 | /// CHECK-START: void Main.noClinitBecauseOfInvokeStatic() liveness (before) |
| 270 | /// CHECK-DAG: <<IntConstant:i\d+>> IntConstant 0 |
| 271 | /// CHECK-DAG: <<LoadClass:l\d+>> LoadClass gen_clinit_check:false |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 272 | /// CHECK-DAG: InvokeStaticOrDirect clinit_check:implicit |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 273 | /// CHECK-DAG: StaticFieldSet [<<LoadClass>>,<<IntConstant>>] |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 274 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 275 | /// CHECK-START: void Main.noClinitBecauseOfInvokeStatic() liveness (before) |
| 276 | /// CHECK-NOT: ClinitCheck |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 277 | |
| 278 | static void noClinitBecauseOfInvokeStatic() { |
Guillaume "Vermeille" Sanchez | e918d38 | 2015-06-03 15:32:41 +0100 | [diff] [blame] | 279 | ClassWithClinit2.$noinline$staticMethod(); |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 280 | ClassWithClinit2.doThrow = false; |
| 281 | } |
| 282 | |
| 283 | /* |
| 284 | * Verify that if the static call is after a field access, the load class |
| 285 | * will generate a clinit check. |
| 286 | */ |
| 287 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 288 | /// CHECK-START: void Main.clinitBecauseOfFieldAccess() liveness (before) |
| 289 | /// CHECK-DAG: <<IntConstant:i\d+>> IntConstant 0 |
| 290 | /// CHECK-DAG: <<LoadClass:l\d+>> LoadClass gen_clinit_check:true |
| 291 | /// CHECK-DAG: StaticFieldSet [<<LoadClass>>,<<IntConstant>>] |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 292 | /// CHECK-DAG: InvokeStaticOrDirect clinit_check:none |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 293 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 294 | /// CHECK-START: void Main.clinitBecauseOfFieldAccess() liveness (before) |
| 295 | /// CHECK-NOT: ClinitCheck |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 296 | static void clinitBecauseOfFieldAccess() { |
| 297 | ClassWithClinit2.doThrow = false; |
Guillaume "Vermeille" Sanchez | e918d38 | 2015-06-03 15:32:41 +0100 | [diff] [blame] | 298 | ClassWithClinit2.$noinline$staticMethod(); |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 299 | } |
| 300 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 301 | /* |
| 302 | * Verify that LoadClass from const-class is not merged with |
| 303 | * later invoke-static (or it's ClinitCheck). |
| 304 | */ |
| 305 | |
| 306 | /// CHECK-START: void Main.constClassAndInvokeStatic(java.lang.Iterable) liveness (before) |
| 307 | /// CHECK: LoadClass gen_clinit_check:false |
| 308 | /// CHECK: InvokeStaticOrDirect clinit_check:implicit |
| 309 | |
| 310 | /// CHECK-START: void Main.constClassAndInvokeStatic(java.lang.Iterable) liveness (before) |
| 311 | /// CHECK-NOT: ClinitCheck |
| 312 | |
| 313 | static void constClassAndInvokeStatic(Iterable it) { |
| 314 | $opt$inline$ignoreClass(ClassWithClinit7.class); |
| 315 | ClassWithClinit7.someStaticMethod(it); |
| 316 | } |
| 317 | |
| 318 | static void $opt$inline$ignoreClass(Class c) { |
| 319 | } |
| 320 | |
| 321 | static class ClassWithClinit7 { |
| 322 | static { |
| 323 | System.out.println("Main$ClassWithClinit7's static initializer"); |
| 324 | } |
| 325 | |
| 326 | // Note: not inlined from constClassAndInvokeStatic() but fully inlined from main(). |
| 327 | static void someStaticMethod(Iterable it) { |
| 328 | // We're not inlining invoke-interface at the moment. |
| 329 | it.iterator(); |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | /* |
| 334 | * Verify that LoadClass from sget is not merged with later invoke-static. |
| 335 | */ |
| 336 | |
| 337 | /// CHECK-START: void Main.sgetAndInvokeStatic(java.lang.Iterable) liveness (before) |
| 338 | /// CHECK: LoadClass gen_clinit_check:true |
| 339 | /// CHECK: InvokeStaticOrDirect clinit_check:none |
| 340 | |
| 341 | /// CHECK-START: void Main.sgetAndInvokeStatic(java.lang.Iterable) liveness (before) |
| 342 | /// CHECK-NOT: ClinitCheck |
| 343 | |
| 344 | static void sgetAndInvokeStatic(Iterable it) { |
| 345 | $opt$inline$ignoreInt(ClassWithClinit8.value); |
| 346 | ClassWithClinit8.someStaticMethod(it); |
| 347 | } |
| 348 | |
| 349 | static void $opt$inline$ignoreInt(int i) { |
| 350 | } |
| 351 | |
| 352 | static class ClassWithClinit8 { |
| 353 | public static int value = 0; |
| 354 | static { |
| 355 | System.out.println("Main$ClassWithClinit8's static initializer"); |
| 356 | } |
| 357 | |
| 358 | // Note: not inlined from sgetAndInvokeStatic() but fully inlined from main(). |
| 359 | static void someStaticMethod(Iterable it) { |
| 360 | // We're not inlining invoke-interface at the moment. |
| 361 | it.iterator(); |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | /* |
| 366 | * Verify that LoadClass from const-class, ClinitCheck from sget and |
| 367 | * InvokeStaticOrDirect from invoke-static are not merged. |
| 368 | */ |
| 369 | |
| 370 | /// CHECK-START: void Main.constClassSgetAndInvokeStatic(java.lang.Iterable) liveness (before) |
| 371 | /// CHECK: LoadClass gen_clinit_check:false |
| 372 | /// CHECK: ClinitCheck |
| 373 | /// CHECK: InvokeStaticOrDirect clinit_check:none |
| 374 | |
| 375 | static void constClassSgetAndInvokeStatic(Iterable it) { |
| 376 | $opt$inline$ignoreClass(ClassWithClinit9.class); |
| 377 | $opt$inline$ignoreInt(ClassWithClinit9.value); |
| 378 | ClassWithClinit9.someStaticMethod(it); |
| 379 | } |
| 380 | |
| 381 | static class ClassWithClinit9 { |
| 382 | public static int value = 0; |
| 383 | static { |
| 384 | System.out.println("Main$ClassWithClinit9's static initializer"); |
| 385 | } |
| 386 | |
| 387 | // Note: not inlined from constClassSgetAndInvokeStatic() but fully inlined from main(). |
| 388 | static void someStaticMethod(Iterable it) { |
| 389 | // We're not inlining invoke-interface at the moment. |
| 390 | it.iterator(); |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | /* |
| 395 | * Verify that LoadClass from a fully-inlined invoke-static is not merged |
| 396 | * with InvokeStaticOrDirect from a later invoke-static to the same method. |
| 397 | */ |
| 398 | |
| 399 | /// CHECK-START: void Main.inlinedInvokeStaticViaNonStatic(java.lang.Iterable) liveness (before) |
| 400 | /// CHECK: LoadClass gen_clinit_check:true |
| 401 | /// CHECK: InvokeStaticOrDirect clinit_check:none |
| 402 | |
| 403 | /// CHECK-START: void Main.inlinedInvokeStaticViaNonStatic(java.lang.Iterable) liveness (before) |
| 404 | /// CHECK-NOT: ClinitCheck |
| 405 | |
| 406 | static void inlinedInvokeStaticViaNonStatic(Iterable it) { |
| 407 | inlinedInvokeStaticViaNonStaticHelper(null); |
| 408 | inlinedInvokeStaticViaNonStaticHelper(it); |
| 409 | } |
| 410 | |
| 411 | static void inlinedInvokeStaticViaNonStaticHelper(Iterable it) { |
| 412 | ClassWithClinit10.inlinedForNull(it); |
| 413 | } |
| 414 | |
| 415 | static class ClassWithClinit10 { |
| 416 | public static int value = 0; |
| 417 | static { |
| 418 | System.out.println("Main$ClassWithClinit10's static initializer"); |
| 419 | } |
| 420 | |
| 421 | static void inlinedForNull(Iterable it) { |
| 422 | if (it != null) { |
| 423 | // We're not inlining invoke-interface at the moment. |
| 424 | it.iterator(); |
| 425 | } |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | /* |
| 430 | * Check that the LoadClass from an invoke-static C.foo() doesn't get merged with |
| 431 | * an invoke-static inside C.foo(). This would mess up the stack walk in the |
| 432 | * resolution trampoline where we would have to load C (if C isn't loaded yet) |
| 433 | * which is not permitted there. |
| 434 | * |
| 435 | * Note: In case of failure, we would get an failed assertion during compilation, |
| 436 | * so we wouldn't really get to the checker tests below. |
| 437 | */ |
| 438 | |
| 439 | /// CHECK-START: void Main.inlinedInvokeStaticViaStatic(java.lang.Iterable) liveness (before) |
| 440 | /// CHECK: LoadClass gen_clinit_check:true |
| 441 | /// CHECK: InvokeStaticOrDirect clinit_check:none |
| 442 | |
| 443 | /// CHECK-START: void Main.inlinedInvokeStaticViaStatic(java.lang.Iterable) liveness (before) |
| 444 | /// CHECK-NOT: ClinitCheck |
| 445 | |
| 446 | static void inlinedInvokeStaticViaStatic(Iterable it) { |
| 447 | ClassWithClinit11.callInlinedForNull(it); |
| 448 | } |
| 449 | |
| 450 | static class ClassWithClinit11 { |
| 451 | public static int value = 0; |
| 452 | static { |
| 453 | System.out.println("Main$ClassWithClinit11's static initializer"); |
| 454 | } |
| 455 | |
| 456 | static void callInlinedForNull(Iterable it) { |
| 457 | inlinedForNull(it); |
| 458 | } |
| 459 | |
| 460 | static void inlinedForNull(Iterable it) { |
| 461 | // We're not inlining invoke-interface at the moment. |
| 462 | it.iterator(); |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | /* |
| 467 | * A test similar to inlinedInvokeStaticViaStatic() but doing the indirect invoke |
| 468 | * twice with the first one to be fully inlined. |
| 469 | */ |
| 470 | |
| 471 | /// CHECK-START: void Main.inlinedInvokeStaticViaStaticTwice(java.lang.Iterable) liveness (before) |
| 472 | /// CHECK: LoadClass gen_clinit_check:true |
| 473 | /// CHECK: InvokeStaticOrDirect clinit_check:none |
| 474 | |
| 475 | /// CHECK-START: void Main.inlinedInvokeStaticViaStaticTwice(java.lang.Iterable) liveness (before) |
| 476 | /// CHECK-NOT: ClinitCheck |
| 477 | |
| 478 | static void inlinedInvokeStaticViaStaticTwice(Iterable it) { |
| 479 | ClassWithClinit12.callInlinedForNull(null); |
| 480 | ClassWithClinit12.callInlinedForNull(it); |
| 481 | } |
| 482 | |
| 483 | static class ClassWithClinit12 { |
| 484 | public static int value = 0; |
| 485 | static { |
| 486 | System.out.println("Main$ClassWithClinit12's static initializer"); |
| 487 | } |
| 488 | |
| 489 | static void callInlinedForNull(Iterable it) { |
| 490 | inlinedForNull(it); |
| 491 | } |
| 492 | |
| 493 | static void inlinedForNull(Iterable it) { |
| 494 | if (it != null) { |
| 495 | // We're not inlining invoke-interface at the moment. |
| 496 | it.iterator(); |
| 497 | } |
| 498 | } |
| 499 | } |
| 500 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 501 | // TODO: Add a test for the case of a static method whose declaring |
| 502 | // class type index is not available (i.e. when `storage_index` |
| 503 | // equals `DexFile::kDexNoIndex` in |
| 504 | // art::HGraphBuilder::BuildInvoke). |
| 505 | |
| 506 | public static void main(String[] args) { |
| 507 | invokeStaticInlined(); |
| 508 | invokeStaticNotInlined(); |
| 509 | ClassWithClinit3.invokeStaticInlined(); |
| 510 | ClassWithClinit4.invokeStaticNotInlined(); |
Roland Levillain | 5f02c6c | 2015-04-24 19:14:22 +0100 | [diff] [blame] | 511 | SubClassOfClassWithClinit5.invokeStaticInlined(); |
| 512 | SubClassOfClassWithClinit6.invokeStaticNotInlined(); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 513 | Iterable it = new Iterable() { public java.util.Iterator iterator() { return null; } }; |
| 514 | constClassAndInvokeStatic(it); |
| 515 | sgetAndInvokeStatic(it); |
| 516 | constClassSgetAndInvokeStatic(it); |
| 517 | inlinedInvokeStaticViaNonStatic(it); |
| 518 | inlinedInvokeStaticViaStatic(it); |
| 519 | inlinedInvokeStaticViaStaticTwice(it); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 520 | } |
| 521 | } |