Skip to content

Commit 3628b1a

Browse files
committed
Move registerBuildTimeIndy/CondyIncludeList to the public API
1 parent f35d2ea commit 3628b1a

6 files changed

Lines changed: 71 additions & 41 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#registerBuildTimeIndyIncludeList` and `Feature.DuringSetupAccess#registerBuildTimeCondyIncludeList`, 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 registerBuildTimeIndyIncludeList(java.lang.reflect.Executable)
1081+
meth public abstract void registerBuildTimeCondyIncludeList(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 registerBuildTimeIndyIncludeList(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 registerBuildTimeCondyIncludeList(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#registerBuildTimeIndyIncludeList(java.lang.reflect.Executable)}.
134+
*/
135+
void registerBuildTimeIndyIncludeList(ResolvedJavaMethod method);
136+
137+
/**
138+
* JVMCI-based counterpart of
139+
* {@link org.graalvm.nativeimage.hosted.Feature.DuringSetupAccess#registerBuildTimeCondyIncludeList(java.lang.reflect.Executable)}.
140+
*/
141+
void registerBuildTimeCondyIncludeList(ResolvedJavaMethod method);
129142
}
130143

131144
/**

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

Lines changed: 14 additions & 18 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 registerBuildTimeIndyIncludeList(ResolvedJavaMethod method) {
451+
BootstrapMethodConfiguration.singleton().addBuildTimeIndy(method);
452+
}
453+
454+
@Override
455+
public void registerBuildTimeCondyIncludeList(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,26 +525,12 @@ 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-
*/
528+
@Override
526529
public void registerBuildTimeIndyIncludeList(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-
*/
533+
@Override
538534
public void registerBuildTimeCondyIncludeList(Executable method) {
539535
BootstrapMethodConfiguration.singleton().addBuildTimeCondy(getUniverse().getOriginalMetaAccess().lookupJavaMethod(method));
540536
}

substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/BootstrapMethodTest.java

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@
2525
*/
2626
package com.oracle.svm.test;
2727

28+
import static java.lang.constant.ConstantDescs.CD_CallSite;
29+
import static java.lang.constant.ConstantDescs.CD_Class;
30+
import static java.lang.constant.ConstantDescs.CD_MethodHandles_Lookup;
31+
import static java.lang.constant.ConstantDescs.CD_MethodType;
32+
import static java.lang.constant.ConstantDescs.CD_Object;
33+
import static java.lang.constant.ConstantDescs.CD_String;
34+
35+
import java.lang.classfile.ClassFile;
36+
import java.lang.constant.ClassDesc;
37+
import java.lang.constant.DirectMethodHandleDesc;
38+
import java.lang.constant.DynamicCallSiteDesc;
39+
import java.lang.constant.DynamicConstantDesc;
40+
import java.lang.constant.MethodHandleDesc;
41+
import java.lang.constant.MethodTypeDesc;
2842
import java.lang.invoke.CallSite;
2943
import java.lang.invoke.ConstantCallSite;
3044
import java.lang.invoke.MethodHandle;
@@ -40,23 +54,6 @@
4054
import org.junit.Assume;
4155
import org.junit.Test;
4256

43-
import java.lang.classfile.ClassFile;
44-
import java.lang.constant.ClassDesc;
45-
import java.lang.constant.DirectMethodHandleDesc;
46-
import java.lang.constant.DynamicCallSiteDesc;
47-
import java.lang.constant.DynamicConstantDesc;
48-
import java.lang.constant.MethodHandleDesc;
49-
import java.lang.constant.MethodTypeDesc;
50-
51-
import com.oracle.svm.hosted.FeatureImpl;
52-
53-
import static java.lang.constant.ConstantDescs.CD_CallSite;
54-
import static java.lang.constant.ConstantDescs.CD_Class;
55-
import static java.lang.constant.ConstantDescs.CD_MethodHandles_Lookup;
56-
import static java.lang.constant.ConstantDescs.CD_MethodType;
57-
import static java.lang.constant.ConstantDescs.CD_Object;
58-
import static java.lang.constant.ConstantDescs.CD_String;
59-
6057
/**
6158
* Tests the {@code registerBuildTimeIndyIncludeList} and {@code registerBuildTimeCondyIncludeList}
6259
* APIs by generating a class with ASM that uses custom bootstrap methods for invokedynamic and
@@ -114,9 +111,8 @@ public void duringSetup(DuringSetupAccess access) {
114111
Method condyBsm = BootstrapMethodTest.class.getDeclaredMethod("myCondyBootstrap",
115112
MethodHandles.Lookup.class, String.class, Class.class);
116113

117-
FeatureImpl.DuringSetupAccessImpl impl = (FeatureImpl.DuringSetupAccessImpl) access;
118-
impl.registerBuildTimeIndyIncludeList(indyBsm);
119-
impl.registerBuildTimeCondyIncludeList(condyBsm);
114+
access.registerBuildTimeIndyIncludeList(indyBsm);
115+
access.registerBuildTimeCondyIncludeList(condyBsm);
120116
} catch (NoSuchMethodException e) {
121117
throw new RuntimeException(e);
122118
}

0 commit comments

Comments
 (0)