Skip to content

Commit 4b89f78

Browse files
committed
Move registerBuildTimeIndy/CondyIncludeList to the public API
1 parent f35d2ea commit 4b89f78

7 files changed

Lines changed: 158 additions & 61 deletions

File tree

sdk/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
This changelog summarizes major changes between GraalVM SDK versions. The main focus is on APIs exported by GraalVM SDK.
44

5+
## Version 25.4.4
6+
* GR-72910: Added `Feature.DuringSetupAccess#registerBuildTimeBootstrapIndy` and `Feature.DuringSetupAccess#registerBuildTimeBootstrapCondy`, allowing frameworks to register invokedynamic and constant-dynamic bootstrap methods for execution at image build time.
7+
58
## Version 25.3.4
69
* GR-76904: Isolated polyglot contexts now warn when host access is enabled without host method scoping. The warning can be disabled with the `engine.WarnMethodScoping=false` option.
710

sdk/src/org.graalvm.nativeimage/snapshot.sigtest

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,8 @@ CLSS public abstract interface static org.graalvm.nativeimage.hosted.Feature$Dur
10771077
intf org.graalvm.nativeimage.hosted.Feature$FeatureAccess
10781078
meth public abstract <%0 extends java.lang.Object> void registerObjectReachabilityHandler(java.util.function.Consumer<{%%0}>,java.lang.Class<{%%0}>)
10791079
meth public abstract void registerObjectReplacer(java.util.function.Function<java.lang.Object,java.lang.Object>)
1080+
meth public abstract void registerBuildTimeBootstrapIndy(java.lang.reflect.Executable)
1081+
meth public abstract void registerBuildTimeBootstrapCondy(java.lang.reflect.Executable)
10801082

10811083
CLSS public abstract interface static org.graalvm.nativeimage.hosted.Feature$FeatureAccess
10821084
outer org.graalvm.nativeimage.hosted.Feature

sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/hosted/Feature.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@
5454
import org.graalvm.nativeimage.ImageSingletons;
5555
import org.graalvm.nativeimage.Platform;
5656
import org.graalvm.nativeimage.Platforms;
57-
import org.graalvm.nativeimage.dynamicaccess.ResourceAccess;
58-
import org.graalvm.nativeimage.dynamicaccess.ReflectiveAccess;
59-
import org.graalvm.nativeimage.dynamicaccess.JNIAccess;
6057
import org.graalvm.nativeimage.dynamicaccess.ForeignAccess;
58+
import org.graalvm.nativeimage.dynamicaccess.JNIAccess;
59+
import org.graalvm.nativeimage.dynamicaccess.ReflectiveAccess;
60+
import org.graalvm.nativeimage.dynamicaccess.ResourceAccess;
6161

6262
/**
6363
* Features allow clients to intercept the native image generation and run custom initialization
@@ -240,6 +240,26 @@ interface DuringSetupAccess extends FeatureAccess {
240240
* @since 24.2
241241
*/
242242
<T> void registerObjectReachabilityHandler(Consumer<T> callback, Class<T> clazz);
243+
244+
/**
245+
* Registers a method that is allowed to be executed at build time if called as the
246+
* bootstrap method for an invokedynamic, in which case each call site outputted will be
247+
* constant-folded. Other bootstrap methods will be executed at run time by default,
248+
* creating the call site at run time.
249+
*
250+
* @since 25.4
251+
*/
252+
void registerBuildTimeBootstrapIndy(Executable method);
253+
254+
/**
255+
* Registers a method that is allowed to be executed at build time if called as the
256+
* bootstrap method for a constantdynamic, in which case each call site outputted will be
257+
* constant-folded. Other bootstrap methods will be executed at run time by default,
258+
* creating the call site at run time.
259+
*
260+
* @since 25.4
261+
*/
262+
void registerBuildTimeBootstrapCondy(Executable method);
243263
}
244264

