Skip to content

Commit

Permalink
[GR-62607] Fix JavaMainSupport.mainArgs.
Browse files Browse the repository at this point in the history
PullRequest: graal/20186
  • Loading branch information
cstancu committed Mar 2, 2025
2 parents d8c463e + bacdca4 commit 80fe02a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

import com.oracle.graal.pointsto.BigBang;
import com.oracle.graal.pointsto.api.PointstoOptions;
import com.oracle.graal.pointsto.flow.ContextInsensitiveFieldTypeFlow;
import com.oracle.graal.pointsto.flow.FieldTypeFlow;
Expand Down Expand Up @@ -268,6 +269,15 @@ public boolean registerAsWritten(Object reason) {
});
}

public void injectDeclaredType() {
BigBang bb = getUniverse().getBigbang();
if (getStorageKind().isObject()) {
bb.injectFieldTypes(this, List.of(this.getType()), true);
} else if (bb.trackPrimitiveValues() && getStorageKind().isPrimitive()) {
((PointsToAnalysisField) this).saturatePrimitiveField();
}
}

public boolean isGuaranteeFolded() {
return getAnnotation(GuaranteeFolded.class) != null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.function.BooleanSupplier;

import jdk.graal.compiler.word.Word;
import org.graalvm.nativeimage.CurrentIsolate;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.Isolate;
Expand Down Expand Up @@ -65,10 +65,14 @@
import com.oracle.svm.core.c.function.CEntryPointOptions.NoEpilogue;
import com.oracle.svm.core.c.function.CEntryPointOptions.NoPrologue;
import com.oracle.svm.core.c.function.CEntryPointSetup;
import com.oracle.svm.core.graal.snippets.CEntryPointSnippets;
import com.oracle.svm.core.jdk.InternalVMMethod;
import com.oracle.svm.core.jdk.RuntimeSupport;
import com.oracle.svm.core.jni.JNIJavaVMList;
import com.oracle.svm.core.jni.functions.JNIFunctionTables;
import com.oracle.svm.core.layeredimagesingleton.ApplicationLayerOnlyImageSingleton;
import com.oracle.svm.core.layeredimagesingleton.LayeredImageSingletonBuilderFlags;
import com.oracle.svm.core.layeredimagesingleton.UnsavedSingleton;
import com.oracle.svm.core.log.Log;
import com.oracle.svm.core.thread.JavaThreads;
import com.oracle.svm.core.thread.PlatformThreads;
Expand All @@ -80,6 +84,8 @@
import com.oracle.svm.util.ClassUtil;
import com.oracle.svm.util.ReflectionUtil;

import jdk.graal.compiler.word.Word;

@InternalVMMethod
public class JavaMainWrapper {
/*
Expand All @@ -90,8 +96,12 @@ public class JavaMainWrapper {

private static UnsignedWord argvLength = Word.zero();

public static class JavaMainSupport {

/**
* In a layered build the {@link JavaMainSupport} is installed in the last layer. However, code
* that uses it may be compiled as part of the base layer, e.g., such as
* {@link CEntryPointSnippets}.
*/
public static class JavaMainSupport implements ApplicationLayerOnlyImageSingleton, UnsavedSingleton {
private final MethodHandle javaMainHandle;
private final MethodHandle javaMainClassCtorHandle;
final String javaMainClassName;
Expand Down Expand Up @@ -157,6 +167,10 @@ public List<String> getInputArguments() {
return Collections.emptyList();
}

@Override
public EnumSet<LayeredImageSingletonBuilderFlags> getImageBuilderFlags() {
return LayeredImageSingletonBuilderFlags.ALL_ACCESS;
}
}

public static void invokeMain(String[] args) throws Throwable {
Expand Down Expand Up @@ -189,6 +203,7 @@ public static void invokeMain(String[] args) throws Throwable {
* Determines whether instance main methodes are enabled. See JDK-8306112: Implementation of JEP
* 445: Unnamed Classes and Instance Main Methods (Preview).
*/
@Platforms(Platform.HOSTED_ONLY.class)
public static boolean instanceMainMethodSupported() {
var previewFeature = ReflectionUtil.lookupClass(true, "jdk.internal.misc.PreviewFeatures");
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,6 @@ private void doAddInternal(Class<?> key, Object value) {

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

if (!key.equals(singleton.getClass())) {
throw UserError.abort("The implementation class must be the same as the key class. key: %s, singleton: %s", key, singleton);
}

if (singleton instanceof MultiLayeredImageSingleton && ApplicationLayerOnlyImageSingleton.isSingletonInstanceOf(singleton)) {
throw UserError.abort("Singleton cannot implement both %s and %s. singleton: %s", MultiLayeredImageSingleton.class, ApplicationLayerOnlyImageSingleton.class, singleton);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ void assignSlots(HostedMetaAccess metaAccess) {
int slotAssignment;
LoadImageSingletonDataImpl info = entry.getValue();
var hType = metaAccess.lookupJavaType(info.getLoadType());
if (hType.isInstantiated()) {
if (hType.getWrapped().isAnySubtypeInstantiated()) {
Class<?> keyClass = entry.getKey();
SlotInfo slotInfo = priorKeyToSlotInfoMap.get(entry.getKey());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1157,9 +1157,15 @@ public void initializeBaseLayerField(AnalysisField analysisField) {
if (!analysisField.isStatic() && (isAccessed || isRead)) {
analysisField.getDeclaringClass().getInstanceFields(true);
}
registerFlag(isAccessed, debug -> analysisField.registerAsAccessed(PERSISTED));
registerFlag(isAccessed, debug -> {
analysisField.injectDeclaredType();
analysisField.registerAsAccessed(PERSISTED);
});
registerFlag(isRead, debug -> analysisField.registerAsRead(PERSISTED));
registerFlag(fieldData.getIsWritten(), debug -> analysisField.registerAsWritten(PERSISTED));
registerFlag(fieldData.getIsWritten(), debug -> {
analysisField.injectDeclaredType();
analysisField.registerAsWritten(PERSISTED);
});
registerFlag(fieldData.getIsFolded(), debug -> analysisField.registerAsFolded(PERSISTED));
}

Expand Down

0 comments on commit 80fe02a

Please sign in to comment.