Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add launcher for JITServer (0.18.0) #8249

Merged
merged 1 commit into from Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion buildspecs/core.feature
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2006, 2018 IBM Corp. and others
Copyright (c) 2006, 2020 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 @@ -44,6 +44,7 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-excepti
<project id="runtime"/>
</source>
<flags>
<flag id="build_jitserver" value="false"/>
<flag id="build_stage_ottawa_vmlab" value="true"/>
<flag id="build_uma" value="true"/>
<flag id="compiler_promotion" value="true"/>
Expand Down
6 changes: 5 additions & 1 deletion buildspecs/j9.flags
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2006, 2019 IBM Corp. and others
Copyright (c) 2006, 2020 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 @@ -186,6 +186,10 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-excepti
<description>BuildSpec represents a Java 9x configuration.</description>
<ifRemoved></ifRemoved>
</flag>
<flag id="build_jitserver">
<description>JITServer support is enabled in the buildspec.</description>
<ifRemoved></ifRemoved>
</flag>
<flag id="build_openj9">
<description>Buildspec compiles sources with openjdk.</description>
<ifRemoved>Openj9 clone,make jobs longer run on this buildspec.</ifRemoved>
Expand Down
9 changes: 8 additions & 1 deletion runtime/CMakeLists.txt
@@ -1,5 +1,5 @@
################################################################################
# Copyright (c) 2017, 2019 IBM Corp. and others
# Copyright (c) 2017, 2020 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 @@ -105,6 +105,9 @@ include(cmake/omr_config.cmake)
if(OPENJ9_BUILD)
add_definitions(-DOPENJ9_BUILD)
endif()
if (JITSERVER_SUPPORT)
add_definitions(-DJITSERVER_SUPPORT)
endif()

# clean up the variables we used
set(versionStr)
Expand Down Expand Up @@ -591,3 +594,7 @@ endif()

# NOTE this is not conditional in the UMA module.xml
add_subdirectory(tests)

if (JITSERVER_SUPPORT)
add_subdirectory(jitserver_launcher)
endif()
93 changes: 46 additions & 47 deletions runtime/compiler/control/HookedByTheJit.cpp
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corp. and others
* Copyright (c) 2000, 2020 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 @@ -636,19 +636,6 @@ static void jitHookInitializeSendTarget(J9HookInterface * * hook, UDATA eventNum
}
}

#if defined(JITSERVER_SUPPORT)
static void jitHookVMInitialized(J9HookInterface * * hook, UDATA eventNum, void * eventData, void * userData)
{
J9VMThread* vmThread = ((J9VMInitEvent *)eventData)->vmThread;
TR::CompilationInfo *compInfo = getCompilationInfo(vmThread->javaVM->jitConfig);
if (compInfo->getPersistentInfo()->getRemoteCompilationMode() == JITServer::SERVER)
{
fprintf(stderr, "\nJITServer ready to accept incoming requests\n");
j9thread_sleep(10000000000);
}
}
#endif

#if defined(J9VM_INTERP_PROFILING_BYTECODES)

static int32_t interpreterProfilingState = IPROFILING_STATE_OFF;
Expand Down Expand Up @@ -7145,39 +7132,6 @@ int32_t setUpHooks(J9JavaVM * javaVM, J9JITConfig * jitConfig, TR_FrontEnd * vm)
}
}

#if defined(JITSERVER_SUPPORT)
if (compInfo->getPersistentInfo()->getRemoteCompilationMode() == JITServer::SERVER)
{
TR_Listener *listener = ((TR_JitPrivateConfig*)(jitConfig->privateConfig))->listener;
listener->startListenerThread(javaVM);

if (TR::Options::getVerboseOption(TR_VerboseJITServer))
TR_VerboseLog::writeLineLocked(TR_Vlog_JITServer, "Started JITServer listener thread: %p ", listener->getListenerThread());

if (jitConfig->samplingFrequency != 0)
{
JITServerStatisticsThread *statsThreadObj = ((TR_JitPrivateConfig*)(jitConfig->privateConfig))->statisticsThreadObject;
// statsThreadObj is guaranteed to be non-null because JITServer will not start if statisticsThreadObject cannot be created
statsThreadObj->startStatisticsThread(javaVM);
// Verify that statistics thread was started
if (!statsThreadObj->getStatisticsThread())
{
j9tty_printf(PORTLIB, "Error: Unable to start the statistics thread\n");
return -1;
// If we decide to start even without a statistics thread, we must
// free `statsThreadObj` and set the corresponding jitConfig field to NULL
}
}

// Give the JIT a chance to do stuff after the VM is initialized
if ((*vmHooks)->J9HookRegisterWithCallSite(vmHooks, J9HOOK_VM_INITIALIZED, jitHookVMInitialized, OMR_GET_CALLSITE(), NULL))
{
j9tty_printf(PORTLIB, "Error: Unable to install J9HOOK_VM_INITIALIZED\n");
return -1;
}
}
#endif // JITSERVER_SUPPORT

