annotate src/share/vm/gc_implementation/g1/heapRegionSeq.cpp @ 6197:d2a62e0f25eb

6995781: Native Memory Tracking (Phase 1) 7151532: DCmd for hotspot native memory tracking Summary: Implementation of native memory tracking phase 1, which tracks VM native memory usage, and related DCmd Reviewed-by: acorn, coleenp, fparain
author zgu
date Thu, 28 Jun 2012 17:03:16 -0400
parents 720b6a76dd9d
children b0d20fa374b4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
1 /*
6010
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
2 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
4 *
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
7 * published by the Free Software Foundation.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
8 *
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
13 * accompanied this code).
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
14 *
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 960
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 960
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 960
diff changeset
21 * questions.
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
22 *
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
23 */
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1886
diff changeset
25 #include "precompiled.hpp"
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
26 #include "gc_implementation/g1/heapRegion.hpp"
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
27 #include "gc_implementation/g1/heapRegionSeq.inline.hpp"
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
28 #include "gc_implementation/g1/heapRegionSets.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1886
diff changeset
29 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1886
diff changeset
30 #include "memory/allocation.hpp"
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
31
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
32 // Private
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
33
6010
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
34 uint HeapRegionSeq::find_contiguous_from(uint from, uint num) {
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
35 uint len = length();
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
36 assert(num > 1, "use this only for sequences of length 2 or greater");
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
37 assert(from <= len,
6010
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
38 err_msg("from: %u should be valid and <= than %u", from, len));
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
39
6010
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
40 uint curr = from;
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
41 uint first = G1_NULL_HRS_INDEX;
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
42 uint num_so_far = 0;
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
43 while (curr < len && num_so_far < num) {
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
44 if (at(curr)->is_empty()) {
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
45 if (first == G1_NULL_HRS_INDEX) {
2152
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents: 2133
diff changeset
46 first = curr;
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents: 2133
diff changeset
47 num_so_far = 1;
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents: 2133
diff changeset
48 } else {
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents: 2133
diff changeset
49 num_so_far += 1;
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents: 2133
diff changeset
50 }
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents: 2133
diff changeset
51 } else {
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
52 first = G1_NULL_HRS_INDEX;
2152
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents: 2133
diff changeset
53 num_so_far = 0;
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents: 2133
diff changeset
54 }
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents: 2133
diff changeset
55 curr += 1;
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents: 2133
diff changeset
56 }
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents: 2133
diff changeset
57 assert(num_so_far <= num, "post-condition");
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents: 2133
diff changeset
58 if (num_so_far == num) {
2361
1216415d8e35 7014923: G1: code cleanup
tonyp
parents: 2172
diff changeset
59 // we found enough space for the humongous object
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
60 assert(from <= first && first < len, "post-condition");
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
61 assert(first < curr && (curr - first) == num, "post-condition");
6010
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
62 for (uint i = first; i < first + num; ++i) {
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
63 assert(at(i)->is_empty(), "post-condition");
2152
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents: 2133
diff changeset
64 }
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents: 2133
diff changeset
65 return first;
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents: 2133
diff changeset
66 } else {
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents: 2133
diff changeset
67 // we failed to find enough space for the humongous object
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
68 return G1_NULL_HRS_INDEX;
2152
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents: 2133
diff changeset
69 }
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents: 2133
diff changeset
70 }
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents: 2133
diff changeset
71
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
72 // Public
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
73
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
74 void HeapRegionSeq::initialize(HeapWord* bottom, HeapWord* end,
6010
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
75 uint max_length) {
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
76 assert((uintptr_t) bottom % HeapRegion::GrainBytes == 0,
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
77 "bottom should be heap region aligned");
6010
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
78 assert((uintptr_t) end % HeapRegion::GrainBytes == 0,
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
79 "end should be heap region aligned");
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
80
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
81 _length = 0;
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
82 _heap_bottom = bottom;
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
83 _heap_end = end;
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
84 _region_shift = HeapRegion::LogOfHRGrainBytes;
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
85 _next_search_index = 0;
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
86 _allocated_length = 0;
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
87 _max_length = max_length;
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
88
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6010
diff changeset
89 _regions = NEW_C_HEAP_ARRAY(HeapRegion*, max_length, mtGC);
6010
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
90 memset(_regions, 0, (size_t) max_length * sizeof(HeapRegion*));
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
91 _regions_biased = _regions - ((uintx) bottom >> _region_shift);
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
92
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
93 assert(&_regions[0] == &_regions_biased[addr_to_index_biased(bottom)],
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
94 "bottom should be included in the region with index 0");
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
95 }
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
96
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
97 MemRegion HeapRegionSeq::expand_by(HeapWord* old_end,
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
98 HeapWord* new_end,
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
99 FreeRegionList* list) {
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
100 assert(old_end < new_end, "don't call it otherwise");
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
101 G1CollectedHeap* g1h = G1CollectedHeap::heap();
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
102
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
103 HeapWord* next_bottom = old_end;
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
104 assert(_heap_bottom <= next_bottom, "invariant");
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
105 while (next_bottom < new_end) {
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
106 assert(next_bottom < _heap_end, "invariant");
6010
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
107 uint index = length();
2152
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents: 2133
diff changeset
108
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
109 assert(index < _max_length, "otherwise we cannot expand further");
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
110 if (index == 0) {
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
111 // We have not allocated any regions so far
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
112 assert(next_bottom == _heap_bottom, "invariant");
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
113 } else {
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
114 // next_bottom should match the end of the last/previous region
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
115 assert(next_bottom == at(index - 1)->end(), "invariant");
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
116 }
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
117
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
118 if (index == _allocated_length) {
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
119 // We have to allocate a new HeapRegion.
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
120 HeapRegion* new_hr = g1h->new_heap_region(index, next_bottom);
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
121 if (new_hr == NULL) {
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
122 // allocation failed, we bail out and return what we have done so far
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
123 return MemRegion(old_end, next_bottom);
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
124 }
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
125 assert(_regions[index] == NULL, "invariant");
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
126 _regions[index] = new_hr;
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
127 increment_length(&_allocated_length);
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
128 }
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
129 // Have to increment the length first, otherwise we will get an
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
130 // assert failure at(index) below.
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
131 increment_length(&_length);
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
132 HeapRegion* hr = at(index);
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
133 list->add_as_tail(hr);
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
134
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
135 next_bottom = hr->end();
2152
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents: 2133
diff changeset
136 }
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
137 assert(next_bottom == new_end, "post-condition");
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
138 return MemRegion(old_end, next_bottom);
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
139 }
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
140
6010
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
141 uint HeapRegionSeq::free_suffix() {
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
142 uint res = 0;
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
143 uint index = length();
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
144 while (index > 0) {
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
145 index -= 1;
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
146 if (!at(index)->is_empty()) {
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
147 break;
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
148 }
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
149 res += 1;
2152
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents: 2133
diff changeset
150 }
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
151 return res;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
152 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
153
6010
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
154 uint HeapRegionSeq::find_contiguous(uint num) {
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
155 assert(num > 1, "use this only for sequences of length 2 or greater");
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
156 assert(_next_search_index <= length(),
6010
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
157 err_msg("_next_search_index: %u should be valid and <= than %u",
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
158 _next_search_index, length()));
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
159
6010
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
160 uint start = _next_search_index;
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
161 uint res = find_contiguous_from(start, num);
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
162 if (res == G1_NULL_HRS_INDEX && start > 0) {
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
163 // Try starting from the beginning. If _next_search_index was 0,
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
164 // no point in doing this again.
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
165 res = find_contiguous_from(0, num);
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
166 }
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
167 if (res != G1_NULL_HRS_INDEX) {
6010
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
168 assert(res < length(), err_msg("res: %u should be valid", res));
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
169 _next_search_index = res + num;
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
170 assert(_next_search_index <= length(),
6010
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
171 err_msg("_next_search_index: %u should be valid and <= than %u",
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
172 _next_search_index, length()));
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
173 }
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
174 return res;
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
175 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
176
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
177 void HeapRegionSeq::iterate(HeapRegionClosure* blk) const {
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
178 iterate_from((HeapRegion*) NULL, blk);
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
179 }
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
180
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
181 void HeapRegionSeq::iterate_from(HeapRegion* hr, HeapRegionClosure* blk) const {
6010
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
182 uint hr_index = 0;
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
183 if (hr != NULL) {
6010
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
184 hr_index = hr->hrs_index();
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
185 }
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
186
6010
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
187 uint len = length();
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
188 for (uint i = hr_index; i < len; i += 1) {
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
189 bool res = blk->doHeapRegion(at(i));
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
190 if (res) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
191 blk->incomplete();
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
192 return;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
193 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
194 }
6010
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
195 for (uint i = 0; i < hr_index; i += 1) {
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
196 bool res = blk->doHeapRegion(at(i));
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
197 if (res) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
198 blk->incomplete();
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
199 return;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
200 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
201 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
202 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
203
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
204 MemRegion HeapRegionSeq::shrink_by(size_t shrink_bytes,
6010
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
205 uint* num_regions_deleted) {
2152
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents: 2133
diff changeset
206 // Reset this in case it's currently pointing into the regions that
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents: 2133
diff changeset
207 // we just removed.
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
208 _next_search_index = 0;
2152
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents: 2133
diff changeset
209
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
210 assert(shrink_bytes % os::vm_page_size() == 0, "unaligned");
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
211 assert(shrink_bytes % HeapRegion::GrainBytes == 0, "unaligned");
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
212 assert(length() > 0, "the region sequence should not be empty");
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
213 assert(length() <= _allocated_length, "invariant");
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
214 assert(_allocated_length > 0, "we should have at least one region committed");
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
215
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
216 // around the loop, i will be the next region to be removed
6010
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
217 uint i = length() - 1;
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
218 assert(i > 0, "we should never remove all regions");
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
219 // [last_start, end) is the MemRegion that covers the regions we will remove.
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
220 HeapWord* end = at(i)->end();
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
221 HeapWord* last_start = end;
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
222 *num_regions_deleted = 0;
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
223 while (shrink_bytes > 0) {
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
224 HeapRegion* cur = at(i);
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
225 // We should leave the humongous regions where they are.
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
226 if (cur->isHumongous()) break;
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
227 // We should stop shrinking if we come across a non-empty region.
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
228 if (!cur->is_empty()) break;
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
229
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
230 i -= 1;
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
231 *num_regions_deleted += 1;
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
232 shrink_bytes -= cur->capacity();
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
233 last_start = cur->bottom();
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
234 decrement_length(&_length);
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
235 // We will reclaim the HeapRegion. _allocated_length should be
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
236 // covering this index. So, even though we removed the region from
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
237 // the active set by decreasing _length, we still have it
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
238 // available in the future if we need to re-use it.
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
239 assert(i > 0, "we should never remove all regions");
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
240 assert(length() > 0, "we should never remove all regions");
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
241 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
242 return MemRegion(last_start, end);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
243 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
244
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
245 #ifndef PRODUCT
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
246 void HeapRegionSeq::verify_optional() {
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
247 guarantee(_length <= _allocated_length,
6010
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
248 err_msg("invariant: _length: %u _allocated_length: %u",
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
249 _length, _allocated_length));
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
250 guarantee(_allocated_length <= _max_length,
6010
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
251 err_msg("invariant: _allocated_length: %u _max_length: %u",
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
252 _allocated_length, _max_length));
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
253 guarantee(_next_search_index <= _length,
6010
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
254 err_msg("invariant: _next_search_index: %u _length: %u",
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
255 _next_search_index, _length));
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
256
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
257 HeapWord* prev_end = _heap_bottom;
6010
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
258 for (uint i = 0; i < _allocated_length; i += 1) {
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
259 HeapRegion* hr = _regions[i];
6010
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
260 guarantee(hr != NULL, err_msg("invariant: i: %u", i));
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
261 guarantee(hr->bottom() == prev_end,
6010
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
262 err_msg("invariant i: %u "HR_FORMAT" prev_end: "PTR_FORMAT,
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
263 i, HR_FORMAT_PARAMS(hr), prev_end));
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
264 guarantee(hr->hrs_index() == i,
6010
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
265 err_msg("invariant: i: %u hrs_index(): %u", i, hr->hrs_index()));
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
266 if (i < _length) {
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
267 // Asserts will fire if i is >= _length
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
268 HeapWord* addr = hr->bottom();
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
269 guarantee(addr_to_region(addr) == hr, "sanity");
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
270 guarantee(addr_to_region_unsafe(addr) == hr, "sanity");
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
271 } else {
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
272 guarantee(hr->is_empty(), "sanity");
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
273 guarantee(!hr->isHumongous(), "sanity");
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
274 // using assert instead of guarantee here since containing_set()
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
275 // is only available in non-product builds.
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
276 assert(hr->containing_set() == NULL, "sanity");
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
277 }
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
278 if (hr->startsHumongous()) {
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
279 prev_end = hr->orig_end();
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
280 } else {
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
281 prev_end = hr->end();
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
282 }
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
283 }
6010
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
284 for (uint i = _allocated_length; i < _max_length; i += 1) {
720b6a76dd9d 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 3766
diff changeset
285 guarantee(_regions[i] == NULL, err_msg("invariant i: %u", i));
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
286 }
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
287 }
3766
c3f1170908be 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 2361
diff changeset
288 #endif // PRODUCT