Skip to content

Commit a6abd7e

Browse files
authored
Merge pull request #22009 from jdmpapin/mcs-koi
Identify `MutableCallSite` for guards based on known object index
2 parents c6a5459 + a48c46d commit a6abd7e

14 files changed

Lines changed: 98 additions & 100 deletions

runtime/compiler/control/JITClientCompilationThread.cpp

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,20 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
13001300
client->write(response, fe->inSnapshotMode());
13011301
}
13021302
break;
1303+
case MessageType::VM_mutableCallSiteEpoch:
1304+
{
1305+
auto recv = client->getRecvData<TR::KnownObjectTable::Index>();
1306+
TR::KnownObjectTable::Index mcs = std::get<0>(recv);
1307+
TR::KnownObjectTable::Index result = fe->mutableCallSiteEpoch(comp, mcs);
1308+
uintptr_t *resultRefLocation = NULL;
1309+
if (result != TR::KnownObjectTable::UNKNOWN)
1310+
{
1311+
resultRefLocation = knot->getPointerLocation(result);
1312+
}
13031313

1314+
client->write(response, result, resultRefLocation);
1315+
}
1316+
break;
13041317
case MessageType::mirrorResolvedJ9Method:
13051318
{
13061319
// allocate a new TR_ResolvedJ9Method on the heap, to be used as a mirror for performing actions which are only
@@ -2773,31 +2786,6 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
27732786
client->write(response, knot->getExistingIndexAt(objectPointerReference));
27742787
}
27752788
break;
2776-
case MessageType::KnownObjectTable_mutableCallSiteEpoch:
2777-
{
2778-
auto recv = client->getRecvData<uintptr_t*, bool>();
2779-
uintptr_t* mcsReferenceLocation = std::get<0>(recv);
2780-
bool knotEnabled = std::get<1>(recv);
2781-
2782-
uintptr_t mcsObject = 0;
2783-
TR::KnownObjectTable::Index knotIndex = TR::KnownObjectTable::UNKNOWN;
2784-
uintptr_t *objectPointerReference = NULL;
2785-
2786-
{
2787-
TR::VMAccessCriticalSection mutableCallSiteEpoch(fe);
2788-
mcsObject = fe->getStaticReferenceFieldAtAddress((uintptr_t)mcsReferenceLocation);
2789-
if (mcsObject && knotEnabled && knot)
2790-
{
2791-
TR_J9VMBase *fej9 = (TR_J9VMBase *)(fe);
2792-
knotIndex = fej9->mutableCallSiteEpoch(comp, mcsObject);
2793-
if (knotIndex != TR::KnownObjectTable::UNKNOWN)
2794-
objectPointerReference = knot->getPointerLocation(knotIndex);
2795-
}
2796-
}
2797-
2798-
client->write(response, mcsObject, knotIndex, objectPointerReference);
2799-
}
2800-
break;
28012789
case MessageType::KnownObjectTable_dereferenceKnownObjectField:
28022790
{
28032791
auto recv = client->getRecvData<TR::KnownObjectTable::Index, TR_ResolvedMethod *, int32_t>();

runtime/compiler/env/CHTable.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -575,9 +575,10 @@ TR_CHTable::commitVirtualGuard(TR_VirtualGuard *info, List<TR_VirtualGuardSite>
575575
// outside TR_CHTable::commit() in the future.
576576
TR_ASSERT(!comp->isOutOfProcessCompilation(), "TR_CHTable::commitVirtualGuard() should not be called at the server\n");
577577
#endif /* defined(J9VM_OPT_JITSERVER) */
578-
uintptr_t *mcsReferenceLocation = info->mutableCallSiteObject();
578+
TR::KnownObjectTable::Index mcs = info->mutableCallSiteObject();
579579
TR::KnownObjectTable *knot = comp->getKnownObjectTable();
580580
TR_ASSERT(knot, "MutableCallSiteTargetGuard requires the Known Object Table");
581+
uintptr_t *mcsReferenceLocation = knot->getPointerLocation(mcs);
581582
void *cookiePointer = comp->trPersistentMemory()->allocatePersistentMemory(1);
582583
uintptr_t potentialCookie = (uintptr_t)(uintptr_t)cookiePointer;
583584
uintptr_t cookie = 0;
@@ -587,7 +588,7 @@ TR_CHTable::commitVirtualGuard(TR_VirtualGuard *info, List<TR_VirtualGuardSite>
587588
{
588589
TR_J9VMBase *fej9 = (TR_J9VMBase *)(comp->fe());
589590
TR::VMAccessCriticalSection invalidateMCSTargetGuards(fej9);
590-
currentIndex = fej9->mutableCallSiteEpoch(comp, *mcsReferenceLocation);
591+
currentIndex = fej9->mutableCallSiteEpoch(comp, mcs);
591592
if (info->mutableCallSiteEpoch() == currentIndex)
592593
cookie = fej9->mutableCallSiteCookie(*mcsReferenceLocation, potentialCookie);
593594
else
@@ -776,8 +777,13 @@ VirtualGuardInfoForCHTable getImportantVGuardInfo(TR::Compilation *comp, TR_Virt
776777
info._mergedWithHCRGuard = vguard->mergedWithHCRGuard();
777778
info._mergedWithOSRGuard = vguard->mergedWithOSRGuard();
778779

779-
info._mutableCallSiteObject = info._kind == TR_MutableCallSiteTargetGuard ? vguard->mutableCallSiteObject() : NULL;
780-
info._mutableCallSiteEpoch = info._kind == TR_MutableCallSiteTargetGuard ? vguard->mutableCallSiteEpoch() : -1;
780+
info._mutableCallSiteObject = TR::KnownObjectTable::UNKNOWN;
781+
info._mutableCallSiteEpoch = TR::KnownObjectTable::UNKNOWN;
782+
if (info._kind == TR_MutableCallSiteTargetGuard)
783+
{
784+
info._mutableCallSiteObject = vguard->mutableCallSiteObject();
785+
info._mutableCallSiteEpoch = vguard->mutableCallSiteEpoch();
786+
}
781787

782788
info._inlinedResolvedMethod = info._kind == TR_BreakpointGuard
783789
? static_cast<TR_ResolvedJ9JITServerMethod *>(comp->getInlinedResolvedMethod(info._calleeIndex))->getRemoteMirror()

runtime/compiler/env/JITServerCHTable.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,10 @@ JITClientCommitVirtualGuard(const VirtualGuardInfoForCHTable *info, std::vector<
412412
static char *dontInvalidateMCSTargetGuards = feGetEnv("TR_dontInvalidateMCSTargetGuards");
413413
if (!dontInvalidateMCSTargetGuards)
414414
{
415-
uintptr_t *mcsReferenceLocation = info->_mutableCallSiteObject;
416415
TR::KnownObjectTable *knot = comp->getKnownObjectTable();
417416
TR_ASSERT(knot, "MutableCallSiteTargetGuard requires the Known Object Table");
417+
TR::KnownObjectTable::Index mcs = info->_mutableCallSiteObject;
418+
uintptr_t *mcsReferenceLocation = knot->getPointerLocation(mcs);
418419
void *cookiePointer = comp->trPersistentMemory()->allocatePersistentMemory(1);
419420
uintptr_t potentialCookie = (uintptr_t)(uintptr_t)cookiePointer;
420421
uintptr_t cookie = 0;
@@ -430,7 +431,7 @@ JITClientCommitVirtualGuard(const VirtualGuardInfoForCHTable *info, std::vector<
430431
// However, JITClientCHTableCommit() is called at the end of compilation,
431432
// and therefore it cannot cause any issues.
432433
TR::VMAccessCriticalSection invalidateMCSTargetGuards(fej9);
433-
currentIndex = fej9->mutableCallSiteEpoch(comp, *mcsReferenceLocation);
434+
currentIndex = fej9->mutableCallSiteEpoch(comp, mcs);
434435
if (info->_mutableCallSiteEpoch == currentIndex)
435436
cookie = fej9->mutableCallSiteCookie(*mcsReferenceLocation, potentialCookie);
436437
else

runtime/compiler/env/JITServerCHTable.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct VirtualGuardInfoForCHTable
4444
bool _mergedWithOSRGuard;
4545

4646
// These reference locations are non-null only for MutableCallSiteGuards
47-
uintptr_t *_mutableCallSiteObject;
47+
TR::KnownObjectTable::Index _mutableCallSiteObject;
4848
TR::KnownObjectTable::Index _mutableCallSiteEpoch;
4949

5050
// Part of the symref

runtime/compiler/env/VMJ9.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4753,13 +4753,17 @@ uintptr_t TR_J9VMBase::mutableCallSiteCookie(uintptr_t mutableCallSite, uintptr_
47534753
return result;
47544754
}
47554755

4756-
TR::KnownObjectTable::Index TR_J9VMBase::mutableCallSiteEpoch(TR::Compilation *comp, uintptr_t mutableCallSite)
4756+
TR::KnownObjectTable::Index TR_J9VMBase::mutableCallSiteEpoch(
4757+
TR::Compilation *comp, TR::KnownObjectTable::Index mcs)
47574758
{
4758-
TR_ASSERT_FATAL(haveAccess(), "mutableCallSiteEpoch requires VM access");
4759-
47604759
TR::KnownObjectTable *knot = comp->getKnownObjectTable();
47614760
if (knot == NULL)
4761+
{
47624762
return TR::KnownObjectTable::UNKNOWN;
4763+
}
4764+
4765+
TR::VMAccessCriticalSection mutableCallSiteEpoch(this);
4766+
uintptr_t mutableCallSite = knot->getPointer(mcs);
47634767

47644768
#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
47654769
// There is no separate epoch field

runtime/compiler/env/VMJ9.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,8 @@ class TR_J9VMBase : public TR_FrontEnd
890890
virtual TR_ResolvedMethod *createMethodHandleArchetypeSpecimen(TR_Memory *, TR_OpaqueMethodBlock *archetype, uintptr_t *methodHandleLocation, TR_ResolvedMethod *owningMethod = 0); // more efficient if you already know the archetype
891891

892892
virtual uintptr_t mutableCallSiteCookie(uintptr_t mutableCallSite, uintptr_t potentialCookie=0);
893-
TR::KnownObjectTable::Index mutableCallSiteEpoch(TR::Compilation *comp, uintptr_t mutableCallSite);
893+
virtual TR::KnownObjectTable::Index mutableCallSiteEpoch(
894+
TR::Compilation *comp, TR::KnownObjectTable::Index mcs);
894895

895896
struct MethodOfHandle
896897
{

runtime/compiler/env/VMJ9Server.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,6 +1943,22 @@ TR_J9ServerVM::createMethodHandleArchetypeSpecimen(TR_Memory *trMemory, uintptr_
19431943
return result;
19441944
}
19451945

1946+
TR::KnownObjectTable::Index
1947+
TR_J9ServerVM::mutableCallSiteEpoch(TR::Compilation *comp, TR::KnownObjectTable::Index mcs)
1948+
{
1949+
JITServer::ServerStream *stream = _compInfoPT->getMethodBeingCompiled()->_stream;
1950+
stream->write(JITServer::MessageType::VM_mutableCallSiteEpoch, mcs);
1951+
1952+
auto recv = stream->read<TR::KnownObjectTable::Index, uintptr_t*>();
1953+
TR::KnownObjectTable::Index result = std::get<0>(recv);
1954+
uintptr_t *resultRefLocation = std::get<1>(recv);
1955+
1956+
TR::KnownObjectTable *knot = comp->getKnownObjectTable();
1957+
knot->updateKnownObjectTableAtServer(result, resultRefLocation);
1958+
1959+
return result;
1960+
}
1961+
19461962
intptr_t
19471963
TR_J9ServerVM::getVFTEntry(TR_OpaqueClassBlock *clazz, int32_t offset)
19481964
{

runtime/compiler/env/VMJ9Server.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ class TR_J9ServerVM: public TR_J9VM
203203
virtual bool needsInvokeExactJ2IThunk(TR::Node *node, TR::Compilation *comp) override;
204204
virtual TR_ResolvedMethod *createMethodHandleArchetypeSpecimen(TR_Memory *trMemory, uintptr_t *methodHandleLocation, TR_ResolvedMethod *owningMethod = 0) override;
205205
virtual TR_ResolvedMethod *createMethodHandleArchetypeSpecimen(TR_Memory *trMemory, TR_OpaqueMethodBlock *archetype, uintptr_t *methodHandleLocation, TR_ResolvedMethod *owningMethod = 0) override;
206+
virtual TR::KnownObjectTable::Index mutableCallSiteEpoch(TR::Compilation *comp, TR::KnownObjectTable::Index mcs) override;
206207

207208
// Is method generated for LambdaForm
208209
virtual bool isLambdaFormGeneratedMethod(TR_OpaqueMethodBlock *method) override;

runtime/compiler/net/CommunicationStream.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class CommunicationStream
129129
// likely to lose an increment when merging/rebasing/etc.
130130
//
131131
static const uint8_t MAJOR_NUMBER = 1;
132-
static const uint16_t MINOR_NUMBER = 82; // ID: frPkOr+y+yphB/Otw4jO
132+
static const uint16_t MINOR_NUMBER = 83; // ID: yInQ3zszluYaDVc6hSwi
133133
static const uint8_t PATCH_NUMBER = 0;
134134
static uint32_t CONFIGURATION_FLAGS;
135135

runtime/compiler/net/MessageTypes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ const char *messageNames[] =
195195
"VM_isInvokeCacheEntryAnArray",
196196
"VM_getMethodHandleTableEntryIndex",
197197
"VM_getLayoutVarHandle",
198+
"VM_mutableCallSiteEpoch",
198199
"CompInfo_isCompiled",
199200
"CompInfo_getPCIfCompiled",
200201
"CompInfo_getInvocationCount",
@@ -252,7 +253,6 @@ const char *messageNames[] =
252253
"KnownObjectTable_getOrCreateIndexAt",
253254
"KnownObjectTable_getPointer",
254255
"KnownObjectTable_getExistingIndexAt",
255-
"KnownObjectTable_mutableCallSiteEpoch",
256256
"KnownObjectTable_dereferenceKnownObjectField",
257257
"KnownObjectTable_dereferenceKnownObjectField2",
258258
"KnownObjectTable_createSymRefWithKnownObject",

0 commit comments

Comments
 (0)