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

Provide JITServer implementation for CRIU specific FE queries (0.38.0) #17151

Merged
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
28 changes: 21 additions & 7 deletions runtime/compiler/control/JITClientCompilationThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
*******************************************************************************/

#include "j9cfg.h"
#include "jitprotos.h"
#include "vmaccess.h"
#include "codegen/CodeGenerator.hpp"
#include "codegen/PicHelpers.hpp"
#include "control/CompilationRuntime.hpp"
Expand All @@ -30,24 +33,22 @@
#include "env/J2IThunk.hpp"
#include "env/j9methodServer.hpp"
#include "env/JITServerPersistentCHTable.hpp"
#include "env/JSR292Methods.h"
#include "env/TypeLayout.hpp"
#include "env/ut_j9jit.h"
#include "env/VerboseLog.hpp"
#include "env/VMAccessCriticalSection.hpp"
#include "env/VMJ9.h"
#include "env/VerboseLog.hpp"
#include "net/ClientStream.hpp"
#include "optimizer/TransformUtil.hpp"
#include "runtime/CodeCacheExceptions.hpp"
#include "runtime/CodeCache.hpp"
#include "runtime/CodeCacheExceptions.hpp"
#include "runtime/CodeCacheManager.hpp"
#include "runtime/J9VMAccess.hpp"
#include "runtime/JITClientSession.hpp"
#include "runtime/JITServerAOTDeserializer.hpp"
#include "runtime/JITServerIProfiler.hpp"
#include "runtime/RelocationTarget.hpp"
#include "env/TypeLayout.hpp"
#include "env/JSR292Methods.h"
#include "jitprotos.h"
#include "vmaccess.h"


extern TR::Monitor *assumptionTableMutex;
Expand Down Expand Up @@ -519,7 +520,13 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
TR_ASSERT_FATAL(header, "Must have valid AOT header stored in SCC by now");
vmInfo._aotHeader = *header;
}

vmInfo._inSnapshotMode = fe->inSnapshotMode();
vmInfo._isSnapshotModeEnabled = fe->isSnapshotModeEnabled();
#if defined(J9VM_OPT_CRIU_SUPPORT)
vmInfo._isNonPortableRestoreMode = javaVM->internalVMFunctions->isNonPortableRestoreMode(vmThread);
#else
vmInfo._isNonPortableRestoreMode = false;
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
client->write(response, vmInfo, listOfCacheDescriptors, comp->getPersistentInfo()->getJITServerAOTCacheName());
}
break;
Expand Down Expand Up @@ -1205,6 +1212,13 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
client->write(response, isStable);
}
break;
case MessageType::VM_inSnapshotMode:
{
client->getRecvData<JITServer::Void>();
client->write(response, fe->inSnapshotMode());
}
break;

case MessageType::mirrorResolvedJ9Method:
{
// allocate a new TR_ResolvedJ9Method on the heap, to be used as a mirror for performing actions which are only
Expand Down
4 changes: 2 additions & 2 deletions runtime/compiler/env/VMJ9.h
Original file line number Diff line number Diff line change
Expand Up @@ -1351,15 +1351,15 @@ class TR_J9VMBase : public TR_FrontEnd
* \return True if snapshots can be taken, false if no snapshots that will include this
* body are allowed.
*/
bool inSnapshotMode();
virtual bool inSnapshotMode();

/**
* \brief Answers whether checkpoint and restore mode is enabled (but not necessarily
* whether snapshots can be taken or if any restores have already occurred).
*
* \return True if checkpoint and restore mode is enabled, false otherwise.
*/
bool isSnapshotModeEnabled();
virtual bool isSnapshotModeEnabled();

protected:

Expand Down
41 changes: 41 additions & 0 deletions runtime/compiler/env/VMJ9Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2434,6 +2434,47 @@ TR_J9ServerVM::isPortableSCCEnabled()
return J9_ARE_ANY_BITS_SET(vmInfo->_extendedRuntimeFlags2, J9_EXTENDED_RUNTIME2_ENABLE_PORTABLE_SHARED_CACHE);
}

