C2: Memory Barrier IR nodes not eliminated for stable array element access

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Unresolved
    • Priority: P4
    • 27
    • Affects Version/s: None
    • Component/s: hotspot

      In cases where there is a constant in a stable object array, some IR nodes describing memory barriers are not eliminated despite the fact that access could be constant folded and the load is indeed elided.

      static final List<Integer> LAZY_LIST = List.ofLazy(1, _ -> THE_VALUE);

          @Test
          @IR(failOn = { IRNode.LOAD, IRNode.MEMBAR })
          static int foldLazyList() {
              // Access should be folded.
              // No barriers expected for a folded access (as opposed to a non-folded).
              return LAZY_LIST.get(0);
          }

      Compilations (2) of Failed Methods (2)
      --------------------------------------
      1) Compilation of "static int compiler.c2.irTests.stable.LazyConstantTest.foldLazyList()":
      > Phase "PrintIdeal":
      AFTER: PrintIdeal
         0 Root === 0 157 [[ 0 1 3 156 ]] inner
         1 Con === 0 [[ ]] #top
         3 Start === 3 0 [[ 3 5 6 7 8 9 ]] #{0:control, 1:abIO, 2:memory, 3:rawptr:BotPTR, 4:return_address}
         5 Parm === 3 [[ 114 ]] Control !jvms: LazyConstantTest::foldLazyList @ bci:-1 (line 78)
         6 Parm === 3 [[ 157 ]] I_O !jvms: LazyConstantTest::foldLazyList @ bci:-1 (line 78)
         7 Parm === 3 [[ 114 ]] Memory Memory: @ptr:BotPTR+bot, idx=Bot; !jvms: LazyConstantTest::foldLazyList @ bci:-1 (line 78)
         8 Parm === 3 [[ 157 ]] FramePtr !jvms: LazyConstantTest::foldLazyList @ bci:-1 (line 78)
         9 Parm === 3 [[ 157 ]] ReturnAdr !jvms: LazyConstantTest::foldLazyList @ bci:-1 (line 78)
       114 MemBarCPUOrder === 5 1 7 1 1 [[ 115 116 ]] !jvms: LazyCollections$LazyList::contentsAcquire @ bci:8 (line 136) LazyCollections$LazyList::get @ bci:13 (line 82) LazyConstantTest::foldLazyList @ bci:4 (line 78)
       115 Proj === 114 [[ 122 ]] #0 !jvms: LazyCollections$LazyList::contentsAcquire @ bci:8 (line 136) LazyCollections$LazyList::get @ bci:13 (line 82) LazyConstantTest::foldLazyList @ bci:4 (line 78)
       116 Proj === 114 [[ 122 ]] #2 Memory: @ptr:BotPTR+bot, idx=Bot; !jvms: LazyCollections$LazyList::contentsAcquire @ bci:8 (line 136) LazyCollections$LazyList::get @ bci:13 (line 82) LazyConstantTest::foldLazyList @ bci:4 (line 78)
       122 MemBarCPUOrder === 115 1 116 1 1 [[ 123 124 ]] !jvms: LazyCollections$LazyList::contentsAcquire @ bci:8 (line 136) LazyCollections$LazyList::get @ bci:13 (line 82) LazyConstantTest::foldLazyList @ bci:4 (line 78)
       123 Proj === 122 [[ 126 ]] #0 !jvms: LazyCollections$LazyList::contentsAcquire @ bci:8 (line 136) LazyCollections$LazyList::get @ bci:13 (line 82) LazyConstantTest::foldLazyList @ bci:4 (line 78)
       124 Proj === 122 [[ 126 ]] #2 Memory: @ptr:BotPTR+bot, idx=Bot; !jvms: LazyCollections$LazyList::contentsAcquire @ bci:8 (line 136) LazyCollections$LazyList::get @ bci:13 (line 82) LazyConstantTest::foldLazyList @ bci:4 (line 78)
       126 MemBarAcquire === 123 1 124 1 1 [[ 127 128 ]] !jvms: LazyCollections$LazyList::contentsAcquire @ bci:8 (line 136) LazyCollections$LazyList::get @ bci:13 (line 82) LazyConstantTest::foldLazyList @ bci:4 (line 78)
       127 Proj === 126 [[ 157 ]] #0 !jvms: LazyCollections$LazyList::contentsAcquire @ bci:8 (line 136) LazyCollections$LazyList::get @ bci:13 (line 82) LazyConstantTest::foldLazyList @ bci:4 (line 78)
       128 Proj === 126 [[ 157 ]] #2 Memory: @ptr:BotPTR+bot, idx=Bot; !jvms: LazyCollections$LazyList::contentsAcquire @ bci:8 (line 136) LazyCollections$LazyList::get @ bci:13 (line 82) LazyConstantTest::foldLazyList @ bci:4 (line 78)
       156 ConI === 0 [[ 157 ]] #int:42
       157 Return === 127 6 128 8 9 returns 156 [[ 0 ]]

      It appears to be the case that such fences _do_ get eliminated if we do a stable _field access_ but not an _array access_.

      A complete reproducer can be found here:

      https://github.com/openjdk/jdk/blob/eb2c2974e3cf2d1d4d28f9cd935363d13e8a3b93/test/hotspot/jtreg/compiler/c2/irTests/stable/LazyConstantsIrTest.java

            Assignee:
            Unassigned
            Reporter:
            Per-Ake Minborg
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: