Skip to content

Commit 5f7626d

Browse files
committed
Make pod support conditional on Serial GC (including Epsilon GC).
1 parent 8735a9d commit 5f7626d

File tree

6 files changed

+47
-13
lines changed

6 files changed

+47
-13
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/jdk/SubstrateObjectCloneSnippets.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import com.oracle.svm.core.graal.snippets.NodeLoweringProvider;
6363
import com.oracle.svm.core.graal.snippets.SubstrateTemplates;
6464
import com.oracle.svm.core.heap.InstanceReferenceMapEncoder;
65+
import com.oracle.svm.core.heap.Pod;
6566
import com.oracle.svm.core.heap.PodReferenceMapDecoder;
6667
import com.oracle.svm.core.hub.DynamicHub;
6768
import com.oracle.svm.core.hub.DynamicHubSupport;
@@ -110,7 +111,7 @@ private static Object doClone(Object original) throws CloneNotSupportedException
110111
}
111112
return newArray;
112113

113-
} else if (hub.isPodInstanceClass()) {
114+
} else if (Pod.RuntimeSupport.isPresent() && hub.isPodInstanceClass()) {
114115
result = PodReferenceMapDecoder.clone(original, hub, layoutEncoding);
115116

116117
} else {

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/Pod.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.util.function.Supplier;
3939

4040
import org.graalvm.collections.EconomicMap;
41+
import org.graalvm.compiler.api.replacements.Fold;
4142
import org.graalvm.nativeimage.ImageSingletons;
4243
import org.graalvm.nativeimage.Platform;
4344
import org.graalvm.nativeimage.Platforms;
@@ -124,11 +125,14 @@ public static <T> Builder<T> createExtending(Class<?> superClass, Class<T> facto
124125

125126
private Builder(Class<?> superClass, Class<?> factoryInterface, Pod<T> superPod) {
126127
assert superPod == null || (superClass == null && factoryInterface == null);
128+
if (!RuntimeSupport.isPresent()) {
129+
throw new UnsupportedOperationException("Pods are not available in this native image. Only SerialGC currently supports pods.");
130+
}
127131
if (superPod != null) {
128132
this.podInfo = superPod.podInfo;
129133
} else if (superClass != null && factoryInterface != null) {
130134
RuntimeSupport.PodSpec spec = new RuntimeSupport.PodSpec(superClass, factoryInterface);
131-
this.podInfo = ImageSingletons.lookup(RuntimeSupport.class).getInfo(spec);
135+
this.podInfo = RuntimeSupport.singleton().getInfo(spec);
132136
if (this.podInfo == null) {
133137
throw new IllegalArgumentException("Pod superclass/factory interface pair was not registered during image build: " + superClass + ", " + factoryInterface);
134138
}
@@ -256,6 +260,16 @@ public int compareTo(Field f) {
256260
}
257261

258262
public static final class RuntimeSupport {
263+
@Fold
264+
public static boolean isPresent() {
265+
return ImageSingletons.contains(RuntimeSupport.class);
266+
}
267+
268+
@Fold
269+
public static RuntimeSupport singleton() {
270+
return ImageSingletons.lookup(RuntimeSupport.class);
271+
}
272+
259273
@Retention(RetentionPolicy.RUNTIME)
260274
@Target(ElementType.TYPE)
261275
public @interface PodFactory {

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/InteriorObjRefWalker.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.oracle.svm.core.heap.InstanceReferenceMapDecoder;
3737
import com.oracle.svm.core.heap.ObjectHeader;
3838
import com.oracle.svm.core.heap.ObjectReferenceVisitor;
39+
import com.oracle.svm.core.heap.Pod;
3940
import com.oracle.svm.core.heap.PodReferenceMapDecoder;
4041
import com.oracle.svm.core.heap.ReferenceAccess;
4142

@@ -80,7 +81,7 @@ public static boolean walkObjectInline(final Object obj, final ObjectReferenceVi
8081
}
8182
pos = pos.add(referenceSize);
8283
}
83-
} else if (objHub.isPodInstanceClass()) {
84+
} else if (Pod.RuntimeSupport.isPresent() && objHub.isPodInstanceClass()) {
8485
if (!PodReferenceMapDecoder.walkOffsetsFromPointer(objPointer, layoutEncoding, visitor, obj)) {
8586
return false;
8687
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ private static HubType computeHubType(AnalysisType type) {
462462
} else if (type.isInstanceClass()) {
463463
if (Reference.class.isAssignableFrom(type.getJavaClass())) {
464464
return HubType.InstanceReference;
465-
} else if (PodSupport.singleton().isPodClass(type.getJavaClass())) {
465+
} else if (PodSupport.isPresent() && PodSupport.singleton().isPodClass(type.getJavaClass())) {
466466
return HubType.PodInstance;
467467
}
468468
assert !Target_java_lang_ref_Reference.class.isAssignableFrom(type.getJavaClass()) : "should not see substitution type here";

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/heap/PodSupport.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.graalvm.nativeimage.ImageSingletons;
4949
import org.graalvm.nativeimage.hosted.Feature;
5050

51+
import com.oracle.svm.core.SubstrateOptions;
5152
import com.oracle.svm.core.annotate.AutomaticFeature;
5253
import com.oracle.svm.core.annotate.DeoptTest;
5354
import com.oracle.svm.core.annotate.Hybrid;
@@ -67,7 +68,14 @@
6768

6869
/** Support for preparing the creation of {@link Pod} objects during the image build. */
6970
public interface PodSupport {
71+
static boolean isPresent() {
72+
return ImageSingletons.contains(PodSupport.class);
73+
}
74+
7075
static PodSupport singleton() {
76+
if (!ImageSingletons.contains(PodSupport.class)) {
77+
throw UserError.abort("Pods are not available in this native image build. Only SerialGC currently supports pods.");
78+
}
7179
return ImageSingletons.lookup(PodSupport.class);
7280
}
7381

@@ -107,6 +115,11 @@ final class PodFeature implements PodSupport, Feature {
107115
private volatile boolean instantiated = false;
108116
private boolean sealed = false;
109117

118+
@Override
119+
public boolean isInConfiguration(IsInConfigurationAccess access) {
120+
return SubstrateOptions.UseSerialGC.getValue();
121+
}
122+
110123
@Override
111124
public void afterRegistration(AfterRegistrationAccess access) {
112125
ImageSingletons.add(PodSupport.class, this);
@@ -133,11 +146,7 @@ private void registerAsInstantiated(DuringAnalysisAccess access) {
133146

134147
private static void registerPodAsInstantiated(BeforeAnalysisAccess access, PodSpec spec, PodInfo info) {
135148
access.registerAsInHeap(info.podClass);
136-
runtimeSupport().registerPod(spec, info);
137-
}
138-
139-
private static Pod.RuntimeSupport runtimeSupport() {
140-
return ImageSingletons.lookup(Pod.RuntimeSupport.class);
149+
Pod.RuntimeSupport.singleton().registerPod(spec, info);
141150
}
142151

143152
@Override

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/UniverseBuilder.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,18 @@ private void layoutInstanceFields() {
401401
layoutInstanceFields(hUniverse.getObjectClass(), ConfigurationValues.getObjectLayout().getFirstFieldOffset(), new HostedField[0]);
402402
}
403403

404+
private static boolean mustReserveLengthField(HostedInstanceClass clazz) {
405+
if (PodSupport.isPresent() && PodSupport.singleton().mustReserveLengthField(clazz.getJavaClass())) {
406+
return true;
407+
}
408+
if (HybridLayout.isHybrid(clazz)) {
409+
// A pod ancestor subclassing Object must have already reserved a length field, unless
410+
// the pod subclasses Object itself, in which case we would have returned true earlier.
411+
return !PodSupport.isPresent() || !PodSupport.singleton().isPodClass(clazz.getJavaClass());
412+
}
413+
return false;
414+
}
415+
404416
private void layoutInstanceFields(HostedInstanceClass clazz, int superSize, HostedField[] superFields) {
405417
ArrayList<HostedField> rawFields = new ArrayList<>();
406418
ArrayList<HostedField> orderedFields = new ArrayList<>();
@@ -414,10 +426,7 @@ private void layoutInstanceFields(HostedInstanceClass clazz, int superSize, Host
414426
startSize = DeoptimizedFrame.getScratchSpaceOffset() + layout.getDeoptScratchSpace();
415427
}
416428

417-
PodSupport pods = PodSupport.singleton();
418-
if ((HybridLayout.isHybrid(clazz) && !pods.isPodClass(clazz.getJavaClass())) || pods.mustReserveLengthField(clazz.getJavaClass())) {
419-
// Reserve space for the array length field. For pods, the ancestor subclassing Object
420-
// must have already reserved this space (unless the pod subclasses Object itself).
429+
if (mustReserveLengthField(clazz)) {
421430
VMError.guarantee(startSize == layout.getArrayLengthOffset());
422431
int fieldSize = layout.sizeInBytes(JavaKind.Int);
423432
startSize += fieldSize;

0 commit comments

Comments
 (0)