Skip to content

Commit

Permalink
Merge pull request #17856 from dsouzai/svmAssert
Browse files Browse the repository at this point in the history
Fix SVM Assert caused by missing class validation
  • Loading branch information
jdmpapin authored Aug 10, 2023
2 parents e4258d8 + 65bf23a commit 67e11c6
Showing 1 changed file with 41 additions and 16 deletions.
57 changes: 41 additions & 16 deletions runtime/compiler/optimizer/J9Inliner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "compile/ResolvedMethod.hpp"
#include "env/CompilerEnv.hpp"
#include "env/CHTable.hpp"
#include "env/HeuristicRegion.hpp"
#include "env/PersistentCHTable.hpp"
#include "env/VMJ9.h"
#include "env/jittypes.h"
Expand Down Expand Up @@ -862,8 +863,11 @@ bool TR_J9InterfaceCallSite::findCallSiteTargetImpl(
// heuristic because in that case we can be certain that the class
// won't be extended later.
bool useVftTestHeuristics = true;
TR::PersistentInfo *persistInfo = comp()->getPersistentInfo();
if (TR::Compiler->vm.isVMInStartupPhase(comp()->fej9()->getJ9JITConfig()))
if (comp()->compileRelocatableCode() && !comp()->getOption(TR_UseSymbolValidationManager))
{
useVftTestHeuristics = false;
}
else if (TR::Compiler->vm.isVMInStartupPhase(comp()->fej9()->getJ9JITConfig()))
{
const static bool useVftTestHeuristicsDuringStartup =
feGetEnv("TR_useInterfaceVftTestHeuristicsDuringStartup") != NULL;
Expand Down Expand Up @@ -924,36 +928,57 @@ bool TR_J9InterfaceCallSite::findCallSiteTargetImpl(
&& valueInfo != NULL
&& !comp()->getOption(TR_DisableProfiledInlining))
{
TR_ASSERT_FATAL(!comp()->compileRelocatableCode() || comp()->getOption(TR_UseSymbolValidationManager),
"Cannot use VFT Test Heuristics in non-SVM AOT!\n");

TR_ScratchList<TR_ExtraAddressInfo> byFreqDesc(comp()->trMemory());
valueInfo->getSortedList(comp(), &byFreqDesc);
ListIterator<TR_ExtraAddressInfo> it(&byFreqDesc);
uint32_t remainingTotalFreq = valueInfo->getTotalFrequency();
TR_OpaqueClassBlock *topProfiledClass = NULL;
uint32_t topProfiledFreq = 0;
TR_ExtraAddressInfo *cur = it.getFirst();
for (; cur != NULL; cur = it.getNext())

{
auto *curClass =
reinterpret_cast<TR_OpaqueClassBlock*>(cur->_value);
TR::HeuristicRegion heuristicRegion(comp());

if (persistInfo->isObsoleteClass(curClass, comp()->fe())
|| fe()->isInstanceOf(curClass, iface, true, true, true) != TR_yes)
{
remainingTotalFreq -= cur->_frequency;
}
else if (topProfiledClass == NULL)
TR::PersistentInfo *persistInfo = comp()->getPersistentInfo();
TR_ExtraAddressInfo *cur = it.getFirst();
for (; cur != NULL; cur = it.getNext())
{
topProfiledClass = curClass;
topProfiledFreq = cur->_frequency;
auto *curClass =
reinterpret_cast<TR_OpaqueClassBlock*>(cur->_value);

if (persistInfo->isObsoleteClass(curClass, comp()->fe())
|| fe()->isInstanceOf(curClass, iface, true, true, true) != TR_yes)
{
remainingTotalFreq -= cur->_frequency;
}
else if (topProfiledClass == NULL)
{
topProfiledClass = curClass;
topProfiledFreq = cur->_frequency;
}
}
}

if (topProfiledClass != NULL
&& remainingTotalFreq >= 32
&& topProfiledFreq == remainingTotalFreq)
{
testType = TR_VftTest;
thisClass = topProfiledClass;
bool valid = true;

if (comp()->compileRelocatableCode())
{
TR::SymbolValidationManager *svm = comp()->getSymbolValidationManager();
valid = svm->addProfiledClassRecord(topProfiledClass)
&& svm->addClassInstanceOfClassRecord(topProfiledClass, iface, true, true, true);
}

if (valid)
{
testType = TR_VftTest;
thisClass = topProfiledClass;
}
}
}
}
Expand Down

0 comments on commit 67e11c6

Please sign in to comment.