Skip to content

Commit

Permalink
Enable PortLib init/shutdown in JitBuiler and compiler tests
Browse files Browse the repository at this point in the history
This change ensures that Port library is initialized and shutdown
when JitBuilder and testcompiler are initialized and shutdown.
This paves the way for using port library features within OMR
Compiler code and replace duplicated functionality through use
of the port library API.

Signed-off-by: Nazim Bhuiyan <nubhuiyan@ibm.com>
  • Loading branch information
nbhuiyan committed Aug 11, 2022
1 parent 497c5e3 commit 4f85a16
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 8 deletions.
6 changes: 3 additions & 3 deletions compiler/env/CompilerEnv.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corp. and others
* Copyright (c) 2000, 2022 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 @@ -32,8 +32,8 @@ namespace TR
class OMR_EXTENSIBLE CompilerEnv : public OMR::CompilerEnvConnector
{
public:
CompilerEnv(TR::RawAllocator raw, const TR::PersistentAllocatorKit &persistentAllocatorKit) :
OMR::CompilerEnvConnector(raw, persistentAllocatorKit)
CompilerEnv(TR::RawAllocator raw, const TR::PersistentAllocatorKit &persistentAllocatorKit, OMRPortLibrary* const omrPortLib=NULL) :
OMR::CompilerEnvConnector(raw, persistentAllocatorKit, omrPortLib)
{}
};

Expand Down
25 changes: 23 additions & 2 deletions fvtest/compilertest/control/TestJit.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2020 IBM Corp. and others
* Copyright (c) 2000, 2022 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 @@ -38,6 +38,8 @@
extern TR_RuntimeHelperTable runtimeHelpers;
extern void setupCodeCacheParameters(int32_t *, OMR::CodeCacheCodeGenCallbacks *callBacks, int32_t *numHelpers, int32_t *CCPreLoadedCodeSize);

static OMRPortLibrary portLibrary;

static void
initHelper(void *helper, TR_RuntimeHelper id)
{
Expand Down Expand Up @@ -150,11 +152,19 @@ initializeTestJit(TR_RuntimeHelper *helperIDs, void **helperAddresses, int32_t n
//
TR::RawAllocator rawAllocator;

// initialize and attach current thread to thread library, and then initialize port library
if (0 == omrthread_init_library())
{
omrthread_t currentThread = NULL;
if (0 == omrthread_attach_ex(&currentThread, J9THREAD_ATTR_DEFAULT))
omrport_init_library(&portLibrary, sizeof(OMRPortLibrary));
}

try
{
// Allocate the host environment structure
//
TR::Compiler = new (rawAllocator) TR::CompilerEnv(rawAllocator, TR::PersistentAllocatorKit(rawAllocator));
TR::Compiler = new (rawAllocator) TR::CompilerEnv(rawAllocator, TR::PersistentAllocatorKit(rawAllocator), &portLibrary);
}
catch (const std::bad_alloc&)
{
Expand All @@ -174,6 +184,9 @@ initializeTestJit(TR_RuntimeHelper *helperIDs, void **helperAddresses, int32_t n

initializeCodeCache(fe.codeCacheManager());

if (TR::Compiler->omrPortLib == NULL)
return false;

return true;
}

Expand Down Expand Up @@ -201,6 +214,14 @@ shutdownJit()
codeCacheManager.destroy();

TR::CompilationController::shutdown();

omrthread_t currentThread = NULL;
if (0 == omrthread_attach_ex(&currentThread, J9THREAD_ATTR_DEFAULT))
{
portLibrary.port_shutdown_library(&portLibrary);
omrthread_detach(currentThread);
omrthread_shutdown_library();
}
}

extern "C"
Expand Down
3 changes: 2 additions & 1 deletion fvtest/tril/tril/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2017, 2021 IBM Corp. and others
# Copyright (c) 2017, 2022 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 @@ -52,6 +52,7 @@ target_include_directories(tril PUBLIC
target_link_libraries(tril PUBLIC
${TRIL_BACKEND_LIB}
${CMAKE_DL_LIBS}
${OMR_PORT_LIB}
)

# TODO system thread library should be linked in a more generic way.
Expand Down
26 changes: 24 additions & 2 deletions jitbuilder/control/Jit.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2014, 2020 IBM Corp. and others
* Copyright (c) 2014, 2022 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 @@ -109,6 +109,8 @@ initializeCodeCache(TR::CodeCacheManager & codeCacheManager)
TR::CodeCache *firstCodeCache = codeCacheManager.initialize(true, 1);
}

static OMRPortLibrary portLibrary;

// helperIDs is an array of helper id corresponding to the addresses passed in "helpers"
// helpers is an array of pointers to helpers that compiled code needs to reference
// currently this argument isn't needed by anything so this function can stay internal
Expand All @@ -121,11 +123,19 @@ initializeJitBuilder(TR_RuntimeHelper *helperIDs, void **helperAddresses, int32_
//
TR::RawAllocator rawAllocator;

// initialize and attach current thread to thread library, and then initialize port library
if (0 == omrthread_init_library())
{
omrthread_t currentThread = NULL;
if (0 == omrthread_attach_ex(&currentThread, J9THREAD_ATTR_DEFAULT))
omrport_init_library(&portLibrary, sizeof(OMRPortLibrary));
}

try
{
// Allocate the host environment structure
//
TR::Compiler = new (rawAllocator) TR::CompilerEnv(rawAllocator, TR::PersistentAllocatorKit(rawAllocator));
TR::Compiler = new (rawAllocator) TR::CompilerEnv(rawAllocator, TR::PersistentAllocatorKit(rawAllocator), &portLibrary);
}
catch (const std::bad_alloc&)
{
Expand All @@ -145,6 +155,9 @@ initializeJitBuilder(TR_RuntimeHelper *helperIDs, void **helperAddresses, int32_

initializeCodeCache(fe.codeCacheManager());

if (TR::Compiler->omrPortLib == NULL)
return false;

return true;
}

Expand Down Expand Up @@ -219,4 +232,13 @@ internal_shutdownJit()
codeCacheManager.destroy();

TR::CompilationController::shutdown();

omrthread_t currentThread = NULL;
if (0 == omrthread_attach_ex(&currentThread, J9THREAD_ATTR_DEFAULT))
{
portLibrary.port_shutdown_library(&portLibrary);
omrthread_detach(currentThread);
omrthread_shutdown_library();
}

}

0 comments on commit 4f85a16

Please sign in to comment.