245265
/**

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/feature/JVMCIFeatureAccess.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import org.graalvm.nativeimage.Platform;
3535
import org.graalvm.nativeimage.Platforms;
36+
3637
import com.oracle.svm.util.JVMCIFieldValueTransformer;
3738
import com.oracle.svm.util.dynamicaccess.JVMCIJNIAccess;
3839
import com.oracle.svm.util.dynamicaccess.JVMCIReflectiveAccess;
@@ -126,6 +127,18 @@ public interface DuringSetupAccess extends FeatureAccess {
126127
* {@link org.graalvm.nativeimage.hosted.Feature.DuringSetupAccess#registerObjectReachabilityHandler(Consumer, Class)}.
127128
*/
128129
void registerObjectReachabilityHandler(Consumer<JavaConstant> callback, ResolvedJavaType type);
130+
131+
/**
132+
* JVMCI-based counterpart of
133+
* {@link org.graalvm.nativeimage.hosted.Feature.DuringSetupAccess#registerBuildTimeBootstrapIndy(java.lang.reflect.Executable)}.
134+
*/
135+
void registerBuildTimeBootstrapIndy(ResolvedJavaMethod method);
136+
137+
/**
138+
* JVMCI-based counterpart of
139+
* {@link org.graalvm.nativeimage.hosted.Feature.DuringSetupAccess#registerBuildTimeBootstrapCondy(java.lang.reflect.Executable)}.
140+
*/
141+
void registerBuildTimeBootstrapCondy(ResolvedJavaMethod method);
129142
}
130143

