Skip to content

Commit

Permalink
Use method symbol address to get the entry point in Tril and JitBuilder
Browse files Browse the repository at this point in the history
Some platforms, such as AIX and z/OS, use metadata structures to
represent "pointer to a function" retrieved via the C `&` operator. On
AIX and z/OS these are called Function Descriptors. We need to
disambiguate between the "pointer to a function" and "address of entry
point of a function".

Currently `getCodeStart` API returns the latter, however this is not
what we want when we query for the result of a compilation in Tril and
JitBuilder. We want the former, i.e. the value of the "pointer to a
function" of the JIT compiled method.

We use the method symbol `getAddress` API here to query for such
values, and ensuring this value is set properly after binary encoding.
It is currently set to the result of `getCodeStart` by default, so no
change in value. If platforms have Function Descriptors it is up to
those linkages to update this value once the location of the Function
Descriptor is known.

Signed-off-by: Filip Jeremic <fjeremic@ca.ibm.com>

Signed-off-by: Filip Jeremic <fjeremic@ca.ibm.com>
  • Loading branch information
fjeremic committed Mar 6, 2020
1 parent c92891e commit 6e902d5
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 32 deletions.
8 changes: 3 additions & 5 deletions compiler/codegen/OMRCodeGenPhase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,6 @@ OMR::CodeGenPhase::performProcessRelocationsPhase(TR::CodeGenerator * cg, TR::Co
diagnostic("%08d %s\n", cg->getCodeLength(), comp->signature());
}

if (comp->getCurrentMethod() == NULL)
{
comp->getMethodSymbol()->setMethodAddress(cg->getBinaryBufferStart());
}

TR_ASSERT(cg->getCodeLength() <= cg->getEstimatedCodeLength(),
"Method length estimate must be conservatively large\n"
" codeLength = %d, estimatedCodeLength = %d \n",
Expand Down Expand Up @@ -304,6 +299,9 @@ OMR::CodeGenPhase::performBinaryEncodingPhase(TR::CodeGenerator * cg, TR::CodeGe

cg->doBinaryEncoding();

// Instructions have been emitted, and now we know what the entry point is, so update the compilation method symbol
comp->getMethodSymbol()->setMethodAddress(cg->getCodeStart());

if (debug("verifyFinalNodeReferenceCounts"))
{
if (cg->getDebug())
Expand Down
2 changes: 1 addition & 1 deletion compiler/control/CompileMethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ compileMethodFromDetails(
// not ready yet...
//OMR::MethodMetaDataPOD *metaData = fe.createMethodMetaData(&compiler);

startPC = compiler.cg()->getCodeStart();
startPC = (uint8_t*)compiler.getMethodSymbol()->getMethodAddress();
uint64_t translationTime = TR::Compiler->vm.getUSecClock() - translationStartTime;

if (TR::Options::isAnyVerboseOptionSet(TR_VerboseCompileEnd, TR_VerbosePerformance))
Expand Down
3 changes: 3 additions & 0 deletions compiler/z/codegen/SystemLinkagezOS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,9 @@ TR::S390zOSSystemLinkage::XPLINKFunctionDescriptorSnippet::emitSnippetBody()
// TODO: We should not have to do this here. This should be done by the caller.
getSnippetLabel()->setCodeLocation(cursor);

// Update the method symbol address to point to the function descriptor
cg()->comp()->getMethodSymbol()->setMethodAddress(cursor);

if (cg()->comp()->target().is32Bit())
{
// Address of function's environment
Expand Down
14 changes: 1 addition & 13 deletions fvtest/tril/tril/simple_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,7 @@ int32_t Tril::SimpleCompiler::compileWithVerifier(TR::IlVerifier* verifier) {
// if compilation was successful, set the entry point for the compiled body
if (rc == 0)
{
#if defined(J9ZOS390)
struct FunctionDescriptor
{
uint64_t environment;
void* func;
};

FunctionDescriptor* fd = new FunctionDescriptor();
fd->environment = 0;
fd->func = entry_point;

entry_point = (uint8_t*) fd;
#elif defined(AIXPPC)
#if defined(AIXPPC)
struct FunctionDescriptor
{
void* func;
Expand Down
14 changes: 1 addition & 13 deletions jitbuilder/control/Jit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,7 @@ internal_compileMethodBuilder(TR::MethodBuilder *m, void **entry)
{
auto rc = m->Compile(entry);

#if defined(J9ZOS390)
struct FunctionDescriptor
{
uint64_t environment;
void* func;
};

FunctionDescriptor* fd = new FunctionDescriptor();
fd->environment = 0;
fd->func = *entry;

*entry = (void*) fd;
#elif defined(AIXPPC)
#if defined(AIXPPC)
struct FunctionDescriptor
{
void* func;
Expand Down

0 comments on commit 6e902d5

Please sign in to comment.