diff options
Diffstat (limited to 'test')
18 files changed, 469 insertions, 80 deletions
diff --git a/test/004-ReferenceMap/stack_walk_refmap_jni.cc b/test/004-ReferenceMap/stack_walk_refmap_jni.cc index 34fb3f8a01..2dbd7e8126 100644 --- a/test/004-ReferenceMap/stack_walk_refmap_jni.cc +++ b/test/004-ReferenceMap/stack_walk_refmap_jni.cc @@ -49,7 +49,9 @@ struct ReferenceMap2Visitor : public CheckReferenceMapVisitor { if (m_name.compare("f") == 0) { CHECK_REGS_CONTAIN_REFS(0x03U, true, 8); // v8: this CHECK_REGS_CONTAIN_REFS(0x06U, true, 8, 1); // v8: this, v1: x - CHECK_REGS_CONTAIN_REFS(0x08U, true, 8, 3, 1); // v8: this, v3: y, v1: x + if (!GetCurrentOatQuickMethodHeader()->IsOptimized()) { + CHECK_REGS_CONTAIN_REFS(0x08U, true, 8, 3, 1); // v8: this, v3: y, v1: x + } CHECK_REGS_CONTAIN_REFS(0x0cU, true, 8, 3, 1); // v8: this, v3: y, v1: x if (!GetCurrentOatQuickMethodHeader()->IsOptimized()) { CHECK_REGS_CONTAIN_REFS(0x0eU, true, 8, 3, 1); // v8: this, v3: y, v1: x @@ -66,9 +68,10 @@ struct ReferenceMap2Visitor : public CheckReferenceMapVisitor { CHECK_REGS_CONTAIN_REFS(0x13U, false, 3); // v3: y // Note that v0: ex can be eliminated because it's a dead merge of two different exceptions. CHECK_REGS_CONTAIN_REFS(0x18U, true, 8, 2, 1); // v8: this, v2: y, v1: x (dead v0: ex) - CHECK_REGS_CONTAIN_REFS(0x1aU, true, 8, 5, 2, 1); // v8: this, v5: x[1], v2: y, v1: x (dead v0: ex) if (!GetCurrentOatQuickMethodHeader()->IsOptimized()) { // v8: this, v5: x[1], v2: y, v1: x (dead v0: ex) + CHECK_REGS_CONTAIN_REFS(0x1aU, true, 8, 5, 2, 1); + // v8: this, v5: x[1], v2: y, v1: x (dead v0: ex) CHECK_REGS_CONTAIN_REFS(0x1dU, true, 8, 5, 2, 1); // v5 is removed from the root set because there is a "merge" operation. // See 0015: if-nez v2, 001f. diff --git a/test/004-ThreadStress/run b/test/004-ThreadStress/run deleted file mode 100755 index 27c501da8d..0000000000 --- a/test/004-ThreadStress/run +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash -# -# Copyright (C) 2015 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. - -# Be less agressive than the default debug option for the jit code cache -# to avoid timeouts. -exec ${RUN} "$@" --runtime-option -Xjitcodecachesize:1M diff --git a/test/449-checker-bce/src/Main.java b/test/449-checker-bce/src/Main.java index 22829cddc8..ffeae7d9a2 100644 --- a/test/449-checker-bce/src/Main.java +++ b/test/449-checker-bce/src/Main.java @@ -624,12 +624,13 @@ public class Main { constantIndexing2(new int[3]); } catch (ArrayIndexOutOfBoundsException e) { assertIsManaged(); // This is to ensure that single-frame deoptimization works. - // Will need to be updated if constantIndexing2 is inlined. + // Will need to be updated if constantIndexing2 is inlined. try { // This will cause AIOOBE. constantIndexingForward6(new int[3]); } catch (ArrayIndexOutOfBoundsException e2) { - assertIsManaged(); + // Having deopted, we expect to be running interpreted at this point. + // Does not apply to debuggable, however, since we do not inline. return 99; } } diff --git a/test/538-checker-embed-constants/src/Main.java b/test/538-checker-embed-constants/src/Main.java index d8618e30fb..979c4c86c0 100644 --- a/test/538-checker-embed-constants/src/Main.java +++ b/test/538-checker-embed-constants/src/Main.java @@ -260,6 +260,29 @@ public class Main { return arg ^ 0xf00000000000000fL; } + /** + * Test that the `-1` constant is not synthesized in a register and that we + * instead simply switch between `add` and `sub` instructions with the + * constant embedded. + * We need two uses (or more) of the constant because the compiler always + * defers to immediate value handling to VIXL when it has only one use. + */ + + /// CHECK-START-ARM64: long Main.addM1(long) register (after) + /// CHECK: <<Arg:j\d+>> ParameterValue + /// CHECK: <<ConstM1:j\d+>> LongConstant -1 + /// CHECK-NOT: ParallelMove + /// CHECK: Add [<<Arg>>,<<ConstM1>>] + /// CHECK: Sub [<<Arg>>,<<ConstM1>>] + + /// CHECK-START-ARM64: long Main.addM1(long) disassembly (after) + /// CHECK: sub x{{\d+}}, x{{\d+}}, #0x1 + /// CHECK: add x{{\d+}}, x{{\d+}}, #0x1 + + public static long addM1(long arg) { + return (arg + (-1)) | (arg - (-1)); + } + public static void main(String[] args) { int arg = 0x87654321; assertIntEquals(and255(arg), 0x21); @@ -286,5 +309,7 @@ public class Main { assertLongEquals(xorNot15(longArg), 0xedcba987789abcd1L); assertLongEquals(xor0xfffffff00000000f(longArg), 0xedcba9888765432eL); assertLongEquals(xor0xf00000000000000f(longArg), 0xe23456788765432eL); + + assertLongEquals(14, addM1(7)); } } diff --git a/test/539-checker-arm64-encodable-immediates/info.txt b/test/539-checker-arm64-encodable-immediates/info.txt deleted file mode 100644 index efeef33231..0000000000 --- a/test/539-checker-arm64-encodable-immediates/info.txt +++ /dev/null @@ -1,2 +0,0 @@ -Basic tests that check the compiler recognizes when constant values can be -encoded in the immediate field of instructions. diff --git a/test/539-checker-arm64-encodable-immediates/src/Main.java b/test/539-checker-arm64-encodable-immediates/src/Main.java deleted file mode 100644 index 7e3ff9fde8..0000000000 --- a/test/539-checker-arm64-encodable-immediates/src/Main.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2015 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. - */ - - -public class Main { - - public static void assertLongEquals(long expected, long result) { - if (expected != result) { - throw new Error("Expected: " + expected + ", found: " + result); - } - } - - /** - * Test that the `-1` constant is not synthesized in a register and that we - * instead simply switch between `add` and `sub` instructions with the - * constant embedded. - * We need two uses (or more) of the constant because the compiler always - * delegates the immediate value handling to VIXL when there is only one use. - */ - - /// CHECK-START-ARM64: long Main.addM1(long) register (after) - /// CHECK: <<Arg:j\d+>> ParameterValue - /// CHECK: <<ConstM1:j\d+>> LongConstant -1 - /// CHECK-NOT: ParallelMove - /// CHECK: Add [<<Arg>>,<<ConstM1>>] - /// CHECK: Sub [<<Arg>>,<<ConstM1>>] - - /// CHECK-START-ARM64: long Main.addM1(long) disassembly (after) - /// CHECK: sub x{{\d+}}, x{{\d+}}, #0x1 - /// CHECK: add x{{\d+}}, x{{\d+}}, #0x1 - - public static long addM1(long arg) { - return (arg + (-1)) | (arg - (-1)); - } - - public static void main(String[] args) { - assertLongEquals(14, addM1(7)); - } -} diff --git a/test/539-checker-arm64-encodable-immediates/expected.txt b/test/542-inline-trycatch/expected.txt index e69de29bb2..e69de29bb2 100644 --- a/test/539-checker-arm64-encodable-immediates/expected.txt +++ b/test/542-inline-trycatch/expected.txt diff --git a/test/542-inline-trycatch/info.txt b/test/542-inline-trycatch/info.txt new file mode 100644 index 0000000000..b3e50d3d61 --- /dev/null +++ b/test/542-inline-trycatch/info.txt @@ -0,0 +1 @@ +Tests inlining in the optimizing compiler under try/catch.
\ No newline at end of file diff --git a/test/542-inline-trycatch/src/Main.java b/test/542-inline-trycatch/src/Main.java new file mode 100644 index 0000000000..5a6e06fa0c --- /dev/null +++ b/test/542-inline-trycatch/src/Main.java @@ -0,0 +1,178 @@ +/* + * Copyright (C) 2014 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. + */ + +public class Main { + + // The following tests make sure that we inline methods used inside try and catch + // blocks, provided they meet other inlining criteria. To do that, we rely on + // the compiler recognizing and enforcing the $inline$ and $noinline$ markers. + + // We expect a single block to always be inlined. + + private static int $inline$SingleBlock(String str) throws NumberFormatException { + return Integer.parseInt(str); + } + + // We expect a "simple" method with multiple blocks to always be inlined. + + private static int $inline$MultipleBlocks(String str, boolean is_hex) + throws NumberFormatException { + return is_hex ? Integer.parseInt(str, 16) : Integer.parseInt(str); + } + + // We expect methods with try/catch to not be inlined. Inlined try/catch + // blocks are not supported at the moment. + + private static int $noinline$TryCatch(String str) { + try { + return Integer.parseInt(str); + } catch (NumberFormatException ex) { + return -1; + } + } + + public static void testSingleBlockFromTry() { + int val = 0; + + try { + val = $inline$SingleBlock("42"); + } catch (NumberFormatException ex) { + unreachable(); + } + assertEquals(42, val); + + try { + $inline$SingleBlock("xyz"); + unreachable(); + } catch (NumberFormatException ex) {} + } + + public static void testSingleBlockFromCatch() { + int val = 0; + + try { + throwException(); + } catch (Exception ex) { + val = $inline$SingleBlock("42"); + } + assertEquals(42, val); + } + + public static void testMultipleBlocksFromTry() { + int val = 0; + + try { + val = $inline$MultipleBlocks("42", false); + } catch (NumberFormatException ex) { + unreachable(); + } + assertEquals(42, val); + + try { + val = $inline$MultipleBlocks("20", true); + } catch (NumberFormatException ex) { + unreachable(); + } + assertEquals(32, val); + + try { + $inline$MultipleBlocks("xyz", false); + unreachable(); + } catch (NumberFormatException ex) {} + + try { + $inline$MultipleBlocks("xyz", true); + unreachable(); + } catch (NumberFormatException ex) {} + } + + public static void testMultipleBlocksFromCatch() { + int val = 0; + + try { + throwException(); + } catch (Exception ex) { + val = $inline$MultipleBlocks("42", false); + } + assertEquals(42, val); + + try { + throwException(); + } catch (Exception ex) { + val = $inline$MultipleBlocks("20", true); + } + assertEquals(32, val); + } + + public static void testTryCatchFromTry() { + int val = 0; + + try { + val = $noinline$TryCatch("42"); + } catch (NumberFormatException ex) { + unreachable(); + } + assertEquals(42, val); + + try { + val = $noinline$TryCatch("xyz"); + } catch (NumberFormatException ex) { + unreachable(); + } + assertEquals(-1, val); + } + + public static void testTryCatchFromCatch() { + int val = 0; + + try { + throwException(); + } catch (Exception ex) { + val = $noinline$TryCatch("42"); + } + assertEquals(42, val); + + try { + throwException(); + } catch (Exception ex) { + val = $noinline$TryCatch("xyz"); + } + assertEquals(-1, val); + } + + public static void main(String[] args) { + testSingleBlockFromTry(); + testSingleBlockFromCatch(); + testMultipleBlocksFromTry(); + testMultipleBlocksFromCatch(); + testTryCatchFromTry(); + testTryCatchFromCatch(); + } + + private static void assertEquals(int expected, int actual) { + if (expected != actual) { + throw new AssertionError("Wrong result: " + expected + " != " + actual); + } + } + + private static void unreachable() { + throw new Error("Unreachable"); + } + + private static void throwException() throws Exception { + throw new Exception(); + } +} diff --git a/test/542-unresolved-access-check/expected.txt b/test/542-unresolved-access-check/expected.txt new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/542-unresolved-access-check/expected.txt diff --git a/test/542-unresolved-access-check/info.txt b/test/542-unresolved-access-check/info.txt new file mode 100644 index 0000000000..30d45b8ec3 --- /dev/null +++ b/test/542-unresolved-access-check/info.txt @@ -0,0 +1 @@ +Test unresolved/access checks entry points with the JIT. diff --git a/test/542-unresolved-access-check/src/Main.java b/test/542-unresolved-access-check/src/Main.java new file mode 100644 index 0000000000..2bdf47f172 --- /dev/null +++ b/test/542-unresolved-access-check/src/Main.java @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2015 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. + */ + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.List; +import p1.InP1; +import p1.PlaceHolder; + + +// Custom class loader to prevent loading while verifying. +class MyClassLoader extends ClassLoader { + MyClassLoader() throws Exception { + super(MyClassLoader.class.getClassLoader()); + + // Some magic to get access to the pathList field of BaseDexClassLoader. + ClassLoader loader = getClass().getClassLoader(); + Class<?> baseDexClassLoader = loader.getClass().getSuperclass(); + Field f = baseDexClassLoader.getDeclaredField("pathList"); + f.setAccessible(true); + Object pathList = f.get(loader); + + // Some magic to get access to the dexField field of pathList. + f = pathList.getClass().getDeclaredField("dexElements"); + f.setAccessible(true); + dexElements = (Object[]) f.get(pathList); + dexFileField = dexElements[0].getClass().getDeclaredField("dexFile"); + dexFileField.setAccessible(true); + } + + Object[] dexElements; + Field dexFileField; + + protected Class<?> loadClass(String className, boolean resolve) throws ClassNotFoundException { + if (className.equals("p1.OtherInP1") && !p1.PlaceHolder.entered) { + // The request comes from the verifier. Return null to get the access check entry + // point in the compiled code. + return null; + } + // Mimic what DexPathList.findClass is doing. + try { + for (Object element : dexElements) { + Object dex = dexFileField.get(element); + Method method = dex.getClass().getDeclaredMethod( + "loadClassBinaryName", String.class, ClassLoader.class, List.class); + + if (dex != null) { + Class clazz = (Class)method.invoke(dex, className, this, null); + if (clazz != null) { + return clazz; + } + } + } + } catch (Exception e) { /* Ignore */ } + return getParent().loadClass(className); + } +} + +public class Main { + public static void main(String[] args) throws Exception { + MyClassLoader o = new MyClassLoader(); + Class foo = o.loadClass("LoadedByMyClassLoader"); + Method m = foo.getDeclaredMethod("main"); + m.invoke(null); + } +} + +class LoadedByMyClassLoader { + public static void main() throws Exception { + for (int i = 0; i < 10000; ++i) { + // Warm up the JIT. + doTheCall(i); + } + // Sleep a while to let the JIT compile things. + // TODO(ngeoffray): Remove the sleep. b/25414532 + Thread.sleep(2000); + doTheCall(10001); + } + + public static void doTheCall(int i) { + InP1.$inline$AllocateOtherInP1(i); + InP1.$inline$AllocateArrayOtherInP1(i); + InP1.$inline$UseStaticFieldOtherInP1(i); + InP1.$inline$SetStaticFieldOtherInP1(i); + InP1.$inline$UseInstanceFieldOtherInP1(i); + InP1.$inline$SetInstanceFieldOtherInP1(i); + InP1.$inline$LoadOtherInP1(i); + InP1.$inline$StaticCallOtherInP1(i); + InP1.$inline$InstanceCallOtherInP1(i); + } +} diff --git a/test/542-unresolved-access-check/src/p1/InP1.java b/test/542-unresolved-access-check/src/p1/InP1.java new file mode 100644 index 0000000000..3516c7231b --- /dev/null +++ b/test/542-unresolved-access-check/src/p1/InP1.java @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2015 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. + */ + +package p1; + +public class InP1 { + public static Object $inline$AllocateOtherInP1(int i) { + // Let this method execute a while to make sure the JIT sees it hot. + if (i <= 10000) { + return null; + } + // Set the flag that we have entered InP1 code to get OtherInP1 loaded. + PlaceHolder.entered = true; + return new OtherInP1(); + } + + public static Object $inline$AllocateArrayOtherInP1(int i) { + if (i <= 10000) { + return null; + } + return new OtherInP1[10]; + } + + public static Object $inline$UseStaticFieldOtherInP1(int i) { + if (i <= 10000) { + return null; + } + return OtherInP1.staticField; + } + + public static void $inline$SetStaticFieldOtherInP1(int i) { + if (i <= 10000) { + return; + } + OtherInP1.staticField = new Object(); + } + + public static Object $inline$UseInstanceFieldOtherInP1(int i) { + if (i <= 10000) { + return null; + } + return $noinline$AllocateOtherInP1().instanceField; + } + + public static void $inline$SetInstanceFieldOtherInP1(int i) { + if (i <= 10000) { + return; + } + $noinline$AllocateOtherInP1().instanceField = new Object(); + } + + public static OtherInP1 $noinline$AllocateOtherInP1() { + try { + return new OtherInP1(); + } catch (Exception e) { + throw new Error(e); + } + } + + public static Object $inline$LoadOtherInP1(int i) { + if (i <= 10000) { + return null; + } + return OtherInP1.class; + } + + public static Object $inline$StaticCallOtherInP1(int i) { + if (i <= 10000) { + return null; + } + return OtherInP1.doTheStaticCall(); + } + + public static Object $inline$InstanceCallOtherInP1(int i) { + if (i <= 10000) { + return null; + } + return $noinline$AllocateOtherInP1().doTheInstanceCall(); + } +} diff --git a/test/542-unresolved-access-check/src/p1/OtherInP1.java b/test/542-unresolved-access-check/src/p1/OtherInP1.java new file mode 100644 index 0000000000..adc1ce1297 --- /dev/null +++ b/test/542-unresolved-access-check/src/p1/OtherInP1.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2015 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. + */ + +package p1; + +class OtherInP1 { + OtherInP1() { + } + static Object staticField = new Object(); + Object instanceField = new Object(); + + static Object doTheStaticCall() { + return null; + } + + Object doTheInstanceCall() { + return null; + } +} diff --git a/test/542-unresolved-access-check/src/p1/PlaceHolder.java b/test/542-unresolved-access-check/src/p1/PlaceHolder.java new file mode 100644 index 0000000000..2bf4bdf15f --- /dev/null +++ b/test/542-unresolved-access-check/src/p1/PlaceHolder.java @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2015 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. + */ + +package p1; + +// Specific class for putting the 'entered' marker. If we were to put the marker +// in InP1 or in OtherInP1, the code in MyClassLoader using that marker would load +// InP1 or OtherInP1 in the system class loader, and not in MyClassLoader. +public class PlaceHolder { + public static boolean entered = false; +} diff --git a/test/962-iface-static/smali/Displayer.smali b/test/962-iface-static/smali/Displayer.smali index 06bec16432..ed4c013d3b 100644 --- a/test/962-iface-static/smali/Displayer.smali +++ b/test/962-iface-static/smali/Displayer.smali @@ -27,7 +27,7 @@ .class public LDisplayer; .super Ljava/lang/Object; -.method public static <clinit>()V +.method static constructor <clinit>()V .locals 3 sget-object v1, Ljava/lang/System;->out:Ljava/io/PrintStream; const-string v0, "init" diff --git a/test/962-iface-static/smali/iface.smali b/test/962-iface-static/smali/iface.smali index 441aae669e..5b9c03ec46 100644 --- a/test/962-iface-static/smali/iface.smali +++ b/test/962-iface-static/smali/iface.smali @@ -27,7 +27,7 @@ .field public final static f:LDisplayer; -.method public static <clinit>()V +.method static constructor <clinit>()V .locals 3 new-instance v1, LDisplayer; invoke-direct {v1}, LDisplayer;-><init>()V diff --git a/test/964-default-iface-init-generated/util-src/generate_smali.py b/test/964-default-iface-init-generated/util-src/generate_smali.py index be2d3ba563..3c138abf26 100755 --- a/test/964-default-iface-init-generated/util-src/generate_smali.py +++ b/test/964-default-iface-init-generated/util-src/generate_smali.py @@ -334,7 +334,7 @@ class TestInterface(mixins.DumpMixin, mixins.Named, mixins.NameComparableMixin, # public static final Displayer field = new Displayer("{tree}"); .field public final static field:LDisplayer; -.method public static constructor <clinit>()V +.method static constructor <clinit>()V .locals 3 const-string v2, "{tree}" new-instance v1, LDisplayer; |