Skip to content

Commit 69f47d1

Browse files
committed
Fix ConfigurationType method subtraction
1 parent 88bc81e commit 69f47d1

File tree

6 files changed

+90
-7
lines changed

6 files changed

+90
-7
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.configure.test;
26+
27+
import java.lang.annotation.ElementType;
28+
import java.lang.annotation.Retention;
29+
import java.lang.annotation.RetentionPolicy;
30+
import java.lang.annotation.Target;
31+
32+
/**
33+
* Specifies packages concealed in JDK modules used by a test. The mx unit test runner will ensure
34+
* the packages are exported to the module containing annotated test class.
35+
*/
36+
@Retention(RetentionPolicy.RUNTIME)
37+
@Target(ElementType.TYPE)
38+
public @interface AddExports {
39+
/**
40+
* The qualified name of the concealed package in {@code <module>/<package>} format (e.g.,
41+
* "jdk.internal.vm.ci/jdk.vm.ci.code").
42+
*/
43+
String[] value() default "";
44+
}

substratevm/src/com.oracle.svm.configure.test/src/com/oracle/svm/configure/test/config/OmitPreviousConfigTests.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@
5252
import com.oracle.svm.configure.config.ResourceConfiguration;
5353
import com.oracle.svm.configure.config.SerializationConfiguration;
5454
import com.oracle.svm.configure.config.TypeConfiguration;
55+
import com.oracle.svm.configure.test.AddExports;
5556
import com.oracle.svm.core.configure.ConfigurationTypeDescriptor;
5657
import com.oracle.svm.core.configure.NamedConfigurationTypeDescriptor;
5758
import com.oracle.svm.core.util.VMError;
5859

60+
@AddExports({"org.graalvm.nativeimage/org.graalvm.nativeimage.impl", "jdk.graal.compiler/jdk.graal.compiler.util"})
5961
public class OmitPreviousConfigTests {
6062

6163
private static final String PREVIOUS_CONFIG_DIR_NAME = "prev-config-dir";
@@ -117,7 +119,7 @@ public void testConfigDifference() {
117119

118120
doTestResourceConfig(config.getResourceConfiguration());
119121

120-
doTestSerializationConfig(config.getSerializationConfiguration());
122+
doTestSerializationConfig(config);
121123

122124
doTestPredefinedClassesConfig(config.getPredefinedClassesConfiguration());
123125
}
@@ -181,6 +183,8 @@ private static void doTestMethods(TypeConfiguration typeConfig) {
181183

182184
Assert.assertNull(ConfigurationType.TestBackdoor.getMethodInfoIfPresent(methodTestType, new ConfigurationMethod("<init>", "(I)V")));
183185
Assert.assertNotNull(ConfigurationType.TestBackdoor.getMethodInfoIfPresent(methodTestType, new ConfigurationMethod("method", "()V")));
186+
Assert.assertNull(ConfigurationType.TestBackdoor.getMethodInfoIfPresent(methodTestType, new ConfigurationMethod("method2", "()V")));
187+
Assert.assertNotNull(ConfigurationType.TestBackdoor.getMethodInfoIfPresent(methodTestType, new ConfigurationMethod("method3", "()V")));
184188
}
185189

186190
private static void doTestProxyConfig(ProxyConfiguration proxyConfig) {
@@ -198,7 +202,13 @@ private static void doTestResourceConfig(ResourceConfiguration resourceConfig) {
198202
Assert.assertTrue(resourceConfig.anyBundleMatches(condition, "unseenBundle"));
199203
}
200204

201-
private static void doTestSerializationConfig(SerializationConfiguration serializationConfig) {
205+
/*
206+
* Note: the parameter cannot be a SerializationConfiguration because the type depends on some
207+
* module exports (see the AddExports annotation) which only get applied _after_ the class is
208+
* loaded.
209+
*/
210+
private static void doTestSerializationConfig(ConfigurationSet config) {
211+
SerializationConfiguration serializationConfig = config.getSerializationConfiguration();
202212
UnresolvedConfigurationCondition condition = UnresolvedConfigurationCondition.alwaysTrue();
203213
Assert.assertFalse(serializationConfig.contains(condition, "seenType", null));
204214
Assert.assertTrue(serializationConfig.contains(condition, "unseenType", null));

substratevm/src/com.oracle.svm.configure.test/src/com/oracle/svm/configure/test/config/config-dir/jni-config.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@
5555
{
5656
"name": "method",
5757
"parameterTypes": []
58+
},
59+
{
60+
"name": "method3",
61+
"parameterTypes": []
62+
}
63+
],
64+
"queriedMethods": [
65+
{
66+
"name": "method2",
67+
"parameterTypes": []
5868
}
5969
]
6070
}

substratevm/src/com.oracle.svm.configure.test/src/com/oracle/svm/configure/test/config/prev-config-dir/jni-config.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@
4949
"parameterTypes": [
5050
"int"
5151
]
52+
},
53+
{
54+
"name": "method2",
55+
"parameterTypes": []
56+
}
57+
],
58+
"queriedMethods": [
59+
{
60+
"name": "method3",
61+
"parameterTypes": []
5262
}
5363
]
5464
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,11 @@ private ConfigurationMemberDeclaration union(ConfigurationMemberDeclaration othe
9292
}
9393

9494
public boolean includes(ConfigurationMemberDeclaration other) {
95-
if (equals(DECLARED_AND_PUBLIC)) {
96-
return DECLARED.equals(other) || PUBLIC.equals(other);
97-
}
98-
return equals(other);
95+
return switch (this) {
96+
case PRESENT -> true;
97+
case DECLARED_AND_PUBLIC -> other == DECLARED || other == PUBLIC;
98+
default -> this == other;
99+
};
99100
}
100101
}
101102

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,15 @@ private void removeMethods(ConfigurationType other) {
264264
maybeRemoveMethods(allDeclaredMethodsAccess.combine(other.allDeclaredMethodsAccess), allPublicMethodsAccess.combine(other.allPublicMethodsAccess),
265265
allDeclaredConstructorsAccess.combine(other.allDeclaredConstructorsAccess), allPublicConstructorsAccess.combine(other.allPublicConstructorsAccess));
266266
if (methods != null && other.methods != null) {
267-
methods.entrySet().removeAll(other.methods.entrySet());
267+
for (Map.Entry<ConfigurationMethod, ConfigurationMemberInfo> entry : other.methods.entrySet()) {
268+
ConfigurationMemberInfo otherMethodInfo = entry.getValue();
269+
methods.computeIfPresent(entry.getKey(), (method, methodInfo) -> {
270+
if (otherMethodInfo.includes(methodInfo)) {
271+
return null; // remove
272+
}
273+
return methodInfo;
274+
});
275+
}
268276
if (methods.isEmpty()) {
269277
methods = null;
270278
}

0 commit comments

Comments
 (0)