if ((*gcOmrHooks)->J9HookRegisterWithCallSite(gcOmrHooks, J9HOOK_MM_OMR_LOCAL_GC_START, jitHookLocalGCStart, OMR_GET_CALLSITE(), NULL) ||
(*gcOmrHooks)->J9HookRegisterWithCallSite(gcOmrHooks, J9HOOK_MM_OMR_LOCAL_GC_END, jitHookLocalGCEnd, OMR_GET_CALLSITE(), NULL) ||
(*gcOmrHooks)->J9HookRegisterWithCallSite(gcOmrHooks, J9HOOK_MM_OMR_GLOBAL_GC_START, jitHookGlobalGCStart, OMR_GET_CALLSITE(), NULL) ||
Expand Down Expand Up @@ -7294,5 +7248,50 @@ int32_t setUpHooks(J9JavaVM * javaVM, J9JITConfig * jitConfig, TR_FrontEnd * vm)
return 0;
}

#if defined(JITSERVER_SUPPORT)
int32_t startJITServer(J9JITConfig *jitConfig)
{
J9JavaVM *javaVM = jitConfig->javaVM;
TR_Listener *listener = ((TR_JitPrivateConfig*)(jitConfig->privateConfig))->listener;
TR::CompilationInfo * compInfo = TR::CompilationInfo::get(jitConfig);
PORT_ACCESS_FROM_JAVAVM(javaVM);

TR_ASSERT(compInfo->getPersistentInfo()->getRemoteCompilationMode() == JITServer::SERVER, "startJITServer cannot be called in non-server mode\n");

listener->startListenerThread(javaVM);

if (TR::Options::getVerboseOption(TR_VerboseJITServer))
TR_VerboseLog::writeLineLocked(TR_Vlog_JITServer, "Started JITServer listener thread: %p ", listener->getListenerThread());

if (jitConfig->samplingFrequency != 0)
{
JITServerStatisticsThread *statsThreadObj = ((TR_JitPrivateConfig*)(jitConfig->privateConfig))->statisticsThreadObject;
// statsThreadObj is guaranteed to be non-null because JITServer will not start if statisticsThreadObject cannot be created
statsThreadObj->startStatisticsThread(javaVM);
// Verify that statistics thread was started
if (!statsThreadObj->getStatisticsThread())
{
j9tty_printf(PORTLIB, "Error: Unable to start the statistics thread\n");
return -1;
// If we decide to start even without a statistics thread, we must
// free `statsThreadObj` and set the corresponding jitConfig field to NULL
}
}
return 0;
}

int32_t waitJITServerTermination(J9JITConfig *jitConfig)
{
J9JavaVM *javaVM = jitConfig->javaVM;
TR_Listener *listener = ((TR_JitPrivateConfig*)(jitConfig->privateConfig))->listener;
TR::CompilationInfo * compInfo = TR::CompilationInfo::get(jitConfig);
int32_t rc = 0;

TR_ASSERT(compInfo->getPersistentInfo()->getRemoteCompilationMode() == JITServer::SERVER, "waitJITServerTermination cannot be called in non-server mode\n");

rc = listener->waitForListenerThreadExit(javaVM);
return rc;
}
#endif /* JITSERVER_SUPPORT */

} /* extern "C" */
53 changes: 23 additions & 30 deletions runtime/compiler/control/J9Options.cpp
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corp. and others
* Copyright (c) 2000, 2020 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 @@ -1942,27 +1942,31 @@ J9::Options::fePreProcess(void * base)
self()->setOption(TR_DisableAOTBytesCompression);

