Skip to content

Commit

Permalink
Merge pull request #26 from jdmpapin/vp-instof-vft
Browse files Browse the repository at this point in the history
(v0.14.2) Constrain the VFT when the object node is unknown
  • Loading branch information
andrewcraik authored May 14, 2019
2 parents d6db6c0 + 0a6f817 commit b56045d
Showing 1 changed file with 35 additions and 18 deletions.
53 changes: 35 additions & 18 deletions compiler/optimizer/VPHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9087,7 +9087,8 @@ static TR::VPConstraint*
passingTypeTestObjectConstraint(
OMR::ValuePropagation *vp,
TR::VPConstraint *classConstraint,
bool testingForFixedType)
bool testingForFixedType,
bool constrainVft)
{
TR_ASSERT_FATAL(
classConstraint->isClassObject() == TR_yes,
Expand All @@ -9107,22 +9108,31 @@ passingTypeTestObjectConstraint(
type = TR::VPResolvedClass::create(vp, type->getClass());
}

// Use the signature to check whether type is java/lang/Class exactly. We
// can't rely on isJavaLangClassObject() because it returns TR_maybe in this
// case. (If it were to return TR_yes, it would mean the referent is a
// java/lang/Class representing java/lang/Class, i.e. Class.class, which
// would be incorrect in this case.)
TR::VPObjectLocation *loc = NULL;
int sigLen;
const char *sig = type->getClassSignature(sigLen);
if (sig != NULL && sigLen == 17 && !strncmp(sig, "Ljava/lang/Class;", sigLen))
{
// Just say that it's a java/lang/Class, with no information about the
// class that it represents.
type = NULL;
loc = TR::VPObjectLocation::create(
vp,
TR::VPObjectLocation::JavaLangClassObject);
if (constrainVft)
{
// The resulting constraint applies to the object's VFT pointer, not to
// the object itself.
loc = TR::VPObjectLocation::create(vp, TR::VPObjectLocation::J9ClassObject);
}
else
{
// Use the signature to check whether type is java/lang/Class exactly. We
// can't rely on isJavaLangClassObject() because it returns TR_maybe in this
// case. (If it were to return TR_yes, it would mean the referent is a
// java/lang/Class representing java/lang/Class, i.e. Class.class, which
// would be incorrect in this case.)
int sigLen;
const char *sig = type->getClassSignature(sigLen);
if (sig != NULL && sigLen == 17 && !strncmp(sig, "Ljava/lang/Class;", sigLen))
{
// Just say that it's a java/lang/Class, with no information about the
// class that it represents.
type = NULL;
loc = TR::VPObjectLocation::create(
vp,
TR::VPObjectLocation::JavaLangClassObject);
}
}

// Objects passing any kind of instanceof are non-null:
Expand Down Expand Up @@ -9590,6 +9600,7 @@ static TR::Node *constrainIfcmpeqne(OMR::ValuePropagation *vp, TR::Node *node, b
//
TR::VPConstraint *instanceofConstraint = NULL;
TR::Node *instanceofObjectRef = NULL;
bool instanceofObjectRefIsVft = false;
bool instanceofOnBranch = false;
bool instanceofDetectedAndFixedType = false;
bool isInstanceOf = false;
Expand Down Expand Up @@ -9632,6 +9643,7 @@ static TR::Node *constrainIfcmpeqne(OMR::ValuePropagation *vp, TR::Node *node, b
{
#ifdef J9_PROJECT_SPECIFIC
instanceofObjectRef = node->getFirstChild();
instanceofObjectRefIsVft = true;
TR::Node *classChild = node->getSecondChild();
bool foldedGuard = false;
static const char* enableJavaLangClassFolding = feGetEnv ("TR_EnableFoldJavaLangClass");
Expand Down Expand Up @@ -9659,7 +9671,10 @@ static TR::Node *constrainIfcmpeqne(OMR::ValuePropagation *vp, TR::Node *node, b

if (!foldedGuard && (instanceofObjectRef->getOpCodeValue() == TR::aloadi) &&
(instanceofObjectRef->getSymbolReference() == vp->comp()->getSymRefTab()->findVftSymbolRef()))
{
instanceofObjectRef = instanceofObjectRef->getFirstChild();
instanceofObjectRefIsVft = false;
}

TR::VPConstraint *classConstraint = vp->getConstraint(classChild, isGlobal);
//foldedGuard indicates that we already set cannotBranch or cannotFallThrough
Expand Down Expand Up @@ -9847,7 +9862,8 @@ static TR::Node *constrainIfcmpeqne(OMR::ValuePropagation *vp, TR::Node *node, b
TR::VPConstraint *newConstraint = passingTypeTestObjectConstraint(
vp,
instanceofConstraint,
instanceofDetectedAndFixedType);
instanceofDetectedAndFixedType,
instanceofObjectRefIsVft);

if (!isVirtualGuardNopable
&& !vp->addEdgeConstraint(instanceofObjectRef, newConstraint, edgeConstraints))
Expand Down Expand Up @@ -9965,7 +9981,8 @@ static TR::Node *constrainIfcmpeqne(OMR::ValuePropagation *vp, TR::Node *node, b
TR::VPConstraint *newConstraint = passingTypeTestObjectConstraint(
vp,
instanceofConstraint,
instanceofDetectedAndFixedType);
instanceofDetectedAndFixedType,
instanceofObjectRefIsVft);

if (!isVirtualGuardNopable
&& !vp->addBlockConstraint(instanceofObjectRef, newConstraint, NULL, false))
Expand Down

0 comments on commit b56045d

Please sign in to comment.