Mercurial > hg > graal-compiler
annotate src/share/vm/memory/genCollectedHeap.cpp @ 1959:9eecf81a02fb
7000578: CMS: assert(SafepointSynchronize::is_at_safepoint()) failed: Else races are possible
Summary: Weakened assert in onj_is_alive() to allow its use at initialization time when is_at_safepoint() normally reports false; added some related asserts to check order of is_init_completed() after Universe::is_fully_initialized().
Reviewed-by: jcoomes
author | ysr |
---|---|
date | Tue, 16 Nov 2010 13:58:48 -0800 |
parents | a7214d79fcf1 |
children | f95d63e2154a |
rev | line source |
---|---|
0 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1520
diff
changeset
|
2 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. |
0 | 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:
1520
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1520
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:
1520
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 # include "incls/_precompiled.incl" | |
26 # include "incls/_genCollectedHeap.cpp.incl" | |
27 | |
28 GenCollectedHeap* GenCollectedHeap::_gch; | |
29 NOT_PRODUCT(size_t GenCollectedHeap::_skip_header_HeapWords = 0;) | |
30 | |
31 // The set of potentially parallel tasks in strong root scanning. | |
32 enum GCH_process_strong_roots_tasks { | |
33 // We probably want to parallelize both of these internally, but for now... | |
34 GCH_PS_younger_gens, | |
35 // Leave this one last. | |
36 GCH_PS_NumElements | |
37 }; | |
38 | |
39 GenCollectedHeap::GenCollectedHeap(GenCollectorPolicy *policy) : | |
40 SharedHeap(policy), | |
41 _gen_policy(policy), | |
42 _gen_process_strong_tasks(new SubTasksDone(GCH_PS_NumElements)), | |
43 _full_collections_completed(0) | |
44 { | |
45 if (_gen_process_strong_tasks == NULL || | |
46 !_gen_process_strong_tasks->valid()) { | |
47 vm_exit_during_initialization("Failed necessary allocation."); | |
48 } | |
49 assert(policy != NULL, "Sanity check"); | |
50 _preloading_shared_classes = false; | |
51 } | |
52 | |
53 jint GenCollectedHeap::initialize() { | |
1166 | 54 CollectedHeap::pre_initialize(); |
55 | |
0 | 56 int i; |
57 _n_gens = gen_policy()->number_of_generations(); | |
58 | |
59 // While there are no constraints in the GC code that HeapWordSize | |
60 // be any particular value, there are multiple other areas in the | |
61 // system which believe this to be true (e.g. oop->object_size in some | |
62 // cases incorrectly returns the size in wordSize units rather than | |
63 // HeapWordSize). | |
64 guarantee(HeapWordSize == wordSize, "HeapWordSize must equal wordSize"); | |
65 | |
66 // The heap must be at least as aligned as generations. | |
67 size_t alignment = Generation::GenGrain; | |
68 | |
69 _gen_specs = gen_policy()->generations(); | |
70 PermanentGenerationSpec *perm_gen_spec = | |
71 collector_policy()->permanent_generation(); | |
72 | |
73 // Make sure the sizes are all aligned. | |
74 for (i = 0; i < _n_gens; i++) { | |
75 _gen_specs[i]->align(alignment); | |
76 } | |
77 perm_gen_spec->align(alignment); | |
78 | |
79 // If we are dumping the heap, then allocate a wasted block of address | |
80 // space in order to push the heap to a lower address. This extra | |
81 // address range allows for other (or larger) libraries to be loaded | |
82 // without them occupying the space required for the shared spaces. | |
83 | |
84 if (DumpSharedSpaces) { | |
85 uintx reserved = 0; | |
86 uintx block_size = 64*1024*1024; | |
87 while (reserved < SharedDummyBlockSize) { | |
88 char* dummy = os::reserve_memory(block_size); | |
89 reserved += block_size; | |
90 } | |
91 } | |
92 | |
93 // Allocate space for the heap. | |
94 | |
95 char* heap_address; | |
96 size_t total_reserved = 0; | |
97 int n_covered_regions = 0; | |
98 ReservedSpace heap_rs(0); | |
99 | |
100 heap_address = allocate(alignment, perm_gen_spec, &total_reserved, | |
101 &n_covered_regions, &heap_rs); | |
102 | |
103 if (UseSharedSpaces) { | |
104 if (!heap_rs.is_reserved() || heap_address != heap_rs.base()) { | |
105 if (heap_rs.is_reserved()) { | |
106 heap_rs.release(); | |
107 } | |
108 FileMapInfo* mapinfo = FileMapInfo::current_info(); | |
109 mapinfo->fail_continue("Unable to reserve shared region."); | |
110 allocate(alignment, perm_gen_spec, &total_reserved, &n_covered_regions, | |
111 &heap_rs); | |
112 } | |
113 } | |
114 | |
115 if (!heap_rs.is_reserved()) { | |
116 vm_shutdown_during_initialization( | |
117 "Could not reserve enough space for object heap"); | |
118 return JNI_ENOMEM; | |
119 } | |
120 | |
121 _reserved = MemRegion((HeapWord*)heap_rs.base(), | |
122 (HeapWord*)(heap_rs.base() + heap_rs.size())); | |
123 | |
124 // It is important to do this in a way such that concurrent readers can't | |
125 // temporarily think somethings in the heap. (Seen this happen in asserts.) | |
126 _reserved.set_word_size(0); | |
127 _reserved.set_start((HeapWord*)heap_rs.base()); | |
128 size_t actual_heap_size = heap_rs.size() - perm_gen_spec->misc_data_size() | |
129 - perm_gen_spec->misc_code_size(); | |
130 _reserved.set_end((HeapWord*)(heap_rs.base() + actual_heap_size)); | |
131 | |
132 _rem_set = collector_policy()->create_rem_set(_reserved, n_covered_regions); | |
133 set_barrier_set(rem_set()->bs()); | |
1166 | 134 |
0 | 135 _gch = this; |
136 | |
137 for (i = 0; i < _n_gens; i++) { | |
138 ReservedSpace this_rs = heap_rs.first_part(_gen_specs[i]->max_size(), | |
139 UseSharedSpaces, UseSharedSpaces); | |
140 _gens[i] = _gen_specs[i]->init(this_rs, i, rem_set()); | |
141 heap_rs = heap_rs.last_part(_gen_specs[i]->max_size()); | |
142 } | |
143 _perm_gen = perm_gen_spec->init(heap_rs, PermSize, rem_set()); | |
144 | |
1888
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1833
diff
changeset
|
145 clear_incremental_collection_failed(); |
0 | 146 |
147 #ifndef SERIALGC | |
148 // If we are running CMS, create the collector responsible | |
149 // for collecting the CMS generations. | |
150 if (collector_policy()->is_concurrent_mark_sweep_policy()) { | |
151 bool success = create_cms_collector(); | |
152 if (!success) return JNI_ENOMEM; | |
153 } | |
154 #endif // SERIALGC | |
155 | |
156 return JNI_OK; | |
157 } | |
158 | |
159 | |
160 char* GenCollectedHeap::allocate(size_t alignment, | |
161 PermanentGenerationSpec* perm_gen_spec, | |
162 size_t* _total_reserved, | |
163 int* _n_covered_regions, | |
164 ReservedSpace* heap_rs){ | |
165 const char overflow_msg[] = "The size of the object heap + VM data exceeds " | |
166 "the maximum representable size"; | |
167 | |
168 // Now figure out the total size. | |
169 size_t total_reserved = 0; | |
170 int n_covered_regions = 0; | |
171 const size_t pageSize = UseLargePages ? | |
172 os::large_page_size() : os::vm_page_size(); | |
173 | |
174 for (int i = 0; i < _n_gens; i++) { | |
175 total_reserved += _gen_specs[i]->max_size(); | |
176 if (total_reserved < _gen_specs[i]->max_size()) { | |
177 vm_exit_during_initialization(overflow_msg); | |
178 } | |
179 n_covered_regions += _gen_specs[i]->n_covered_regions(); | |
180 } | |
1626
1a11430e0326
6888573: class data sharing does not always disable large pages
jcoomes
parents:
1552
diff
changeset
|
181 assert(total_reserved % pageSize == 0, |
1a11430e0326
6888573: class data sharing does not always disable large pages
jcoomes
parents:
1552
diff
changeset
|
182 err_msg("Gen size; total_reserved=" SIZE_FORMAT ", pageSize=" |
1a11430e0326
6888573: class data sharing does not always disable large pages
jcoomes
parents:
1552
diff
changeset
|
183 SIZE_FORMAT, total_reserved, pageSize)); |
0 | 184 total_reserved += perm_gen_spec->max_size(); |
1626
1a11430e0326
6888573: class data sharing does not always disable large pages
jcoomes
parents:
1552
diff
changeset
|
185 assert(total_reserved % pageSize == 0, |
1a11430e0326
6888573: class data sharing does not always disable large pages
jcoomes
parents:
1552
diff
changeset
|
186 err_msg("Perm size; total_reserved=" SIZE_FORMAT ", pageSize=" |
1a11430e0326
6888573: class data sharing does not always disable large pages
jcoomes
parents:
1552
diff
changeset
|
187 SIZE_FORMAT ", perm gen max=" SIZE_FORMAT, total_reserved, |
1a11430e0326
6888573: class data sharing does not always disable large pages
jcoomes
parents:
1552
diff
changeset
|
188 pageSize, perm_gen_spec->max_size())); |
0 | 189 |
190 if (total_reserved < perm_gen_spec->max_size()) { | |
191 vm_exit_during_initialization(overflow_msg); | |
192 } | |
193 n_covered_regions += perm_gen_spec->n_covered_regions(); | |
194 | |
195 // Add the size of the data area which shares the same reserved area | |
196 // as the heap, but which is not actually part of the heap. | |
197 size_t s = perm_gen_spec->misc_data_size() + perm_gen_spec->misc_code_size(); | |
198 | |
199 total_reserved += s; | |
200 if (total_reserved < s) { | |
201 vm_exit_during_initialization(overflow_msg); | |
202 } | |
203 | |
204 if (UseLargePages) { | |
205 assert(total_reserved != 0, "total_reserved cannot be 0"); | |
206 total_reserved = round_to(total_reserved, os::large_page_size()); | |
207 if (total_reserved < os::large_page_size()) { | |
208 vm_exit_during_initialization(overflow_msg); | |
209 } | |
210 } | |
211 | |
212 // Calculate the address at which the heap must reside in order for | |
213 // the shared data to be at the required address. | |
214 | |
215 char* heap_address; | |
216 if (UseSharedSpaces) { | |
217 | |
218 // Calculate the address of the first word beyond the heap. | |
219 FileMapInfo* mapinfo = FileMapInfo::current_info(); | |
220 int lr = CompactingPermGenGen::n_regions - 1; | |
221 size_t capacity = align_size_up(mapinfo->space_capacity(lr), alignment); | |
222 heap_address = mapinfo->region_base(lr) + capacity; | |
223 | |
224 // Calculate the address of the first word of the heap. | |
225 heap_address -= total_reserved; | |
226 } else { | |
227 heap_address = NULL; // any address will do. | |
642
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
615
diff
changeset
|
228 if (UseCompressedOops) { |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
615
diff
changeset
|
229 heap_address = Universe::preferred_heap_base(total_reserved, Universe::UnscaledNarrowOop); |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
615
diff
changeset
|
230 *_total_reserved = total_reserved; |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
615
diff
changeset
|
231 *_n_covered_regions = n_covered_regions; |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
615
diff
changeset
|
232 *heap_rs = ReservedHeapSpace(total_reserved, alignment, |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
615
diff
changeset
|
233 UseLargePages, heap_address); |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
615
diff
changeset
|
234 |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
615
diff
changeset
|
235 if (heap_address != NULL && !heap_rs->is_reserved()) { |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
615
diff
changeset
|
236 // Failed to reserve at specified address - the requested memory |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
615
diff
changeset
|
237 // region is taken already, for example, by 'java' launcher. |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
615
diff
changeset
|
238 // Try again to reserver heap higher. |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
615
diff
changeset
|
239 heap_address = Universe::preferred_heap_base(total_reserved, Universe::ZeroBasedNarrowOop); |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
615
diff
changeset
|
240 *heap_rs = ReservedHeapSpace(total_reserved, alignment, |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
615
diff
changeset
|
241 UseLargePages, heap_address); |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
615
diff
changeset
|
242 |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
615
diff
changeset
|
243 if (heap_address != NULL && !heap_rs->is_reserved()) { |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
615
diff
changeset
|
244 // Failed to reserve at specified address again - give up. |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
615
diff
changeset
|
245 heap_address = Universe::preferred_heap_base(total_reserved, Universe::HeapBasedNarrowOop); |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
615
diff
changeset
|
246 assert(heap_address == NULL, ""); |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
615
diff
changeset
|
247 *heap_rs = ReservedHeapSpace(total_reserved, alignment, |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
615
diff
changeset
|
248 UseLargePages, heap_address); |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
615
diff
changeset
|
249 } |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
615
diff
changeset
|
250 } |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
615
diff
changeset
|
251 return heap_address; |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
615
diff
changeset
|
252 } |
0 | 253 } |
254 | |
255 *_total_reserved = total_reserved; | |
256 *_n_covered_regions = n_covered_regions; | |
237
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
257 *heap_rs = ReservedHeapSpace(total_reserved, alignment, |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
258 UseLargePages, heap_address); |
0 | 259 |
260 return heap_address; | |
261 } | |
262 | |
263 | |
264 void GenCollectedHeap::post_initialize() { | |
265 SharedHeap::post_initialize(); | |
266 TwoGenerationCollectorPolicy *policy = | |
267 (TwoGenerationCollectorPolicy *)collector_policy(); | |
268 guarantee(policy->is_two_generation_policy(), "Illegal policy type"); | |
269 DefNewGeneration* def_new_gen = (DefNewGeneration*) get_gen(0); | |
270 assert(def_new_gen->kind() == Generation::DefNew || | |
271 def_new_gen->kind() == Generation::ParNew || | |
272 def_new_gen->kind() == Generation::ASParNew, | |
273 "Wrong generation kind"); | |
274 | |
275 Generation* old_gen = get_gen(1); | |
276 assert(old_gen->kind() == Generation::ConcurrentMarkSweep || | |
277 old_gen->kind() == Generation::ASConcurrentMarkSweep || | |
278 old_gen->kind() == Generation::MarkSweepCompact, | |
279 "Wrong generation kind"); | |
280 | |
281 policy->initialize_size_policy(def_new_gen->eden()->capacity(), | |
282 old_gen->capacity(), | |
283 def_new_gen->from()->capacity()); | |
284 policy->initialize_gc_policy_counters(); | |
285 } | |
286 | |
287 void GenCollectedHeap::ref_processing_init() { | |
288 SharedHeap::ref_processing_init(); | |
289 for (int i = 0; i < _n_gens; i++) { | |
290 _gens[i]->ref_processor_init(); | |
291 } | |
292 } | |
293 | |
294 size_t GenCollectedHeap::capacity() const { | |
295 size_t res = 0; | |
296 for (int i = 0; i < _n_gens; i++) { | |
297 res += _gens[i]->capacity(); | |
298 } | |
299 return res; | |
300 } | |
301 | |
302 size_t GenCollectedHeap::used() const { | |
303 size_t res = 0; | |
304 for (int i = 0; i < _n_gens; i++) { | |
305 res += _gens[i]->used(); | |
306 } | |
307 return res; | |
308 } | |
309 | |
310 // Save the "used_region" for generations level and lower, | |
311 // and, if perm is true, for perm gen. | |
312 void GenCollectedHeap::save_used_regions(int level, bool perm) { | |
313 assert(level < _n_gens, "Illegal level parameter"); | |
314 for (int i = level; i >= 0; i--) { | |
315 _gens[i]->save_used_region(); | |
316 } | |
317 if (perm) { | |
318 perm_gen()->save_used_region(); | |
319 } | |
320 } | |
321 | |
322 size_t GenCollectedHeap::max_capacity() const { | |
323 size_t res = 0; | |
324 for (int i = 0; i < _n_gens; i++) { | |
325 res += _gens[i]->max_capacity(); | |
326 } | |
327 return res; | |
328 } | |
329 | |
330 // Update the _full_collections_completed counter | |
331 // at the end of a stop-world full GC. | |
332 unsigned int GenCollectedHeap::update_full_collections_completed() { | |
333 MonitorLockerEx ml(FullGCCount_lock, Mutex::_no_safepoint_check_flag); | |
334 assert(_full_collections_completed <= _total_full_collections, | |
335 "Can't complete more collections than were started"); | |
336 _full_collections_completed = _total_full_collections; | |
337 ml.notify_all(); | |
338 return _full_collections_completed; | |
339 } | |
340 | |
341 // Update the _full_collections_completed counter, as appropriate, | |
342 // at the end of a concurrent GC cycle. Note the conditional update | |
343 // below to allow this method to be called by a concurrent collector | |
344 // without synchronizing in any manner with the VM thread (which | |
345 // may already have initiated a STW full collection "concurrently"). | |
346 unsigned int GenCollectedHeap::update_full_collections_completed(unsigned int count) { | |
347 MonitorLockerEx ml(FullGCCount_lock, Mutex::_no_safepoint_check_flag); | |
348 assert((_full_collections_completed <= _total_full_collections) && | |
349 (count <= _total_full_collections), | |
350 "Can't complete more collections than were started"); | |
351 if (count > _full_collections_completed) { | |
352 _full_collections_completed = count; | |
353 ml.notify_all(); | |
354 } | |
355 return _full_collections_completed; | |
356 } | |
357 | |
358 | |
359 #ifndef PRODUCT | |
360 // Override of memory state checking method in CollectedHeap: | |
361 // Some collectors (CMS for example) can't have badHeapWordVal written | |
362 // in the first two words of an object. (For instance , in the case of | |
363 // CMS these words hold state used to synchronize between certain | |
364 // (concurrent) GC steps and direct allocating mutators.) | |
365 // The skip_header_HeapWords() method below, allows us to skip | |
366 // over the requisite number of HeapWord's. Note that (for | |
367 // generational collectors) this means that those many words are | |
368 // skipped in each object, irrespective of the generation in which | |
369 // that object lives. The resultant loss of precision seems to be | |
370 // harmless and the pain of avoiding that imprecision appears somewhat | |
371 // higher than we are prepared to pay for such rudimentary debugging | |
372 // support. | |
373 void GenCollectedHeap::check_for_non_bad_heap_word_value(HeapWord* addr, | |
374 size_t size) { | |
375 if (CheckMemoryInitialization && ZapUnusedHeapArea) { | |
376 // We are asked to check a size in HeapWords, | |
377 // but the memory is mangled in juint words. | |
378 juint* start = (juint*) (addr + skip_header_HeapWords()); | |
379 juint* end = (juint*) (addr + size); | |
380 for (juint* slot = start; slot < end; slot += 1) { | |
381 assert(*slot == badHeapWordVal, | |
382 "Found non badHeapWordValue in pre-allocation check"); | |
383 } | |
384 } | |
385 } | |
386 #endif | |
387 | |
388 HeapWord* GenCollectedHeap::attempt_allocation(size_t size, | |
389 bool is_tlab, | |
390 bool first_only) { | |
391 HeapWord* res; | |
392 for (int i = 0; i < _n_gens; i++) { | |
393 if (_gens[i]->should_allocate(size, is_tlab)) { | |
394 res = _gens[i]->allocate(size, is_tlab); | |
395 if (res != NULL) return res; | |
396 else if (first_only) break; | |
397 } | |
398 } | |
399 // Otherwise... | |
400 return NULL; | |
401 } | |
402 | |
403 HeapWord* GenCollectedHeap::mem_allocate(size_t size, | |
404 bool is_large_noref, | |
405 bool is_tlab, | |
406 bool* gc_overhead_limit_was_exceeded) { | |
407 return collector_policy()->mem_allocate_work(size, | |
408 is_tlab, | |
409 gc_overhead_limit_was_exceeded); | |
410 } | |
411 | |
412 bool GenCollectedHeap::must_clear_all_soft_refs() { | |
413 return _gc_cause == GCCause::_last_ditch_collection; | |
414 } | |
415 | |
416 bool GenCollectedHeap::should_do_concurrent_full_gc(GCCause::Cause cause) { | |
1520
bb843ebc7c55
6919638: CMS: ExplicitGCInvokesConcurrent misinteracts with gc locker
ysr
parents:
1387
diff
changeset
|
417 return UseConcMarkSweepGC && |
bb843ebc7c55
6919638: CMS: ExplicitGCInvokesConcurrent misinteracts with gc locker
ysr
parents:
1387
diff
changeset
|
418 ((cause == GCCause::_gc_locker && GCLockerInvokesConcurrent) || |
bb843ebc7c55
6919638: CMS: ExplicitGCInvokesConcurrent misinteracts with gc locker
ysr
parents:
1387
diff
changeset
|
419 (cause == GCCause::_java_lang_system_gc && ExplicitGCInvokesConcurrent)); |
0 | 420 } |
421 | |
422 void GenCollectedHeap::do_collection(bool full, | |
423 bool clear_all_soft_refs, | |
424 size_t size, | |
425 bool is_tlab, | |
426 int max_level) { | |
427 bool prepared_for_verification = false; | |
428 ResourceMark rm; | |
429 DEBUG_ONLY(Thread* my_thread = Thread::current();) | |
430 | |
431 assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint"); | |
432 assert(my_thread->is_VM_thread() || | |
433 my_thread->is_ConcurrentGC_thread(), | |
434 "incorrect thread type capability"); | |
1387
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1170
diff
changeset
|
435 assert(Heap_lock->is_locked(), |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1170
diff
changeset
|
436 "the requesting thread should have the Heap_lock"); |
0 | 437 guarantee(!is_gc_active(), "collection is not reentrant"); |
438 assert(max_level < n_gens(), "sanity check"); | |
439 | |
440 if (GC_locker::check_active_before_gc()) { | |
441 return; // GC is disabled (e.g. JNI GetXXXCritical operation) | |
442 } | |
443 | |
1387
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1170
diff
changeset
|
444 const bool do_clear_all_soft_refs = clear_all_soft_refs || |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1170
diff
changeset
|
445 collector_policy()->should_clear_all_soft_refs(); |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1170
diff
changeset
|
446 |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1170
diff
changeset
|
447 ClearedAllSoftRefs casr(do_clear_all_soft_refs, collector_policy()); |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1170
diff
changeset
|
448 |
0 | 449 const size_t perm_prev_used = perm_gen()->used(); |
450 | |
451 if (PrintHeapAtGC) { | |
452 Universe::print_heap_before_gc(); | |
453 if (Verbose) { | |
454 gclog_or_tty->print_cr("GC Cause: %s", GCCause::to_string(gc_cause())); | |
455 } | |
456 } | |
457 | |
458 { | |
459 FlagSetting fl(_is_gc_active, true); | |
460 | |
461 bool complete = full && (max_level == (n_gens()-1)); | |
462 const char* gc_cause_str = "GC "; | |
463 if (complete) { | |
464 GCCause::Cause cause = gc_cause(); | |
465 if (cause == GCCause::_java_lang_system_gc) { | |
466 gc_cause_str = "Full GC (System) "; | |
467 } else { | |
468 gc_cause_str = "Full GC "; | |
469 } | |
470 } | |
471 gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps); | |
472 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); | |
473 TraceTime t(gc_cause_str, PrintGCDetails, false, gclog_or_tty); | |
474 | |
475 gc_prologue(complete); | |
476 increment_total_collections(complete); | |
477 | |
478 size_t gch_prev_used = used(); | |
479 | |
480 int starting_level = 0; | |
481 if (full) { | |
482 // Search for the oldest generation which will collect all younger | |
483 // generations, and start collection loop there. | |
484 for (int i = max_level; i >= 0; i--) { | |
485 if (_gens[i]->full_collects_younger_generations()) { | |
486 starting_level = i; | |
487 break; | |
488 } | |
489 } | |
490 } | |
491 | |
492 bool must_restore_marks_for_biased_locking = false; | |
493 | |
494 int max_level_collected = starting_level; | |
495 for (int i = starting_level; i <= max_level; i++) { | |
496 if (_gens[i]->should_collect(full, size, is_tlab)) { | |
880
2b4230d1e589
6862295: JDWP threadid changes during debugging session (leading to ingored breakpoints)
dcubed
parents:
457
diff
changeset
|
497 if (i == n_gens() - 1) { // a major collection is to happen |
2b4230d1e589
6862295: JDWP threadid changes during debugging session (leading to ingored breakpoints)
dcubed
parents:
457
diff
changeset
|
498 if (!complete) { |
2b4230d1e589
6862295: JDWP threadid changes during debugging session (leading to ingored breakpoints)
dcubed
parents:
457
diff
changeset
|
499 // The full_collections increment was missed above. |
2b4230d1e589
6862295: JDWP threadid changes during debugging session (leading to ingored breakpoints)
dcubed
parents:
457
diff
changeset
|
500 increment_total_full_collections(); |
2b4230d1e589
6862295: JDWP threadid changes during debugging session (leading to ingored breakpoints)
dcubed
parents:
457
diff
changeset
|
501 } |
615
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
546
diff
changeset
|
502 pre_full_gc_dump(); // do any pre full gc dumps |
880
2b4230d1e589
6862295: JDWP threadid changes during debugging session (leading to ingored breakpoints)
dcubed
parents:
457
diff
changeset
|
503 } |
0 | 504 // Timer for individual generations. Last argument is false: no CR |
505 TraceTime t1(_gens[i]->short_name(), PrintGCDetails, false, gclog_or_tty); | |
506 TraceCollectorStats tcs(_gens[i]->counters()); | |
507 TraceMemoryManagerStats tmms(_gens[i]->kind()); | |
508 | |
509 size_t prev_used = _gens[i]->used(); | |
510 _gens[i]->stat_record()->invocations++; | |
511 _gens[i]->stat_record()->accumulated_time.start(); | |
512 | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
513 // Must be done anew before each collection because |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
514 // a previous collection will do mangling and will |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
515 // change top of some spaces. |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
516 record_gen_tops_before_GC(); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
517 |
0 | 518 if (PrintGC && Verbose) { |
519 gclog_or_tty->print("level=%d invoke=%d size=" SIZE_FORMAT, | |
520 i, | |
521 _gens[i]->stat_record()->invocations, | |
522 size*HeapWordSize); | |
523 } | |
524 | |
525 if (VerifyBeforeGC && i >= VerifyGCLevel && | |
526 total_collections() >= VerifyGCStartAt) { | |
527 HandleMark hm; // Discard invalid handles created during verification | |
528 if (!prepared_for_verification) { | |
529 prepare_for_verify(); | |
530 prepared_for_verification = true; | |
531 } | |
532 gclog_or_tty->print(" VerifyBeforeGC:"); | |
533 Universe::verify(true); | |
534 } | |
535 COMPILER2_PRESENT(DerivedPointerTable::clear()); | |
536 | |
537 if (!must_restore_marks_for_biased_locking && | |
538 _gens[i]->performs_in_place_marking()) { | |
539 // We perform this mark word preservation work lazily | |
540 // because it's only at this point that we know whether we | |
541 // absolutely have to do it; we want to avoid doing it for | |
542 // scavenge-only collections where it's unnecessary | |
543 must_restore_marks_for_biased_locking = true; | |
544 BiasedLocking::preserve_marks(); | |
545 } | |
546 | |
547 // Do collection work | |
548 { | |
549 // Note on ref discovery: For what appear to be historical reasons, | |
550 // GCH enables and disabled (by enqueing) refs discovery. | |
551 // In the future this should be moved into the generation's | |
552 // collect method so that ref discovery and enqueueing concerns | |
553 // are local to a generation. The collect method could return | |
554 // an appropriate indication in the case that notification on | |
555 // the ref lock was needed. This will make the treatment of | |
556 // weak refs more uniform (and indeed remove such concerns | |
557 // from GCH). XXX | |
558 | |
559 HandleMark hm; // Discard invalid handles created during gc | |
560 save_marks(); // save marks for all gens | |
561 // We want to discover references, but not process them yet. | |
562 // This mode is disabled in process_discovered_references if the | |
563 // generation does some collection work, or in | |
564 // enqueue_discovered_references if the generation returns | |
565 // without doing any work. | |
566 ReferenceProcessor* rp = _gens[i]->ref_processor(); | |
567 // If the discovery of ("weak") refs in this generation is | |
568 // atomic wrt other collectors in this configuration, we | |
569 // are guaranteed to have empty discovered ref lists. | |
570 if (rp->discovery_is_atomic()) { | |
571 rp->verify_no_references_recorded(); | |
572 rp->enable_discovery(); | |
1387
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1170
diff
changeset
|
573 rp->setup_policy(do_clear_all_soft_refs); |
0 | 574 } else { |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
269
diff
changeset
|
575 // collect() below will enable discovery as appropriate |
0 | 576 } |
1387
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1170
diff
changeset
|
577 _gens[i]->collect(full, do_clear_all_soft_refs, size, is_tlab); |
0 | 578 if (!rp->enqueuing_is_done()) { |
579 rp->enqueue_discovered_references(); | |
580 } else { | |
581 rp->set_enqueuing_is_done(false); | |
582 } | |
583 rp->verify_no_references_recorded(); | |
584 } | |
585 max_level_collected = i; | |
586 | |
587 // Determine if allocation request was met. | |
588 if (size > 0) { | |
589 if (!is_tlab || _gens[i]->supports_tlab_allocation()) { | |
590 if (size*HeapWordSize <= _gens[i]->unsafe_max_alloc_nogc()) { | |
591 size = 0; | |
592 } | |
593 } | |
594 } | |
595 | |
596 COMPILER2_PRESENT(DerivedPointerTable::update_pointers()); | |
597 | |
598 _gens[i]->stat_record()->accumulated_time.stop(); | |
599 | |
600 update_gc_stats(i, full); | |
601 | |
602 if (VerifyAfterGC && i >= VerifyGCLevel && | |
603 total_collections() >= VerifyGCStartAt) { | |
604 HandleMark hm; // Discard invalid handles created during verification | |
605 gclog_or_tty->print(" VerifyAfterGC:"); | |
606 Universe::verify(false); | |
607 } | |
608 | |
609 if (PrintGCDetails) { | |
610 gclog_or_tty->print(":"); | |
611 _gens[i]->print_heap_change(prev_used); | |
612 } | |
613 } | |
614 } | |
615 | |
616 // Update "complete" boolean wrt what actually transpired -- | |
617 // for instance, a promotion failure could have led to | |
618 // a whole heap collection. | |
619 complete = complete || (max_level_collected == n_gens() - 1); | |
620 | |
615
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
546
diff
changeset
|
621 if (complete) { // We did a "major" collection |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
546
diff
changeset
|
622 post_full_gc_dump(); // do any post full gc dumps |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
546
diff
changeset
|
623 } |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
546
diff
changeset
|
624 |
0 | 625 if (PrintGCDetails) { |
626 print_heap_change(gch_prev_used); | |
627 | |
628 // Print perm gen info for full GC with PrintGCDetails flag. | |
629 if (complete) { | |
630 print_perm_heap_change(perm_prev_used); | |
631 } | |
632 } | |
633 | |
634 for (int j = max_level_collected; j >= 0; j -= 1) { | |
635 // Adjust generation sizes. | |
636 _gens[j]->compute_new_size(); | |
637 } | |
638 | |
639 if (complete) { | |
640 // Ask the permanent generation to adjust size for full collections | |
641 perm()->compute_new_size(); | |
642 update_full_collections_completed(); | |
643 } | |
644 | |
645 // Track memory usage and detect low memory after GC finishes | |
646 MemoryService::track_memory_usage(); | |
647 | |
648 gc_epilogue(complete); | |
649 | |
650 if (must_restore_marks_for_biased_locking) { | |
651 BiasedLocking::restore_marks(); | |
652 } | |
653 } | |
654 | |
655 AdaptiveSizePolicy* sp = gen_policy()->size_policy(); | |
656 AdaptiveSizePolicyOutput(sp, total_collections()); | |
657 | |
658 if (PrintHeapAtGC) { | |
659 Universe::print_heap_after_gc(); | |
660 } | |
661 | |
546
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
517
diff
changeset
|
662 #ifdef TRACESPINNING |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
517
diff
changeset
|
663 ParallelTaskTerminator::print_termination_counts(); |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
517
diff
changeset
|
664 #endif |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
517
diff
changeset
|
665 |
0 | 666 if (ExitAfterGCNum > 0 && total_collections() == ExitAfterGCNum) { |
667 tty->print_cr("Stopping after GC #%d", ExitAfterGCNum); | |
668 vm_exit(-1); | |
669 } | |
670 } | |
671 | |
672 HeapWord* GenCollectedHeap::satisfy_failed_allocation(size_t size, bool is_tlab) { | |
673 return collector_policy()->satisfy_failed_allocation(size, is_tlab); | |
674 } | |
675 | |
676 void GenCollectedHeap::set_par_threads(int t) { | |
677 SharedHeap::set_par_threads(t); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1681
diff
changeset
|
678 _gen_process_strong_tasks->set_n_threads(t); |
0 | 679 } |
680 | |
681 class AssertIsPermClosure: public OopClosure { | |
682 public: | |
683 void do_oop(oop* p) { | |
684 assert((*p) == NULL || (*p)->is_perm(), "Referent should be perm."); | |
685 } | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
686 void do_oop(narrowOop* p) { ShouldNotReachHere(); } |
0 | 687 }; |
688 static AssertIsPermClosure assert_is_perm_closure; | |
689 | |
690 void GenCollectedHeap:: | |
691 gen_process_strong_roots(int level, | |
692 bool younger_gens_as_roots, | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
881
diff
changeset
|
693 bool activate_scope, |
0 | 694 bool collecting_perm_gen, |
695 SharedHeap::ScanningOption so, | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
881
diff
changeset
|
696 OopsInGenClosure* not_older_gens, |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
881
diff
changeset
|
697 bool do_code_roots, |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
881
diff
changeset
|
698 OopsInGenClosure* older_gens) { |
0 | 699 // General strong roots. |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
881
diff
changeset
|
700 |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
881
diff
changeset
|
701 if (!do_code_roots) { |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
881
diff
changeset
|
702 SharedHeap::process_strong_roots(activate_scope, collecting_perm_gen, so, |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
881
diff
changeset
|
703 not_older_gens, NULL, older_gens); |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
881
diff
changeset
|
704 } else { |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
881
diff
changeset
|
705 bool do_code_marking = (activate_scope || nmethod::oops_do_marking_is_active()); |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
881
diff
changeset
|
706 CodeBlobToOopClosure code_roots(not_older_gens, /*do_marking=*/ do_code_marking); |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
881
diff
changeset
|
707 SharedHeap::process_strong_roots(activate_scope, collecting_perm_gen, so, |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
881
diff
changeset
|
708 not_older_gens, &code_roots, older_gens); |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
881
diff
changeset
|
709 } |
0 | 710 |
711 if (younger_gens_as_roots) { | |
712 if (!_gen_process_strong_tasks->is_task_claimed(GCH_PS_younger_gens)) { | |
713 for (int i = 0; i < level; i++) { | |
714 not_older_gens->set_generation(_gens[i]); | |
715 _gens[i]->oop_iterate(not_older_gens); | |
716 } | |
717 not_older_gens->reset_generation(); | |
718 } | |
719 } | |
720 // When collection is parallel, all threads get to cooperate to do | |
721 // older-gen scanning. | |
722 for (int i = level+1; i < _n_gens; i++) { | |
723 older_gens->set_generation(_gens[i]); | |
724 rem_set()->younger_refs_iterate(_gens[i], older_gens); | |
725 older_gens->reset_generation(); | |
726 } | |
727 | |
728 _gen_process_strong_tasks->all_tasks_completed(); | |
729 } | |
730 | |
731 void GenCollectedHeap::gen_process_weak_roots(OopClosure* root_closure, | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
881
diff
changeset
|
732 CodeBlobClosure* code_roots, |
0 | 733 OopClosure* non_root_closure) { |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
881
diff
changeset
|
734 SharedHeap::process_weak_roots(root_closure, code_roots, non_root_closure); |
0 | 735 // "Local" "weak" refs |
736 for (int i = 0; i < _n_gens; i++) { | |
737 _gens[i]->ref_processor()->weak_oops_do(root_closure); | |
738 } | |
739 } | |
740 | |
741 #define GCH_SINCE_SAVE_MARKS_ITERATE_DEFN(OopClosureType, nv_suffix) \ | |
742 void GenCollectedHeap:: \ | |
743 oop_since_save_marks_iterate(int level, \ | |
744 OopClosureType* cur, \ | |
745 OopClosureType* older) { \ | |
746 _gens[level]->oop_since_save_marks_iterate##nv_suffix(cur); \ | |
747 for (int i = level+1; i < n_gens(); i++) { \ | |
748 _gens[i]->oop_since_save_marks_iterate##nv_suffix(older); \ | |
749 } \ | |
750 perm_gen()->oop_since_save_marks_iterate##nv_suffix(older); \ | |
751 } | |
752 | |
753 ALL_SINCE_SAVE_MARKS_CLOSURES(GCH_SINCE_SAVE_MARKS_ITERATE_DEFN) | |
754 | |
755 #undef GCH_SINCE_SAVE_MARKS_ITERATE_DEFN | |
756 | |
757 bool GenCollectedHeap::no_allocs_since_save_marks(int level) { | |
758 for (int i = level; i < _n_gens; i++) { | |
759 if (!_gens[i]->no_allocs_since_save_marks()) return false; | |
760 } | |
761 return perm_gen()->no_allocs_since_save_marks(); | |
762 } | |
763 | |
764 bool GenCollectedHeap::supports_inline_contig_alloc() const { | |
765 return _gens[0]->supports_inline_contig_alloc(); | |
766 } | |
767 | |
768 HeapWord** GenCollectedHeap::top_addr() const { | |
769 return _gens[0]->top_addr(); | |
770 } | |
771 | |
772 HeapWord** GenCollectedHeap::end_addr() const { | |
773 return _gens[0]->end_addr(); | |
774 } | |
775 | |
776 size_t GenCollectedHeap::unsafe_max_alloc() { | |
777 return _gens[0]->unsafe_max_alloc_nogc(); | |
778 } | |
779 | |
780 // public collection interfaces | |
781 | |
782 void GenCollectedHeap::collect(GCCause::Cause cause) { | |
783 if (should_do_concurrent_full_gc(cause)) { | |
784 #ifndef SERIALGC | |
785 // mostly concurrent full collection | |
786 collect_mostly_concurrent(cause); | |
787 #else // SERIALGC | |
788 ShouldNotReachHere(); | |
789 #endif // SERIALGC | |
790 } else { | |
791 #ifdef ASSERT | |
792 if (cause == GCCause::_scavenge_alot) { | |
793 // minor collection only | |
794 collect(cause, 0); | |
795 } else { | |
796 // Stop-the-world full collection | |
797 collect(cause, n_gens() - 1); | |
798 } | |
799 #else | |
800 // Stop-the-world full collection | |
801 collect(cause, n_gens() - 1); | |
802 #endif | |
803 } | |
804 } | |
805 | |
806 void GenCollectedHeap::collect(GCCause::Cause cause, int max_level) { | |
807 // The caller doesn't have the Heap_lock | |
808 assert(!Heap_lock->owned_by_self(), "this thread should not own the Heap_lock"); | |
809 MutexLocker ml(Heap_lock); | |
810 collect_locked(cause, max_level); | |
811 } | |
812 | |
813 // This interface assumes that it's being called by the | |
814 // vm thread. It collects the heap assuming that the | |
815 // heap lock is already held and that we are executing in | |
816 // the context of the vm thread. | |
817 void GenCollectedHeap::collect_as_vm_thread(GCCause::Cause cause) { | |
818 assert(Thread::current()->is_VM_thread(), "Precondition#1"); | |
819 assert(Heap_lock->is_locked(), "Precondition#2"); | |
820 GCCauseSetter gcs(this, cause); | |
821 switch (cause) { | |
822 case GCCause::_heap_inspection: | |
823 case GCCause::_heap_dump: { | |
824 HandleMark hm; | |
825 do_full_collection(false, // don't clear all soft refs | |
826 n_gens() - 1); | |
827 break; | |
828 } | |
829 default: // XXX FIX ME | |
830 ShouldNotReachHere(); // Unexpected use of this function | |
831 } | |
832 } | |
833 | |
834 void GenCollectedHeap::collect_locked(GCCause::Cause cause) { | |
835 // The caller has the Heap_lock | |
836 assert(Heap_lock->owned_by_self(), "this thread should own the Heap_lock"); | |
837 collect_locked(cause, n_gens() - 1); | |
838 } | |
839 | |
840 // this is the private collection interface | |
841 // The Heap_lock is expected to be held on entry. | |
842 | |
843 void GenCollectedHeap::collect_locked(GCCause::Cause cause, int max_level) { | |
844 if (_preloading_shared_classes) { | |
845 warning("\nThe permanent generation is not large enough to preload " | |
846 "requested classes.\nUse -XX:PermSize= to increase the initial " | |
847 "size of the permanent generation.\n"); | |
848 vm_exit(2); | |
849 } | |
850 // Read the GC count while holding the Heap_lock | |
851 unsigned int gc_count_before = total_collections(); | |
852 unsigned int full_gc_count_before = total_full_collections(); | |
853 { | |
854 MutexUnlocker mu(Heap_lock); // give up heap lock, execute gets it back | |
855 VM_GenCollectFull op(gc_count_before, full_gc_count_before, | |
856 cause, max_level); | |
857 VMThread::execute(&op); | |
858 } | |
859 } | |
860 | |
861 #ifndef SERIALGC | |
862 bool GenCollectedHeap::create_cms_collector() { | |
863 | |
864 assert(((_gens[1]->kind() == Generation::ConcurrentMarkSweep) || | |
865 (_gens[1]->kind() == Generation::ASConcurrentMarkSweep)) && | |
866 _perm_gen->as_gen()->kind() == Generation::ConcurrentMarkSweep, | |
867 "Unexpected generation kinds"); | |
868 // Skip two header words in the block content verification | |
869 NOT_PRODUCT(_skip_header_HeapWords = CMSCollector::skip_header_HeapWords();) | |
870 CMSCollector* collector = new CMSCollector( | |
871 (ConcurrentMarkSweepGeneration*)_gens[1], | |
872 (ConcurrentMarkSweepGeneration*)_perm_gen->as_gen(), | |
873 _rem_set->as_CardTableRS(), | |
874 (ConcurrentMarkSweepPolicy*) collector_policy()); | |
875 | |
876 if (collector == NULL || !collector->completed_initialization()) { | |
877 if (collector) { | |
878 delete collector; // Be nice in embedded situation | |
879 } | |
880 vm_shutdown_during_initialization("Could not create CMS collector"); | |
881 return false; | |
882 } | |
883 return true; // success | |
884 } | |
885 | |
886 void GenCollectedHeap::collect_mostly_concurrent(GCCause::Cause cause) { | |
887 assert(!Heap_lock->owned_by_self(), "Should not own Heap_lock"); | |
888 | |
889 MutexLocker ml(Heap_lock); | |
890 // Read the GC counts while holding the Heap_lock | |
891 unsigned int full_gc_count_before = total_full_collections(); | |
892 unsigned int gc_count_before = total_collections(); | |
893 { | |
894 MutexUnlocker mu(Heap_lock); | |
895 VM_GenCollectFullConcurrent op(gc_count_before, full_gc_count_before, cause); | |
896 VMThread::execute(&op); | |
897 } | |
898 } | |
899 #endif // SERIALGC | |
900 | |
901 | |
902 void GenCollectedHeap::do_full_collection(bool clear_all_soft_refs, | |
903 int max_level) { | |
904 int local_max_level; | |
905 if (!incremental_collection_will_fail() && | |
906 gc_cause() == GCCause::_gc_locker) { | |
907 local_max_level = 0; | |
908 } else { | |
909 local_max_level = max_level; | |
910 } | |
911 | |
912 do_collection(true /* full */, | |
913 clear_all_soft_refs /* clear_all_soft_refs */, | |
914 0 /* size */, | |
915 false /* is_tlab */, | |
916 local_max_level /* max_level */); | |
917 // Hack XXX FIX ME !!! | |
918 // A scavenge may not have been attempted, or may have | |
919 // been attempted and failed, because the old gen was too full | |
920 if (local_max_level == 0 && gc_cause() == GCCause::_gc_locker && | |
921 incremental_collection_will_fail()) { | |
922 if (PrintGCDetails) { | |
923 gclog_or_tty->print_cr("GC locker: Trying a full collection " | |
924 "because scavenge failed"); | |
925 } | |
926 // This time allow the old gen to be collected as well | |
927 do_collection(true /* full */, | |
928 clear_all_soft_refs /* clear_all_soft_refs */, | |
929 0 /* size */, | |
930 false /* is_tlab */, | |
931 n_gens() - 1 /* max_level */); | |
932 } | |
933 } | |
934 | |
935 // Returns "TRUE" iff "p" points into the allocated area of the heap. | |
936 bool GenCollectedHeap::is_in(const void* p) const { | |
937 #ifndef ASSERT | |
938 guarantee(VerifyBeforeGC || | |
939 VerifyDuringGC || | |
940 VerifyBeforeExit || | |
1155
4e6abf09f540
6912062: disassembler plugin needs to produce symbolic information in product mode
jrose
parents:
989
diff
changeset
|
941 PrintAssembly || |
4e6abf09f540
6912062: disassembler plugin needs to produce symbolic information in product mode
jrose
parents:
989
diff
changeset
|
942 tty->count() != 0 || // already printing |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1626
diff
changeset
|
943 VerifyAfterGC || |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1626
diff
changeset
|
944 VMError::fatal_error_in_progress(), "too expensive"); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1626
diff
changeset
|
945 |
0 | 946 #endif |
947 // This might be sped up with a cache of the last generation that | |
948 // answered yes. | |
949 for (int i = 0; i < _n_gens; i++) { | |
950 if (_gens[i]->is_in(p)) return true; | |
951 } | |
952 if (_perm_gen->as_gen()->is_in(p)) return true; | |
953 // Otherwise... | |
954 return false; | |
955 } | |
956 | |
957 // Returns "TRUE" iff "p" points into the allocated area of the heap. | |
958 bool GenCollectedHeap::is_in_youngest(void* p) { | |
959 return _gens[0]->is_in(p); | |
960 } | |
961 | |
962 void GenCollectedHeap::oop_iterate(OopClosure* cl) { | |
963 for (int i = 0; i < _n_gens; i++) { | |
964 _gens[i]->oop_iterate(cl); | |
965 } | |
966 } | |
967 | |
968 void GenCollectedHeap::oop_iterate(MemRegion mr, OopClosure* cl) { | |
969 for (int i = 0; i < _n_gens; i++) { | |
970 _gens[i]->oop_iterate(mr, cl); | |
971 } | |
972 } | |
973 | |
974 void GenCollectedHeap::object_iterate(ObjectClosure* cl) { | |
975 for (int i = 0; i < _n_gens; i++) { | |
976 _gens[i]->object_iterate(cl); | |
977 } | |
978 perm_gen()->object_iterate(cl); | |
979 } | |
980 | |
517
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
981 void GenCollectedHeap::safe_object_iterate(ObjectClosure* cl) { |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
982 for (int i = 0; i < _n_gens; i++) { |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
983 _gens[i]->safe_object_iterate(cl); |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
984 } |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
985 perm_gen()->safe_object_iterate(cl); |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
986 } |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
987 |
0 | 988 void GenCollectedHeap::object_iterate_since_last_GC(ObjectClosure* cl) { |
989 for (int i = 0; i < _n_gens; i++) { | |
990 _gens[i]->object_iterate_since_last_GC(cl); | |
991 } | |
992 } | |
993 | |
994 Space* GenCollectedHeap::space_containing(const void* addr) const { | |
995 for (int i = 0; i < _n_gens; i++) { | |
996 Space* res = _gens[i]->space_containing(addr); | |
997 if (res != NULL) return res; | |
998 } | |
999 Space* res = perm_gen()->space_containing(addr); | |
1000 if (res != NULL) return res; | |
1001 // Otherwise... | |
1002 assert(false, "Could not find containing space"); | |
1003 return NULL; | |
1004 } | |
1005 | |
1006 | |
1007 HeapWord* GenCollectedHeap::block_start(const void* addr) const { | |
1008 assert(is_in_reserved(addr), "block_start of address outside of heap"); | |
1009 for (int i = 0; i < _n_gens; i++) { | |
1010 if (_gens[i]->is_in_reserved(addr)) { | |
1011 assert(_gens[i]->is_in(addr), | |
1012 "addr should be in allocated part of generation"); | |
1013 return _gens[i]->block_start(addr); | |
1014 } | |
1015 } | |
1016 if (perm_gen()->is_in_reserved(addr)) { | |
1017 assert(perm_gen()->is_in(addr), | |
1018 "addr should be in allocated part of perm gen"); | |
1019 return perm_gen()->block_start(addr); | |
1020 } | |
1021 assert(false, "Some generation should contain the address"); | |
1022 return NULL; | |
1023 } | |
1024 | |
1025 size_t GenCollectedHeap::block_size(const HeapWord* addr) const { | |
1026 assert(is_in_reserved(addr), "block_size of address outside of heap"); | |
1027 for (int i = 0; i < _n_gens; i++) { | |
1028 if (_gens[i]->is_in_reserved(addr)) { | |
1029 assert(_gens[i]->is_in(addr), | |
1030 "addr should be in allocated part of generation"); | |
1031 return _gens[i]->block_size(addr); | |
1032 } | |
1033 } | |
1034 if (perm_gen()->is_in_reserved(addr)) { | |
1035 assert(perm_gen()->is_in(addr), | |
1036 "addr should be in allocated part of perm gen"); | |
1037 return perm_gen()->block_size(addr); | |
1038 } | |
1039 assert(false, "Some generation should contain the address"); | |
1040 return 0; | |
1041 } | |
1042 | |
1043 bool GenCollectedHeap::block_is_obj(const HeapWord* addr) const { | |
1044 assert(is_in_reserved(addr), "block_is_obj of address outside of heap"); | |
1045 assert(block_start(addr) == addr, "addr must be a block start"); | |
1046 for (int i = 0; i < _n_gens; i++) { | |
1047 if (_gens[i]->is_in_reserved(addr)) { | |
1048 return _gens[i]->block_is_obj(addr); | |
1049 } | |
1050 } | |
1051 if (perm_gen()->is_in_reserved(addr)) { | |
1052 return perm_gen()->block_is_obj(addr); | |
1053 } | |
1054 assert(false, "Some generation should contain the address"); | |
1055 return false; | |
1056 } | |
1057 | |
1058 bool GenCollectedHeap::supports_tlab_allocation() const { | |
1059 for (int i = 0; i < _n_gens; i += 1) { | |
1060 if (_gens[i]->supports_tlab_allocation()) { | |
1061 return true; | |
1062 } | |
1063 } | |
1064 return false; | |
1065 } | |
1066 | |
1067 size_t GenCollectedHeap::tlab_capacity(Thread* thr) const { | |
1068 size_t result = 0; | |
1069 for (int i = 0; i < _n_gens; i += 1) { | |
1070 if (_gens[i]->supports_tlab_allocation()) { | |
1071 result += _gens[i]->tlab_capacity(); | |
1072 } | |
1073 } | |
1074 return result; | |
1075 } | |
1076 | |
1077 size_t GenCollectedHeap::unsafe_max_tlab_alloc(Thread* thr) const { | |
1078 size_t result = 0; | |
1079 for (int i = 0; i < _n_gens; i += 1) { | |
1080 if (_gens[i]->supports_tlab_allocation()) { | |
1081 result += _gens[i]->unsafe_max_tlab_alloc(); | |
1082 } | |
1083 } | |
1084 return result; | |
1085 } | |
1086 | |
1087 HeapWord* GenCollectedHeap::allocate_new_tlab(size_t size) { | |
1088 bool gc_overhead_limit_was_exceeded; | |
1089 HeapWord* result = mem_allocate(size /* size */, | |
1090 false /* is_large_noref */, | |
1091 true /* is_tlab */, | |
1092 &gc_overhead_limit_was_exceeded); | |
1093 return result; | |
1094 } | |
1095 | |
1096 // Requires "*prev_ptr" to be non-NULL. Deletes and a block of minimal size | |
1097 // from the list headed by "*prev_ptr". | |
1098 static ScratchBlock *removeSmallestScratch(ScratchBlock **prev_ptr) { | |
1099 bool first = true; | |
1100 size_t min_size = 0; // "first" makes this conceptually infinite. | |
1101 ScratchBlock **smallest_ptr, *smallest; | |
1102 ScratchBlock *cur = *prev_ptr; | |
1103 while (cur) { | |
1104 assert(*prev_ptr == cur, "just checking"); | |
1105 if (first || cur->num_words < min_size) { | |
1106 smallest_ptr = prev_ptr; | |
1107 smallest = cur; | |
1108 min_size = smallest->num_words; | |
1109 first = false; | |
1110 } | |
1111 prev_ptr = &cur->next; | |
1112 cur = cur->next; | |
1113 } | |
1114 smallest = *smallest_ptr; | |
1115 *smallest_ptr = smallest->next; | |
1116 return smallest; | |
1117 } | |
1118 | |
1119 // Sort the scratch block list headed by res into decreasing size order, | |
1120 // and set "res" to the result. | |
1121 static void sort_scratch_list(ScratchBlock*& list) { | |
1122 ScratchBlock* sorted = NULL; | |
1123 ScratchBlock* unsorted = list; | |
1124 while (unsorted) { | |
1125 ScratchBlock *smallest = removeSmallestScratch(&unsorted); | |
1126 smallest->next = sorted; | |
1127 sorted = smallest; | |
1128 } | |
1129 list = sorted; | |
1130 } | |
1131 | |
1132 ScratchBlock* GenCollectedHeap::gather_scratch(Generation* requestor, | |
1133 size_t max_alloc_words) { | |
1134 ScratchBlock* res = NULL; | |
1135 for (int i = 0; i < _n_gens; i++) { | |
1136 _gens[i]->contribute_scratch(res, requestor, max_alloc_words); | |
1137 } | |
1138 sort_scratch_list(res); | |
1139 return res; | |
1140 } | |
1141 | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
1142 void GenCollectedHeap::release_scratch() { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
1143 for (int i = 0; i < _n_gens; i++) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
1144 _gens[i]->reset_scratch(); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
1145 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
1146 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
1147 |
0 | 1148 size_t GenCollectedHeap::large_typearray_limit() { |
1149 return gen_policy()->large_typearray_limit(); | |
1150 } | |
1151 | |
1152 class GenPrepareForVerifyClosure: public GenCollectedHeap::GenClosure { | |
1153 void do_generation(Generation* gen) { | |
1154 gen->prepare_for_verify(); | |
1155 } | |
1156 }; | |
1157 | |
1158 void GenCollectedHeap::prepare_for_verify() { | |
1159 ensure_parsability(false); // no need to retire TLABs | |
1160 GenPrepareForVerifyClosure blk; | |
1161 generation_iterate(&blk, false); | |
1162 perm_gen()->prepare_for_verify(); | |
1163 } | |
1164 | |
1165 | |
1166 void GenCollectedHeap::generation_iterate(GenClosure* cl, | |
1167 bool old_to_young) { | |
1168 if (old_to_young) { | |
1169 for (int i = _n_gens-1; i >= 0; i--) { | |
1170 cl->do_generation(_gens[i]); | |
1171 } | |
1172 } else { | |
1173 for (int i = 0; i < _n_gens; i++) { | |
1174 cl->do_generation(_gens[i]); | |
1175 } | |
1176 } | |
1177 } | |
1178 | |
1179 void GenCollectedHeap::space_iterate(SpaceClosure* cl) { | |
1180 for (int i = 0; i < _n_gens; i++) { | |
1181 _gens[i]->space_iterate(cl, true); | |
1182 } | |
1183 perm_gen()->space_iterate(cl, true); | |
1184 } | |
1185 | |
1186 bool GenCollectedHeap::is_maximal_no_gc() const { | |
1187 for (int i = 0; i < _n_gens; i++) { // skip perm gen | |
1188 if (!_gens[i]->is_maximal_no_gc()) { | |
1189 return false; | |
1190 } | |
1191 } | |
1192 return true; | |
1193 } | |
1194 | |
1195 void GenCollectedHeap::save_marks() { | |
1196 for (int i = 0; i < _n_gens; i++) { | |
1197 _gens[i]->save_marks(); | |
1198 } | |
1199 perm_gen()->save_marks(); | |
1200 } | |
1201 | |
1202 void GenCollectedHeap::compute_new_generation_sizes(int collectedGen) { | |
1203 for (int i = 0; i <= collectedGen; i++) { | |
1204 _gens[i]->compute_new_size(); | |
1205 } | |
1206 } | |
1207 | |
1208 GenCollectedHeap* GenCollectedHeap::heap() { | |
1209 assert(_gch != NULL, "Uninitialized access to GenCollectedHeap::heap()"); | |
1210 assert(_gch->kind() == CollectedHeap::GenCollectedHeap, "not a generational heap"); | |
1211 return _gch; | |
1212 } | |
1213 | |
1214 | |
1215 void GenCollectedHeap::prepare_for_compaction() { | |
1216 Generation* scanning_gen = _gens[_n_gens-1]; | |
1217 // Start by compacting into same gen. | |
1218 CompactPoint cp(scanning_gen, NULL, NULL); | |
1219 while (scanning_gen != NULL) { | |
1220 scanning_gen->prepare_for_compaction(&cp); | |
1221 scanning_gen = prev_gen(scanning_gen); | |
1222 } | |
1223 } | |
1224 | |
1225 GCStats* GenCollectedHeap::gc_stats(int level) const { | |
1226 return _gens[level]->gc_stats(); | |
1227 } | |
1228 | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
647
diff
changeset
|
1229 void GenCollectedHeap::verify(bool allow_dirty, bool silent, bool option /* ignored */) { |
0 | 1230 if (!silent) { |
1231 gclog_or_tty->print("permgen "); | |
1232 } | |
1233 perm_gen()->verify(allow_dirty); | |
1234 for (int i = _n_gens-1; i >= 0; i--) { | |
1235 Generation* g = _gens[i]; | |
1236 if (!silent) { | |
1237 gclog_or_tty->print(g->name()); | |
1238 gclog_or_tty->print(" "); | |
1239 } | |
1240 g->verify(allow_dirty); | |
1241 } | |
1242 if (!silent) { | |
1243 gclog_or_tty->print("remset "); | |
1244 } | |
1245 rem_set()->verify(); | |
1246 if (!silent) { | |
1247 gclog_or_tty->print("ref_proc "); | |
1248 } | |
1249 ReferenceProcessor::verify(); | |
1250 } | |
1251 | |
1252 void GenCollectedHeap::print() const { print_on(tty); } | |
1253 void GenCollectedHeap::print_on(outputStream* st) const { | |
1254 for (int i = 0; i < _n_gens; i++) { | |
1255 _gens[i]->print_on(st); | |
1256 } | |
1257 perm_gen()->print_on(st); | |
1258 } | |
1259 | |
1260 void GenCollectedHeap::gc_threads_do(ThreadClosure* tc) const { | |
1261 if (workers() != NULL) { | |
1262 workers()->threads_do(tc); | |
1263 } | |
1264 #ifndef SERIALGC | |
1265 if (UseConcMarkSweepGC) { | |
1266 ConcurrentMarkSweepThread::threads_do(tc); | |
1267 } | |
1268 #endif // SERIALGC | |
1269 } | |
1270 | |
1271 void GenCollectedHeap::print_gc_threads_on(outputStream* st) const { | |
1272 #ifndef SERIALGC | |
1273 if (UseParNewGC) { | |
1274 workers()->print_worker_threads_on(st); | |
1275 } | |
1276 if (UseConcMarkSweepGC) { | |
1277 ConcurrentMarkSweepThread::print_all_on(st); | |
1278 } | |
1279 #endif // SERIALGC | |
1280 } | |
1281 | |
1282 void GenCollectedHeap::print_tracing_info() const { | |
1283 if (TraceGen0Time) { | |
1284 get_gen(0)->print_summary_info(); | |
1285 } | |
1286 if (TraceGen1Time) { | |
1287 get_gen(1)->print_summary_info(); | |
1288 } | |
1289 } | |
1290 | |
1291 void GenCollectedHeap::print_heap_change(size_t prev_used) const { | |
1292 if (PrintGCDetails && Verbose) { | |
1293 gclog_or_tty->print(" " SIZE_FORMAT | |
1294 "->" SIZE_FORMAT | |
1295 "(" SIZE_FORMAT ")", | |
1296 prev_used, used(), capacity()); | |
1297 } else { | |
1298 gclog_or_tty->print(" " SIZE_FORMAT "K" | |
1299 "->" SIZE_FORMAT "K" | |
1300 "(" SIZE_FORMAT "K)", | |
1301 prev_used / K, used() / K, capacity() / K); | |
1302 } | |
1303 } | |
1304 | |
1305 //New method to print perm gen info with PrintGCDetails flag | |
1306 void GenCollectedHeap::print_perm_heap_change(size_t perm_prev_used) const { | |
1307 gclog_or_tty->print(", [%s :", perm_gen()->short_name()); | |
1308 perm_gen()->print_heap_change(perm_prev_used); | |
1309 gclog_or_tty->print("]"); | |
1310 } | |
1311 | |
1312 class GenGCPrologueClosure: public GenCollectedHeap::GenClosure { | |
1313 private: | |
1314 bool _full; | |
1315 public: | |
1316 void do_generation(Generation* gen) { | |
1317 gen->gc_prologue(_full); | |
1318 } | |
1319 GenGCPrologueClosure(bool full) : _full(full) {}; | |
1320 }; | |
1321 | |
1322 void GenCollectedHeap::gc_prologue(bool full) { | |
1323 assert(InlineCacheBuffer::is_empty(), "should have cleaned up ICBuffer"); | |
1324 | |
1325 always_do_update_barrier = false; | |
1326 // Fill TLAB's and such | |
1327 CollectedHeap::accumulate_statistics_all_tlabs(); | |
1328 ensure_parsability(true); // retire TLABs | |
1329 | |
1330 // Call allocation profiler | |
1331 AllocationProfiler::iterate_since_last_gc(); | |
1332 // Walk generations | |
1333 GenGCPrologueClosure blk(full); | |
1334 generation_iterate(&blk, false); // not old-to-young. | |
1335 perm_gen()->gc_prologue(full); | |
1336 }; | |
1337 | |
1338 class GenGCEpilogueClosure: public GenCollectedHeap::GenClosure { | |
1339 private: | |
1340 bool _full; | |
1341 public: | |
1342 void do_generation(Generation* gen) { | |
1343 gen->gc_epilogue(_full); | |
1344 } | |
1345 GenGCEpilogueClosure(bool full) : _full(full) {}; | |
1346 }; | |
1347 | |
1348 void GenCollectedHeap::gc_epilogue(bool full) { | |
1349 #ifdef COMPILER2 | |
1350 assert(DerivedPointerTable::is_empty(), "derived pointer present"); | |
1351 size_t actual_gap = pointer_delta((HeapWord*) (max_uintx-3), *(end_addr())); | |
1352 guarantee(actual_gap > (size_t)FastAllocateSizeLimit, "inline allocation wraps"); | |
1353 #endif /* COMPILER2 */ | |
1354 | |
1355 resize_all_tlabs(); | |
1356 | |
1357 GenGCEpilogueClosure blk(full); | |
1358 generation_iterate(&blk, false); // not old-to-young. | |
1359 perm_gen()->gc_epilogue(full); | |
1360 | |
1361 always_do_update_barrier = UseConcMarkSweepGC; | |
1362 }; | |
1363 | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
1364 #ifndef PRODUCT |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
1365 class GenGCSaveTopsBeforeGCClosure: public GenCollectedHeap::GenClosure { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
1366 private: |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
1367 public: |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
1368 void do_generation(Generation* gen) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
1369 gen->record_spaces_top(); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
1370 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
1371 }; |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
1372 |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
1373 void GenCollectedHeap::record_gen_tops_before_GC() { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
1374 if (ZapUnusedHeapArea) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
1375 GenGCSaveTopsBeforeGCClosure blk; |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
1376 generation_iterate(&blk, false); // not old-to-young. |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
1377 perm_gen()->record_spaces_top(); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
1378 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
1379 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
1380 #endif // not PRODUCT |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
1381 |
0 | 1382 class GenEnsureParsabilityClosure: public GenCollectedHeap::GenClosure { |
1383 public: | |
1384 void do_generation(Generation* gen) { | |
1385 gen->ensure_parsability(); | |
1386 } | |
1387 }; | |
1388 | |
1389 void GenCollectedHeap::ensure_parsability(bool retire_tlabs) { | |
1390 CollectedHeap::ensure_parsability(retire_tlabs); | |
1391 GenEnsureParsabilityClosure ep_cl; | |
1392 generation_iterate(&ep_cl, false); | |
1393 perm_gen()->ensure_parsability(); | |
1394 } | |
1395 | |
1396 oop GenCollectedHeap::handle_failed_promotion(Generation* gen, | |
1397 oop obj, | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1398 size_t obj_size) { |
0 | 1399 assert(obj_size == (size_t)obj->size(), "bad obj_size passed in"); |
1400 HeapWord* result = NULL; | |
1401 | |
1402 // First give each higher generation a chance to allocate the promoted object. | |
1403 Generation* allocator = next_gen(gen); | |
1404 if (allocator != NULL) { | |
1405 do { | |
1406 result = allocator->allocate(obj_size, false); | |
1407 } while (result == NULL && (allocator = next_gen(allocator)) != NULL); | |
1408 } | |
1409 | |
1410 if (result == NULL) { | |
1411 // Then give gen and higher generations a chance to expand and allocate the | |
1412 // object. | |
1413 do { | |
1414 result = gen->expand_and_allocate(obj_size, false); | |
1415 } while (result == NULL && (gen = next_gen(gen)) != NULL); | |
1416 } | |
1417 | |
1418 if (result != NULL) { | |
1419 Copy::aligned_disjoint_words((HeapWord*)obj, result, obj_size); | |
1420 } | |
1421 return oop(result); | |
1422 } | |
1423 | |
1424 class GenTimeOfLastGCClosure: public GenCollectedHeap::GenClosure { | |
1425 jlong _time; // in ms | |
1426 jlong _now; // in ms | |
1427 | |
1428 public: | |
1429 GenTimeOfLastGCClosure(jlong now) : _time(now), _now(now) { } | |
1430 | |
1431 jlong time() { return _time; } | |
1432 | |
1433 void do_generation(Generation* gen) { | |
1434 _time = MIN2(_time, gen->time_of_last_gc(_now)); | |
1435 } | |
1436 }; | |
1437 | |
1438 jlong GenCollectedHeap::millis_since_last_gc() { | |
1439 jlong now = os::javaTimeMillis(); | |
1440 GenTimeOfLastGCClosure tolgc_cl(now); | |
1441 // iterate over generations getting the oldest | |
1442 // time that a generation was collected | |
1443 generation_iterate(&tolgc_cl, false); | |
1444 tolgc_cl.do_generation(perm_gen()); | |
1445 // XXX Despite the assert above, since javaTimeMillis() | |
1446 // doesnot guarantee monotonically increasing return | |
1447 // values (note, i didn't say "strictly monotonic"), | |
1448 // we need to guard against getting back a time | |
1449 // later than now. This should be fixed by basing | |
1450 // on someting like gethrtime() which guarantees | |
1451 // monotonicity. Note that cond_wait() is susceptible | |
1452 // to a similar problem, because its interface is | |
1453 // based on absolute time in the form of the | |
1454 // system time's notion of UCT. See also 4506635 | |
1455 // for yet another problem of similar nature. XXX | |
1456 jlong retVal = now - tolgc_cl.time(); | |
1457 if (retVal < 0) { | |
1458 NOT_PRODUCT(warning("time warp: %d", retVal);) | |
1459 return 0; | |
1460 } | |
1461 return retVal; | |
1462 } |