annotate src/share/vm/gc_implementation/g1/g1BiasedArray.cpp @ 12305:a19bea467577

7163191: G1: introduce a "heap spanning table" abstraction Summary: Add G1BiasedArray<T> that is an array where each element represents a fixed-sized subdivision of the heap. Use this abstraction to refactor the HeapRegionSeq class. Reviewed-by: brutisso
author tschatzl
date Wed, 25 Sep 2013 13:25:24 +0200
parents
children 5479cb006184
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12305
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
1 /*
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
4 *
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
7 * published by the Free Software Foundation.
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
8 *
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
13 * accompanied this code).
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
14 *
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
18 *
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
21 * questions.
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
22 *
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
23 */
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
24
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
25 #include "precompiled.hpp"
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
26 #include "gc_implementation/g1/g1BiasedArray.hpp"
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
27
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
28 #ifndef PRODUCT
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
29 void G1BiasedMappedArrayBase::verify_index(idx_t index) const {
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
30 guarantee(_base != NULL, "Array not initialized");
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
31 guarantee(index < length(), err_msg("Index out of bounds index: "SIZE_FORMAT" length: "SIZE_FORMAT, index, length()));
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
32 }
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
33
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
34 void G1BiasedMappedArrayBase::verify_biased_index(idx_t biased_index) const {
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
35 guarantee(_biased_base != NULL, "Array not initialized");
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
36 guarantee(biased_index >= bias() && biased_index < (bias() + length()),
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
37 err_msg("Biased index out of bounds, index: "SIZE_FORMAT" bias: "SIZE_FORMAT" length: "SIZE_FORMAT, biased_index, bias(), length()));
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
38 }
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
39
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
40 void G1BiasedMappedArrayBase::verify_biased_index_inclusive_end(idx_t biased_index) const {
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
41 guarantee(_biased_base != NULL, "Array not initialized");
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
42 guarantee(biased_index >= bias() && biased_index <= (bias() + length()),
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
43 err_msg("Biased index out of inclusive bounds, index: "SIZE_FORMAT" bias: "SIZE_FORMAT" length: "SIZE_FORMAT, biased_index, bias(), length()));
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
44 }
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
45
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
46 class TestMappedArray : public G1BiasedMappedArray<int> {
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
47 protected:
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
48 virtual int default_value() const { return 0xBAADBABE; }
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
49 public:
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
50 static void test_biasedarray() {
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
51 const size_t REGION_SIZE_IN_WORDS = 512;
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
52 const size_t NUM_REGIONS = 20;
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
53 HeapWord* fake_heap = (HeapWord*)LP64_ONLY(0xBAAA00000) NOT_LP64(0xBA000000); // Any value that is non-zero
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
54
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
55 TestMappedArray array;
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
56 array.initialize(fake_heap, fake_heap + REGION_SIZE_IN_WORDS * NUM_REGIONS,
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
57 REGION_SIZE_IN_WORDS * HeapWordSize);
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
58 // Check address calculation (bounds)
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
59 assert(array.bottom_address_mapped() == fake_heap,
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
60 err_msg("bottom mapped address should be "PTR_FORMAT", but is "PTR_FORMAT, fake_heap, array.bottom_address_mapped()));
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
61 assert(array.end_address_mapped() == (fake_heap + REGION_SIZE_IN_WORDS * NUM_REGIONS), "must be");
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
62
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
63 int* bottom = array.address_mapped_to(fake_heap);
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
64 assert((void*)bottom == (void*) array.base(), "must be");
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
65 int* end = array.address_mapped_to(fake_heap + REGION_SIZE_IN_WORDS * NUM_REGIONS);
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
66 assert((void*)end == (void*)(array.base() + array.length()), "must be");
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
67 // The entire array should contain default value elements
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
68 for (int* current = bottom; current < end; current++) {
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
69 assert(*current == array.default_value(), "must be");
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
70 }
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
71
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
72 // Test setting values in the table
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
73
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
74 HeapWord* region_start_address = fake_heap + REGION_SIZE_IN_WORDS * (NUM_REGIONS / 2);
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
75 HeapWord* region_end_address = fake_heap + (REGION_SIZE_IN_WORDS * (NUM_REGIONS / 2) + REGION_SIZE_IN_WORDS - 1);
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
76
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
77 // Set/get by address tests: invert some value; first retrieve one
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
78 int actual_value = array.get_by_index(NUM_REGIONS / 2);
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
79 array.set_by_index(NUM_REGIONS / 2, ~actual_value);
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
80 // Get the same value by address, should correspond to the start of the "region"
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
81 int value = array.get_by_address(region_start_address);
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
82 assert(value == ~actual_value, "must be");
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
83 // Get the same value by address, at one HeapWord before the start
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
84 value = array.get_by_address(region_start_address - 1);
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
85 assert(value == array.default_value(), "must be");
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
86 // Get the same value by address, at the end of the "region"
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
87 value = array.get_by_address(region_end_address);
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
88 assert(value == ~actual_value, "must be");
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
89 // Make sure the next value maps to another index
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
90 value = array.get_by_address(region_end_address + 1);
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
91 assert(value == array.default_value(), "must be");
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
92
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
93 // Reset the value in the array
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
94 array.set_by_address(region_start_address + (region_end_address - region_start_address) / 2, actual_value);
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
95
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
96 // The entire array should have the default value again
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
97 for (int* current = bottom; current < end; current++) {
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
98 assert(*current == array.default_value(), "must be");
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
99 }
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
100
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
101 // Set/get by index tests: invert some value
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
102 idx_t index = NUM_REGIONS / 2;
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
103 actual_value = array.get_by_index(index);
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
104 array.set_by_index(index, ~actual_value);
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
105
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
106 value = array.get_by_index(index);
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
107 assert(value == ~actual_value, "must be");
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
108
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
109 value = array.get_by_index(index - 1);
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
110 assert(value == array.default_value(), "must be");
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
111
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
112 value = array.get_by_index(index + 1);
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
113 assert(value == array.default_value(), "must be");
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
114
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
115 array.set_by_index(0, 0);
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
116 value = array.get_by_index(0);
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
117 assert(value == 0, "must be");
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
118
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
119 array.set_by_index(array.length() - 1, 0);
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
120 value = array.get_by_index(array.length() - 1);
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
121 assert(value == 0, "must be");
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
122
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
123 array.set_by_index(index, 0);
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
124
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
125 // The array should have three zeros, and default values otherwise
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
126 size_t num_zeros = 0;
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
127 for (int* current = bottom; current < end; current++) {
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
128 assert(*current == array.default_value() || *current == 0, "must be");
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
129 if (*current == 0) {
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
130 num_zeros++;
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
131 }
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
132 }
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
133 assert(num_zeros == 3, "must be");
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
134 }
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
135 };
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
136
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
137 void TestG1BiasedArray_test() {
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
138 TestMappedArray::test_biasedarray();
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
139 }
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
140
a19bea467577 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
141 #endif