bool
TR_J9ServerVM::inSnapshotMode()
{
JITServer::ServerStream *stream = _compInfoPT->getMethodBeingCompiled()->_stream;
auto *vmInfo = _compInfoPT->getClientData()->getOrCacheVMInfo(stream);
if (vmInfo->_isSnapshotModeEnabled)
{
if (vmInfo->_isNonPortableRestoreMode)
{
// The VM starts in snapshot mode, but after a restore it will exit snapshot mode
if (vmInfo->_inSnapshotMode)
{
// Must ask confirmation from client that it is still running in snapshot mode
stream->write(JITServer::MessageType::VM_inSnapshotMode, JITServer::Void());
vmInfo->_inSnapshotMode = std::get<0>(stream->read<bool>()); // cache the response
return vmInfo->_inSnapshotMode;
}
else // Once false, it will never be true again
{
return false;
}
}
else // If we are NOT in portable CRIU mode, then we are always in snapshot mode
{
return true;
}
}
else // If CRIU is disabled we cannot be in snapshot mode
{
return false;
}
}

bool
TR_J9ServerVM::isSnapshotModeEnabled()
{
JITServer::ServerStream *stream = _compInfoPT->getMethodBeingCompiled()->_stream;
auto *vmInfo = _compInfoPT->getClientData()->getOrCacheVMInfo(stream);
return vmInfo->_isSnapshotModeEnabled;
}

bool
TR_J9SharedCacheServerVM::isClassLibraryMethod(TR_OpaqueMethodBlock *method, bool vettedForAOT)
{
Expand Down
2 changes: 2 additions & 0 deletions runtime/compiler/env/VMJ9Server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ class TR_J9ServerVM: public TR_J9VM
#endif
virtual TR::KnownObjectTable::Index getMemberNameFieldKnotIndexFromMethodHandleKnotIndex(TR::Compilation *comp, TR::KnownObjectTable::Index mhIndex, char *fieldName) override;
virtual bool isMethodHandleExpectedType(TR::Compilation *comp, TR::KnownObjectTable::Index mhIndex, TR::KnownObjectTable::Index expectedTypeIndex) override;
virtual bool inSnapshotMode() override;
virtual bool isSnapshotModeEnabled() override;

private:
bool instanceOfOrCheckCastHelper(J9Class *instanceClass, J9Class* castClass, bool cacheUpdate);
Expand Down
2 changes: 1 addition & 1 deletion runtime/compiler/net/CommunicationStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class CommunicationStream
ClientMessage _cMsg;

static const uint8_t MAJOR_NUMBER = 1;
static const uint16_t MINOR_NUMBER = 42;
static const uint16_t MINOR_NUMBER = 43;
static const uint8_t PATCH_NUMBER = 0;
static uint32_t CONFIGURATION_FLAGS;

Expand Down
1 change: 1 addition & 0 deletions runtime/compiler/net/MessageTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ const char *messageNames[] =
"VM_delegatingMethodHandleTarget",
"VM_getVMTargetOffset",
"VM_getVMIndexOffset",
"VM_inSnapshotMode",
"CompInfo_isCompiled",
"CompInfo_getPCIfCompiled",
"CompInfo_getInvocationCount",
Expand Down
1 change: 1 addition & 0 deletions runtime/compiler/net/MessageTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ enum MessageType : uint16_t
VM_delegatingMethodHandleTarget,
VM_getVMTargetOffset,
VM_getVMIndexOffset,
VM_inSnapshotMode,

// For static TR::CompilationInfo methods
CompInfo_isCompiled,
Expand Down
6 changes: 6 additions & 0 deletions runtime/compiler/runtime/JITClientSession.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,12 @@ class ClientSessionData
TR_AOTHeader _aotHeader;
TR_OpaqueClassBlock *_JavaLangObject;
TR_OpaqueClassBlock *_JavaStringObject;
// The following three fields refer to CRIU support
// Do not protect them with #if defined(J9VM_OPT_CRIU_SUPPORT) because we want JITServer to be
// able to handle all clients whether or not they have CRIU support enabled
bool _inSnapshotMode;
bool _isSnapshotModeEnabled;
bool _isNonPortableRestoreMode;
}; // struct VMInfo

/**
Expand Down