summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Nicolas Geoffray <ngeoffray@google.com> 2022-10-04 15:32:33 +0100
committer Nicolas Geoffray <ngeoffray@google.com> 2022-10-05 14:41:02 +0000
commit8f0c6503461690e565edb83908373c86100c2fb8 (patch)
tree170527c22c4856457495400926c64cabd906e8ca
parent62ed9bb28ecf67f45bdc8cd0a7a262cb0bcbab80 (diff)
Add a test for invokeinterface and default methods.
In S we used to have a bug overriding the imt index of an abstract method. This got accidentally fixed in T, so add a regression test. Test: 843-default-interface Bug: 249522283 Change-Id: Ife65400a8ede0351bdcac67e6c6be44affdbe152
-rw-r--r--test/843-default-interface/expected-stderr.txt0
-rw-r--r--test/843-default-interface/expected-stdout.txt0
-rw-r--r--test/843-default-interface/info.txt2
-rw-r--r--test/843-default-interface/src/Impl.java21
-rw-r--r--test/843-default-interface/src/Itf.java21
-rw-r--r--test/843-default-interface/src/Main.java29
-rw-r--r--test/843-default-interface/src/OtherItf.java24
-rw-r--r--test/843-default-interface/src/SubItf.java23
-rw-r--r--test/843-default-interface/src2/OtherItf.java21
9 files changed, 141 insertions, 0 deletions
diff --git a/test/843-default-interface/expected-stderr.txt b/test/843-default-interface/expected-stderr.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/test/843-default-interface/expected-stderr.txt
diff --git a/test/843-default-interface/expected-stdout.txt b/test/843-default-interface/expected-stdout.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/test/843-default-interface/expected-stdout.txt
diff --git a/test/843-default-interface/info.txt b/test/843-default-interface/info.txt
new file mode 100644
index 0000000000..3586e7f225
--- /dev/null
+++ b/test/843-default-interface/info.txt
@@ -0,0 +1,2 @@
+Regression test for ArtMethod::CopyFrom, which used to wrongly override the
+imt_index_ of abstract methods with 0.
diff --git a/test/843-default-interface/src/Impl.java b/test/843-default-interface/src/Impl.java
new file mode 100644
index 0000000000..8c9d76c565
--- /dev/null
+++ b/test/843-default-interface/src/Impl.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2022 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 Impl implements SubItf {
+ public String foo() {
+ return "Impl";
+ }
+}
diff --git a/test/843-default-interface/src/Itf.java b/test/843-default-interface/src/Itf.java
new file mode 100644
index 0000000000..0625429238
--- /dev/null
+++ b/test/843-default-interface/src/Itf.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2022 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 {
+ public default String bar() {
+ return "Itf";
+ }
+}
diff --git a/test/843-default-interface/src/Main.java b/test/843-default-interface/src/Main.java
new file mode 100644
index 0000000000..8b2b2dae92
--- /dev/null
+++ b/test/843-default-interface/src/Main.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2022 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 {
+ static SubItf itf = new Impl();
+ public static void main(String[] args) throws Exception {
+ // Loop enough to trigger the native OOME.
+ for (int i = 0; i < 50000; ++i) {
+ // Because the imt index was overwritten to 0, this call ended up
+ // in the conflict trampoline which wrongly updated the 0th entry
+ // of the imt table. This lead to this call always calling the
+ // conflict trampoline.
+ itf.foo();
+ }
+ }
+}
diff --git a/test/843-default-interface/src/OtherItf.java b/test/843-default-interface/src/OtherItf.java
new file mode 100644
index 0000000000..368631c4e6
--- /dev/null
+++ b/test/843-default-interface/src/OtherItf.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2022 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 OtherItf {
+ // javac will complain when compiling SubItf if both superinterfaces Itf and OtherItf
+ // define a default method bar(), so we do not define bar() here.
+ // What will be loaded at runtime will actually be src2/OtherItf.
+ // public default String bar() {
+ // return "OtherItf";
+ // }
+}
diff --git a/test/843-default-interface/src/SubItf.java b/test/843-default-interface/src/SubItf.java
new file mode 100644
index 0000000000..6983b185db
--- /dev/null
+++ b/test/843-default-interface/src/SubItf.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+
+// The method bar will be a default conflict for this class. That used to make
+// the class linker re-allocate its ArtMethod array, and calling CopyFrom.
+// The bug was that CopyFrom was overwriting the imt index of interface methods,
+// and for this example `foo`.
+public interface SubItf extends Itf, OtherItf {
+ public String foo();
+}
diff --git a/test/843-default-interface/src2/OtherItf.java b/test/843-default-interface/src2/OtherItf.java
new file mode 100644
index 0000000000..08028f4ced
--- /dev/null
+++ b/test/843-default-interface/src2/OtherItf.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2022 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 OtherItf {
+ public default String bar() {
+ return "OtherItf";
+ }
+}