Skip to content

Commit 2e1a6df

Browse files
Automatic merge of master into galahad
2 parents c485978 + 02dfcdf commit 2e1a6df

File tree

5 files changed

+21
-6
lines changed

5 files changed

+21
-6
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,7 @@ CLSS public abstract interface static org.graalvm.nativeimage.hosted.Feature$Dur
10511051
outer org.graalvm.nativeimage.hosted.Feature
10521052
intf org.graalvm.nativeimage.hosted.Feature$FeatureAccess
10531053
meth public abstract void registerObjectReplacer(java.util.function.Function<java.lang.Object,java.lang.Object>)
1054+
meth public abstract void registerObjectReachabilityHandler(java.util.function.Consumer<T>,java.lang.Class<T>)
10541055

10551056
CLSS public abstract interface static org.graalvm.nativeimage.hosted.Feature$FeatureAccess
10561057
outer org.graalvm.nativeimage.hosted.Feature

sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/hosted/Feature.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,15 @@ interface DuringSetupAccess extends FeatureAccess {
191191
* @since 19.0
192192
*/
193193
void registerObjectReplacer(Function<Object, Object> replacer);
194+
195+
/**
196+
* Register a callback that is executed when an object of type {@code clazz}, or any of its
197+
* subtypes, is marked as reachable during heap scanning. The callback may be executed for
198+
* the same object by multiple worker threads concurrently.
199+
*
200+
* @since 24.2
201+
*/
202+
<T> void registerObjectReachabilityHandler(Consumer<T> callback, Class<T> clazz);
194203
}
195204

196205
/**

substratevm/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
This changelog summarizes major changes to GraalVM Native Image.
44

55
## GraalVM for JDK 24 (Internal Version 24.2.0)
6+
* (GR-59717) Added `DuringSetupAccess.registerObjectReachabilityHandler` to allow registering a callback that is executed when an object of a specified type is marked as reachable during heap scanning.
67
* (GR-55708) (Alibaba contribution) Support for running premain methods of Java agents at runtime as an experimental feature. At build time, `-H:PremainClasses` is used to set the premain classes.
78
At runtime, premain runtime options are set along with main class' arguments in the format of `-XXpremain:[class]:[options]`.
89
* (GR-54476): Issue a deprecation warning on first use of a legacy `graal.` prefix (see GR-49960 in [Compiler changelog](../compiler/CHANGELOG.md)).

substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/LibGraalFeature.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@
5353
import org.graalvm.nativeimage.hosted.RuntimeReflection;
5454

5555
import com.oracle.graal.pointsto.BigBang;
56-
import com.oracle.graal.pointsto.ObjectScanner;
5756
import com.oracle.graal.pointsto.meta.AnalysisType;
58-
import com.oracle.graal.pointsto.meta.ObjectReachableCallback;
5957
import com.oracle.graal.pointsto.reports.CallTreePrinter;
6058
import com.oracle.svm.core.SubstrateTargetDescription;
6159
import com.oracle.svm.core.hub.ClassForNameSupport;
@@ -256,8 +254,8 @@ public void duringSetup(DuringSetupAccess access) {
256254
DuringSetupAccessImpl accessImpl = (DuringSetupAccessImpl) access;
257255
accessImpl.registerClassReachabilityListener(this::registerPhaseStatistics);
258256
optionCollector = new OptionCollector(LibGraalEntryPoints.vmOptionDescriptors);
259-
accessImpl.registerObjectReachableCallback(OptionKey.class, optionCollector::doCallback);
260-
accessImpl.registerObjectReachableCallback(loadClassOrFail(OptionKey.class.getName()), optionCollector::doCallback);
257+
access.registerObjectReachabilityHandler(optionCollector::accept, OptionKey.class);
258+
access.registerObjectReachabilityHandler(optionCollector::accept, loadClassOrFail(OptionKey.class.getName()));
261259
GetJNIConfig.register(loader);
262260
}
263261

@@ -270,7 +268,7 @@ public void duringSetup(DuringSetupAccess access) {
270268
* compiler options are instances of {@link OptionKey} loaded by the
271269
* {@code HostedLibGraalClassLoader}.
272270
*/
273-
private class OptionCollector implements ObjectReachableCallback<Object> {
271+
private class OptionCollector implements Consumer<Object> {
274272
private final Set<Object> options = Collections.newSetFromMap(new ConcurrentHashMap<>());
275273

276274
/**
@@ -297,7 +295,7 @@ private class OptionCollector implements ObjectReachableCallback<Object> {
297295
}
298296

299297
@Override
300-
public void doCallback(DuringAnalysisAccess access, Object option, ObjectScanner.ScanReason reason) {
298+
public void accept(Object option) {
301299
if (sealed) {
302300
VMError.guarantee(options.contains(option), "All options must have been discovered during static analysis: %s", option);
303301
} else {

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/FeatureImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,12 @@ public <T> void registerObjectReachableCallback(Class<T> clazz, ObjectReachableC
317317
getMetaAccess().lookupJavaType(clazz).registerObjectReachableCallback(callback);
318318
}
319319

320+
@Override
321+
public <T> void registerObjectReachabilityHandler(Consumer<T> callback, Class<T> clazz) {
322+
ObjectReachableCallback<T> wrapper = (access, obj, reason) -> callback.accept(obj);
323+
getMetaAccess().lookupJavaType(clazz).registerObjectReachableCallback(wrapper);
324+
}
325+
320326
public void registerSubstitutionProcessor(SubstitutionProcessor substitution) {
321327
getUniverse().registerFeatureSubstitution(substitution);
322328
}

0 commit comments

Comments
 (0)