Skip to content

Commit d63d66f

Browse files
author
mihailo
committed
Introduced public API for registration conditions.
ConfigurationCondition is divided into InclusionCondition(API) and TypeCondition(implementation). Replaced all usages of ConfigurationCondition.
1 parent 73a626e commit d63d66f

File tree

53 files changed

+522
-443
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+522
-443
lines changed

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

+4
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,10 @@ CLSS public abstract interface org.graalvm.nativeimage.hosted.FieldValueTransfor
10821082
meth public abstract java.lang.Object transform(java.lang.Object,java.lang.Object)
10831083
meth public boolean isAvailable()
10841084

1085+
CLSS public abstract interface org.graalvm.nativeimage.hosted.InclusionCondition
1086+
meth public static org.graalvm.nativeimage.hosted.InclusionCondition alwaysInclude()
1087+
meth public static org.graalvm.nativeimage.hosted.InclusionCondition typeReached(java.lang.Class<?>)
1088+
10851089
CLSS public final org.graalvm.nativeimage.hosted.RuntimeClassInitialization
10861090
meth public !varargs static void initializeAtBuildTime(java.lang.Class<?>[])
10871091
meth public !varargs static void initializeAtBuildTime(java.lang.String[])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package org.graalvm.nativeimage.hosted;
42+
43+
import org.graalvm.nativeimage.impl.TypeCondition;
44+
45+
/**
46+
* Condition that must be satisfied for inclusion of elements for dynamic access (e.g., runtime
47+
* reflection, serialization, JNI access, and resource access at runtime).
48+
* {@link InclusionCondition} is used together with {@link Feature} for programmatic registration of
49+
* metadata.
50+
* <p>
51+
* Currently, there is only one type of condition: {@link #typeReached} that signifies that the type
52+
* must be both reachable by static analysis at build time, and reached at run time. A type is
53+
* reached at run time, right before the class-initialization routine starts for that type, or any
54+
* of the type's subtypes are reached.
55+
* </p>
56+
*
57+
* Conditions can be created via {@link #alwaysInclude} and {@link #typeReached} factory methods.
58+
*/
59+
public interface InclusionCondition {
60+
61+
/**
62+
* Creates the type-reached condition that is always satisfied. Any element that is predicated
63+
* with this condition will always be included.
64+
*
65+
* @return instance of the condition
66+
*/
67+
static InclusionCondition alwaysInclude() {
68+
return TypeCondition.JAVA_LANG_OBJECT_REACHED;
69+
}
70+
71+
/**
72+
* Creates the default type-reached condition that is satisfied when the type is reached at
73+
* runtime.
74+
*
75+
* @param type that has to be reached for this condition to be satisfied
76+
* @return instance of the condition
77+
*/
78+
static InclusionCondition typeReached(Class<?> type) {
79+
return TypeCondition.create(type, true);
80+
}
81+
}

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

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -46,7 +46,6 @@
4646
import org.graalvm.nativeimage.ImageSingletons;
4747
import org.graalvm.nativeimage.Platform;
4848
import org.graalvm.nativeimage.Platforms;
49-
import org.graalvm.nativeimage.impl.ConfigurationCondition;
5049
import org.graalvm.nativeimage.impl.RuntimeForeignAccessSupport;
5150

