Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8311923

TestIRMatching.java fails on RISC-V

    XMLWordPrintable

Details

    • b07
    • riscv
    • linux

    Backports

      Description


        Hi, we are experiencing test case failure in test test/hotspot/jtreg/testlibrary_tests/ir_framework/tests/TestIRMatching.java:
        ```
        One or more @IR rules failed:

        Failed IR Rules (1) of Methods (1)
        ----------------------------------
        1) Method "public java.lang.Object[] ir_framework.tests.CheckCastArray.arrayCopy(java.lang.Object[],java.lang.Class)" - [Failed IR rules: 1]:
           * @IR rule 1: "@compiler.lib.ir_framework.IR(phase={DEFAULT}, applyIfCPUFeatureAnd={}, applyIf={}, applyIfCPUFeatureOr={}, applyIfCPUFeature={}, counts={}, failOn={"_#CHECKCAST_ARRAYCOPY#_"}, applyIfAnd={}, applyIfOr={}, applyIfNot={})"
             > Phase "PrintOptoAssembly":
               - failOn: Graph contains forbidden nodes:
                 * Constraint 1: "(.*((?i:call_leaf_nofp,runtime)|CALL,\\s?runtime leaf nofp|BCTRL.*.leaf call).*checkcast_arraycopy.*)"
                   - Matched forbidden node:
                     * 15a + CALL, runtime leaf nofp 0x0000003f7fbd9600 #@CallLeafNoFPDirect checkcast_arraycopy

        >>> Check stdout for compilation output of the failed methods
        ```

        After troubleshooting, the problem is related to the definition of the matching rules for the CHECKCAST_ARRAY, CHECKCAST_ARRAY_OF fields in test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java:
        ```
            public static final String CHECKCAST_ARRAY = PREFIX + "CHECKCAST_ARRAY" + POSTFIX;
            static {
                String regex = "(((?i:cmp|CLFI|CLR).*precise \\[.*:|.*(?i:mov|or).*precise \\[.*:.*\\R.*(cmp|CMP|CLR))" + END;
                optoOnly(CHECKCAST_ARRAY, regex);
            }

            public static final String CHECKCAST_ARRAY_OF = COMPOSITE_PREFIX + "CHECKCAST_ARRAY_OF" + POSTFIX;
            static {
                String regex = "(((?i:cmp|CLFI|CLR).*precise \\[.*" + IS_REPLACED + ":|.*(?i:mov|or).*precise \\[.*" + IS_REPLACED + ":.*\\R.*(cmp|CMP|CLR))" + END;
                optoOnly(CHECKCAST_ARRAY_OF, regex);
            }
        ```
        This rule is used to match the Opto compilation log of the `array()/arrayCopy()` method of the subclass CheckCastArray in test/hotspot/jtreg/testlibrary_tests/ir_framework/tests/TestIRMatching.java. If the match does not work, the above test fails.

        The `array()` part of the Opto log for CheckCastArray on the aarch64 platform is as follows:
        ```
        06c B2: # out( B5 B3 ) <- in( B1 ) Freq: 0.999999
        06c + mov R12, narrowklass: precise [ir_framework/tests/MyClass: 0x0000ffff58420808 * (java/lang/Cloneable,java/io/Serializable): :Constant:exact * # compressed klass ptr
        074 + cmp R10, R12 // compressed ptr
        078 bne B5 # unsigned P=0.100000 C=-1.000000
        ```
        The `array()` part of the Opto log for CheckCastArray on the riscv platform is as follows:
        ```
        054 B2: # out( B5 B3 ) <- in( B1 ) Freq: 0.999999
        054 + mv R29, narrowklass: precise [ir_framework/tests/MyClass: 0x0000003f34437df8 * (java/lang/Cloneable,java/io/Serializable): :Constant:exact * # compressed klass ptr, #@loadConNKlass
        062 + bne R7, R29, B5 #@cmpN_branch P=0.100000 C=-1.000000
        ```
        From the above Opto log, we can see that the match rule of CHECKCAST_ARRAY in test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java can be matched with aarch64. However, on the riscv platform, since the mv instruction is generated, it does not correspond to the matching rule, so the test case fails. To solve this problem, we modified the match rules defined by CHECKCAST_ARRAY, CHECKCAST_ARRAY_OF in test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java to include the mv directive in the match rules.


        Same problem with ALLOC_ARRAY, ALLOC_ARRAY_OF in test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java
        ```
            public static final String ALLOC_ARRAY = PREFIX + "ALLOC_ARRAY" + POSTFIX;
            static {
                String optoRegex = "(.*precise \\[.*\\R((.*(?i:mov|xor|nop|spill).*|\\s*|.*(LGHI|LI).*)\\R)*.*(?i:call,static).*wrapper for: _new_array_Java" + END;
                allocNodes(ALLOC_ARRAY, "AllocateArray", optoRegex);
            }

            public static final String ALLOC_ARRAY_OF = COMPOSITE_PREFIX + "ALLOC_ARRAY_OF" + POSTFIX;
            static {
                String regex = "(.*precise \\[.*" + IS_REPLACED + ":.*\\R((.*(?i:mov|xorl|nop|spill).*|\\s*|.*(LGHI|LI).*)\\R)*.*(?i:call,static).*wrapper for: _new_array_Java" + END;
                optoOnly(ALLOC_ARRAY_OF, regex);
            }
        ```
        This rule is used to match the compilation log of the `allocArray()` method of the subclass AllocArray in test/hotspot/jtreg/testlibrary_tests/ir_framework/tests/TestIRMatching.java, and if it doesn't match it also fails. test fails.
        The `allocArray()` part of the Opto log for AllocArray on the aarch64 platform is as follows:
        ```
        1a8 B14: # out( B17 B15 ) <- in( B1 ) Freq: 0.000100017
        1a8 + mov R1, precise [ir_framework/tests/MyClass: 0x0000ffff244beb58 * (java/lang/Cloneable,java/io/Serializable): :Constant:exact * # ptr

        1b4 call,static 0x0000ffff6fb9c540 // ==> wrapper for: _new_array_Java
                # ir_framework.tests.AllocArray::allocArray @ bci:2 (line 930) L[0]=_ STK[0]=R29
                # OopMap {rfp=Oop off=440/0x1b8}
        ```
        The `allocArray()` part of the Opto log for AllocArray on the riscv platform is as follows:
        ```
        16a B14: # out( B17 B15 ) <- in( B1 ) Freq: 0.000100017
        16a + mv R11, precise [ir_framework/tests/MyClass: 0x00007fff4c34c018 * (java/lang/Cloneable,java/io/Serializable): :Constant:exact * # ptr, #@loadConP
        182 + li R12, #2 # int, #@loadConI
        184 CALL,static 0x00007fff9bb74840 #@CallStaticJavaDirect wrapper for: _new_array_Java
                # ir_framework.tests.AllocArray::allocArray @ bci:2 (line 930) L[0]=_ STK[0]=R8
                # OopMap {fp=Oop off=392/0x188}
        ```
        As we can see in the above logs, the aarch64 log matches the empty line under precise, which also matches the ALLOC_ARRAY_OF rule in test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java, but in the riscv log. precise is followed by the li, which doesn't match the rule and therefore also causes the test case to fail. To solve this problem, we firstly modified the loadConI, loadConL nodes in riscv.ad, and changed the log message of li into mv, and secondly, we modified the ALLOC_ARRAY and ALLOC_ARRAY_OF match rule in test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java, and added the mv directive to the match rule.

        Attachments

          Issue Links

            Activity

              People

                gcao Gui Cao
                gcao Gui Cao
                Votes:
                0 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: