Skip to content

Commit

Permalink
Merge pull request #18821 from cjjdespres/faking-the-scc-api-change
Browse files Browse the repository at this point in the history
Modify SCC queries to take non-persistent parameters
  • Loading branch information
mpirvu authored Jan 28, 2024
2 parents 2b552ad + 2abc8e7 commit 00a123d
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 35 deletions.
20 changes: 10 additions & 10 deletions runtime/compiler/codegen/J9AheadOfTimeCompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ J9::AheadOfTimeCompile::offsetInSharedCacheFromPointer(TR_SharedCache *sharedCac
}

uintptr_t
J9::AheadOfTimeCompile::offsetInSharedCacheFromROMClass(TR_SharedCache *sharedCache, J9ROMClass *romClass)
J9::AheadOfTimeCompile::offsetInSharedCacheFromClass(TR_SharedCache *sharedCache, TR_OpaqueClassBlock *clazz)
{
uintptr_t offset = 0;
if (sharedCache->isROMClassInSharedCache(romClass, &offset))
if (sharedCache->isClassInSharedCache(clazz, &offset))
return offset;
else
self()->comp()->failCompilation<J9::ClassChainPersistenceFailure>("Failed to find romClass %p in SCC", romClass);
self()->comp()->failCompilation<J9::ClassChainPersistenceFailure>("Failed to find clazz %p in SCC", clazz);

return offset;
}
Expand Down Expand Up @@ -550,8 +550,7 @@ J9::AheadOfTimeCompile::initializeCommonAOTRelocationHeader(TR::IteratedExternal
flags |= methodTracingEnabled;

TR_OpaqueClassBlock *inlinedMethodClass = resolvedMethod->containingClass();
J9ROMClass *romClass = reinterpret_cast<J9ROMClass *>(fej9->getPersistentClassPointerFromClassPointer(inlinedMethodClass));
uintptr_t romClassOffsetInSharedCache = self()->offsetInSharedCacheFromROMClass(sharedCache, romClass);
uintptr_t romClassOffsetInSharedCache = self()->offsetInSharedCacheFromClass(sharedCache, inlinedMethodClass);

imRecord->setReloFlags(reloTarget, flags);
imRecord->setInlinedSiteIndex(reloTarget, inlinedSiteIndex);
Expand All @@ -577,8 +576,7 @@ J9::AheadOfTimeCompile::initializeCommonAOTRelocationHeader(TR::IteratedExternal
uintptr_t inlinedSiteIndex = reinterpret_cast<uintptr_t>(relocation->getTargetAddress());
TR::AOTClassInfo *aotCI = reinterpret_cast<TR::AOTClassInfo *>(relocation->getTargetAddress2());

J9ROMClass *romClass = reinterpret_cast<J9ROMClass *>(fej9->getPersistentClassPointerFromClassPointer(aotCI->_clazz));
uintptr_t romClassOffsetInSharedCache = self()->offsetInSharedCacheFromROMClass(sharedCache, romClass);
uintptr_t romClassOffsetInSharedCache = self()->offsetInSharedCacheFromClass(sharedCache, aotCI->_clazz);

vsfRecord->setInlinedSiteIndex(reloTarget, inlinedSiteIndex);
vsfRecord->setConstantPool(reloTarget, reinterpret_cast<uintptr_t>(aotCI->_constantPool));
Expand Down Expand Up @@ -621,9 +619,11 @@ J9::AheadOfTimeCompile::initializeCommonAOTRelocationHeader(TR::IteratedExternal
TR_ResolvedMethod *inlinedMethod = comp->getInlinedResolvedMethod(inlinedSiteIndex);
TR_OpaqueClassBlock *inlinedCodeClass = reinterpret_cast<TR_OpaqueClassBlock *>(inlinedMethod->classOfMethod());

J9ROMClass *romClass = reinterpret_cast<J9ROMClass *>(fej9->getPersistentClassPointerFromClassPointer(inlinedCodeClass));
uintptr_t romClassOffsetInSharedCache = self()->offsetInSharedCacheFromROMClass(sharedCache, romClass);
traceMsg(comp, "class is %p, romclass is %p, offset is %llu\n", inlinedCodeClass, romClass, romClassOffsetInSharedCache);
uintptr_t romClassOffsetInSharedCache = self()->offsetInSharedCacheFromClass(sharedCache, inlinedCodeClass);
traceMsg(comp, "class is %p, romclass is %p, offset is %llu\n",
inlinedCodeClass,
reinterpret_cast<J9ROMClass *>(fej9->getPersistentClassPointerFromClassPointer(inlinedCodeClass)),
romClassOffsetInSharedCache);

uintptr_t classChainIdentifyingLoaderOffsetInSharedCache = sharedCache->getClassChainOffsetIdentifyingLoader(inlinedCodeClass);

Expand Down
16 changes: 8 additions & 8 deletions runtime/compiler/codegen/J9AheadOfTimeCompile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@ class OMR_EXTENSIBLE AheadOfTimeCompile : public OMR::AheadOfTimeCompileConnecto
#endif /* defined(J9VM_OPT_JITSERVER) */

/**
* @brief TR_J9SharedCache::offsetInSharedCacheFrom* asserts if the pointer
* passed in does not exist in the SCC. Under HCR, when an agent redefines
* a class, it causes the J9Class pointer to stay the same, but the
* J9ROMClass pointer changes. This means that if the compiler has a
* @brief TR_J9SharedCache::offsetInSharedCacheFrom* asserts if the persistent pointer
* (J9ROMClass, J9ROMMethod) underlying the value passed in does not exist in the SCC.
* Under HCR, when an agent redefines a class, it causes the J9Class pointer to stay the
* same, but the J9ROMClass pointer changes. This means that if the compiler has a
* reference to a J9Class who J9ROMClass was in the SCC at one point in the
* compilation, it may no longer be so at another point in the compilation.
*
Expand All @@ -206,20 +206,20 @@ class OMR_EXTENSIBLE AheadOfTimeCompile : public OMR::AheadOfTimeCompileConnecto
* compilation, the compiler will fail the compile if such a redefinition
* occurred.
*
* Calling TR_J9SharedCache::offsetInSharedCacheFromPointer after such a
* Calling TR_J9SharedCache::offsetInSharedCacheFromClass after such a
* redefinition could result in an assert. Therefore, this method exists as
* a wrapper around TR_J9SharedCache::isROMClassInSharedCache which doesn't
* a wrapper around TR_J9SharedCache::isClassInSharedCache which doesn't
* assert and conveniently, updates the location referred to by the cacheOffset
* pointer passed in as a parameter.
*
* If the ptr isn't in the SCC, then the current method will abort the
* compilation. If the ptr is in the SCC, then the cacheOffset will be updated.
*
* @param sharedCache pointer to the TR_SharedCache object
* @param romClass J9ROMClass * whose offset in the SCC is required
* @param clazz J9Class * whose J9ROMClass offset in the SCC is required
* @return The offset into the SCC of romClass
*/
uintptr_t offsetInSharedCacheFromROMClass(TR_SharedCache *sharedCache, J9ROMClass *romClass);
uintptr_t offsetInSharedCacheFromClass(TR_SharedCache *sharedCache, TR_OpaqueClassBlock *clazz);

/**
* @brief Same circumstance as offsetInSharedCacheFromROMClass above
Expand Down
2 changes: 1 addition & 1 deletion runtime/compiler/control/CompilationThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7902,7 +7902,7 @@ TR::CompilationInfoPerThreadBase::preCompilationTasks(J9VMThread * vmThread,

// Eligibility checks
&& !entry->_doNotUseAotCodeFromSharedCache
&& fe->sharedCache()->isROMClassInSharedCache(J9_CLASS_FROM_METHOD(method)->romClass)
&& fe->sharedCache()->isClassInSharedCache(J9_CLASS_FROM_METHOD(method))
&& !_compInfo.isMethodIneligibleForAot(method)
&& (!TR::Options::getAOTCmdLineOptions()->getOption(TR_AOTCompileOnlyFromBootstrap)
|| fe->isClassLibraryMethod((TR_OpaqueMethodBlock *)method), true)
Expand Down
4 changes: 2 additions & 2 deletions runtime/compiler/control/HookedByTheJit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ static void jitHookInitializeSendTarget(J9HookInterface * * hook, UDATA eventNum
TR_J9VMBase *fej9 = TR_J9VMBase::get(jitConfig, vmThread, TR_J9VMBase::AOT_VM);
TR_J9SharedCache *sc = fej9 ? fej9->sharedCache() : NULL;
#if defined(J9VM_INTERP_AOT_COMPILE_SUPPORT) && defined(J9VM_OPT_SHARED_CLASSES) && (defined(TR_HOST_X86) || defined(TR_HOST_POWER) || defined(TR_HOST_S390) || defined(TR_HOST_ARM) || defined(TR_HOST_ARM64))
if (sc && sc->isROMClassInSharedCache(J9_CLASS_FROM_METHOD(method)->romClass))
if (sc && sc->isClassInSharedCache(J9_CLASS_FROM_METHOD(method)))
{
PORT_ACCESS_FROM_JAVAVM(jitConfig->javaVM);
I_64 sharedQueryTime = 0;
Expand Down Expand Up @@ -642,7 +642,7 @@ static void jitHookInitializeSendTarget(J9HookInterface * * hook, UDATA eventNum
int32_t sigLen = sprintf(buf, "%.*s.%.*s%.*s", J9UTF8_LENGTH(className), utf8Data(className), J9UTF8_LENGTH(name), utf8Data(name), J9UTF8_LENGTH(signature), utf8Data(signature));
printf("Initial: Signature %s Count %d isLoopy %d isAOT %" OMR_PRIuPTR " is in SCC %d SCCContainsProfilingInfo %d \n",buf,TR::CompilationInfo::getInvocationCount(method),J9ROMMETHOD_HAS_BACKWARDS_BRANCHES(romMethod),
TR::Options::sharedClassCache() ? jitConfig->javaVM->sharedClassConfig->existsCachedCodeForROMMethod(vmThread, romMethod) : 0,
TR::Options::sharedClassCache() ? TR_J9VMBase::get(jitConfig, vmThread, TR_J9VMBase::AOT_VM)->sharedCache()->isROMClassInSharedCache(J9_CLASS_FROM_METHOD(method)->romClass) : 0,containsInfo) ; fflush(stdout);
TR::Options::sharedClassCache() ? TR_J9VMBase::get(jitConfig, vmThread, TR_J9VMBase::AOT_VM)->sharedCache()->isClassInSharedCache(J9_CLASS_FROM_METHOD(method)) : 0,containsInfo) ; fflush(stdout);
}
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/compiler/control/JITClientCompilationThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1885,7 +1885,7 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
// Collect AOT stats
TR_ResolvedJ9Method *resolvedMethod = std::get<0>(methodInfo).remoteMirror;

isRomClassForMethodInSC = fe->sharedCache()->isROMClassInSharedCache(J9_CLASS_FROM_METHOD(j9method)->romClass);
isRomClassForMethodInSC = fe->sharedCache()->isClassInSharedCache(J9_CLASS_FROM_METHOD(j9method));

J9Class *j9clazz = (J9Class *) J9_CLASS_FROM_CP(((J9RAMConstantPoolItem *) J9_CP_FROM_METHOD(((J9Method *)j9method))));
TR_OpaqueClassBlock *clazzOfInlinedMethod = fe->convertClassPtrToClassOffset(j9clazz);
Expand Down
7 changes: 7 additions & 0 deletions runtime/compiler/env/J9SharedCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,13 @@ TR_J9SharedCache::isROMStructureInSharedCache(void *romStructure, uintptr_t *cac
return false;
}

bool
TR_J9SharedCache::isClassInSharedCache(TR_OpaqueClassBlock *clazz, uintptr_t *cacheOffset)
{
J9ROMClass *romClass = reinterpret_cast<J9ROMClass *>(fe()->getPersistentClassPointerFromClassPointer(clazz));
return isROMClassInSharedCache(romClass, cacheOffset);
}

bool
TR_J9SharedCache::isROMClassInSharedCache(J9ROMClass *romClass, uintptr_t *cacheOffset)
{
Expand Down
24 changes: 19 additions & 5 deletions runtime/compiler/env/J9SharedCache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,18 @@ class TR_J9SharedCache : public TR_SharedCache
virtual bool isOffsetInSharedCache(uintptr_t encoded_offset, void *ptr = NULL);

/**
* \brief Checks whether the specified J9ROMClass exists in the SCC
* \brief Checks whether the J9ROMClass underlying the given class exists in the SCC
*
* \param[in] romClass The J9ROMClass * to check
* \param[out] cacheOffset If the J9ROMClass is in the SCC and this parameter
* \param[in] clazz The J9Class * to check
* \param[out] cacheOffset If the J9ROMClass associated to the J9Class is in the SCC and this parameter
* is not NULL the result of converting romClass into an offset will
* be returned here. If romClass does not point into the SCC, this
* be returned here. If it does not point into the SCC, this
* parameter is ignored.
* \return True if romClass points into the SCC, false otherwise.
*/
virtual bool isROMClassInSharedCache(J9ROMClass *romClass, uintptr_t *cacheOffset = NULL);
virtual bool isClassInSharedCache(TR_OpaqueClassBlock *clazz, uintptr_t *cacheOffset = NULL);
virtual bool isClassInSharedCache(J9Class *clazz, uintptr_t *cacheOffset = NULL)
{ return isClassInSharedCache(reinterpret_cast<TR_OpaqueClassBlock *>(clazz)); }

/**
* \brief Checks whether the specified offset is within the ROMClass section
Expand Down Expand Up @@ -505,6 +507,18 @@ class TR_J9SharedCache : public TR_SharedCache
*/
virtual bool isOffsetinROMClassesSectionInCache(const J9SharedClassCacheDescriptor *cacheDesc, uintptr_t offset);

/**
* \brief Checks whether the specified J9ROMClass exists in the SCC
*
* \param[in] romClass The J9ROMClass * to check
* \param[out] cacheOffset If the J9ROMClass is in the SCC and this parameter
* is not NULL the result of converting romClass into an offset will
* be returned here. If romClass does not point into the SCC, this
* parameter is ignored.
* \return True if romClass points into the SCC, false otherwise.
*/
virtual bool isROMClassInSharedCache(J9ROMClass *romClass, uintptr_t *cacheOffset = NULL);

/**
* \brief Gets the cached result of a prior class chain validation
*
Expand Down
3 changes: 2 additions & 1 deletion runtime/compiler/env/SharedCache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class TR_SharedCache

virtual J9ROMClass *romClassFromOffsetInSharedCache(uintptr_t offset) { return NULL; }
virtual uintptr_t offsetInSharedCacheFromROMClass(J9ROMClass *romClass) { return 0; }
virtual bool isROMClassInSharedCache(J9ROMClass *romClass, uintptr_t *cacheOffset = NULL) { return false; }
virtual uintptr_t offsetInSharedCacheFromClass(TR_OpaqueClassBlock *clazz) { return 0; }
virtual bool isClassInSharedCache(TR_OpaqueClassBlock *clazz, uintptr_t *cacheOffset = NULL) { return false; }
virtual bool isROMClassOffsetInSharedCache(uintptr_t offset, J9ROMClass **romClassPtr = NULL) { return false; }

virtual J9ROMMethod *romMethodFromOffsetInSharedCache(uintptr_t offset) { return NULL; }
Expand Down
5 changes: 3 additions & 2 deletions runtime/compiler/env/j9method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,10 +794,11 @@ static intptr_t getInitialCountForMethod(TR_ResolvedMethod *rm, TR::Compilation
#if defined(J9VM_INTERP_AOT_COMPILE_SUPPORT) && defined(J9VM_OPT_SHARED_CLASSES) && (defined(TR_HOST_X86) || defined(TR_HOST_POWER) || defined(TR_HOST_S390) || defined(TR_HOST_ARM) || defined(TR_HOST_ARM64))
if (TR::Options::sharedClassCache())
{
J9Class *ramClass = m->constantPoolHdr();
J9ROMClass *romClass = m->romClassPtr();
J9ROMMethod *romMethod = m->romMethod();

if (!comp->fej9()->sharedCache()->isROMClassInSharedCache(romClass))
if (!comp->fej9()->sharedCache()->isClassInSharedCache(ramClass))
{
#if defined(J9ZOS390)
// Do not change the counts on zos at the moment since the shared cache capacity is higher on this platform
Expand Down Expand Up @@ -1847,7 +1848,7 @@ TR_ResolvedRelocatableJ9Method::createResolvedMethodFromJ9Method(TR::Compilation
isSystemClassLoader = ((void*)_fe->vmThread()->javaVM->systemClassLoader->classLoaderObject == (void*)_fe->getClassLoader(clazzOfInlinedMethod));
}

bool methodInSCC = _fe->sharedCache()->isROMClassInSharedCache(J9_CLASS_FROM_METHOD(j9method)->romClass);
bool methodInSCC = _fe->sharedCache()->isClassInSharedCache(J9_CLASS_FROM_METHOD(j9method));
if (methodInSCC)
{
bool sameLoaders = false;
Expand Down
2 changes: 1 addition & 1 deletion runtime/compiler/env/j9methodServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,7 @@ TR_ResolvedJ9JITServerMethod::createResolvedMethodFromJ9MethodMirror(TR_Resolved
isSystemClassLoader = ((void*)fej9->vmThread()->javaVM->systemClassLoader->classLoaderObject == (void*)fej9->getClassLoader(clazzOfInlinedMethod));
}

if (fej9->sharedCache()->isROMClassInSharedCache(J9_CLASS_FROM_METHOD(j9method)->romClass))
if (fej9->sharedCache()->isClassInSharedCache(J9_CLASS_FROM_METHOD(j9method)))
{
bool sameLoaders = false;
TR_J9VMBase *fej9 = (TR_J9VMBase *)fe;
Expand Down
5 changes: 2 additions & 3 deletions runtime/compiler/runtime/IProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3055,7 +3055,7 @@ TR_IPBCDataCallGraph::canBePersisted(TR_J9SharedCache *sharedCache, TR::Persiste
return IPBC_ENTRY_PERSIST_UNLOADED;
}

if (!sharedCache->isROMClassInSharedCache(clazz->romClass))
if (!sharedCache->isClassInSharedCache(clazz))
{
releaseEntry(); // release the lock on the entry
return IPBC_ENTRY_PERSIST_NOTINSCC;
Expand Down Expand Up @@ -3114,8 +3114,7 @@ TR_IPBCDataCallGraph::createPersistentCopy(TR_J9SharedCache *sharedCache, TR_IPB
TR_OpaqueClassBlock *clazz = (TR_OpaqueClassBlock*)_csInfo.getClazz(indexMaxWeight);
if (!info->isUnloadedClass(clazz, true))
{
J9ROMClass *romClass = ((J9Class*)clazz)->romClass;
if (sharedCache->isROMClassInSharedCache(romClass))
if (sharedCache->isClassInSharedCache(clazz))
{
uintptr_t *classChain = sharedCache->rememberClass(clazz);
if (classChain)
Expand Down
2 changes: 1 addition & 1 deletion runtime/compiler/runtime/JITServerAOTDeserializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ JITServerAOTDeserializer::cacheRecord(const ClassSerializationRecord *record, TR

// Check that the ROMClass is in the SCC and get its SCC offset
uintptr_t offset = (uintptr_t)-1;
if (!_sharedCache->isROMClassInSharedCache(ramClass->romClass, &offset))
if (!_sharedCache->isClassInSharedCache(ramClass, &offset))
{
if (TR::Options::getVerboseOption(TR_VerboseJITServer))
TR_VerboseLog::writeLineLocked(TR_Vlog_JITServer, "ERROR: ROMClass %p %.*s ID %zu is not in SCC",
Expand Down

0 comments on commit 00a123d

Please sign in to comment.