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

Fix Arena::Amalloc to check for overflow better

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 18
    • 18
    • hotspot
    • None
    • b06

      From [~kbarrett]
      Instead of my previously suggested if (_max - _hwm < x), use if (pointer_delta(_max, _hwm, 1) < x) to avoid the signed vs unsigned comparison warning. Then I think check_for_overflow is just not needed. (Sorry, I forgot to mention previously that I think check_for_overflow can be eliminated.)

       
      @coleenp coleenp 10 hours ago Author Member
      check_for_overflow does more than just the pointer comparison. It conditionally calls vm_exit_out_of_memory. I don't want to copy this into both of the Amalloc function, and it has a nice name vs. squinting and trying to understand why "if (pointer_delta(_max, _hwm, 1) < x)" does the same thing. As is, this is readable and I don't want to change it.

       
      @kimbarrett kimbarrett 4 hours ago Member
      Such a use of pointer_delta is one of its canonical use-cases, as discussed in the comment describing that function.

      grow does everything that check_for_overflow does, except correctly. check_for_overflow can incorrectly report an error if the current chunk happens to be near the end of the address space, even though malloc can succeed.

      The current code with the call to check_for_overflow is incorrect, slower, and larger than it needs to be. It's got nothing at all going for it except the "whence" string, which is not enough to make up for the other problems. If that feature is important, add it to grow().

            coleenp Coleen Phillimore
            coleenp Coleen Phillimore
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: