diff --git a/cvm/test/hotspot/runtime/linkResolver/LegacyInterfaceMethodref.java b/cvm/test/hotspot/runtime/linkResolver/LegacyInterfaceMethodref.java new file mode 100644 index 00000000000..bb9e00b721c --- /dev/null +++ b/cvm/test/hotspot/runtime/linkResolver/LegacyInterfaceMethodref.java @@ -0,0 +1,35 @@ +/* + * @test + * @summary Verify CVM8 accepts the legacy Scala 2.11 Methodref encoding for an interface static method + * @compile LegacyInterfaceMethodrefCaller.jasm + * @compile LegacyInterfaceMethodref.java + * @run main/othervm LegacyInterfaceMethodref + * @run main/othervm -Xint LegacyInterfaceMethodref + * @run main/othervm -Xcomp LegacyInterfaceMethodref + * @run main/othervm -XX:-AllowLegacyInterfaceMethodref -DexpectICCE=true LegacyInterfaceMethodref + */ + +interface LegacyStaticInterface { + static int value() { + return 42; + } +} + +public class LegacyInterfaceMethodref { + public static void main(String[] args) { + boolean expectICCE = Boolean.getBoolean("expectICCE"); + try { + int result = LegacyInterfaceMethodrefCaller.call(); + if (expectICCE) { + throw new AssertionError("Expected IncompatibleClassChangeError"); + } + if (result != 42) { + throw new AssertionError("Unexpected result: " + result); + } + } catch (IncompatibleClassChangeError error) { + if (!expectICCE) { + throw error; + } + } + } +} diff --git a/cvm/test/hotspot/runtime/linkResolver/LegacyInterfaceMethodrefCaller.jasm b/cvm/test/hotspot/runtime/linkResolver/LegacyInterfaceMethodrefCaller.jasm new file mode 100644 index 00000000000..ee0ef3e5062 --- /dev/null +++ b/cvm/test/hotspot/runtime/linkResolver/LegacyInterfaceMethodrefCaller.jasm @@ -0,0 +1,10 @@ +super public class LegacyInterfaceMethodrefCaller +version 52:0 +{ + public static Method call:"()I" + stack 1 locals 0 + { + invokestatic Method LegacyStaticInterface.value:"()I"; + ireturn; + } +} diff --git a/src/hotspot/share/interpreter/linkResolver.cpp b/src/hotspot/share/interpreter/linkResolver.cpp index 2e2259f1ee4..0da79838d0b 100644 --- a/src/hotspot/share/interpreter/linkResolver.cpp +++ b/src/hotspot/share/interpreter/linkResolver.cpp @@ -862,7 +862,16 @@ Method* LinkResolver::resolve_interface_method(const LinkInfo& link_info, Byteco } // check constant pool tag for called method - must be JVM_CONSTANT_InterfaceMethodref - if (!link_info.tag().is_invalid() && !link_info.tag().is_interface_method()) { +#if HOTSPOT_TARGET_CLASSLIB == 8 + const bool invalid_tag = !link_info.tag().is_invalid() && + !link_info.tag().is_interface_method() && + (!AllowLegacyInterfaceMethodref || + code != Bytecodes::_invokestatic || + !link_info.tag().is_method()); +#else + const bool invalid_tag = !link_info.tag().is_invalid() && !link_info.tag().is_interface_method(); +#endif + if (invalid_tag) { ResourceMark rm(THREAD); stringStream ss; ss.print("Method '"); diff --git a/src/hotspot/share/runtime/globals.hpp b/src/hotspot/share/runtime/globals.hpp index 67c06eb8d29..2e2c14b0ccb 100644 --- a/src/hotspot/share/runtime/globals.hpp +++ b/src/hotspot/share/runtime/globals.hpp @@ -2112,6 +2112,10 @@ const intx ObjectAlignmentInBytes = 8; "(default) disables native heap trimming.") \ range(0, UINT_MAX) \ \ + CLASSLIB8_ONLY(product(bool, AllowLegacyInterfaceMethodref, true, \ + "Allow invokestatic to reference an interface static " \ + "method with a Methodref constant")) \ + \ CLASSLIB8_ONLY(develop(bool, VerifyLatin1NamesOnly, false, \ "Ensure class/method/field names are encoded in Latin1")) \ \