diff --git a/runtime/j9vm/java11vmi.c b/runtime/j9vm/java11vmi.c index 87d08517438..3155e37877a 100644 --- a/runtime/j9vm/java11vmi.c +++ b/runtime/j9vm/java11vmi.c @@ -1731,12 +1731,13 @@ JVM_IsSharingEnabled(JNIEnv *env) #endif /* JAVA_SPEC_VERSION >= 16 */ JNIEXPORT jboolean JNICALL -JVM_IsUseContainerSupport(JNIEnv *env) +JVM_IsUseContainerSupport(void) { - J9VMThread *const currentThread = (J9VMThread *)env; - J9JavaVM *vm = currentThread->javaVM; + J9JavaVM *vm = BFUjavaVM; jboolean result = JNI_FALSE; + Assert_SC_true(NULL != vm); + if (J9_ARE_ALL_BITS_SET(vm->extendedRuntimeFlags2, J9_EXTENDED_RUNTIME2_USE_CONTAINER_SUPPORT)) { /* Return true if -XX:+UseContainerSupport is specified. This option is enabled by default. */ result = JNI_TRUE; diff --git a/runtime/j9vm/javanextvmi.cpp b/runtime/j9vm/javanextvmi.cpp index dfbe9d7d669..50e7808dde1 100644 --- a/runtime/j9vm/javanextvmi.cpp +++ b/runtime/j9vm/javanextvmi.cpp @@ -793,10 +793,25 @@ JVM_GetCDSConfigStatus() #endif /* JAVA_SPEC_VERSION >= 23 */ #if JAVA_SPEC_VERSION >= 24 +/** + * @brief Determine if the JVM is running inside a container. + * + * @return JNI_TRUE if running inside a container; otherwise, JNI_FALSE + */ JNIEXPORT jboolean JNICALL JVM_IsContainerized(void) { - return JNI_FALSE; + J9JavaVM *vm = BFUjavaVM; + jboolean isContainerized = JNI_FALSE; + + Assert_SC_true(NULL != vm); + + OMRPORT_ACCESS_FROM_J9PORT(vm->portLibrary); + if (omrsysinfo_is_running_in_container()) { + isContainerized = JNI_TRUE; + } + + return isContainerized; } #endif /* JAVA_SPEC_VERSION >= 24 */ diff --git a/runtime/redirector/forwarders.m4 b/runtime/redirector/forwarders.m4 index e4663d62b8c..b82beaf18f5 100644 --- a/runtime/redirector/forwarders.m4 +++ b/runtime/redirector/forwarders.m4 @@ -382,7 +382,7 @@ _IF([JAVA_SPEC_VERSION >= 16], [_X(JVM_DefineArchivedModules, JNICALL, false, void, JNIEnv *env, jobject obj1, jobject obj2)]) _IF([JAVA_SPEC_VERSION >= 16], [_X(JVM_LogLambdaFormInvoker, JNICALL, false, void, JNIEnv *env, jstring str)]) -_X(JVM_IsUseContainerSupport, JNICALL, false, jboolean, JNIEnv *env) +_X(JVM_IsUseContainerSupport, JNICALL, false, jboolean, void) _X(AsyncGetCallTrace, JNICALL, false, void, void *trace, jint depth, void *ucontext) _IF([JAVA_SPEC_VERSION >= 17], [_X(JVM_DumpClassListToFile, JNICALL, false, void, JNIEnv *env, jstring str)])