131144
/**

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

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import java.util.function.Predicate;
4545
import java.util.stream.Collectors;
4646

47-
import com.oracle.svm.core.image.ImageHeapLayoutInfo;
4847
import org.graalvm.collections.EconomicSet;
4948
import org.graalvm.nativeimage.ImageSingletons;
5049
import org.graalvm.nativeimage.dynamicaccess.AccessCondition;
@@ -80,6 +79,7 @@
8079
import com.oracle.svm.core.feature.InternalFeature;
8180
import com.oracle.svm.core.feature.JVMCIFeatureAccess;
8281
import com.oracle.svm.core.graal.meta.RuntimeConfiguration;
82+
import com.oracle.svm.core.image.ImageHeapLayoutInfo;
8383
import com.oracle.svm.core.meta.SharedField;
8484
import com.oracle.svm.core.meta.SharedMethod;
8585
import com.oracle.svm.core.meta.SharedType;
@@ -105,8 +105,8 @@
105105
import com.oracle.svm.hosted.reflect.ReflectionDataBuilder;
106106
import com.oracle.svm.shared.util.ReflectionUtil;
107107
import com.oracle.svm.shared.util.VMError;
108-
import com.oracle.svm.util.GuestAnnotationAccess;
109108
import com.oracle.svm.util.GuestAccess;
109+
import com.oracle.svm.util.GuestAnnotationAccess;
110110
import com.oracle.svm.util.JVMCIFieldValueTransformer;
111111
import com.oracle.svm.util.OriginalFieldProvider;
112112
import com.oracle.svm.util.dynamicaccess.JVMCIJNIAccess;
@@ -446,6 +446,16 @@ public void registerJVMCIObjectReplacer(Function<JavaConstant, JavaConstant> rep
446446
});
447447
}
448448

449+
@Override
450+
public void registerBuildTimeBootstrapIndy(ResolvedJavaMethod method) {
451+
BootstrapMethodConfiguration.singleton().addBuildTimeIndy(method);
452+
}
453+
454+
@Override
455+
public void registerBuildTimeBootstrapCondy(ResolvedJavaMethod method) {
456+
BootstrapMethodConfiguration.singleton().addBuildTimeCondy(method);
457+
}
458+
449459
/**
450460
* Register an object replacer which may return an ImageHeapConstant. Note only one replacer
451461
* can be triggered for a given object; otherwise an error will be thrown. Too, if the
@@ -515,27 +525,13 @@ public void registerClassReachabilityListener(BiConsumer<DuringAnalysisAccess, C
515525
getHostVM().registerClassReachabilityListener(listener);
516526
}
517527

518-
/**
519-
* Registers a method that is allowed to be executed at build time if called as the
520-
* bootstrap method for an invokedynamic, in which case each call site outputted will be
521-
* constant-folded. Other bootstrap methods will be executed at run time by default,
522-
* creating the call site at run time.
523-
*
524-
* @since 25.1
525-
*/
526-
public void registerBuildTimeIndyIncludeList(Executable method) {
528+
@Override
529+
public void registerBuildTimeBootstrapIndy(Executable method) {
527530
BootstrapMethodConfiguration.singleton().addBuildTimeIndy(getUniverse().getOriginalMetaAccess().lookupJavaMethod(method));
528531
}
529532

530-
/**
531-
* Registers a method that is allowed to be executed at build time if called as the
532-
* bootstrap method for a constantdynamic, in which case each call site outputted will be
533-
* constant-folded. Other bootstrap methods will be executed at run time by default,
534-
* creating the call site at run time.
535-
*
536-
* @since 25.1
537-
*/
538-
public void registerBuildTimeCondyIncludeList(Executable method) {
533+
@Override
534+
public void registerBuildTimeBootstrapCondy(Executable method) {
539535
BootstrapMethodConfiguration.singleton().addBuildTimeCondy(getUniverse().getOriginalMetaAccess().lookupJavaMethod(method));
540536
}
541537

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/bootstrap/BootstrapMethodConfiguration.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@
3838

3939
import org.graalvm.nativeimage.ImageSingletons;
4040

41-
import com.oracle.graal.pointsto.meta.AnalysisMethod;
42-
import com.oracle.svm.shared.feature.AutomaticallyRegisteredFeature;
4341
import com.oracle.svm.core.feature.InternalFeature;
42+
import com.oracle.svm.hosted.reflect.proxy.ProxyRenamingSubstitutionProcessor;
43+
import com.oracle.svm.shared.feature.AutomaticallyRegisteredFeature;
4444
import com.oracle.svm.shared.singletons.traits.BuiltinTraits.BuildtimeAccessOnly;
4545
import com.oracle.svm.shared.singletons.traits.BuiltinTraits.NoLayeredCallbacks;
4646
import com.oracle.svm.shared.singletons.traits.SingletonTraits;
47-
import com.oracle.svm.hosted.reflect.proxy.ProxyRenamingSubstitutionProcessor;
4847
import com.oracle.svm.util.GuestAccess;
4948
import com.oracle.svm.util.JVMCIReflectionUtil;
49+
import com.oracle.svm.util.OriginalMethodProvider;
5050

5151
import jdk.vm.ci.meta.MetaAccessProvider;
5252
import jdk.vm.ci.meta.ResolvedJavaMethod;
@@ -120,37 +120,29 @@ public void duringSetup(DuringSetupAccess access) {
120120
}
121121

122122
public void addBuildTimeIndy(ResolvedJavaMethod method) {
123-
buildTimeIndy.add(method);
123+
buildTimeIndy.add(OriginalMethodProvider.getOriginalMethod(method));
124124
}
125125

126126
public void addBuildTimeCondy(ResolvedJavaMethod method) {
127-
buildTimeCondy.add(method);
127+
buildTimeCondy.add(OriginalMethodProvider.getOriginalMethod(method));
128128
}
129129

130130
/**
131131
* Check if the provided method is allowed to be executed at build time.
132132
*/
133133
public boolean isIndyAllowedAtBuildTime(ResolvedJavaMethod method) {
134-
ResolvedJavaMethod m = getWrapped(method);
134+
ResolvedJavaMethod m = OriginalMethodProvider.getOriginalMethod(method);
135135
return m != null && buildTimeIndy.contains(m);
136136
}
137137

138138
/**
139139
* Check if the provided method is allowed to be executed at build time.
140140
*/
141141
public boolean isCondyAllowedAtBuildTime(ResolvedJavaMethod method) {
142-
ResolvedJavaMethod m = getWrapped(method);
142+
ResolvedJavaMethod m = OriginalMethodProvider.getOriginalMethod(method);
143143
return m != null && (buildTimeCondy.contains(m) || isProxyCondy(m));
144144
}
145145

146-
private static ResolvedJavaMethod getWrapped(ResolvedJavaMethod method) {
147-
if (method instanceof AnalysisMethod analysisMethod) {
148-
return analysisMethod.getWrapped();
149-
} else {
150-
return method;
151-
}
152-
}
153-
154146
/**
155147
* Every {@link Proxy} class has its own bootstrap method that is used for a constant dynamic.
156148
*/

0 commit comments

Comments
 (0)