summaryrefslogtreecommitdiff
path: root/test/2280-const-method-handle-validation/src/InvokeStaticForClassInitializer.java
diff options
context:
space:
mode:
author Almaz Mingaleev <mingaleev@google.com> 2024-08-29 12:57:14 +0000
committer Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2024-09-24 10:15:56 +0000
commit63b8399f3f144769260d93a7a985233e5ac5b910 (patch)
tree2d46e0d91f2df79a80f9ed80cdcb49c08e7de9f6 /test/2280-const-method-handle-validation/src/InvokeStaticForClassInitializer.java
parent0b8cc45c57bd0d13901e2c1d15f74c8b562fb2d2 (diff)
Add more validation for const-method-handle.
Making it closer to JVMS 4.4.8 and 5.4.3.5. The RI rejects certain constructions at the class verification stage, hence there are separate classes for MethodHandle-s targeting <init> and <clinit> methods. In these cases The RI throws ClassFormatError during class load, but currently we do validations only when actual MethodHandle object is constructed, that's is the reason why test code has ICCE | CFE in catch blocks. That will be addressed in the upcoming CLs. This should not cause any compat issues as even if some of these MethodHandle were constructed successfully, their invocation leads to runtime crashes. Bug: 297147201 Test: ./art/test/testrunner/testrunner.py --host --64 --jvm -b Change-Id: I551b04e3c00ffc8bcdeac4760d9ac4b3bb7b2aff
Diffstat (limited to 'test/2280-const-method-handle-validation/src/InvokeStaticForClassInitializer.java')
-rw-r--r--test/2280-const-method-handle-validation/src/InvokeStaticForClassInitializer.java43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/2280-const-method-handle-validation/src/InvokeStaticForClassInitializer.java b/test/2280-const-method-handle-validation/src/InvokeStaticForClassInitializer.java
new file mode 100644
index 0000000000..ebce0ee3d2
--- /dev/null
+++ b/test/2280-const-method-handle-validation/src/InvokeStaticForClassInitializer.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.
+ */
+
+import java.lang.invoke.MethodHandle;
+
+import annotations.ConstantMethodHandle;
+
+public class InvokeStaticForClassInitializer {
+
+ private static int STATIC_FIELD = 1;
+
+ private static void unreachable() {
+ throw new AssertionError("unreachable!");
+ }
+
+ @ConstantMethodHandle(
+ kind = ConstantMethodHandle.INVOKE_STATIC,
+ owner = "InvokeStaticForClassInitializer",
+ fieldOrMethodName = "<clinit>",
+ descriptor = "()V")
+ private static MethodHandle forClassInitializer() {
+ unreachable();
+ return null;
+ }
+
+ public static void runTests() {
+ forClassInitializer();
+ }
+
+}