Skip to content

Commit 80fe02a

Browse files
committed
[GR-62607] Fix JavaMainSupport.mainArgs.
PullRequest: graal/20186
2 parents d8c463e + bacdca4 commit 80fe02a

File tree

5 files changed

+37
-10
lines changed

5 files changed

+37
-10
lines changed

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisField.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.concurrent.ConcurrentMap;
3232
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
3333

34+
import com.oracle.graal.pointsto.BigBang;
3435
import com.oracle.graal.pointsto.api.PointstoOptions;
3536
import com.oracle.graal.pointsto.flow.ContextInsensitiveFieldTypeFlow;
3637
import com.oracle.graal.pointsto.flow.FieldTypeFlow;
@@ -268,6 +269,15 @@ public boolean registerAsWritten(Object reason) {
268269
});
269270
}
270271

272+
public void injectDeclaredType() {
273+
BigBang bb = getUniverse().getBigbang();
274+
if (getStorageKind().isObject()) {
275+
bb.injectFieldTypes(this, List.of(this.getType()), true);
276+
} else if (bb.trackPrimitiveValues() && getStorageKind().isPrimitive()) {
277+
((PointsToAnalysisField) this).saturatePrimitiveField();
278+
}
279+
}
280+
271281
public boolean isGuaranteeFolded() {
272282
return getAnnotation(GuaranteeFolded.class) != null;
273283
}

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
import java.util.ArrayList;
3333
import java.util.Arrays;
3434
import java.util.Collections;
35+
import java.util.EnumSet;
3536
import java.util.List;
3637
import java.util.function.BooleanSupplier;
3738

38-
import jdk.graal.compiler.word.Word;
3939
import org.graalvm.nativeimage.CurrentIsolate;
4040
import org.graalvm.nativeimage.ImageSingletons;
4141
import org.graalvm.nativeimage.Isolate;
@@ -65,10 +65,14 @@
6565
import com.oracle.svm.core.c.function.CEntryPointOptions.NoEpilogue;
6666
import com.oracle.svm.core.c.function.CEntryPointOptions.NoPrologue;
6767
import com.oracle.svm.core.c.function.CEntryPointSetup;
68+
import com.oracle.svm.core.graal.snippets.CEntryPointSnippets;
6869
import com.oracle.svm.core.jdk.InternalVMMethod;
6970
import com.oracle.svm.core.jdk.RuntimeSupport;
7071
import com.oracle.svm.core.jni.JNIJavaVMList;
7172
import com.oracle.svm.core.jni.functions.JNIFunctionTables;
73+
import com.oracle.svm.core.layeredimagesingleton.ApplicationLayerOnlyImageSingleton;
74+
import com.oracle.svm.core.layeredimagesingleton.LayeredImageSingletonBuilderFlags;
75+
import com.oracle.svm.core.layeredimagesingleton.UnsavedSingleton;
7276
import com.oracle.svm.core.log.Log;
7377
import com.oracle.svm.core.thread.JavaThreads;
7478
import com.oracle.svm.core.thread.PlatformThreads;
@@ -80,6 +84,8 @@
8084
import com.oracle.svm.util.ClassUtil;
8185
import com.oracle.svm.util.ReflectionUtil;
8286

87+
import jdk.graal.compiler.word.Word;
88+
8389
@InternalVMMethod
8490
public class JavaMainWrapper {
8591
/*
@@ -90,8 +96,12 @@ public class JavaMainWrapper {
9096

9197
private static UnsignedWord argvLength = Word.zero();
9298

93-
public static class JavaMainSupport {
94-
99+
/**
100+
* In a layered build the {@link JavaMainSupport} is installed in the last layer. However, code
101+
* that uses it may be compiled as part of the base layer, e.g., such as
102+
* {@link CEntryPointSnippets}.
103+
*/
104+
public static class JavaMainSupport implements ApplicationLayerOnlyImageSingleton, UnsavedSingleton {
95105
private final MethodHandle javaMainHandle;
96106
private final MethodHandle javaMainClassCtorHandle;
97107
final String javaMainClassName;
@@ -157,6 +167,10 @@ public List<String> getInputArguments() {
157167
return Collections.emptyList();
158168
}
159169

170+
@Override
171+
public EnumSet<LayeredImageSingletonBuilderFlags> getImageBuilderFlags() {
172+
return LayeredImageSingletonBuilderFlags.ALL_ACCESS;
173+
}
160174
}
161175

162176
public static void invokeMain(String[] args) throws Throwable {
@@ -189,6 +203,7 @@ public static void invokeMain(String[] args) throws Throwable {
189203
* Determines whether instance main methodes are enabled. See JDK-8306112: Implementation of JEP
190204
* 445: Unnamed Classes and Instance Main Methods (Preview).
191205
*/
206+
@Platforms(Platform.HOSTED_ONLY.class)
192207
public static boolean instanceMainMethodSupported() {
193208
var previewFeature = ReflectionUtil.lookupClass(true, "jdk.internal.misc.PreviewFeatures");
194209
try {

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,6 @@ private void doAddInternal(Class<?> key, Object value) {
228228

229229
if (singleton instanceof MultiLayeredImageSingleton || ApplicationLayerOnlyImageSingleton.isSingletonInstanceOf(singleton)) {
230230

231-
if (!key.equals(singleton.getClass())) {
232-
throw UserError.abort("The implementation class must be the same as the key class. key: %s, singleton: %s", key, singleton);
233-
}
234-
235231
if (singleton instanceof MultiLayeredImageSingleton && ApplicationLayerOnlyImageSingleton.isSingletonInstanceOf(singleton)) {
236232
throw UserError.abort("Singleton cannot implement both %s and %s. singleton: %s", MultiLayeredImageSingleton.class, ApplicationLayerOnlyImageSingleton.class, singleton);
237233
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/LoadImageSingletonFeature.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ void assignSlots(HostedMetaAccess metaAccess) {
580580
int slotAssignment;
581581
LoadImageSingletonDataImpl info = entry.getValue();
582582
var hType = metaAccess.lookupJavaType(info.getLoadType());
583-
if (hType.isInstantiated()) {
583+
if (hType.getWrapped().isAnySubtypeInstantiated()) {
584584
Class<?> keyClass = entry.getKey();
585585
SlotInfo slotInfo = priorKeyToSlotInfoMap.get(entry.getKey());
586586

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/SVMImageLayerLoader.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,9 +1157,15 @@ public void initializeBaseLayerField(AnalysisField analysisField) {
11571157
if (!analysisField.isStatic() && (isAccessed || isRead)) {
11581158
analysisField.getDeclaringClass().getInstanceFields(true);
11591159
}
1160-
registerFlag(isAccessed, debug -> analysisField.registerAsAccessed(PERSISTED));
1160+
registerFlag(isAccessed, debug -> {
1161+
analysisField.injectDeclaredType();
1162+
analysisField.registerAsAccessed(PERSISTED);
1163+
});
11611164
registerFlag(isRead, debug -> analysisField.registerAsRead(PERSISTED));
1162-
registerFlag(fieldData.getIsWritten(), debug -> analysisField.registerAsWritten(PERSISTED));
1165+
registerFlag(fieldData.getIsWritten(), debug -> {
1166+
analysisField.injectDeclaredType();
1167+
analysisField.registerAsWritten(PERSISTED);
1168+
});
11631169
registerFlag(fieldData.getIsFolded(), debug -> analysisField.registerAsFolded(PERSISTED));
11641170
}
11651171

0 commit comments

Comments
 (0)