Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VPKnownObject Constraints for JITServer #7565

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 11 additions & 21 deletions compiler/optimizer/VPConstraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1353,28 +1353,18 @@ TR::VPKnownObject *TR::VPKnownObject::create(OMR::ValuePropagation *vp, TR::Know
//
constraint = NULL;
#ifdef J9_PROJECT_SPECIFIC
{
TR::VMAccessCriticalSection vpKnownObjectCriticalSection(vp->comp(),
TR::VMAccessCriticalSection::tryToAcquireVMAccess);

if (vpKnownObjectCriticalSection.hasVMAccess())
{
TR_OpaqueClassBlock *clazz = TR::Compiler->cls.objectClass(vp->comp(), knot->getPointer(index));
TR_OpaqueClassBlock *jlClass = vp->fe()->getClassClassPointer(clazz);
if (isJavaLangClass)
{
TR_ASSERT(clazz == jlClass, "Use createForJavaLangClass only for instances of java/lang/Class");
clazz = TR::Compiler->cls.classFromJavaLangClass(vp->comp(), knot->getPointer(index));
}
else
{
// clazz is already right
TR_ASSERT(clazz != jlClass, "For java/lang/Class instances, caller needs to use createForJavaLangClass.");
}
constraint = new (vp->trStackMemory()) TR::VPKnownObject(clazz, vp->comp(), index, isJavaLangClass);
vp->addConstraint(constraint, hash);
}
}
bool matchJavaLangClass;
TR_OpaqueClassBlock *clazz = vp->comp()->fej9()->getObjectClassFromKnownObjectIndex
(vp->comp(), index, &matchJavaLangClass);
TR_ASSERT_FATAL(matchJavaLangClass == isJavaLangClass,
"Use createForJavaLangClass if and only if the object is an instance of java/lang/Class");

constraint = new (vp->trStackMemory()) TR::VPKnownObject(clazz,
vp->comp(),
index,
isJavaLangClass);
vp->addConstraint(constraint, hash);
#endif
return constraint;
}
Expand Down
53 changes: 14 additions & 39 deletions compiler/optimizer/VPHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1698,18 +1698,12 @@ static const char *getFieldSignature(OMR::ValuePropagation *vp, TR::Node *node,
*/
static bool addKnownObjectConstraints(OMR::ValuePropagation *vp, TR::Node *node)
{
// Access to VM for multiple operations including KnownObjectTable::getOrCreateIndex()
// is not supported at the server for OMR.
if (vp->comp()->isOutOfProcessCompilation())
return false;

TR::KnownObjectTable *knot = vp->comp()->getKnownObjectTable();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep this test that makes sure knot exists

if (!knot)
return false;

TR::SymbolReference *symRef = node->getSymbolReference();
if (symRef->isUnresolved())
return false;

if (!vp->comp()->getKnownObjectTable())
return false;

uintptr_t *objectReferenceLocation = NULL;
if (symRef->hasKnownObjectIndex())
Expand All @@ -1720,30 +1714,11 @@ static bool addKnownObjectConstraints(OMR::ValuePropagation *vp, TR::Node *node)
#ifdef J9_PROJECT_SPECIFIC
if (objectReferenceLocation)
{
bool isString;
bool isFixedJavaLangClass;
TR::KnownObjectTable::Index knownObjectIndex;
TR_OpaqueClassBlock *clazz, *jlClass;

{
TR::VMAccessCriticalSection getObjectReferenceLocation(vp->comp());
uintptr_t objectReference = vp->comp()->fej9()->getStaticReferenceFieldAtAddress((uintptr_t)objectReferenceLocation);
clazz = TR::Compiler->cls.objectClass(vp->comp(), objectReference);
isString = TR::Compiler->cls.isString(vp->comp(), clazz);
jlClass = vp->fe()->getClassClassPointer(clazz);
isFixedJavaLangClass = (jlClass == clazz);
if (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.
//
clazz = TR::Compiler->cls.classFromJavaLangClass(vp->comp(), objectReference);
}
knownObjectIndex = knot->getOrCreateIndex(objectReference);
}

TR_J9VMBase::ObjectClassInfo ci =
vp->comp()->fej9()->getObjectClassInfoFromObjectReferenceLocation(vp->comp(),
(uintptr_t)objectReferenceLocation);

if (isString && symRef->getSymbol()->isStatic())
if (ci.isString && symRef->getSymbol()->isStatic())
{
// There's a lot of machinery around optimizing const strings. Even
// though we lose object identity info this way, it's likely better to
Expand All @@ -1754,27 +1729,27 @@ static bool addKnownObjectConstraints(OMR::ValuePropagation *vp, TR::Node *node)
TR::VPNonNullObject::create(vp), NULL, NULL,
TR::VPObjectLocation::create(vp, TR::VPObjectLocation::HeapObject)));
}
else if (jlClass) // without a jlClass, we can't tell what kind of constraint to add
else if (ci.jlClass) // without a jlClass, we can't tell what kind of constraint to add
{
TR::VPConstraint *constraint = NULL;
const char *classSig = TR::Compiler->cls.classSignature(vp->comp(), clazz, vp->trMemory());
if (isFixedJavaLangClass)
const char *classSig = TR::Compiler->cls.classSignature(vp->comp(), ci.clazz, vp->trMemory());
if (ci.isFixedJavaLangClass)
{
if (performTransformation(vp->comp(), "%sAdd ClassObject constraint to %p based on known java/lang/Class %s =obj%d\n", OPT_DETAILS, node, classSig, knownObjectIndex))
if (performTransformation(vp->comp(), "%sAdd ClassObject constraint to %p based on known java/lang/Class %s =obj%d\n", OPT_DETAILS, node, classSig, ci.knownObjectIndex))
{
constraint = TR::VPClass::create(vp,
TR::VPKnownObject::createForJavaLangClass(vp, knownObjectIndex),
TR::VPKnownObject::createForJavaLangClass(vp, ci.knownObjectIndex),
TR::VPNonNullObject::create(vp), NULL, NULL,
TR::VPObjectLocation::create(vp, TR::VPObjectLocation::JavaLangClassObject));
vp->addGlobalConstraint(node, constraint);
}
}
else
{
if (performTransformation(vp->comp(), "%sAdd known-object constraint to %p based on known object obj%d of class %s\n", OPT_DETAILS, node, knownObjectIndex, classSig))
if (performTransformation(vp->comp(), "%sAdd known-object constraint to %p based on known object obj%d of class %s\n", OPT_DETAILS, node, ci.knownObjectIndex, classSig))
{
constraint = TR::VPClass::create(vp,
TR::VPKnownObject::create(vp, knownObjectIndex),
TR::VPKnownObject::create(vp, ci.knownObjectIndex),
TR::VPNonNullObject::create(vp), NULL, NULL,
TR::VPObjectLocation::create(vp, TR::VPObjectLocation::HeapObject));
vp->addBlockConstraint(node, constraint);
Expand Down