annotate src/share/vm/gc_implementation/g1/heapRegionSet.inline.hpp @ 2152:0fa27f37d4d4

6977804: G1: remove the zero-filling thread Summary: This changeset removes the zero-filling thread from G1 and collapses the two free region lists we had before (the "free" and "unclean" lists) into one. The new free list uses the new heap region sets / lists abstractions that we'll ultimately use it to keep track of all regions in the heap. A heap region set was also introduced for the humongous regions. Finally, this change increases the concurrency between the thread that completes freeing regions (after a cleanup pause) and the rest of the system (before we'd have to wait for said thread to complete before allocating a new region). The changest also includes a lot of refactoring and code simplification. Reviewed-by: jcoomes, johnc
author tonyp
date Wed, 19 Jan 2011 19:30:42 -0500
parents
children 1216415d8e35
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2152
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
1 /*
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
2 * copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
4 *
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
7 * published by the Free Software Foundation.
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
8 *
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
13 * accompanied this code).
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
14 *
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
18 *
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
21 * questions.
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
22 *
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
23 */
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
24
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
26 #define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
27
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
28 #include "gc_implementation/g1/heapRegionSet.hpp"
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
29
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
30 //////////////////// HeapRegionSetBase ////////////////////
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
31
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
32 inline void HeapRegionSetBase::update_for_addition(HeapRegion* hr) {
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
33 // Assumes the caller has already verified the region.
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
34
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
35 _length += 1;
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
36 if (!hr->isHumongous()) {
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
37 _region_num += 1;
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
38 } else {
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
39 _region_num += calculate_region_num(hr);
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
40 }
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
41 _total_used_bytes += hr->used();
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
42 }
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
43
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
44 inline void HeapRegionSetBase::add_internal(HeapRegion* hr) {
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
45 hrl_assert_region_ok(this, hr, NULL);
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
46 assert(hr->next() == NULL, hrl_ext_msg(this, "should not already be linked"));
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
47
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
48 update_for_addition(hr);
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
49 hr->set_containing_set(this);
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
50 }
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
51
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
52 inline void HeapRegionSetBase::update_for_removal(HeapRegion* hr) {
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
53 // Assumes the caller has already verified the region.
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
54 assert(_length > 0, hrl_ext_msg(this, "pre-condition"));
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
55 _length -= 1;
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
56
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
57 size_t region_num_diff;
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
58 if (!hr->isHumongous()) {
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
59 region_num_diff = 1;
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
60 } else {
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
61 region_num_diff = calculate_region_num(hr);
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
62 }
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
63 assert(region_num_diff <= _region_num,
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
64 hrl_err_msg("[%s] region's region num: "SIZE_FORMAT" "
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
65 "should be <= region num: "SIZE_FORMAT,
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
66 name(), region_num_diff, _region_num));
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
67 _region_num -= region_num_diff;
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
68
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
69 size_t used_bytes = hr->used();
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
70 assert(used_bytes <= _total_used_bytes,
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
71 hrl_err_msg("[%s] region's used bytes: "SIZE_FORMAT" "
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
72 "should be <= used bytes: "SIZE_FORMAT,
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
73 name(), used_bytes, _total_used_bytes));
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
74 _total_used_bytes -= used_bytes;
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
75 }
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
76
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
77 inline void HeapRegionSetBase::remove_internal(HeapRegion* hr) {
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
78 hrl_assert_region_ok(this, hr, this);
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
79 assert(hr->next() == NULL, hrl_ext_msg(this, "should already be unlinked"));
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
80
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
81 hr->set_containing_set(NULL);
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
82 update_for_removal(hr);
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
83 }
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
84
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
85 //////////////////// HeapRegionSet ////////////////////
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
86
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
87 inline void HeapRegionSet::add(HeapRegion* hr) {
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
88 hrl_assert_mt_safety_ok(this);
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
89 // add_internal() will verify the region.
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
90 add_internal(hr);
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
91 }
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
92
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
93 inline void HeapRegionSet::remove(HeapRegion* hr) {
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
94 hrl_assert_mt_safety_ok(this);
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
95 // remove_internal() will verify the region.
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
96 remove_internal(hr);
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
97 }
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
98
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
99 inline void HeapRegionSet::remove_with_proxy(HeapRegion* hr,
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
100 HeapRegionSet* proxy_set) {
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
101 // No need to fo the MT safety check here given that this method
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
102 // does not update the contents of the set but instead accumulates
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
103 // the changes in proxy_set which is assumed to be thread-local.
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
104 hrl_assert_sets_match(this, proxy_set);
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
105 hrl_assert_region_ok(this, hr, this);
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
106
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
107 hr->set_containing_set(NULL);
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
108 proxy_set->update_for_addition(hr);
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
109 }
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
110
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
111 //////////////////// HeapRegionLinkedList ////////////////////
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
112
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
113 inline void HeapRegionLinkedList::add_as_tail(HeapRegion* hr) {
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
114 hrl_assert_mt_safety_ok(this);
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
115 assert((length() == 0 && _head == NULL && _tail == NULL) ||
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
116 (length() > 0 && _head != NULL && _tail != NULL),
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
117 hrl_ext_msg(this, "invariant"));
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
118 // add_internal() will verify the region.
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
119 add_internal(hr);
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
120
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
121 // Now link the region.
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
122 if (_tail != NULL) {
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
123 _tail->set_next(hr);
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
124 } else {
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
125 _head = hr;
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
126 }
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
127 _tail = hr;
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
128 }
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
129
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
130 inline HeapRegion* HeapRegionLinkedList::remove_head() {
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
131 hrl_assert_mt_safety_ok(this);
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
132 assert(!is_empty(), hrl_ext_msg(this, "the list should not be empty"));
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
133 assert(length() > 0 && _head != NULL && _tail != NULL,
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
134 hrl_ext_msg(this, "invariant"));
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
135
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
136 // We need to unlink it first.
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
137 HeapRegion* hr = _head;
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
138 _head = hr->next();
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
139 if (_head == NULL) {
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
140 _tail = NULL;
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
141 }
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
142 hr->set_next(NULL);
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
143
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
144 // remove_internal() will verify the region.
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
145 remove_internal(hr);
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
146 return hr;
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
147 }
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
148
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
149 inline HeapRegion* HeapRegionLinkedList::remove_head_or_null() {
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
150 hrl_assert_mt_safety_ok(this);
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
151
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
152 if (!is_empty()) {
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
153 return remove_head();
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
154 } else {
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
155 return NULL;
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
156 }
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
157 }
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
158
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
159 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP