Skip to content

8357621: G1: Clean up G1BiasedArray #25406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/hotspot/share/gc/g1/g1BiasedArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,4 @@ void G1BiasedMappedArrayBase::verify_biased_index(idx_t biased_index) const {
"Biased index out of bounds, index: %zu bias: %zu length: %zu",
biased_index, bias(), length());
}

void G1BiasedMappedArrayBase::verify_biased_index_inclusive_end(idx_t biased_index) const {
guarantee(_biased_base != nullptr, "Array not initialized");
guarantee(biased_index >= bias() && biased_index <= (bias() + length()),
"Biased index out of inclusive bounds, index: %zu bias: %zu length: %zu",
biased_index, bias(), length());
}

#endif
56 changes: 18 additions & 38 deletions src/hotspot/share/gc/g1/g1BiasedArray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,6 @@ class G1BiasedMappedArrayBase : public CHeapObj<mtGC> {

void* _alloc_base; // the address the unpadded array has been allocated to

public:
typedef size_t idx_t;

protected:
address _base; // the real base address
size_t _length; // the length of the array
address _biased_base; // base address biased by "bias" elements
size_t _bias; // the bias, i.e. the offset biased_base is located to the right in elements
uint _shift_by; // the amount of bits to shift right when mapping to an index of the array.

protected:
G1BiasedMappedArrayBase();

// Allocate a new array, generic version.
address create_new_base_array(size_t length, size_t elem_size);

Expand All @@ -67,6 +54,18 @@ class G1BiasedMappedArrayBase : public CHeapObj<mtGC> {
_shift_by = shift_by;
}

public:
typedef size_t idx_t;

protected:
address _base; // the real base address
size_t _length; // the length of the array
address _biased_base; // base address biased by "bias" elements
size_t _bias; // the bias, i.e. the offset biased_base is located to the right in elements
uint _shift_by; // the amount of bits to shift right when mapping to an index of the array.

G1BiasedMappedArrayBase();

// Allocate and initialize this array to cover the heap addresses in the range
// of [bottom, end).
void initialize(HeapWord* bottom, HeapWord* end, size_t target_elem_size_in_bytes, size_t mapping_granularity_in_bytes) {
Expand All @@ -90,7 +89,6 @@ class G1BiasedMappedArrayBase : public CHeapObj<mtGC> {

void verify_index(idx_t index) const PRODUCT_RETURN;
void verify_biased_index(idx_t biased_index) const PRODUCT_RETURN;
void verify_biased_index_inclusive_end(idx_t biased_index) const PRODUCT_RETURN;

public:
virtual ~G1BiasedMappedArrayBase();
Expand All @@ -103,10 +101,15 @@ class G1BiasedMappedArrayBase : public CHeapObj<mtGC> {
// heap into this array.
template<class T>
class G1BiasedMappedArray : public G1BiasedMappedArrayBase {
protected:
T* base() const { return (T*)G1BiasedMappedArrayBase::_base; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like base() needs to be public for testing as well :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for all these issues, I just found out that I did not have gtests configured for my build. Should be fixed now.

I moved the test helper methods into the test.


// The raw biased base pointer.
T* biased_base() const { return (T*)G1BiasedMappedArrayBase::_biased_base; }

public:
typedef G1BiasedMappedArrayBase::idx_t idx_t;

T* base() const { return (T*)G1BiasedMappedArrayBase::_base; }
// Return the element of the given array at the given index. Assume
// the index is valid. This is a convenience method that does sanity
// checking on the index.
Expand All @@ -123,9 +126,6 @@ class G1BiasedMappedArray : public G1BiasedMappedArrayBase {
this->base()[index] = value;
}

// The raw biased base pointer.
T* biased_base() const { return (T*)G1BiasedMappedArrayBase::_biased_base; }

// Return the element of the given array that covers the given word in the
// heap. Assumes the index is valid.
T get_by_address(HeapWord* value) const {
Expand Down Expand Up @@ -154,26 +154,6 @@ class G1BiasedMappedArray : public G1BiasedMappedArrayBase {
biased_base()[biased_index] = value;
}

// Set the value of all array entries that correspond to addresses
// in the specified MemRegion.
void set_by_address(MemRegion range, T value) {
idx_t biased_start = ((uintptr_t)range.start()) >> this->shift_by();
idx_t biased_last = ((uintptr_t)range.last()) >> this->shift_by();
this->verify_biased_index(biased_start);
this->verify_biased_index(biased_last);
for (idx_t i = biased_start; i <= biased_last; i++) {
biased_base()[i] = value;
}
}

protected:
// Returns the address of the element the given address maps to
T* address_mapped_to(HeapWord* address) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems to be used by testing.

idx_t biased_index = ((uintptr_t)address) >> this->shift_by();
this->verify_biased_index_inclusive_end(biased_index);
return biased_base() + biased_index;
}

public:
// Return the smallest address (inclusive) in the heap that this array covers.
HeapWord* bottom_address_mapped() const {
Expand Down
18 changes: 17 additions & 1 deletion test/hotspot/gtest/gc/g1/test_g1BiasedArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,29 @@
#include "unittest.hpp"

class TestMappedArray : public G1BiasedMappedArray<int> {
void verify_biased_index_inclusive_end(idx_t biased_index) const {
guarantee(_biased_base != nullptr, "Array not initialized");
guarantee(biased_index >= bias() && biased_index <= (bias() + length()),
"Biased index out of inclusive bounds, index: %zu bias: %zu length: %zu",
biased_index, bias(), length());
}

public:
virtual int default_value() const {
return 0xBAADBABE;
}

// Returns the address of the element the given address maps to
int* my_address_mapped_to(HeapWord* address) {
return address_mapped_to(address);
idx_t biased_index = ((uintptr_t)address) >> shift_by();
verify_biased_index_inclusive_end(biased_index);
return biased_base() + biased_index;
}

int* base() const { return G1BiasedMappedArray<int>::base(); }

// The raw biased base pointer.
int* biased_base() const { return G1BiasedMappedArray<int>::biased_base(); }
};

TEST_VM(G1BiasedArray, simple) {
Expand Down