Skip to content

Commit

Permalink
Rearrange test to make it more robust.
Browse files Browse the repository at this point in the history
  • Loading branch information
axel22 committed Sep 9, 2020
1 parent f116db3 commit 3dae02e
Showing 1 changed file with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@
*/
package org.graalvm.compiler.core.test;

import org.graalvm.compiler.debug.DebugContext;
import org.graalvm.compiler.nodes.IfNode;
import org.graalvm.compiler.nodes.calc.ObjectEqualsNode;
import org.junit.Test;

import jdk.vm.ci.meta.ResolvedJavaMethod;

public class IntegerBoxEqualsTest extends SubprocessTest {

class Cell<V> {
private final V value;
class Cell {
private final Integer value;

Cell(V value) {
Cell(Integer value) {
this.value = value;
}

Expand All @@ -48,25 +48,24 @@ public String check(Integer i) {
}
}

public static boolean cellGet(Cell<Integer> cell, Integer value) {
public static boolean cellGet(Cell cell, Integer value) {
return cell.check(value).length() == 0;
}

public void cellTest() {
final Integer value = 19112;
final Cell<Integer> cell = new Cell<>(value);
final Integer value = 1911;
final Cell cell = new Cell(value);
ResolvedJavaMethod get = getResolvedJavaMethod(IntegerBoxEqualsTest.class, "cellGet");
for (int i = 0; i < 2000; i++) {
for (int j = 0; j < 20; j++) {
cellGet(cell, i);
for (int k = 0; k < 20; k++) {
cellGet(cell, k);
}
cellGet(cell, value);
}
test(get, null, cell, 0);
if (lastCompiledGraph.getNodes().filter(ObjectEqualsNode.class).count() != 0) {
DebugContext.forCurrentThread().forceDump(lastCompiledGraph, "comparisons");
}
assertTrue(lastCompiledGraph.getNodes().filter(ObjectEqualsNode.class).count() == 0, "There must be no reference comparisons in the graph.");
test(get, null, cell, value);
final int equalsCount = lastCompiledGraph.getNodes().filter(ObjectEqualsNode.class).count();
final int ifCount = lastCompiledGraph.getNodes().filter(IfNode.class).count();
assertTrue(equalsCount == 0 || ifCount > 1, "There must be no reference comparisons in the graph, or everything reachable in equals.");
}

@Test
Expand Down

0 comments on commit 3dae02e

Please sign in to comment.