Zero: Replace Java math ops with UB-safe implementations

XMLWordPrintable

      For Valhalla enablement reasons, I have been hunting Zero bugs.

      Noticed that Zero fails with UBSan enabled, mostly when doing Java math and running in C++ UBs around signed math overflows:

      $ CONF=linux-x86_64-zero-fastdebug make images | ts -s
      00:00:00 Building target 'images' in configuration 'linux-x86_64-zero-fastdebug'
      00:02:23 Compiling up to 4 files for COMPILE_CREATE_SYMBOLS
      00:02:23 Compiling up to 4 files for COMPILE_CREATE_SYMBOLS
      /home/shade/trunks/jdk/src/hotspot/cpu/zero/bytecodeInterpreter_zero.inline.hpp:119:11: runtime error: negation of -9223372036854775808 cannot be represented in type 'long int'; cast to an unsigned type to negate this value to itself

      Luckily, we already have the whole group of java_* methods that are there for the purpose we need in Zero: emulate Java math without running into UB.

      Fixing these issues seems to resolve some of the hair-pulling bugs I have been chasing, that reproduce even in mainline. So it is Bug, not Enhancement.

            Assignee:
            Aleksey Shipilev
            Reporter:
            Aleksey Shipilev
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: