Skip to content

Commit

Permalink
Add frontend method getVFTEntry
Browse files Browse the repository at this point in the history
The optimizer should ideally not fetch class fields directly.
Factor it out into a ClassEnv method instead.

Signed-off-by: Noah Weninger <Noah.Weninger@ibm.com>
  • Loading branch information
Omer Sheikh authored and Noah Weninger committed Jun 15, 2018
1 parent dc6e3a1 commit d36ad53
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
8 changes: 7 additions & 1 deletion compiler/env/OMRClassEnv.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2016 IBM Corp. and others
* Copyright (c) 2000, 2018 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -42,3 +42,9 @@ OMR::ClassEnv::getArrayElementWidthInBytes(TR::Compilation *comp, TR_OpaqueClass
notImplemented("getArrayElementWidthInBytes");
return 0;
}

intptrj_t
OMR::ClassEnv::getVFTEntry(TR::Compilation *comp, TR_OpaqueClassBlock* clazz, int32_t offset)
{
return *(intptrj_t*) (((uint8_t *)clazz) + offset);
}
11 changes: 10 additions & 1 deletion compiler/env/OMRClassEnv.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2016 IBM Corp. and others
* Copyright (c) 2000, 2018 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -111,6 +111,15 @@ class OMR_EXTENSIBLE ClassEnv
char *classSignature_DEPRECATED(TR::Compilation *comp, TR_OpaqueClassBlock * clazz, int32_t & length, TR_Memory *) { return NULL; }
char *classSignature(TR::Compilation *comp, TR_OpaqueClassBlock * clazz, TR_Memory *) { return NULL; }

/**
* Get the virtual function table entry at a specific offset from the class
*
* @param clazz The RAM class pointer to read from
* @param offset An offset into the virtual function table (VFT) of clazz
* @return The entry point of the method at the given offset
*/
intptrj_t getVFTEntry(TR::Compilation *comp, TR_OpaqueClassBlock* clazz, int32_t offset);

};

}
Expand Down
4 changes: 2 additions & 2 deletions compiler/optimizer/VPHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9678,9 +9678,9 @@ static TR::Node *constrainIfcmpeqne(OMR::ValuePropagation *vp, TR::Node *node, b
TR::VPConstraint *classConstraint = vp->getConstraint(classNode, isGlobal);
if (ignoreVirtualGuard && classConstraint && classConstraint->isFixedClass())
{
uint8_t *clazz = (uint8_t*)classConstraint->getClass();
TR_OpaqueClassBlock *clazz = classConstraint->getClass();
int32_t vftOffset = vtableEntryNode->getSymbolReference()->getOffset();
intptrj_t vftEntry = *(intptrj_t*)(clazz + vftOffset);
intptrj_t vftEntry = TR::Compiler->cls.getVFTEntry(vp->comp(), clazz, vftOffset);
bool childrenAreEqual = (vftEntry == methodPtrNode->getAddress());
bool testForEquality = (node->getOpCodeValue() == TR::ifacmpeq);
traceMsg(vp->comp(), "TR_MethodTest: node=%p, vtableEntryNode=%p, clazz=%p, vftOffset=%d, vftEntry=%p, childrenAreEqual=%d, testForEquality=%d\n",
Expand Down

0 comments on commit d36ad53

Please sign in to comment.