1 /*
2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
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
|
1 /*
2 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
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 " SIZE_FORMAT, 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 " SIZE_FORMAT ", 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 " SIZE_FORMAT ", 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
|