Skip to content

Commit

Permalink
Merge pull request #13934 from keithc-ca/criu
Browse files Browse the repository at this point in the history
Tidy up CRIU support
  • Loading branch information
tajila committed Nov 17, 2021
2 parents 2579502 + 43e287f commit 5bd7e26
Show file tree
Hide file tree
Showing 12 changed files with 242 additions and 181 deletions.
13 changes: 6 additions & 7 deletions runtime/compiler/control/HookedByTheJit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1824,7 +1824,7 @@ static void jitHookPrepareRestore(J9HookInterface * * hookInterface, UDATA event
jitConfig->targetProcessor = TR::Compiler->target.cpu.getProcessorDescription();
}
}
#endif
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */

#if defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING)
static void jitHookClassesUnload(J9HookInterface * * hookInterface, UDATA eventNum, void * eventData, void * userData)
Expand Down Expand Up @@ -2127,7 +2127,7 @@ static void jitHookClassUnload(J9HookInterface * * hookInterface, UDATA eventNum
compInfo->getUnloadedClassesTempList()->push_back(clazz);
// Loop through the set to find the class that needs to be purged.
// Once found erase from the set.
compInfo->getclassesCachedAtServer().erase(unloadedEvent->clazz);
compInfo->getclassesCachedAtServer().erase(unloadedEvent->clazz);
if (auto deserializer = compInfo->getJITServerAOTDeserializer())
deserializer->invalidateClass(vmThread, j9clazz);
}
Expand Down Expand Up @@ -5160,7 +5160,7 @@ static void DoCalculateOverallCompCPUUtilization(TR::CompilationInfo *compInfo,
const CpuSelfThreadUtilization& cpuUtil = arrayOfCompInfoPT[i]->getCompThreadCPU();
TR_VerboseLog::write(" compThr%d:%3d%% (%2d%%, %2d%%) ", i, cpuUtilizationValues[i], cpuUtil.getThreadLastCpuUtil(), cpuUtil.getThreadPrevCpuUtil());
if (TR::Options::getCmdLineOptions()->getVerboseOption(TR_VerboseCompilationThreadsDetails))
TR_VerboseLog::write("(%dms, %dms, lastCheckpoint=%u) ",
TR_VerboseLog::write("(%dms, %dms, lastCheckpoint=%u) ",
static_cast<int32_t>(cpuUtil.getLastMeasurementInterval()) / 1000000,
static_cast<int32_t>(cpuUtil.getSecondLastMeasurementInterval()) / 1000000,
cpuUtil.getLowResolutionClockAtLastUpdate());
Expand Down Expand Up @@ -5404,7 +5404,7 @@ static void iProfilerActivationLogic(J9JITConfig * jitConfig, TR::CompilationInf
TR_J9VMBase *fej9 = (TR_J9VMBase *)(TR_J9VMBase::get(jitConfig, 0));
TR_IProfiler *iProfiler = fej9->getIProfiler();
TR::PersistentInfo *persistentInfo = compInfo->getPersistentInfo();
if (iProfiler
if (iProfiler
&& iProfiler->getProfilerMemoryFootprint() < TR::Options::_iProfilerMemoryConsumptionLimit
#if defined(J9VM_OPT_JITSERVER)
&& compInfo->getPersistentInfo()->getRemoteCompilationMode() != JITServer::SERVER
Expand Down Expand Up @@ -6564,7 +6564,7 @@ int32_t setUpHooks(J9JavaVM * javaVM, J9JITConfig * jitConfig, TR_FrontEnd * vm)

jitConfig->samplerMonitor = NULL; // initialize this field just in case
compInfo->setSamplingThreadLifetimeState(TR::CompilationInfo::SAMPLE_THR_NOT_CREATED); // just in case
if (jitConfig->samplingFrequency
if (jitConfig->samplingFrequency
&& !vmj9->isAOT_DEPRECATED_DO_NOT_USE()
#if defined(J9VM_OPT_JITSERVER)
&& compInfo->getPersistentInfo()->getRemoteCompilationMode() != JITServer::SERVER
Expand All @@ -6579,7 +6579,6 @@ int32_t setUpHooks(J9JavaVM * javaVM, J9JITConfig * jitConfig, TR_FrontEnd * vm)

j9thread_monitor_init_with_name(&(jitConfig->samplerMonitor), 0, "JIT sampling thread");


if (jitConfig->samplerMonitor)
{
UDATA priority;
Expand Down Expand Up @@ -6807,7 +6806,7 @@ int32_t setUpHooks(J9JavaVM * javaVM, J9JITConfig * jitConfig, TR_FrontEnd * vm)
j9tty_printf(PORTLIB, "Error: Unable to register CRIU hook\n");
return -1;
}
#endif
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */

if (!vmj9->isAOT_DEPRECATED_DO_NOT_USE()
#if defined(J9VM_OPT_JITSERVER)
Expand Down
2 changes: 1 addition & 1 deletion runtime/compiler/control/J9Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ void J9::Options::preProcessMmf(J9JavaVM *vm, J9JITConfig *jitConfig)
if (J9_ARE_ANY_BITS_SET(vm->extendedRuntimeFlags2, J9_EXTENDED_RUNTIME2_ENABLE_PORTABLE_SHARED_CACHE)
#if defined(J9VM_OPT_CRIU_SUPPORT)
|| vm->internalVMFunctions->isCheckpointAllowed(vmThread)
#endif
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
)
{
// Disable any fixed-size heap optimizations under portable shared cache mode
Expand Down
2 changes: 1 addition & 1 deletion runtime/compiler/control/rossa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2037,7 +2037,7 @@ aboutToBootstrap(J9JavaVM * javaVM, J9JITConfig * jitConfig)
TR::Compiler->target.cpu = TR::CPU::detectRelocatable(TR::Compiler->omrPortLib);
jitConfig->targetProcessor = TR::Compiler->target.cpu.getProcessorDescription();
}
#endif
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */

#if defined(TR_TARGET_S390)
uintptr_t * tocBase = (uintptr_t *)jitConfig->pseudoTOC;
Expand Down
4 changes: 2 additions & 2 deletions runtime/compiler/env/VMJ9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9453,9 +9453,9 @@ TR_J9VMBase::inSnapshotMode()
{
#if defined(J9VM_OPT_CRIU_SUPPORT)
return getJ9JITConfig()->javaVM->internalVMFunctions->isCheckpointAllowed(vmThread());
#else
#else /* defined(J9VM_OPT_CRIU_SUPPORT) */
return false;
#endif
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
}


Expand Down
2 changes: 1 addition & 1 deletion runtime/criusupport/criusupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ getNativeString(J9VMThread *currentThread, j9object_t javaString, char **nativeS
}
}

(localNativeString)[requiredConvertedStringSize - 1] = '\0';
localNativeString[requiredConvertedStringSize - 1] = '\0';

/* convert the string */
requiredConvertedStringSize = omrstr_convert(J9STR_CODE_MUTF8, J9STR_CODE_PLATFORM_RAW,
Expand Down
8 changes: 4 additions & 4 deletions runtime/gc_modron_startup/mminit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ gcInitializeXmxXmdxVerification(J9JavaVM *javaVM, IDATA* memoryParameters, bool
/* Fail to initialize if assertions are off */
return JNI_ERR;
}

/* Adjust heap ceiling value if it is necessary */
if (extensions->heapCeiling > maxHeapForCR) {
extensions->heapCeiling = maxHeapForCR;
Expand Down Expand Up @@ -2918,11 +2918,11 @@ gcInitializeDefaults(J9JavaVM* vm)

if (hwSupported) {
/* Software Barrier request overwrites HW usage on supported HW */
extensions->concurrentScavengerHWSupport = hwSupported
&& !extensions->softwareRangeCheckReadBarrier
extensions->concurrentScavengerHWSupport = hwSupported
&& !extensions->softwareRangeCheckReadBarrier
#if defined(J9VM_OPT_CRIU_SUPPORT)
&& !vm->internalVMFunctions->isCRIUSupportEnabled(vm->internalVMFunctions->currentVMThread(vm))
#endif
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
&& !J9_ARE_ANY_BITS_SET(vm->extendedRuntimeFlags2, J9_EXTENDED_RUNTIME2_ENABLE_PORTABLE_SHARED_CACHE);
extensions->concurrentScavenger = hwSupported || extensions->softwareRangeCheckReadBarrier;
} else {
Expand Down
43 changes: 22 additions & 21 deletions runtime/oti/j9nonbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -620,19 +620,19 @@ typedef struct J9HotField {
struct J9HotField* next;
uint32_t hotness;
uint16_t cpuUtil;
uint8_t hotFieldOffset;
uint8_t hotFieldOffset;
} J9HotField;

typedef struct J9ClassHotFieldsInfo {
struct J9HotField* hotFieldListHead;
struct J9ClassLoader* classLoader;
BOOLEAN isClassHotFieldListDirty;
BOOLEAN isClassHotFieldListDirty;
uint8_t hotFieldOffset1;
uint8_t hotFieldOffset2;
uint8_t hotFieldOffset3;
uint8_t consecutiveHotFieldSelections;
uint8_t hotFieldListLength;
} J9ClassHotFieldsInfo;
uint8_t consecutiveHotFieldSelections;
uint8_t hotFieldListLength;
} J9ClassHotFieldsInfo;

typedef struct J9ROMNameAndSignature {
J9SRP name;
Expand Down Expand Up @@ -2876,11 +2876,11 @@ typedef struct J9Object {
/**
* An aligned class pointer representing the type of the object. The low order bits must be masked off prior to
* dereferencing this pointer. The bit values are described below.
*
* @details
*
*
* @details
*
* The following diagram describes the metadata stored in the low order bit flags of an object class pointer:
*
*
* Bit 31 23 15 7 6 5 4 3 2 1 0
* ┌─────────────────────────────────────────────────────────────────────┐
* Word │0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0│
Expand All @@ -2891,30 +2891,30 @@ typedef struct J9Object {
* │ │ └──────► [3] Slot contains forwarded pointer
* │ └────────► [4] Object has been hashed
* └─────────────► [5] Nursery age (0 - 14) or various remembered states
*
*
* [1] If bit is 0, the slot represents the start of object, ie object header, which depending of forwarded bit
* could be class slot or forwarded pointer.
* If bit is 1, the slot represents the start of a hole, in which case the value is the address of the next
* connected hole (as part of free memory pool). The address could be null, in which case it is a small
* connected hole (as part of free memory pool). The address could be null, in which case it is a small
* stand-alone hole that is not part of the list, so called dark-matter. A hole will also have one more slot,
* with info about its size/length.
* This bit designation is needed when heap objects are iterated in address order - once an object is found,
* it can be followed by another object, or a hole that needs to be skipped.
* [2] If object is hashed (hash bit 4 set), and object is moved by a GC, the object will grow by a hash slot
* (position of hash slot is found in class struct), and this bit will be set.
* This bit is used to find hash value (from object address if not moved or from hash slot if moved) and to
* find proper size of object (for example when heap objects are iterated, to find the position of the next
* find proper size of object (for example when heap objects are iterated, to find the position of the next
* object).
* [3] If the object has been moved on the heap and we encounter a stale reference, this bit tells us that the a
* slot within the object contains a forwarding pointer (FP) to where we can find the moved object. FP
* partially overlaps with class slot (it's not quite following it). In 32bit it exactly overlaps (both FP and
* class slots are 32 bit). In 64bit non-CR, again it exactly overlaps (both FP and class slots are 64 bit ).
* In 64bit CR, 1/2 of FP overlaps with class slot, and the other 1/2 of FP follows the class slots (FP is
* In 64bit CR, 1/2 of FP overlaps with class slot, and the other 1/2 of FP follows the class slots (FP is
* uncommpressed 64 bit, and class slot is 32 bit).
* [4] Object has been hashed by application thread, for example by using the object as a key in a hash map
* [5] If the object is in the nursery (gencon) these four bits count how many times the object has been flipped.
* If the object is in tenure (gencon) these bits describe the various tenure states. These bits are not used
* under the balanced GC policy.
* under the balanced GC policy.
*/
j9objectclass_t clazz;
} J9Object;
Expand Down Expand Up @@ -3640,29 +3640,29 @@ typedef struct J9Method {

/**
* This field is overloaded and can have several meanings:
*
*
* 1. If the J9_STARTPC_NOT_TRANSLATED bit is set, this method is interpreted
* a. If the value is non-negative, then the field contains the invocation count which is decremented towards
* zero. When the invocation count reaches zero, the method will be queued for JIT compilation. The invocation
* count is represented as:
*
*
* ```
* (invocationCount << 1) | J9_STARTPC_NOT_TRANSLATED
* ```
*
*
* b. If the method is a default method which has conflicts then this field contains the RAM method to execute.
* That is, the extra field will contain:
*
*
* ```
* ((J9Method*)<default method to execute>) | J9_STARTPC_NOT_TRANSLATED
* ```
*
*
* c. If the value is negative, then it can be one of (see definition for documentation on these):
* - J9_JIT_NEVER_TRANSLATE
* The VM will not decrement the count and the method will stay interpreted
* - J9_JIT_QUEUED_FOR_COMPILATION
* The method has been queued for JIT compilation
*
*
* 2. If the J9_STARTPC_NOT_TRANSLATED bit is not set, this method is JIT compiled
* a. The field contains the address of the start PC of the JIT compiled method
*/
Expand Down Expand Up @@ -5100,6 +5100,7 @@ typedef struct J9VMThread {
#define J9VMTHREAD_DISCONTIGUOUS_HEADER_SIZE(vmThread) (J9VMTHREAD_COMPRESS_OBJECT_REFERENCES(vmThread) ? sizeof(J9IndexableObjectDiscontiguousCompressed) : sizeof(J9IndexableObjectDiscontiguousFull))

typedef struct J9CRIUCheckpointState {
BOOLEAN isCheckPointEnabled;
BOOLEAN isCheckPointAllowed;
BOOLEAN isNonPortableRestoreMode;
} J9CRIUCheckpointState;
Expand Down Expand Up @@ -5557,8 +5558,8 @@ typedef struct J9JavaVM {
jmethodID criuJVMCheckpointExceptionInit;
jmethodID criuSystemCheckpointExceptionInit;
jmethodID criuRestoreExceptionInit;
J9CRIUCheckpointState checkpointState;
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
J9CRIUCheckpointState *checkpointState;
#if JAVA_SPEC_VERSION >= 16
struct J9Pool *cifNativeCalloutDataCache;
omrthread_monitor_t cifNativeCalloutDataCacheMutex;
Expand Down
8 changes: 5 additions & 3 deletions runtime/oti/vm_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,12 +488,13 @@ internalCreateRAMClassFromROMClass(J9VMThread *vmThread, J9ClassLoader *classLoa
IDATA entryIndex, I_32 locationType, J9Class *classBeingRedefined, J9Class *hostClass);


#if defined(J9VM_OPT_CRIU_SUPPORT)

/* ---------------- criuhelpers.cpp ---------------- */
/**
* @brief Queries if CRIU support is enabled. By default support
* is not enabled, it can be enabled with `-XX:+EnableCRIUSupport`
*
*
* @param currentThread vmthread token
* @return TRUE if enabled, FALSE otherwise
*/
Expand All @@ -506,7 +507,6 @@ isCRIUSupportEnabled(J9VMThread *currentThread);
* will not be permitted after the JVM has been restored from a checkpoint
* (checkpoint once mode).
*
*
* @param currentThread vmthread token
* @return TRUE if permitted, FALSE otherwise
*/
Expand All @@ -532,6 +532,8 @@ jvmCheckpointHooks(J9VMThread *currentThread);
BOOLEAN
jvmRestoreHooks(J9VMThread *currentThread);

#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */

/* ---------------- classloadersearch.c ---------------- */

/**
Expand Down Expand Up @@ -4712,7 +4714,7 @@ void
throwNewJavaIoIOException(JNIEnv *env, const char *message);

#ifdef __cplusplus
}
} /* extern "C" */
#endif

#endif /* vm_api_h */
11 changes: 8 additions & 3 deletions runtime/vm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ if(OMR_ARCH_POWER AND OMR_OS_AIX)
]]
endif()
elseif(OMR_OS_ZOS)
#TODO need to handle optimized debug info
# TODO need to handle optimized debug info
list(APPEND interp_flags_to_remove "-O3" "-g" "-qdebug=nohook")

list(APPEND interp_new_flags
Expand Down Expand Up @@ -91,7 +91,6 @@ set(main_sources
classseg.c
classsupport.c
createramclass.cpp
criuhelpers.cpp
description.c
dllsup.c
drophelp.c
Expand Down Expand Up @@ -182,6 +181,13 @@ set(main_sources

${CMAKE_CURRENT_BINARY_DIR}/ut_j9vm.c
)

if(J9VM_OPT_CRIU_SUPPORT)
list(APPEND main_sources
criuhelpers.cpp
)
endif()

set(interpreter_sources
BytecodeInterpreterCompressed.cpp
BytecodeInterpreterFull.cpp
Expand Down Expand Up @@ -219,7 +225,6 @@ if(interp_new_flags)
set_property(SOURCE ${interpreter_sources} APPEND_STRING PROPERTY COMPILE_FLAGS " ${flags_str}")
endif()


if(OMR_OS_WINDOWS AND (OMR_TOOLCONFIG STREQUAL "msvc"))
# JIT helper methods require us to disable buffer security checks on Windows
# See https://github.com/eclipse-openj9/openj9/pull/1494 for rationale
Expand Down
19 changes: 8 additions & 11 deletions runtime/vm/criuhelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ jvmRestoreHooks(J9VMThread *currentThread)
nas.name = (J9UTF8 *)&runPostRestoreHooks_name;
nas.signature = (J9UTF8 *)&runPostRestoreHooks_sig;

Assert_VM_notNull(vm->checkpointState);
Assert_VM_true(vm->checkpointState.isCheckPointEnabled);

if (vm->checkpointState->isNonPortableRestoreMode) {
vm->checkpointState->isCheckPointAllowed = FALSE;
if (vm->checkpointState.isNonPortableRestoreMode) {
vm->checkpointState.isCheckPointAllowed = FALSE;
}

TRIGGER_J9HOOK_VM_PREPARING_FOR_RESTORE(vm->hookInterface, currentThread);
Expand All @@ -88,22 +88,19 @@ jvmRestoreHooks(J9VMThread *currentThread)
BOOLEAN
isCRIUSupportEnabled(J9VMThread *currentThread)
{
return NULL != currentThread->javaVM->checkpointState;
return currentThread->javaVM->checkpointState.isCheckPointEnabled;
}

BOOLEAN
isCheckpointAllowed(J9VMThread *currentThread)
{
J9JavaVM *vm = currentThread->javaVM;
BOOLEAN res = FALSE;
BOOLEAN result = FALSE;

if (isCRIUSupportEnabled(currentThread)) {
res = vm->checkpointState->isCheckPointAllowed;
result = currentThread->javaVM->checkpointState.isCheckPointAllowed;
}

return res;
return result;
}



}/* extern "C" */
} /* extern "C" */

0 comments on commit 5bd7e26

Please sign in to comment.