test: Modify 536-checker-intrinsic-optimization for javac/dx
Previously 1 of the methods were failing checker with javac/dx.
Move their old bytecode to a smali file to retain testing of those
optimizations.
Rewrite the checker tests in Main.java to use the javac/dx-generated
bytecode.
Test: art/test/run-test --64 --host --optimizing --build-with-javac-dx 536-checker-intrinsic-optimization
Bug: 62950048
Bug: 36902714
Change-Id: I8b002c1bdd2c0014c410aaa8ff18524dc1466026
diff --git a/test/536-checker-intrinsic-optimization/build b/test/536-checker-intrinsic-optimization/build
new file mode 100755
index 0000000..49292c9
--- /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 0000000..6612fae
--- /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 e395e28..3dce23f 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 @@
}
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 @@
}
/// 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 @@
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/knownfailures.json b/test/knownfailures.json
index 4ac1287..cf73a5f 100644
--- a/test/knownfailures.json
+++ b/test/knownfailures.json
@@ -602,7 +602,6 @@
},
{
"tests": [
- "536-checker-intrinsic-optimization",
"565-checker-doublenegbitwise",
"567-checker-compare",
"586-checker-null-array-get",