Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [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 | public static void assertIntEquals(int expected, int result) { |
| 20 | if (expected != result) { |
| 21 | throw new Error("Expected: " + expected + ", found: " + result); |
| 22 | } |
| 23 | } |
| 24 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 25 | public static void assertStringEquals(String expected, String result) { |
| 26 | if (expected != null ? !expected.equals(result) : result != null) { |
| 27 | throw new Error("Expected: " + expected + ", found: " + result); |
| 28 | } |
| 29 | } |
| 30 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 31 | public static void assertClassEquals(Class<?> expected, Class<?> result) { |
| 32 | if (expected != result) { |
| 33 | throw new Error("Expected: " + expected + ", found: " + result); |
| 34 | } |
| 35 | } |
| 36 | |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 37 | public static boolean doThrow = false; |
| 38 | |
| 39 | private static int $noinline$foo(int x) { |
| 40 | if (doThrow) { throw new Error(); } |
| 41 | return x; |
| 42 | } |
| 43 | |
| 44 | /// CHECK-START: int Main.testSimple(int) sharpening (before) |
| 45 | /// CHECK: InvokeStaticOrDirect method_load_kind:dex_cache_via_method |
| 46 | |
| 47 | /// CHECK-START-ARM: int Main.testSimple(int) sharpening (after) |
| 48 | /// CHECK-NOT: ArmDexCacheArraysBase |
| 49 | /// CHECK: InvokeStaticOrDirect method_load_kind:dex_cache_pc_relative |
| 50 | |
| 51 | /// CHECK-START-ARM64: int Main.testSimple(int) sharpening (after) |
| 52 | /// CHECK: InvokeStaticOrDirect method_load_kind:dex_cache_pc_relative |
| 53 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 54 | /// CHECK-START-MIPS: int Main.testSimple(int) sharpening (after) |
| 55 | /// CHECK-NOT: MipsDexCacheArraysBase |
| 56 | /// CHECK: InvokeStaticOrDirect method_load_kind:dex_cache_pc_relative |
| 57 | |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 58 | /// CHECK-START-X86: int Main.testSimple(int) sharpening (after) |
| 59 | /// CHECK-NOT: X86ComputeBaseMethodAddress |
| 60 | /// CHECK: InvokeStaticOrDirect method_load_kind:dex_cache_pc_relative |
| 61 | |
| 62 | /// CHECK-START-X86_64: int Main.testSimple(int) sharpening (after) |
| 63 | /// CHECK: InvokeStaticOrDirect method_load_kind:dex_cache_pc_relative |
| 64 | |
| 65 | /// CHECK-START-ARM: int Main.testSimple(int) dex_cache_array_fixups_arm (after) |
| 66 | /// CHECK: ArmDexCacheArraysBase |
| 67 | /// CHECK-NOT: ArmDexCacheArraysBase |
| 68 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 69 | /// CHECK-START-MIPS: int Main.testSimple(int) dex_cache_array_fixups_mips (after) |
| 70 | /// CHECK: MipsDexCacheArraysBase |
| 71 | /// CHECK-NOT: MipsDexCacheArraysBase |
| 72 | |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 73 | /// CHECK-START-X86: int Main.testSimple(int) pc_relative_fixups_x86 (after) |
| 74 | /// CHECK: X86ComputeBaseMethodAddress |
| 75 | /// CHECK-NOT: X86ComputeBaseMethodAddress |
| 76 | |
| 77 | public static int testSimple(int x) { |
| 78 | // This call should use PC-relative dex cache array load to retrieve the target method. |
| 79 | return $noinline$foo(x); |
| 80 | } |
| 81 | |
| 82 | /// CHECK-START: int Main.testDiamond(boolean, int) sharpening (before) |
| 83 | /// CHECK: InvokeStaticOrDirect method_load_kind:dex_cache_via_method |
| 84 | |
| 85 | /// CHECK-START-ARM: int Main.testDiamond(boolean, int) sharpening (after) |
| 86 | /// CHECK-NOT: ArmDexCacheArraysBase |
| 87 | /// CHECK: InvokeStaticOrDirect method_load_kind:dex_cache_pc_relative |
| 88 | /// CHECK: InvokeStaticOrDirect method_load_kind:dex_cache_pc_relative |
| 89 | |
| 90 | /// CHECK-START-ARM64: int Main.testDiamond(boolean, int) sharpening (after) |
| 91 | /// CHECK: InvokeStaticOrDirect method_load_kind:dex_cache_pc_relative |
| 92 | /// CHECK: InvokeStaticOrDirect method_load_kind:dex_cache_pc_relative |
| 93 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 94 | /// CHECK-START-MIPS: int Main.testDiamond(boolean, int) sharpening (after) |
| 95 | /// CHECK-NOT: MipsDexCacheArraysBase |
| 96 | /// CHECK: InvokeStaticOrDirect method_load_kind:dex_cache_pc_relative |
| 97 | /// CHECK: InvokeStaticOrDirect method_load_kind:dex_cache_pc_relative |
| 98 | |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 99 | /// CHECK-START-X86: int Main.testDiamond(boolean, int) sharpening (after) |
| 100 | /// CHECK-NOT: X86ComputeBaseMethodAddress |
| 101 | /// CHECK: InvokeStaticOrDirect method_load_kind:dex_cache_pc_relative |
| 102 | /// CHECK: InvokeStaticOrDirect method_load_kind:dex_cache_pc_relative |
| 103 | |
| 104 | /// CHECK-START-X86_64: int Main.testDiamond(boolean, int) sharpening (after) |
| 105 | /// CHECK: InvokeStaticOrDirect method_load_kind:dex_cache_pc_relative |
| 106 | /// CHECK: InvokeStaticOrDirect method_load_kind:dex_cache_pc_relative |
| 107 | |
| 108 | /// CHECK-START-ARM: int Main.testDiamond(boolean, int) dex_cache_array_fixups_arm (after) |
| 109 | /// CHECK: ArmDexCacheArraysBase |
| 110 | /// CHECK-NOT: ArmDexCacheArraysBase |
| 111 | |
| 112 | /// CHECK-START-ARM: int Main.testDiamond(boolean, int) dex_cache_array_fixups_arm (after) |
| 113 | /// CHECK: ArmDexCacheArraysBase |
| 114 | /// CHECK-NEXT: If |
| 115 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 116 | /// CHECK-START-MIPS: int Main.testDiamond(boolean, int) dex_cache_array_fixups_mips (after) |
| 117 | /// CHECK: MipsDexCacheArraysBase |
| 118 | /// CHECK-NOT: MipsDexCacheArraysBase |
| 119 | |
| 120 | /// CHECK-START-MIPS: int Main.testDiamond(boolean, int) dex_cache_array_fixups_mips (after) |
| 121 | /// CHECK: MipsDexCacheArraysBase |
| 122 | /// CHECK-NEXT: If |
| 123 | |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 124 | /// CHECK-START-X86: int Main.testDiamond(boolean, int) pc_relative_fixups_x86 (after) |
| 125 | /// CHECK: X86ComputeBaseMethodAddress |
| 126 | /// CHECK-NOT: X86ComputeBaseMethodAddress |
| 127 | |
| 128 | /// CHECK-START-X86: int Main.testDiamond(boolean, int) pc_relative_fixups_x86 (after) |
| 129 | /// CHECK: X86ComputeBaseMethodAddress |
| 130 | /// CHECK-NEXT: If |
| 131 | |
| 132 | public static int testDiamond(boolean negate, int x) { |
| 133 | // These calls should use PC-relative dex cache array loads to retrieve the target method. |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 134 | // PC-relative bases used by ARM, MIPS and X86 should be pulled before the If. |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 135 | if (negate) { |
| 136 | return $noinline$foo(-x); |
| 137 | } else { |
| 138 | return $noinline$foo(x); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | /// CHECK-START-X86: int Main.testLoop(int[], int) pc_relative_fixups_x86 (before) |
| 143 | /// CHECK-NOT: X86ComputeBaseMethodAddress |
| 144 | |
| 145 | /// CHECK-START-X86: int Main.testLoop(int[], int) pc_relative_fixups_x86 (after) |
| 146 | /// CHECK: X86ComputeBaseMethodAddress |
| 147 | /// CHECK-NOT: X86ComputeBaseMethodAddress |
| 148 | |
| 149 | /// CHECK-START-X86: int Main.testLoop(int[], int) pc_relative_fixups_x86 (after) |
| 150 | /// CHECK: InvokeStaticOrDirect |
| 151 | /// CHECK-NOT: InvokeStaticOrDirect |
| 152 | |
| 153 | /// CHECK-START-X86: int Main.testLoop(int[], int) pc_relative_fixups_x86 (after) |
| 154 | /// CHECK: ArrayLength |
| 155 | /// CHECK-NEXT: X86ComputeBaseMethodAddress |
| 156 | /// CHECK-NEXT: Goto |
| 157 | /// CHECK: begin_block |
| 158 | /// CHECK: InvokeStaticOrDirect method_load_kind:dex_cache_pc_relative |
| 159 | |
| 160 | /// CHECK-START-ARM: int Main.testLoop(int[], int) dex_cache_array_fixups_arm (before) |
| 161 | /// CHECK-NOT: ArmDexCacheArraysBase |
| 162 | |
| 163 | /// CHECK-START-ARM: int Main.testLoop(int[], int) dex_cache_array_fixups_arm (after) |
| 164 | /// CHECK: ArmDexCacheArraysBase |
| 165 | /// CHECK-NOT: ArmDexCacheArraysBase |
| 166 | |
| 167 | /// CHECK-START-ARM: int Main.testLoop(int[], int) dex_cache_array_fixups_arm (after) |
| 168 | /// CHECK: InvokeStaticOrDirect |
| 169 | /// CHECK-NOT: InvokeStaticOrDirect |
| 170 | |
| 171 | /// CHECK-START-ARM: int Main.testLoop(int[], int) dex_cache_array_fixups_arm (after) |
| 172 | /// CHECK: ArrayLength |
| 173 | /// CHECK-NEXT: ArmDexCacheArraysBase |
| 174 | /// CHECK-NEXT: Goto |
| 175 | /// CHECK: begin_block |
| 176 | /// CHECK: InvokeStaticOrDirect method_load_kind:dex_cache_pc_relative |
| 177 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 178 | /// CHECK-START-MIPS: int Main.testLoop(int[], int) dex_cache_array_fixups_mips (before) |
| 179 | /// CHECK-NOT: MipsDexCacheArraysBase |
| 180 | |
| 181 | /// CHECK-START-MIPS: int Main.testLoop(int[], int) dex_cache_array_fixups_mips (after) |
| 182 | /// CHECK: MipsDexCacheArraysBase |
| 183 | /// CHECK-NOT: MipsDexCacheArraysBase |
| 184 | |
| 185 | /// CHECK-START-MIPS: int Main.testLoop(int[], int) dex_cache_array_fixups_mips (after) |
| 186 | /// CHECK: InvokeStaticOrDirect |
| 187 | /// CHECK-NOT: InvokeStaticOrDirect |
| 188 | |
| 189 | /// CHECK-START-MIPS: int Main.testLoop(int[], int) dex_cache_array_fixups_mips (after) |
| 190 | /// CHECK: ArrayLength |
| 191 | /// CHECK-NEXT: MipsDexCacheArraysBase |
| 192 | /// CHECK-NEXT: Goto |
| 193 | /// CHECK: begin_block |
| 194 | /// CHECK: InvokeStaticOrDirect method_load_kind:dex_cache_pc_relative |
| 195 | |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 196 | public static int testLoop(int[] array, int x) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 197 | // PC-relative bases used by ARM, MIPS and X86 should be pulled before the loop. |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 198 | for (int i : array) { |
| 199 | x += $noinline$foo(i); |
| 200 | } |
| 201 | return x; |
| 202 | } |
| 203 | |
| 204 | /// CHECK-START-X86: int Main.testLoopWithDiamond(int[], boolean, int) pc_relative_fixups_x86 (before) |
| 205 | /// CHECK-NOT: X86ComputeBaseMethodAddress |
| 206 | |
| 207 | /// CHECK-START-X86: int Main.testLoopWithDiamond(int[], boolean, int) pc_relative_fixups_x86 (after) |
| 208 | /// CHECK: If |
| 209 | /// CHECK: begin_block |
| 210 | /// CHECK: ArrayLength |
| 211 | /// CHECK-NEXT: X86ComputeBaseMethodAddress |
| 212 | /// CHECK-NEXT: Goto |
| 213 | |
| 214 | /// CHECK-START-ARM: int Main.testLoopWithDiamond(int[], boolean, int) dex_cache_array_fixups_arm (before) |
| 215 | /// CHECK-NOT: ArmDexCacheArraysBase |
| 216 | |
| 217 | /// CHECK-START-ARM: int Main.testLoopWithDiamond(int[], boolean, int) dex_cache_array_fixups_arm (after) |
| 218 | /// CHECK: If |
| 219 | /// CHECK: begin_block |
| 220 | /// CHECK: ArrayLength |
| 221 | /// CHECK-NEXT: ArmDexCacheArraysBase |
| 222 | /// CHECK-NEXT: Goto |
| 223 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 224 | /// CHECK-START-MIPS: int Main.testLoopWithDiamond(int[], boolean, int) dex_cache_array_fixups_mips (before) |
| 225 | /// CHECK-NOT: MipsDexCacheArraysBase |
| 226 | |
| 227 | /// CHECK-START-MIPS: int Main.testLoopWithDiamond(int[], boolean, int) dex_cache_array_fixups_mips (after) |
| 228 | /// CHECK: If |
| 229 | /// CHECK: begin_block |
| 230 | /// CHECK: ArrayLength |
| 231 | /// CHECK-NEXT: MipsDexCacheArraysBase |
| 232 | /// CHECK-NEXT: Goto |
| 233 | |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 234 | public static int testLoopWithDiamond(int[] array, boolean negate, int x) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 235 | // PC-relative bases used by ARM, MIPS and X86 should be pulled before the loop |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 236 | // but not outside the if. |
| 237 | if (array != null) { |
| 238 | for (int i : array) { |
| 239 | if (negate) { |
| 240 | x += $noinline$foo(-i); |
| 241 | } else { |
| 242 | x += $noinline$foo(i); |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | return x; |
| 247 | } |
| 248 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 249 | /// CHECK-START: java.lang.String Main.$noinline$getBootImageString() sharpening (before) |
| 250 | /// CHECK: LoadString load_kind:DexCacheViaMethod |
| 251 | |
| 252 | /// CHECK-START-X86: java.lang.String Main.$noinline$getBootImageString() sharpening (after) |
| 253 | // Note: load kind depends on PIC/non-PIC |
| 254 | // TODO: Remove DexCacheViaMethod when read barrier config supports BootImageAddress. |
Vladimir Marko | 54d6a20 | 2016-11-09 12:46:38 +0000 | [diff] [blame^] | 255 | /// CHECK: LoadString load_kind:{{BootImageAddress|BssEntry|DexCacheViaMethod}} |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 256 | |
| 257 | /// CHECK-START-X86_64: java.lang.String Main.$noinline$getBootImageString() sharpening (after) |
| 258 | // Note: load kind depends on PIC/non-PIC |
| 259 | // TODO: Remove DexCacheViaMethod when read barrier config supports BootImageAddress. |
Vladimir Marko | 54d6a20 | 2016-11-09 12:46:38 +0000 | [diff] [blame^] | 260 | /// CHECK: LoadString load_kind:{{BootImageAddress|BssEntry|DexCacheViaMethod}} |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 261 | |
| 262 | /// CHECK-START-ARM: java.lang.String Main.$noinline$getBootImageString() sharpening (after) |
| 263 | // Note: load kind depends on PIC/non-PIC |
| 264 | // TODO: Remove DexCacheViaMethod when read barrier config supports BootImageAddress. |
Vladimir Marko | 54d6a20 | 2016-11-09 12:46:38 +0000 | [diff] [blame^] | 265 | /// CHECK: LoadString load_kind:{{BootImageAddress|BssEntry|DexCacheViaMethod}} |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 266 | |
| 267 | /// CHECK-START-ARM64: java.lang.String Main.$noinline$getBootImageString() sharpening (after) |
| 268 | // Note: load kind depends on PIC/non-PIC |
| 269 | // TODO: Remove DexCacheViaMethod when read barrier config supports BootImageAddress. |
Vladimir Marko | 54d6a20 | 2016-11-09 12:46:38 +0000 | [diff] [blame^] | 270 | /// CHECK: LoadString load_kind:{{BootImageAddress|BssEntry|DexCacheViaMethod}} |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 271 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 272 | /// CHECK-START-MIPS: java.lang.String Main.$noinline$getBootImageString() sharpening (after) |
| 273 | // Note: load kind depends on PIC/non-PIC |
| 274 | // TODO: Remove DexCacheViaMethod when read barrier config supports BootImageAddress. |
Vladimir Marko | 54d6a20 | 2016-11-09 12:46:38 +0000 | [diff] [blame^] | 275 | /// CHECK: LoadString load_kind:{{BootImageAddress|BssEntry|DexCacheViaMethod}} |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 276 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 277 | public static String $noinline$getBootImageString() { |
| 278 | // Prevent inlining to avoid the string comparison being optimized away. |
| 279 | if (doThrow) { throw new Error(); } |
| 280 | // Empty string is known to be in the boot image. |
| 281 | return ""; |
| 282 | } |
| 283 | |
| 284 | /// CHECK-START: java.lang.String Main.$noinline$getNonBootImageString() sharpening (before) |
| 285 | /// CHECK: LoadString load_kind:DexCacheViaMethod |
| 286 | |
Vladimir Marko | 1bc4b17 | 2016-10-24 16:53:39 +0000 | [diff] [blame] | 287 | /// CHECK-START-X86: java.lang.String Main.$noinline$getNonBootImageString() sharpening (after) |
| 288 | /// CHECK: LoadString load_kind:BssEntry |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 289 | |
Vladimir Marko | 1bc4b17 | 2016-10-24 16:53:39 +0000 | [diff] [blame] | 290 | /// CHECK-START-X86: java.lang.String Main.$noinline$getNonBootImageString() pc_relative_fixups_x86 (after) |
| 291 | /// CHECK-DAG: X86ComputeBaseMethodAddress |
| 292 | /// CHECK-DAG: LoadString load_kind:BssEntry |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 293 | |
Vladimir Marko | 1bc4b17 | 2016-10-24 16:53:39 +0000 | [diff] [blame] | 294 | /// CHECK-START-X86_64: java.lang.String Main.$noinline$getNonBootImageString() sharpening (after) |
| 295 | /// CHECK: LoadString load_kind:BssEntry |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 296 | |
Vladimir Marko | 1bc4b17 | 2016-10-24 16:53:39 +0000 | [diff] [blame] | 297 | /// CHECK-START-ARM: java.lang.String Main.$noinline$getNonBootImageString() sharpening (after) |
| 298 | /// CHECK: LoadString load_kind:BssEntry |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 299 | |
Vladimir Marko | 1bc4b17 | 2016-10-24 16:53:39 +0000 | [diff] [blame] | 300 | /// CHECK-START-ARM64: java.lang.String Main.$noinline$getNonBootImageString() sharpening (after) |
| 301 | /// CHECK: LoadString load_kind:BssEntry |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 302 | |
Vladimir Marko | 1bc4b17 | 2016-10-24 16:53:39 +0000 | [diff] [blame] | 303 | /// CHECK-START-MIPS: java.lang.String Main.$noinline$getNonBootImageString() sharpening (after) |
| 304 | /// CHECK: LoadString load_kind:BssEntry |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 305 | |
Vladimir Marko | 1bc4b17 | 2016-10-24 16:53:39 +0000 | [diff] [blame] | 306 | /// CHECK-START-MIPS: java.lang.String Main.$noinline$getNonBootImageString() pc_relative_fixups_mips (after) |
| 307 | /// CHECK-DAG: MipsComputeBaseMethodAddress |
| 308 | /// CHECK-DAG: LoadString load_kind:BssEntry |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 309 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 310 | public static String $noinline$getNonBootImageString() { |
| 311 | // Prevent inlining to avoid the string comparison being optimized away. |
| 312 | if (doThrow) { throw new Error(); } |
| 313 | // This string is not in the boot image. |
| 314 | return "non-boot-image-string"; |
| 315 | } |
| 316 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 317 | /// CHECK-START: java.lang.Class Main.$noinline$getStringClass() sharpening (before) |
| 318 | /// CHECK: LoadClass load_kind:DexCacheViaMethod class_name:java.lang.String |
| 319 | |
| 320 | /// CHECK-START-X86: java.lang.Class Main.$noinline$getStringClass() sharpening (after) |
| 321 | // Note: load kind depends on PIC/non-PIC |
| 322 | // TODO: Remove DexCacheViaMethod when read barrier config supports BootImageAddress. |
| 323 | /// CHECK: LoadClass load_kind:{{BootImageAddress|DexCachePcRelative|DexCacheViaMethod}} class_name:java.lang.String |
| 324 | |
| 325 | /// CHECK-START-X86_64: java.lang.Class Main.$noinline$getStringClass() sharpening (after) |
| 326 | // Note: load kind depends on PIC/non-PIC |
| 327 | // TODO: Remove DexCacheViaMethod when read barrier config supports BootImageAddress. |
| 328 | /// CHECK: LoadClass load_kind:{{BootImageAddress|DexCachePcRelative|DexCacheViaMethod}} class_name:java.lang.String |
| 329 | |
| 330 | /// CHECK-START-ARM: java.lang.Class Main.$noinline$getStringClass() sharpening (after) |
| 331 | // Note: load kind depends on PIC/non-PIC |
| 332 | // TODO: Remove DexCacheViaMethod when read barrier config supports BootImageAddress. |
| 333 | /// CHECK: LoadClass load_kind:{{BootImageAddress|DexCachePcRelative|DexCacheViaMethod}} class_name:java.lang.String |
| 334 | |
| 335 | /// CHECK-START-ARM64: java.lang.Class Main.$noinline$getStringClass() sharpening (after) |
| 336 | // Note: load kind depends on PIC/non-PIC |
| 337 | // TODO: Remove DexCacheViaMethod when read barrier config supports BootImageAddress. |
| 338 | /// CHECK: LoadClass load_kind:{{BootImageAddress|DexCachePcRelative|DexCacheViaMethod}} class_name:java.lang.String |
| 339 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 340 | /// CHECK-START-MIPS: java.lang.Class Main.$noinline$getStringClass() sharpening (after) |
| 341 | // Note: load kind depends on PIC/non-PIC |
| 342 | // TODO: Remove DexCacheViaMethod when read barrier config supports BootImageAddress. |
| 343 | /// CHECK: LoadClass load_kind:{{BootImageAddress|DexCachePcRelative|DexCacheViaMethod}} class_name:java.lang.String |
| 344 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 345 | public static Class<?> $noinline$getStringClass() { |
| 346 | // Prevent inlining to avoid the string comparison being optimized away. |
| 347 | if (doThrow) { throw new Error(); } |
| 348 | // String class is known to be in the boot image. |
| 349 | return String.class; |
| 350 | } |
| 351 | |
| 352 | /// CHECK-START: java.lang.Class Main.$noinline$getOtherClass() sharpening (before) |
| 353 | /// CHECK: LoadClass load_kind:DexCacheViaMethod class_name:Other |
| 354 | |
| 355 | /// CHECK-START-X86: java.lang.Class Main.$noinline$getOtherClass() sharpening (after) |
| 356 | /// CHECK: LoadClass load_kind:DexCachePcRelative class_name:Other |
| 357 | |
| 358 | /// CHECK-START-X86: java.lang.Class Main.$noinline$getOtherClass() pc_relative_fixups_x86 (after) |
| 359 | /// CHECK-DAG: X86ComputeBaseMethodAddress |
| 360 | /// CHECK-DAG: LoadClass load_kind:DexCachePcRelative class_name:Other |
| 361 | |
| 362 | /// CHECK-START-X86_64: java.lang.Class Main.$noinline$getOtherClass() sharpening (after) |
| 363 | /// CHECK: LoadClass load_kind:DexCachePcRelative class_name:Other |
| 364 | |
| 365 | /// CHECK-START-ARM: java.lang.Class Main.$noinline$getOtherClass() sharpening (after) |
| 366 | /// CHECK: LoadClass load_kind:DexCachePcRelative class_name:Other |
| 367 | |
| 368 | /// CHECK-START-ARM: java.lang.Class Main.$noinline$getOtherClass() dex_cache_array_fixups_arm (after) |
| 369 | /// CHECK-DAG: ArmDexCacheArraysBase |
| 370 | /// CHECK-DAG: LoadClass load_kind:DexCachePcRelative class_name:Other |
| 371 | |
| 372 | /// CHECK-START-ARM64: java.lang.Class Main.$noinline$getOtherClass() sharpening (after) |
| 373 | /// CHECK: LoadClass load_kind:DexCachePcRelative class_name:Other |
| 374 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 375 | /// CHECK-START-MIPS: java.lang.Class Main.$noinline$getOtherClass() sharpening (after) |
| 376 | /// CHECK: LoadClass load_kind:DexCachePcRelative class_name:Other |
| 377 | |
| 378 | /// CHECK-START-MIPS: java.lang.Class Main.$noinline$getOtherClass() dex_cache_array_fixups_mips (after) |
| 379 | /// CHECK-DAG: MipsDexCacheArraysBase |
| 380 | /// CHECK-DAG: LoadClass load_kind:DexCachePcRelative class_name:Other |
| 381 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 382 | public static Class<?> $noinline$getOtherClass() { |
| 383 | // Prevent inlining to avoid the string comparison being optimized away. |
| 384 | if (doThrow) { throw new Error(); } |
| 385 | // Other class is not in the boot image. |
| 386 | return Other.class; |
| 387 | } |
| 388 | |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 389 | public static void main(String[] args) { |
| 390 | assertIntEquals(1, testSimple(1)); |
| 391 | assertIntEquals(1, testDiamond(false, 1)); |
| 392 | assertIntEquals(-1, testDiamond(true, 1)); |
| 393 | assertIntEquals(3, testLoop(new int[]{ 2 }, 1)); |
| 394 | assertIntEquals(8, testLoop(new int[]{ 3, 4 }, 1)); |
| 395 | assertIntEquals(1, testLoopWithDiamond(null, false, 1)); |
| 396 | assertIntEquals(3, testLoopWithDiamond(new int[]{ 2 }, false, 1)); |
| 397 | assertIntEquals(-6, testLoopWithDiamond(new int[]{ 3, 4 }, true, 1)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 398 | assertStringEquals("", $noinline$getBootImageString()); |
| 399 | assertStringEquals("non-boot-image-string", $noinline$getNonBootImageString()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 400 | assertClassEquals(String.class, $noinline$getStringClass()); |
| 401 | assertClassEquals(Other.class, $noinline$getOtherClass()); |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 402 | } |
| 403 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 404 | |
| 405 | class Other { |
| 406 | } |