5251
@Platforms(Platform.HOSTED_ONLY.class)
@@ -68,7 +67,7 @@ public final class RuntimeForeignAccess {
6867
* @since 23.1
6968
*/
7069
public static void registerForDowncall(Object desc, Object... options) {
71-
ImageSingletons.lookup(RuntimeForeignAccessSupport.class).registerForDowncall(ConfigurationCondition.alwaysTrue(), desc, options);
70+
ImageSingletons.lookup(RuntimeForeignAccessSupport.class).registerForDowncall(InclusionCondition.alwaysInclude(), desc, options);
7271
}
7372

7473
/**
@@ -86,7 +85,7 @@ public static void registerForDowncall(Object desc, Object... options) {
8685
* @since 24.1
8786
*/
8887
public static void registerForUpcall(Object desc, Object... options) {
89-
ImageSingletons.lookup(RuntimeForeignAccessSupport.class).registerForUpcall(ConfigurationCondition.alwaysTrue(), desc, options);
88+
ImageSingletons.lookup(RuntimeForeignAccessSupport.class).registerForUpcall(InclusionCondition.alwaysInclude(), desc, options);
9089
}
9190

9291
/**
@@ -114,7 +113,7 @@ public static void registerForUpcall(Object desc, Object... options) {
114113
* @since 24.2
115114
*/
116115
public static void registerForDirectUpcall(MethodHandle target, Object desc, Object... options) {
117-
ImageSingletons.lookup(RuntimeForeignAccessSupport.class).registerForDirectUpcall(ConfigurationCondition.alwaysTrue(), target, desc, options);
116+
ImageSingletons.lookup(RuntimeForeignAccessSupport.class).registerForDirectUpcall(InclusionCondition.alwaysInclude(), target, desc, options);
118117
}
119118

120119
private RuntimeForeignAccess() {

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

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -46,7 +46,6 @@
4646
import org.graalvm.nativeimage.ImageSingletons;
4747
import org.graalvm.nativeimage.Platform;
4848
import org.graalvm.nativeimage.Platforms;
49-
import org.graalvm.nativeimage.impl.ConfigurationCondition;
5049
import org.graalvm.nativeimage.impl.RuntimeJNIAccessSupport;
5150

5251
/**
@@ -66,7 +65,7 @@ public final class RuntimeJNIAccess {
6665
* @since 22.3
6766
*/
6867
public static void register(Class<?>... classes) {
69-
ImageSingletons.lookup(RuntimeJNIAccessSupport.class).register(ConfigurationCondition.alwaysTrue(), classes);
68+
ImageSingletons.lookup(RuntimeJNIAccessSupport.class).register(InclusionCondition.alwaysInclude(), classes);
7069
}
7170

7271
/**
@@ -79,7 +78,7 @@ public static void register(Class<?>... classes) {
7978
* @since 22.3
8079
*/
8180
public static void register(Executable... methods) {
82-
ImageSingletons.lookup(RuntimeJNIAccessSupport.class).register(ConfigurationCondition.alwaysTrue(), false, methods);
81+
ImageSingletons.lookup(RuntimeJNIAccessSupport.class).register(InclusionCondition.alwaysInclude(), false, methods);
8382
}
8483

8584
/**
@@ -92,7 +91,7 @@ public static void register(Executable... methods) {
9291
* @since 22.3
9392
*/
9493
public static void register(Field... fields) {
95-
ImageSingletons.lookup(RuntimeJNIAccessSupport.class).register(ConfigurationCondition.alwaysTrue(), false, fields);
94+
ImageSingletons.lookup(RuntimeJNIAccessSupport.class).register(InclusionCondition.alwaysInclude(), false, fields);
9695
}
9796

9897
private RuntimeJNIAccess() {

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -43,7 +43,6 @@
4343
import org.graalvm.nativeimage.ImageSingletons;
4444
import org.graalvm.nativeimage.Platform;
4545
import org.graalvm.nativeimage.Platforms;
46-
import org.graalvm.nativeimage.impl.ConfigurationCondition;
4746
import org.graalvm.nativeimage.impl.RuntimeProxyCreationSupport;
4847

4948
/**
@@ -62,7 +61,7 @@ public final class RuntimeProxyCreation {
6261
* @since 22.3
6362
*/
6463
public static void register(Class<?>... interfaces) {
65-
ImageSingletons.lookup(RuntimeProxyCreationSupport.class).addProxyClass(ConfigurationCondition.alwaysTrue(), interfaces);
64+
ImageSingletons.lookup(RuntimeProxyCreationSupport.class).addProxyClass(InclusionCondition.alwaysInclude(), interfaces);
6665
}
6766

6867
private RuntimeProxyCreation() {

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

+20-21
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import org.graalvm.nativeimage.ImageSingletons;
4949
import org.graalvm.nativeimage.Platform;
5050
import org.graalvm.nativeimage.Platforms;
51-
import org.graalvm.nativeimage.impl.ConfigurationCondition;
5251
import org.graalvm.nativeimage.impl.RuntimeReflectionSupport;
5352

5453
//Checkstyle: allow reflection
@@ -69,7 +68,7 @@ public final class RuntimeReflection {
6968
* @since 19.0
7069
*/
7170
public static void register(Class<?>... classes) {
72-
ImageSingletons.lookup(RuntimeReflectionSupport.class).register(ConfigurationCondition.alwaysTrue(), classes);
71+
ImageSingletons.lookup(RuntimeReflectionSupport.class).register(InclusionCondition.alwaysInclude(), classes);
7372
}
7473

7574
/**
@@ -80,7 +79,7 @@ public static void register(Class<?>... classes) {
8079
* @since 23.0
8180
*/
8281
public static void registerClassLookup(String className) {
83-
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerClassLookup(ConfigurationCondition.alwaysTrue(), className);
82+
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerClassLookup(InclusionCondition.alwaysInclude(), className);
8483
}
8584

8685
/**
@@ -91,7 +90,7 @@ public static void registerClassLookup(String className) {
9190
* @since 19.0
9291
*/
9392
public static void register(Executable... methods) {
94-
ImageSingletons.lookup(RuntimeReflectionSupport.class).register(ConfigurationCondition.alwaysTrue(), false, methods);
93+
ImageSingletons.lookup(RuntimeReflectionSupport.class).register(InclusionCondition.alwaysInclude(), false, methods);
9594
}
9695

9796
/**
@@ -103,7 +102,7 @@ public static void register(Executable... methods) {
103102
* @since 21.3
104103
*/
105104
public static void registerAsQueried(Executable... methods) {
106-
ImageSingletons.lookup(RuntimeReflectionSupport.class).register(ConfigurationCondition.alwaysTrue(), true, methods);
105+
ImageSingletons.lookup(RuntimeReflectionSupport.class).register(InclusionCondition.alwaysInclude(), true, methods);
107106
}
108107

109108
/**
@@ -116,7 +115,7 @@ public static void registerAsQueried(Executable... methods) {
116115
* @since 23.0
117116
*/
118117
public static void registerMethodLookup(Class<?> declaringClass, String methodName, Class<?>... parameterTypes) {
119-
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerMethodLookup(ConfigurationCondition.alwaysTrue(), declaringClass, methodName, parameterTypes);
118+
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerMethodLookup(InclusionCondition.alwaysInclude(), declaringClass, methodName, parameterTypes);
120119
}
121120

122121
/**
@@ -130,7 +129,7 @@ public static void registerMethodLookup(Class<?> declaringClass, String methodNa
130129
* @since 23.0
131130
*/
132131
public static void registerConstructorLookup(Class<?> declaringClass, Class<?>... parameterTypes) {
133-
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerConstructorLookup(ConfigurationCondition.alwaysTrue(), declaringClass, parameterTypes);
132+
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerConstructorLookup(InclusionCondition.alwaysInclude(), declaringClass, parameterTypes);
134133
}
135134

136135
/**
@@ -141,7 +140,7 @@ public static void registerConstructorLookup(Class<?> declaringClass, Class<?>..
141140
* @since 19.0
142141
*/
143142
public static void register(Field... fields) {
144-
ImageSingletons.lookup(RuntimeReflectionSupport.class).register(ConfigurationCondition.alwaysTrue(), false, fields);
143+
ImageSingletons.lookup(RuntimeReflectionSupport.class).register(InclusionCondition.alwaysInclude(), false, fields);
145144
}
146145

147146
/**
@@ -153,7 +152,7 @@ public static void register(Field... fields) {
153152
* @since 19.0
154153
*/
155154
public static void registerFieldLookup(Class<?> declaringClass, String fieldName) {
156-
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerFieldLookup(ConfigurationCondition.alwaysTrue(), declaringClass, fieldName);
155+
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerFieldLookup(InclusionCondition.alwaysInclude(), declaringClass, fieldName);
157156
}
158157

159158
/**
@@ -162,7 +161,7 @@ public static void registerFieldLookup(Class<?> declaringClass, String fieldName
162161
* @since 23.0
163162
*/
164163
public static void registerAllClasses(Class<?> declaringClass) {
165-
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllClassesQuery(ConfigurationCondition.alwaysTrue(), declaringClass);
164+
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllClassesQuery(InclusionCondition.alwaysInclude(), declaringClass);
166165
}
167166

168167
/**
@@ -171,7 +170,7 @@ public static void registerAllClasses(Class<?> declaringClass) {
171170
* @since 23.0
172171
*/
173172
public static void registerAllDeclaredClasses(Class<?> declaringClass) {
174-
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllDeclaredClassesQuery(ConfigurationCondition.alwaysTrue(), declaringClass);
173+
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllDeclaredClassesQuery(InclusionCondition.alwaysInclude(), declaringClass);
175174
}
176175

177176
/**
@@ -181,7 +180,7 @@ public static void registerAllDeclaredClasses(Class<?> declaringClass) {
181180
* @since 23.0
182181
*/
183182
public static void registerAllMethods(Class<?> declaringClass) {
184-
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllMethodsQuery(ConfigurationCondition.alwaysTrue(), true, declaringClass);
183+
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllMethodsQuery(InclusionCondition.alwaysInclude(), true, declaringClass);
185184
}
186185

187186
/**
@@ -191,7 +190,7 @@ public static void registerAllMethods(Class<?> declaringClass) {
191190
* @since 23.0
192191
*/
193192
public static void registerAllDeclaredMethods(Class<?> declaringClass) {
194-
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllDeclaredMethodsQuery(ConfigurationCondition.alwaysTrue(), true, declaringClass);
193+
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllDeclaredMethodsQuery(InclusionCondition.alwaysInclude(), true, declaringClass);
195194
}
196195

197196
/**
@@ -201,7 +200,7 @@ public static void registerAllDeclaredMethods(Class<?> declaringClass) {
201200
* @since 23.0
202201
*/
203202
public static void registerAllConstructors(Class<?> declaringClass) {
204-
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllConstructorsQuery(ConfigurationCondition.alwaysTrue(), true, declaringClass);
203+
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllConstructorsQuery(InclusionCondition.alwaysInclude(), true, declaringClass);
205204
}
206205

207206
/**
@@ -211,7 +210,7 @@ public static void registerAllConstructors(Class<?> declaringClass) {
211210
* @since 23.0
212211
*/
213212
public static void registerAllDeclaredConstructors(Class<?> declaringClass) {
214-
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllDeclaredConstructorsQuery(ConfigurationCondition.alwaysTrue(), true, declaringClass);
213+
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllDeclaredConstructorsQuery(InclusionCondition.alwaysInclude(), true, declaringClass);
215214
}
216215

217216
/**
@@ -221,7 +220,7 @@ public static void registerAllDeclaredConstructors(Class<?> declaringClass) {
221220
* @since 23.0
222221
*/
223222
public static void registerAllFields(Class<?> declaringClass) {
224-
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllFields(ConfigurationCondition.alwaysTrue(), declaringClass);
223+
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllFields(InclusionCondition.alwaysInclude(), declaringClass);
225224
}
226225

227226
/**
@@ -231,7 +230,7 @@ public static void registerAllFields(Class<?> declaringClass) {
231230
* @since 23.0
232231
*/
233232
public static void registerAllDeclaredFields(Class<?> declaringClass) {
234-
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllDeclaredFields(ConfigurationCondition.alwaysTrue(), declaringClass);
233+
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllDeclaredFields(InclusionCondition.alwaysInclude(), declaringClass);
235234
}
236235

237236
/**
@@ -240,7 +239,7 @@ public static void registerAllDeclaredFields(Class<?> declaringClass) {
240239
* @since 23.0
241240
*/
242241
public static void registerAllNestMembers(Class<?> declaringClass) {
243-
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllNestMembersQuery(ConfigurationCondition.alwaysTrue(), declaringClass);
242+
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllNestMembersQuery(InclusionCondition.alwaysInclude(), declaringClass);
244243
}
245244

246245
/**
@@ -249,7 +248,7 @@ public static void registerAllNestMembers(Class<?> declaringClass) {
249248
* @since 23.0
250249
*/
251250
public static void registerAllPermittedSubclasses(Class<?> declaringClass) {
252-
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllPermittedSubclassesQuery(ConfigurationCondition.alwaysTrue(), declaringClass);
251+
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllPermittedSubclassesQuery(InclusionCondition.alwaysInclude(), declaringClass);
253252
}
254253

255254
/**
@@ -258,7 +257,7 @@ public static void registerAllPermittedSubclasses(Class<?> declaringClass) {
258257
* @since 23.0
259258
*/
260259
public static void registerAllRecordComponents(Class<?> declaringClass) {
261-
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllRecordComponentsQuery(ConfigurationCondition.alwaysTrue(), declaringClass);
260+
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllRecordComponentsQuery(InclusionCondition.alwaysInclude(), declaringClass);
262261
}
263262

264263
/**
@@ -267,7 +266,7 @@ public static void registerAllRecordComponents(Class<?> declaringClass) {
267266
* @since 23.0
268267
*/
269268
public static void registerAllSigners(Class<?> declaringClass) {
270-
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllSignersQuery(ConfigurationCondition.alwaysTrue(), declaringClass);
269+
ImageSingletons.lookup(RuntimeReflectionSupport.class).registerAllSignersQuery(InclusionCondition.alwaysInclude(), declaringClass);
271270
}
272271

273272
/**

0 commit comments

Comments
 (0)