From 1bea0be4cc32eb90b3daf2de4d141c91bdf7f690 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Wed, 3 Jul 2024 10:05:22 +0200 Subject: [PATCH] svm/libcontainer: replace isContainerized(boolean) with isInitialized() and isContainerized() --- .../oracle/svm/core/SubstrateDiagnostics.java | 10 ++++--- .../oracle/svm/core/container/Container.java | 27 +++++++++++-------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateDiagnostics.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateDiagnostics.java index a416839fac73..403d189e20cb 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateDiagnostics.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateDiagnostics.java @@ -30,7 +30,6 @@ import java.util.ArrayList; import java.util.Arrays; -import com.oracle.svm.core.container.OperatingSystem; import org.graalvm.collections.EconomicMap; import org.graalvm.nativeimage.CurrentIsolate; import org.graalvm.nativeimage.ImageSingletons; @@ -57,6 +56,7 @@ import com.oracle.svm.core.code.RuntimeCodeInfoMemory; import com.oracle.svm.core.config.ConfigurationValues; import com.oracle.svm.core.container.Container; +import com.oracle.svm.core.container.OperatingSystem; import com.oracle.svm.core.deopt.DeoptimizationSupport; import com.oracle.svm.core.deopt.Deoptimizer; import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton; @@ -508,7 +508,11 @@ private static boolean pointsIntoNativeImageCode(CodePointer possibleIp) { private static boolean isContainerized() { boolean allowInit = !SubstrateOptions.AsyncSignalSafeDiagnostics.getValue(); - return Container.singleton().isContainerized(allowInit); + if (Container.singleton().isInitialized() || allowInit) { + return Container.singleton().isContainerized(); + } + // uninitialized and initialization not allowed + return false; } public static class FatalErrorState { @@ -860,7 +864,7 @@ public void printDiagnostics(Log log, ErrorContext context, int maxDiagnosticLev Platform platform = ImageSingletons.lookup(Platform.class); log.string("Platform: ").string(platform.getOS()).string("/").string(platform.getArchitecture()).newline(); log.string("Page size: ").unsigned(SubstrateOptions.getPageSize()).newline(); - log.string("Containerized: ").bool(isContainerized()).newline(); + log.string("Containerized: ").string(Container.singleton().isInitialized() ? String.valueOf(isContainerized()) : "unknown").newline(); log.string("CPU features used for AOT compiled code: ").string(getBuildTimeCpuFeatures()).newline(); log.indent(false); } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/container/Container.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/container/Container.java index 15d2b0c74f96..050af828e479 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/container/Container.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/container/Container.java @@ -74,22 +74,27 @@ public static Container singleton() { } @Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true) - public boolean isContainerized() { - return isContainerized(true); + public boolean isInitialized() { + return STATE.get().readWord(0) != State.UNINITIALIZED; } + /** + * Determines whether the image runs containerized, potentially initializing container support + * if not yet initialized. If initialization is not desired, calls to this method must be + * guarded by {@link #isInitialized()}. + */ @Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true) - public boolean isContainerized(boolean allowInit) { + public boolean isContainerized() { if (!isSupported()) { return false; } UnsignedWord value = STATE.get().readWord(0); - if (allowInit && value == State.UNINITIALIZED) { + if (value == State.UNINITIALIZED) { value = initialize(); } - assert value == State.CONTAINERIZED || value == State.NOT_CONTAINERIZED || !allowInit; + assert value == State.CONTAINERIZED || value == State.NOT_CONTAINERIZED; return value == State.CONTAINERIZED; } @@ -126,7 +131,7 @@ private static UnsignedWord initialize() { @Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true) public int getActiveProcessorCount() { - VMError.guarantee(isContainerized(false)); + VMError.guarantee(isInitialized() && isContainerized()); long currentMs = System.currentTimeMillis(); if (currentMs > activeProcessorCountTimeoutMs) { @@ -138,13 +143,13 @@ public int getActiveProcessorCount() { @Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true) public int getCachedActiveProcessorCount() { - VMError.guarantee(isContainerized(false)); + VMError.guarantee(isInitialized() && isContainerized()); return cachedActiveProcessorCount; } @Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true) public UnsignedWord getPhysicalMemory() { - VMError.guarantee(isContainerized(false)); + VMError.guarantee(isInitialized() && isContainerized()); long currentMs = System.currentTimeMillis(); if (currentMs > physicalMemoryTimeoutMs) { @@ -156,13 +161,13 @@ public UnsignedWord getPhysicalMemory() { @Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true) public UnsignedWord getCachedPhysicalMemory() { - VMError.guarantee(isContainerized(false)); + VMError.guarantee(isInitialized() && isContainerized()); return cachedPhysicalMemorySize; } @Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true) public long getMemoryLimitInBytes() { - VMError.guarantee(isContainerized(false)); + VMError.guarantee(isInitialized() && isContainerized()); long currentMs = System.currentTimeMillis(); if (currentMs > memoryLimitInBytesTimeoutMs) { @@ -174,7 +179,7 @@ public long getMemoryLimitInBytes() { @Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true) public long getCachedMemoryLimitInBytes() { - VMError.guarantee(isContainerized(false)); + VMError.guarantee(isInitialized() && isContainerized()); return cachedMemoryLimitInBytes; }