From 58b5f4d2043db07037fab5440b0124f67f0a8e4e Mon Sep 17 00:00:00 2001 From: Irwin D'Souza Date: Wed, 11 Dec 2024 13:55:43 -0500 Subject: [PATCH] Add SVM validations for JITServer ResolvedHandle/DynamicMethod APIs The JITServer version of getResolvedDynamicMethod and getResolvedHandleMethod were missing SVM validations, which caused errors when generate AOT support for Method Handles with JITServer. Signed-off-by: Irwin D'Souza --- runtime/compiler/env/j9methodServer.cpp | 60 ++++++++++++++++++-- runtime/compiler/net/CommunicationStream.hpp | 2 +- 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/runtime/compiler/env/j9methodServer.cpp b/runtime/compiler/env/j9methodServer.cpp index 0a0084b1e8b..4ddda39061f 100644 --- a/runtime/compiler/env/j9methodServer.cpp +++ b/runtime/compiler/env/j9methodServer.cpp @@ -1129,10 +1129,36 @@ TR_ResolvedJ9JITServerMethod::getResolvedHandleMethod(TR::Compilation *comp, I_3 auto ramMethod = std::get<0>(recv); auto &methodInfo = std::get<1>(recv); auto &signature = std::get<2>(recv); + auto unresolved = std::get<3>(recv); + auto invokeCacheAppendixNull = std::get<4>(recv); if (unresolvedInCP) - *unresolvedInCP = std::get<3>(recv); + *unresolvedInCP = unresolved; if (isInvokeCacheAppendixNull) - *isInvokeCacheAppendixNull = std::get<4>(recv); + *isInvokeCacheAppendixNull = invokeCacheAppendixNull; + +#if defined(J9VM_OPT_OPENJDK_METHODHANDLE) + if (comp->compileRelocatableCode()) + { + if (!unresolved) + { + bool valid = + comp->getSymbolValidationManager()->addHandleMethodFromCPIndex( + ramMethod, + getNonPersistentIdentifier(), + cpIndex, + invokeCacheAppendixNull); + + if (!valid) + comp->failCompilation("Failed to add validation record for resolved handle method %p", ramMethod); + } + else + { + // Call getMethodFromName to create an SVM record + auto dummyInvoke = _fe->getMethodFromName("java/lang/invoke/MethodHandle", "linkToStatic", "([Ljava/lang/Object;)Ljava/lang/Object;"); + TR_ASSERT_FATAL(ramMethod == dummyInvoke, "%p != %p; Unresolved targetMethod not dummyInvoke\n", ramMethod, dummyInvoke); + } + } +#endif // #if defined(J9VM_OPT_OPENJDK_METHODHANDLE) return static_cast(_fe)->createResolvedMethodWithSignature( comp->trMemory(), ramMethod, NULL, (char *)signature.data(), signature.length(), this, methodInfo @@ -1198,10 +1224,36 @@ TR_ResolvedJ9JITServerMethod::getResolvedDynamicMethod(TR::Compilation *comp, I_ auto ramMethod = std::get<0>(recv); auto &methodInfo = std::get<1>(recv); auto &signature = std::get<2>(recv); + auto unresolved = std::get<3>(recv); + auto invokeCacheAppendixNull = std::get<4>(recv); if (unresolvedInCP) - *unresolvedInCP = std::get<3>(recv); + *unresolvedInCP = unresolved; if (isInvokeCacheAppendixNull) - *isInvokeCacheAppendixNull = std::get<4>(recv); + *isInvokeCacheAppendixNull = invokeCacheAppendixNull; + +#if defined(J9VM_OPT_OPENJDK_METHODHANDLE) + if (comp->compileRelocatableCode()) + { + if (!unresolved) + { + bool valid = + comp->getSymbolValidationManager()->addDynamicMethodFromCallsiteIndex( + ramMethod, + getNonPersistentIdentifier(), + callSiteIndex, + invokeCacheAppendixNull); + + if (!valid) + comp->failCompilation("Failed to add validation record for resolved dynamic method %p", ramMethod); + } + else + { + // Call getMethodFromName to create an SVM record + auto dummyInvoke = _fe->getMethodFromName("java/lang/invoke/MethodHandle", "linkToStatic", "([Ljava/lang/Object;)Ljava/lang/Object;"); + TR_ASSERT_FATAL(ramMethod == dummyInvoke, "%p != %p; Unresolved targetMethod not dummyInvoke\n", ramMethod, dummyInvoke); + } + } +#endif // #if defined(J9VM_OPT_OPENJDK_METHODHANDLE) return static_cast(_fe)->createResolvedMethodWithSignature( comp->trMemory(), ramMethod, NULL, (char *)signature.data(), signature.size(), this, methodInfo diff --git a/runtime/compiler/net/CommunicationStream.hpp b/runtime/compiler/net/CommunicationStream.hpp index eca531df600..86e8cc0ec84 100644 --- a/runtime/compiler/net/CommunicationStream.hpp +++ b/runtime/compiler/net/CommunicationStream.hpp @@ -129,7 +129,7 @@ class CommunicationStream // likely to lose an increment when merging/rebasing/etc. // static const uint8_t MAJOR_NUMBER = 1; - static const uint16_t MINOR_NUMBER = 76; // ID: BpR0Syhau116Bh0vAoVr + static const uint16_t MINOR_NUMBER = 77; // ID: J440z7/ZN5+KF233VhGB static const uint8_t PATCH_NUMBER = 0; static uint32_t CONFIGURATION_FLAGS;