Skip to content

Commit 7f0972a

Browse files
committed
First draft of the compatibility mode
1 parent bcd6019 commit 7f0972a

4 files changed

Lines changed: 32 additions & 10 deletions

File tree

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,16 @@ public enum ReportingMode {
14761476
@Option(help = "Number of context lines printed for each missing registration error in Warn mode")//
14771477
public static final RuntimeOptionKey<Integer> MissingRegistrationWarnContextLines = new RuntimeOptionKey<>(8);
14781478

1479+
@Option(help = "Remove all Native-Image-specific behavior from build time or runtime for classpath/module-path classes.")//
1480+
public static final HostedOptionKey<Boolean> CompatibilityMode = new HostedOptionKey<>(false) {
1481+
@Override
1482+
protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Boolean oldValue, Boolean newValue) {
1483+
super.onValueUpdate(values, oldValue, newValue);
1484+
FutureDefaultsOptions.FutureDefaults.update(values, "all");
1485+
RuntimeClassLoading.Options.RuntimeClassLoading.update(values, true);
1486+
}
1487+
};
1488+
14791489
@Option(help = "Instead of warning, throw IOExceptions for link-at-build-time resources at build time")//
14801490
public static final HostedOptionKey<Boolean> ThrowLinkAtBuildTimeIOExceptions = new HostedOptionKey<>(false);
14811491

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/SystemPropertiesSupport.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,15 @@ protected SystemPropertiesSupport() {
146146
initializeProperty("java.ext.dirs", "");
147147
initializeProperty("sun.arch.data.model", Integer.toString(ConfigurationValues.getTarget().wordJavaKind.getBitCount()));
148148

149-
initializeProperty(ImageInfo.PROPERTY_IMAGE_CODE_KEY, ImageInfo.PROPERTY_IMAGE_CODE_VALUE_RUNTIME);
149+
if (!SubstrateOptions.CompatibilityMode.getValue()) {
150+
initializeProperty(ImageInfo.PROPERTY_IMAGE_CODE_KEY, ImageInfo.PROPERTY_IMAGE_CODE_VALUE_RUNTIME);
150151

151-
for (String futureDefault : FutureDefaultsOptions.getFutureDefaults()) {
152-
initializeProperty(FutureDefaultsOptions.SYSTEM_PROPERTY_PREFIX + futureDefault, Boolean.TRUE.toString());
153-
}
154-
for (String futureDefault : FutureDefaultsOptions.getRetiredFutureDefaults()) {
155-
initializeProperty(FutureDefaultsOptions.SYSTEM_PROPERTY_PREFIX + futureDefault, Boolean.TRUE.toString());
152+
for (String futureDefault : FutureDefaultsOptions.getFutureDefaults()) {
153+
initializeProperty(FutureDefaultsOptions.SYSTEM_PROPERTY_PREFIX + futureDefault, Boolean.TRUE.toString());
154+
}
155+
for (String futureDefault : FutureDefaultsOptions.getRetiredFutureDefaults()) {
156+
initializeProperty(FutureDefaultsOptions.SYSTEM_PROPERTY_PREFIX + futureDefault, Boolean.TRUE.toString());
157+
}
156158
}
157159

158160
ArrayList<LazySystemProperty> lazyProperties = new ArrayList<>();

substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -757,9 +757,11 @@ public boolean processMetaInfResource(Path classpathEntry, Path resourceRoot, Pa
757757
if (imageNameValue != null) {
758758
addPlainImageBuilderArg(oHName + resolver.apply(imageNameValue), resourcePath.toUri().toString());
759759
}
760-
forEachPropertyValue(properties.get("JavaArgs"), NativeImage.this::addImageBuilderJavaArgs, resolver);
761-
forEachPropertyValue(properties.get("Args"), args, resolver);
762-
forEachPropertyValue(properties.get("ProvidedHostedOptions"), apiOptionHandler::injectKnownHostedOption, resolver);
760+
if (!isCompatibilityModeEnabled()) {
761+
forEachPropertyValue(properties.get("JavaArgs"), NativeImage.this::addImageBuilderJavaArgs, resolver);
762+
forEachPropertyValue(properties.get("Args"), args, resolver);
763+
forEachPropertyValue(properties.get("ProvidedHostedOptions"), apiOptionHandler::injectKnownHostedOption, resolver);
764+
}
763765
} else {
764766
args.accept(oH(type.optionKey) + resourceRoot.relativize(resourcePath));
765767
}
@@ -1510,6 +1512,10 @@ private static Boolean getHostedOptionBooleanArgumentValue(List<String> args, Op
15101512
return result;
15111513
}
15121514

1515+
private boolean isCompatibilityModeEnabled() {
1516+
return Boolean.TRUE.equals(getHostedOptionBooleanArgumentValue(imageBuilderArgs, SubstrateOptions.CompatibilityMode));
1517+
}
1518+
15131519
private boolean shouldAddCWDToCP() {
15141520
if (config.buildFallbackImage() || printFlagsOptionQuery != null || printFlagsWithExtraHelpOptionQuery != null) {
15151521
return false;

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotationSubstitutionProcessor.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,11 @@ protected void handleClass(Class<?> annotatedClass, Set<Module> builderModules)
397397
return;
398398
}
399399

400+
boolean userSubstitution = !builderModules.contains(annotatedClass.getModule());
401+
if (SubstrateOptions.CompatibilityMode.getValue() && userSubstitution) {
402+
return;
403+
}
404+
400405
TargetClass targetClassAnnotation = lookupAnnotation(annotatedClass, TargetClass.class);
401406
Class<?> originalClass = findTargetClass(annotatedClass, targetClassAnnotation);
402407
if (originalClass == null) {
@@ -415,7 +420,6 @@ protected void handleClass(Class<?> annotatedClass, Set<Module> builderModules)
415420
int numAnnotations = (deleteAnnotation != null ? 1 : 0) + (substituteAnnotation != null ? 1 : 0);
416421
guarantee(numAnnotations <= 1, "Only one of @Delete or @Substitute can be used: %s", annotatedClass);
417422

418-
boolean userSubstitution = !builderModules.contains(annotatedClass.getModule());
419423
if (deleteAnnotation != null) {
420424
handleDeletedClass(originalClass, deleteAnnotation);
421425
} else if (substituteAnnotation != null) {

0 commit comments

Comments
 (0)