Skip to content

Commit

Permalink
partial escape phase: try to respect ensure virtualized in loop depth…
Browse files Browse the repository at this point in the history
… nest mode
  • Loading branch information
davleopo committed Jul 24, 2020
1 parent 3791c35 commit de281d7
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,52 @@ public static class C {
}
}

/**
* Very deep loop nests, once {@linkplain GraalOptions#EscapeAnalysisLoopCutoff} is reached, no
* new virtualizations are performed. We check this by ensuring that the allocations of B >
* level remain
*/
public static int method20LevelNoNewAllocationsEnsureVirtualized(int a) {
if (a == 0) {
return 0;
}
int res = 0;
for (int i = 0; i < a; i++) {
res += new A(method20LevelNoNewAllocations1EnsureVirtualized(20)).x;
}
return res;
}

public static int method20LevelNoNewAllocations1EnsureVirtualized(int a) {
if (GraalDirectives.injectBranchProbability(0.01D, a == 0)) {
B b = new B(a);
GraalDirectives.ensureVirtualized(b);
return b.x;
}
int res = 0;
for (int i = 0; i < IntSideEffect; i++) {
res += new A(method20LevelNoNewAllocations1EnsureVirtualized(a - 1)).x;
}
return res;
}

/**
* Test that the depth cutoff of partial escape analysis triggers after the correct loop depth
* and that no new virtualizations are performed once we reach a certain depth.
*/
@Test
public void testNoNewAllocationsEnsureVirtualized() {
method20LevelNoNewAllocations(0);
method20LevelNoNewAllocations(1);
method20LevelNoNewAllocations1(0);
method20LevelNoNewAllocations1(1);
/*
* 2 remaining allocations = 1 times the >= depth level allocation of a and one allocations
* of b inside
*/
testAndTimeFixedDepth("method20LevelNoNewAllocationsEnsureVirtualized", 1);
}

/**
* Very deep loop nests, once {@linkplain GraalOptions#EscapeAnalysisLoopCutoff} is reached, no
* new virtualizations are performed. We check this by ensuring that the allocations of B >
Expand Down Expand Up @@ -121,7 +167,7 @@ public void testNoNewAllocations() {
method20LevelNoNewAllocations1(0);
method20LevelNoNewAllocations1(1);
/*
* 3 remaining allocations = 1 times the >= depth level allocation of a and all allocations
* 2 remaining allocations = 1 times the >= depth level allocation of a and one allocations
* of b inside
*/
testAndTimeFixedDepth("method20LevelNoNewAllocations", 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import org.graalvm.compiler.nodes.spi.VirtualizableAllocation;
import org.graalvm.compiler.nodes.spi.VirtualizerTool;
import org.graalvm.compiler.nodes.virtual.AllocatedObjectNode;
import org.graalvm.compiler.nodes.virtual.EnsureVirtualizedNode;
import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
import org.graalvm.compiler.virtual.nodes.VirtualObjectState;

Expand Down Expand Up @@ -249,11 +250,20 @@ private boolean processVirtualizable(ValueNode node, FixedNode insertBefore, Blo
break;
case STOP_NEW_VIRTUALIZATIONS_LOOP_NEST:
if (node instanceof VirtualizableAllocation) {
/*
* Do not try to do new devirtualizations of allocations after we reached a
* certain loop nest.
*/
return false;
boolean mayEnsureVirtualized = false;
for (Node usage : node.usages()) {
if (usage instanceof EnsureVirtualizedNode) {
mayEnsureVirtualized = true;
break;
}
}
if (!mayEnsureVirtualized) {
/*
* Do not try to do new devirtualizations of allocations after we reached a
* certain loop nest.
*/
return false;
}
}
break;
case LOOP_NEST_OVERFLOW:
Expand Down

0 comments on commit de281d7

Please sign in to comment.