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

Wrong instruction generation in aarch64 backend

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b26
    • CPU:
      aarch64
    • Verification:
      Not verified

      Description

      In assembler_aarch64.hpp, method encode(Instruction_aarch64 *i) sometimes selects the wrong instruction because of a test using the same mask for signed and unsigned value (Thanks to Patric Hedlin for the analysis of the bug).

      The fix basically replaces:

              if (_offset < 0 || _offset & mask)
                {
                  i->f(0b00, 25, 24);
                  i->f(0, 21), i->f(0b00, 11, 10);
                  i->sf(_offset, 20, 12);
                } else {
                  i->f(0b01, 25, 24);
                  i->f(_offset >> size, 21, 10);
                }

      with

              if (Assembler::is_simm9(_offset))
                {
                  i->f(0b00, 25, 24);
                  i->f(0, 21), i->f(0b00, 11, 10);
                  i->sf(_offset, 20, 12);
                } else {
                  assert(Assembler::is_uimm12(_offset), "should be");
                  i->f(0b01, 25, 24);
                  i->f(_offset >> size, 21, 10);
                }

      Th full patch is provided in attachment (the new version of the test requires to move the method from the hpp file to the inline.hpp file).

      However, once applied, this patch changes the code generated by C1 and this triggers an assertion failure in the patching code:

      # Internal Error (/home/christian/valhalla_c1/valhalla/open/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp:170), pid=1127960, tid=1127979
      # Error: ShouldNotReachHere()
      #
      # JRE version: Java(TM) SE Runtime Environment (18.0) (fastdebug build 18-lworld3ea+0-2021-10-26-1342512.christian...)
      # Java VM: Java HotSpot(TM) 64-Bit Server VM (fastdebug 18-lworld3ea+0-2021-10-26-1342512.christian..., mixed mode, tiered, compressed oops, compressed class ptrs, g1 gc, linux-aarch64)
      # Problematic frame:
      # V [libjvm.so+0x1355970] MacroAssembler::pd_patch_instruction_size(unsigned char*, unsigned char*)+0x11c
      #
      # Core dump will be written. Default location: Core dumps may be processed with "/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h %e" (or dumping to /home/christian/valhalla_c1/valhalla/open/make/core.1127960)
      #
      # If you would like to submit a bug report, please visit:
      # https://bugreport.java.com/bugreport/crash.jsp
      #

      --------------- S U M M A R Y ------------

      Command Line: -Xms64M -Xmx1600M --add-exports=java.base/jdk.internal.module=ALL-UNNAMED build.tools.jigsaw.AddPackagesAttribute /home/christian/valhalla_c1/valhalla/build/c1_cleanup/jdk

      Host: *, AArch64, 6 cores, 46G, Oracle Linux Server release 8.3
      Time: Thu Oct 28 12:06:13 2021 UTC elapsed time: 0.212753 seconds (0d 0h 0m 0s)

      --------------- T H R E A D ---------------

      Current thread (0x0000ffff18373320): JavaThread "C1 CompilerThread0" daemon [_thread_in_vm, id=1127979, stack(0x0000ffff04200000,0x0000ffff04400000)]


      Current CompileTask:
      C1: 212 5 3 java.lang.StringLatin1::hashCode (42 bytes)

      Stack: [0x0000ffff04200000,0x0000ffff04400000], sp=0x0000ffff043fd1d0, free space=2036k
      Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
      V [libjvm.so+0x1355970] MacroAssembler::pd_patch_instruction_size(unsigned char*, unsigned char*)+0x11c
      V [libjvm.so+0x9ca4a4] CodeBuffer::relocate_code_to(CodeBuffer*) const+0x470
      V [libjvm.so+0x9cd4d4] CodeBuffer::copy_code_to(CodeBlob*)+0x94
      V [libjvm.so+0x14a035c] nmethod::nmethod(Method*, CompilerType, int, int, int, CodeOffsets*, int, DebugInformationRecorder*, Dependencies*, CodeBuffer*, int, OopMapSet*, ExceptionHandlerTable*, ImplicitExceptionTable*, AbstractCompiler*, int, GrowableArrayView<RuntimeStub*> const&, char*, int, int)+0x448
      V [libjvm.so+0x14a0a6c] nmethod::new_nmethod(methodHandle const&, int, int, CodeOffsets*, int, DebugInformationRecorder*, Dependencies*, CodeBuffer*, int, OopMapSet*, ExceptionHandlerTable*, ImplicitExceptionTable*, AbstractCompiler*, int, GrowableArrayView<RuntimeStub*> const&, char*, int, int, char const*, FailedSpeculation**)+0x2dc
      V [libjvm.so+0x8c3690] ciEnv::register_method(ciMethod*, int, CodeOffsets*, int, CodeBuffer*, int, OopMapSet*, ExceptionHandlerTable*, ImplicitExceptionTable*, AbstractCompiler*, bool, bool, RTMState, GrowableArrayView<RuntimeStub*> const&)+0x310
      V [libjvm.so+0x71f120] Compilation::install_code(int)+0xf0
      V [libjvm.so+0x721eec] Compilation::compile_method()+0x33c
      V [libjvm.so+0x722764] Compilation::Compilation(AbstractCompiler*, ciEnv*, ciMethod*, int, BufferBlob*, bool, DirectiveSet*)+0x324
      V [libjvm.so+0x723d28] Compiler::compile_method(ciEnv*, ciMethod*, int, bool, DirectiveSet*)+0x158
      V [libjvm.so+0xa2dab8] CompileBroker::invoke_compiler_on_method(CompileTask*)+0x8b8
      V [libjvm.so+0xa2e51c] CompileBroker::compiler_thread_loop()+0x2dc
      V [libjvm.so+0x1828e54] JavaThread::thread_main_inner()+0x284
      V [libjvm.so+0x182f3f8] Thread::call_run()+0xf8
      V [libjvm.so+0x1535e04] thread_native_entry(Thread*)+0x104
      C [libpthread.so.0+0x7738] start_thread+0x198




        Attachments

        1. fix_aarch64.patch
          4 kB
        2. hs_err_pid1127960.log
          49 kB
        3. lir-as-address.diff
          1 kB
        4. nick-changes.diff
          4 kB

          Issue Links

            Activity

              People

              Assignee:
              phedlin Patric Hedlin (Inactive)
              Reporter:
              fparain Frederic Parain
              Votes:
              0 Vote for this issue
              Watchers:
              12 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: