Skip to content

Commit

Permalink
svm/libcontainer: replace isContainerized(boolean) with isInitialized…
Browse files Browse the repository at this point in the history
…() and isContainerized()
  • Loading branch information
zapster committed Jul 4, 2024
1 parent 434867d commit 1bea0be
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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;
}

Expand Down

0 comments on commit 1bea0be

Please # to comment.