Skip to content

Commit a27ba35

Browse files
committed
Implement JVM_IsContainerized and fix JVM_IsUseContainerSupport
An implementation of JVM_IsContainerized has been added. The signature of JVM_IsUseContainerSupport has been corrected. Closes: #19801 Signed-off-by: Babneet Singh <[email protected]>
1 parent 677181c commit a27ba35

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

runtime/j9vm/java11vmi.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ static UDATA allowReadAccessToModule(J9VMThread * currentThread, J9Module * from
8989
static void trcModulesAddReadsModule(J9VMThread *currentThread, jobject toModule, J9Module *j9FromMod, J9Module *j9ToMod);
9090

9191
/* These come from jvm.c */
92+
extern J9JavaVM *BFUjavaVM;
9293
extern IDATA (*f_monitorEnter)(omrthread_monitor_t monitor);
9394
extern IDATA (*f_monitorExit)(omrthread_monitor_t monitor);
9495

@@ -1730,13 +1731,19 @@ JVM_IsSharingEnabled(JNIEnv *env)
17301731
#endif /* JAVA_SPEC_VERSION < 23 */
17311732
#endif /* JAVA_SPEC_VERSION >= 16 */
17321733

1734+
/**
1735+
* @brief Determine if -XX:+UseContainerSupport is specified.
1736+
*
1737+
* @return JNI_TRUE if -XX:+UseContainerSupport is specified; otherwise, JNI_FALSE
1738+
*/
17331739
JNIEXPORT jboolean JNICALL
1734-
JVM_IsUseContainerSupport(JNIEnv *env)
1740+
JVM_IsUseContainerSupport(void)
17351741
{
1736-
J9VMThread *const currentThread = (J9VMThread *)env;
1737-
J9JavaVM *vm = currentThread->javaVM;
1742+
J9JavaVM *vm = BFUjavaVM;
17381743
jboolean result = JNI_FALSE;
17391744

1745+
Assert_SC_true(NULL != vm);
1746+
17401747
if (J9_ARE_ALL_BITS_SET(vm->extendedRuntimeFlags2, J9_EXTENDED_RUNTIME2_USE_CONTAINER_SUPPORT)) {
17411748
/* Return true if -XX:+UseContainerSupport is specified. This option is enabled by default. */
17421749
result = JNI_TRUE;

runtime/j9vm/javanextvmi.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,10 +793,25 @@ JVM_GetCDSConfigStatus()
793793
#endif /* JAVA_SPEC_VERSION >= 23 */
794794

795795
#if JAVA_SPEC_VERSION >= 24
796+
/**
797+
* @brief Determine if the JVM is running inside a container.
798+
*
799+
* @return JNI_TRUE if running inside a container; otherwise, JNI_FALSE
800+
*/
796801
JNIEXPORT jboolean JNICALL
797802
JVM_IsContainerized(void)
798803
{
799-
return JNI_FALSE;
804+
J9JavaVM *vm = BFUjavaVM;
805+
jboolean isContainerized = JNI_FALSE;
806+
807+
Assert_SC_true(NULL != vm);
808+
809+
OMRPORT_ACCESS_FROM_J9PORT(vm->portLibrary);
810+
if (omrsysinfo_is_running_in_container()) {
811+
isContainerized = JNI_TRUE;
812+
}
813+
814+
return isContainerized;
800815
}
801816
#endif /* JAVA_SPEC_VERSION >= 24 */
802817

runtime/redirector/forwarders.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ _IF([JAVA_SPEC_VERSION >= 16],
382382
[_X(JVM_DefineArchivedModules, JNICALL, false, void, JNIEnv *env, jobject obj1, jobject obj2)])
383383
_IF([JAVA_SPEC_VERSION >= 16],
384384
[_X(JVM_LogLambdaFormInvoker, JNICALL, false, void, JNIEnv *env, jstring str)])
385-
_X(JVM_IsUseContainerSupport, JNICALL, false, jboolean, JNIEnv *env)
385+
_X(JVM_IsUseContainerSupport, JNICALL, false, jboolean, void)
386386
_X(AsyncGetCallTrace, JNICALL, false, void, void *trace, jint depth, void *ucontext)
387387
_IF([JAVA_SPEC_VERSION >= 17],
388388
[_X(JVM_DumpClassListToFile, JNICALL, false, void, JNIEnv *env, jstring str)])

0 commit comments

Comments
 (0)