Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GR-58929] Fix ConfigurationType method subtraction. #10279

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.configure.test;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Specifies packages concealed in JDK modules used by a test. The mx unit test runner will ensure
* the packages are exported to the module containing annotated test class.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface AddExports {
/**
* The qualified name of the concealed package in {@code <module>/<package>} format (e.g.,
* "jdk.internal.vm.ci/jdk.vm.ci.code").
*/
String[] value() default "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@
import com.oracle.svm.configure.config.ResourceConfiguration;
import com.oracle.svm.configure.config.SerializationConfiguration;
import com.oracle.svm.configure.config.TypeConfiguration;
import com.oracle.svm.configure.test.AddExports;
import com.oracle.svm.core.configure.ConfigurationTypeDescriptor;
import com.oracle.svm.core.configure.NamedConfigurationTypeDescriptor;
import com.oracle.svm.core.util.VMError;

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

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

doTestResourceConfig(config.getResourceConfiguration());

doTestSerializationConfig(config.getSerializationConfiguration());
doTestSerializationConfig(config);

doTestPredefinedClassesConfig(config.getPredefinedClassesConfiguration());
}
Expand Down Expand Up @@ -181,6 +183,8 @@ private static void doTestMethods(TypeConfiguration typeConfig) {

Assert.assertNull(ConfigurationType.TestBackdoor.getMethodInfoIfPresent(methodTestType, new ConfigurationMethod("<init>", "(I)V")));
Assert.assertNotNull(ConfigurationType.TestBackdoor.getMethodInfoIfPresent(methodTestType, new ConfigurationMethod("method", "()V")));
Assert.assertNull(ConfigurationType.TestBackdoor.getMethodInfoIfPresent(methodTestType, new ConfigurationMethod("method2", "()V")));
Assert.assertNotNull(ConfigurationType.TestBackdoor.getMethodInfoIfPresent(methodTestType, new ConfigurationMethod("method3", "()V")));
}

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

private static void doTestSerializationConfig(SerializationConfiguration serializationConfig) {
/*
* Note: the parameter cannot be a SerializationConfiguration because the type depends on some
* module exports (see the AddExports annotation) which only get applied _after_ the class is
* loaded.
*/
private static void doTestSerializationConfig(ConfigurationSet config) {
SerializationConfiguration serializationConfig = config.getSerializationConfiguration();
UnresolvedConfigurationCondition condition = UnresolvedConfigurationCondition.alwaysTrue();
Assert.assertFalse(serializationConfig.contains(condition, "seenType", null));
Assert.assertTrue(serializationConfig.contains(condition, "unseenType", null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@
{
"name": "method",
"parameterTypes": []
},
{
"name": "method3",
"parameterTypes": []
}
],
"queriedMethods": [
{
"name": "method2",
"parameterTypes": []
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@
"parameterTypes": [
"int"
]
},
{
"name": "method2",
"parameterTypes": []
}
],
"queriedMethods": [
{
"name": "method3",
"parameterTypes": []
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ private ConfigurationMemberDeclaration union(ConfigurationMemberDeclaration othe
}

public boolean includes(ConfigurationMemberDeclaration other) {
if (equals(DECLARED_AND_PUBLIC)) {
return DECLARED.equals(other) || PUBLIC.equals(other);
}
return equals(other);
return switch (this) {
case PRESENT -> true;
case DECLARED_AND_PUBLIC -> other == DECLARED || other == PUBLIC;
default -> this == other;
};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,15 @@ private void removeMethods(ConfigurationType other) {
maybeRemoveMethods(allDeclaredMethodsAccess.combine(other.allDeclaredMethodsAccess), allPublicMethodsAccess.combine(other.allPublicMethodsAccess),
allDeclaredConstructorsAccess.combine(other.allDeclaredConstructorsAccess), allPublicConstructorsAccess.combine(other.allPublicConstructorsAccess));
if (methods != null && other.methods != null) {
methods.entrySet().removeAll(other.methods.entrySet());
for (Map.Entry<ConfigurationMethod, ConfigurationMemberInfo> entry : other.methods.entrySet()) {
ConfigurationMemberInfo otherMethodInfo = entry.getValue();
methods.computeIfPresent(entry.getKey(), (method, methodInfo) -> {
if (otherMethodInfo.includes(methodInfo)) {
return null; // remove
}
return methodInfo;
});
}
if (methods.isEmpty()) {
methods = null;
}
Expand Down