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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/symbolTable.hpp"
27 #include "classfile/systemDictionary.hpp"
28 #include "classfile/vmSymbols.hpp"
29 #include "code/codeCache.hpp"
30 #include "code/icBuffer.hpp"
31 #include "gc/shared/collectedHeap.inline.hpp"
32 #include "gc/shared/collectorCounters.hpp"
33 #include "gc/shared/gcLocker.inline.hpp"
34 #include "gc/shared/gcTrace.hpp"
35 #include "gc/shared/gcTraceTime.hpp"
36 #include "gc/shared/genCollectedHeap.hpp"
37 #include "gc/shared/genOopClosures.inline.hpp"
38 #include "gc/shared/generationSpec.hpp"
39 #include "gc/shared/space.hpp"
40 #include "gc/shared/strongRootsScope.hpp"
41 #include "gc/shared/vmGCOperations.hpp"
42 #include "gc/shared/workgroup.hpp"
43 #include "memory/filemap.hpp"
44 #include "memory/resourceArea.hpp"
45 #include "oops/oop.inline.hpp"
46 #include "runtime/biasedLocking.hpp"
47 #include "runtime/fprofiler.hpp"
48 #include "runtime/handles.hpp"
49 #include "runtime/handles.inline.hpp"
50 #include "runtime/java.hpp"
51 #include "runtime/vmThread.hpp"
52 #include "services/management.hpp"
298 }
299
300 bool GenCollectedHeap::should_do_concurrent_full_gc(GCCause::Cause cause) {
301 if (!UseConcMarkSweepGC) {
302 return false;
303 }
304
305 switch (cause) {
306 case GCCause::_gc_locker: return GCLockerInvokesConcurrent;
307 case GCCause::_java_lang_system_gc:
308 case GCCause::_dcmd_gc_run: return ExplicitGCInvokesConcurrent;
309 default: return false;
310 }
311 }
312
313 void GenCollectedHeap::collect_generation(Generation* gen, bool full, size_t size,
314 bool is_tlab, bool run_verification, bool clear_soft_refs,
315 bool restore_marks_for_biased_locking) {
316 // Timer for individual generations. Last argument is false: no CR
317 // FIXME: We should try to start the timing earlier to cover more of the GC pause
318 // The PrintGCDetails logging starts before we have incremented the GC id. We will do that later
319 // so we can assume here that the next GC id is what we want.
320 GCTraceTime t1(gen->short_name(), PrintGCDetails, false, NULL, GCId::peek());
321 TraceCollectorStats tcs(gen->counters());
322 TraceMemoryManagerStats tmms(gen->kind(),gc_cause());
323
324 size_t prev_used = gen->used();
325 gen->stat_record()->invocations++;
326 gen->stat_record()->accumulated_time.start();
327
328 // Must be done anew before each collection because
329 // a previous collection will do mangling and will
330 // change top of some spaces.
331 record_gen_tops_before_GC();
332
333 if (PrintGC && Verbose) {
334 // I didn't want to change the logging when removing the level concept,
335 // but I guess this logging could say young/old or something instead of 0/1.
336 uint level;
337 if (heap()->is_young_gen(gen)) {
338 level = 0;
339 } else {
340 level = 1;
417 void GenCollectedHeap::do_collection(bool full,
418 bool clear_all_soft_refs,
419 size_t size,
420 bool is_tlab,
421 GenerationType max_generation) {
422 ResourceMark rm;
423 DEBUG_ONLY(Thread* my_thread = Thread::current();)
424
425 assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");
426 assert(my_thread->is_VM_thread() ||
427 my_thread->is_ConcurrentGC_thread(),
428 "incorrect thread type capability");
429 assert(Heap_lock->is_locked(),
430 "the requesting thread should have the Heap_lock");
431 guarantee(!is_gc_active(), "collection is not reentrant");
432
433 if (GC_locker::check_active_before_gc()) {
434 return; // GC is disabled (e.g. JNI GetXXXCritical operation)
435 }
436
437 const bool do_clear_all_soft_refs = clear_all_soft_refs ||
438 collector_policy()->should_clear_all_soft_refs();
439
440 ClearedAllSoftRefs casr(do_clear_all_soft_refs, collector_policy());
441
442 const size_t metadata_prev_used = MetaspaceAux::used_bytes();
443
444 print_heap_before_gc();
445
446 {
447 FlagSetting fl(_is_gc_active, true);
448
449 bool complete = full && (max_generation == OldGen);
450 const char* gc_cause_prefix = complete ? "Full GC" : "GC";
451 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty);
452 // The PrintGCDetails logging starts before we have incremented the GC id. We will do that later
453 // so we can assume here that the next GC id is what we want.
454 GCTraceTime t(GCCauseString(gc_cause_prefix, gc_cause()), PrintGCDetails, false, NULL, GCId::peek());
455
456 gc_prologue(complete);
457 increment_total_collections(complete);
458
459 size_t gch_prev_used = used();
460 bool run_verification = total_collections() >= VerifyGCStartAt;
461
462 bool prepared_for_verification = false;
463 bool collected_old = false;
464 bool old_collects_young = complete &&
465 _old_gen->full_collects_young_generation();
466 if (!old_collects_young &&
467 _young_gen->should_collect(full, size, is_tlab)) {
468 if (run_verification && VerifyGCLevel <= 0 && VerifyBeforeGC) {
469 prepare_for_verify();
470 prepared_for_verification = true;
471 }
472
473 assert(!_young_gen->performs_in_place_marking(), "No young generation do in place marking");
474 collect_generation(_young_gen,
475 full,
476 size,
477 is_tlab,
478 run_verification && VerifyGCLevel <= 0,
479 do_clear_all_soft_refs,
480 false);
481
482 if (size > 0 && (!is_tlab || _young_gen->supports_tlab_allocation()) &&
483 size * HeapWordSize <= _young_gen->unsafe_max_alloc_nogc()) {
484 // Allocation request was met by young GC.
485 size = 0;
486 }
487 }
488
489 bool must_restore_marks_for_biased_locking = false;
490
491 if (max_generation == OldGen && _old_gen->should_collect(full, size, is_tlab)) {
492 if (!complete) {
493 // The full_collections increment was missed above.
494 increment_total_full_collections();
495 }
496
497 pre_full_gc_dump(NULL); // do any pre full gc dumps
498
499 if (!prepared_for_verification && run_verification &&
500 VerifyGCLevel <= 1 && VerifyBeforeGC) {
501 prepare_for_verify();
502 }
503
504 assert(_old_gen->performs_in_place_marking(), "All old generations do in place marking");
505 collect_generation(_old_gen,
506 full,
507 size,
508 is_tlab,
509 run_verification && VerifyGCLevel <= 1,
510 do_clear_all_soft_refs,
511 true);
|
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/symbolTable.hpp"
27 #include "classfile/systemDictionary.hpp"
28 #include "classfile/vmSymbols.hpp"
29 #include "code/codeCache.hpp"
30 #include "code/icBuffer.hpp"
31 #include "gc/shared/collectedHeap.inline.hpp"
32 #include "gc/shared/collectorCounters.hpp"
33 #include "gc/shared/gcId.hpp"
34 #include "gc/shared/gcLocker.inline.hpp"
35 #include "gc/shared/gcTrace.hpp"
36 #include "gc/shared/gcTraceTime.hpp"
37 #include "gc/shared/genCollectedHeap.hpp"
38 #include "gc/shared/genOopClosures.inline.hpp"
39 #include "gc/shared/generationSpec.hpp"
40 #include "gc/shared/space.hpp"
41 #include "gc/shared/strongRootsScope.hpp"
42 #include "gc/shared/vmGCOperations.hpp"
43 #include "gc/shared/workgroup.hpp"
44 #include "memory/filemap.hpp"
45 #include "memory/resourceArea.hpp"
46 #include "oops/oop.inline.hpp"
47 #include "runtime/biasedLocking.hpp"
48 #include "runtime/fprofiler.hpp"
49 #include "runtime/handles.hpp"
50 #include "runtime/handles.inline.hpp"
51 #include "runtime/java.hpp"
52 #include "runtime/vmThread.hpp"
53 #include "services/management.hpp"
299 }
300
301 bool GenCollectedHeap::should_do_concurrent_full_gc(GCCause::Cause cause) {
302 if (!UseConcMarkSweepGC) {
303 return false;
304 }
305
306 switch (cause) {
307 case GCCause::_gc_locker: return GCLockerInvokesConcurrent;
308 case GCCause::_java_lang_system_gc:
309 case GCCause::_dcmd_gc_run: return ExplicitGCInvokesConcurrent;
310 default: return false;
311 }
312 }
313
314 void GenCollectedHeap::collect_generation(Generation* gen, bool full, size_t size,
315 bool is_tlab, bool run_verification, bool clear_soft_refs,
316 bool restore_marks_for_biased_locking) {
317 // Timer for individual generations. Last argument is false: no CR
318 // FIXME: We should try to start the timing earlier to cover more of the GC pause
319 GCTraceTime t1(gen->short_name(), PrintGCDetails, false, NULL);
320 TraceCollectorStats tcs(gen->counters());
321 TraceMemoryManagerStats tmms(gen->kind(),gc_cause());
322
323 size_t prev_used = gen->used();
324 gen->stat_record()->invocations++;
325 gen->stat_record()->accumulated_time.start();
326
327 // Must be done anew before each collection because
328 // a previous collection will do mangling and will
329 // change top of some spaces.
330 record_gen_tops_before_GC();
331
332 if (PrintGC && Verbose) {
333 // I didn't want to change the logging when removing the level concept,
334 // but I guess this logging could say young/old or something instead of 0/1.
335 uint level;
336 if (heap()->is_young_gen(gen)) {
337 level = 0;
338 } else {
339 level = 1;
416 void GenCollectedHeap::do_collection(bool full,
417 bool clear_all_soft_refs,
418 size_t size,
419 bool is_tlab,
420 GenerationType max_generation) {
421 ResourceMark rm;
422 DEBUG_ONLY(Thread* my_thread = Thread::current();)
423
424 assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");
425 assert(my_thread->is_VM_thread() ||
426 my_thread->is_ConcurrentGC_thread(),
427 "incorrect thread type capability");
428 assert(Heap_lock->is_locked(),
429 "the requesting thread should have the Heap_lock");
430 guarantee(!is_gc_active(), "collection is not reentrant");
431
432 if (GC_locker::check_active_before_gc()) {
433 return; // GC is disabled (e.g. JNI GetXXXCritical operation)
434 }
435
436 GCIdMark gc_id_mark;
437
438 const bool do_clear_all_soft_refs = clear_all_soft_refs ||
439 collector_policy()->should_clear_all_soft_refs();
440
441 ClearedAllSoftRefs casr(do_clear_all_soft_refs, collector_policy());
442
443 const size_t metadata_prev_used = MetaspaceAux::used_bytes();
444
445 print_heap_before_gc();
446
447 {
448 FlagSetting fl(_is_gc_active, true);
449
450 bool complete = full && (max_generation == OldGen);
451 const char* gc_cause_prefix = complete ? "Full GC" : "GC";
452 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty);
453 GCTraceTime t(GCCauseString(gc_cause_prefix, gc_cause()), PrintGCDetails, false, NULL);
454
455 gc_prologue(complete);
456 increment_total_collections(complete);
457
458 size_t gch_prev_used = used();
459 bool run_verification = total_collections() >= VerifyGCStartAt;
460
461 bool prepared_for_verification = false;
462 bool collected_old = false;
463 bool old_collects_young = complete &&
464 _old_gen->full_collects_young_generation();
465 if (!old_collects_young &&
466 _young_gen->should_collect(full, size, is_tlab)) {
467 if (run_verification && VerifyGCLevel <= 0 && VerifyBeforeGC) {
468 prepare_for_verify();
469 prepared_for_verification = true;
470 }
471
472 assert(!_young_gen->performs_in_place_marking(), "No young generation do in place marking");
473 collect_generation(_young_gen,
474 full,
475 size,
476 is_tlab,
477 run_verification && VerifyGCLevel <= 0,
478 do_clear_all_soft_refs,
479 false);
480
481 if (size > 0 && (!is_tlab || _young_gen->supports_tlab_allocation()) &&
482 size * HeapWordSize <= _young_gen->unsafe_max_alloc_nogc()) {
483 // Allocation request was met by young GC.
484 size = 0;
485 }
486 }
487
488 bool must_restore_marks_for_biased_locking = false;
489
490 if (max_generation == OldGen && _old_gen->should_collect(full, size, is_tlab)) {
491 GCIdMark gc_id_mark;
492 if (!complete) {
493 // The full_collections increment was missed above.
494 increment_total_full_collections();
495 }
496
497 pre_full_gc_dump(NULL); // do any pre full gc dumps
498
499 if (!prepared_for_verification && run_verification &&
500 VerifyGCLevel <= 1 && VerifyBeforeGC) {
501 prepare_for_verify();
502 }
503
504 assert(_old_gen->performs_in_place_marking(), "All old generations do in place marking");
505 collect_generation(_old_gen,
506 full,
507 size,
508 is_tlab,
509 run_verification && VerifyGCLevel <= 1,
510 do_clear_all_soft_refs,
511 true);
|