1 /*
2 * Copyright (c) 2013, 2014, 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 *
23 */
24
25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1BIASEDARRAY_HPP
26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1BIASEDARRAY_HPP
27
28 #include "memory/allocation.hpp"
29 #include "utilities/debug.hpp"
30
31 // Implements the common base functionality for arrays that contain provisions
32 // for accessing its elements using a biased index.
33 // The element type is defined by the instantiating the template.
34 class G1BiasedMappedArrayBase VALUE_OBJ_CLASS_SPEC {
35 friend class VMStructs;
36 public:
37 typedef size_t idx_t;
38 protected:
39 address _base; // the real base address
40 size_t _length; // the length of the array
41 address _biased_base; // base address biased by "bias" elements
42 size_t _bias; // the bias, i.e. the offset biased_base is located to the right in elements
43 uint _shift_by; // the amount of bits to shift right when mapping to an index of the array.
44
45 protected:
46
157 protected:
158 virtual T default_value() const = 0;
159 // Set all elements of the given array to the given value.
160 void clear() {
161 T value = default_value();
162 for (idx_t i = 0; i < length(); i++) {
163 set_by_index(i, value);
164 }
165 }
166 public:
167 G1BiasedMappedArray() {}
168
169 // Allocate and initialize this array to cover the heap addresses in the range
170 // of [bottom, end).
171 void initialize(HeapWord* bottom, HeapWord* end, size_t mapping_granularity) {
172 G1BiasedMappedArrayBase::initialize(bottom, end, sizeof(T), mapping_granularity);
173 this->clear();
174 }
175 };
176
177 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1BIASEDARRAY_HPP
|
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 *
23 */
24
25 #ifndef SHARE_VM_GC_G1_G1BIASEDARRAY_HPP
26 #define SHARE_VM_GC_G1_G1BIASEDARRAY_HPP
27
28 #include "memory/allocation.hpp"
29 #include "utilities/debug.hpp"
30
31 // Implements the common base functionality for arrays that contain provisions
32 // for accessing its elements using a biased index.
33 // The element type is defined by the instantiating the template.
34 class G1BiasedMappedArrayBase VALUE_OBJ_CLASS_SPEC {
35 friend class VMStructs;
36 public:
37 typedef size_t idx_t;
38 protected:
39 address _base; // the real base address
40 size_t _length; // the length of the array
41 address _biased_base; // base address biased by "bias" elements
42 size_t _bias; // the bias, i.e. the offset biased_base is located to the right in elements
43 uint _shift_by; // the amount of bits to shift right when mapping to an index of the array.
44
45 protected:
46
157 protected:
158 virtual T default_value() const = 0;
159 // Set all elements of the given array to the given value.
160 void clear() {
161 T value = default_value();
162 for (idx_t i = 0; i < length(); i++) {
163 set_by_index(i, value);
164 }
165 }
166 public:
167 G1BiasedMappedArray() {}
168
169 // Allocate and initialize this array to cover the heap addresses in the range
170 // of [bottom, end).
171 void initialize(HeapWord* bottom, HeapWord* end, size_t mapping_granularity) {
172 G1BiasedMappedArrayBase::initialize(bottom, end, sizeof(T), mapping_granularity);
173 this->clear();
174 }
175 };
176
177 #endif // SHARE_VM_GC_G1_G1BIASEDARRAY_HPP
|