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 | bdb2ecc | 2018-09-18 14:33:55 +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>>] |
Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 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 | |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 101 | static boolean staticField = false; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 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 | } |
| 105 | } |
| 106 | |
| 107 | /* |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 108 | * Ensure an inlined call from a static method to a static method |
| 109 | * of the same class does not require an explicit clinit check |
| 110 | * (already initialized or initializing in the same thread). |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 111 | */ |
| 112 | |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 113 | /// CHECK-START: void Main$ClassWithClinit3Static.invokeStaticInlined() builder (after) |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 114 | /// CHECK-DAG: InvokeStaticOrDirect |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 115 | |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 116 | /// CHECK-START: void Main$ClassWithClinit3Static.invokeStaticInlined() builder (after) |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 117 | /// CHECK-NOT: LoadClass |
| 118 | /// CHECK-NOT: ClinitCheck |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 119 | |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 120 | /// CHECK-START: void Main$ClassWithClinit3Static.invokeStaticInlined() inliner (after) |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 121 | /// CHECK-NOT: LoadClass |
| 122 | /// CHECK-NOT: ClinitCheck |
| 123 | /// CHECK-NOT: InvokeStaticOrDirect |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 124 | |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 125 | static class ClassWithClinit3Static { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 126 | static void invokeStaticInlined() { |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 127 | // The invocation of invokeStaticInlined happens only after a clinit check |
| 128 | // of ClassWithClinit3Static, meaning that the hereinbelow call to |
| 129 | // $opt$inline$StaticMethod does not need another clinit check. |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 130 | $opt$inline$StaticMethod(); |
| 131 | } |
| 132 | |
| 133 | static { |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 134 | System.out.println("Main$ClassWithClinit3Static's static initializer"); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | static void $opt$inline$StaticMethod() { |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | /* |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 142 | * Ensure an inlined call from an instance method to a static method |
| 143 | * of the same class actually requires an explicit clinit check when |
| 144 | * the class has a non-trivial initialization as we could be executing |
| 145 | * the instance method on an escaped object of an erroneous class. b/62478025 |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 146 | */ |
| 147 | |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 148 | /// CHECK-START: void Main$ClassWithClinit3Instance.invokeStaticInlined() builder (after) |
| 149 | /// CHECK-DAG: LoadClass |
| 150 | /// CHECK-DAG: ClinitCheck |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 151 | /// CHECK-DAG: InvokeStaticOrDirect |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 152 | |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 153 | /// CHECK-START: void Main$ClassWithClinit3Instance.invokeStaticInlined() inliner (after) |
| 154 | /// CHECK-DAG: LoadClass |
| 155 | /// CHECK-DAG: ClinitCheck |
| 156 | |
| 157 | /// CHECK-START: void Main$ClassWithClinit3Instance.invokeStaticInlined() inliner (after) |
| 158 | /// CHECK-NOT: InvokeStaticOrDirect |
| 159 | |
| 160 | static class ClassWithClinit3Instance { |
| 161 | void invokeStaticInlined() { |
| 162 | // ClinitCheck required. |
| 163 | $opt$inline$StaticMethod(); |
| 164 | } |
| 165 | |
| 166 | static { |
| 167 | System.out.println("Main$ClassWithClinit3Instance's static initializer"); |
| 168 | } |
| 169 | |
| 170 | static void $opt$inline$StaticMethod() { |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | /* |
| 175 | * Ensure a non-inlined call from a static method to a static method |
| 176 | * of the same class does not require an explicit clinit check |
| 177 | * (already initialized or initializing in the same thread). |
| 178 | */ |
| 179 | |
| 180 | /// CHECK-START: void Main$ClassWithClinit4Static.invokeStaticNotInlined() builder (after) |
| 181 | /// CHECK-DAG: InvokeStaticOrDirect |
| 182 | |
| 183 | /// CHECK-START: void Main$ClassWithClinit4Static.invokeStaticNotInlined() builder (after) |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 184 | /// CHECK-NOT: LoadClass |
| 185 | /// CHECK-NOT: ClinitCheck |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 186 | |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 187 | /// CHECK-START: void Main$ClassWithClinit4Static.invokeStaticNotInlined() inliner (after) |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 188 | /// CHECK-DAG: InvokeStaticOrDirect |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 189 | |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 190 | /// CHECK-START: void Main$ClassWithClinit4Static.invokeStaticNotInlined() inliner (after) |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 191 | /// CHECK-NOT: LoadClass |
| 192 | /// CHECK-NOT: ClinitCheck |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 193 | |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 194 | static class ClassWithClinit4Static { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 195 | static void invokeStaticNotInlined() { |
| 196 | // The invocation of invokeStaticNotInlined triggers the |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 197 | // initialization of ClassWithClinit4Static, meaning that the |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 198 | // call to staticMethod below does not need a clinit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 199 | // check. |
Guillaume "Vermeille" Sanchez | e918d38 | 2015-06-03 15:32:41 +0100 | [diff] [blame] | 200 | $noinline$staticMethod(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | static { |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 204 | System.out.println("Main$ClassWithClinit4Static's static initializer"); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 205 | } |
| 206 | |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 207 | static void $noinline$staticMethod() { |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | /* |
| 212 | * Ensure a non-inlined call from an instance method to a static method |
| 213 | * of the same class actually requires an explicit clinit check when |
| 214 | * the class has a non-trivial initialization as we could be executing |
| 215 | * the instance method on an escaped object of an erroneous class. b/62478025 |
| 216 | */ |
| 217 | |
| 218 | /// CHECK-START: void Main$ClassWithClinit4Instance.invokeStaticNotInlined() builder (after) |
| 219 | /// CHECK-DAG: LoadClass |
| 220 | /// CHECK-DAG: ClinitCheck |
| 221 | /// CHECK-DAG: InvokeStaticOrDirect |
| 222 | |
| 223 | /// CHECK-START: void Main$ClassWithClinit4Instance.invokeStaticNotInlined() inliner (after) |
| 224 | /// CHECK-DAG: LoadClass |
| 225 | /// CHECK-DAG: ClinitCheck |
| 226 | /// CHECK-DAG: InvokeStaticOrDirect |
| 227 | |
Vladimir Marko | 78da5e2 | 2019-05-30 14:14:34 +0100 | [diff] [blame^] | 228 | // The following checks ensure the clinit check and load class |
| 229 | // instructions added by the builder are pruned by the |
| 230 | // PrepareForRegisterAllocation. As the control flow graph is not |
| 231 | // dumped after (nor before) this step, we check the CFG as it is |
| 232 | // before the next pass (liveness analysis) instead. |
| 233 | |
| 234 | /// CHECK-START: void Main$ClassWithClinit4Instance.invokeStaticNotInlined() liveness (before) |
| 235 | /// CHECK: InvokeStaticOrDirect clinit_check:implicit |
| 236 | |
| 237 | /// CHECK-START: void Main$ClassWithClinit4Instance.invokeStaticNotInlined() liveness (before) |
| 238 | /// CHECK-NOT: LoadClass |
| 239 | /// CHECK-NOT: ClinitCheck |
| 240 | |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 241 | static class ClassWithClinit4Instance { |
| 242 | void invokeStaticNotInlined() { |
| 243 | // ClinitCheck required. |
| 244 | $noinline$staticMethod(); |
| 245 | } |
| 246 | |
| 247 | static { |
| 248 | System.out.println("Main$ClassWithClinit4Instance's static initializer"); |
| 249 | } |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 250 | |
Guillaume "Vermeille" Sanchez | e918d38 | 2015-06-03 15:32:41 +0100 | [diff] [blame] | 251 | static void $noinline$staticMethod() { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | |
Roland Levillain | 5f02c6c | 2015-04-24 19:14:22 +0100 | [diff] [blame] | 255 | /* |
Vladimir Marko | 51b8aaf | 2017-06-09 15:17:05 +0100 | [diff] [blame] | 256 | * We used to remove clinit check for calls to static methods in a superclass. However, this |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 257 | * is not a valid optimization when instances of erroneous classes can escape, therefore |
| 258 | * we avoid this optimization for classes with non-trivial initialization. b/62478025 |
Roland Levillain | 5f02c6c | 2015-04-24 19:14:22 +0100 | [diff] [blame] | 259 | */ |
| 260 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 261 | /// CHECK-START: void Main$SubClassOfClassWithClinit5.invokeStaticInlined() builder (after) |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 262 | /// CHECK-DAG: LoadClass |
| 263 | /// CHECK-DAG: ClinitCheck |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 264 | /// CHECK-DAG: InvokeStaticOrDirect |
Roland Levillain | 5f02c6c | 2015-04-24 19:14:22 +0100 | [diff] [blame] | 265 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 266 | /// CHECK-START: void Main$SubClassOfClassWithClinit5.invokeStaticInlined() inliner (after) |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 267 | /// CHECK-DAG: LoadClass |
| 268 | /// CHECK-DAG: ClinitCheck |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 269 | /// CHECK-NOT: InvokeStaticOrDirect |
Roland Levillain | 5f02c6c | 2015-04-24 19:14:22 +0100 | [diff] [blame] | 270 | |
| 271 | static class ClassWithClinit5 { |
| 272 | static void $opt$inline$StaticMethod() { |
| 273 | } |
| 274 | |
| 275 | static { |
| 276 | System.out.println("Main$ClassWithClinit5's static initializer"); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | static class SubClassOfClassWithClinit5 extends ClassWithClinit5 { |
| 281 | static void invokeStaticInlined() { |
| 282 | ClassWithClinit5.$opt$inline$StaticMethod(); |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | /* |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 287 | * Ensure an inlined call to a static method whose declaring class is a super class |
| 288 | * of the caller's class does not require an explicit clinit check if the declaring |
| 289 | * class has a trivial initialization. b/62478025 |
| 290 | */ |
| 291 | |
| 292 | /// CHECK-START: void Main$SubClassOfClassWithoutClinit5.invokeStaticInlined() builder (after) |
| 293 | /// CHECK-DAG: InvokeStaticOrDirect |
| 294 | |
| 295 | /// CHECK-START: void Main$SubClassOfClassWithoutClinit5.invokeStaticInlined() builder (after) |
| 296 | /// CHECK-NOT: LoadClass |
| 297 | /// CHECK-NOT: ClinitCheck |
| 298 | |
| 299 | /// CHECK-START: void Main$SubClassOfClassWithoutClinit5.invokeStaticInlined() inliner (after) |
| 300 | /// CHECK-NOT: LoadClass |
| 301 | /// CHECK-NOT: ClinitCheck |
| 302 | /// CHECK-NOT: InvokeStaticOrDirect |
| 303 | |
| 304 | static class ClassWithoutClinit5 { // Mimicks ClassWithClinit5 but without the <clinit>. |
| 305 | static void $opt$inline$StaticMethod() { |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | static class SubClassOfClassWithoutClinit5 extends ClassWithoutClinit5 { |
| 310 | static { |
| 311 | System.out.println("Main$SubClassOfClassWithoutClinit5's static initializer"); |
| 312 | } |
| 313 | |
| 314 | static void invokeStaticInlined() { |
| 315 | ClassWithoutClinit5.$opt$inline$StaticMethod(); |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | /* |
Vladimir Marko | 51b8aaf | 2017-06-09 15:17:05 +0100 | [diff] [blame] | 320 | * We used to remove clinit check for calls to static methods in a superclass. However, this |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 321 | * is not a valid optimization when instances of erroneous classes can escape, therefore |
| 322 | * we avoid this optimization for classes with non-trivial initialization. b/62478025 |
Roland Levillain | 5f02c6c | 2015-04-24 19:14:22 +0100 | [diff] [blame] | 323 | */ |
| 324 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 325 | /// CHECK-START: void Main$SubClassOfClassWithClinit6.invokeStaticNotInlined() builder (after) |
| 326 | /// CHECK-DAG: InvokeStaticOrDirect |
Roland Levillain | 5f02c6c | 2015-04-24 19:14:22 +0100 | [diff] [blame] | 327 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 328 | /// CHECK-START: void Main$SubClassOfClassWithClinit6.invokeStaticNotInlined() builder (after) |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 329 | /// CHECK-DAG: LoadClass |
| 330 | /// CHECK-DAG: ClinitCheck |
Roland Levillain | 5f02c6c | 2015-04-24 19:14:22 +0100 | [diff] [blame] | 331 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 332 | /// CHECK-START: void Main$SubClassOfClassWithClinit6.invokeStaticNotInlined() inliner (after) |
Vladimir Marko | 51b8aaf | 2017-06-09 15:17:05 +0100 | [diff] [blame] | 333 | /// CHECK-DAG: LoadClass |
| 334 | /// CHECK-DAG: ClinitCheck |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 335 | /// CHECK-DAG: InvokeStaticOrDirect |
Roland Levillain | 5f02c6c | 2015-04-24 19:14:22 +0100 | [diff] [blame] | 336 | |
Roland Levillain | 5f02c6c | 2015-04-24 19:14:22 +0100 | [diff] [blame] | 337 | static class ClassWithClinit6 { |
Guillaume "Vermeille" Sanchez | e918d38 | 2015-06-03 15:32:41 +0100 | [diff] [blame] | 338 | static void $noinline$staticMethod() { |
Roland Levillain | 5f02c6c | 2015-04-24 19:14:22 +0100 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | static { |
| 342 | System.out.println("Main$ClassWithClinit6's static initializer"); |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | static class SubClassOfClassWithClinit6 extends ClassWithClinit6 { |
| 347 | static void invokeStaticNotInlined() { |
Guillaume "Vermeille" Sanchez | e918d38 | 2015-06-03 15:32:41 +0100 | [diff] [blame] | 348 | ClassWithClinit6.$noinline$staticMethod(); |
Roland Levillain | 5f02c6c | 2015-04-24 19:14:22 +0100 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 352 | /* |
| 353 | * Ensure a non-inlined call to a static method whose declaring class is a super class |
| 354 | * of the caller's class does not require an explicit clinit check if the declaring |
| 355 | * class has a trivial initialization. b/62478025 |
| 356 | */ |
| 357 | |
| 358 | /// CHECK-START: void Main$SubClassOfClassWithoutClinit6.invokeStaticNotInlined() builder (after) |
| 359 | /// CHECK-DAG: InvokeStaticOrDirect |
| 360 | |
| 361 | /// CHECK-START: void Main$SubClassOfClassWithoutClinit6.invokeStaticNotInlined() builder (after) |
| 362 | /// CHECK-NOT: LoadClass |
| 363 | /// CHECK-NOT: ClinitCheck |
| 364 | |
| 365 | /// CHECK-START: void Main$SubClassOfClassWithoutClinit6.invokeStaticNotInlined() inliner (after) |
| 366 | /// CHECK-DAG: InvokeStaticOrDirect |
| 367 | |
| 368 | /// CHECK-START: void Main$SubClassOfClassWithoutClinit6.invokeStaticNotInlined() inliner (after) |
| 369 | /// CHECK-NOT: LoadClass |
| 370 | /// CHECK-NOT: ClinitCheck |
| 371 | |
| 372 | static class ClassWithoutClinit6 { // Mimicks ClassWithClinit6 but without the <clinit>. |
| 373 | static void $noinline$staticMethod() { |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | static class SubClassOfClassWithoutClinit6 extends ClassWithoutClinit6 { |
| 378 | static { |
| 379 | System.out.println("Main$SubClassOfClassWithoutClinit6's static initializer"); |
| 380 | } |
| 381 | |
| 382 | static void invokeStaticNotInlined() { |
| 383 | ClassWithoutClinit6.$noinline$staticMethod(); |
| 384 | } |
| 385 | } |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 386 | |
| 387 | /* |
| 388 | * Verify that if we have a static call immediately after the load class |
| 389 | * we don't do generate a clinit check. |
| 390 | */ |
| 391 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 392 | /// CHECK-START: void Main.noClinitBecauseOfInvokeStatic() liveness (before) |
| 393 | /// CHECK-DAG: <<IntConstant:i\d+>> IntConstant 0 |
| 394 | /// CHECK-DAG: <<LoadClass:l\d+>> LoadClass gen_clinit_check:false |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 395 | /// CHECK-DAG: InvokeStaticOrDirect clinit_check:implicit |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 396 | /// CHECK-DAG: StaticFieldSet [<<LoadClass>>,<<IntConstant>>] |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 397 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 398 | /// CHECK-START: void Main.noClinitBecauseOfInvokeStatic() liveness (before) |
| 399 | /// CHECK-NOT: ClinitCheck |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 400 | |
| 401 | static void noClinitBecauseOfInvokeStatic() { |
Guillaume "Vermeille" Sanchez | e918d38 | 2015-06-03 15:32:41 +0100 | [diff] [blame] | 402 | ClassWithClinit2.$noinline$staticMethod(); |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 403 | ClassWithClinit2.staticField = false; |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | /* |
| 407 | * Verify that if the static call is after a field access, the load class |
| 408 | * will generate a clinit check. |
| 409 | */ |
| 410 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 411 | /// CHECK-START: void Main.clinitBecauseOfFieldAccess() liveness (before) |
| 412 | /// CHECK-DAG: <<IntConstant:i\d+>> IntConstant 0 |
| 413 | /// CHECK-DAG: <<LoadClass:l\d+>> LoadClass gen_clinit_check:true |
| 414 | /// CHECK-DAG: StaticFieldSet [<<LoadClass>>,<<IntConstant>>] |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 415 | /// CHECK-DAG: InvokeStaticOrDirect clinit_check:none |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 416 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 417 | /// CHECK-START: void Main.clinitBecauseOfFieldAccess() liveness (before) |
| 418 | /// CHECK-NOT: ClinitCheck |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 419 | static void clinitBecauseOfFieldAccess() { |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 420 | ClassWithClinit2.staticField = false; |
Guillaume "Vermeille" Sanchez | e918d38 | 2015-06-03 15:32:41 +0100 | [diff] [blame] | 421 | ClassWithClinit2.$noinline$staticMethod(); |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 422 | } |
| 423 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 424 | /* |
| 425 | * Verify that LoadClass from const-class is not merged with |
| 426 | * later invoke-static (or it's ClinitCheck). |
| 427 | */ |
| 428 | |
| 429 | /// CHECK-START: void Main.constClassAndInvokeStatic(java.lang.Iterable) liveness (before) |
| 430 | /// CHECK: LoadClass gen_clinit_check:false |
| 431 | /// CHECK: InvokeStaticOrDirect clinit_check:implicit |
| 432 | |
| 433 | /// CHECK-START: void Main.constClassAndInvokeStatic(java.lang.Iterable) liveness (before) |
| 434 | /// CHECK-NOT: ClinitCheck |
| 435 | |
Vladimir Marko | c7591b4 | 2016-06-29 14:59:07 +0100 | [diff] [blame] | 436 | static void constClassAndInvokeStatic(Iterable<?> it) { |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 437 | $opt$inline$ignoreClass(ClassWithClinit7.class); |
Nicolas Geoffray | 5bf7bac | 2016-07-06 14:18:23 +0000 | [diff] [blame] | 438 | ClassWithClinit7.$noinline$someStaticMethod(it); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 439 | } |
| 440 | |
Vladimir Marko | c7591b4 | 2016-06-29 14:59:07 +0100 | [diff] [blame] | 441 | static void $opt$inline$ignoreClass(Class<?> c) { |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | static class ClassWithClinit7 { |
| 445 | static { |
| 446 | System.out.println("Main$ClassWithClinit7's static initializer"); |
| 447 | } |
| 448 | |
Nicolas Geoffray | 5bf7bac | 2016-07-06 14:18:23 +0000 | [diff] [blame] | 449 | static void $noinline$someStaticMethod(Iterable<?> it) { |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 450 | it.iterator(); |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | /* |
| 455 | * Verify that LoadClass from sget is not merged with later invoke-static. |
| 456 | */ |
| 457 | |
| 458 | /// CHECK-START: void Main.sgetAndInvokeStatic(java.lang.Iterable) liveness (before) |
| 459 | /// CHECK: LoadClass gen_clinit_check:true |
| 460 | /// CHECK: InvokeStaticOrDirect clinit_check:none |
| 461 | |
| 462 | /// CHECK-START: void Main.sgetAndInvokeStatic(java.lang.Iterable) liveness (before) |
| 463 | /// CHECK-NOT: ClinitCheck |
| 464 | |
Vladimir Marko | c7591b4 | 2016-06-29 14:59:07 +0100 | [diff] [blame] | 465 | static void sgetAndInvokeStatic(Iterable<?> it) { |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 466 | $opt$inline$ignoreInt(ClassWithClinit8.value); |
Nicolas Geoffray | 5bf7bac | 2016-07-06 14:18:23 +0000 | [diff] [blame] | 467 | ClassWithClinit8.$noinline$someStaticMethod(it); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | static void $opt$inline$ignoreInt(int i) { |
| 471 | } |
| 472 | |
| 473 | static class ClassWithClinit8 { |
| 474 | public static int value = 0; |
| 475 | static { |
| 476 | System.out.println("Main$ClassWithClinit8's static initializer"); |
| 477 | } |
| 478 | |
Nicolas Geoffray | 5bf7bac | 2016-07-06 14:18:23 +0000 | [diff] [blame] | 479 | static void $noinline$someStaticMethod(Iterable<?> it) { |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 480 | it.iterator(); |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | /* |
| 485 | * Verify that LoadClass from const-class, ClinitCheck from sget and |
| 486 | * InvokeStaticOrDirect from invoke-static are not merged. |
| 487 | */ |
| 488 | |
| 489 | /// CHECK-START: void Main.constClassSgetAndInvokeStatic(java.lang.Iterable) liveness (before) |
| 490 | /// CHECK: LoadClass gen_clinit_check:false |
| 491 | /// CHECK: ClinitCheck |
| 492 | /// CHECK: InvokeStaticOrDirect clinit_check:none |
| 493 | |
Vladimir Marko | c7591b4 | 2016-06-29 14:59:07 +0100 | [diff] [blame] | 494 | static void constClassSgetAndInvokeStatic(Iterable<?> it) { |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 495 | $opt$inline$ignoreClass(ClassWithClinit9.class); |
| 496 | $opt$inline$ignoreInt(ClassWithClinit9.value); |
Nicolas Geoffray | 5bf7bac | 2016-07-06 14:18:23 +0000 | [diff] [blame] | 497 | ClassWithClinit9.$noinline$someStaticMethod(it); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | static class ClassWithClinit9 { |
| 501 | public static int value = 0; |
| 502 | static { |
| 503 | System.out.println("Main$ClassWithClinit9's static initializer"); |
| 504 | } |
| 505 | |
Nicolas Geoffray | 5bf7bac | 2016-07-06 14:18:23 +0000 | [diff] [blame] | 506 | static void $noinline$someStaticMethod(Iterable<?> it) { |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 507 | it.iterator(); |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | /* |
| 512 | * Verify that LoadClass from a fully-inlined invoke-static is not merged |
| 513 | * with InvokeStaticOrDirect from a later invoke-static to the same method. |
| 514 | */ |
| 515 | |
| 516 | /// CHECK-START: void Main.inlinedInvokeStaticViaNonStatic(java.lang.Iterable) liveness (before) |
| 517 | /// CHECK: LoadClass gen_clinit_check:true |
| 518 | /// CHECK: InvokeStaticOrDirect clinit_check:none |
| 519 | |
| 520 | /// CHECK-START: void Main.inlinedInvokeStaticViaNonStatic(java.lang.Iterable) liveness (before) |
| 521 | /// CHECK-NOT: ClinitCheck |
| 522 | |
Vladimir Marko | c7591b4 | 2016-06-29 14:59:07 +0100 | [diff] [blame] | 523 | static void inlinedInvokeStaticViaNonStatic(Iterable<?> it) { |
Nicolas Geoffray | fdb7d63 | 2017-02-08 15:07:18 +0000 | [diff] [blame] | 524 | if (it != null) { |
| 525 | inlinedInvokeStaticViaNonStaticHelper(null); |
| 526 | inlinedInvokeStaticViaNonStaticHelper(it); |
| 527 | } |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 528 | } |
| 529 | |
Vladimir Marko | c7591b4 | 2016-06-29 14:59:07 +0100 | [diff] [blame] | 530 | static void inlinedInvokeStaticViaNonStaticHelper(Iterable<?> it) { |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 531 | ClassWithClinit10.inlinedForNull(it); |
| 532 | } |
| 533 | |
| 534 | static class ClassWithClinit10 { |
| 535 | public static int value = 0; |
| 536 | static { |
| 537 | System.out.println("Main$ClassWithClinit10's static initializer"); |
| 538 | } |
| 539 | |
Vladimir Marko | c7591b4 | 2016-06-29 14:59:07 +0100 | [diff] [blame] | 540 | static void inlinedForNull(Iterable<?> it) { |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 541 | if (it != null) { |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 542 | it.iterator(); |
Nicolas Geoffray | fdb7d63 | 2017-02-08 15:07:18 +0000 | [diff] [blame] | 543 | // We're not inlining methods that always throw. |
| 544 | throw new Error(""); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 545 | } |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | /* |
| 550 | * Check that the LoadClass from an invoke-static C.foo() doesn't get merged with |
| 551 | * an invoke-static inside C.foo(). This would mess up the stack walk in the |
| 552 | * resolution trampoline where we would have to load C (if C isn't loaded yet) |
| 553 | * which is not permitted there. |
| 554 | * |
| 555 | * Note: In case of failure, we would get an failed assertion during compilation, |
| 556 | * so we wouldn't really get to the checker tests below. |
| 557 | */ |
| 558 | |
| 559 | /// CHECK-START: void Main.inlinedInvokeStaticViaStatic(java.lang.Iterable) liveness (before) |
| 560 | /// CHECK: LoadClass gen_clinit_check:true |
| 561 | /// CHECK: InvokeStaticOrDirect clinit_check:none |
| 562 | |
| 563 | /// CHECK-START: void Main.inlinedInvokeStaticViaStatic(java.lang.Iterable) liveness (before) |
| 564 | /// CHECK-NOT: ClinitCheck |
| 565 | |
Vladimir Marko | c7591b4 | 2016-06-29 14:59:07 +0100 | [diff] [blame] | 566 | static void inlinedInvokeStaticViaStatic(Iterable<?> it) { |
Nicolas Geoffray | fdb7d63 | 2017-02-08 15:07:18 +0000 | [diff] [blame] | 567 | if (it != null) { |
| 568 | ClassWithClinit11.callInlinedForNull(it); |
| 569 | } |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | static class ClassWithClinit11 { |
| 573 | public static int value = 0; |
| 574 | static { |
| 575 | System.out.println("Main$ClassWithClinit11's static initializer"); |
| 576 | } |
| 577 | |
Vladimir Marko | c7591b4 | 2016-06-29 14:59:07 +0100 | [diff] [blame] | 578 | static void callInlinedForNull(Iterable<?> it) { |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 579 | inlinedForNull(it); |
| 580 | } |
| 581 | |
Vladimir Marko | c7591b4 | 2016-06-29 14:59:07 +0100 | [diff] [blame] | 582 | static void inlinedForNull(Iterable<?> it) { |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 583 | it.iterator(); |
Nicolas Geoffray | 5bf7bac | 2016-07-06 14:18:23 +0000 | [diff] [blame] | 584 | if (it != null) { |
Nicolas Geoffray | fdb7d63 | 2017-02-08 15:07:18 +0000 | [diff] [blame] | 585 | // We're not inlining methods that always throw. |
| 586 | throw new Error(""); |
Nicolas Geoffray | 5bf7bac | 2016-07-06 14:18:23 +0000 | [diff] [blame] | 587 | } |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 588 | } |
| 589 | } |
| 590 | |
| 591 | /* |
| 592 | * A test similar to inlinedInvokeStaticViaStatic() but doing the indirect invoke |
| 593 | * twice with the first one to be fully inlined. |
| 594 | */ |
| 595 | |
| 596 | /// CHECK-START: void Main.inlinedInvokeStaticViaStaticTwice(java.lang.Iterable) liveness (before) |
| 597 | /// CHECK: LoadClass gen_clinit_check:true |
| 598 | /// CHECK: InvokeStaticOrDirect clinit_check:none |
| 599 | |
| 600 | /// CHECK-START: void Main.inlinedInvokeStaticViaStaticTwice(java.lang.Iterable) liveness (before) |
| 601 | /// CHECK-NOT: ClinitCheck |
| 602 | |
Vladimir Marko | c7591b4 | 2016-06-29 14:59:07 +0100 | [diff] [blame] | 603 | static void inlinedInvokeStaticViaStaticTwice(Iterable<?> it) { |
Nicolas Geoffray | fdb7d63 | 2017-02-08 15:07:18 +0000 | [diff] [blame] | 604 | if (it != null) { |
| 605 | ClassWithClinit12.callInlinedForNull(null); |
| 606 | ClassWithClinit12.callInlinedForNull(it); |
| 607 | } |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | static class ClassWithClinit12 { |
| 611 | public static int value = 0; |
| 612 | static { |
| 613 | System.out.println("Main$ClassWithClinit12's static initializer"); |
| 614 | } |
| 615 | |
Vladimir Marko | c7591b4 | 2016-06-29 14:59:07 +0100 | [diff] [blame] | 616 | static void callInlinedForNull(Iterable<?> it) { |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 617 | inlinedForNull(it); |
| 618 | } |
| 619 | |
Vladimir Marko | c7591b4 | 2016-06-29 14:59:07 +0100 | [diff] [blame] | 620 | static void inlinedForNull(Iterable<?> it) { |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 621 | if (it != null) { |
Nicolas Geoffray | fdb7d63 | 2017-02-08 15:07:18 +0000 | [diff] [blame] | 622 | // We're not inlining methods that always throw. |
| 623 | throw new Error(""); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 624 | } |
| 625 | } |
| 626 | } |
| 627 | |
Vladimir Marko | c7591b4 | 2016-06-29 14:59:07 +0100 | [diff] [blame] | 628 | static class ClassWithClinit13 { |
| 629 | static { |
| 630 | System.out.println("Main$ClassWithClinit13's static initializer"); |
| 631 | } |
| 632 | |
| 633 | public static void $inline$forwardToGetIterator(Iterable<?> it) { |
| 634 | $noinline$getIterator(it); |
| 635 | } |
| 636 | |
| 637 | public static void $noinline$getIterator(Iterable<?> it) { |
Vladimir Marko | c7591b4 | 2016-06-29 14:59:07 +0100 | [diff] [blame] | 638 | it.iterator(); |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | // TODO: Write checker statements. |
| 643 | static Object $noinline$testInliningAndNewInstance(Iterable<?> it) { |
Vladimir Marko | c7591b4 | 2016-06-29 14:59:07 +0100 | [diff] [blame] | 644 | ClassWithClinit13.$inline$forwardToGetIterator(it); |
| 645 | return new ClassWithClinit13(); |
| 646 | } |
| 647 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 648 | // TODO: Add a test for the case of a static method whose declaring |
| 649 | // class type index is not available (i.e. when `storage_index` |
Andreas Gampe | e2abbc6 | 2017-09-15 11:59:26 -0700 | [diff] [blame] | 650 | // equals `dex::kDexNoIndex` in |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 651 | // art::HGraphBuilder::BuildInvoke). |
| 652 | |
| 653 | public static void main(String[] args) { |
| 654 | invokeStaticInlined(); |
| 655 | invokeStaticNotInlined(); |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 656 | ClassWithClinit3Static.invokeStaticInlined(); |
| 657 | new ClassWithClinit3Instance().invokeStaticInlined(); |
| 658 | ClassWithClinit4Static.invokeStaticNotInlined(); |
| 659 | new ClassWithClinit4Instance().invokeStaticNotInlined(); |
Roland Levillain | 5f02c6c | 2015-04-24 19:14:22 +0100 | [diff] [blame] | 660 | SubClassOfClassWithClinit5.invokeStaticInlined(); |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 661 | SubClassOfClassWithoutClinit5.invokeStaticInlined(); |
Roland Levillain | 5f02c6c | 2015-04-24 19:14:22 +0100 | [diff] [blame] | 662 | SubClassOfClassWithClinit6.invokeStaticNotInlined(); |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 663 | SubClassOfClassWithoutClinit6.invokeStaticNotInlined(); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 664 | Iterable it = new Iterable() { public java.util.Iterator iterator() { return null; } }; |
| 665 | constClassAndInvokeStatic(it); |
| 666 | sgetAndInvokeStatic(it); |
| 667 | constClassSgetAndInvokeStatic(it); |
Nicolas Geoffray | fdb7d63 | 2017-02-08 15:07:18 +0000 | [diff] [blame] | 668 | try { |
| 669 | inlinedInvokeStaticViaNonStatic(it); |
| 670 | } catch (Error e) { |
| 671 | // Expected |
| 672 | } |
| 673 | try { |
| 674 | inlinedInvokeStaticViaStatic(it); |
| 675 | } catch (Error e) { |
| 676 | // Expected |
| 677 | } |
| 678 | try{ |
| 679 | inlinedInvokeStaticViaStaticTwice(it); |
| 680 | } catch (Error e) { |
| 681 | // Expected |
| 682 | } |
Vladimir Marko | c7591b4 | 2016-06-29 14:59:07 +0100 | [diff] [blame] | 683 | $noinline$testInliningAndNewInstance(it); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 684 | } |
| 685 | } |