Skip to content

Commit

Permalink
Merge pull request eclipse-openj9#43 from cathyzhyi/nopbpguard
Browse files Browse the repository at this point in the history
Add support for nopable breakpoint guard
  • Loading branch information
andrewcraik authored Oct 10, 2017
2 parents 092787a + b9e6275 commit a04db82
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 5 deletions.
20 changes: 20 additions & 0 deletions runtime/tr.source/trj9/control/HookedByTheJit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3184,6 +3184,26 @@ void jitClassesRedefined(J9VMThread * currentThread, UDATA classCount, J9JITRede

#endif // #if (defined(TR_HOST_X86) || defined(TR_HOST_POWER) || defined(TR_HOST_S390))

void jitMethodBreakpointed(J9VMThread * vmThread, J9Method *j9method)
{
reportHook(vmThread, "jitMethodbreakpointed", "j9method %p\n", j9method);
J9JITConfig * jitConfig = vmThread->javaVM->jitConfig;
TR::CompilationInfo * compInfo = TR::CompilationInfo::get(jitConfig);
TR_RuntimeAssumptionTable *rat = compInfo->getPersistentInfo()->getRuntimeAssumptionTable();
OMR::RuntimeAssumption **headPtr = rat->getBucketPtr(RuntimeAssumptionOnMethodBreakPoint, TR_RuntimeAssumptionTable::hashCode((uintptrj_t)j9method));
TR_PatchNOPedGuardSiteOnMethodBreakPoint *cursor = (TR_PatchNOPedGuardSiteOnMethodBreakPoint *)(*headPtr);
while (cursor)
{
if (cursor->matches((uintptrj_t)j9method))
{
TR::PatchNOPedGuardSite::compensate(0, cursor->getLocation(), cursor->getDestination());
}
cursor = (TR_PatchNOPedGuardSiteOnMethodBreakPoint *)cursor->getNext();
}

reportHookFinished(vmThread, "jitMethodbreakpointed");
}

#if defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING)
static void jitHookInterruptCompilation(J9HookInterface * * hookInterface, UDATA eventNum, void * eventData, void * userData)
{
Expand Down
21 changes: 16 additions & 5 deletions runtime/tr.source/trj9/env/CHTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,6 @@ TR_CHTable::commitVirtualGuard(TR_VirtualGuard *info, List<TR_VirtualGuardSite>
return;
}

if (info->getKind() == TR_BreakpointGuard)
{
/* nothing to do */
return;
}

TR::SymbolReference *symRef = info->getSymbolReference();
TR::MethodSymbol *methodSymbol = symRef->getSymbol()->castToMethodSymbol();
Expand Down Expand Up @@ -409,6 +404,7 @@ TR_CHTable::commitVirtualGuard(TR_VirtualGuard *info, List<TR_VirtualGuardSite>
if (!info->isNopable())
return;
}

if (info->getKind() == TR_DummyGuard)
{
/* nothing to do */
Expand Down Expand Up @@ -462,6 +458,21 @@ TR_CHTable::commitVirtualGuard(TR_VirtualGuard *info, List<TR_VirtualGuardSite>
{
/* nothing to do */
}
else if (info->getKind() == TR_BreakpointGuard)
{
if (comp->getOption(TR_DisableNopBreakpointGuard))
return;
TR_ResolvedMethod *breakpointedMethod = comp->getInlinedResolvedMethod(info->getCalleeIndex());
TR_OpaqueMethodBlock *method = breakpointedMethod->getPersistentIdentifier();
if (comp->fej9()->isMethodBreakpointed(method))
nopAssumptionIsValid = false;
ListIterator<TR_VirtualGuardSite> it(&sites);
for (TR_VirtualGuardSite *site = it.getFirst(); site; site = it.getNext())
{
TR_PatchNOPedGuardSiteOnMethodBreakPoint
::make(comp->fe(), comp->trPersistentMemory(), method, site->getLocation(), site->getDestination(), comp->getMetadataAssumptionList());
}
}
else if (info->getKind() == TR_ArrayStoreCheckGuard)
{
guardedClass = info->getThisClass();
Expand Down
15 changes: 15 additions & 0 deletions runtime/tr.source/trj9/env/CHTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,21 @@ class TR_PatchNOPedGuardSiteOnMutableCallSiteChange : public TR::PatchNOPedGuard
virtual TR_RuntimeAssumptionKind getAssumptionKind() { return RuntimeAssumptionOnMutableCallSiteChange; }
};

class TR_PatchNOPedGuardSiteOnMethodBreakPoint : public TR::PatchNOPedGuardSite
{
protected:
TR_PatchNOPedGuardSiteOnMethodBreakPoint(TR_PersistentMemory *pm, TR_OpaqueMethodBlock *j9method,
uint8_t *location, uint8_t *destination)
: TR::PatchNOPedGuardSite(pm, (uintptrj_t)j9method, RuntimeAssumptionOnMethodBreakPoint, location, destination) {}

public:
static TR_PatchNOPedGuardSiteOnMethodBreakPoint *make(
TR_FrontEnd *fe, TR_PersistentMemory * pm, TR_OpaqueMethodBlock *j9method, uint8_t *location, uint8_t *destination,
OMR::RuntimeAssumption **sentinel);

virtual TR_RuntimeAssumptionKind getAssumptionKind() { return RuntimeAssumptionOnMethodBreakPoint; }
};

class TR_PatchJNICallSite : public OMR::ValueModifyRuntimeAssumption
{
protected:
Expand Down
2 changes: 2 additions & 0 deletions runtime/tr.source/trj9/env/RuntimeAssumptionTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ enum TR_RuntimeAssumptionKind
RuntimeAssumptionOnClassRedefinitionUPIC,
RuntimeAssumptionOnClassRedefinitionNOP,
RuntimeAssumptionOnMutableCallSiteChange,
RuntimeAssumptionOnMethodBreakPoint,
LastAssumptionKind,
// If you add another kind, add its name to the runtimeAssumptionKindNames array
RuntimeAssumptionSentinel // This is special as there is no hashtable associated with it and we only create one of them
Expand All @@ -61,6 +62,7 @@ char const * const runtimeAssumptionKindNames[LastAssumptionKind] =
"ClassRedefinitionUPIC",
"ClassRedefinitionNOP",
"MutableCallSiteChange",
"OnMethodBreakpoint",
};

struct TR_RatHT
Expand Down
5 changes: 5 additions & 0 deletions runtime/tr.source/trj9/env/VMJ9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ TR_J9VMBase::stackWalkerMaySkipFrames(TR_OpaqueMethodBlock *method, TR_OpaqueCla
return false;
}

bool
TR_J9VMBase::isMethodBreakpointed(TR_OpaqueMethodBlock *method)
{
return jitIsMethodBreakpointed(vmThread(), (J9Method *)method);
}

// Points to address: what if vmThread is not the compilation thread.
// What if the compilation thread does not have the classUnloadMonitor.
Expand Down
1 change: 1 addition & 0 deletions runtime/tr.source/trj9/env/VMJ9.h
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,7 @@ class TR_J9VMBase : public TR_FrontEnd
virtual bool shouldDelayAotLoad() { return false; }

virtual void *getLocationOfClassLoaderObjectPointer(TR_OpaqueClassBlock *classPointer);
virtual bool isMethodBreakpointed(TR_OpaqueMethodBlock *method);

protected:
#if defined(TR_TARGET_S390)
Expand Down
9 changes: 9 additions & 0 deletions runtime/tr.source/trj9/runtime/RuntimeAssumptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ TR_PatchNOPedGuardSiteOnClassPreInitialize::matches(char *sig, uint32_t sigLen)
return true;
}

TR_PatchNOPedGuardSiteOnMethodBreakPoint* TR_PatchNOPedGuardSiteOnMethodBreakPoint::make(
TR_FrontEnd *fe, TR_PersistentMemory * pm, TR_OpaqueMethodBlock *method, uint8_t *location, uint8_t *destination,
OMR::RuntimeAssumption **sentinel)
{
TR_PatchNOPedGuardSiteOnMethodBreakPoint *result = new (pm) TR_PatchNOPedGuardSiteOnMethodBreakPoint(pm, method, location, destination);
result->addToRAT(pm, RuntimeAssumptionOnMethodBreakPoint, fe, sentinel);
return result;
}


void
TR_PreXRecompile::compensate(TR_FrontEnd *fe, bool, void *)
Expand Down
3 changes: 3 additions & 0 deletions runtime/tr.source/trj9/runtime/codertinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ extern "C" UDATA jitAMD64Handler(J9VMThread* vmThread, U_32 sigType, void* sigIn
extern "C" void jitClassesRedefined(J9VMThread * currentThread, UDATA classCount, J9JITRedefinedClass *classList);
#endif

extern "C" void jitMethodBreakpointed(J9VMThread * currentThread, J9Method *j9method);

extern "C" void jitDiscardPendingCompilationsOfNatives(J9VMThread *vmThread, J9Class *clazz);

#if defined(J9VM_JIT_DYNAMIC_LOOP_TRANSFER)
Expand Down Expand Up @@ -516,6 +518,7 @@ void codert_init_helpers_and_targets(J9JITConfig * jitConfig, char isSMP)
jitConfig->jitClassesRedefined = jitClassesRedefined;
#endif
jitConfig->jitDiscardPendingCompilationsOfNatives = jitDiscardPendingCompilationsOfNatives;
jitConfig->jitMethodBreakpointed = jitMethodBreakpointed;

initializeCodertFunctionTable(javaVM);

Expand Down

0 comments on commit a04db82

Please sign in to comment.