Mercurial > hg > graal-compiler
annotate src/share/vm/gc_implementation/g1/collectionSetChooser.hpp @ 4834:6a78aa6ac1ff
7132311: G1: assert((s == klass->oop_size(this)) || (Universe::heap()->is_gc_active() && ((is_typeArray()...
Summary: Move the check for when to call collect() to before we do a humongous object allocation
Reviewed-by: stefank, tonyp
author | brutisso |
---|---|
date | Mon, 23 Jan 2012 20:36:16 +0100 |
parents | b9390528617c |
children | a9647476d1a4 |
rev | line source |
---|---|
342 | 1 /* |
3989
b9390528617c
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
2435
diff
changeset
|
2 * Copyright (c) 2001, 2011, 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 | |
342 | 31 // We need to sort heap regions by collection desirability. |
3989
b9390528617c
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
2435
diff
changeset
|
32 // This sorting is currently done in two "stages". An initial sort is |
b9390528617c
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
2435
diff
changeset
|
33 // done following a cleanup pause as soon as all of the marked but |
b9390528617c
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
2435
diff
changeset
|
34 // non-empty regions have been identified and the completely empty |
b9390528617c
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
2435
diff
changeset
|
35 // ones reclaimed. |
b9390528617c
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
2435
diff
changeset
|
36 // This gives us a global sort on a GC efficiency metric |
b9390528617c
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
2435
diff
changeset
|
37 // based on predictive data available at that time. However, |
b9390528617c
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
2435
diff
changeset
|
38 // any of these regions that are collected will only be collected |
b9390528617c
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
2435
diff
changeset
|
39 // during a future GC pause, by which time it is possible that newer |
b9390528617c
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
2435
diff
changeset
|
40 // data might allow us to revise and/or refine the earlier |
b9390528617c
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
2435
diff
changeset
|
41 // pause predictions, leading to changes in expected gc efficiency |
b9390528617c
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
2435
diff
changeset
|
42 // order. To somewhat mitigate this obsolescence, more so in the |
b9390528617c
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
2435
diff
changeset
|
43 // case of regions towards the end of the list, which will be |
b9390528617c
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
2435
diff
changeset
|
44 // picked later, these pre-sorted regions from the _markedRegions |
b9390528617c
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
2435
diff
changeset
|
45 // array are not used as is, but a small prefix thereof is |
b9390528617c
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
2435
diff
changeset
|
46 // insertion-sorted again into a small cache, based on more |
b9390528617c
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
2435
diff
changeset
|
47 // recent remembered set information. Regions are then drawn |
b9390528617c
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
2435
diff
changeset
|
48 // from this cache to construct the collection set at each |
b9390528617c
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
2435
diff
changeset
|
49 // incremental GC. |
b9390528617c
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
2435
diff
changeset
|
50 // This scheme and/or its implementation may be subject to |
b9390528617c
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
2435
diff
changeset
|
51 // revision in the future. |
342 | 52 |
549
fe3d7c11b4b7
6700941: G1: allocation spec missing for some G1 classes
apetrusenko
parents:
342
diff
changeset
|
53 class CSetChooserCache VALUE_OBJ_CLASS_SPEC { |
342 | 54 private: |
55 enum { | |
56 CacheLength = 16 | |
57 } PrivateConstants; | |
58 | |
59 HeapRegion* _cache[CacheLength]; | |
3989
b9390528617c
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
2435
diff
changeset
|
60 int _occupancy; // number of regions in cache |
b9390528617c
7095236: G1: _markedRegions never contains NULL regions
ysr
parents:
2435
diff
changeset
|
61 int _first; // (index of) "first" region in the cache |
342 | 62 |
63 // adding CacheLength to deal with negative values | |
64 inline int trim_index(int index) { | |
65 return (index + CacheLength) % CacheLength; | |
66 } | |
67 | |
68 inline int get_sort_index(int index) { | |
69 return -index-2; | |
70 } | |
71 inline int get_index(int sort_index) { | |
72 return -sort_index-2; | |
73 } | |
74 | |
75 public: | |
76 CSetChooserCache(void); | |
77 | |
78 inline int occupancy(void) { return _occupancy; } | |
79 inline bool is_full() { return _occupancy == CacheLength; } | |
80 inline bool is_empty() { return _occupancy == 0; } | |
81 | |
82 void clear(void); | |
83 void insert(HeapRegion *hr); | |
84 HeapRegion *remove_first(void); | |
85 inline HeapRegion *get_first(void) { | |
86 return _cache[_first]; | |
87 } | |
88 | |
89 #ifndef PRODUCT | |
90 bool verify (void); | |
91 bool region_in_cache(HeapRegion *hr) { | |
92 int sort_index = hr->sort_index(); | |
93 if (sort_index < -1) { | |
94 int index = get_index(sort_index); | |
95 guarantee(index < CacheLength, "should be within bounds"); | |
96 return _cache[index] == hr; | |
97 } else | |
98 return 0; | |
99 } | |
100 #endif // PRODUCT | |
101 }; | |
102 | |
103 class CollectionSetChooser: public CHeapObj { | |
104 | |
105 GrowableArray<HeapRegion*> _markedRegions; | |
106 int _curMarkedIndex; | |
107 int _numMarkedRegions; | |
108 CSetChooserCache _cache; | |
109 | |
110 // True iff last collection pause ran of out new "age 0" regions, and | |
111 // returned an "age 1" region. | |
112 bool _unmarked_age_1_returned_as_new; | |
113 | |
114 jint _first_par_unreserved_idx; | |
115 | |
116 public: | |
117 | |
118 HeapRegion* getNextMarkedRegion(double time_so_far, double avg_prediction); | |
119 | |
120 CollectionSetChooser(); | |
121 | |
122 void sortMarkedHeapRegions(); | |
123 void fillCache(); | |
124 void addMarkedHeapRegion(HeapRegion *hr); | |
125 | |
126 // Must be called before calls to getParMarkedHeapRegionChunk. | |
127 // "n_regions" is the number of regions, "chunkSize" the chunk size. | |
128 void prepareForAddMarkedHeapRegionsPar(size_t n_regions, size_t chunkSize); | |
129 // Returns the first index in a contiguous chunk of "n_regions" indexes | |
130 // that the calling thread has reserved. These must be set by the | |
131 // calling thread using "setMarkedHeapRegion" (to NULL if necessary). | |
132 jint getParMarkedHeapRegionChunk(jint n_regions); | |
133 // Set the marked array entry at index to hr. Careful to claim the index | |
134 // first if in parallel. | |
135 void setMarkedHeapRegion(jint index, HeapRegion* hr); | |
136 // Atomically increment the number of claimed regions by "inc_by". | |
137 void incNumMarkedHeapRegions(jint inc_by); | |
138 | |
139 void clearMarkedHeapRegions(); | |
140 | |
141 void updateAfterFullCollection(); | |
142 | |
143 bool unmarked_age_1_returned_as_new() { return _unmarked_age_1_returned_as_new; } | |
144 | |
145 // Returns true if the used portion of "_markedRegions" is properly | |
146 // sorted, otherwise asserts false. | |
147 #ifndef PRODUCT | |
148 bool verify(void); | |
149 bool regionProperlyOrdered(HeapRegion* r) { | |
150 int si = r->sort_index(); | |
151 return (si == -1) || | |
152 (si > -1 && _markedRegions.at(si) == r) || | |
153 (si < -1 && _cache.region_in_cache(r)); | |
154 } | |
155 #endif | |
156 | |
157 }; | |
1972 | 158 |
159 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP |