JDK-8199885 : [Graal] org.graalvm.compiler.core.test.CountedLoopTest fails with "ControlFlowAnchor should never be cloned in the same graph"
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 11
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2018-03-20
  • Updated: 2019-09-13
  • Resolved: 2018-09-26
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 12
12 b14Fixed
Related Reports
Relates :  
Description
org.graalvm.compiler.core.test.CountedLoopTest ran with Graal as JIT fails with "ControlFlowAnchor should never be cloned in the same graph"
assertion when running using latest jdk/hs fastdebug bits. The full error log is

org.graalvm.compiler.core.test.CountedLoopTest started (1 of 1)
  incrementEq1: Passed
  incrementEq2: Passed
  incrementEq3: Passed
  incrementEq4: Passed
  incrementEq5: Passed
  incrementEq6: Passed
  incrementEq7: Dumping debug output in /home/katya/work/JavaSE/Hotspot/ws/jdk.hs/open/src/jdk.internal.vm.compiler/share/dumps/1521571093746
Thread[JVMCI CompilerThread0,9,system]: Compilation of org.graalvm.compiler.core.test.CountedLoopTest.incrementEqSnippet(int, int, int) failed: java.lang.AssertionError: 54|ControlFlowAnchor should never be cloned in the same graph
        at jdk.internal.vm.compiler@11-internal/org.graalvm.compiler.nodes.debug.ControlFlowAnchorNode.afterClone(ControlFlowAnchorNode.java:66)
        at jdk.internal.vm.compiler@11-internal/org.graalvm.compiler.graph.Node.clone(Node.java:933)
        at jdk.internal.vm.compiler@11-internal/org.graalvm.compiler.graph.NodeClass.createNodeDuplicates(NodeClass.java:899)
        at jdk.internal.vm.compiler@11-internal/org.graalvm.compiler.graph.NodeClass.addGraphDuplicate(NodeClass.java:848)
        at jdk.internal.vm.compiler@11-internal/org.graalvm.compiler.graph.Graph.addDuplicates(Graph.java:1252)
        at jdk.internal.vm.compiler@11-internal/org.graalvm.compiler.loop.LoopFragment.patchNodes(LoopFragment.java:178)
        at jdk.internal.vm.compiler@11-internal/org.graalvm.compiler.loop.LoopFragmentInside.insertBefore(LoopFragmentInside.java:135)
        at jdk.internal.vm.compiler@11-internal/org.graalvm.compiler.loop.phases.LoopTransformations.peel(LoopTransformations.java:78)
        at jdk.internal.vm.compiler@11-internal/org.graalvm.compiler.hotspot.phases.OnStackReplacementPhase.run(OnStackReplacementPhase.java:151)
        at jdk.internal.vm.compiler@11-internal/org.graalvm.compiler.phases.Phase.run(Phase.java:47)
        at jdk.internal.vm.compiler@11-internal/org.graalvm.compiler.phases.BasePhase.apply(BasePhase.java:195)
        at jdk.internal.vm.compiler@11-internal/org.graalvm.compiler.phases.BasePhase.apply(BasePhase.java:137)
        at jdk.internal.vm.compiler@11-internal/org.graalvm.compiler.phases.PhaseSuite.run(PhaseSuite.java:210)
        at jdk.internal.vm.compiler@11-internal/org.graalvm.compiler.phases.BasePhase.apply(BasePhase.java:195)
        at jdk.internal.vm.compiler@11-internal/org.graalvm.compiler.phases.BasePhase.apply(BasePhase.java:137)
        at jdk.internal.vm.compiler@11-internal/org.graalvm.compiler.core.GraalCompiler.emitFrontEnd(GraalCompiler.java:222)
        at jdk.internal.vm.compiler@11-internal/org.graalvm.compiler.core.GraalCompiler.compile(GraalCompiler.java:172)
        at jdk.internal.vm.compiler@11-internal/org.graalvm.compiler.core.GraalCompiler.compileGraph(GraalCompiler.java:158)
        at jdk.internal.vm.compiler@11-internal/org.graalvm.compiler.hotspot.HotSpotGraalCompiler.compileHelper(HotSpotGraalCompiler.java:189)
        at jdk.internal.vm.compiler@11-internal/org.graalvm.compiler.hotspot.HotSpotGraalCompiler.compile(HotSpotGraalCompiler.java:202)
        at jdk.internal.vm.compiler@11-internal/org.graalvm.compiler.hotspot.CompilationTask$HotSpotCompilationWrapper.performCompilation(CompilationTask.java:169)
        at jdk.internal.vm.compiler@11-internal/org.graalvm.compiler.hotspot.CompilationTask$HotSpotCompilationWrapper.performCompilation(CompilationTask.java:94)
        at jdk.internal.vm.compiler@11-internal/org.graalvm.compiler.core.CompilationWrapper.run(CompilationWrapper.java:165)
        at jdk.internal.vm.compiler@11-internal/org.graalvm.compiler.hotspot.CompilationTask.runCompilation(CompilationTask.java:317)
        at jdk.internal.vm.compiler@11-internal/org.graalvm.compiler.hotspot.HotSpotGraalCompiler.compileMethod(HotSpotGraalCompiler.java:142)
        at jdk.internal.vm.compiler@11-internal/org.graalvm.compiler.hotspot.HotSpotGraalCompiler.compileMethod(HotSpotGraalCompiler.java:108)
        at jdk.internal.vm.ci/jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.compileMethod(HotSpotJVMCIRuntime.java:443)


The test doesn't fail in case Graal as JIT is not used (-XX:+TieredCompilation -XX:+UseJVMCICompiler -Djvmci.Compiler=graal).

 
Comments
I had a look already but i couldn't make any sense of it: it seems to be "impossible" to reach that state. I would need to reproduce but it doesn't when we run it from our side. I'll try to reproduce in the jdk repository.
14-08-2018

[~gdub], this looks like a bug in CountedLoopTest right?
14-08-2018

[~dnsimon], it looks like org.graalvm.compiler.core.test.CountedLoopTest intermittently fails even when running with disabled graal . It fails with NullPointerException: org.graalvm.compiler.core.test.CountedLoopTest started (32 of 137) incrementEq1: Passed 350.4 ms incrementEq2: Passed 103.8 ms incrementEq3: Passed 100.4 ms incrementEq4: Passed 104.8 ms incrementEq5: Passed 54.3 ms incrementEq6: Passed 79.5 ms incrementEq7: Passed 5650.8 ms incrementEq8: Passed 4223.9 ms incrementNeq: Passed 130.4 ms testTwoVariables: Passed 116.9 ms increment1: Passed 227.7 ms increment2: Passed 68.3 ms increment3: Passed 95.2 ms increment4: Passed 51.6 ms increment5: Passed 73.1 ms increment6: Passed 80.8 ms increment7: Passed 5772.9 ms increment8: Passed 4092.9 ms decrement1: Passed 191.7 ms decrement2: Passed 122.6 ms decrement3: Passed 115.0 ms decrement4: Passed 8164.2 ms decrement5: Passed 4532.2 ms incrementLong1: Passed 137.1 ms incrementLong2: Passed 108.4 ms incrementLong3: Passed 79.4 ms incrementLong4: Passed 78.3 ms incrementLong5: Passed 60.5 ms incrementLong6: Passed 56.5 ms decrementEq1: Passed 140.8 ms decrementEq2: Passed 86.1 ms decrementEq3: Passed 67.6 ms decrementEq4: Passed 53.3 ms decrementEq5: FAILED decrementEq5(org.graalvm.compiler.core.test.CountedLoopTest) java.lang.NullPointerException at jdk.internal.vm.compiler@12-internal/org.graalvm.compiler.loop.BasicInductionVariable.isConstantExtremum(BasicInductionVariable.java:174) at org.graalvm.compiler.core.test.CountedLoopTest$IVPropertyNode.rewrite(CountedLoopTest.java:417) at org.graalvm.compiler.core.test.CountedLoopTest.checkHighTierGraph(CountedLoopTest.java:487) at org.graalvm.compiler.core.test.GraalCompilerTest$2.run(GraalCompilerTest.java:287) at jdk.internal.vm.compiler@12-internal/org.graalvm.compiler.phases.Phase.run(Phase.java:49) at jdk.internal.vm.compiler@12-internal/org.graalvm.compiler.phases.BasePhase.apply(BasePhase.java:197) at jdk.internal.vm.compiler@12-internal/org.graalvm.compiler.phases.BasePhase.apply(BasePhase.java:139) at jdk.internal.vm.compiler@12-internal/org.graalvm.compiler.phases.PhaseSuite.run(PhaseSuite.java:212) at jdk.internal.vm.compiler@12-internal/org.graalvm.compiler.phases.BasePhase.apply(BasePhase.java:197) at jdk.internal.vm.compiler@12-internal/org.graalvm.compiler.phases.BasePhase.apply(BasePhase.java:139) at jdk.internal.vm.compiler@12-internal/org.graalvm.compiler.core.GraalCompiler.emitFrontEnd(GraalCompiler.java:256) at jdk.internal.vm.compiler@12-internal/org.graalvm.compiler.core.GraalCompiler.compile(GraalCompiler.java:180) at org.graalvm.compiler.core.test.GraalCompilerTest.compile(GraalCompilerTest.java:1060) at org.graalvm.compiler.core.test.GraalCompilerTest.getCode(GraalCompilerTest.java:957) at org.graalvm.compiler.core.test.GraalCompilerTest.getCode(GraalCompilerTest.java:898) at org.graalvm.compiler.core.test.GraalCompilerTest.executeActual(GraalCompilerTest.java:734) at org.graalvm.compiler.core.test.GraalCompilerTest.executeActualCheckDeopt(GraalCompilerTest.java:866) at org.graalvm.compiler.core.test.GraalCompilerTest.testAgainstExpected(GraalCompilerTest.java:856) at org.graalvm.compiler.core.test.GraalCompilerTest.testAgainstExpected(GraalCompilerTest.java:852) at org.graalvm.compiler.core.test.GraalCompilerTest.test(GraalCompilerTest.java:821) at org.graalvm.compiler.core.test.GraalCompilerTest.test(GraalCompilerTest.java:790) at org.graalvm.compiler.core.test.GraalCompilerTest.test(GraalCompilerTest.java:783) at org.graalvm.compiler.core.test.CountedLoopTest.testCounted(CountedLoopTest.java:503) at org.graalvm.compiler.core.test.CountedLoopTest.decrementEq5(CountedLoopTest.java:292) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runners.Suite.runChild(Suite.java:128) at org.junit.runners.Suite.runChild(Suite.java:27) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at org.junit.runner.JUnitCore.run(JUnitCore.java:115) at com.oracle.mxtool.junit.MxJUnitWrapper.runRequest(MxJUnitWrapper.java:280) at com.oracle.mxtool.junit.MxJUnitWrapper.main(MxJUnitWrapper.java:196)
14-08-2018

Yes, that's the best approach for now.
10-08-2018

[~dnsimon], all org.graalvm.compiler.core.test.* tests except following two subclass GraalCompilerTest: org.graalvm.compiler.core.test.tutorial.GraalTutorial org.graalvm.compiler.core.test.StaticInterfaceFieldTest Should these two tests also run only with disabled graal (-XX:-UseJVMCICompiler) ?
09-08-2018

As Gilles states, most (all?) tests that subclass GraalCompilerTest should be run with -XX:-UseJVMCICompiler since that is the mode for which these tests were designed. At some point, these tests will have to be investigated to see how they (or Graal) should be modified such that they can run with -XX:+UseJVMCICompiler, especially that is intended to become the default one day.
29-05-2018

The same failure mode exists on JDK 8 already: most of those tests (Graal's JTTs and GraalCompilerTests in general) are not designed to have Graal has the JIT compiler: they use the underlying JVM to get a trusted result and then do an explicit Graal compilation to compare the results. This doesn't test much if Graal is the JIT compiler. In this precise case we get into an problematic situation because the VM requests an OSR compilation of a method that is used as a test snippet and contains a call to GraalDirectives.controlFlowAnchor() in its loop. This node tries to force the compiler to never duplicate it but, as we can see in the stack trace the OSR phase *needs* to duplicate it. I think the path forward is to explicitly silence ControlFlowAnchorNode issues during the OSR phase: either by making it a permanent bailout or by making sure they are skipped during the peeling done by OSR.
23-03-2018

initial ILW = Assert failure; for one CountedLoopTest Graal test, with Graal as JIT; none = HLH = P2
21-03-2018

Hi [~dnsimon], request your help with this bug. Thank you.
21-03-2018

This seems to happen since JDK 9: dsimon@kruger-4 ~/h/g/compiler> java -version java version "1.8.0_161" Java(TM) SE Runtime Environment (build 1.8.0_161-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.71-b01-internal-jvmci-0.41, mixed mode) dsimon@kruger-4 ~/h/g/compiler> mx unittest -XX:+UseJVMCICompiler --no-eager org.graalvm.compiler.core.test.CountedLoopTest MxJUnitCore JUnit version 4.12 .................................... Time: 28.441 OK (36 tests) dsimon@kruger-4 ~/h/g/compiler> java -version java version "9.0.4" Java(TM) SE Runtime Environment (build 9.0.4+11) Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode) dsimon@kruger-4 ~/h/g/compiler> mx unittest -XX:+UseJVMCICompiler --no-eager org.graalvm.compiler.core.test.CountedLoopTest MxJUnitCore JUnit version 4.12 .......Dumping debug output in /Users/dsimon/hs/graal/compiler/dumps/1521635894279 Thread[JVMCI CompilerThread2,9,system]: Compilation of org.graalvm.compiler.core.test.CountedLoopTest.incrementEqSnippet(int, int, int) failed: java.lang.AssertionError: 54|ControlFlowAnchor should never be cloned in the same graph at jdk.internal.vm.compiler/org.graalvm.compiler.nodes.debug.ControlFlowAnchorNode.afterClone(ControlFlowAnchorNode.java:66) at jdk.internal.vm.compiler/org.graalvm.compiler.graph.Node.clone(Node.java:1035) at jdk.internal.vm.compiler/org.graalvm.compiler.graph.NodeClass.createNodeDuplicates(NodeClass.java:899) at jdk.internal.vm.compiler/org.graalvm.compiler.graph.NodeClass.addGraphDuplicate(NodeClass.java:848) at jdk.internal.vm.compiler/org.graalvm.compiler.graph.Graph.addDuplicates(Graph.java:1279) at jdk.internal.vm.compiler/org.graalvm.compiler.loop.LoopFragment.patchNodes(LoopFragment.java:178) at jdk.internal.vm.compiler/org.graalvm.compiler.loop.LoopFragmentInside.insertBefore(LoopFragmentInside.java:135) at jdk.internal.vm.compiler/org.graalvm.compiler.loop.phases.LoopTransformations.peel(LoopTransformations.java:78) at jdk.internal.vm.compiler/org.graalvm.compiler.hotspot.phases.OnStackReplacementPhase.run(OnStackReplacementPhase.java:153) at jdk.internal.vm.compiler/org.graalvm.compiler.phases.Phase.run(Phase.java:47) at jdk.internal.vm.compiler/org.graalvm.compiler.phases.BasePhase.apply(BasePhase.java:195) at jdk.internal.vm.compiler/org.graalvm.compiler.phases.BasePhase.apply(BasePhase.java:137) at jdk.internal.vm.compiler/org.graalvm.compiler.phases.PhaseSuite.run(PhaseSuite.java:210) at jdk.internal.vm.compiler/org.graalvm.compiler.phases.BasePhase.apply(BasePhase.java:195) at jdk.internal.vm.compiler/org.graalvm.compiler.phases.BasePhase.apply(BasePhase.java:137) at jdk.internal.vm.compiler/org.graalvm.compiler.core.GraalCompiler.emitFrontEnd(GraalCompiler.java:222) at jdk.internal.vm.compiler/org.graalvm.compiler.core.GraalCompiler.compile(GraalCompiler.java:172) at jdk.internal.vm.compiler/org.graalvm.compiler.core.GraalCompiler.compileGraph(GraalCompiler.java:158) at jdk.internal.vm.compiler/org.graalvm.compiler.hotspot.HotSpotGraalCompiler.compileHelper(HotSpotGraalCompiler.java:189) at jdk.internal.vm.compiler/org.graalvm.compiler.hotspot.HotSpotGraalCompiler.compile(HotSpotGraalCompiler.java:202) at jdk.internal.vm.compiler/org.graalvm.compiler.hotspot.CompilationTask$HotSpotCompilationWrapper.performCompilation(CompilationTask.java:179) at jdk.internal.vm.compiler/org.graalvm.compiler.hotspot.CompilationTask$HotSpotCompilationWrapper.performCompilation(CompilationTask.java:1) at jdk.internal.vm.compiler/org.graalvm.compiler.core.CompilationWrapper.run(CompilationWrapper.java:167) at jdk.internal.vm.compiler/org.graalvm.compiler.hotspot.CompilationTask.runCompilation(CompilationTask.java:328) at jdk.internal.vm.compiler/org.graalvm.compiler.hotspot.HotSpotGraalCompiler.compileMethod(HotSpotGraalCompiler.java:142) at jdk.internal.vm.compiler/org.graalvm.compiler.hotspot.HotSpotGraalCompiler.compileMethod(HotSpotGraalCompiler.java:108) at jdk.internal.vm.ci/jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.compileMethod(HotSpotJVMCIRuntime.java:433)
21-03-2018