diff options
author | Nicolas Geoffray <ngeoffray@google.com> | 2024-05-09 15:13:50 +0100 |
---|---|---|
committer | Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> | 2024-05-10 13:36:02 +0000 |
commit | 14be0bbe4b8ed0af6dfbccc84de0af94fed4cd9d (patch) | |
tree | abd85d66f9cdfa32db18d682092e1c50bb1ac787 | |
parent | ef219ce92b4491ead921092a7f4992b8b0fecd6f (diff) | |
download | art-14be0bbe4b8ed0af6dfbccc84de0af94fed4cd9d.tar.gz |
Regression test for b/336842546.
We used to incorrectly assume a class in the profile would mean it
would be in the app image.
This got fixed with aosp/3064144.
Test: 854-image-inlining
Bug: 336842546
Change-Id: I0159b5594922b54f51943497fa25d782e6026bc4
-rw-r--r-- | test/854-image-inlining/expected-stderr.txt | 0 | ||||
-rw-r--r-- | test/854-image-inlining/expected-stdout.txt | 0 | ||||
-rw-r--r-- | test/854-image-inlining/info.txt | 4 | ||||
-rw-r--r-- | test/854-image-inlining/profile | 7 | ||||
-rw-r--r-- | test/854-image-inlining/run.py | 20 | ||||
-rw-r--r-- | test/854-image-inlining/src-ex/Test.java | 43 | ||||
-rw-r--r-- | test/854-image-inlining/src/Itf.java | 18 | ||||
-rw-r--r-- | test/854-image-inlining/src/Main.java | 40 | ||||
-rw-r--r-- | test/knownfailures.json | 1 |
9 files changed, 133 insertions, 0 deletions
diff --git a/test/854-image-inlining/expected-stderr.txt b/test/854-image-inlining/expected-stderr.txt new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/854-image-inlining/expected-stderr.txt diff --git a/test/854-image-inlining/expected-stdout.txt b/test/854-image-inlining/expected-stdout.txt new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/854-image-inlining/expected-stdout.txt diff --git a/test/854-image-inlining/info.txt b/test/854-image-inlining/info.txt new file mode 100644 index 0000000000..92564a9893 --- /dev/null +++ b/test/854-image-inlining/info.txt @@ -0,0 +1,4 @@ +We used to incorrectly assume a class in the profile would mean it +would be in the app image. + +This got fixed with aosp/3064144. diff --git a/test/854-image-inlining/profile b/test/854-image-inlining/profile new file mode 100644 index 0000000000..ec8fb7521c --- /dev/null +++ b/test/854-image-inlining/profile @@ -0,0 +1,7 @@ +# We need callInstance to be AOT compiled. The AOT compiled code used to wrongly assume +# the CallStatic class was loaded. +HSLTest;->callInstance()I + +# We need CallStatic to be in the profile to make the compiler think it will be part of +# the image. +LCallStatic; diff --git a/test/854-image-inlining/run.py b/test/854-image-inlining/run.py new file mode 100644 index 0000000000..621611002e --- /dev/null +++ b/test/854-image-inlining/run.py @@ -0,0 +1,20 @@ +#!/bin/bash +# +# Copyright (C) 2024 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. + + +def run(ctx, args): + # Make sure we pass the profile when compiling. + ctx.default_run(args, profile=True) diff --git a/test/854-image-inlining/src-ex/Test.java b/test/854-image-inlining/src-ex/Test.java new file mode 100644 index 0000000000..6f56a2759d --- /dev/null +++ b/test/854-image-inlining/src-ex/Test.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2024 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 WithStatic { + public static int field = 42; +} + +// `CallStatic` being part of the profile, the compiler used to think it will be in the app image. +// However, given it implements `Itf` which is from a different dex file from a different class +// loader, we cannot encode `CallStatic` in the image. We used to find that information too late in +// the compilation stage and were therefore wrongly assuming we could inline methods from +// `CallStatic` without the need for resolving it. +// +// Note that to trigger the crash, we needed an interface from a different dex file. We were +// correctly pruning the class if the superclass was from a different dex file. +class CallStatic implements Itf { + public static int $inline$foo() { + // Access a static field to make sure we invoke the runtime, which will then walk the call + // stack. + return WithStatic.field; + } +} + +public class Test { + public static int callInstance() { + // Call a method from `CallStatic` which will be inlined. If the compiler thinks `CallStatic` + // will be in the image, it will skip the slow path of resolving it. + return CallStatic.$inline$foo(); + } +} diff --git a/test/854-image-inlining/src/Itf.java b/test/854-image-inlining/src/Itf.java new file mode 100644 index 0000000000..963a194116 --- /dev/null +++ b/test/854-image-inlining/src/Itf.java @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2024 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 interface Itf { +} diff --git a/test/854-image-inlining/src/Main.java b/test/854-image-inlining/src/Main.java new file mode 100644 index 0000000000..f983344833 --- /dev/null +++ b/test/854-image-inlining/src/Main.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2024 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.Constructor; +import java.lang.reflect.Method; + +public class Main { + static final String DEX_FILE = + System.getenv("DEX_LOCATION") + "/854-image-inlining-ex.jar"; + static final String LIBRARY_SEARCH_PATH = System.getProperty("java.library.path"); + + public static void main(String[] args) throws Exception { + // Create the secondary class loader. + Class<?> pathClassLoader = Class.forName("dalvik.system.PathClassLoader"); + Constructor<?> constructor = + pathClassLoader.getDeclaredConstructor(String.class, String.class, ClassLoader.class); + ClassLoader loader = (ClassLoader) constructor.newInstance( + DEX_FILE, LIBRARY_SEARCH_PATH, ClassLoader.getSystemClassLoader()); + + // Invoke the test method to trigger the runtime crash. + Method m = loader.loadClass("Test").getDeclaredMethod("callInstance"); + int result = ((Integer) m.invoke(null)).intValue(); + if (result != 42) { + throw new Error("Expected 42, got " + result); + } + } +} diff --git a/test/knownfailures.json b/test/knownfailures.json index 89b5196d84..4e5a19d0eb 100644 --- a/test/knownfailures.json +++ b/test/knownfailures.json @@ -1178,6 +1178,7 @@ "846-multidex-data-image", "847-filled-new-aray", "848-pattern-match", + "854-image-inlining", "999-redefine-hiddenapi", "1000-non-moving-space-stress", "1001-app-image-regions", |