Skip to content

Commit 2e641cb

Browse files
committed
[GR-69577] Make --future-defaults=complete-reflection-types default
PullRequest: graal/22114
2 parents 67dcf2b + 3417dda commit 2e641cb

File tree

25 files changed

+399
-142
lines changed

25 files changed

+399
-142
lines changed

sdk/mx.sdk/mx_sdk_benchmark.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5627,6 +5627,12 @@ def version(self):
56275627
def applicationDist(self):
56285628
return mx.library("PETCLINIC_" + self.version(), True).get_path(True)
56295629

5630+
def extra_image_build_argument(self, benchmark, args):
5631+
additional_configuration = os.path.join(getattr(self, '.mxsuite').mxDir, "petclinic-config")
5632+
return [
5633+
f"-H:ConfigurationFileDirectories={additional_configuration}",
5634+
] + super(BasePetClinicBenchmarkSuite, self).extra_image_build_argument(benchmark, args)
5635+
56305636

56315637
class PetClinicWrkBenchmarkSuite(BasePetClinicBenchmarkSuite, BaseWrkBenchmarkSuite):
56325638
"""PetClinic benchmark suite that measures throughput using Wrk."""
@@ -5728,8 +5734,14 @@ def extra_image_build_argument(self, benchmark, args):
57285734
"org.apache.xmlbeans.metadata.system.sXMLLANG.TypeSystemHolder",
57295735
"org.apache.xmlbeans.metadata.system.sXMLSCHEMA.TypeSystemHolder"
57305736
]
5737+
tika_run_time_init = [
5738+
# Prevents build-time initialization of sun.awt.datatransfer.DesktopDatatransferServiceImpl through DefaultDesktopDatatransferService.INSTANCE
5739+
# This class is made reachable through DragSource.<init>, which is reachable because XToolkit.createDragGestureRecognizer is registered for reflective querying
5740+
"sun.datatransfer.DataFlavorUtil$DefaultDesktopDatatransferService"
5741+
]
57315742
return [
57325743
f"--initialize-at-build-time={','.join(tika_build_time_init)}",
5744+
f"--initialize-at-run-time={','.join(tika_run_time_init)}",
57335745
] + super(BaseTikaBenchmarkSuite, self).extra_image_build_argument(benchmark, args)
57345746

57355747

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"reflection": [
3+
{
4+
"type": "org.apache.coyote.AbstractProtocol",
5+
"methods": [
6+
{
7+
"name": "setProperty",
8+
"parameterTypes": [
9+
"java.lang.String",
10+
"java.lang.String"
11+
]
12+
},
13+
{
14+
"name": "getAddress",
15+
"parameterTypes": []
16+
}
17+
]
18+
},
19+
{
20+
"type": "org.apache.coyote.http11.AbstractHttp11Protocol",
21+
"methods": [
22+
{
23+
"name": "isSSLEnabled",
24+
"parameterTypes": []
25+
}
26+
]
27+
},
28+
{
29+
"type": "com.zaxxer.hikari.HikariDataSource",
30+
"fields": [
31+
{
32+
"name": "pool"
33+
}
34+
]
35+
}
36+
]
37+
}

sdk/src/org.graalvm.nativeimage/snapshot.sigtest

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ meth public java.lang.Class<?> getDeclaringClass()
257257
meth public java.lang.Class<?> getElementType()
258258
meth public java.lang.Class<?>[] getParameterTypes()
259259
meth public java.lang.String getElementName()
260+
meth public static boolean isInvocable(java.lang.reflect.Executable)
260261
supr java.lang.LinkageError
261262
hfds declaringClass,elementName,elementType,parameterTypes,serialVersionUID
262263

sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/MissingReflectionRegistrationError.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@
4242

4343
import java.io.Serial;
4444
import java.lang.reflect.Constructor;
45+
import java.lang.reflect.Executable;
4546
import java.lang.reflect.Field;
4647
import java.lang.reflect.Method;
4748

