From 2669f1f07085773d4d8aa00ffd7c36138edb8b7d Mon Sep 17 00:00:00 2001 From: Christian Despres Date: Mon, 16 Dec 2024 15:09:11 -0500 Subject: [PATCH] Avoid shared lambda form statics name comparison When lambda form sharing is enabled, distinct lambda forms can end up with identical names and signatures, since that option causes the non-deterministic address suffix in their name to be replaced with a NULL address. Thus, the existing name comparison in TR_ResolvedJ9JITServerMethod::staticsAreSame() could cause distinct lambda forms to be identified together inappropriately, leading to crashes in remotely-compiled code. The new code instead always treats two lambda forms with identical names as being distinct, relying on the existing fallback in TR_J9ServerVM::jitStaticsAreSame() to ensure that equal lambda forms are correctly identified as such. Signed-off-by: Christian Despres --- runtime/compiler/env/j9methodServer.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/runtime/compiler/env/j9methodServer.cpp b/runtime/compiler/env/j9methodServer.cpp index 9235177ae9f..0a0084b1e8b 100644 --- a/runtime/compiler/env/j9methodServer.cpp +++ b/runtime/compiler/env/j9methodServer.cpp @@ -477,7 +477,8 @@ TR_ResolvedJ9JITServerMethod::fieldsAreSame(int32_t cpIndex1, TR_ResolvedMethod bool TR_ResolvedJ9JITServerMethod::staticsAreSame(int32_t cpIndex1, TR_ResolvedMethod *m2, int32_t cpIndex2, bool &sigSame) { - if (TR::comp()->compileRelocatableCode()) + auto comp = TR::comp(); + if (comp->compileRelocatableCode()) // in AOT, this should always return false, because mainline compares class loaders // with fe->sameClassLoaders, which always returns false for AOT compiles return false; @@ -509,7 +510,16 @@ TR_ResolvedJ9JITServerMethod::staticsAreSame(int32_t cpIndex1, TR_ResolvedMethod char *declaringClassName2 = serverMethod2->classNameOfFieldOrStatic(cpIndex2, class2Len); if (class1Len == class2Len && !memcmp(declaringClassName1, declaringClassName2, class1Len)) - return true; + { +#if defined(J9VM_OPT_OPENJDK_METHODHANDLE) + // Lambda form name comparison is unreliable when they are shared, so + // pretend that the name and signature comparison was inconclusive and + // rely on the fallback in TR_J9VM::jitStaticsAreSame(). + if (isLambdaFormClassName(declaringClassName1, class1Len, NULL)) + return false; +#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */ + return true; + } } else {