From 6e902d5cbc1d30cfa666647c4e173ea881248056 Mon Sep 17 00:00:00 2001 From: Filip Jeremic Date: Fri, 6 Mar 2020 16:14:19 -0500 Subject: [PATCH] Use method symbol address to get the entry point in Tril and JitBuilder 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 Signed-off-by: Filip Jeremic --- compiler/codegen/OMRCodeGenPhase.cpp | 8 +++----- compiler/control/CompileMethod.cpp | 2 +- compiler/z/codegen/SystemLinkagezOS.cpp | 3 +++ fvtest/tril/tril/simple_compiler.cpp | 14 +------------- jitbuilder/control/Jit.cpp | 14 +------------- 5 files changed, 9 insertions(+), 32 deletions(-) diff --git a/compiler/codegen/OMRCodeGenPhase.cpp b/compiler/codegen/OMRCodeGenPhase.cpp index 4b410b665a5..9e70cc81a93 100644 --- a/compiler/codegen/OMRCodeGenPhase.cpp +++ b/compiler/codegen/OMRCodeGenPhase.cpp @@ -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", @@ -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()) diff --git a/compiler/control/CompileMethod.cpp b/compiler/control/CompileMethod.cpp index e9d54858412..1101d9d679c 100644 --- a/compiler/control/CompileMethod.cpp +++ b/compiler/control/CompileMethod.cpp @@ -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)) diff --git a/compiler/z/codegen/SystemLinkagezOS.cpp b/compiler/z/codegen/SystemLinkagezOS.cpp index 271a2fe1534..78b4d5f722a 100644 --- a/compiler/z/codegen/SystemLinkagezOS.cpp +++ b/compiler/z/codegen/SystemLinkagezOS.cpp @@ -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 diff --git a/fvtest/tril/tril/simple_compiler.cpp b/fvtest/tril/tril/simple_compiler.cpp index da1cb7370eb..2f19e3cfeb8 100644 --- a/fvtest/tril/tril/simple_compiler.cpp +++ b/fvtest/tril/tril/simple_compiler.cpp @@ -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; diff --git a/jitbuilder/control/Jit.cpp b/jitbuilder/control/Jit.cpp index 08067fb41d0..ccbe49d6045 100644 --- a/jitbuilder/control/Jit.cpp +++ b/jitbuilder/control/Jit.cpp @@ -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;