Skip to content
Merged
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
1 change: 1 addition & 0 deletions sdk/src/org.graalvm.nativeimage/snapshot.sigtest
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,7 @@ CLSS public abstract interface static org.graalvm.nativeimage.hosted.Feature$Dur
outer org.graalvm.nativeimage.hosted.Feature
intf org.graalvm.nativeimage.hosted.Feature$FeatureAccess
meth public abstract void registerObjectReplacer(java.util.function.Function<java.lang.Object,java.lang.Object>)
meth public abstract void registerObjectReachabilityHandler(java.util.function.Consumer<T>,java.lang.Class<T>)

CLSS public abstract interface static org.graalvm.nativeimage.hosted.Feature$FeatureAccess
outer org.graalvm.nativeimage.hosted.Feature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ interface DuringSetupAccess extends FeatureAccess {
* @since 19.0
*/
void registerObjectReplacer(Function<Object, Object> replacer);

/**
* Register a callback that is executed when an object of type {@code clazz}, or any of its
* subtypes, is marked as reachable during heap scanning. The callback may be executed for
* the same object by multiple worker threads concurrently.
*
* @since 24.2
*/
<T> void registerObjectReachabilityHandler(Consumer<T> callback, Class<T> clazz);
}

/**
Expand Down
1 change: 1 addition & 0 deletions substratevm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This changelog summarizes major changes to GraalVM Native Image.

## GraalVM for JDK 24 (Internal Version 24.2.0)
* (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.
* (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.
At runtime, premain runtime options are set along with main class' arguments in the format of `-XXpremain:[class]:[options]`.
* (GR-54476): Issue a deprecation warning on first use of a legacy `graal.` prefix (see GR-49960 in [Compiler changelog](../compiler/CHANGELOG.md)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@
import org.graalvm.nativeimage.hosted.RuntimeReflection;

import com.oracle.graal.pointsto.BigBang;
import com.oracle.graal.pointsto.ObjectScanner;
import com.oracle.graal.pointsto.meta.AnalysisType;
import com.oracle.graal.pointsto.meta.ObjectReachableCallback;
import com.oracle.graal.pointsto.reports.CallTreePrinter;
import com.oracle.svm.core.SubstrateTargetDescription;
import com.oracle.svm.core.hub.ClassForNameSupport;
Expand Down Expand Up @@ -256,8 +254,8 @@ public void duringSetup(DuringSetupAccess access) {
DuringSetupAccessImpl accessImpl = (DuringSetupAccessImpl) access;
accessImpl.registerClassReachabilityListener(this::registerPhaseStatistics);
optionCollector = new OptionCollector(LibGraalEntryPoints.vmOptionDescriptors);
accessImpl.registerObjectReachableCallback(OptionKey.class, optionCollector::doCallback);
accessImpl.registerObjectReachableCallback(loadClassOrFail(OptionKey.class.getName()), optionCollector::doCallback);
access.registerObjectReachabilityHandler(optionCollector::accept, OptionKey.class);
access.registerObjectReachabilityHandler(optionCollector::accept, loadClassOrFail(OptionKey.class.getName()));
GetJNIConfig.register(loader);
}

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

/**
Expand All @@ -297,7 +295,7 @@ private class OptionCollector implements ObjectReachableCallback<Object> {
}

@Override
public void doCallback(DuringAnalysisAccess access, Object option, ObjectScanner.ScanReason reason) {
public void accept(Object option) {
if (sealed) {
VMError.guarantee(options.contains(option), "All options must have been discovered during static analysis: %s", option);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,12 @@ public <T> void registerObjectReachableCallback(Class<T> clazz, ObjectReachableC
getMetaAccess().lookupJavaType(clazz).registerObjectReachableCallback(callback);
}

@Override
public <T> void registerObjectReachabilityHandler(Consumer<T> callback, Class<T> clazz) {
ObjectReachableCallback<T> wrapper = (access, obj, reason) -> callback.accept(obj);
getMetaAccess().lookupJavaType(clazz).registerObjectReachableCallback(wrapper);
}

public void registerSubstitutionProcessor(SubstitutionProcessor substitution) {
getUniverse().registerFeatureSubstitution(substitution);
}
Expand Down