Skip to content

[GR-45250] [GR-45734] Reachability proofs for reflective operations #11079

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

Open
wants to merge 13 commits 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
Expand Up @@ -28,6 +28,8 @@
import static jdk.graal.compiler.core.common.type.StampFactory.objectNonNull;
import static jdk.vm.ci.meta.DeoptimizationAction.InvalidateReprofile;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import jdk.graal.compiler.bytecode.Bytecode;
Expand Down Expand Up @@ -281,6 +283,22 @@ default int getDepth() {
return result;
}

/**
* Gets the inlined call stack for this context. A list with only one element implies that no
* inlining has taken place.
*
* @param ignoreInvocationPluginTarget if set to true, and {@link #isParsingInvocationPlugin()}
* returns true, the resulting call stack does not include the target of the
* invocation plugin.
*/
default List<StackTraceElement> getInliningCallStack(boolean ignoreInvocationPluginTarget) {
List<StackTraceElement> callStack = new ArrayList<>();
for (GraphBuilderContext cur = this; cur != null; cur = cur.getParent()) {
callStack.add(cur.getMethod().asStackTraceElement(cur.bci()));
}
return Collections.unmodifiableList(callStack);
}

/**
* Computes the recursive inlining depth of the provided method, i.e., counts how often the
* provided method is already in the {@link #getParent()} chain starting at this context.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

import static jdk.vm.ci.code.BytecodeFrame.AFTER_BCI;

import java.util.Collections;
import java.util.List;

import jdk.graal.compiler.bytecode.Bytecode;
import jdk.graal.compiler.core.common.type.Stamp;
import jdk.graal.compiler.core.common.type.StampFactory;
Expand Down Expand Up @@ -325,6 +328,11 @@ public int getDepth() {
return 0;
}

@Override
public List<StackTraceElement> getInliningCallStack(boolean ignoreInvocationPluginTarget) {
return Collections.emptyList();
}

@Override
public boolean parsingIntrinsic() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Formatter;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -412,6 +413,21 @@ public int getDepth() {
return methodScope.inliningDepth;
}

@Override
public List<StackTraceElement> getInliningCallStack(boolean ignoreInvocationPluginTarget) {
StackTraceElement[] callStackArray = methodScope.getCallStack();
List<StackTraceElement> callStack = new ArrayList<>(callStackArray.length);
Collections.addAll(callStack, callStackArray);
/*
* If triggered while processing an invocation plugin, the call stack as returned by the
* methodScope object will include the target of the plugin.
*/
if (isParsingInvocationPlugin() && ignoreInvocationPluginTarget) {
callStack.removeFirst();
}
return Collections.unmodifiableList(callStack);
}

@Override
public int recursiveInliningDepth(ResolvedJavaMethod method) {
int result = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,8 @@ public List<JavaConstant> getStaticArguments() {
return wrapped.getStaticArguments().stream().map(WrappedConstantPool.this::lookupConstant).collect(Collectors.toList());
}
}

