diff options
| author | 2017-06-27 23:45:47 +0000 | |
|---|---|---|
| committer | 2017-06-27 23:45:50 +0000 | |
| commit | 133b4a4971a8311d17f4d2f47d7a1a9e510401a6 (patch) | |
| tree | 7bdea59722130fec3fa28192e22d898911604027 | |
| parent | e5232948fb301604480ae129bea9ded4345c1287 (diff) | |
| parent | 0381bed9bc857a4c48b5aecee6f8ab9c468c18de (diff) | |
Merge changes from topic 'art_javac'
* changes:
test: Modify 536-checker-intrinsic-optimization for javac/dx
test: Modify 593-checker-boolean-2-integral-conv for javac/dx
| -rwxr-xr-x | test/536-checker-intrinsic-optimization/build | 23 | ||||
| -rw-r--r-- | test/536-checker-intrinsic-optimization/smali/SmaliTests.smali | 64 | ||||
| -rw-r--r-- | test/536-checker-intrinsic-optimization/src/Main.java | 21 | ||||
| -rwxr-xr-x | test/593-checker-boolean-2-integral-conv/build | 23 | ||||
| -rw-r--r-- | test/593-checker-boolean-2-integral-conv/smali/SmaliTests.smali | 119 | ||||
| -rw-r--r-- | test/593-checker-boolean-2-integral-conv/src/Main.java | 97 | ||||
| -rw-r--r-- | test/knownfailures.json | 2 |
7 files changed, 316 insertions, 33 deletions
diff --git a/test/536-checker-intrinsic-optimization/build b/test/536-checker-intrinsic-optimization/build new file mode 100755 index 0000000000..49292c9ac1 --- /dev/null +++ b/test/536-checker-intrinsic-optimization/build @@ -0,0 +1,23 @@ +#!/bin/bash +# +# Copyright 2017 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This checker test is incompatible with jack bytecode output, +# so force it to use javac/dx. +export USE_JACK=false +# Also disable desugar because it is missing in jack platform builds. +export DESUGAR=false + +./default-build "$@" diff --git a/test/536-checker-intrinsic-optimization/smali/SmaliTests.smali b/test/536-checker-intrinsic-optimization/smali/SmaliTests.smali new file mode 100644 index 0000000000..6612faeb77 --- /dev/null +++ b/test/536-checker-intrinsic-optimization/smali/SmaliTests.smali @@ -0,0 +1,64 @@ +# Copyright (C) 2017 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.class public LSmaliTests; +.super Ljava/lang/Object; + +## CHECK-START: char SmaliTests.stringCharAtCatch(java.lang.String, int) instruction_simplifier (before) +## CHECK-DAG: <<Char:c\d+>> InvokeVirtual intrinsic:StringCharAt +## CHECK-DAG: Return [<<Char>>] + +## CHECK-START: char SmaliTests.stringCharAtCatch(java.lang.String, int) instruction_simplifier (after) +## CHECK-DAG: <<String:l\d+>> ParameterValue +## CHECK-DAG: <<Pos:i\d+>> ParameterValue +## CHECK-DAG: <<NullCk:l\d+>> NullCheck [<<String>>] +## CHECK-DAG: <<Length:i\d+>> ArrayLength [<<NullCk>>] is_string_length:true +## CHECK-DAG: <<Bounds:i\d+>> BoundsCheck [<<Pos>>,<<Length>>] is_string_char_at:true +## CHECK-DAG: <<Char:c\d+>> ArrayGet [<<NullCk>>,<<Bounds>>] is_string_char_at:true +## CHECK-DAG: Return [<<Char>>] + +## CHECK-START: char SmaliTests.stringCharAtCatch(java.lang.String, int) instruction_simplifier (after) +## CHECK-NOT: InvokeVirtual intrinsic:StringCharAt +.method public static stringCharAtCatch(Ljava/lang/String;I)C + .registers 4 + .param p0, "s" # Ljava/lang/String; + .param p1, "pos" # I + + .prologue + + # if (doThrow) { throw new Error(); } + sget-boolean v1, LMain;->doThrow:Z + if-eqz v1, :doThrow_false + new-instance v1, Ljava/lang/Error; + invoke-direct {v1}, Ljava/lang/Error;-><init>()V + throw v1 + + :doThrow_false + :try_start + # tmp = s.charAt(pos) + invoke-virtual {p0, p1}, Ljava/lang/String;->charAt(I)C + :try_end + .catch Ljava/lang/StringIndexOutOfBoundsException; {:try_start .. :try_end} :catch + + # return tmp + move-result v1 + return v1 + + :catch + # return '\0' + move-exception v0 + const/4 v1, 0x0 + return v1 +.end method + diff --git a/test/536-checker-intrinsic-optimization/src/Main.java b/test/536-checker-intrinsic-optimization/src/Main.java index e395e283e0..3dce23fb31 100644 --- a/test/536-checker-intrinsic-optimization/src/Main.java +++ b/test/536-checker-intrinsic-optimization/src/Main.java @@ -14,6 +14,7 @@ * limitations under the License. */ +import java.lang.reflect.Method; public class Main { public static boolean doThrow = false; @@ -83,7 +84,9 @@ public class Main { } assertCharEquals('7', $opt$noinline$stringCharAtCatch("0123456789", 7)); + assertCharEquals('7', $noinline$runSmaliTest("stringCharAtCatch", "0123456789", 7)); assertCharEquals('\0', $opt$noinline$stringCharAtCatch("0123456789", 10)); + assertCharEquals('\0', $noinline$runSmaliTest("stringCharAtCatch","0123456789", 10)); assertIntEquals('a' + 'b' + 'c', $opt$noinline$stringSumChars("abc")); assertIntEquals('a' + 'b' + 'c', $opt$noinline$stringSumLeadingChars("abcdef", 3)); @@ -166,17 +169,21 @@ public class Main { } /// CHECK-START: char Main.$opt$noinline$stringCharAtCatch(java.lang.String, int) instruction_simplifier (before) + /// CHECK-DAG: <<Int:i\d+>> IntConstant 0 /// CHECK-DAG: <<Char:c\d+>> InvokeVirtual intrinsic:StringCharAt - /// CHECK-DAG: Return [<<Char>>] + /// CHECK-DAG: <<Phi:i\d+>> Phi [<<Char>>,<<Int>>] + /// CHECK-DAG: Return [<<Phi>>] /// CHECK-START: char Main.$opt$noinline$stringCharAtCatch(java.lang.String, int) instruction_simplifier (after) /// CHECK-DAG: <<String:l\d+>> ParameterValue /// CHECK-DAG: <<Pos:i\d+>> ParameterValue + /// CHECK-DAG: <<Int:i\d+>> IntConstant 0 /// CHECK-DAG: <<NullCk:l\d+>> NullCheck [<<String>>] /// CHECK-DAG: <<Length:i\d+>> ArrayLength [<<NullCk>>] is_string_length:true /// CHECK-DAG: <<Bounds:i\d+>> BoundsCheck [<<Pos>>,<<Length>>] is_string_char_at:true /// CHECK-DAG: <<Char:c\d+>> ArrayGet [<<NullCk>>,<<Bounds>>] is_string_char_at:true - /// CHECK-DAG: Return [<<Char>>] + /// CHECK-DAG: <<Phi:i\d+>> Phi [<<Char>>,<<Int>>] + /// CHECK-DAG: Return [<<Phi>>] /// CHECK-START: char Main.$opt$noinline$stringCharAtCatch(java.lang.String, int) instruction_simplifier (after) /// CHECK-NOT: InvokeVirtual intrinsic:StringCharAt @@ -421,4 +428,14 @@ public class Main { static String myString; static Object myObject; + + public static char $noinline$runSmaliTest(String name, String str, int pos) { + try { + Class<?> c = Class.forName("SmaliTests"); + Method m = c.getMethod(name, String.class, int.class); + return (Character) m.invoke(null, str, pos); + } catch (Exception ex) { + throw new Error(ex); + } + } } diff --git a/test/593-checker-boolean-2-integral-conv/build b/test/593-checker-boolean-2-integral-conv/build new file mode 100755 index 0000000000..49292c9ac1 --- /dev/null +++ b/test/593-checker-boolean-2-integral-conv/build @@ -0,0 +1,23 @@ +#!/bin/bash +# +# Copyright 2017 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This checker test is incompatible with jack bytecode output, +# so force it to use javac/dx. +export USE_JACK=false +# Also disable desugar because it is missing in jack platform builds. +export DESUGAR=false + +./default-build "$@" diff --git a/test/593-checker-boolean-2-integral-conv/smali/SmaliTests.smali b/test/593-checker-boolean-2-integral-conv/smali/SmaliTests.smali new file mode 100644 index 0000000000..00ebaaf451 --- /dev/null +++ b/test/593-checker-boolean-2-integral-conv/smali/SmaliTests.smali @@ -0,0 +1,119 @@ +# Copyright (C) 2017 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.class public LSmaliTests; +.super Ljava/lang/Object; + +# static fields +.field public static booleanField:Z + +.method static constructor <clinit>()V + .registers 1 + + .prologue + const/4 v0, 0x1 + + # booleanField = true + sput-boolean v0, LSmaliTests;->booleanField:Z + + return-void +.end method + +## CHECK-START: long SmaliTests.booleanToLong(boolean) builder (after) +## CHECK-DAG: <<Arg:z\d+>> ParameterValue +## CHECK-DAG: <<Zero:i\d+>> IntConstant 0 +## CHECK-DAG: <<One:i\d+>> IntConstant 1 +## CHECK-DAG: <<Cond:z\d+>> Equal [<<Arg>>,<<Zero>>] +## CHECK-DAG: If [<<Cond>>] +## CHECK-DAG: <<Phi:i\d+>> Phi [<<One>>,<<Zero>>] +## CHECK-DAG: <<IToJ:j\d+>> TypeConversion [<<Phi>>] +## CHECK-DAG: Return [<<IToJ>>] + +## CHECK-START: long SmaliTests.booleanToLong(boolean) select_generator (after) +## CHECK-DAG: <<Arg:z\d+>> ParameterValue +## CHECK-DAG: <<Zero:i\d+>> IntConstant 0 +## CHECK-DAG: <<One:i\d+>> IntConstant 1 +## CHECK-DAG: <<Sel:i\d+>> Select [<<Zero>>,<<One>>,<<Arg>>] +## CHECK-DAG: <<IToJ:j\d+>> TypeConversion [<<Sel>>] +## CHECK-DAG: Return [<<IToJ>>] + +## CHECK-START: long SmaliTests.booleanToLong(boolean) instruction_simplifier$after_bce (after) +## CHECK-DAG: <<Arg:z\d+>> ParameterValue +## CHECK-DAG: <<ZToJ:j\d+>> TypeConversion [<<Arg>>] +## CHECK-DAG: Return [<<ZToJ>>] +.method public static booleanToLong(Z)J + .registers 3 + .param p0, "b" # Z + .prologue + + # return b ? 1 : 0; + if-eqz p0, :b_is_zero + +# :b_is_one + const/4 v0, 0x1 + + :l_return + int-to-long v0, v0 + return-wide v0 + + :b_is_zero + const/4 v0, 0x0 + goto :l_return +.end method + +## CHECK-START: int SmaliTests.longToIntOfBoolean() builder (after) +## CHECK-DAG: <<Method:[ij]\d+>> CurrentMethod +## CHECK-DAG: <<Sget:z\d+>> StaticFieldGet +## CHECK-DAG: <<ZToJ:j\d+>> InvokeStaticOrDirect [<<Sget>>,<<Method>>] +## CHECK-DAG: <<JToI:i\d+>> TypeConversion [<<ZToJ>>] +## CHECK-DAG: Return [<<JToI>>] + +## CHECK-START: int SmaliTests.longToIntOfBoolean() inliner (after) +## CHECK-DAG: <<Method:[ij]\d+>> CurrentMethod +## CHECK-DAG: <<Zero:i\d+>> IntConstant 0 +## CHECK-DAG: <<One:i\d+>> IntConstant 1 +## CHECK-DAG: <<Sget:z\d+>> StaticFieldGet +## CHECK-DAG: If [<<Sget>>] +## CHECK-DAG: <<Phi:i\d+>> Phi [<<One>>,<<Zero>>] +## CHECK-DAG: <<IToJ:j\d+>> TypeConversion [<<Phi>>] +## CHECK-DAG: <<JToI:i\d+>> TypeConversion [<<IToJ>>] +## CHECK-DAG: Return [<<JToI>>] + +## CHECK-START: int SmaliTests.longToIntOfBoolean() select_generator (after) +## CHECK-DAG: <<Method:[ij]\d+>> CurrentMethod +## CHECK-DAG: <<Zero:i\d+>> IntConstant 0 +## CHECK-DAG: <<One:i\d+>> IntConstant 1 +## CHECK-DAG: <<Sget:z\d+>> StaticFieldGet +## CHECK-DAG: <<Sel:i\d+>> Select [<<Zero>>,<<One>>,<<Sget>>] +## CHECK-DAG: <<IToJ:j\d+>> TypeConversion [<<Sel>>] +## CHECK-DAG: <<JToI:i\d+>> TypeConversion [<<IToJ>>] +## CHECK-DAG: Return [<<JToI>>] + +## CHECK-START: int SmaliTests.longToIntOfBoolean() instruction_simplifier$after_bce (after) +## CHECK-DAG: <<Method:[ij]\d+>> CurrentMethod +## CHECK-DAG: <<Sget:z\d+>> StaticFieldGet +## CHECK-DAG: Return [<<Sget>>] +.method public static longToIntOfBoolean()I + .registers 3 + .prologue + + # long l = booleanToLong(booleanField); + sget-boolean v2, LSmaliTests;->booleanField:Z + invoke-static {v2}, LSmaliTests;->booleanToLong(Z)J + move-result-wide v0 + + # return (int) l; + long-to-int v2, v0 + return v2 +.end method diff --git a/test/593-checker-boolean-2-integral-conv/src/Main.java b/test/593-checker-boolean-2-integral-conv/src/Main.java index b4c91c8db6..3503b2e877 100644 --- a/test/593-checker-boolean-2-integral-conv/src/Main.java +++ b/test/593-checker-boolean-2-integral-conv/src/Main.java @@ -14,6 +14,8 @@ * limitations under the License. */ +import java.lang.reflect.Method; + public class Main { public static void main(String args[]) { @@ -22,8 +24,10 @@ public class Main { expectEqualsChar((char)1, booleanToChar(true)); expectEqualsInt(1, booleanToInt(true)); expectEqualsLong(1L, booleanToLong(true)); + expectEqualsLong(1L, $noinline$runSmaliTest("booleanToLong", true)); expectEqualsInt(1, longToIntOfBoolean()); + expectEqualsInt(1, $noinline$runSmaliTest("longToIntOfBoolean")); System.out.println("passed"); } @@ -132,26 +136,34 @@ public class Main { /// CHECK-START: long Main.booleanToLong(boolean) builder (after) /// CHECK: <<Arg:z\d+>> ParameterValue - /// CHECK-DAG: <<Zero:i\d+>> IntConstant 0 - /// CHECK-DAG: <<One:i\d+>> IntConstant 1 - /// CHECK-DAG: <<Cond:z\d+>> Equal [<<Arg>>,<<Zero>>] + /// CHECK-DAG: <<IZero:i\d+>> IntConstant 0 + /// CHECK-DAG: <<Zero:j\d+>> LongConstant 0 + /// CHECK-DAG: <<One:j\d+>> LongConstant 1 + /// CHECK-DAG: <<Cond:z\d+>> Equal [<<Arg>>,<<IZero>>] /// CHECK-DAG: If [<<Cond>>] - /// CHECK-DAG: <<Phi:i\d+>> Phi [<<One>>,<<Zero>>] - /// CHECK-DAG: <<IToJ:j\d+>> TypeConversion [<<Phi>>] - /// CHECK-DAG: Return [<<IToJ>>] + /// CHECK-DAG: <<Phi:j\d+>> Phi [<<One>>,<<Zero>>] + /// CHECK-DAG: Return [<<Phi>>] /// CHECK-START: long Main.booleanToLong(boolean) select_generator (after) - /// CHECK: <<Arg:z\d+>> ParameterValue - /// CHECK-DAG: <<Zero:i\d+>> IntConstant 0 - /// CHECK-DAG: <<One:i\d+>> IntConstant 1 - /// CHECK-DAG: <<Sel:i\d+>> Select [<<Zero>>,<<One>>,<<Arg>>] - /// CHECK-DAG: <<IToJ:j\d+>> TypeConversion [<<Sel>>] - /// CHECK-DAG: Return [<<IToJ>>] + /// CHECK-NOT: IntConstant + /// CHECK-NOT: Equal + /// CHECK-NOT: If + /// CHECK-NOT: Phi - /// CHECK-START: long Main.booleanToLong(boolean) instruction_simplifier$after_bce (after) + /// CHECK-START: long Main.booleanToLong(boolean) select_generator (after) /// CHECK: <<Arg:z\d+>> ParameterValue - /// CHECK-DAG: <<ZToJ:j\d+>> TypeConversion [<<Arg>>] - /// CHECK-DAG: Return [<<ZToJ>>] + /// CHECK-DAG: <<Zero:j\d+>> LongConstant 0 + /// CHECK-DAG: <<One:j\d+>> LongConstant 1 + /// CHECK-DAG: <<Sel:j\d+>> Select [<<Zero>>,<<One>>,<<Arg>>] + /// CHECK-DAG: Return [<<Sel>>] + + // As of now, the code is not optimized any further than the above. + // TODO: Re-enable checks below after simplifier is updated to handle this pattern: b/63064517 + + // CHECK-START: long Main.booleanToLong(boolean) instruction_simplifier$after_bce (after) + // CHECK: <<Arg:z\d+>> ParameterValue + // CHECK-DAG: <<ZToJ:j\d+>> TypeConversion [<<Arg>>] + // CHECK-DAG: Return [<<ZToJ>>] static long booleanToLong(boolean b) { return b ? 1 : 0; @@ -166,29 +178,36 @@ public class Main { /// CHECK-START: int Main.longToIntOfBoolean() inliner (after) /// CHECK-DAG: <<Method:[ij]\d+>> CurrentMethod - /// CHECK-DAG: <<Zero:i\d+>> IntConstant 0 - /// CHECK-DAG: <<One:i\d+>> IntConstant 1 + /// CHECK-DAG: <<Zero:j\d+>> LongConstant 0 + /// CHECK-DAG: <<One:j\d+>> LongConstant 1 /// CHECK-DAG: <<Sget:z\d+>> StaticFieldGet /// CHECK-DAG: If [<<Sget>>] - /// CHECK-DAG: <<Phi:i\d+>> Phi [<<One>>,<<Zero>>] - /// CHECK-DAG: <<IToJ:j\d+>> TypeConversion [<<Phi>>] - /// CHECK-DAG: <<JToI:i\d+>> TypeConversion [<<IToJ>>] + /// CHECK-DAG: <<Phi:j\d+>> Phi [<<One>>,<<Zero>>] + /// CHECK-DAG: <<JToI:i\d+>> TypeConversion [<<Phi>>] /// CHECK-DAG: Return [<<JToI>>] + /// CHECK-START: long Main.booleanToLong(boolean) select_generator (after) + /// CHECK-NOT: IntConstant + /// CHECK-NOT: Equal + /// CHECK-NOT: If + /// CHECK-NOT: Phi + /// CHECK-START: int Main.longToIntOfBoolean() select_generator (after) /// CHECK-DAG: <<Method:[ij]\d+>> CurrentMethod - /// CHECK-DAG: <<Zero:i\d+>> IntConstant 0 - /// CHECK-DAG: <<One:i\d+>> IntConstant 1 + /// CHECK-DAG: <<Zero:j\d+>> LongConstant 0 + /// CHECK-DAG: <<One:j\d+>> LongConstant 1 /// CHECK-DAG: <<Sget:z\d+>> StaticFieldGet - /// CHECK-DAG: <<Sel:i\d+>> Select [<<Zero>>,<<One>>,<<Sget>>] - /// CHECK-DAG: <<IToJ:j\d+>> TypeConversion [<<Sel>>] - /// CHECK-DAG: <<JToI:i\d+>> TypeConversion [<<IToJ>>] + /// CHECK-DAG: <<Sel:j\d+>> Select [<<Zero>>,<<One>>,<<Sget>>] + /// CHECK-DAG: <<JToI:i\d+>> TypeConversion [<<Sel>>] /// CHECK-DAG: Return [<<JToI>>] - /// CHECK-START: int Main.longToIntOfBoolean() instruction_simplifier$after_bce (after) - /// CHECK-DAG: <<Method:[ij]\d+>> CurrentMethod - /// CHECK-DAG: <<Sget:z\d+>> StaticFieldGet - /// CHECK-DAG: Return [<<Sget>>] + // As of now, the code is not optimized any further than the above. + // TODO: Re-enable checks below after simplifier is updated to handle this pattern: b/63064517 + + // CHECK-START: int Main.longToIntOfBoolean() instruction_simplifier$after_bce (after) + // CHECK-DAG: <<Method:[ij]\d+>> CurrentMethod + // CHECK-DAG: <<Sget:z\d+>> StaticFieldGet + // CHECK-DAG: Return [<<Sget>>] static int longToIntOfBoolean() { long l = booleanToLong(booleanField); @@ -226,6 +245,26 @@ public class Main { } } + public static long $noinline$runSmaliTest(String name, boolean input) { + try { + Class<?> c = Class.forName("SmaliTests"); + Method m = c.getMethod(name, boolean.class); + return (Long) m.invoke(null, input); + } catch (Exception ex) { + throw new Error(ex); + } + } + + public static int $noinline$runSmaliTest(String name) { + try { + Class<?> c = Class.forName("SmaliTests"); + Method m = c.getMethod(name); + return (Integer) m.invoke(null); + } catch (Exception ex) { + throw new Error(ex); + } + } + public static boolean booleanField = true; diff --git a/test/knownfailures.json b/test/knownfailures.json index a21c97c263..cf73a5f10b 100644 --- a/test/knownfailures.json +++ b/test/knownfailures.json @@ -602,11 +602,9 @@ }, { "tests": [ - "536-checker-intrinsic-optimization", "565-checker-doublenegbitwise", "567-checker-compare", "586-checker-null-array-get", - "593-checker-boolean-2-integral-conv", "633-checker-rtp-getclass" ], "description": "Checker tests failing when run with --build-with-javac-dx.", |