src/share/vm/gc_implementation/g1/g1BiasedArray.hpp

Fri, 10 Oct 2014 15:51:58 +0200

author
tschatzl
date
Fri, 10 Oct 2014 15:51:58 +0200
changeset 7257
e7d0505c8a30
parent 6680
78bbf4d43a14
child 6876
710a3c8b516e
child 7842
34714dc91411
permissions
-rw-r--r--

8059758: Footprint regressions with JDK-8038423
Summary: Changes in JDK-8038423 always initialize (zero out) virtual memory used for auxiliary data structures. This causes a footprint regression for G1 in startup benchmarks. This is because they do not touch that memory at all, so the operating system does not actually commit these pages. The fix is to, if the initialization value of the data structures matches the default value of just committed memory (=0), do not do anything.
Reviewed-by: jwilhelm, brutisso

tschatzl@5773 1 /*
drchase@6680 2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
tschatzl@5773 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
tschatzl@5773 4 *
tschatzl@5773 5 * This code is free software; you can redistribute it and/or modify it
tschatzl@5773 6 * under the terms of the GNU General Public License version 2 only, as
tschatzl@5773 7 * published by the Free Software Foundation.
tschatzl@5773 8 *
tschatzl@5773 9 * This code is distributed in the hope that it will be useful, but WITHOUT
tschatzl@5773 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
tschatzl@5773 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
tschatzl@5773 12 * version 2 for more details (a copy is included in the LICENSE file that
tschatzl@5773 13 * accompanied this code).
tschatzl@5773 14 *
tschatzl@5773 15 * You should have received a copy of the GNU General Public License version
tschatzl@5773 16 * 2 along with this work; if not, write to the Free Software Foundation,
tschatzl@5773 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
tschatzl@5773 18 *
tschatzl@5773 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
tschatzl@5773 20 * or visit www.oracle.com if you need additional information or have any
tschatzl@5773 21 * questions.
tschatzl@5773 22 *
tschatzl@5773 23 */
tschatzl@5773 24
tschatzl@5773 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1BIASEDARRAY_HPP
tschatzl@5773 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1BIASEDARRAY_HPP
tschatzl@5773 27
tschatzl@6409 28 #include "memory/allocation.hpp"
tschatzl@5773 29 #include "utilities/debug.hpp"
tschatzl@5773 30
tschatzl@5773 31 // Implements the common base functionality for arrays that contain provisions
tschatzl@5773 32 // for accessing its elements using a biased index.
tschatzl@5773 33 // The element type is defined by the instantiating the template.
tschatzl@5773 34 class G1BiasedMappedArrayBase VALUE_OBJ_CLASS_SPEC {
tschatzl@5773 35 friend class VMStructs;
tschatzl@5773 36 public:
tschatzl@5773 37 typedef size_t idx_t;
tschatzl@5773 38 protected:
tschatzl@5773 39 address _base; // the real base address
tschatzl@5773 40 size_t _length; // the length of the array
tschatzl@5773 41 address _biased_base; // base address biased by "bias" elements
tschatzl@5773 42 size_t _bias; // the bias, i.e. the offset biased_base is located to the right in elements
tschatzl@5773 43 uint _shift_by; // the amount of bits to shift right when mapping to an index of the array.
tschatzl@5773 44
tschatzl@5773 45 protected:
tschatzl@5773 46
tschatzl@5773 47 G1BiasedMappedArrayBase() : _base(NULL), _length(0), _biased_base(NULL),
tschatzl@5773 48 _bias(0), _shift_by(0) { }
tschatzl@5773 49
tschatzl@5773 50 // Allocate a new array, generic version.
tschatzl@6409 51 static address create_new_base_array(size_t length, size_t elem_size);
tschatzl@5773 52
tschatzl@5773 53 // Initialize the members of this class. The biased start address of this array
tschatzl@5773 54 // is the bias (in elements) multiplied by the element size.
tschatzl@5773 55 void initialize_base(address base, size_t length, size_t bias, size_t elem_size, uint shift_by) {
tschatzl@5773 56 assert(base != NULL, "just checking");
tschatzl@5773 57 assert(length > 0, "just checking");
drchase@6680 58 assert(shift_by < sizeof(uintptr_t) * 8, err_msg("Shifting by " SSIZE_FORMAT ", larger than word size?", (size_t) shift_by));
tschatzl@5773 59 _base = base;
tschatzl@5773 60 _length = length;
tschatzl@5773 61 _biased_base = base - (bias * elem_size);
tschatzl@5773 62 _bias = bias;
tschatzl@5773 63 _shift_by = shift_by;
tschatzl@5773 64 }
tschatzl@5773 65
tschatzl@5773 66 // Allocate and initialize this array to cover the heap addresses in the range
tschatzl@5773 67 // of [bottom, end).
tschatzl@5773 68 void initialize(HeapWord* bottom, HeapWord* end, size_t target_elem_size_in_bytes, size_t mapping_granularity_in_bytes) {
tschatzl@5773 69 assert(mapping_granularity_in_bytes > 0, "just checking");
tschatzl@5773 70 assert(is_power_of_2(mapping_granularity_in_bytes),
tschatzl@5773 71 err_msg("mapping granularity must be power of 2, is %zd", mapping_granularity_in_bytes));
tschatzl@5773 72 assert((uintptr_t)bottom % mapping_granularity_in_bytes == 0,
drchase@6680 73 err_msg("bottom mapping area address must be a multiple of mapping granularity %zd, is " PTR_FORMAT,
drchase@6680 74 mapping_granularity_in_bytes, p2i(bottom)));
tschatzl@5773 75 assert((uintptr_t)end % mapping_granularity_in_bytes == 0,
drchase@6680 76 err_msg("end mapping area address must be a multiple of mapping granularity %zd, is " PTR_FORMAT,
drchase@6680 77 mapping_granularity_in_bytes, p2i(end)));
tschatzl@5773 78 size_t num_target_elems = (end - bottom) / (mapping_granularity_in_bytes / HeapWordSize);
tschatzl@5773 79 idx_t bias = (uintptr_t)bottom / mapping_granularity_in_bytes;
tschatzl@5773 80 address base = create_new_base_array(num_target_elems, target_elem_size_in_bytes);
tschatzl@5773 81 initialize_base(base, num_target_elems, bias, target_elem_size_in_bytes, log2_intptr(mapping_granularity_in_bytes));
tschatzl@5773 82 }
tschatzl@5773 83
tschatzl@5773 84 size_t bias() const { return _bias; }
tschatzl@5773 85 uint shift_by() const { return _shift_by; }
tschatzl@5773 86
tschatzl@5773 87 void verify_index(idx_t index) const PRODUCT_RETURN;
tschatzl@5773 88 void verify_biased_index(idx_t biased_index) const PRODUCT_RETURN;
tschatzl@5773 89 void verify_biased_index_inclusive_end(idx_t biased_index) const PRODUCT_RETURN;
tschatzl@5773 90
tschatzl@5773 91 public:
tschatzl@5773 92 // Return the length of the array in elements.
tschatzl@5773 93 size_t length() const { return _length; }
tschatzl@5773 94 };
tschatzl@5773 95
tschatzl@5773 96 // Array that provides biased access and mapping from (valid) addresses in the
tschatzl@5773 97 // heap into this array.
tschatzl@5773 98 template<class T>
tschatzl@5773 99 class G1BiasedMappedArray : public G1BiasedMappedArrayBase {
tschatzl@5773 100 public:
tschatzl@5773 101 typedef G1BiasedMappedArrayBase::idx_t idx_t;
tschatzl@5773 102
tschatzl@5773 103 T* base() const { return (T*)G1BiasedMappedArrayBase::_base; }
tschatzl@5773 104 // Return the element of the given array at the given index. Assume
tschatzl@5773 105 // the index is valid. This is a convenience method that does sanity
tschatzl@5773 106 // checking on the index.
tschatzl@5773 107 T get_by_index(idx_t index) const {
tschatzl@5773 108 verify_index(index);
tschatzl@5773 109 return this->base()[index];
tschatzl@5773 110 }
tschatzl@5773 111
tschatzl@5773 112 // Set the element of the given array at the given index to the
tschatzl@5773 113 // given value. Assume the index is valid. This is a convenience
tschatzl@5773 114 // method that does sanity checking on the index.
tschatzl@5773 115 void set_by_index(idx_t index, T value) {
tschatzl@5773 116 verify_index(index);
tschatzl@5773 117 this->base()[index] = value;
tschatzl@5773 118 }
tschatzl@5773 119
tschatzl@5773 120 // The raw biased base pointer.
tschatzl@5773 121 T* biased_base() const { return (T*)G1BiasedMappedArrayBase::_biased_base; }
tschatzl@5773 122
tschatzl@5773 123 // Return the element of the given array that covers the given word in the
tschatzl@5773 124 // heap. Assumes the index is valid.
tschatzl@5773 125 T get_by_address(HeapWord* value) const {
tschatzl@5773 126 idx_t biased_index = ((uintptr_t)value) >> this->shift_by();
tschatzl@5773 127 this->verify_biased_index(biased_index);
tschatzl@5773 128 return biased_base()[biased_index];
tschatzl@5773 129 }
tschatzl@5773 130
tschatzl@5773 131 // Set the value of the array entry that corresponds to the given array.
tschatzl@5773 132 void set_by_address(HeapWord * address, T value) {
tschatzl@5773 133 idx_t biased_index = ((uintptr_t)address) >> this->shift_by();
tschatzl@5773 134 this->verify_biased_index(biased_index);
tschatzl@5773 135 biased_base()[biased_index] = value;
tschatzl@5773 136 }
tschatzl@5773 137
tschatzl@5773 138 protected:
tschatzl@5773 139 // Returns the address of the element the given address maps to
tschatzl@5773 140 T* address_mapped_to(HeapWord* address) {
tschatzl@5773 141 idx_t biased_index = ((uintptr_t)address) >> this->shift_by();
tschatzl@5773 142 this->verify_biased_index_inclusive_end(biased_index);
tschatzl@5773 143 return biased_base() + biased_index;
tschatzl@5773 144 }
tschatzl@5773 145
tschatzl@5773 146 public:
tschatzl@5773 147 // Return the smallest address (inclusive) in the heap that this array covers.
tschatzl@5773 148 HeapWord* bottom_address_mapped() const {
tschatzl@5773 149 return (HeapWord*) ((uintptr_t)this->bias() << this->shift_by());
tschatzl@5773 150 }
tschatzl@5773 151
tschatzl@5773 152 // Return the highest address (exclusive) in the heap that this array covers.
tschatzl@5773 153 HeapWord* end_address_mapped() const {
tschatzl@5773 154 return (HeapWord*) ((uintptr_t)(this->bias() + this->length()) << this->shift_by());
tschatzl@5773 155 }
tschatzl@5773 156
tschatzl@5773 157 protected:
tschatzl@5773 158 virtual T default_value() const = 0;
tschatzl@5773 159 // Set all elements of the given array to the given value.
tschatzl@5773 160 void clear() {
tschatzl@5773 161 T value = default_value();
tschatzl@5773 162 for (idx_t i = 0; i < length(); i++) {
tschatzl@5773 163 set_by_index(i, value);
tschatzl@5773 164 }
tschatzl@5773 165 }
tschatzl@5773 166 public:
tschatzl@5773 167 G1BiasedMappedArray() {}
tschatzl@5773 168
tschatzl@5773 169 // Allocate and initialize this array to cover the heap addresses in the range
tschatzl@5773 170 // of [bottom, end).
tschatzl@5773 171 void initialize(HeapWord* bottom, HeapWord* end, size_t mapping_granularity) {
tschatzl@5773 172 G1BiasedMappedArrayBase::initialize(bottom, end, sizeof(T), mapping_granularity);
tschatzl@5773 173 this->clear();
tschatzl@5773 174 }
tschatzl@5773 175 };
tschatzl@5773 176
tschatzl@5773 177 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1BIASEDARRAY_HPP

mercurial