39 protected:
40 address _base; // the real base address
41 size_t _length; // the length of the array
42 address _biased_base; // base address biased by "bias" elements
43 size_t _bias; // the bias, i.e. the offset biased_base is located to the right in elements
44 uint _shift_by; // the amount of bits to shift right when mapping to an index of the array.
45
46 protected:
47
48 G1BiasedMappedArrayBase() : _base(NULL), _length(0), _biased_base(NULL),
49 _bias(0), _shift_by(0) { }
50
51 // Allocate a new array, generic version.
52 static address create_new_base_array(size_t length, size_t elem_size);
53
54 // Initialize the members of this class. The biased start address of this array
55 // is the bias (in elements) multiplied by the element size.
56 void initialize_base(address base, size_t length, size_t bias, size_t elem_size, uint shift_by) {
57 assert(base != NULL, "just checking");
58 assert(length > 0, "just checking");
59 assert(shift_by < sizeof(uintptr_t) * 8, err_msg("Shifting by %u, larger than word size?", shift_by));
60 _base = base;
61 _length = length;
62 _biased_base = base - (bias * elem_size);
63 _bias = bias;
64 _shift_by = shift_by;
65 }
66
67 // Allocate and initialize this array to cover the heap addresses in the range
68 // of [bottom, end).
69 void initialize(HeapWord* bottom, HeapWord* end, size_t target_elem_size_in_bytes, size_t mapping_granularity_in_bytes) {
70 assert(mapping_granularity_in_bytes > 0, "just checking");
71 assert(is_power_of_2(mapping_granularity_in_bytes),
72 err_msg("mapping granularity must be power of 2, is %zd", mapping_granularity_in_bytes));
73 assert((uintptr_t)bottom % mapping_granularity_in_bytes == 0,
74 err_msg("bottom mapping area address must be a multiple of mapping granularity %zd, is " PTR_FORMAT,
75 mapping_granularity_in_bytes, p2i(bottom)));
76 assert((uintptr_t)end % mapping_granularity_in_bytes == 0,
77 err_msg("end mapping area address must be a multiple of mapping granularity %zd, is " PTR_FORMAT,
78 mapping_granularity_in_bytes, p2i(end)));
79 size_t num_target_elems = pointer_delta(end, bottom, mapping_granularity_in_bytes);
80 idx_t bias = (uintptr_t)bottom / mapping_granularity_in_bytes;
81 address base = create_new_base_array(num_target_elems, target_elem_size_in_bytes);
82 initialize_base(base, num_target_elems, bias, target_elem_size_in_bytes, log2_intptr(mapping_granularity_in_bytes));
83 }
84
85 size_t bias() const { return _bias; }
86 uint shift_by() const { return _shift_by; }
87
88 void verify_index(idx_t index) const PRODUCT_RETURN;
89 void verify_biased_index(idx_t biased_index) const PRODUCT_RETURN;
90 void verify_biased_index_inclusive_end(idx_t biased_index) const PRODUCT_RETURN;
91
92 public:
93 // Return the length of the array in elements.
94 size_t length() const { return _length; }
95 };
96
97 // Array that provides biased access and mapping from (valid) addresses in the
98 // heap into this array.
|
39 protected:
40 address _base; // the real base address
41 size_t _length; // the length of the array
42 address _biased_base; // base address biased by "bias" elements
43 size_t _bias; // the bias, i.e. the offset biased_base is located to the right in elements
44 uint _shift_by; // the amount of bits to shift right when mapping to an index of the array.
45
46 protected:
47
48 G1BiasedMappedArrayBase() : _base(NULL), _length(0), _biased_base(NULL),
49 _bias(0), _shift_by(0) { }
50
51 // Allocate a new array, generic version.
52 static address create_new_base_array(size_t length, size_t elem_size);
53
54 // Initialize the members of this class. The biased start address of this array
55 // is the bias (in elements) multiplied by the element size.
56 void initialize_base(address base, size_t length, size_t bias, size_t elem_size, uint shift_by) {
57 assert(base != NULL, "just checking");
58 assert(length > 0, "just checking");
59 assert(shift_by < sizeof(uintptr_t) * 8, "Shifting by %u, larger than word size?", shift_by);
60 _base = base;
61 _length = length;
62 _biased_base = base - (bias * elem_size);
63 _bias = bias;
64 _shift_by = shift_by;
65 }
66
67 // Allocate and initialize this array to cover the heap addresses in the range
68 // of [bottom, end).
69 void initialize(HeapWord* bottom, HeapWord* end, size_t target_elem_size_in_bytes, size_t mapping_granularity_in_bytes) {
70 assert(mapping_granularity_in_bytes > 0, "just checking");
71 assert(is_power_of_2(mapping_granularity_in_bytes),
72 "mapping granularity must be power of 2, is %zd", mapping_granularity_in_bytes);
73 assert((uintptr_t)bottom % mapping_granularity_in_bytes == 0,
74 "bottom mapping area address must be a multiple of mapping granularity %zd, is " PTR_FORMAT,
75 mapping_granularity_in_bytes, p2i(bottom));
76 assert((uintptr_t)end % mapping_granularity_in_bytes == 0,
77 "end mapping area address must be a multiple of mapping granularity %zd, is " PTR_FORMAT,
78 mapping_granularity_in_bytes, p2i(end));
79 size_t num_target_elems = pointer_delta(end, bottom, mapping_granularity_in_bytes);
80 idx_t bias = (uintptr_t)bottom / mapping_granularity_in_bytes;
81 address base = create_new_base_array(num_target_elems, target_elem_size_in_bytes);
82 initialize_base(base, num_target_elems, bias, target_elem_size_in_bytes, log2_intptr(mapping_granularity_in_bytes));
83 }
84
85 size_t bias() const { return _bias; }
86 uint shift_by() const { return _shift_by; }
87
88 void verify_index(idx_t index) const PRODUCT_RETURN;
89 void verify_biased_index(idx_t biased_index) const PRODUCT_RETURN;
90 void verify_biased_index_inclusive_end(idx_t biased_index) const PRODUCT_RETURN;
91
92 public:
93 // Return the length of the array in elements.
94 size_t length() const { return _length; }
95 };
96
97 // Array that provides biased access and mapping from (valid) addresses in the
98 // heap into this array.
|