#if defined(JITSERVER_SUPPORT)
// Check option -XX:+UseJITServer and/or -XX:StartAsJITServer
// -XX:-UseJITServer disables JITServer at the client
static bool JITServerAlreadyParsed = false;
if (!JITServerAlreadyParsed) // Avoid processing twice for AOT and JIT and produce duplicate messages
{
JITServerAlreadyParsed = true;
if (vm->internalVMFunctions->isJITServerEnabled(vm))
{
compInfo->getPersistentInfo()->setRemoteCompilationMode(JITServer::SERVER);
// Increase the default timeout value for JITServer.
// It can be overridden with -XX:JITServerTimeout= option in JITServerParseCommonOptions().
compInfo->getPersistentInfo()->setSocketTimeout(30000);
}
else
{
// Check option -XX:+UseJITServer
// -XX:-UseJITServer disables JITServer at the client
const char *xxUseJITServerOption = "-XX:+UseJITServer";
const char *xxDisableUseJITServerOption = "-XX:-UseJITServer";

const char *xxUseJITServerOption = "-XX:+UseJITServer";
const char *xxDisableUseJITServerOption = "-XX:-UseJITServer";
const char *xxStartAsJITServerOption = "-XX:StartAsJITServer";

int32_t xxUseJITServerArgIndex = FIND_ARG_IN_VMARGS(STARTSWITH_MATCH, xxUseJITServerOption, 0);
int32_t xxDisableUseJITServerArgIndex = FIND_ARG_IN_VMARGS(STARTSWITH_MATCH, xxDisableUseJITServerOption, 0);
int32_t xxStartAsJITServerArgIndex = FIND_ARG_IN_VMARGS(STARTSWITH_MATCH, xxStartAsJITServerOption, 0);
int32_t xxUseJITServerArgIndex = FIND_ARG_IN_VMARGS(STARTSWITH_MATCH, xxUseJITServerOption, 0);
int32_t xxDisableUseJITServerArgIndex = FIND_ARG_IN_VMARGS(STARTSWITH_MATCH, xxDisableUseJITServerOption, 0);

// Check if option is at all specified
if ((xxUseJITServerArgIndex > xxDisableUseJITServerArgIndex) ||
(xxStartAsJITServerArgIndex >= 0))
{
if (xxUseJITServerArgIndex > xxStartAsJITServerArgIndex) // Client mode
// Check if option is at all specified
if (xxUseJITServerArgIndex > xxDisableUseJITServerArgIndex)
{
j9tty_printf(PORTLIB, "JITServer is currently a technology preview. Its use is not yet supported\n");
compInfo->getPersistentInfo()->setRemoteCompilationMode(JITServer::CLIENT);

const char *xxJITServerAddressOption = "-XX:JITServerAddress=";
Expand All @@ -1975,16 +1979,8 @@ J9::Options::fePreProcess(void * base)
compInfo->getPersistentInfo()->setJITServerAddress(address);
}
}
else // Server mode
{
compInfo->getPersistentInfo()->setRemoteCompilationMode(JITServer::SERVER);
// Increase the default timeout value for JITServer.
// It can be overridden with -XX:JITServerTimeout= option in JITServerParseCommonOptions().
compInfo->getPersistentInfo()->setSocketTimeout(30000);
}

JITServerParseCommonOptions(vm, compInfo);
}
JITServerParseCommonOptions(vm, compInfo);
if (compInfo->getPersistentInfo()->getRemoteCompilationMode() == JITServer::CLIENT)
{
// Generate a random identifier for this JITServer instance.
Expand All @@ -1994,14 +1990,11 @@ J9::Options::fePreProcess(void * base)
std::mt19937_64 rng(rd());
std::uniform_int_distribution<uint64_t> dist;
compInfo->getPersistentInfo()->setClientUID(dist(rng));
// _safeReservePhysicalMemoryValue is set as 0 for the JITClient because compilations
// are done remotely. The user can still override it with a command line option
J9::Options::_safeReservePhysicalMemoryValue = 0;
}
}
// _safeReservePhysicalMemoryValue is set as 0 for the JITClient because compilations
// are done remotely. The user can still override it with a command line option
if (compInfo->getPersistentInfo()->getRemoteCompilationMode() == JITServer::CLIENT)
{
J9::Options::_safeReservePhysicalMemoryValue = 0;
}
#endif /* defined(JITSERVER_SUPPORT) */