public ConstantPool getWrapped() {
return wrapped;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@ protected boolean tryInvocationPlugin(CallTargetNode.InvokeKind invokeKind, Valu
protected boolean shouldVerifyFrameStates() {
return Options.VerifyRuntimeCompilationFrameStates.getValue();
}

@Override
protected boolean strictDynamicAccessInferenceIsApplicable() {
return false;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import com.oracle.svm.hosted.dynamicaccessinference.DynamicAccessInferenceLog;
import com.oracle.svm.hosted.dynamicaccessinference.StrictDynamicAccessInferenceFeature;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.hosted.RuntimeResourceAccess;
import org.graalvm.nativeimage.impl.ConfigurationCondition;
Expand Down Expand Up @@ -174,6 +176,8 @@ private record CompiledConditionalPattern(ConfigurationCondition condition, Reso
private int loadedConfigurations;
private ImageClassLoader imageClassLoader;

private DynamicAccessInferenceLog inferenceLog;

private class ResourcesRegistryImpl extends ConditionalConfigurationRegistry implements ResourcesRegistry<ConfigurationCondition> {
private final ClassInitializationSupport classInitializationSupport = ClassInitializationSupport.singleton();

Expand Down Expand Up @@ -392,6 +396,7 @@ public void afterRegistration(AfterRegistrationAccess a) {
ImageSingletons.add(RuntimeResourceSupport.class, resourcesRegistry);
EmbeddedResourcesInfo embeddedResourcesInfo = new EmbeddedResourcesInfo();
ImageSingletons.add(EmbeddedResourcesInfo.class, embeddedResourcesInfo);
inferenceLog = ImageSingletons.contains(DynamicAccessInferenceLog.class) ? DynamicAccessInferenceLog.singleton() : null;
}

private static ResourcesRegistryImpl resourceRegistryImpl() {
Expand Down Expand Up @@ -672,7 +677,7 @@ public void beforeCompilation(BeforeCompilationAccess access) {

@Override
public void registerInvocationPlugins(Providers providers, GraphBuilderConfiguration.Plugins plugins, ParsingReason reason) {
if (!reason.duringAnalysis() || reason == ParsingReason.JITCompilation) {
if (!reason.duringAnalysis() || reason == ParsingReason.JITCompilation || StrictDynamicAccessInferenceFeature.isEnforced()) {
return;
}

Expand Down Expand Up @@ -712,6 +717,9 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec
throw VMError.shouldNotReachHere(e);
}
b.add(ReachabilityRegistrationNode.create(() -> RuntimeResourceAccess.addResource(clazz.getModule(), resourceName), reason));
if (inferenceLog != null) {
inferenceLog.logRegistration(b, reason, targetMethod, clazz, new String[]{resource});
}
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import java.util.function.Function;
import java.util.function.Predicate;

import com.oracle.svm.hosted.dynamicaccessinference.StrictDynamicAccessInferenceFeature;
import com.oracle.svm.hosted.dynamicaccessinference.StrictDynamicAccessInferenceSupport;
import org.graalvm.nativeimage.AnnotationAccess;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.Platform;
Expand Down Expand Up @@ -219,6 +221,8 @@ public enum UsageKind {
private final boolean buildingImageLayer = ImageLayerBuildingSupport.buildingImageLayer();
private final LayeredStaticFieldSupport layeredStaticFieldSupport;

private final StrictDynamicAccessInferenceSupport strictDynamicAccessInferenceSupport;

@SuppressWarnings("this-escape")
public SVMHost(OptionValues options, ImageClassLoader loader, ClassInitializationSupport classInitializationSupport, AnnotationSubstitutionProcessor annotationSubstitutions,
MissingRegistrationSupport missingRegistrationSupport) {
Expand Down Expand Up @@ -255,6 +259,8 @@ public SVMHost(OptionValues options, ImageClassLoader loader, ClassInitializatio
enableTrackAcrossLayers = ImageLayerBuildingSupport.buildingSharedLayer();
enableReachableInCurrentLayer = ImageLayerBuildingSupport.buildingExtensionLayer();
layeredStaticFieldSupport = ImageLayerBuildingSupport.buildingImageLayer() ? LayeredStaticFieldSupport.singleton() : null;

strictDynamicAccessInferenceSupport = StrictDynamicAccessInferenceFeature.isDisabled() ? null : StrictDynamicAccessInferenceSupport.singleton();
}

/**
Expand Down Expand Up @@ -1270,4 +1276,8 @@ public boolean allowConstantFolding(AnalysisMethod method) {
public SimulateClassInitializerSupport createSimulateClassInitializerSupport(AnalysisMetaAccess aMetaAccess) {
return new SimulateClassInitializerSupport(aMetaAccess, this);
}

public StrictDynamicAccessInferenceSupport getStrictDynamicAccessInferenceSupport() {
return strictDynamicAccessInferenceSupport;
}
}
Loading
Loading