PSOldPromotionLAB::allocate (at https://hg.openjdk.java.net/jdk/jdk/file/7cf02b2c1455/src/hotspot/share/gc/parallel/psPromotionLAB.hpp#l116) says
HeapWord* allocate(size_t size) {
....
HeapWord* obj = top();
HeapWord* new_top = obj + size;
// The 'new_top>obj' check is needed to detect overflow of obj+size.
if (new_top > obj && new_top <= end()) {
set_top(new_top);
....
where there is an explicit check for overflow of the addition. The usual way to write that code is
HeapWord* obj = top();
if (pointer_delta(end(), obj) >= size) {
HeapWord* new_top = obj + size;
set_top(new_top)
so that there would not have to be an explicit test for overflow.
The suggested change does not improve the correctness of the code. I don't think it will be possible to measure the performance effect of the suggested change. But the code would be cleaner, and more like the other allocations.
HeapWord* allocate(size_t size) {
....
HeapWord* obj = top();
HeapWord* new_top = obj + size;
// The 'new_top>obj' check is needed to detect overflow of obj+size.
if (new_top > obj && new_top <= end()) {
set_top(new_top);
....
where there is an explicit check for overflow of the addition. The usual way to write that code is
HeapWord* obj = top();
if (pointer_delta(end(), obj) >= size) {
HeapWord* new_top = obj + size;
set_top(new_top)
so that there would not have to be an explicit test for overflow.
The suggested change does not improve the correctness of the code. I don't think it will be possible to measure the performance effect of the suggested change. But the code would be cleaner, and more like the other allocations.
- duplicates
-
JDK-8258382 Fix optimization-unstable code involving pointer overflow
- Resolved