From 63b8399f3f144769260d93a7a985233e5ac5b910 Mon Sep 17 00:00:00 2001 From: Almaz Mingaleev Date: Thu, 29 Aug 2024 12:57:14 +0000 Subject: 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 and 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 --- .../src/InvokeInterfaceForClassInitializer.java | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 test/2280-const-method-handle-validation/src/InvokeInterfaceForClassInitializer.java (limited to 'test/2280-const-method-handle-validation/src/InvokeInterfaceForClassInitializer.java') diff --git a/test/2280-const-method-handle-validation/src/InvokeInterfaceForClassInitializer.java b/test/2280-const-method-handle-validation/src/InvokeInterfaceForClassInitializer.java new file mode 100644 index 0000000000..a837a7a066 --- /dev/null +++ b/test/2280-const-method-handle-validation/src/InvokeInterfaceForClassInitializer.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 InvokeInterfaceForClassInitializer { + + private static int STATIC_FIELD = 1; + + private static void unreachable() { + throw new AssertionError("unreachable!"); + } + + @ConstantMethodHandle( + kind = ConstantMethodHandle.INVOKE_INTERFACE, + owner = "InvokeInterfaceForClassInitializer", + fieldOrMethodName = "", + descriptor = "()V") + private static MethodHandle forClassInitializer() { + unreachable(); + return null; + } + + public static void runTests() { + forClassInitializer(); + } + +} -- cgit v1.2.3-59-g8ed1b