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
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
*/
package org.graalvm.compiler.nodes;

import static jdk.vm.ci.services.Services.IS_BUILDING_NATIVE_IMAGE;
import static jdk.vm.ci.services.Services.IS_IN_NATIVE_IMAGE;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
Expand Down Expand Up @@ -336,26 +333,12 @@ private StructuredGraph(String name,
assert !isSubstitution || profileProvider == null;
this.profileProvider = profileProvider;
this.isSubstitution = isSubstitution;
assert checkIsSubstitutionInvariants(method, isSubstitution);
this.cancellable = cancellable;
this.inliningLog = GraalOptions.TraceInlining.getValue(options) || OptimizationLog.isOptimizationLogEnabled(options) ? new InliningLog(rootMethod) : null;
this.callerContext = context;
this.optimizationLog = OptimizationLog.getInstance(this);
}

private static boolean checkIsSubstitutionInvariants(ResolvedJavaMethod method, boolean isSubstitution) {
if (!IS_IN_NATIVE_IMAGE && !IS_BUILDING_NATIVE_IMAGE) {
if (method != null) {
if (method.getAnnotation(Snippet.class) != null) {
assert isSubstitution : "Graph for method " + method.format("%H.%n(%p)") +
" annotated by " + Snippet.class.getName() +
" must have its `isSubstitution` field set to true";
}
}
}
return true;
}

