Skip to content

Commit

Permalink
VPKnownObject Constraints for JITServer
Browse files Browse the repository at this point in the history
Ensure VPKnownObject works in server mode with appropriate queries.

Signed-off-by: Luke Li <[email protected]>
  • Loading branch information
luke-li-2003 committed Nov 28, 2024
1 parent 752c652 commit 31ed188
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 0 deletions.
18 changes: 18 additions & 0 deletions runtime/compiler/control/JITClientCompilationThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,24 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
client->write(response, fe->getObjectClassFromKnownObjectIndex(comp, idx));
}
break;
case MessageType::VM_getObjectClassFromKnownObjectIndexJLClass:
{
auto recv = client->getRecvData<TR::KnownObjectTable::Index, bool>();
auto idx = std::get<0>(recv);
bool isJL = std::get<1>(recv);
client->write(response, fe->getObjectClassFromKnownObjectIndex(comp, idx, &isJL), isJL);
}
break;
case MessageType::VM_getObjectClassInfoFromObjectReferenceLocation:
{
auto recv = client->getRecvData<uintptr_t>();
uintptr_t objectReferenceLocation = std::get<0>(recv);
auto ci = fe->getObjectClassInfoFromObjectReferenceLocation(comp, objectReferenceLocation);
client->write(response,
ci,
knot->getPointerLocation(ci.knownObjectIndex));
}
break;
case MessageType::VM_stackWalkerMaySkipFrames:
{
client->getRecvData<JITServer::Void>();
Expand Down
48 changes: 48 additions & 0 deletions runtime/compiler/env/VMJ9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1213,13 +1213,61 @@ TR_J9VMBase::getObjectClassFromKnownObjectIndex(TR::Compilation *comp, TR::Known
return clazz;
}

TR_OpaqueClassBlock *
TR_J9VMBase::getObjectClassFromKnownObjectIndex(TR::Compilation *comp,
TR::KnownObjectTable::Index idx,
bool *isJavaLangClass)
{
TR::VMAccessCriticalSection vpKnownObjectCriticalSection(comp);

TR::KnownObjectTable *knot = comp->getKnownObjectTable();
if (!knot)
return NULL;

TR_OpaqueClassBlock *clazz = getObjectClass(knot->getPointer(idx));
TR_OpaqueClassBlock *jlClass = getClassClassPointer(clazz);
*isJavaLangClass = (clazz == jlClass);
if (*isJavaLangClass)
{
clazz = getClassFromJavaLangClass(knot->getPointer(idx));
}
return clazz;
}
uintptr_t
TR_J9VMBase::getStaticReferenceFieldAtAddress(uintptr_t fieldAddress)
{
TR_ASSERT(haveAccess(), "Must haveAccess in getStaticReferenceFieldAtAddress");
return (uintptr_t)J9STATIC_OBJECT_LOAD(vmThread(), NULL, fieldAddress);
}

TR_J9VMBase::ObjectClassInfo
TR_J9VMBase::getObjectClassInfoFromObjectReferenceLocation(TR::Compilation *comp,
uintptr_t objectReferenceLocation)
{
TR_J9VMBase::ObjectClassInfo ci = {};
TR::KnownObjectTable *knot = comp->getKnownObjectTable();
if (knot)
{
TR::VMAccessCriticalSection getObjectReferenceLocation(comp);
uintptr_t objectReference = getStaticReferenceFieldAtAddress
(objectReferenceLocation);
ci.clazz = getObjectClass(objectReference);
ci.isString = isString(ci.clazz);
ci.jlClass = getClassClassPointer(ci.clazz);
ci.isFixedJavaLangClass = (ci.jlClass == ci.clazz);
if (ci.isFixedJavaLangClass)
{
// A FixedClass constraint means something different
// when the class happens to be java/lang/Class.
// Must add constraints pertaining to the class that
// the java/lang/Class object represents.
ci.clazz = getClassFromJavaLangClass(objectReference);
}
ci.knownObjectIndex = knot->getOrCreateIndex(objectReference);
}
return ci;
}

uintptr_t
TR_J9VMBase::getReferenceFieldAtAddress(uintptr_t fieldAddress)
{
Expand Down
15 changes: 15 additions & 0 deletions runtime/compiler/env/VMJ9.h
Original file line number Diff line number Diff line change
Expand Up @@ -635,13 +635,28 @@ class TR_J9VMBase : public TR_FrontEnd
virtual TR_OpaqueClassBlock *getObjectClass(uintptr_t objectPointer);
virtual TR_OpaqueClassBlock *getObjectClassAt(uintptr_t objectAddress);
virtual TR_OpaqueClassBlock *getObjectClassFromKnownObjectIndex(TR::Compilation *comp, TR::KnownObjectTable::Index idx);
virtual TR_OpaqueClassBlock *getObjectClassFromKnownObjectIndex(TR::Compilation *comp, TR::KnownObjectTable::Index idx, bool *isJavaLangClass);
virtual uintptr_t getReferenceFieldAt(uintptr_t objectPointer, uintptr_t offsetFromHeader);
virtual uintptr_t getVolatileReferenceFieldAt(uintptr_t objectPointer, uintptr_t offsetFromHeader);
virtual uintptr_t getReferenceFieldAtAddress(uintptr_t fieldAddress);
virtual uintptr_t getReferenceFieldAtAddress(void *fieldAddress){ return getReferenceFieldAtAddress((uintptr_t)fieldAddress); }
virtual uintptr_t getStaticReferenceFieldAtAddress(uintptr_t fieldAddress);
virtual int32_t getInt32FieldAt(uintptr_t objectPointer, uintptr_t fieldOffset);

/* Used to contain all information needed for getObjectClassInfoFromObjectReferenceLocation
* to create a VPKnownObject constraint.
*/
struct ObjectClassInfo
{
TR_OpaqueClassBlock *clazz;
TR_OpaqueClassBlock *jlClass;
bool isFixedJavaLangClass;
bool isString;
TR::KnownObjectTable::Index knownObjectIndex;
};
virtual ObjectClassInfo getObjectClassInfoFromObjectReferenceLocation
(TR::Compilation *comp, uintptr_t objectReferenceLocation);

int32_t getInt32Field(uintptr_t objectPointer, const char *fieldName)
{
return getInt32FieldAt(objectPointer, getInstanceFieldOffset(getObjectClass(objectPointer), fieldName, "I"));
Expand Down
29 changes: 29 additions & 0 deletions runtime/compiler/env/VMJ9Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,12 +947,41 @@ TR_J9ServerVM::getObjectClassFromKnownObjectIndex(TR::Compilation *comp, TR::Kno
return std::get<0>(stream->read<TR_OpaqueClassBlock *>());
}

TR_OpaqueClassBlock *
TR_J9ServerVM::getObjectClassFromKnownObjectIndex(TR::Compilation *comp,
TR::KnownObjectTable::Index idx,
bool *isJavaLangClass)
{
JITServer::ServerStream *stream = _compInfoPT->getMethodBeingCompiled()->_stream;
stream->write(JITServer::MessageType::VM_getObjectClassFromKnownObjectIndexJLClass,
idx, *isJavaLangClass);
auto recv = stream->read<TR_OpaqueClassBlock *, bool>();
*isJavaLangClass = std::get<1>(recv);
return std::get<0>(recv);
}

uintptr_t
TR_J9ServerVM::getStaticReferenceFieldAtAddress(uintptr_t fieldAddress)
{
TR_ASSERT_FATAL(false, "getStaticReferenceFieldAtAddress() should not be called by JITServer");
}

TR_J9VMBase::ObjectClassInfo
TR_J9ServerVM::getObjectClassInfoFromObjectReferenceLocation(TR::Compilation *comp, uintptr_t objectReferenceLocation)
{
JITServer::ServerStream *stream = _compInfoPT->getMethodBeingCompiled()->_stream;
stream->write(JITServer::MessageType::VM_getObjectClassInfoFromObjectReferenceLocation,
objectReferenceLocation);

auto recv = stream->read<TR_J9VMBase::ObjectClassInfo, uintptr_t *>();
TR_J9VMBase::ObjectClassInfo result = std::get<0>(recv);

uintptr_t *objectReferenceLocationClient = std::get<1>(recv);
comp->getKnownObjectTable()->updateKnownObjectTableAtServer(result.knownObjectIndex, objectReferenceLocationClient);

return result;
}

bool
TR_J9ServerVM::stackWalkerMaySkipFrames(TR_OpaqueMethodBlock *method, TR_OpaqueClassBlock *clazz)
{
Expand Down
4 changes: 4 additions & 0 deletions runtime/compiler/env/VMJ9Server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,12 @@ class TR_J9ServerVM: public TR_J9VM
virtual TR_OpaqueClassBlock * getObjectClass(uintptr_t objectPointer) override;
virtual TR_OpaqueClassBlock * getObjectClassAt(uintptr_t objectAddress) override;
virtual TR_OpaqueClassBlock *getObjectClassFromKnownObjectIndex(TR::Compilation *comp, TR::KnownObjectTable::Index idx) override;
virtual TR_OpaqueClassBlock *getObjectClassFromKnownObjectIndex(TR::Compilation *comp, TR::KnownObjectTable::Index idx, bool *isJavaLangClass) override;
virtual uintptr_t getStaticReferenceFieldAtAddress(uintptr_t fieldAddress) override;

virtual ObjectClassInfo getObjectClassInfoFromObjectReferenceLocation
(TR::Compilation *comp, uintptr_t objectReferenceLocation) override;

virtual bool stackWalkerMaySkipFrames(TR_OpaqueMethodBlock *method, TR_OpaqueClassBlock *clazz) override;
virtual bool hasFinalFieldsInClass(TR_OpaqueClassBlock *clazz) override;
virtual const char *sampleSignature(TR_OpaqueMethodBlock * aMethod, char *buf, int32_t bufLen, TR_Memory *memory) override;
Expand Down
2 changes: 2 additions & 0 deletions runtime/compiler/net/MessageTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ const char *messageNames[] =
"VM_getObjectClass",
"VM_getObjectClassAt",
"VM_getObjectClassFromKnownObjectIndex",
"VM_getObjectClassFromKnownObjectIndexJLClass",
"VM_getObjectClassInfoFromObjectReferenceLocation",
"VM_stackWalkerMaySkipFrames",
"VM_getStringUTF8Length",
"VM_classInitIsFinished",
Expand Down
2 changes: 2 additions & 0 deletions runtime/compiler/net/MessageTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ enum MessageType : uint16_t
VM_getObjectClass,
VM_getObjectClassAt,
VM_getObjectClassFromKnownObjectIndex,
VM_getObjectClassFromKnownObjectIndexJLClass,
VM_getObjectClassInfoFromObjectReferenceLocation,
VM_stackWalkerMaySkipFrames,
VM_getStringUTF8Length,
VM_classInitIsFinished,
Expand Down

0 comments on commit 31ed188

Please sign in to comment.