From 30d8cd2d962d4dc4d0178f54ff2d0e3ca0ce4e52 Mon Sep 17 00:00:00 2001 From: Jason Feng Date: Tue, 13 Dec 2022 18:01:22 -0500 Subject: [PATCH] Add CRIU helper VM.isJVMInSingleThreadedMode() Signed-off-by: Jason Feng --- .../share/classes/com/ibm/oti/vm/VM.java | 8 +++++++- runtime/jcl/common/com_ibm_oti_vm_VM.c | 19 ++++++++++++++++++- runtime/jcl/exports.cmake | 1 + runtime/jcl/uma/se7_exports.xml | 3 ++- runtime/oti/jclprots.h | 7 +++++++ 5 files changed, 35 insertions(+), 3 deletions(-) diff --git a/jcl/src/java.base/share/classes/com/ibm/oti/vm/VM.java b/jcl/src/java.base/share/classes/com/ibm/oti/vm/VM.java index 377d2c892ec..2f72b58df30 100644 --- a/jcl/src/java.base/share/classes/com/ibm/oti/vm/VM.java +++ b/jcl/src/java.base/share/classes/com/ibm/oti/vm/VM.java @@ -1,4 +1,4 @@ -/*[INCLUDE-IF Sidecar16]*/ +/*[INCLUDE-IF JAVA_SPEC_VERSION >= 8]*/ package com.ibm.oti.vm; /******************************************************************************* @@ -577,4 +577,10 @@ public static int markCurrentThreadAsSystem() */ public static native long getJ9ConstantPoolFromJ9Class(long j9clazz); +/** + * Queries whether the JVM is running in single threaded mode. + * + * @return true if JVM is in single threaded mode, false otherwise + */ +public static native boolean isJVMInSingleThreadedMode(); } diff --git a/runtime/jcl/common/com_ibm_oti_vm_VM.c b/runtime/jcl/common/com_ibm_oti_vm_VM.c index c91b95b7c54..6fd628a0060 100644 --- a/runtime/jcl/common/com_ibm_oti_vm_VM.c +++ b/runtime/jcl/common/com_ibm_oti_vm_VM.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 1998, 2021 IBM Corp. and others + * Copyright (c) 1998, 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 @@ -173,3 +173,20 @@ Java_com_ibm_oti_vm_VM_getJ9ConstantPoolFromJ9Class(JNIEnv *env, jclass unused, */ return (jlong)(UDATA)clazz->ramConstantPool; } + +/** + * Queries whether the JVM is running in single threaded mode. + * + * @return JNI_TRUE if JVM is in single threaded mode, JNI_FALSE otherwise + */ +jboolean JNICALL +Java_com_ibm_oti_vm_VM_isJVMInSingleThreadedMode(JNIEnv *env, jclass unused) +{ + jboolean result = JNI_FALSE; +#if defined(J9VM_OPT_CRIU_SUPPORT) + if (J9_IS_SINGLE_THREAD_MODE(((J9VMThread*)env)->javaVM)) { + result = JNI_TRUE; + } +#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */ + return result; +} diff --git a/runtime/jcl/exports.cmake b/runtime/jcl/exports.cmake index 75c66077b6b..ab1c685bfc1 100644 --- a/runtime/jcl/exports.cmake +++ b/runtime/jcl/exports.cmake @@ -300,6 +300,7 @@ omr_add_exports(jclse Java_com_ibm_oti_vm_VM_markCurrentThreadAsSystemImpl Java_com_ibm_oti_vm_VM_setCommonData Java_com_ibm_oti_vm_VM_getJ9ConstantPoolFromJ9Class + Java_com_ibm_oti_vm_VM_isJVMInSingleThreadedMode Java_com_ibm_rmi_io_IIOPInputStream_00024LUDCLStackWalkOptimizer_LUDCLMarkFrame Java_com_ibm_rmi_io_IIOPInputStream_00024LUDCLStackWalkOptimizer_LUDCLUnmarkFrameImpl Java_com_ibm_virtualization_management_internal_GuestOS_retrieveMemoryUsageImpl diff --git a/runtime/jcl/uma/se7_exports.xml b/runtime/jcl/uma/se7_exports.xml index 6d8303f8b22..be9bcc368f5 100644 --- a/runtime/jcl/uma/se7_exports.xml +++ b/runtime/jcl/uma/se7_exports.xml @@ -1,5 +1,5 @@