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

Mon, 24 Mar 2014 15:30:14 +0100

author
tschatzl
date
Mon, 24 Mar 2014 15:30:14 +0100
changeset 6402
191174b49bec
parent 5773
a19bea467577
child 6409
5479cb006184
permissions
-rw-r--r--

8035406: Improve data structure for Code Cache remembered sets
Summary: Change the code cache remembered sets data structure from a GrowableArray to a chunked list of nmethods. This makes the data structure more amenable to parallelization, and decreases freeing time.
Reviewed-by: mgerdin, brutisso

tschatzl@5773 1 /*
tschatzl@5773 2 * Copyright (c) 2013, 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 #include "precompiled.hpp"
tschatzl@5773 26 #include "gc_implementation/g1/g1BiasedArray.hpp"
tschatzl@5773 27
tschatzl@5773 28 #ifndef PRODUCT
tschatzl@5773 29 void G1BiasedMappedArrayBase::verify_index(idx_t index) const {
tschatzl@5773 30 guarantee(_base != NULL, "Array not initialized");
tschatzl@5773 31 guarantee(index < length(), err_msg("Index out of bounds index: "SIZE_FORMAT" length: "SIZE_FORMAT, index, length()));
tschatzl@5773 32 }
tschatzl@5773 33
tschatzl@5773 34 void G1BiasedMappedArrayBase::verify_biased_index(idx_t biased_index) const {
tschatzl@5773 35 guarantee(_biased_base != NULL, "Array not initialized");
tschatzl@5773 36 guarantee(biased_index >= bias() && biased_index < (bias() + length()),
tschatzl@5773 37 err_msg("Biased index out of bounds, index: "SIZE_FORMAT" bias: "SIZE_FORMAT" length: "SIZE_FORMAT, biased_index, bias(), length()));
tschatzl@5773 38 }
tschatzl@5773 39
tschatzl@5773 40 void G1BiasedMappedArrayBase::verify_biased_index_inclusive_end(idx_t biased_index) const {
tschatzl@5773 41 guarantee(_biased_base != NULL, "Array not initialized");
tschatzl@5773 42 guarantee(biased_index >= bias() && biased_index <= (bias() + length()),
tschatzl@5773 43 err_msg("Biased index out of inclusive bounds, index: "SIZE_FORMAT" bias: "SIZE_FORMAT" length: "SIZE_FORMAT, biased_index, bias(), length()));
tschatzl@5773 44 }
tschatzl@5773 45
tschatzl@5773 46 class TestMappedArray : public G1BiasedMappedArray<int> {
tschatzl@5773 47 protected:
tschatzl@5773 48 virtual int default_value() const { return 0xBAADBABE; }
tschatzl@5773 49 public:
tschatzl@5773 50 static void test_biasedarray() {
tschatzl@5773 51 const size_t REGION_SIZE_IN_WORDS = 512;
tschatzl@5773 52 const size_t NUM_REGIONS = 20;
tschatzl@5773 53 HeapWord* fake_heap = (HeapWord*)LP64_ONLY(0xBAAA00000) NOT_LP64(0xBA000000); // Any value that is non-zero
tschatzl@5773 54
tschatzl@5773 55 TestMappedArray array;
tschatzl@5773 56 array.initialize(fake_heap, fake_heap + REGION_SIZE_IN_WORDS * NUM_REGIONS,
tschatzl@5773 57 REGION_SIZE_IN_WORDS * HeapWordSize);
tschatzl@5773 58 // Check address calculation (bounds)
tschatzl@5773 59 assert(array.bottom_address_mapped() == fake_heap,
tschatzl@5773 60 err_msg("bottom mapped address should be "PTR_FORMAT", but is "PTR_FORMAT, fake_heap, array.bottom_address_mapped()));
tschatzl@5773 61 assert(array.end_address_mapped() == (fake_heap + REGION_SIZE_IN_WORDS * NUM_REGIONS), "must be");
tschatzl@5773 62
tschatzl@5773 63 int* bottom = array.address_mapped_to(fake_heap);
tschatzl@5773 64 assert((void*)bottom == (void*) array.base(), "must be");
tschatzl@5773 65 int* end = array.address_mapped_to(fake_heap + REGION_SIZE_IN_WORDS * NUM_REGIONS);
tschatzl@5773 66 assert((void*)end == (void*)(array.base() + array.length()), "must be");
tschatzl@5773 67 // The entire array should contain default value elements
tschatzl@5773 68 for (int* current = bottom; current < end; current++) {
tschatzl@5773 69 assert(*current == array.default_value(), "must be");
tschatzl@5773 70 }
tschatzl@5773 71
tschatzl@5773 72 // Test setting values in the table
tschatzl@5773 73
tschatzl@5773 74 HeapWord* region_start_address = fake_heap + REGION_SIZE_IN_WORDS * (NUM_REGIONS / 2);
tschatzl@5773 75 HeapWord* region_end_address = fake_heap + (REGION_SIZE_IN_WORDS * (NUM_REGIONS / 2) + REGION_SIZE_IN_WORDS - 1);
tschatzl@5773 76
tschatzl@5773 77 // Set/get by address tests: invert some value; first retrieve one
tschatzl@5773 78 int actual_value = array.get_by_index(NUM_REGIONS / 2);
tschatzl@5773 79 array.set_by_index(NUM_REGIONS / 2, ~actual_value);
tschatzl@5773 80 // Get the same value by address, should correspond to the start of the "region"
tschatzl@5773 81 int value = array.get_by_address(region_start_address);
tschatzl@5773 82 assert(value == ~actual_value, "must be");
tschatzl@5773 83 // Get the same value by address, at one HeapWord before the start
tschatzl@5773 84 value = array.get_by_address(region_start_address - 1);
tschatzl@5773 85 assert(value == array.default_value(), "must be");
tschatzl@5773 86 // Get the same value by address, at the end of the "region"
tschatzl@5773 87 value = array.get_by_address(region_end_address);
tschatzl@5773 88 assert(value == ~actual_value, "must be");
tschatzl@5773 89 // Make sure the next value maps to another index
tschatzl@5773 90 value = array.get_by_address(region_end_address + 1);
tschatzl@5773 91 assert(value == array.default_value(), "must be");
tschatzl@5773 92
tschatzl@5773 93 // Reset the value in the array
tschatzl@5773 94 array.set_by_address(region_start_address + (region_end_address - region_start_address) / 2, actual_value);
tschatzl@5773 95
tschatzl@5773 96 // The entire array should have the default value again
tschatzl@5773 97 for (int* current = bottom; current < end; current++) {
tschatzl@5773 98 assert(*current == array.default_value(), "must be");
tschatzl@5773 99 }
tschatzl@5773 100
tschatzl@5773 101 // Set/get by index tests: invert some value
tschatzl@5773 102 idx_t index = NUM_REGIONS / 2;
tschatzl@5773 103 actual_value = array.get_by_index(index);
tschatzl@5773 104 array.set_by_index(index, ~actual_value);
tschatzl@5773 105
tschatzl@5773 106 value = array.get_by_index(index);
tschatzl@5773 107 assert(value == ~actual_value, "must be");
tschatzl@5773 108
tschatzl@5773 109 value = array.get_by_index(index - 1);
tschatzl@5773 110 assert(value == array.default_value(), "must be");
tschatzl@5773 111
tschatzl@5773 112 value = array.get_by_index(index + 1);
tschatzl@5773 113 assert(value == array.default_value(), "must be");
tschatzl@5773 114
tschatzl@5773 115 array.set_by_index(0, 0);
tschatzl@5773 116 value = array.get_by_index(0);
tschatzl@5773 117 assert(value == 0, "must be");
tschatzl@5773 118
tschatzl@5773 119 array.set_by_index(array.length() - 1, 0);
tschatzl@5773 120 value = array.get_by_index(array.length() - 1);
tschatzl@5773 121 assert(value == 0, "must be");
tschatzl@5773 122
tschatzl@5773 123 array.set_by_index(index, 0);
tschatzl@5773 124
tschatzl@5773 125 // The array should have three zeros, and default values otherwise
tschatzl@5773 126 size_t num_zeros = 0;
tschatzl@5773 127 for (int* current = bottom; current < end; current++) {
tschatzl@5773 128 assert(*current == array.default_value() || *current == 0, "must be");
tschatzl@5773 129 if (*current == 0) {
tschatzl@5773 130 num_zeros++;
tschatzl@5773 131 }
tschatzl@5773 132 }
tschatzl@5773 133 assert(num_zeros == 3, "must be");
tschatzl@5773 134 }
tschatzl@5773 135 };
tschatzl@5773 136
tschatzl@5773 137 void TestG1BiasedArray_test() {
tschatzl@5773 138 TestMappedArray::test_biasedarray();
tschatzl@5773 139 }
tschatzl@5773 140
tschatzl@5773 141 #endif

mercurial