#if (defined(TR_HOST_X86) || defined(TR_HOST_S390) || defined(TR_HOST_POWER)) && defined(TR_TARGET_64BIT)
Expand Down
9 changes: 8 additions & 1 deletion runtime/compiler/control/rossa.cpp
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corp. and others
* Copyright (c) 2000, 2020 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 @@ -244,6 +244,8 @@ launchGPU(J9VMThread *vmThread, jobject invokeObject,
extern "C" void promoteGPUCompile(J9VMThread *vmThread);

extern "C" int32_t setUpHooks(J9JavaVM * javaVM, J9JITConfig * jitConfig, TR_FrontEnd * vm);
extern "C" int32_t startJITServer(J9JITConfig *jitConfig);
extern "C" int32_t waitJITServerTermination(J9JITConfig *jitConfig);

char *AOTcgDiagOn="1";

Expand Down Expand Up @@ -1132,6 +1134,11 @@ onLoadInternal(
TR_VerboseLog::initialize(jitConfig);
initializePersistentMemory(jitConfig);

// set up entry point for starting JITServer
#if defined(JITSERVER_SUPPORT)
jitConfig->startJITServer = startJITServer;
jitConfig->waitJITServerTermination = waitJITServerTermination;
#endif /* JITSERVER_SUPPORT */

TR_PersistentMemory * persistentMemory = (TR_PersistentMemory *)jitConfig->scratchSegment;
if (persistentMemory == NULL)
Expand Down
13 changes: 11 additions & 2 deletions runtime/compiler/runtime/Listener.cpp
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2019 IBM Corp. and others
* Copyright (c) 2018, 2020 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 @@ -92,7 +92,8 @@ void TR_Listener::startListenerThread(J9JavaVM *javaVM)
{
// create the thread for listening to a Client compilation request
const UDATA defaultOSStackSize = javaVM->defaultOSStackSize; //256KB stack size
if (javaVM->internalVMFunctions->createThreadWithCategory(&_listenerOSThread,

if (J9THREAD_SUCCESS != javaVM->internalVMFunctions->createJoinableThreadWithCategory(&_listenerOSThread,
defaultOSStackSize,
priority,
0,
Expand Down Expand Up @@ -121,3 +122,11 @@ void TR_Listener::startListenerThread(J9JavaVM *javaVM)
j9tty_printf(PORTLIB, "Error: Unable to create JITServer Listener Monitor\n");
}
}

int32_t TR_Listener::waitForListenerThreadExit(J9JavaVM *javaVM)
{
if (NULL != _listenerOSThread)
return omrthread_join(_listenerOSThread);
else
return 0;
}
3 changes: 2 additions & 1 deletion runtime/compiler/runtime/Listener.hpp
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2019 IBM Corp. and others
* Copyright (c) 2018, 2020 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 @@ -43,6 +43,7 @@ class TR_Listener
TR_Listener();
static TR_Listener* allocate();
void startListenerThread(J9JavaVM *javaVM);
int32_t waitForListenerThreadExit(J9JavaVM *javaVM);
void setAttachAttempted(bool b) { _listenerThreadAttachAttempted = b; }
bool getAttachAttempted() const { return _listenerThreadAttachAttempted; }

Expand Down
8 changes: 7 additions & 1 deletion runtime/include/j9cfg.h.ftl
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 1998, 2019 IBM Corp. and others
* Copyright (c) 1998, 2020 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 @@ -70,6 +70,12 @@ extern "C" {
#define J9VM_OPT_MULTI_LAYER_SHARED_CLASS_CACHE
#endif

#if defined(J9VM_BUILD_JITSERVER)
#ifndef JITSERVER_SUPPORT
#define JITSERVER_SUPPORT
#endif
#endif

#ifdef __cplusplus
}
#endif
Expand Down
8 changes: 7 additions & 1 deletion runtime/j9vm/exports.cmake
@@ -1,5 +1,5 @@
################################################################################
# Copyright (c) 2019, 2019 IBM Corp. and others
# Copyright (c) 2019, 2020 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 @@ -350,3 +350,9 @@ if(NOT JAVA_SPEC_VERSION LESS 14)
JVM_GetExtendedNPEMessage
)
endif()

if(JITSERVER_SUPPORT)
jvm_add_exports(jvm
JITServer_CreateServer
)
endif()
5 changes: 4 additions & 1 deletion runtime/j9vm/j9vmnatives.xml
@@ -1,5 +1,5 @@
<!--
Copyright (c) 2007, 2019 IBM Corp. and others
Copyright (c) 2007, 2020 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 All @@ -25,6 +25,9 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-excepti
<export name="JNI_CreateJavaVM" />
<export name="JNI_GetCreatedJavaVMs" />
<export name="JNI_GetDefaultJavaVMInitArgs" />
<export name="JITServer_CreateServer">
<include-if condition="spec.flags.build_jitserver"/>
</export>
</exports>

<exports group="j9vmnatives">
Expand Down