Skip to content

Commit

Permalink
8329840: Fix ZPhysicalMemorySegment::_end type
Browse files Browse the repository at this point in the history
Backport-of: b4ddddeff1ce4293c88a9ab8ad3ca9d3b0e2352e
  • Loading branch information
Liang Mao authored and RealCLanger committed May 23, 2024
1 parent acff39d commit cdfe2f4
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/hotspot/share/gc/z/zAddress.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ inline bool operator<(zoffset first, zoffset_end second) {
return untype(first) < untype(second);
}

inline bool operator<=(zoffset_end first, zoffset second) {
return untype(first) <= untype(second);
}

inline bool operator>(zoffset first, zoffset_end second) {
return untype(first) > untype(second);
}
Expand Down
8 changes: 4 additions & 4 deletions src/hotspot/share/gc/z/zPhysicalMemory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@

class ZPhysicalMemorySegment : public CHeapObj<mtGC> {
private:
zoffset _start;
zoffset _end;
bool _committed;
zoffset _start;
zoffset_end _end;
bool _committed;

public:
ZPhysicalMemorySegment();
ZPhysicalMemorySegment(zoffset start, size_t size, bool committed);

zoffset start() const;
zoffset end() const;
zoffset_end end() const;
size_t size() const;

bool is_committed() const;
Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/share/gc/z/zPhysicalMemory.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@

inline ZPhysicalMemorySegment::ZPhysicalMemorySegment()
: _start(zoffset(UINTPTR_MAX)),
_end(zoffset(UINTPTR_MAX)),
_end(zoffset_end(UINTPTR_MAX)),
_committed(false) {}

inline ZPhysicalMemorySegment::ZPhysicalMemorySegment(zoffset start, size_t size, bool committed)
: _start(start),
_end(start + size),
_end(to_zoffset_end(start, size)),
_committed(committed) {}

inline zoffset ZPhysicalMemorySegment::start() const {
return _start;
}

inline zoffset ZPhysicalMemorySegment::end() const {
inline zoffset_end ZPhysicalMemorySegment::end() const {
return _end;
}

Expand Down
45 changes: 45 additions & 0 deletions test/hotspot/gtest/gc/z/test_zPhysicalMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,27 @@
#include "gc/z/zPhysicalMemory.inline.hpp"
#include "unittest.hpp"

class ZAddressOffsetMaxSetter {
private:
const size_t _old_max;
const size_t _old_mask;

public:
ZAddressOffsetMaxSetter()
: _old_max(ZAddressOffsetMax),
_old_mask(ZAddressOffsetMask) {
ZAddressOffsetMax = size_t(16) * G * 1024;
ZAddressOffsetMask = ZAddressOffsetMax - 1;
}
~ZAddressOffsetMaxSetter() {
ZAddressOffsetMax = _old_max;
ZAddressOffsetMask = _old_mask;
}
};

TEST(ZPhysicalMemoryTest, copy) {
ZAddressOffsetMaxSetter setter;

const ZPhysicalMemorySegment seg0(zoffset(0), 100, true);
const ZPhysicalMemorySegment seg1(zoffset(200), 100, true);

Expand All @@ -52,6 +72,8 @@ TEST(ZPhysicalMemoryTest, copy) {
}

TEST(ZPhysicalMemoryTest, add) {
ZAddressOffsetMaxSetter setter;

const ZPhysicalMemorySegment seg0(zoffset(0), 1, true);
const ZPhysicalMemorySegment seg1(zoffset(1), 1, true);
const ZPhysicalMemorySegment seg2(zoffset(2), 1, true);
Expand Down Expand Up @@ -114,6 +136,8 @@ TEST(ZPhysicalMemoryTest, add) {
}

TEST(ZPhysicalMemoryTest, remove) {
ZAddressOffsetMaxSetter setter;

ZPhysicalMemory pmem;

pmem.add_segment(ZPhysicalMemorySegment(zoffset(10), 10, true));
Expand All @@ -130,6 +154,8 @@ TEST(ZPhysicalMemoryTest, remove) {
}

TEST(ZPhysicalMemoryTest, split) {
ZAddressOffsetMaxSetter setter;

ZPhysicalMemory pmem;

pmem.add_segment(ZPhysicalMemorySegment(zoffset(0), 10, true));
Expand Down Expand Up @@ -158,6 +184,8 @@ TEST(ZPhysicalMemoryTest, split) {
}

TEST(ZPhysicalMemoryTest, split_committed) {
ZAddressOffsetMaxSetter setter;

ZPhysicalMemory pmem0;
pmem0.add_segment(ZPhysicalMemorySegment(zoffset(0), 10, true));
pmem0.add_segment(ZPhysicalMemorySegment(zoffset(10), 10, false));
Expand All @@ -172,3 +200,20 @@ TEST(ZPhysicalMemoryTest, split_committed) {
EXPECT_EQ(pmem1.nsegments(), 2);
EXPECT_EQ(pmem1.size(), 20u);
}

TEST(ZPhysicalMemoryTest, limits) {
ZAddressOffsetMaxSetter setter;

const size_t HalfZAddressOffsetMax = ZAddressOffsetMax >> 1;
ZPhysicalMemory pmem0;
pmem0.add_segment(ZPhysicalMemorySegment(zoffset(0), HalfZAddressOffsetMax, true));
pmem0.add_segment(ZPhysicalMemorySegment(zoffset(HalfZAddressOffsetMax), HalfZAddressOffsetMax, false));
EXPECT_EQ(pmem0.nsegments(), 2);
EXPECT_EQ(pmem0.size(), ZAddressOffsetMax);

ZPhysicalMemory pmem1 = pmem0.split_committed();
EXPECT_EQ(pmem0.nsegments(), 1);
EXPECT_EQ(pmem0.size(), HalfZAddressOffsetMax);
EXPECT_EQ(pmem1.nsegments(), 1);
EXPECT_EQ(pmem1.size(), HalfZAddressOffsetMax);
}

1 comment on commit cdfe2f4

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.