Skip to content

Commit c10f3fc

Browse files
committed
svm/libcontainer: replace isContainerized(boolean) with isInitialized() and isContainerized()
1 parent 9a72f54 commit c10f3fc

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateDiagnostics.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.util.ArrayList;
3131
import java.util.Arrays;
3232

33-
import com.oracle.svm.core.container.OperatingSystem;
3433
import org.graalvm.collections.EconomicMap;
3534
import org.graalvm.nativeimage.CurrentIsolate;
3635
import org.graalvm.nativeimage.ImageSingletons;
@@ -57,6 +56,7 @@
5756
import com.oracle.svm.core.code.RuntimeCodeInfoMemory;
5857
import com.oracle.svm.core.config.ConfigurationValues;
5958
import com.oracle.svm.core.container.Container;
59+
import com.oracle.svm.core.container.OperatingSystem;
6060
import com.oracle.svm.core.deopt.DeoptimizationSupport;
6161
import com.oracle.svm.core.deopt.Deoptimizer;
6262
import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton;
@@ -508,7 +508,11 @@ private static boolean pointsIntoNativeImageCode(CodePointer possibleIp) {
508508

509509
private static boolean isContainerized() {
510510
boolean allowInit = !SubstrateOptions.AsyncSignalSafeDiagnostics.getValue();
511-
return Container.singleton().isContainerized(allowInit);
511+
if (Container.singleton().isInitialized() || allowInit) {
512+
return Container.singleton().isContainerized();
513+
}
514+
// uninitialized and initialization not allowed
515+
return false;
512516
}
513517

514518
public static class FatalErrorState {
@@ -860,7 +864,7 @@ public void printDiagnostics(Log log, ErrorContext context, int maxDiagnosticLev
860864
Platform platform = ImageSingletons.lookup(Platform.class);
861865
log.string("Platform: ").string(platform.getOS()).string("/").string(platform.getArchitecture()).newline();
862866
log.string("Page size: ").unsigned(SubstrateOptions.getPageSize()).newline();
863-
log.string("Containerized: ").bool(isContainerized()).newline();
867+
log.string("Containerized: ").string(Container.singleton().isInitialized() ? String.valueOf(isContainerized()) : "unknown").newline();
864868
log.string("CPU features used for AOT compiled code: ").string(getBuildTimeCpuFeatures()).newline();
865869
log.indent(false);
866870
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/container/Container.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,22 @@ public static Container singleton() {
7474
}
7575

7676
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
77-
public boolean isContainerized() {
78-
return isContainerized(true);
77+
public boolean isInitialized() {
78+
return STATE.get().readWord(0) != State.UNINITIALIZED;
7979
}
8080

8181
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
82-
public boolean isContainerized(boolean allowInit) {
82+
public boolean isContainerized() {
8383
if (!isSupported()) {
8484
return false;
8585
}
8686

8787
UnsignedWord value = STATE.get().readWord(0);
88-
if (allowInit && value == State.UNINITIALIZED) {
88+
if (value == State.UNINITIALIZED) {
8989
value = initialize();
9090
}
9191

92-
assert value == State.CONTAINERIZED || value == State.NOT_CONTAINERIZED || !allowInit;
92+
assert value == State.CONTAINERIZED || value == State.NOT_CONTAINERIZED;
9393
return value == State.CONTAINERIZED;
9494
}
9595

@@ -126,7 +126,7 @@ private static UnsignedWord initialize() {
126126

127127
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
128128
public int getActiveProcessorCount() {
129-
VMError.guarantee(isContainerized(false));
129+
VMError.guarantee(isInitialized() && isContainerized());
130130

131131
long currentMs = System.currentTimeMillis();
132132
if (currentMs > activeProcessorCountTimeoutMs) {
@@ -138,13 +138,13 @@ public int getActiveProcessorCount() {
138138

139139
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
140140
public int getCachedActiveProcessorCount() {
141-
VMError.guarantee(isContainerized(false));
141+
VMError.guarantee(isInitialized() && isContainerized());
142142
return cachedActiveProcessorCount;
143143
}
144144

145145
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
146146
public UnsignedWord getPhysicalMemory() {
147-
VMError.guarantee(isContainerized(false));
147+
VMError.guarantee(isInitialized() && isContainerized());
148148

149149
long currentMs = System.currentTimeMillis();
150150
if (currentMs > physicalMemoryTimeoutMs) {
@@ -156,13 +156,13 @@ public UnsignedWord getPhysicalMemory() {
156156

157157
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
158158
public UnsignedWord getCachedPhysicalMemory() {
159-
VMError.guarantee(isContainerized(false));
159+
VMError.guarantee(isInitialized() && isContainerized());
160160
return cachedPhysicalMemorySize;
161161
}
162162

163163
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
164164
public long getMemoryLimitInBytes() {
165-
VMError.guarantee(isContainerized(false));
165+
VMError.guarantee(isInitialized() && isContainerized());
166166

167167
long currentMs = System.currentTimeMillis();
168168
if (currentMs > memoryLimitInBytesTimeoutMs) {
@@ -174,7 +174,7 @@ public long getMemoryLimitInBytes() {
174174

175175
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
176176
public long getCachedMemoryLimitInBytes() {
177-
VMError.guarantee(isContainerized(false));
177+
VMError.guarantee(isInitialized() && isContainerized());
178178
return cachedMemoryLimitInBytes;
179179
}
180180

0 commit comments

Comments
 (0)