Skip to content

Commit

Permalink
CRIUSupport helpers
Browse files Browse the repository at this point in the history
Basic support to detect if criu is available on the machine. More
changes to follow.

Signed-off-by: Tobi Ajila <[email protected]>
  • Loading branch information
tajila committed Jun 14, 2021
1 parent cf3b49b commit a529391
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 2 deletions.
3 changes: 2 additions & 1 deletion buildspecs/core.feature
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2006, 2020 IBM Corp. and others
Copyright (c) 2006, 2021 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 @@ -106,6 +106,7 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-excepti
<flag id="module_util_core" value="true"/>
<flag id="module_verutil" value="true"/>
<flag id="module_vm" value="true"/>
<flag id="opt_criuSupport" value="false"/>
<flag id="opt_fragmentRamClasses" value="true"/>
<flag id="opt_inlineJsrs" value="true"/>
<flag id="opt_jitserver" value="false"/>
Expand Down
46 changes: 46 additions & 0 deletions jcl/src/openj9.jvm/share/classes/com/ibm/jvm/CRIUSupport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*[INCLUDE-IF CRIU_SUPPORT]*/

/*******************************************************************************
* Copyright (c) 2021, 2021 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
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
* or the Apache License, Version 2.0 which accompanies this distribution and
* is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following
* Secondary Licenses when the conditions for such availability set
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
* General Public License, version 2 with the GNU Classpath
* Exception [1] and GNU General Public License, version 2 with the
* OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] http://openjdk.java.net/legal/assembly-exception.html
*
* 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
*******************************************************************************/
package com.ibm.jvm;

/**
* CRIU Support API
*/
public final class CRIUSupport {

private static final boolean criuSupportEnabled = isCRIUSupportEnabledImpl();

private CRIUSupport() {}

private static native boolean isCRIUSupportEnabledImpl();

/**
* Queries if CRIU support is enabled.
*
* @return TRUE is support is enabled, FALSE otherwise
*/
public static boolean isCRIUSupportEnabled() {
return criuSupportEnabled;
}

}
3 changes: 3 additions & 0 deletions runtime/cmake/platform/toolcfg/gnu.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ omr_append_flags(CMAKE_CXX_FLAGS ${OMR_STRNCPY_FORTIFY_OPTIONS})
if(J9VM_USE_RDYNAMIC AND OMR_OS_LINUX)
omr_append_flags(CMAKE_SHARED_LINKER_FLAGS "-rdynamic")
endif()
if(J9VM_OPT_CRIU_SUPPORT AND OMR_OS_LINUX)
set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} -lcriu")
endif()
1 change: 1 addition & 0 deletions runtime/include/j9cfg.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ extern "C" {
#cmakedefine J9VM_MATH_DIRECT_HELPERS
#cmakedefine J9VM_OPT_ANNOTATIONS
#cmakedefine J9VM_OPT_BIG_INTEGER
#cmakedefine J9VM_OPT_CRIU_SUPPORT
#cmakedefine J9VM_OPT_CUDA
#cmakedefine J9VM_OPT_DEBUG_INFO_SERVER
#cmakedefine J9VM_OPT_DEBUG_JSR45_SUPPORT
Expand Down
7 changes: 7 additions & 0 deletions runtime/jcl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ else()
target_sources(jclse PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/unix/syshelp.c)
endif()

if(J9VM_OPT_CRIU_SUPPORT)
target_sources(jclse
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/common/criusupport.c
)
endif()

if(J9VM_OPT_METHOD_HANDLE)
target_sources(jclse
PRIVATE
Expand Down
46 changes: 46 additions & 0 deletions runtime/jcl/common/criusupport.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*******************************************************************************
* Copyright (c) 2021, 2021 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
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
* or the Apache License, Version 2.0 which accompanies this distribution and
* is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following
* Secondary Licenses when the conditions for such availability set
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
* General Public License, version 2 with the GNU Classpath
* Exception [1] and GNU General Public License, version 2 with the
* OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] http://openjdk.java.net/legal/assembly-exception.html
*
* 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
*******************************************************************************/
#if defined(LINUX)
#include <criu/criu.h>
#endif /* defined(LINUX) */

#include "jni.h"
#include "j9.h"
#include "jclprots.h"

jboolean JNICALL
Java_com_ibm_jvm_CRIUSupport_isCRIUSupportEnabledImpl(JNIEnv *env, jclass unused)
{
J9VMThread *currentThread = (J9VMThread *) env;
J9JavaVM *vm = currentThread->javaVM;
jboolean res = JNI_FALSE;

if (J9_ARE_ALL_BITS_SET(vm->extendedRuntimeFlags2, J9_EXTENDED_RUNTIME2_ENABLE_CRIU_SUPPORT)) {
#if defined(LINUX)
if (0 == criu_init_opts()) {
res = JNI_TRUE;
}
#endif /* defined(LINUX) */
}

return res;
}
7 changes: 7 additions & 0 deletions runtime/jcl/exports.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -631,3 +631,10 @@ if(J9VM_OPT_OPENJDK_METHODHANDLE)
Java_java_lang_invoke_MethodHandleNatives_registerNatives
)
endif()

