Skip to content

Commit 01c61f0

Browse files
committed
Remove abstractions over different conditions
1 parent afaa640 commit 01c61f0

20 files changed

+119
-239
lines changed

substratevm/src/com.oracle.svm.configure/src/com/oracle/svm/configure/config/TypeConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public void printJson(JsonWriter writer) throws IOException {
150150

151151
@Override
152152
public ConfigurationParser createParser() {
153-
return new ReflectionConfigurationParser<>(ConfigurationConditionResolver.identityResolver(), new ParserConfigurationAdapter(this), true, false);
153+
return new ReflectionConfigurationParser<>(ConfigurationConditionResolver.identityResolver(), new ParserConfigurationAdapter(this), true, false, false);
154154
}
155155

156156
@Override

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/RuntimeMetadataDecoderImpl.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
import java.lang.reflect.Parameter;
3434
import java.lang.reflect.RecordComponent;
3535
import java.util.Arrays;
36-
import java.util.HashSet;
37-
import java.util.Set;
3836
import java.util.function.Function;
3937

4038
import org.graalvm.nativeimage.ImageSingletons;
@@ -43,7 +41,6 @@
4341

4442
import com.oracle.svm.core.SubstrateUtil;
4543
import com.oracle.svm.core.c.NonmovableArrays;
46-
import com.oracle.svm.core.configure.RuntimeCondition;
4744
import com.oracle.svm.core.configure.RuntimeConditionSet;
4845
import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton;
4946
import com.oracle.svm.core.hub.DynamicHub;
@@ -381,11 +378,7 @@ private static Object decodeField(UnsafeArrayTypeReader buf, Class<?> declaringC
381378

382379
private static RuntimeConditionSet decodeConditions(UnsafeArrayTypeReader buf) {
383380
var conditionTypes = decodeArray(buf, Class.class, i -> decodeType(buf));
384-
Set<RuntimeCondition> runtimeConditions = new HashSet<>(conditionTypes.length);
385-
for (Class<?> conditionType : conditionTypes) {
386-
runtimeConditions.add(RuntimeCondition.createTypeReachedCondition(conditionType));
387-
}
388-
return RuntimeConditionSet.createRuntime(runtimeConditions);
381+
return RuntimeConditionSet.createDecoded(conditionTypes);
389382
}
390383

391384
/**

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/configure/ConfigurationFiles.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,13 @@ public static final class Options {
128128
@Option(help = "Testing flag: the typeReachable condition is treated as typeReached so the semantics of programs can change.")//
129129
public static final HostedOptionKey<Boolean> TreatAllTypeReachableConditionsAsTypeReached = new HostedOptionKey<>(false);
130130

131-
@Option(help = "Testing flag: the typeReached condition is always satisfied however it prints the stack traces where it would not be satisfied.")//
131+
@Option(help = "Testing flag: the 'name' is treated as 'type' reflection configuration.")//
132+
public static final HostedOptionKey<Boolean> TreatAllNameEntriesAsType = new HostedOptionKey<>(false);
133+
134+
@Option(help = "Testing flag: the 'typeReached' condition is always satisfied however it prints the stack trace where it would not be satisfied.")//
132135
public static final HostedOptionKey<Boolean> TrackUnsatisfiedTypeReachedConditions = new HostedOptionKey<>(false);
133136

134-
@Option(help = "Testing flag: print typeReached conditions that are used on interfaces.")//
137+
@Option(help = "Testing flag: print 'typeReached' conditions that are used on interfaces at build time.")//
135138
public static final HostedOptionKey<Boolean> TrackTypeReachedOnInterfaces = new HostedOptionKey<>(false);
136139

137140
@Option(help = "Testing flag: every type is considered as it participates in a typeReachable condition.")//

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/configure/ConfigurationParser.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ protected UnresolvedConfigurationCondition parseCondition(EconomicMap<String, Ob
215215

216216
if (conditionObject.containsKey(TYPE_REACHED_KEY)) {
217217
if (!runtimeCondition) {
218-
failOnSchemaError("'" + TYPE_REACHED_KEY + "' condition can not be used in older schemas. Please migrate to the latest schema.");
218+
failOnSchemaError("'" + TYPE_REACHED_KEY + "' condition cannot be used in older schemas. Please migrate the file to the latest schema.");
219219
}
220220
Object object = conditionObject.get(TYPE_REACHED_KEY);
221221
var condition = parseTypeContents(object);
@@ -224,7 +224,7 @@ protected UnresolvedConfigurationCondition parseCondition(EconomicMap<String, Ob
224224
return UnresolvedConfigurationCondition.create(className, true);
225225
}
226226
} else if (conditionObject.containsKey(TYPE_REACHABLE_KEY)) {
227-
if (runtimeCondition) {
227+
if (runtimeCondition && !TreatAllTypeReachableConditionsAsTypeReached.getValue()) {
228228
failOnSchemaError("'" + TYPE_REACHABLE_KEY + "' condition can not be used with the latest schema. Please use '" + TYPE_REACHED_KEY + "'.");
229229
}
230230
Object object = conditionObject.get(TYPE_REACHABLE_KEY);
@@ -242,13 +242,13 @@ private static JSONParserException failOnSchemaError(String message) {
242242
throw new JSONParserException(message);
243243
}
244244

245-
protected static Optional<ConfigurationTypeDescriptor> parseTypeOrName(EconomicMap<String, Object> data) {
245+
protected static Optional<ConfigurationTypeDescriptor> parseTypeOrName(EconomicMap<String, Object> data, boolean treatAllNameEntriesAsType) {
246246
Object typeObject = data.get(TYPE_KEY);
247247
Object name = data.get(NAME_KEY);
248248
if (typeObject != null) {
249249
return parseTypeContents(typeObject);
250250
} else if (name != null) {
251-
return Optional.of(new NamedConfigurationTypeDescriptor(asString(name)));
251+
return Optional.of(new NamedConfigurationTypeDescriptor(asString(name), treatAllNameEntriesAsType));
252252
} else {
253253
throw failOnSchemaError("must have type or name specified for an element");
254254
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/configure/ConfigurationTypeDescriptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,5 @@ static String checkQualifiedJavaName(String javaName) {
7373
return canonicalizeTypeName(javaName);
7474
}
7575

76-
boolean isType();
76+
boolean definedAsType();
7777
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/configure/NamedConfigurationTypeDescriptor.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@
3030

3131
import com.oracle.svm.core.util.json.JsonWriter;
3232

33-
public record NamedConfigurationTypeDescriptor(String name, boolean type) implements ConfigurationTypeDescriptor {
33+
public record NamedConfigurationTypeDescriptor(String name, boolean definedAsType) implements ConfigurationTypeDescriptor {
3434

3535
public NamedConfigurationTypeDescriptor(String name) {
3636
this(name, false);
3737
}
3838

39-
public NamedConfigurationTypeDescriptor(String name, boolean type) {
39+
public NamedConfigurationTypeDescriptor(String name, boolean definedAsType) {
4040
this.name = ConfigurationTypeDescriptor.checkQualifiedJavaName(name);
41-
this.type = type;
41+
this.definedAsType = definedAsType;
4242
}
4343

4444
@Override
45-
public boolean isType() {
46-
return type;
45+
public boolean definedAsType() {
46+
return definedAsType;
4747
}
4848

4949
@Override
@@ -74,5 +74,4 @@ public int compareTo(ConfigurationTypeDescriptor other) {
7474
public void printJson(JsonWriter writer) throws IOException {
7575
writer.quote(name);
7676
}
77-
7877
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/configure/ProxyConfigurationTypeDescriptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public int compareTo(ConfigurationTypeDescriptor other) {
6565
}
6666

6767
@Override
68-
public boolean isType() {
68+
public boolean definedAsType() {
6969
return true;
7070
}
7171

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/configure/ReflectionConfigurationParser.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,15 @@ public final class ReflectionConfigurationParser<C, T> extends ConfigurationPars
5656
"allPublicClasses", "methods", "queriedMethods", "fields", CONDITIONAL_KEY,
5757
"queryAllDeclaredConstructors", "queryAllPublicConstructors", "queryAllDeclaredMethods", "queryAllPublicMethods", "unsafeAllocated");
5858
private final boolean printMissingElements;
59+
private final boolean treatAllNameEntriesAsType;
5960

6061
public ReflectionConfigurationParser(ConfigurationConditionResolver<C> conditionResolver, ReflectionConfigurationParserDelegate<C, T> delegate, boolean strictConfiguration,
61-
boolean printMissingElements) {
62+
boolean printMissingElements, boolean treatAllNameEntriesAsType) {
6263
super(strictConfiguration);
6364
this.conditionResolver = conditionResolver;
6465
this.printMissingElements = printMissingElements;
6566
this.delegate = delegate;
67+
this.treatAllNameEntriesAsType = treatAllNameEntriesAsType;
6668
}
6769

6870
@Override
@@ -80,11 +82,11 @@ private void parseClass(EconomicMap<String, Object> data) {
8082
checkAttributes(data, "reflection class descriptor object", Collections.emptyList(), OPTIONAL_REFLECT_CONFIG_OBJECT_ATTRS);
8183
checkHasExactlyOneAttribute(data, "reflection class descriptor object", List.of("name", "type"));
8284

83-
Optional<ConfigurationTypeDescriptor> type = parseTypeOrName(data);
85+
Optional<ConfigurationTypeDescriptor> type = parseTypeOrName(data, treatAllNameEntriesAsType);
8486
if (type.isEmpty()) {
8587
return;
8688
}
87-
boolean isType = type.get().isType();
89+
boolean isType = type.get().definedAsType();
8890

8991
UnresolvedConfigurationCondition unresolvedCondition = parseCondition(data, isType);
9092
TypeResult<C> conditionResult = conditionResolver.resolveCondition(unresolvedCondition);

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/configure/RuntimeCondition.java

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)