Skip to content

Commit b0bbc22

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 535cf93 commit b0bbc22

File tree

2 files changed

+119
-0
lines changed

2 files changed

+119
-0
lines changed
Lines changed: 81 additions & 0 deletions
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/impl/TypeReachabilityCondition.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
import java.util.Objects;
4444

45+
<<<<<<<< HEAD:sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/TypeReachabilityCondition.java
4546
import org.graalvm.nativeimage.hosted.RegistrationCondition;
4647

4748
/**
@@ -53,6 +54,19 @@ public class TypeReachabilityCondition implements RegistrationCondition {
5354

5455
/* Cached to save space: it is used as a marker for all non-conditional elements */
5556
public static final TypeReachabilityCondition JAVA_LANG_OBJECT_REACHED = new TypeReachabilityCondition(Object.class, true);
57+
========
58+
import org.graalvm.nativeimage.hosted.InclusionCondition;
59+
60+
/**
61+
* Type that represents both type-reached and type-reachable condition. When
62+
* {@link TypeCondition#runtimeChecked} is <code>true</code> denotes that this is a
63+
* <code>typeReached</code> condition.
64+
*/
65+
public class TypeCondition implements InclusionCondition {
66+
67+
/* Cached to save space: it is used as a marker for all non-conditional elements */
68+
public static final TypeCondition JAVA_LANG_OBJECT_REACHED = new TypeCondition(Object.class, true);
69+
>>>>>>>> 675ac0bf8ee (Introduced public API for registration conditions.):sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/TypeCondition.java
5670
private final Class<?> type;
5771

5872
public final boolean runtimeChecked;
@@ -65,6 +79,7 @@ public class TypeReachabilityCondition implements RegistrationCondition {
6579
* @param runtimeChecked makes this a type-reachable condition when false
6680
* @return instance of the condition
6781
*/
82+
<<<<<<<< HEAD:sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/TypeReachabilityCondition.java
6883
public static TypeReachabilityCondition create(Class<?> type, boolean runtimeChecked) {
6984
Objects.requireNonNull(type);
7085
if (TypeReachabilityCondition.JAVA_LANG_OBJECT_REACHED.getKey().equals(type)) {
@@ -78,6 +93,21 @@ public boolean isAlwaysTrue() {
7893
}
7994

8095
public TypeReachabilityCondition(Class<?> type, boolean runtimeChecked) {
96+
========
97+
public static TypeCondition create(Class<?> type, boolean runtimeChecked) {
98+
Objects.requireNonNull(type);
99+
if (TypeCondition.JAVA_LANG_OBJECT_REACHED.getKey().equals(type)) {
100+
return TypeCondition.JAVA_LANG_OBJECT_REACHED;
101+
}
102+
return new TypeCondition(type, runtimeChecked);
103+
}
104+
105+
public boolean isAlwaysTrue() {
106+
return InclusionCondition.alwaysInclude().equals(this);
107+
}
108+
109+
public TypeCondition(Class<?> type, boolean runtimeChecked) {
110+
>>>>>>>> 675ac0bf8ee (Introduced public API for registration conditions.):sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/TypeCondition.java
81111
this.runtimeChecked = runtimeChecked;
82112
this.type = type;
83113
}
@@ -94,7 +124,11 @@ public boolean equals(Object o) {
94124
if (o == null || getClass() != o.getClass()) {
95125
return false;
96126
}
127+
<<<<<<<< HEAD:sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/TypeReachabilityCondition.java
97128
TypeReachabilityCondition that = (TypeReachabilityCondition) o;
129+
========
130+
TypeCondition that = (TypeCondition) o;
131+
>>>>>>>> 675ac0bf8ee (Introduced public API for registration conditions.):sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/TypeCondition.java
98132
return runtimeChecked == that.runtimeChecked && Objects.equals(type, that.type);
99133
}
100134

@@ -105,7 +139,11 @@ public int hashCode() {
105139

106140
@Override
107141
public String toString() {
142+
<<<<<<<< HEAD:sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/TypeReachabilityCondition.java
108143
return "TypeReachabilityCondition(" +
144+
========
145+
return "TypeCondition(" +
146+
>>>>>>>> 675ac0bf8ee (Introduced public API for registration conditions.):sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/TypeCondition.java
109147
"type=" + type +
110148
", runtimeChecked=" + runtimeChecked +
111149
')';

0 commit comments

Comments
 (0)