Skip to content

Commit

Permalink
[GR-22209] Mitigate against OOME in NodeBenchmark.createAndDeleteAdd.
Browse files Browse the repository at this point in the history
PullRequest: graal/5876
  • Loading branch information
dougxc committed Apr 7, 2020
2 parents 23f94e2 + 969dcaf commit e045810
Showing 1 changed file with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.graalvm.compiler.microbenchmarks.graal.util.NodesState;
import org.graalvm.compiler.microbenchmarks.graal.util.NodesState.NodePair;
import org.graalvm.compiler.nodes.ConstantNode;
import org.graalvm.compiler.nodes.StructuredGraph;
import org.graalvm.compiler.nodes.calc.AddNode;
import org.graalvm.compiler.nodes.util.GraphUtil;

Expand All @@ -46,6 +47,27 @@ public class NodeBenchmark extends GraalBenchmark {
public static class StringEquals extends NodesState {
}

/**
* Variation of {@link StringEquals} that calls {@link StructuredGraph#maybeCompress()} after
* every N iterations. The prevents benchmarks that mutate the graph by adding and removing
* nodes from causing {@link OutOfMemoryError}s.
*/
@MethodSpec(declaringClass = String.class, name = "equals")
public static class StringEqualsWithGraphCompression extends NodesState {
private static final int N = 100_000;

private int latch = N;

@Override
public void afterInvocation() {
super.afterInvocation();
if (--latch == 0) {
graph.maybeCompress();
latch = N;
}
}
}

@Benchmark
@Warmup(iterations = 20)
public int getNodeClass(StringEquals s) {
Expand Down Expand Up @@ -101,15 +123,15 @@ public Node apply(Node t, Node u) {
}

@Benchmark
public void createAndDeleteAdd(StringEquals s, Blackhole bh) {
public void createAndDeleteAdd(StringEqualsWithGraphCompression s, Blackhole bh) {
AddNode addNode = new AddNode(ConstantNode.forInt(40), ConstantNode.forInt(2));
s.graph.addOrUniqueWithInputs(addNode);
GraphUtil.killWithUnusedFloatingInputs(addNode);
bh.consume(addNode);
}

@Benchmark
public void createAndDeleteConstant(StringEquals s, Blackhole bh) {
public void createAndDeleteConstant(StringEqualsWithGraphCompression s, Blackhole bh) {
ConstantNode constantNode = ConstantNode.forInt(42);
s.graph.addOrUnique(constantNode);
GraphUtil.killWithUnusedFloatingInputs(constantNode);
Expand Down

0 comments on commit e045810

Please sign in to comment.