diff options
| author | 2020-09-02 12:03:14 +0100 | |
|---|---|---|
| committer | 2020-09-24 09:39:00 +0000 | |
| commit | 5437e6fa3c5a1865e4146356d05e0a48764a5e3b (patch) | |
| tree | d2394e4504afd4aa1cecc8a75511b7be1c3ab1ff | |
| parent | 59a122afb0d2af069a055de7437c736480782e41 (diff) | |
Add tests for accessing referrer's class.
Prepare for improving codegen for accessing referrer's class
from unresolved compiling class by improving test coverage.
The disabled CHECK statements show the intended results.
Test: Additional tests in 727-checker-unresolved-class.
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Bug: 161898207
Change-Id: I7473d2693060b843670ea81f5f0e7bbb3c2d9031
27 files changed, 680 insertions, 20 deletions
diff --git a/test/727-checker-unresolved-class/expected.txt b/test/727-checker-unresolved-class/expected.txt index 2fbc3f4e5d..b33a798ab2 100644 --- a/test/727-checker-unresolved-class/expected.txt +++ b/test/727-checker-unresolved-class/expected.txt @@ -1,5 +1,6 @@ ResolvedPackagePrivateClass.$noinline$publicStaticMethod() UnresolvedPublicClass passed +UnresolvedPackagePrivateClass passed ResolvedPackagePrivateClass.$noinline$publicStaticMethod() ResolvedPackagePrivateClass.$noinline$publicStaticMethod() ResolvedPackagePrivateClass.$noinline$staticMethod() @@ -7,3 +8,5 @@ ResolvedPackagePrivateClass.$noinline$staticMethod() PublicSubclassOfUnresolvedClass passed ResolvedPackagePrivateClass.$noinline$publicStaticMethod() PublicSubclassOfUnresolvedClass2 passed +PackagePrivateSubclassOfUnresolvedClass passed +PackagePrivateSubclassOfUnresolvedClass2 passed diff --git a/test/727-checker-unresolved-class/jasmin/GetPackagePrivateSubclassOfUnresolvedClass2FromSamePackage.j b/test/727-checker-unresolved-class/jasmin/GetPackagePrivateSubclassOfUnresolvedClass2FromSamePackage.j new file mode 100644 index 0000000000..0add87bea2 --- /dev/null +++ b/test/727-checker-unresolved-class/jasmin/GetPackagePrivateSubclassOfUnresolvedClass2FromSamePackage.j @@ -0,0 +1,27 @@ +; Copyright (C) 2020 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. + +.bytecode 49.0 + +.class public resolved/GetPackagePrivateSubclassOfUnresolvedClass2FromSamePackage +.super java/lang/Object + +; TODO: Make $inline$ when we relax the verifier. b/28313047 +.method public static get()Ljava/lang/Class; + .limit stack 1 + .limit locals 0 + ; Fail to resolve class in same literal package but defined in child ClassLoader. + ldc resolved/PackagePrivateSubclassOfUnresolvedClass2 + areturn +.end method diff --git a/test/727-checker-unresolved-class/jasmin/GetPublicSubclassOfUnresolvedClass2FromSamePackage.j b/test/727-checker-unresolved-class/jasmin/GetPublicSubclassOfUnresolvedClass2FromSamePackage.j new file mode 100644 index 0000000000..086836574b --- /dev/null +++ b/test/727-checker-unresolved-class/jasmin/GetPublicSubclassOfUnresolvedClass2FromSamePackage.j @@ -0,0 +1,27 @@ +; Copyright (C) 2020 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. + +.bytecode 49.0 + +.class public resolved/GetPublicSubclassOfUnresolvedClass2FromSamePackage +.super java/lang/Object + +; TODO: Make $inline$ when we relax the verifier. b/28313047 +.method public static get()Ljava/lang/Class; + .limit stack 1 + .limit locals 0 + ; Fail to resolve class in same literal package but defined in child ClassLoader. + ldc resolved/PublicSubclassOfUnresolvedClass2 + areturn +.end method diff --git a/test/727-checker-unresolved-class/src-ex/Test.java b/test/727-checker-unresolved-class/src-ex/Test.java index 839de6d7e8..54d7b8d089 100644 --- a/test/727-checker-unresolved-class/src-ex/Test.java +++ b/test/727-checker-unresolved-class/src-ex/Test.java @@ -14,14 +14,20 @@ * limitations under the License. */ +import resolved.PackagePrivateSubclassOfUnresolvedClassProxy; +import resolved.PackagePrivateSubclassOfUnresolvedClass2Proxy; import resolved.PublicSubclassOfUnresolvedClass; import resolved.PublicSubclassOfUnresolvedClass2; +import unresolved.UnresolvedPackagePrivateClassProxy; import unresolved.UnresolvedPublicClass; public class Test { public static void $noinline$main() { UnresolvedPublicClass.$noinline$main(); + UnresolvedPackagePrivateClassProxy.$noinline$main(); PublicSubclassOfUnresolvedClass.$noinline$main(); PublicSubclassOfUnresolvedClass2.$noinline$main(); + PackagePrivateSubclassOfUnresolvedClassProxy.$noinline$main(); + PackagePrivateSubclassOfUnresolvedClass2Proxy.$noinline$main(); } } diff --git a/test/727-checker-unresolved-class/src-ex/getters/GetPackagePrivateSubclassOfUnresolvedClass2.java b/test/727-checker-unresolved-class/src-ex/getters/GetPackagePrivateSubclassOfUnresolvedClass2.java new file mode 100644 index 0000000000..41ba071f56 --- /dev/null +++ b/test/727-checker-unresolved-class/src-ex/getters/GetPackagePrivateSubclassOfUnresolvedClass2.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2020 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 getters; + +import resolved.PackagePrivateSubclassOfUnresolvedClass2; + +public class GetPackagePrivateSubclassOfUnresolvedClass2 { + // TODO: Make $inline$ when we relax the verifier. b/28313047 + public static Class<?> get() { + return PackagePrivateSubclassOfUnresolvedClass2.class; + } +} diff --git a/test/727-checker-unresolved-class/src-ex/getters/GetPublicSubclassOfUnresolvedClass2.java b/test/727-checker-unresolved-class/src-ex/getters/GetPublicSubclassOfUnresolvedClass2.java new file mode 100644 index 0000000000..9020f97e6a --- /dev/null +++ b/test/727-checker-unresolved-class/src-ex/getters/GetPublicSubclassOfUnresolvedClass2.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2020 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 getters; + +import resolved.PublicSubclassOfUnresolvedClass2; + +public class GetPublicSubclassOfUnresolvedClass2 { + // TODO: Make $inline$ when we relax the verifier. b/28313047 + public static Class<?> get() { + return PublicSubclassOfUnresolvedClass2.class; + } +} diff --git a/test/727-checker-unresolved-class/src-ex/resolved/PackagePrivateSubclassOfUnresolvedClass2.java b/test/727-checker-unresolved-class/src-ex/resolved/PackagePrivateSubclassOfUnresolvedClass2.java new file mode 100644 index 0000000000..3f0bc05675 --- /dev/null +++ b/test/727-checker-unresolved-class/src-ex/resolved/PackagePrivateSubclassOfUnresolvedClass2.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2020 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 resolved; + +import getters.GetPackagePrivateSubclassOfUnresolvedClass2; +import unresolved.UnresolvedPublicClass; + +// This class is used for compiling code that accesses it but it is +// replaced by a package-private class from src-ex2/ with reduced access +// to run tests, including access check tests. +public class PackagePrivateSubclassOfUnresolvedClass2 extends UnresolvedPublicClass { + public static void $noinline$main() { + throw new Error("Unreachable"); + } +} diff --git a/test/727-checker-unresolved-class/src-ex/resolved/PackagePrivateSubclassOfUnresolvedClass2Proxy.java b/test/727-checker-unresolved-class/src-ex/resolved/PackagePrivateSubclassOfUnresolvedClass2Proxy.java new file mode 100644 index 0000000000..a6dc8030f8 --- /dev/null +++ b/test/727-checker-unresolved-class/src-ex/resolved/PackagePrivateSubclassOfUnresolvedClass2Proxy.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2020 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 resolved; + +public class PackagePrivateSubclassOfUnresolvedClass2Proxy + extends PackagePrivateSubclassOfUnresolvedClass2 { +} diff --git a/test/727-checker-unresolved-class/src-ex/resolved/PublicSubclassOfUnresolvedClass2.java b/test/727-checker-unresolved-class/src-ex/resolved/PublicSubclassOfUnresolvedClass2.java index 4846c2d2b2..8dcc2e45ac 100644 --- a/test/727-checker-unresolved-class/src-ex/resolved/PublicSubclassOfUnresolvedClass2.java +++ b/test/727-checker-unresolved-class/src-ex/resolved/PublicSubclassOfUnresolvedClass2.java @@ -16,6 +16,7 @@ package resolved; +import getters.GetPublicSubclassOfUnresolvedClass2; import unresolved.UnresolvedPublicClass; // This class is defined by the child class loader, so access to @@ -23,6 +24,10 @@ import unresolved.UnresolvedPublicClass; // loader is illegal even though the package name is the same. public class PublicSubclassOfUnresolvedClass2 extends UnresolvedPublicClass { public static void $noinline$main() { + $noinline$testReferrersClass(); + $noinline$testInlinedReferrersClass(); + $noinline$testInlinedReferrersClassFromSamePackage(); + $noinline$testResolvedPublicClass(); $noinline$testResolvedPackagePrivateClass(); @@ -43,6 +48,30 @@ public class PublicSubclassOfUnresolvedClass2 extends UnresolvedPublicClass { System.out.println("PublicSubclassOfUnresolvedClass2 passed"); } + /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testReferrersClass() builder (after) + // CHECK: LoadClass class_name:resolved.PublicSubclassOfUnresolvedClass2 needs_access_check:false + static void $noinline$testReferrersClass() { + Class<?> c = PublicSubclassOfUnresolvedClass2.class; + } + + /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testInlinedReferrersClass() inliner (after) + // CHECK: LoadClass class_name:resolved.PublicSubclassOfUnresolvedClass2 needs_access_check:false + static void $noinline$testInlinedReferrersClass() { + // TODO: Make $inline$ and enable CHECK above when we relax the verifier. b/28313047 + Class<?> c = GetPublicSubclassOfUnresolvedClass2.get(); + } + + /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testInlinedReferrersClassFromSamePackage() inliner (after) + // CHECK: LoadClass class_name:resolved.PublicSubclassOfUnresolvedClass2 needs_access_check:true + static void $noinline$testInlinedReferrersClassFromSamePackage() { + // Trying to resolve this class by name in parent class loader throws NoClassDefFoundError. + try{ + // TODO: Make $inline$ and enable CHECK above when we relax the verifier. b/28313047 + Class<?> c = GetPublicSubclassOfUnresolvedClass2FromSamePackage.get(); + throw new Error("Unreachable"); + } catch (NoClassDefFoundError expected) {} + } + /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testResolvedPublicClass() builder (after) /// CHECK: LoadClass class_name:resolved.ResolvedPublicSubclassOfPackagePrivateClass needs_access_check:false static void $noinline$testResolvedPublicClass() { diff --git a/test/727-checker-unresolved-class/src-ex2/resolved/PackagePrivateSubclassOfUnresolvedClass2.java b/test/727-checker-unresolved-class/src-ex2/resolved/PackagePrivateSubclassOfUnresolvedClass2.java new file mode 100644 index 0000000000..52e2448252 --- /dev/null +++ b/test/727-checker-unresolved-class/src-ex2/resolved/PackagePrivateSubclassOfUnresolvedClass2.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2020 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 resolved; + +import getters.GetPackagePrivateSubclassOfUnresolvedClass2; +import unresolved.UnresolvedPublicClass; + +// This class is defined by the child class loader, so access to +// package-private classes and members defined in the parent class +// loader is illegal even though the package name is the same. +public class PackagePrivateSubclassOfUnresolvedClass2 extends UnresolvedPublicClass { + public static void $noinline$main() { + $noinline$testReferrersClass(); + $noinline$testInlinedReferrersClass(); + $noinline$testInlinedReferrersClassFromSamePackage(); + + System.out.println("PackagePrivateSubclassOfUnresolvedClass2 passed"); + } + + /// CHECK-START: void resolved.PackagePrivateSubclassOfUnresolvedClass2.$noinline$testReferrersClass() builder (after) + // CHECK: LoadClass class_name:resolved.PackagePrivateSubclassOfUnresolvedClass2 needs_access_check:false + static void $noinline$testReferrersClass() { + Class<?> c = PackagePrivateSubclassOfUnresolvedClass2.class; + } + + /// CHECK-START: void resolved.PackagePrivateSubclassOfUnresolvedClass2.$noinline$testInlinedReferrersClass() inliner (after) + // CHECK: LoadClass class_name:resolved.PackagePrivateSubclassOfUnresolvedClass2 needs_access_check:true + static void $noinline$testInlinedReferrersClass() { + // TODO: Make $inline$ and enable CHECK above when we relax the verifier. b/28313047 + Class<?> c = GetPackagePrivateSubclassOfUnresolvedClass2.get(); + } + + /// CHECK-START: void resolved.PackagePrivateSubclassOfUnresolvedClass2.$noinline$testInlinedReferrersClassFromSamePackage() inliner (after) + // CHECK: LoadClass class_name:resolved.PackagePrivateSubclassOfUnresolvedClass2 needs_access_check:true + static void $noinline$testInlinedReferrersClassFromSamePackage() { + // Trying to resolve this class by name in parent class loader throws NoClassDefFoundError. + try { + // TODO: Make $inline$ and enable CHECK above when we relax the verifier. b/28313047 + Class<?> c = GetPackagePrivateSubclassOfUnresolvedClass2FromSamePackage.get(); + throw new Error("Unreachable"); + } catch (NoClassDefFoundError expected) {} + } +} diff --git a/test/727-checker-unresolved-class/src/getters/GetPackagePrivateSubclassOfUnresolvedClass.java b/test/727-checker-unresolved-class/src/getters/GetPackagePrivateSubclassOfUnresolvedClass.java new file mode 100644 index 0000000000..cf79d8052c --- /dev/null +++ b/test/727-checker-unresolved-class/src/getters/GetPackagePrivateSubclassOfUnresolvedClass.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2020 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 getters; + +import resolved.PackagePrivateSubclassOfUnresolvedClass; + +public class GetPackagePrivateSubclassOfUnresolvedClass { + // TODO: Make $inline$ when we relax the verifier. b/28313047 + public static Class<?> get() { + return PackagePrivateSubclassOfUnresolvedClass.class; + } +} diff --git a/test/727-checker-unresolved-class/src/getters/GetPublicSubclassOfUnresolvedClass.java b/test/727-checker-unresolved-class/src/getters/GetPublicSubclassOfUnresolvedClass.java new file mode 100644 index 0000000000..099fd5379c --- /dev/null +++ b/test/727-checker-unresolved-class/src/getters/GetPublicSubclassOfUnresolvedClass.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2020 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 getters; + +import resolved.PublicSubclassOfUnresolvedClass; + +public class GetPublicSubclassOfUnresolvedClass { + // TODO: Make $inline$ when we relax the verifier. b/28313047 + public static Class<?> get() { + return PublicSubclassOfUnresolvedClass.class; + } +} diff --git a/test/727-checker-unresolved-class/src/getters/GetUnresolvedPackagePrivateClass.java b/test/727-checker-unresolved-class/src/getters/GetUnresolvedPackagePrivateClass.java new file mode 100644 index 0000000000..356d0e07aa --- /dev/null +++ b/test/727-checker-unresolved-class/src/getters/GetUnresolvedPackagePrivateClass.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2020 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 getters; + +import unresolved.UnresolvedPackagePrivateClass; + +public class GetUnresolvedPackagePrivateClass { + // TODO: When we relax verifier to ignore access check failures, + // change this method to `$inline$`. + public static Class<?> get() { + return UnresolvedPackagePrivateClass.class; + } +} diff --git a/test/727-checker-unresolved-class/src/getters/GetUnresolvedPublicClass.java b/test/727-checker-unresolved-class/src/getters/GetUnresolvedPublicClass.java new file mode 100644 index 0000000000..2c0bb0bfd4 --- /dev/null +++ b/test/727-checker-unresolved-class/src/getters/GetUnresolvedPublicClass.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2020 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 getters; + +import unresolved.UnresolvedPublicClass; + +public class GetUnresolvedPublicClass { + // TODO: Make $inline$ when we relax the verifier. b/28313047 + public static Class<?> get() { + return UnresolvedPublicClass.class; + } +} diff --git a/test/727-checker-unresolved-class/src/resolved/GetPackagePrivateSubclassOfUnresolvedClassFromSamePackage.java b/test/727-checker-unresolved-class/src/resolved/GetPackagePrivateSubclassOfUnresolvedClassFromSamePackage.java new file mode 100644 index 0000000000..2c221c5bd2 --- /dev/null +++ b/test/727-checker-unresolved-class/src/resolved/GetPackagePrivateSubclassOfUnresolvedClassFromSamePackage.java @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2020 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 resolved; + +public class GetPackagePrivateSubclassOfUnresolvedClassFromSamePackage { + // TODO: Make $inline$ when we relax the verifier. b/28313047 + public static Class<?> get() { + return PackagePrivateSubclassOfUnresolvedClass.class; + } +} diff --git a/test/727-checker-unresolved-class/src/resolved/GetPublicSubclassOfUnresolvedClassFromSamePackage.java b/test/727-checker-unresolved-class/src/resolved/GetPublicSubclassOfUnresolvedClassFromSamePackage.java new file mode 100644 index 0000000000..687490649f --- /dev/null +++ b/test/727-checker-unresolved-class/src/resolved/GetPublicSubclassOfUnresolvedClassFromSamePackage.java @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2020 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 resolved; + +public class GetPublicSubclassOfUnresolvedClassFromSamePackage { + // TODO: Make $inline$ when we relax the verifier. b/28313047 + public static Class<?> get() { + return PublicSubclassOfUnresolvedClass.class; + } +} diff --git a/test/727-checker-unresolved-class/src/resolved/PackagePrivateSubclassOfUnresolvedClass.java b/test/727-checker-unresolved-class/src/resolved/PackagePrivateSubclassOfUnresolvedClass.java new file mode 100644 index 0000000000..7ba0c2c8a8 --- /dev/null +++ b/test/727-checker-unresolved-class/src/resolved/PackagePrivateSubclassOfUnresolvedClass.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2020 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 resolved; + +// This class is used for compiling code that accesses it but it is +// replaced by a package-private class from src2/ with reduced access +// to run tests, including access check tests. +public class PackagePrivateSubclassOfUnresolvedClass { + public static void $noinline$main() { + throw new Error("Unreachable"); + } +} diff --git a/test/727-checker-unresolved-class/src/resolved/PackagePrivateSubclassOfUnresolvedClassProxy.java b/test/727-checker-unresolved-class/src/resolved/PackagePrivateSubclassOfUnresolvedClassProxy.java new file mode 100644 index 0000000000..8d07de6764 --- /dev/null +++ b/test/727-checker-unresolved-class/src/resolved/PackagePrivateSubclassOfUnresolvedClassProxy.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2020 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 resolved; + +public class PackagePrivateSubclassOfUnresolvedClassProxy + extends PackagePrivateSubclassOfUnresolvedClass { +} diff --git a/test/727-checker-unresolved-class/src/resolved/PublicSubclassOfUnresolvedClass.java b/test/727-checker-unresolved-class/src/resolved/PublicSubclassOfUnresolvedClass.java index fc9d24d2ca..168853cdb0 100644 --- a/test/727-checker-unresolved-class/src/resolved/PublicSubclassOfUnresolvedClass.java +++ b/test/727-checker-unresolved-class/src/resolved/PublicSubclassOfUnresolvedClass.java @@ -16,10 +16,15 @@ package resolved; +import getters.GetPublicSubclassOfUnresolvedClass; import unresolved.UnresolvedPublicClass; public class PublicSubclassOfUnresolvedClass extends UnresolvedPublicClass { public static void $noinline$main() { + $noinline$testReferrersClass(); + $noinline$testInlinedReferrersClass(); + $noinline$testInlinedReferrersClassFromSamePackage(); + $noinline$testResolvedPublicClass(); $noinline$testResolvedPackagePrivateClass(); @@ -40,6 +45,26 @@ public class PublicSubclassOfUnresolvedClass extends UnresolvedPublicClass { System.out.println("PublicSubclassOfUnresolvedClass passed"); } + /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass.$noinline$testReferrersClass() builder (after) + // CHECK: LoadClass class_name:resolved.PublicSubclassOfUnresolvedClass needs_access_check:false + static void $noinline$testReferrersClass() { + Class<?> c = PublicSubclassOfUnresolvedClass.class; + } + + /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass.$noinline$testInlinedReferrersClass() inliner (after) + // CHECK: LoadClass class_name:resolved.PublicSubclassOfUnresolvedClass needs_access_check:false + static void $noinline$testInlinedReferrersClass() { + // TODO: Make $inline$ and enable CHECK above when we relax the verifier. b/28313047 + Class<?> c = GetPublicSubclassOfUnresolvedClass.get(); + } + + /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass.$noinline$testInlinedReferrersClassFromSamePackage() inliner (after) + // CHECK: LoadClass class_name:resolved.PublicSubclassOfUnresolvedClass needs_access_check:false + static void $noinline$testInlinedReferrersClassFromSamePackage() { + // TODO: Make $inline$ and enable CHECK above when we relax the verifier. b/28313047 + Class<?> c = GetPublicSubclassOfUnresolvedClassFromSamePackage.get(); + } + /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass.$noinline$testResolvedPublicClass() builder (after) /// CHECK: LoadClass class_name:resolved.ResolvedPublicSubclassOfPackagePrivateClass needs_access_check:false static void $noinline$testResolvedPublicClass() { diff --git a/test/727-checker-unresolved-class/src/resolved/ResolvedPackagePrivateClass.java b/test/727-checker-unresolved-class/src/resolved/ResolvedPackagePrivateClass.java index 132e967eda..0c7d05520a 100644 --- a/test/727-checker-unresolved-class/src/resolved/ResolvedPackagePrivateClass.java +++ b/test/727-checker-unresolved-class/src/resolved/ResolvedPackagePrivateClass.java @@ -20,19 +20,19 @@ package resolved; // replaced by a package-private class from src2/ with reduced access to // some members to test different access checks. public class ResolvedPackagePrivateClass { - public static int publicIntField; - public static int privateIntField; - public static int intField; + public static int publicIntField; + public static int privateIntField; + public static int intField; - public static void $noinline$publicStaticMethod() { - System.out.println("ResolvedPackagePrivateClass.$noinline$publicStaticMethod()"); - } + public static void $noinline$publicStaticMethod() { + System.out.println("ResolvedPackagePrivateClass.$noinline$publicStaticMethod()"); + } - public static void $noinline$privateStaticMethod() { - System.out.println("ResolvedPackagePrivateClass.$noinline$privateStaticMethod()"); - } + public static void $noinline$privateStaticMethod() { + System.out.println("ResolvedPackagePrivateClass.$noinline$privateStaticMethod()"); + } - public static void $noinline$staticMethod() { - System.out.println("ResolvedPackagePrivateClass.$noinline$staticMethod()"); - } + public static void $noinline$staticMethod() { + System.out.println("ResolvedPackagePrivateClass.$noinline$staticMethod()"); + } } diff --git a/test/727-checker-unresolved-class/src/unresolved/UnresolvedPackagePrivateClass.java b/test/727-checker-unresolved-class/src/unresolved/UnresolvedPackagePrivateClass.java new file mode 100644 index 0000000000..b5ed7ff28b --- /dev/null +++ b/test/727-checker-unresolved-class/src/unresolved/UnresolvedPackagePrivateClass.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2020 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 unresolved; + +// This class is used for compiling code that accesses it but it is +// replaced by a package-private class from src2/ with reduced access +// to run tests, including access check tests. +public class UnresolvedPackagePrivateClass { + public static void $noinline$main() { + throw new Error("Unreachable"); + } +} diff --git a/test/727-checker-unresolved-class/src/unresolved/UnresolvedPackagePrivateClassProxy.java b/test/727-checker-unresolved-class/src/unresolved/UnresolvedPackagePrivateClassProxy.java new file mode 100644 index 0000000000..b880a8722d --- /dev/null +++ b/test/727-checker-unresolved-class/src/unresolved/UnresolvedPackagePrivateClassProxy.java @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2020 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 unresolved; + +public class UnresolvedPackagePrivateClassProxy extends UnresolvedPackagePrivateClass { +} diff --git a/test/727-checker-unresolved-class/src/unresolved/UnresolvedPublicClass.java b/test/727-checker-unresolved-class/src/unresolved/UnresolvedPublicClass.java index 477425c8a8..8bbe4f6560 100644 --- a/test/727-checker-unresolved-class/src/unresolved/UnresolvedPublicClass.java +++ b/test/727-checker-unresolved-class/src/unresolved/UnresolvedPublicClass.java @@ -16,11 +16,15 @@ package unresolved; +import getters.GetUnresolvedPublicClass; import resolved.ResolvedPackagePrivateClass; import resolved.ResolvedPublicSubclassOfPackagePrivateClass; public class UnresolvedPublicClass { public static void $noinline$main() { + $noinline$testReferrersClass(); + $noinline$testInlinedReferrersClass(); + $noinline$testResolvedPublicClass(); $noinline$testResolvedPackagePrivateClass(); @@ -41,6 +45,19 @@ public class UnresolvedPublicClass { System.out.println("UnresolvedPublicClass passed"); } + /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testReferrersClass() builder (after) + // CHECK: LoadClass class_name:unresolved.UnresolvedPublicClass needs_access_check:false + static void $noinline$testReferrersClass() { + Class<?> c = UnresolvedPublicClass.class; + } + + /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testInlinedReferrersClass() inliner (after) + // CHECK: LoadClass class_name:unresolved.UnresolvedPublicClass needs_access_check:false + static void $noinline$testInlinedReferrersClass() { + // TODO: Make $inline$ and enable CHECK above when we relax the verifier. b/28313047 + Class<?> c = GetUnresolvedPublicClass.get(); + } + /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testResolvedPublicClass() builder (after) /// CHECK: LoadClass class_name:resolved.ResolvedPublicSubclassOfPackagePrivateClass needs_access_check:false static void $noinline$testResolvedPublicClass() { diff --git a/test/727-checker-unresolved-class/src2/resolved/PackagePrivateSubclassOfUnresolvedClass.java b/test/727-checker-unresolved-class/src2/resolved/PackagePrivateSubclassOfUnresolvedClass.java new file mode 100644 index 0000000000..ce94cce551 --- /dev/null +++ b/test/727-checker-unresolved-class/src2/resolved/PackagePrivateSubclassOfUnresolvedClass.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2020 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 resolved; + +import getters.GetPackagePrivateSubclassOfUnresolvedClass; +import unresolved.UnresolvedPublicClass; + +class PackagePrivateSubclassOfUnresolvedClass extends UnresolvedPublicClass { + public static void $noinline$main() { + $noinline$testReferrersClass(); + $noinline$testInlinedReferrersClass(); + $noinline$testInlinedReferrersClassFromSamePackage(); + + System.out.println("PackagePrivateSubclassOfUnresolvedClass passed"); + } + + /// CHECK-START: void resolved.PackagePrivateSubclassOfUnresolvedClass.$noinline$testReferrersClass() builder (after) + // CHECK: LoadClass class_name:resolved.PackagePrivateSubclassOfUnresolvedClass needs_access_check:false + static void $noinline$testReferrersClass() { + Class<?> c = PackagePrivateSubclassOfUnresolvedClass.class; + } + + /// CHECK-START: void resolved.PackagePrivateSubclassOfUnresolvedClass.$noinline$testInlinedReferrersClass() inliner (after) + // CHECK: LoadClass class_name:resolved.PackagePrivateSubclassOfUnresolvedClass needs_access_check:true + static void $noinline$testInlinedReferrersClass() { + try { + // TODO: Make $inline$ and enable CHECK above when we relax the verifier. b/28313047 + Class<?> c = GetPackagePrivateSubclassOfUnresolvedClass.get(); + throw new Error("Unreachable"); + } catch (IllegalAccessError expected) {} + } + + /// CHECK-START: void resolved.PackagePrivateSubclassOfUnresolvedClass.$noinline$testInlinedReferrersClassFromSamePackage() inliner (after) + // CHECK: LoadClass class_name:resolved.PackagePrivateSubclassOfUnresolvedClass needs_access_check:false + static void $noinline$testInlinedReferrersClassFromSamePackage() { + Class<?> c = GetPackagePrivateSubclassOfUnresolvedClassFromSamePackage.get(); + } +} diff --git a/test/727-checker-unresolved-class/src2/unresolved/UnresolvedPackagePrivateClass.java b/test/727-checker-unresolved-class/src2/unresolved/UnresolvedPackagePrivateClass.java new file mode 100644 index 0000000000..81a76a1b42 --- /dev/null +++ b/test/727-checker-unresolved-class/src2/unresolved/UnresolvedPackagePrivateClass.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2020 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 unresolved; + +import getters.GetUnresolvedPackagePrivateClass; + +class UnresolvedPackagePrivateClass { + public static void $noinline$main() { + $noinline$testReferrersClass(); + $noinline$testInlinedReferrersClass(); + + System.out.println("UnresolvedPackagePrivateClass passed"); + } + + /// CHECK-START: void unresolved.UnresolvedPackagePrivateClass.$noinline$testReferrersClass() builder (after) + // CHECK: LoadClass class_name:unresolved.UnresolvedPackagePrivateClass needs_access_check:false + static void $noinline$testReferrersClass() { + Class<?> c = UnresolvedPackagePrivateClass.class; + } + + /// CHECK-START: void unresolved.UnresolvedPackagePrivateClass.$noinline$testInlinedReferrersClass() inliner (after) + // CHECK: LoadClass class_name:unresolved.UnresolvedPackagePrivateClass needs_access_check:true + static void $noinline$testInlinedReferrersClass() { + try { + // TODO: When we relax verifier to ignore access check failures, + // change the called method to `$inline$` and enable the CHECK above. + Class<?> c = GetUnresolvedPackagePrivateClass.get(); + throw new Error("Unreachable"); + } catch (IllegalAccessError expected) {} + } +} diff --git a/test/etc/default-build b/test/etc/default-build index 1122c01f5d..03e029f653 100755 --- a/test/etc/default-build +++ b/test/etc/default-build @@ -92,6 +92,12 @@ else HAS_SRC_EX=false fi +if [ -d src-ex2 ]; then + HAS_SRC_EX2=true +else + HAS_SRC_EX2=false +fi + if [ -d src-dex2oat-unresolved ]; then HAS_SRC_DEX2OAT_UNRESOLVED=true else @@ -153,6 +159,9 @@ while true; do elif [ "x$1" = "x--no-src-ex" ]; then HAS_SRC_EX=false shift + elif [ "x$1" = "x--no-src-ex2" ]; then + HAS_SRC_EX2=false + shift elif [ "x$1" = "x--no-smali" ]; then HAS_SMALI=false shift @@ -411,7 +420,7 @@ if [[ "${HAS_JASMIN}" == true ]]; then else # Move jasmin classes into classes directory so that they are picked up with -cp classes. mkdir -p classes - mv jasmin_classes/* classes + cp -r jasmin_classes/* classes/ fi fi @@ -447,21 +456,35 @@ if [ "${HAS_SMALI_MULTIDEX}" = "true" -a ${NEED_DEX} = "true" ]; then make_dexmerge classes2.dex smali_classes2.dex fi -if [ ${HAS_SRC_EX} = "true" ]; then +if [ ${HAS_SRC_EX} = "true" -o ${HAS_SRC_EX2} = "true" ]; then # Build src-ex into classes-ex. - # Includes 'src', 'src-art' source when compiling classes-ex, but exclude their .class files. - if [[ "${HAS_SRC}" == "true" ]]; then + # Includes 'src', 'src-art' and 'jasmin' source when compiling classes-ex, + # but exclude their .class files. + if [ "${HAS_SRC}" = "true" -o "${HAS_SRC_ART}" = "true" -o "${HAS_JASMIN}" = "true" ]; then mkdir -p classes-tmp-for-ex - javac_with_bootclasspath -d classes-tmp-for-ex `find src -name '*.java'` src_tmp_for_ex="-cp classes-tmp-for-ex" fi + if [[ "${HAS_SRC}" == "true" ]]; then + javac_with_bootclasspath -d classes-tmp-for-ex `find src -name '*.java'` + fi if [[ "${HAS_SRC_ART}" == "true" ]]; then - mkdir -p classes-tmp-for-ex javac_with_bootclasspath -d classes-tmp-for-ex `find src-art -name '*.java'` - src_tmp_for_ex="-cp classes-tmp-for-ex" + fi + if [[ "${HAS_JASMIN}" == "true" ]]; then + make_jasmin classes-tmp-for-ex $(find 'jasmin' -name '*.j') fi mkdir -p classes-ex - javac_with_bootclasspath -d classes-ex $src_tmp_for_ex `find src-ex -name '*.java'` + if [ ${HAS_SRC_EX} = "true" ]; then + javac_with_bootclasspath -d classes-ex $src_tmp_for_ex `find src-ex -name '*.java'` + if [[ "x$src_tmp_for_ex" = "x" ]]; then + src_tmp_for_ex="-cp classes-ex" + else + src_tmp_for_ex="$src_tmp_for_ex:classes-ex" + fi + fi + if [ ${HAS_SRC_EX2} = "true" ]; then + javac_with_bootclasspath -d classes-ex $src_tmp_for_ex `find src-ex2 -name '*.java'` + fi fi if [[ -d classes-ex ]] && [ ${NEED_DEX} = "true" ]; then diff --git a/test/utils/regen-test-files b/test/utils/regen-test-files index 4a4bdfa612..066d747994 100755 --- a/test/utils/regen-test-files +++ b/test/utils/regen-test-files @@ -296,6 +296,7 @@ while read run_test; do [[ -d "$tests_dir/$run_test/jasmin-multidex" ]] && continue [[ -d "$tests_dir/$run_test/smali-ex" ]] && continue [[ -d "$tests_dir/$run_test/src-ex" ]] && continue + [[ -d "$tests_dir/$run_test/src-ex2" ]] && continue [[ -d "$tests_dir/$run_test/src-dex2oat-unresolved" ]] && continue # Ignore test with a copy of `sun.misc.Unsafe`. [[ -f "$tests_dir/$run_test/src/sun/misc/Unsafe.java" ]] && continue |