Skip to content

Commit

Permalink
Always call classMatchesCachedVersion in rememberClass
Browse files Browse the repository at this point in the history
See #15013 for more
details.

It is possible for two J9Classes to have the same J9ROMClass but have
different class chains. However, because a class chain is stored into
the SCC using a key derived from the J9ROMClass, it isn't possible to
store different class chains that have the same first J9ROMClass in the
chain. This can lead to undefined behaviour as invalid AOT code can be
executed.

This commit fixes the issue by changing the code that assumes that if it
can find an existing class chain in the SCC for a given J9Class, that it
is valid for said J9Class. The code now always validates the class
chain.

Signed-off-by: Irwin D'Souza <dsouzai.gh@gmail.com>
  • Loading branch information
dsouzai committed May 11, 2022
1 parent 29e80bf commit 33042c2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion runtime/compiler/env/J9SharedCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,15 @@ TR_J9SharedCache::rememberClass(J9Class *clazz, const AOTCacheClassChainRecord *
chainData = findChainForClass(clazz, key, keyLength);
if (chainData != NULL)
{
LOG(1, "\tchain exists (%p) so nothing to store\n", chainData);
if (classMatchesCachedVersion(clazz, chainData))
{
LOG(1, "\tcurrent class and class chain found (%p) are identical; returning the class chain\n", chainData);
}
else
{
LOG(1, "\tcurrent class and class chain found (%p) do not match, so cannot use class chain; returning NULL\n", chainData);
chainData = NULL;
}
return chainData;
}

Expand Down

0 comments on commit 33042c2

Please sign in to comment.