Mercurial > hg > truffle
annotate src/share/vm/gc_implementation/g1/collectionSetChooser.hpp @ 5935:a735aec54ea4
7123170: JCK vm/jvmti/ResourceExhausted/resexh001/resexh00101/ tests fails since 7u4 b02
Summary: The JVMTI ResourceExhausted events must be generated in all places where OOME is thrown
Reviewed-by: acorn, coleenp, dcubed, dholmes, dsamersoff, jwilhelm, tonyp
Contributed-by: serguei.spitsyn@oracle.com
author | sspitsyn |
---|---|
date | Wed, 14 Mar 2012 20:06:48 -0700 |
parents | a9647476d1a4 |
children | 720b6a76dd9d |
rev | line source |
---|---|
342 | 1 /* |
4912
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
2 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. |
342 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
579
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
579
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:
579
diff
changeset
|
21 * questions. |
342 | 22 * |
23 */ | |
24 | |
1972 | 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP |
26 #define SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP | |
27 | |
28 #include "gc_implementation/g1/heapRegion.hpp" | |
29 #include "utilities/growableArray.hpp" | |
30 | |
549
fe3d7c11b4b7
6700941: G1: allocation spec missing for some G1 classes
apetrusenko
parents:
342
diff
changeset
|
31 class CSetChooserCache VALUE_OBJ_CLASS_SPEC { |
342 | 32 private: |
33 enum { | |
34 CacheLength = 16 | |
35 } PrivateConstants; | |
36 | |
37 HeapRegion* _cache[CacheLength]; | |
3989
b9390528617c
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
2435
diff
changeset
|
38 int _occupancy; // number of regions in cache |
b9390528617c
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
2435
diff
changeset
|
39 int _first; // (index of) "first" region in the cache |
342 | 40 |
41 // adding CacheLength to deal with negative values | |
42 inline int trim_index(int index) { | |
43 return (index + CacheLength) % CacheLength; | |
44 } | |
45 | |
46 inline int get_sort_index(int index) { | |
47 return -index-2; | |
48 } | |
49 inline int get_index(int sort_index) { | |
50 return -sort_index-2; | |
51 } | |
52 | |
53 public: | |
54 CSetChooserCache(void); | |
55 | |
56 inline int occupancy(void) { return _occupancy; } | |
57 inline bool is_full() { return _occupancy == CacheLength; } | |
58 inline bool is_empty() { return _occupancy == 0; } | |
59 | |
60 void clear(void); | |
61 void insert(HeapRegion *hr); | |
62 HeapRegion *remove_first(void); | |
63 inline HeapRegion *get_first(void) { | |
64 return _cache[_first]; | |
65 } | |
66 | |
67 #ifndef PRODUCT | |
68 bool verify (void); | |
69 bool region_in_cache(HeapRegion *hr) { | |
70 int sort_index = hr->sort_index(); | |
71 if (sort_index < -1) { | |
72 int index = get_index(sort_index); | |
73 guarantee(index < CacheLength, "should be within bounds"); | |
74 return _cache[index] == hr; | |
75 } else | |
76 return 0; | |
77 } | |
78 #endif // PRODUCT | |
79 }; | |
80 | |
81 class CollectionSetChooser: public CHeapObj { | |
82 | |
83 GrowableArray<HeapRegion*> _markedRegions; | |
4912
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
84 |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
85 // The index of the next candidate old region to be considered for |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
86 // addition to the CSet. |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
87 int _curr_index; |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
88 |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
89 // The number of candidate old regions added to the CSet chooser. |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
90 int _length; |
342 | 91 |
4912
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
92 CSetChooserCache _cache; |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
93 jint _first_par_unreserved_idx; |
342 | 94 |
4912
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
95 // If a region has more live bytes than this threshold, it will not |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
96 // be added to the CSet chooser and will not be a candidate for |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
97 // collection. |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
98 size_t _regionLiveThresholdBytes; |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
99 |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
100 // The sum of reclaimable bytes over all the regions in the CSet chooser. |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
101 size_t _remainingReclaimableBytes; |
342 | 102 |
103 public: | |
104 | |
4912
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
105 // Return the current candidate region to be considered for |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
106 // collection without removing it from the CSet chooser. |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
107 HeapRegion* peek() { |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
108 HeapRegion* res = NULL; |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
109 if (_curr_index < _length) { |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
110 res = _markedRegions.at(_curr_index); |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
111 assert(res != NULL, |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
112 err_msg("Unexpected NULL hr in _markedRegions at index %d", |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
113 _curr_index)); |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
114 } |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
115 return res; |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
116 } |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
117 |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
118 // Remove the given region from the CSet chooser and move to the |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
119 // next one. The given region should be the current candidate region |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
120 // in the CSet chooser. |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
121 void remove_and_move_to_next(HeapRegion* hr) { |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
122 assert(hr != NULL, "pre-condition"); |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
123 assert(_curr_index < _length, "pre-condition"); |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
124 assert(_markedRegions.at(_curr_index) == hr, "pre-condition"); |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
125 hr->set_sort_index(-1); |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
126 _markedRegions.at_put(_curr_index, NULL); |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
127 assert(hr->reclaimable_bytes() <= _remainingReclaimableBytes, |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
128 err_msg("remaining reclaimable bytes inconsistent " |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
129 "from region: "SIZE_FORMAT" remaining: "SIZE_FORMAT, |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
130 hr->reclaimable_bytes(), _remainingReclaimableBytes)); |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
131 _remainingReclaimableBytes -= hr->reclaimable_bytes(); |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
132 _curr_index += 1; |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
133 } |
342 | 134 |
135 CollectionSetChooser(); | |
136 | |
137 void sortMarkedHeapRegions(); | |
138 void fillCache(); | |
4912
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
139 |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
140 // Determine whether to add the given region to the CSet chooser or |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
141 // not. Currently, we skip humongous regions (we never add them to |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
142 // the CSet, we only reclaim them during cleanup) and regions whose |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
143 // live bytes are over the threshold. |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
144 bool shouldAdd(HeapRegion* hr) { |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
145 assert(hr->is_marked(), "pre-condition"); |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
146 assert(!hr->is_young(), "should never consider young regions"); |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
147 return !hr->isHumongous() && |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
148 hr->live_bytes() < _regionLiveThresholdBytes; |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
149 } |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
150 |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
151 // Calculate the minimum number of old regions we'll add to the CSet |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
152 // during a mixed GC. |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
153 size_t calcMinOldCSetLength(); |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
154 |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
155 // Calculate the maximum number of old regions we'll add to the CSet |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
156 // during a mixed GC. |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
157 size_t calcMaxOldCSetLength(); |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
158 |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
159 // Serial version. |
342 | 160 void addMarkedHeapRegion(HeapRegion *hr); |
161 | |
162 // Must be called before calls to getParMarkedHeapRegionChunk. | |
163 // "n_regions" is the number of regions, "chunkSize" the chunk size. | |
164 void prepareForAddMarkedHeapRegionsPar(size_t n_regions, size_t chunkSize); | |
165 // Returns the first index in a contiguous chunk of "n_regions" indexes | |
166 // that the calling thread has reserved. These must be set by the | |
167 // calling thread using "setMarkedHeapRegion" (to NULL if necessary). | |
168 jint getParMarkedHeapRegionChunk(jint n_regions); | |
169 // Set the marked array entry at index to hr. Careful to claim the index | |
170 // first if in parallel. | |
171 void setMarkedHeapRegion(jint index, HeapRegion* hr); | |
4912
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
172 // Atomically increment the number of added regions by region_num |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
173 // and the amount of reclaimable bytes by reclaimable_bytes. |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
174 void updateTotals(jint region_num, size_t reclaimable_bytes); |
342 | 175 |
176 void clearMarkedHeapRegions(); | |
177 | |
4912
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
178 // Return the number of candidate regions that remain to be collected. |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
179 size_t remainingRegions() { return _length - _curr_index; } |
342 | 180 |
4912
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
181 // Determine whether the CSet chooser has more candidate regions or not. |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
182 bool isEmpty() { return remainingRegions() == 0; } |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
183 |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
184 // Return the reclaimable bytes that remain to be collected on |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
185 // all the candidate regions in the CSet chooser. |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
186 size_t remainingReclaimableBytes () { return _remainingReclaimableBytes; } |
342 | 187 |
188 // Returns true if the used portion of "_markedRegions" is properly | |
189 // sorted, otherwise asserts false. | |
190 #ifndef PRODUCT | |
191 bool verify(void); | |
192 bool regionProperlyOrdered(HeapRegion* r) { | |
193 int si = r->sort_index(); | |
4912
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
194 if (si > -1) { |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
195 guarantee(_curr_index <= si && si < _length, |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
196 err_msg("curr: %d sort index: %d: length: %d", |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
197 _curr_index, si, _length)); |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
198 guarantee(_markedRegions.at(si) == r, |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
199 err_msg("sort index: %d at: "PTR_FORMAT" r: "PTR_FORMAT, |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
200 si, _markedRegions.at(si), r)); |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
201 } else { |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
202 guarantee(si == -1, err_msg("sort index: %d", si)); |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
203 } |
a9647476d1a4
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
3989
diff
changeset
|
204 return true; |
342 | 205 } |
206 #endif | |
207 | |
208 }; | |
1972 | 209 |
210 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP |