Skip to content

Commit

Permalink
[GR-25570] Make LoopNode.reportLoopCount() PE to just adding to the l…
Browse files Browse the repository at this point in the history
…oop count in first tier.

PullRequest: graal/6947
  • Loading branch information
eregon committed Sep 1, 2020
2 parents df007aa + a0dc6ff commit 9f4dfc8
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
import org.graalvm.options.OptionDescriptors;
import org.graalvm.options.OptionValues;

import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.impl.Accessor.RuntimeSupport;
import com.oracle.truffle.api.nodes.BlockNode;
import com.oracle.truffle.api.nodes.BlockNode.ElementExecutor;
import com.oracle.truffle.api.nodes.ExplodeLoop;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.RootNode;

Expand All @@ -43,8 +45,11 @@ final class GraalRuntimeSupport extends RuntimeSupport {
super(permission);
}

@ExplodeLoop
@Override
public void onLoopCount(Node source, int count) {
CompilerAsserts.partialEvaluationConstant(source);

Node node = source;
Node parentNode = source != null ? source.getParent() : null;
while (node != null) {
Expand All @@ -54,7 +59,7 @@ public void onLoopCount(Node source, int count) {
parentNode = node;
node = node.getParent();
}
if (parentNode != null && parentNode instanceof RootNode) {
if (parentNode instanceof RootNode) {
CallTarget target = ((RootNode) parentNode).getCallTarget();
if (target instanceof OptimizedCallTarget) {
((OptimizedCallTarget) target).onLoopCount(count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,10 @@ public static VirtualFrame createFrame(FrameDescriptor descriptor, Object[] args
}

final void onLoopCount(int count) {
callAndLoopCount += count;
assert count >= 0;
int oldLoopCallCount = this.callAndLoopCount;
int newLoopCallCount = oldLoopCallCount + count;
this.callAndLoopCount = newLoopCallCount >= oldLoopCallCount ? newLoopCallCount : Integer.MAX_VALUE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ public Object execute(VirtualFrame frame) {
}
return status;
} finally {
if (CompilerDirectives.inInterpreter()) {
reportLoopCount(this, loopCount);
}
reportLoopCount(this, loopCount);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import java.util.Objects;

import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import org.graalvm.compiler.truffle.options.PolyglotCompilerOptions;
import org.graalvm.options.OptionValues;

Expand Down Expand Up @@ -175,7 +174,6 @@ private Object profilingLoop(VirtualFrame frame) {
}
}

@TruffleBoundary
private void reportParentLoopCount(int iterations) {
Node parent = getParent();
if (parent != null) {
Expand Down
1 change: 1 addition & 0 deletions truffle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This changelog summarizes major changes between Truffle versions relevant to lan
* All instances of `TruffleContext` accessible from instruments can now be closed by the instrument. Previously this was only possible for creators of the TruffleContext instance.
* Added the ability to create context and context thread locals in languages and instruments. See [ContextLocal](https://www.graalvm.org/truffle/javadoc/com/oracle/truffle/api/ContextLocal.html) and [ContextThreadLocal](https://www.graalvm.org/truffle/javadoc/com/oracle/truffle/api/ContextThreadLocal.html) for details.
* Removed the hard "maximum node count" splitting limit controlled by `TruffleSplittingMaxNumberOfSplitNodes` as well as the option itself.
* The `iterations` for `LoopNode.reportLoopCount(source, iterations)` must now be >= 0.

## Version 20.2.0
* Added new internal engine option `ShowInternalStackFrames` to show internal frames specific to the language implementation in stack traces.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
package com.oracle.truffle.api.nodes;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.TruffleRuntime;
import com.oracle.truffle.api.frame.VirtualFrame;

Expand Down Expand Up @@ -198,13 +199,23 @@ public Object execute(VirtualFrame frame) {
* </p>
*
* @param source the Node which invoked the loop.
* @param iterations the number iterations to report to the runtime system
* @param iterations the number iterations to report to the runtime system, must be >= 0
* @since 0.12
*/
public static void reportLoopCount(Node source, int iterations) {
if (CompilerDirectives.inInterpreter()) {
NodeAccessor.RUNTIME.onLoopCount(source, iterations);
assert iterations >= 0;
if (CompilerDirectives.inInterpreter() || NodeAccessor.RUNTIME.inFirstTier()) {
if (CompilerDirectives.isPartialEvaluationConstant(source)) {
NodeAccessor.RUNTIME.onLoopCount(source, iterations);
} else {
onLoopCountBoundary(source, iterations);
}
}
}

@TruffleBoundary
private static void onLoopCountBoundary(Node source, int iterations) {
NodeAccessor.RUNTIME.onLoopCount(source, iterations);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public abstract class RootNode extends ExecutableNode {

private static final AtomicReferenceFieldUpdater<RootNode, ReentrantLock> LOCK_UPDATER = AtomicReferenceFieldUpdater.newUpdater(RootNode.class, ReentrantLock.class, "lock");

private volatile RootCallTarget callTarget;
@CompilationFinal private volatile RootCallTarget callTarget;
@CompilationFinal private FrameDescriptor frameDescriptor;
private volatile ReentrantLock lock;

Expand Down

0 comments on commit 9f4dfc8

Please sign in to comment.