49+
import org.graalvm.nativeimage.impl.ReflectionIntrospector;
50+
4851
/**
4952
* This exception is thrown when a reflective query (such as
5053
* {@link Class#getMethod(String, Class[])}) tries to access an element that was not <a href=
@@ -152,4 +155,14 @@ public String getElementName() {
152155
public Class<?>[] getParameterTypes() {
153156
return parameterTypes;
154157
}
158+
159+
/**
160+
* @return Whether the executable can be invoked without throwing a
161+
* {@link MissingReflectionRegistrationError}.
162+
*
163+
* @since 25.1
164+
*/
165+
public static boolean isInvocable(Executable executable) {
166+
return !ImageSingletons.contains(ReflectionIntrospector.class) || ImageSingletons.lookup(ReflectionIntrospector.class).isInvocable(executable);
167+
}
155168
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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.impl;
42+
43+
import java.lang.reflect.Executable;
44+
45+
/**
46+
* Provides an interface to query whether an executable has invocation capabilities, or was only
47+
* registered for reflective queries.
48+
*/
49+
public interface ReflectionIntrospector {
50+
boolean isInvocable(Executable executable);
51+
}

substratevm/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This changelog summarizes major changes to GraalVM Native Image.
1414
* (GR-68984) Improve the schema to capture detailed constraints about each element in the `reachability-metadata-schema.json`.
1515
* (GR-70046) Remove all support for running image builder on classpath.
1616
* (GR-71146) Make `ParseRuntimeOptions` a non-experimental flag and extract a separate (experimental) `InitializeVM` flag. If your project previously used `ParseRuntimeOptions` and you call `VMRuntime.initialize()` manually, you might have to disable the new flag.
17+
* (GR-69577) Retire `--future-defaults=complete-reflection-types`. All reflective operations on types registered for reflection will now return complete results.
1718

1819
## GraalVM 25
1920
* (GR-52276) (GR-61959) Add support for Arena.ofShared().

substratevm/mx.substratevm/mx_substratevm_benchmark.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,13 @@ def extra_run_arg(self, benchmark, args, image_run_args):
376376
def extra_image_build_argument(self, benchmark, args):
377377
extra_image_build_args = []
378378
if benchmark == "quarkus-tika":
379-
# Band-aid solution for class initizalization deadlock due to org.openxmlformats.schemas.drawingml.x2006 (GR-59899)
380-
extra_image_build_args += ["-H:NumberOfThreads=1"]
379+
extra_image_build_args += [
380+
# Band-aid solution for class initizalization deadlock due to org.openxmlformats.schemas.drawingml.x2006 (GR-59899)
381+
"-H:NumberOfThreads=1",
382+
# Prevents build-time initialization of sun.awt.datatransfer.DesktopDatatransferServiceImpl through DefaultDesktopDatatransferService.INSTANCE
383+
# This class is made reachable through DragSource.<init>, which is reachable because XToolkit.createDragGestureRecognizer is registered for reflective querying
384+
"--initialize-at-run-time=sun.datatransfer.DataFlavorUtil$DefaultDesktopDatatransferService"
385+
]
381386
return extra_image_build_args + super().extra_image_build_argument(benchmark, args)
382387

383388
def build_assertions(self, benchmark: str, is_gate: bool) -> List[str]:

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/AbstractAnalysisEngine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ public void tryRegisterNativeMethodsForBaseImage(ResolvedJavaType type) {
421421
* Some modules contain native methods that should not be included in the image because they
422422
* are hosted only, or because they are currently unsupported.
423423
*/
424-
Set<Module> forbiddenModules = hostVM.getForbiddenModules();
424+
Set<Module> forbiddenModules = hostVM.getSharedLayerForbiddenModules();
425425
if (forbiddenModules.contains(OriginalClassProvider.getJavaClass(type).getModule())) {
426426
return;
427427
}

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/api/HostVM.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ public boolean preventConstantFolding(AnalysisField aField) {
467467
return false;
468468
}
469469

470-
public Set<Module> getForbiddenModules() {
470+
public Set<Module> getSharedLayerForbiddenModules() {
471471
return Set.of();
472472
}
473473

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisUniverse.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,12 @@ public AnalysisMethod[] lookup(JavaMethod[] inputs) {
474474
List<AnalysisMethod> result = new ArrayList<>(inputs.length);
475475
for (JavaMethod method : inputs) {
476476
if (hostVM.platformSupported((ResolvedJavaMethod) method)) {
477-
AnalysisMethod aMethod = lookup(method);
477+
AnalysisMethod aMethod = null;
478+
try {
479+
aMethod = lookup(method);
480+
} catch (UnsupportedFeatureException ignored) {
481+
/* Unsupported elements should not prevent querying other members of the type */
482+
}
478483
if (aMethod != null) {
479484
result.add(aMethod);
480485
}

0 commit comments

Comments
 (0)