public void setLastSchedule(ScheduleResult result) {
GraalError.guarantee(result == null || result.cfg.getStartBlock().isModifiable(), "Schedule must use blocks that can be modified");
lastSchedule = result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,19 @@ public static ConstantFieldInfo forDimensions(int dimensions) {
private ConstantFieldInfo(int dimensions) {
this.dimensions = dimensions;
}

@Override
public int hashCode() {
return dimensions;
}

@Override
public boolean equals(Object obj) {
if (obj instanceof ConstantFieldInfo other) {
return dimensions == other.dimensions;
}
return false;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -986,9 +986,6 @@ public final class KnownMethods {
public final ResolvedJavaMethod callTargetMethod;
public final ResolvedJavaMethod callInlinedCallMethod;
public final ResolvedJavaMethod[] anyFrameMethod;
public final ResolvedJavaMethod inInterpreterMethod;
public final ResolvedJavaMethod inInterpreterFastPathMethod;
public final ResolvedJavaMethod[] transferToInterpreterMethods;

public KnownMethods(MetaAccessProvider metaAccess) {
this.callDirectMethod = metaAccess.lookupJavaMethod(GraalFrameInstance.CALL_DIRECT);
Expand All @@ -997,26 +994,9 @@ public KnownMethods(MetaAccessProvider metaAccess) {
this.callInlinedCallMethod = metaAccess.lookupJavaMethod(GraalFrameInstance.CALL_INLINED_CALL);
this.callTargetMethod = metaAccess.lookupJavaMethod(GraalFrameInstance.CALL_TARGET_METHOD);
this.anyFrameMethod = new ResolvedJavaMethod[]{callDirectMethod, callIndirectMethod, callInlinedMethod, callTargetMethod, callInlinedCallMethod};
ResolvedJavaType compilerDirectives = metaAccess.lookupJavaType(CompilerDirectives.class);
this.transferToInterpreterMethods = new ResolvedJavaMethod[2];
this.transferToInterpreterMethods[0] = searchMethod(compilerDirectives, "transferToInterpreter");
this.transferToInterpreterMethods[1] = searchMethod(compilerDirectives, "transferToInterpreterAndInvalidate");
this.inInterpreterMethod = searchMethod(compilerDirectives, "inInterpreter");

ResolvedJavaType hostCompilerDirectives = metaAccess.lookupJavaType(HostCompilerDirectives.class);
this.inInterpreterFastPathMethod = searchMethod(hostCompilerDirectives, "inInterpreterFastPath");
}
}

protected static ResolvedJavaMethod searchMethod(ResolvedJavaType type, String name) {
for (ResolvedJavaMethod searchMethod : type.getDeclaredMethods()) {
if (searchMethod.getName().equals(name)) {
return searchMethod;
}
}
throw CompilerDirectives.shouldNotReachHere(type + "." + name + " method not found.");
}

@Override
public boolean isValueType(ResolvedJavaType type) {
return getAnnotation(CompilerDirectives.ValueType.class, type) != null;
Expand Down Expand Up @@ -1130,30 +1110,25 @@ public boolean isInliningCutoff(ResolvedJavaMethod method) {
* Determines if {@code method} is an inInterpeter method.
*/
@Override
public boolean isInInterpreter(ResolvedJavaMethod targetMethod) {
return getKnownMethods().inInterpreterMethod.equals(targetMethod);
public boolean isInInterpreter(ResolvedJavaMethod method) {
return method.getName().equals("inInterpreter") && method.getDeclaringClass().toClassName().equals(CompilerDirectives.class.getName());
}

/**
* Determines if {@code method} is an inInterpeter method.
*/
@Override
public boolean isInInterpreterFastPath(ResolvedJavaMethod targetMethod) {
return getKnownMethods().inInterpreterFastPathMethod.equals(targetMethod);
public boolean isInInterpreterFastPath(ResolvedJavaMethod method) {
return method.getName().equals("inInterpreterFastPath") && method.getDeclaringClass().toClassName().equals(HostCompilerDirectives.class.getName());
}

/**
* Determines if {@code method} is a method is a transferToInterpreter method.
*/
@Override
public boolean isTransferToInterpreterMethod(ResolvedJavaMethod method) {
ResolvedJavaMethod[] methods = getKnownMethods().transferToInterpreterMethods;
for (int i = 0; i < methods.length; i++) {
if (methods[i].equals(method)) {
return true;
}
}
return false;
return (method.getName().equals("transferToInterpreter") || method.getName().equals("transferToInterpreterAndInvalidate")) &&
method.getDeclaringClass().toClassName().equals(CompilerDirectives.class.getName());
}

@SuppressWarnings("deprecation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@
import org.graalvm.compiler.phases.BasePhase;
import org.graalvm.compiler.phases.common.AddressLoweringByUsePhase;
import org.graalvm.compiler.phases.util.Providers;
import org.graalvm.nativeimage.AnnotationAccess;
import org.graalvm.nativeimage.ImageSingletons;

import com.oracle.svm.core.FrameAccess;
Expand Down Expand Up @@ -152,7 +151,6 @@
import com.oracle.svm.core.meta.SubstrateMethodPointerConstant;
import com.oracle.svm.core.meta.SubstrateObjectConstant;
import com.oracle.svm.core.nodes.SafepointCheckNode;
import com.oracle.svm.core.snippets.SubstrateForeignCallTarget;
import com.oracle.svm.core.thread.VMThreads.StatusSupport;
import com.oracle.svm.core.util.VMError;

Expand Down Expand Up @@ -791,8 +789,8 @@ public Variable emitReadReturnAddress() {

@Override
public ForeignCallLinkage lookupGraalStub(ValueNode valueNode, ForeignCallDescriptor foreignCallDescriptor) {
ResolvedJavaMethod method = valueNode.graph().method();
if (method != null && AnnotationAccess.getAnnotation(method, SubstrateForeignCallTarget.class) != null) {
SharedMethod method = (SharedMethod) valueNode.graph().method();
if (method != null && method.isForeignCallTarget()) {
// Emit assembly for snippet stubs
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@
import org.graalvm.compiler.phases.common.AddressLoweringByNodePhase;
import org.graalvm.compiler.phases.util.Providers;
import org.graalvm.compiler.replacements.amd64.AMD64IntrinsicStubs;
import org.graalvm.nativeimage.AnnotationAccess;
import org.graalvm.nativeimage.ImageSingletons;

import com.oracle.svm.core.CPUFeatureAccess;
Expand Down Expand Up @@ -170,7 +169,6 @@
import com.oracle.svm.core.meta.SubstrateMethodPointerConstant;
import com.oracle.svm.core.meta.SubstrateObjectConstant;
import com.oracle.svm.core.nodes.SafepointCheckNode;
import com.oracle.svm.core.snippets.SubstrateForeignCallTarget;
import com.oracle.svm.core.thread.VMThreads.StatusSupport;
import com.oracle.svm.core.util.VMError;

Expand Down Expand Up @@ -927,8 +925,8 @@ public Variable emitReadReturnAddress() {

@Override
public ForeignCallLinkage lookupGraalStub(ValueNode valueNode, ForeignCallDescriptor foreignCallDescriptor) {
ResolvedJavaMethod method = valueNode.graph().method();
if (method != null && AnnotationAccess.getAnnotation(method, SubstrateForeignCallTarget.class) != null) {
SharedMethod method = (SharedMethod) valueNode.graph().method();
if (method != null && method.isForeignCallTarget()) {
// Emit assembly for snippet stubs
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

import org.graalvm.compiler.api.replacements.Fold;
import org.graalvm.nativeimage.AnnotationAccess;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;
import org.graalvm.nativeimage.c.function.CFunction;
import org.graalvm.nativeimage.c.function.InvokeCFunctionPointer;
import org.graalvm.word.WordBase;
Expand Down Expand Up @@ -202,10 +204,12 @@ public static Uninterruptible getAnnotation(AnnotatedElement method) {
* Returns whether the method is {@link Uninterruptible}, either by explicit annotation of
* the method or implicitly due to other annotations.
*/
@Platforms(Platform.HOSTED_ONLY.class)
public static boolean isUninterruptible(AnnotatedElement method) {
return getAnnotation(method) != null;
}

@Platforms(Platform.HOSTED_ONLY.class)
public static boolean inliningAllowed(AnnotatedElement caller, AnnotatedElement callee) {
boolean callerUninterruptible = isUninterruptible(caller);
boolean calleeUninterruptible = isUninterruptible(callee);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,31 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.graalvm.nativeimage.AnnotationAccess;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;

import jdk.vm.ci.meta.ResolvedJavaMethod;

/**
* Annotation that overrides the default calling convention used for a method.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(value = {ElementType.METHOD})
public @interface ExplicitCallingConvention {
SubstrateCallingConventionKind value();

class Util {
@Platforms(Platform.HOSTED_ONLY.class)
public static SubstrateCallingConventionKind getCallingConventionKind(ResolvedJavaMethod method, boolean isEntryPoint) {
ExplicitCallingConvention explicitCallingConvention = AnnotationAccess.getAnnotation(method, ExplicitCallingConvention.class);
if (explicitCallingConvention != null) {
return explicitCallingConvention.value();
} else if (isEntryPoint) {
return SubstrateCallingConventionKind.Native;
} else {
return SubstrateCallingConventionKind.Java;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
public @interface StubCallingConvention {

class Utils {
@Platforms(Platform.HOSTED_ONLY.class)
public static boolean hasStubCallingConvention(ResolvedJavaMethod method) {
boolean result = false;
if (CalleeSavedRegisters.supportedByPlatform()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import org.graalvm.compiler.core.common.spi.MetaAccessExtensionProvider;

import com.oracle.svm.core.Uninterruptible;
import com.oracle.svm.core.meta.SharedMethod;
import com.oracle.svm.core.meta.SharedType;

Expand Down Expand Up @@ -59,14 +58,14 @@ public boolean isGuaranteedSafepoint(ResolvedJavaMethod method, boolean isDirect

// check if the method itself indicates it will not have a safepoint.
SharedMethod sharedMethod = (SharedMethod) method;
if (Uninterruptible.Utils.isUninterruptible(sharedMethod)) {
if (sharedMethod.isUninterruptible()) {
return false;
}

// for indirect calls, confirming all implementations also have safepoints.
if (!isDirect) {
for (SharedMethod implementation : sharedMethod.getImplementations()) {
if (Uninterruptible.Utils.isUninterruptible(implementation)) {
if (implementation.isUninterruptible()) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@

import com.oracle.svm.core.SubstrateTargetDescription;
import com.oracle.svm.core.config.ConfigurationValues;
import com.oracle.svm.core.meta.SharedMethod;
import com.oracle.svm.core.option.HostedOptionValues;
import com.oracle.svm.core.util.VMError;

Expand Down Expand Up @@ -407,4 +408,13 @@ public Stamp getInjectedStamp(Class<?> type, boolean nonNull) {
return StampFactory.forKind(kind);
}
}

@Override
public boolean isSnippet(ResolvedJavaMethod method) {
if (method instanceof SharedMethod sharedMethod) {
return sharedMethod.isSnippet();
} else {
return super.isSnippet(method);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,24 @@
import org.graalvm.compiler.phases.common.LoopSafepointInsertionPhase;
import org.graalvm.compiler.phases.tiers.MidTierContext;
import org.graalvm.nativeimage.AnnotationAccess;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;
import org.graalvm.nativeimage.c.function.CFunction;
import org.graalvm.nativeimage.c.function.InvokeCFunctionPointer;

import com.oracle.svm.core.Uninterruptible;
import com.oracle.svm.core.graal.code.SubstrateBackend;
import com.oracle.svm.core.meta.SharedMethod;

import jdk.vm.ci.meta.ResolvedJavaMethod;

/**
* Adds safepoints to loops and at method ends.
*/
public class SubstrateSafepointInsertionPhase extends LoopSafepointInsertionPhase {

public static boolean needSafepointCheck(SharedMethod method) {
@Platforms(Platform.HOSTED_ONLY.class)
public static boolean needSafepointCheck(ResolvedJavaMethod method) {
if (Uninterruptible.Utils.isUninterruptible(method)) {
/* Uninterruptible methods must not have a safepoint inserted. */
return false;
Expand All @@ -62,7 +67,7 @@ public static boolean needSafepointCheck(SharedMethod method) {
@Override
protected void run(StructuredGraph graph, MidTierContext context) {
SharedMethod method = (SharedMethod) graph.method();
if (!needSafepointCheck(method)) {
if (!method.needSafepointCheck()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
import com.oracle.svm.core.FrameAccess;
import com.oracle.svm.core.SubstrateOptions;
import com.oracle.svm.core.SubstrateUtil;
import com.oracle.svm.core.Uninterruptible;
import com.oracle.svm.core.code.CodeInfoTable;
import com.oracle.svm.core.graal.code.SubstrateBackend;
import com.oracle.svm.core.graal.meta.KnownOffsets;
Expand Down Expand Up @@ -304,7 +303,7 @@ public void lower(FixedNode node, LoweringTool tool) {
InvokeKind invokeKind = callTarget.invokeKind();
SharedMethod[] implementations = method.getImplementations();

if (verifyTypes && !callTarget.isStatic() && receiver.getStackKind() == JavaKind.Object && !Uninterruptible.Utils.isUninterruptible(graph.method())) {
if (verifyTypes && !callTarget.isStatic() && receiver.getStackKind() == JavaKind.Object && !((SharedMethod) graph.method()).isUninterruptible()) {
/*
* Verify that the receiver is an instance of the class that declares the call
* target method. To avoid that the new type check floats above a deoptimization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@
import org.graalvm.word.LocationIdentity;

import com.oracle.svm.core.SubstrateOptions;
import com.oracle.svm.core.Uninterruptible;
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
import com.oracle.svm.core.feature.InternalFeature;
import com.oracle.svm.core.graal.meta.RuntimeConfiguration;
import com.oracle.svm.core.graal.meta.SubstrateForeignCallsProvider;
import com.oracle.svm.core.meta.SharedMethod;
import com.oracle.svm.core.nodes.SafepointCheckNode;
import com.oracle.svm.core.thread.Safepoint;

Expand Down Expand Up @@ -93,7 +93,7 @@ class SafepointLowering implements NodeLoweringProvider<SafepointNode> {
public void lower(SafepointNode node, LoweringTool tool) {
if (tool.getLoweringStage() == LoweringTool.StandardLoweringStage.LOW_TIER) {
assert SubstrateOptions.MultiThreaded.getValue() : "safepoints are only inserted into the graph in MultiThreaded mode";
if (Uninterruptible.Utils.isUninterruptible(node.graph().method())) {
if (((SharedMethod) node.graph().method()).isUninterruptible()) {
/* Basic sanity check to catch errors during safepoint insertion. */
throw GraalError.shouldNotReachHere("Must not insert safepoints in Uninterruptible code: " + node.stateBefore().toString(Verbosity.Debugger)); // ExcludeFromJacocoGeneratedReport
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ private static StackOverflowError newStackOverflowError0() {
}

public static boolean needStackOverflowCheck(SharedMethod method) {
if (Uninterruptible.Utils.isUninterruptible(method)) {
if (method.isUninterruptible()) {
/*
* Uninterruptible methods are allowed to use the yellow and red zones of the stack.
* Also, the thread register and stack boundary might not be set up. We cannot do a
Expand Down
Loading