# CRIU support
if(J9VM_OPT_CRIU_SUPPORT)
omr_add_exports(jclse
Java_com_ibm_jvm_CRIUSupport_isCRIUSupportEnabledImpl
)
endif()
12 changes: 11 additions & 1 deletion runtime/jcl/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ OpenJDK Assembly Exception [2].
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
-->
<module xmlns:xi="http://www.w3.org/2001/XInclude">

<xi:include href="uma/criusupport_exports.xml"></xi:include>
<xi:include href="uma/java_lang_invoke_MethodHandleNatives_exports.xml"></xi:include>
<xi:include href="uma/java_dyn_methodhandle_exports.xml"></xi:include>
<xi:include href="uma/sun_misc_Unsafe_exports.xml"></xi:include>
Expand All @@ -45,6 +45,7 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-excepti
<xi:fallback/>
</xi:include>

<xi:include href="uma/criusupport_objects.xml"></xi:include>
<xi:include href="uma/java_lang_invoke_MethodHandleNatives_objects.xml"></xi:include>
<xi:include href="uma/java_dyn_methodhandle_objects.xml"></xi:include>
<xi:include href="uma/sun_misc_Unsafe_objects.xml"></xi:include>
Expand Down Expand Up @@ -93,6 +94,9 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-excepti
<group name="jithelpers"/>
<group name="sun_misc_Unsafe"/>
<group name="sun_misc_Unsafe_inl"/>
<group name="criusupport">
<include-if condition="spec.flags.opt_criuSupport"/>
</group>
<group name="attach">
<include-if condition="spec.flags.opt_sidecar"/>
</group>
Expand Down Expand Up @@ -164,6 +168,9 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-excepti
<group name="attach">
<include-if condition="spec.flags.opt_sidecar"/>
</group>
<group name="criusupport">
<include-if condition="spec.flags.opt_criuSupport"/>
</group>
<group name="se626_orb_ludcl"/>
<group name="se7"/>
<group name="se8"/>
Expand Down Expand Up @@ -211,6 +218,9 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-excepti
<library name="j9thr"/>
<library name="socket" type="macro"/>
<library name="sunvmi"/>
<library name="criu" type="external">
<include-if condition="spec.flags.opt_criuSupport and spec.linux.*"/>
</library>
</libraries>
</artifact>

Expand Down
24 changes: 24 additions & 0 deletions runtime/jcl/uma/criusupport_exports.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!--
Copyright (c) 2021, 2021 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
distribution and is available at https://www.eclipse.org/legal/epl-2.0/
or the Apache License, Version 2.0 which accompanies this distribution and
is available at https://www.apache.org/licenses/LICENSE-2.0.
This Source Code may also be made available under the following
Secondary Licenses when the conditions for such availability set
forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
General Public License, version 2 with the GNU Classpath
Exception [1] and GNU General Public License, version 2 with the
OpenJDK Assembly Exception [2].
[1] https://www.gnu.org/software/classpath/license.html
[2] http://openjdk.java.net/legal/assembly-exception.html
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
-->
<exports group="criusupport">
<export name="Java_com_ibm_jvm_CRIUSupport_isCRIUSupportEnabledImpl" />
</exports>
26 changes: 26 additions & 0 deletions runtime/jcl/uma/criusupport_objects.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!--
Copyright (c) 2021, 2021 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
distribution and is available at https://www.eclipse.org/legal/epl-2.0/
or the Apache License, Version 2.0 which accompanies this distribution and
is available at https://www.apache.org/licenses/LICENSE-2.0.
This Source Code may also be made available under the following
Secondary Licenses when the conditions for such availability set
forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
General Public License, version 2 with the GNU Classpath
Exception [1] and GNU General Public License, version 2 with the
OpenJDK Assembly Exception [2].
[1] https://www.gnu.org/software/classpath/license.html
[2] http://openjdk.java.net/legal/assembly-exception.html
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
-->
<objects group="criusupport">
<object name="criusupport" >
<include-if condition="spec.flags.opt_criuSupport" />
</object>
</objects>
4 changes: 4 additions & 0 deletions runtime/oti/jclprots.h
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,10 @@ Java_com_ibm_lang_management_internal_UnixExtendedOperatingSystem_getOpenFileDes
jobject JNICALL
Java_com_ibm_virtualization_management_internal_GuestOS_retrieveProcessorUsageImpl(JNIEnv *env, jobject beanInstance, jobject procUsageObject);

/* CRIUSupport.c */
jboolean JNICALL
Java_com_ibm_jvm_CRIUSupport_isCRIUSupportEnabledImpl(JNIEnv *env, jclass unused);

/* com_ibm_jvm_Stats.c */
void JNICALL
Java_com_ibm_jvm_Stats_getStats(JNIEnv *env, jobject obj);
Expand Down

0 comments on commit a529391

Please sign in to comment.