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().
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().
- relates to
-
JDK-8253779 Amalloc may be wasting space by overaligning
-
- Resolved
-
-
JDK-8270179 Rename Amalloc_4
-
- Resolved
-