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 @@ -25,24 +25,29 @@

package jdk.graal.compiler.hotspot.test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.math.BigInteger;
import java.util.Collections;
import jdk.vm.ci.meta.ResolvedJavaType;
import jdk.vm.ci.runtime.JVMCI;

import org.junit.Test;
import org.objectweb.asm.Type;

import jdk.graal.compiler.api.runtime.GraalJVMCICompiler;
import jdk.graal.compiler.debug.DebugContext;
import jdk.graal.compiler.debug.DebugContext.Builder;
import jdk.graal.compiler.hotspot.meta.HotSpotJITClassInitializationPlugin;
import jdk.graal.compiler.java.GraphBuilderPhase;
import jdk.graal.compiler.java.LambdaUtils;
import jdk.graal.compiler.options.OptionValues;
import jdk.graal.compiler.phases.OptimisticOptimizations;
import jdk.graal.compiler.phases.util.Providers;
import jdk.graal.compiler.runtime.RuntimeProvider;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Test;
import org.objectweb.asm.Type;
import jdk.vm.ci.meta.ResolvedJavaType;
import jdk.vm.ci.runtime.JVMCI;

public class LambdaStableNameTest {
private String findStableLambdaName(ResolvedJavaType type) {
Expand All @@ -51,7 +56,8 @@ private String findStableLambdaName(ResolvedJavaType type) {
GraalJVMCICompiler compiler = (GraalJVMCICompiler) JVMCI.getRuntime().getCompiler();
Providers providers = compiler.getGraalRuntime().getCapability(RuntimeProvider.class).getHostBackend().getProviders();
final HotSpotJITClassInitializationPlugin initializationPlugin = new HotSpotJITClassInitializationPlugin();
return LambdaUtils.findStableLambdaName(initializationPlugin, providers, type, options, debug, this);
return LambdaUtils.findStableLambdaName(initializationPlugin, providers, type, options, debug, this,
config -> new GraphBuilderPhase.Instance(providers, config, OptimisticOptimizations.NONE, null));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1792,7 +1792,7 @@ private boolean genDynamicInvokeHelper(ResolvedJavaMethod target, int cpi, int o

}

boolean hasReceiver = (opcode == INVOKEDYNAMIC) ? false : !target.isStatic();
boolean hasReceiver = opcode != INVOKEDYNAMIC && !target.isStatic();
ValueNode[] args = frameState.popArguments(target.getSignature().getParameterCount(hasReceiver));
if (hasReceiver) {
appendInvoke(InvokeKind.Virtual, target, args, null);
Expand Down Expand Up @@ -2089,12 +2089,7 @@ private static boolean checkPartialIntrinsicExit(ValueNode[] originalArgs, Value
protected Invoke createNonInlinedInvoke(ExceptionEdgeAction exceptionEdge, int invokeBci, ValueNode[] invokeArgs, ResolvedJavaMethod targetMethod,
InvokeKind invokeKind, JavaKind resultType, JavaType returnType, JavaTypeProfile profile) {

StampPair returnStamp = graphBuilderConfig.getPlugins().getOverridingStamp(this, returnType, false);
if (returnStamp == null) {
returnStamp = StampFactory.forDeclaredType(graph.getAssumptions(), returnType, false);
}

MethodCallTargetNode callTarget = graph.add(createMethodCallTarget(invokeKind, targetMethod, invokeArgs, returnStamp, profile));
MethodCallTargetNode callTarget = graph.add(createMethodCallTarget(invokeKind, targetMethod, invokeArgs, returnType, profile));
Invoke invoke = createNonInlinedInvoke(exceptionEdge, invokeBci, callTarget, resultType);

for (InlineInvokePlugin plugin : graphBuilderConfig.getPlugins().getInlineInvokePlugins()) {
Expand All @@ -2105,11 +2100,14 @@ protected Invoke createNonInlinedInvoke(ExceptionEdgeAction exceptionEdge, int i
}

protected Invoke createNonInlinedInvoke(ExceptionEdgeAction exceptionEdge, int invokeBci, CallTargetNode callTarget, JavaKind resultType) {
Invoke invoke;
if (exceptionEdge == ExceptionEdgeAction.OMIT) {
return createInvoke(invokeBci, callTarget, resultType);
invoke = append(createInvoke(invokeBci, callTarget, resultType));
} else {
return createInvokeWithException(invokeBci, callTarget, resultType, exceptionEdge);
invoke = append(createInvokeWithException(invokeBci, callTarget, resultType, exceptionEdge));
}
invoke.setStateAfter(createFrameState(stream.nextBCI(), invoke));
return invoke;
}

/**
Expand Down Expand Up @@ -2675,14 +2673,22 @@ private ValueNode processCalleeReturn(ResolvedJavaMethod targetMethod, InliningS
return null;
}

public MethodCallTargetNode createMethodCallTarget(InvokeKind invokeKind, ResolvedJavaMethod targetMethod, ValueNode[] args, JavaType returnType, JavaTypeProfile profile) {
StampPair returnStamp = graphBuilderConfig.getPlugins().getOverridingStamp(this, returnType, false);
if (returnStamp == null) {
returnStamp = StampFactory.forDeclaredType(graph.getAssumptions(), returnType, false);
}

return createMethodCallTarget(invokeKind, targetMethod, args, returnStamp, profile);
}

public MethodCallTargetNode createMethodCallTarget(InvokeKind invokeKind, ResolvedJavaMethod targetMethod, ValueNode[] args, StampPair returnStamp, JavaTypeProfile profile) {
return new MethodCallTargetNode(invokeKind, targetMethod, args, returnStamp, profile);
}

protected InvokeNode createInvoke(int invokeBci, CallTargetNode callTarget, JavaKind resultType) {
InvokeNode invoke = append(new InvokeNode(callTarget, invokeBci));
InvokeNode invoke = new InvokeNode(callTarget, invokeBci);
frameState.pushReturn(resultType, invoke);
invoke.setStateAfter(createFrameState(stream.nextBCI(), invoke));
return invoke;
}

Expand All @@ -2696,9 +2702,8 @@ protected InvokeWithExceptionNode createInvokeWithException(int invokeBci, CallT
}

AbstractBeginNode exceptionEdge = handleException(null, bci(), exceptionEdgeAction == ExceptionEdgeAction.INCLUDE_AND_DEOPTIMIZE);
InvokeWithExceptionNode invoke = append(new InvokeWithExceptionNode(callTarget, exceptionEdge, invokeBci));
InvokeWithExceptionNode invoke = new InvokeWithExceptionNode(callTarget, exceptionEdge, invokeBci);
frameState.pushReturn(resultType, invoke);
invoke.setStateAfter(createFrameState(stream.nextBCI(), invoke));
return invoke;
}

Expand Down Expand Up @@ -3939,7 +3944,7 @@ public BailoutException bailout(String string) {
throw GraphUtil.createBailoutException(string, bailout, elements);
}

private FrameState createFrameState(int bci, StateSplit forStateSplit) {
protected FrameState createFrameState(int bci, StateSplit forStateSplit) {
assert !(forStateSplit instanceof BytecodeExceptionNode) : Assertions.errorMessageContext("forStateSplit", forStateSplit);
if (currentBlock != null && bci > currentBlock.getEndBci()) {
frameState.clearNonLiveLocals(currentBlock, liveness, false);
Expand Down Expand Up @@ -4023,19 +4028,24 @@ public void storeLocal(JavaKind kind, int index) {

protected void genLoadConstant(int cpi, int opcode) {
Object con = lookupConstant(cpi, opcode, false);
genLoadConstantHelper(con, opcode);
}

protected void genLoadConstantHelper(Object con, int opcode) {
if (con == null) {
handleUnresolvedLoadConstant(null);
} else if (con instanceof JavaType) {
} else if (con instanceof JavaType type) {
// this is a load of class constant which might be unresolved
JavaType type = (JavaType) con;
if (typeIsResolved(type)) {
assert opcode != LDC2_W : "Type cannot use two slots";
frameState.push(JavaKind.Object, appendConstant(getConstantReflection().asJavaClass((ResolvedJavaType) type)));
} else {
handleUnresolvedLoadConstant(type);
}
} else if (con instanceof JavaConstant) {
JavaConstant constant = (JavaConstant) con;
frameState.push(constant.getJavaKind(), appendConstant(constant));
} else if (con instanceof JavaConstant constant) {
JavaKind javaKind = constant.getJavaKind();
assert (opcode == LDC2_W) == javaKind.needsTwoSlots() : "Constant required incorrect number of slots: needsTwoSlots is " + javaKind.needsTwoSlots();
frameState.push(javaKind, appendConstant(constant));
} else if (!(con instanceof Throwable)) {
/**
* We use the exceptional return value of {@link #lookupConstant(int, int)} as sentinel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,23 @@
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import jdk.graal.compiler.debug.DebugContext;
import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderContext;
import jdk.graal.compiler.nodes.Invoke;
import jdk.graal.compiler.nodes.StructuredGraph;
import jdk.graal.compiler.nodes.graphbuilderconf.ClassInitializationPlugin;
import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
import jdk.graal.compiler.nodes.graphbuilderconf.IntrinsicContext;
import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderContext;
import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins;
import jdk.graal.compiler.nodes.spi.CoreProviders;
import jdk.graal.compiler.options.OptionValues;
import jdk.graal.compiler.phases.OptimisticOptimizations;
import jdk.graal.compiler.phases.tiers.HighTierContext;
import jdk.graal.compiler.phases.util.Providers;

import jdk.vm.ci.common.JVMCIError;
import jdk.vm.ci.meta.ResolvedJavaMethod;
import jdk.vm.ci.meta.ResolvedJavaType;
Expand Down Expand Up @@ -99,7 +97,8 @@ private LambdaUtils() {
* @return stable name for the lambda class
*/
@SuppressWarnings("try")
public static String findStableLambdaName(ClassInitializationPlugin cip, Providers providers, ResolvedJavaType lambdaType, OptionValues options, DebugContext debug, Object ctx)
public static String findStableLambdaName(ClassInitializationPlugin cip, Providers providers, ResolvedJavaType lambdaType, OptionValues options, DebugContext debug, Object ctx,
Function<GraphBuilderConfiguration, GraphBuilderPhase.Instance> graphBuilderSupplier)
throws RuntimeException {
ResolvedJavaMethod[] lambdaProxyMethods = Arrays.stream(lambdaType.getDeclaredMethods(false)).filter(m -> !m.isBridge() && m.isPublic()).toArray(ResolvedJavaMethod[]::new);
/*
Expand All @@ -108,7 +107,7 @@ public static String findStableLambdaName(ClassInitializationPlugin cip, Provide
*/
StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(lambdaProxyMethods[0]).build();
try (DebugContext.Scope ignored = debug.scope("Lambda target method analysis", graph, lambdaType, ctx)) {
GraphBuilderPhase lambdaParserPhase = new LambdaGraphBuilder(LambdaUtils.buildLambdaParserConfig(cip));
GraphBuilderPhase.Instance lambdaParserPhase = graphBuilderSupplier.apply(buildLambdaParserConfig(cip));
HighTierContext context = new HighTierContext(providers, null, OptimisticOptimizations.NONE);
lambdaParserPhase.apply(graph, context);
} catch (Throwable e) {
Expand Down Expand Up @@ -171,44 +170,4 @@ public static String digest(String value) {
public static String capturingClass(String className) {
return className.split(LambdaUtils.SERIALIZATION_TEST_LAMBDA_CLASS_SPLIT_PATTERN)[0];
}

private static final class LambdaGraphBuilder extends GraphBuilderPhase {

private LambdaGraphBuilder(GraphBuilderConfiguration config) {
super(config);
}

@Override
protected GraphBuilderPhase.Instance createInstance(CoreProviders providers, GraphBuilderConfiguration instanceGBConfig, OptimisticOptimizations optimisticOpts,
IntrinsicContext initialIntrinsicContext) {
return new Instance(providers, instanceGBConfig, optimisticOpts, initialIntrinsicContext);
}

private static class Instance extends GraphBuilderPhase.Instance {
Instance(CoreProviders providers, GraphBuilderConfiguration instanceGBConfig, OptimisticOptimizations optimisticOpts, IntrinsicContext initialIntrinsicContext) {
super(providers, instanceGBConfig, optimisticOpts, initialIntrinsicContext);
}

@Override
protected BytecodeParser createBytecodeParser(StructuredGraph graph, BytecodeParser parent, ResolvedJavaMethod method, int entryBCI, IntrinsicContext intrinsicContext) {
return new LambdaBytecodeParser(this, graph, parent, method, entryBCI, intrinsicContext);
}
}
}

private static class LambdaBytecodeParser extends BytecodeParser {

LambdaBytecodeParser(GraphBuilderPhase.Instance instance, StructuredGraph graph, BytecodeParser parent, ResolvedJavaMethod method, int entryBCI, IntrinsicContext intrinsicContext) {
super(instance, graph, parent, method, entryBCI, intrinsicContext);
}

@Override
protected Object lookupConstant(int cpi, int opcode, boolean allowBootstrapMethodInvocation) {
/*
* Native Image forces bootstrap method invocation at build time until support has been
* added for doing the invocation at runtime (GR-45806)
*/
return super.lookupConstant(cpi, opcode, true);
}
}
}
Loading