From cac5a7e871f1f346b317894359ad06fa7bd67fba Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Mon, 22 Feb 2016 10:39:50 +0000 Subject: Optimizing: Improve const-string code generation. For strings in the boot image, use either direct pointers or pc-relative addresses. For other strings, use PC-relative access to the dex cache arrays for AOT and direct address of the string's dex cache slot for JIT. For aosp_flounder-userdebug: - 32-bit boot.oat: -692KiB (-0.9%) - 64-bit boot.oat: -948KiB (-1.1%) - 32-bit dalvik cache total: -900KiB (-0.9%) - 64-bit dalvik cache total: -3672KiB (-1.5%) (contains more files than the 32-bit dalvik cache) For aosp_flounder-userdebug forced to compile PIC: - 32-bit boot.oat: -380KiB (-0.5%) - 64-bit boot.oat: -928KiB (-1.0%) - 32-bit dalvik cache total: -468KiB (-0.4%) - 64-bit dalvik cache total: -1928KiB (-0.8%) (contains more files than the 32-bit dalvik cache) Bug: 26884697 Change-Id: Iec7266ce67e6fedc107be78fab2e742a8dab2696 --- test/552-checker-sharpening/src/Main.java | 68 +++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'test/552-checker-sharpening/src/Main.java') diff --git a/test/552-checker-sharpening/src/Main.java b/test/552-checker-sharpening/src/Main.java index d50edd8f2f..3d985bfaf0 100644 --- a/test/552-checker-sharpening/src/Main.java +++ b/test/552-checker-sharpening/src/Main.java @@ -22,6 +22,12 @@ public class Main { } } + public static void assertStringEquals(String expected, String result) { + if (expected != null ? !expected.equals(result) : result != null) { + throw new Error("Expected: " + expected + ", found: " + result); + } + } + public static boolean doThrow = false; private static int $noinline$foo(int x) { @@ -185,6 +191,66 @@ public class Main { return x; } + /// CHECK-START: java.lang.String Main.$noinline$getBootImageString() sharpening (before) + /// CHECK: LoadString load_kind:DexCacheViaMethod + + /// CHECK-START-X86: java.lang.String Main.$noinline$getBootImageString() sharpening (after) + // Note: load kind depends on PIC/non-PIC + // TODO: Remove DexCacheViaMethod when read barrier config supports BootImageAddress. + /// CHECK: LoadString load_kind:{{BootImageAddress|DexCachePcRelative|DexCacheViaMethod}} + + /// CHECK-START-X86_64: java.lang.String Main.$noinline$getBootImageString() sharpening (after) + // Note: load kind depends on PIC/non-PIC + // TODO: Remove DexCacheViaMethod when read barrier config supports BootImageAddress. + /// CHECK: LoadString load_kind:{{BootImageAddress|DexCachePcRelative|DexCacheViaMethod}} + + /// CHECK-START-ARM: java.lang.String Main.$noinline$getBootImageString() sharpening (after) + // Note: load kind depends on PIC/non-PIC + // TODO: Remove DexCacheViaMethod when read barrier config supports BootImageAddress. + /// CHECK: LoadString load_kind:{{BootImageAddress|DexCachePcRelative|DexCacheViaMethod}} + + /// CHECK-START-ARM64: java.lang.String Main.$noinline$getBootImageString() sharpening (after) + // Note: load kind depends on PIC/non-PIC + // TODO: Remove DexCacheViaMethod when read barrier config supports BootImageAddress. + /// CHECK: LoadString load_kind:{{BootImageAddress|DexCachePcRelative|DexCacheViaMethod}} + + public static String $noinline$getBootImageString() { + // Prevent inlining to avoid the string comparison being optimized away. + if (doThrow) { throw new Error(); } + // Empty string is known to be in the boot image. + return ""; + } + + /// CHECK-START: java.lang.String Main.$noinline$getNonBootImageString() sharpening (before) + /// CHECK: LoadString load_kind:DexCacheViaMethod + + /// CHECK-START-X86: java.lang.String Main.$noinline$getNonBootImageString() sharpening (after) + /// CHECK: LoadString load_kind:DexCachePcRelative + + /// CHECK-START-X86: java.lang.String Main.$noinline$getNonBootImageString() pc_relative_fixups_x86 (after) + /// CHECK-DAG: X86ComputeBaseMethodAddress + /// CHECK-DAG: LoadString load_kind:DexCachePcRelative + + /// CHECK-START-X86_64: java.lang.String Main.$noinline$getNonBootImageString() sharpening (after) + /// CHECK: LoadString load_kind:DexCachePcRelative + + /// CHECK-START-ARM: java.lang.String Main.$noinline$getNonBootImageString() sharpening (after) + /// CHECK: LoadString load_kind:DexCachePcRelative + + /// CHECK-START-ARM: java.lang.String Main.$noinline$getNonBootImageString() dex_cache_array_fixups_arm (after) + /// CHECK-DAG: ArmDexCacheArraysBase + /// CHECK-DAG: LoadString load_kind:DexCachePcRelative + + /// CHECK-START-ARM64: java.lang.String Main.$noinline$getNonBootImageString() sharpening (after) + /// CHECK: LoadString load_kind:DexCachePcRelative + + public static String $noinline$getNonBootImageString() { + // Prevent inlining to avoid the string comparison being optimized away. + if (doThrow) { throw new Error(); } + // This string is not in the boot image. + return "non-boot-image-string"; + } + public static void main(String[] args) { assertIntEquals(1, testSimple(1)); assertIntEquals(1, testDiamond(false, 1)); @@ -194,5 +260,7 @@ public class Main { assertIntEquals(1, testLoopWithDiamond(null, false, 1)); assertIntEquals(3, testLoopWithDiamond(new int[]{ 2 }, false, 1)); assertIntEquals(-6, testLoopWithDiamond(new int[]{ 3, 4 }, true, 1)); + assertStringEquals("", $noinline$getBootImageString()); + assertStringEquals("non-boot-image-string", $noinline$getNonBootImageString()); } } -- cgit v1.2.3-59-g8ed1b