Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gluon-bot committed Oct 5, 2023
2 parents 99f0e04 + 55b8e06 commit 4845fc3
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 18 deletions.
6 changes: 4 additions & 2 deletions docs/reference-manual/java-on-truffle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ You can download a standalone based on Oracle GraalVM or GraalVM Community Editi

3. A standalone comes with a JVM in addition to its native launcher. Check the version to see the Java on Truffle runtime is active:
```shell
./path/to/bin/java -truffle --version
# Path to Java on Truffle (Espresso) installation
./path/to/bin/java -truffle -version
```

## Run Java on Truffle
Expand Down Expand Up @@ -99,7 +100,8 @@ This might be important for options such as `MaxDirectMemorySize` which can be s
To ensure you have successfully installed Java on Truffle, verify its version:
```shell
java -truffle -version
# Path to Java on Truffle (Espresso) installation
./path/to/bin/java -truffle -version
```
Taking this `HelloWorld.java` example, compile it and run from the command line:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1474,7 +1474,7 @@ protected void processMethodInvocation(TypeFlowsOfNodes state, Invoke invoke, In
}

/* Get a reasonable position for inlined invokes, avoiding cycles in the parsing backtrace. */
private BytecodePosition getInvokePosition(FixedNode invokeNode) {
protected BytecodePosition getInvokePosition(FixedNode invokeNode) {
BytecodePosition invokePosition = invokeNode.getNodeSourcePosition();
/* Get the outermost caller position for inlined invokes. */
while (invokePosition != null && invokePosition.getCaller() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -927,19 +927,27 @@ private void waitOnLock(ReentrantLock lock) {
}
}

public StructuredGraph decodeAnalyzedGraph(DebugContext debug, Iterable<EncodedNodeReference> nodeReferences) {
if (analyzedGraph == null) {
return null;
}

return decodeAnalyzedGraph(debug, nodeReferences, analyzedGraph.trackNodeSourcePosition());
}

/**
* Returns the {@link StructuredGraph Graal IR} for the method that has been processed by the
* static analysis.
*/
public StructuredGraph decodeAnalyzedGraph(DebugContext debug, Iterable<EncodedNodeReference> nodeReferences) {
public StructuredGraph decodeAnalyzedGraph(DebugContext debug, Iterable<EncodedNodeReference> nodeReferences, boolean trackNodeSourcePosition) {
if (analyzedGraph == null) {
return null;
}

var allowAssumptions = getUniverse().hostVM().allowAssumptions(this);
// Note we never record inlined methods. This is correct even for runtime compiled methods
StructuredGraph result = new StructuredGraph.Builder(debug.getOptions(), debug, allowAssumptions).method(this).recordInlinedMethods(false).trackNodeSourcePosition(
analyzedGraph.trackNodeSourcePosition()).build();
trackNodeSourcePosition).build();
GraphDecoder decoder = new GraphDecoder(AnalysisParsedGraph.HOST_ARCHITECTURE, result);
decoder.decode(analyzedGraph, nodeReferences);
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ protected InlineBeforeAnalysisMethodScope cast(MethodScope methodScope) {
@Override
protected FixedWithNextNode afterMethodScopeCreation(PEMethodScope is, FixedWithNextNode predecessor) {
InlineBeforeAnalysisMethodScope inlineScope = cast(is);
return policy.processInvokeArgs(inlineScope.method, predecessor, inlineScope.getArguments());
var sourcePosition = inlineScope.invokeData.invoke.asNode().getNodeSourcePosition();
return policy.processInvokeArgs(inlineScope.method, predecessor, inlineScope.getArguments(), sourcePosition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package com.oracle.graal.pointsto.phases;

import org.graalvm.compiler.graph.Node;
import org.graalvm.compiler.graph.NodeSourcePosition;
import org.graalvm.compiler.nodes.FixedWithNextNode;
import org.graalvm.compiler.nodes.ValueNode;
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
Expand Down Expand Up @@ -93,7 +94,7 @@ protected InlineBeforeAnalysisPolicy(NodePlugin[] nodePlugins) {

protected abstract boolean tryInvocationPlugins();

protected abstract FixedWithNextNode processInvokeArgs(ResolvedJavaMethod targetMethod, FixedWithNextNode insertionPoint, ValueNode[] arguments);
protected abstract FixedWithNextNode processInvokeArgs(ResolvedJavaMethod targetMethod, FixedWithNextNode insertionPoint, ValueNode[] arguments, NodeSourcePosition sourcePosition);

protected abstract AbstractPolicyScope createRootScope();

Expand Down Expand Up @@ -132,7 +133,7 @@ protected boolean tryInvocationPlugins() {
}

@Override
protected FixedWithNextNode processInvokeArgs(ResolvedJavaMethod targetMethod, FixedWithNextNode insertionPoint, ValueNode[] arguments) {
protected FixedWithNextNode processInvokeArgs(ResolvedJavaMethod targetMethod, FixedWithNextNode insertionPoint, ValueNode[] arguments, NodeSourcePosition sourcePosition) {
throw AnalysisError.shouldNotReachHere("NO_INLINING policy should not try to inline");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,8 @@ public class SubstrateGraphKit extends GraphKit {
private final FrameStateBuilder frameState;
private int nextBCI;

// For GR-45916 this should be unconditionally true when parseOnce is enabled.
private static boolean trackNodeSourcePosition(boolean forceTrackNodeSourcePosition) {
return forceTrackNodeSourcePosition || (SubstrateOptions.parseOnce() && !SubstrateOptions.ParseOnceJIT.getValue());
return forceTrackNodeSourcePosition || SubstrateOptions.parseOnce();
}

@SuppressWarnings("this-escape")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.graalvm.compiler.debug.DebugHandlersFactory;
import org.graalvm.compiler.debug.Indent;
import org.graalvm.compiler.graph.NodeClass;
import org.graalvm.compiler.graph.NodeSourcePosition;
import org.graalvm.compiler.java.BytecodeParser;
import org.graalvm.compiler.java.GraphBuilderPhase;
import org.graalvm.compiler.loop.phases.ConvertDeoptimizeToGuardPhase;
Expand Down Expand Up @@ -569,7 +570,7 @@ private void compileRuntimeCompiledMethod(DebugContext debug, HostedMethod metho
assert method.getMultiMethodKey() == RUNTIME_COMPILED_METHOD;

AnalysisMethod aMethod = method.getWrapped();
StructuredGraph graph = aMethod.decodeAnalyzedGraph(debug, null);
StructuredGraph graph = aMethod.decodeAnalyzedGraph(debug, null, false);
if (graph == null) {
throw VMError.shouldNotReachHere("Method not parsed during static analysis: " + aMethod.format("%r %H.%n(%p)"));
}
Expand Down Expand Up @@ -1021,9 +1022,10 @@ protected boolean needsExplicitExceptions() {
}

@Override
protected FixedWithNextNode processInvokeArgs(ResolvedJavaMethod targetMethod, FixedWithNextNode insertionPoint, ValueNode[] arguments) {
protected FixedWithNextNode processInvokeArgs(ResolvedJavaMethod targetMethod, FixedWithNextNode insertionPoint, ValueNode[] arguments, NodeSourcePosition sourcePosition) {
StructuredGraph graph = insertionPoint.graph();
InlinedInvokeArgumentsNode newNode = graph.add(new InlinedInvokeArgumentsNode(targetMethod, arguments));
newNode.setNodeSourcePosition(sourcePosition);
graph.addAfterFixed(insertionPoint, newNode);
return newNode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ public void initializeRuntimeCompilationConfiguration(HostedProviders newHostedP
runtimeCompilationCandidatePredicateUpdated = true;
deoptimizeOnExceptionPredicate = newDeoptimizeOnExceptionPredicate;

if (SubstrateOptions.IncludeNodeSourcePositions.getValue()) {
if (SubstrateOptions.IncludeNodeSourcePositions.getValue() || SubstrateOptions.parseOnce()) {
graphBuilderConfig = graphBuilderConfig.withNodeSourcePosition(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,7 @@ private void processInlinedInvokeArgumentsNode(TypeFlowsOfNodes state, InlinedIn
* Create a proxy invoke type flow for the inlined method.
*/
PointsToAnalysisMethod targetMethod = (PointsToAnalysisMethod) node.getInvokeTarget();
// GR-45916 add proper source position information.
BytecodePosition position = AbstractAnalysisEngine.syntheticSourcePosition(node, method);
InvokeKind invokeKind = targetMethod.isStatic() ? InvokeKind.Static : InvokeKind.Special;
processMethodInvocation(state, node, invokeKind, targetMethod, node.getArguments(), true, position, true);
processMethodInvocation(state, node, invokeKind, targetMethod, node.getArguments(), true, getInvokePosition(node), true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package com.oracle.svm.hosted.classinitialization;

import org.graalvm.compiler.graph.Node;
import org.graalvm.compiler.graph.NodeSourcePosition;
import org.graalvm.compiler.nodes.FixedWithNextNode;
import org.graalvm.compiler.nodes.ValueNode;
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
Expand Down Expand Up @@ -139,7 +140,7 @@ protected InlineInvokePlugin.InlineInfo createInvokeInfo(ResolvedJavaMethod meth
}

@Override
protected FixedWithNextNode processInvokeArgs(ResolvedJavaMethod targetMethod, FixedWithNextNode insertionPoint, ValueNode[] arguments) {
protected FixedWithNextNode processInvokeArgs(ResolvedJavaMethod targetMethod, FixedWithNextNode insertionPoint, ValueNode[] arguments, NodeSourcePosition sourcePosition) {
// No action is needed
return insertionPoint;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
package com.oracle.svm.hosted.phases;

import org.graalvm.compiler.graph.NodeSourcePosition;
import org.graalvm.compiler.nodes.FixedWithNextNode;
import org.graalvm.compiler.nodes.ValueNode;
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
Expand Down Expand Up @@ -117,7 +118,7 @@ protected boolean shouldOmitIntermediateMethodInState(ResolvedJavaMethod method)
}

@Override
protected FixedWithNextNode processInvokeArgs(ResolvedJavaMethod targetMethod, FixedWithNextNode insertionPoint, ValueNode[] arguments) {
protected FixedWithNextNode processInvokeArgs(ResolvedJavaMethod targetMethod, FixedWithNextNode insertionPoint, ValueNode[] arguments, NodeSourcePosition sourcePosition) {
// No action is needed
return insertionPoint;
}
Expand Down

0 comments on commit 4845fc3

Please sign in to comment.