diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/530-checker-lse/expected.txt | 1 | ||||
| -rw-r--r-- | test/530-checker-lse/src/Main.java | 23 | ||||
| -rw-r--r-- | test/675-checker-unverified-method/expected.txt | 1 | ||||
| -rw-r--r-- | test/675-checker-unverified-method/info.txt | 1 | ||||
| -rw-r--r-- | test/675-checker-unverified-method/smali/TestCase.smali | 55 | ||||
| -rw-r--r-- | test/675-checker-unverified-method/src/Main.java | 28 | ||||
| -rw-r--r-- | test/956-methodhandles/src/Main.java | 18 |
7 files changed, 127 insertions, 0 deletions
diff --git a/test/530-checker-lse/expected.txt b/test/530-checker-lse/expected.txt index ddae16aff4..fb67e22d0b 100644 --- a/test/530-checker-lse/expected.txt +++ b/test/530-checker-lse/expected.txt @@ -1 +1,2 @@ java.lang.ArrayIndexOutOfBoundsException: length=3; index=3 +Got NegativeArraySizeException. diff --git a/test/530-checker-lse/src/Main.java b/test/530-checker-lse/src/Main.java index 98838c5089..ebde3bf845 100644 --- a/test/530-checker-lse/src/Main.java +++ b/test/530-checker-lse/src/Main.java @@ -1052,6 +1052,23 @@ public class Main { return array[1] + array[i]; } + /// CHECK-START: int Main.testAllocationEliminationOfArray5(int) load_store_elimination (before) + /// CHECK: NewArray + /// CHECK: ArraySet + /// CHECK: ArrayGet + + /// CHECK-START: int Main.testAllocationEliminationOfArray5(int) load_store_elimination (after) + /// CHECK: NewArray + /// CHECK-NOT: ArraySet + /// CHECK-NOT: ArrayGet + private static int testAllocationEliminationOfArray5(int i) { + // Cannot eliminate array allocation due to unknown i that may + // cause NegativeArraySizeException. + int[] array = new int[i]; + array[1] = 12; + return array[1]; + } + /// CHECK-START: int Main.testExitMerge(boolean) load_store_elimination (before) /// CHECK: NewInstance /// CHECK: InstanceFieldSet @@ -1205,6 +1222,12 @@ public class Main { assertIntEquals(testAllocationEliminationOfArray2(), 11); assertIntEquals(testAllocationEliminationOfArray3(2), 4); assertIntEquals(testAllocationEliminationOfArray4(2), 6); + assertIntEquals(testAllocationEliminationOfArray5(2), 12); + try { + testAllocationEliminationOfArray5(-2); + } catch (NegativeArraySizeException e) { + System.out.println("Got NegativeArraySizeException."); + } assertIntEquals(testStoreStore().i, 41); assertIntEquals(testStoreStore().j, 43); diff --git a/test/675-checker-unverified-method/expected.txt b/test/675-checker-unverified-method/expected.txt new file mode 100644 index 0000000000..b0aad4deb5 --- /dev/null +++ b/test/675-checker-unverified-method/expected.txt @@ -0,0 +1 @@ +passed diff --git a/test/675-checker-unverified-method/info.txt b/test/675-checker-unverified-method/info.txt new file mode 100644 index 0000000000..667211a2fa --- /dev/null +++ b/test/675-checker-unverified-method/info.txt @@ -0,0 +1 @@ +Make sure analysis of unverified method is skipped. diff --git a/test/675-checker-unverified-method/smali/TestCase.smali b/test/675-checker-unverified-method/smali/TestCase.smali new file mode 100644 index 0000000000..673b3f2708 --- /dev/null +++ b/test/675-checker-unverified-method/smali/TestCase.smali @@ -0,0 +1,55 @@ +# Copyright (C) 2018 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 LTestCase; + +.super Ljava/lang/Object; + +# +# Ensure foo() does not analyze unverified bad() always-throws property. +# +## CHECK-START: void TestCase.foo(java.lang.Object) inliner (after) +## CHECK-DAG: InvokeStaticOrDirect method_name:TestCase.bar always_throws:true +## CHECK-DAG: InvokeStaticOrDirect method_name:TestCase.bad always_throws:false +.method public static foo(Ljava/lang/Object;)V + .registers 1 + if-nez v0, :Skip1 + invoke-static {}, LTestCase;->bar()V +:Skip1 + if-nez v0, :Skip2 + invoke-static {}, LTestCase;->bad()Lwont/be/Resolvable; +:Skip2 + return-void +.end method + +# +# Method bar() that verifies (but is never called). +# +.method public static bar()V + .registers 1 + new-instance v0, Ljava/lang/RuntimeException; + invoke-direct {v0}, Ljava/lang/RuntimeException;-><init>()V + throw v0 +.end method + +# +# Method bad() that fails to verify (but is never called). +# +.method public static bad()Lwont/be/Resolvable; + .registers 1 + invoke-static {}, LTestCase;->bar()Lwont/be/Resolvable; + move-result-object v0 + throw v0 +.end method + diff --git a/test/675-checker-unverified-method/src/Main.java b/test/675-checker-unverified-method/src/Main.java new file mode 100644 index 0000000000..0cdb2fe84b --- /dev/null +++ b/test/675-checker-unverified-method/src/Main.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2018 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. + */ + +/** + * Ensure unverified method is not analyzed. + */ +public class Main { + public static void main(String[] args) throws Exception { + Object o = new Object(); + Class<?> c = Class.forName("TestCase"); + Object[] arguments = { o }; + c.getMethod("foo", Object.class).invoke(null, arguments); + System.out.println("passed"); + } +} diff --git a/test/956-methodhandles/src/Main.java b/test/956-methodhandles/src/Main.java index cb06e4263e..1ddef03d62 100644 --- a/test/956-methodhandles/src/Main.java +++ b/test/956-methodhandles/src/Main.java @@ -22,6 +22,7 @@ import java.lang.invoke.MethodType; import java.lang.invoke.WrongMethodTypeException; import java.lang.reflect.Constructor; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; @@ -79,6 +80,7 @@ public class Main { testVariableArity(); testVariableArity_MethodHandles_bind(); testRevealDirect(); + testReflectiveCalls(); } public static void testfindSpecial_invokeSuperBehaviour() throws Throwable { @@ -1624,4 +1626,20 @@ public class Main { assertEquals(field, info.reflectAs(Field.class, MethodHandles.lookup())); assertEquals(MethodType.methodType(String.class), info.getMethodType()); } + + public static void testReflectiveCalls() throws Throwable { + String[] methodNames = { "invoke", "invokeExact" }; + for (String methodName : methodNames) { + Method invokeMethod = MethodHandle.class.getMethod(methodName, Object[].class); + MethodHandle instance = + MethodHandles.lookup().findVirtual(java.io.PrintStream.class, "println", + MethodType.methodType(void.class, String.class)); + try { + invokeMethod.invoke(instance, new Object[] { new Object[] { Integer.valueOf(1) } } ); + fail(); + } catch (InvocationTargetException ite) { + assertEquals(ite.getCause().getClass(), UnsupportedOperationException.class); + } + } + } } |