comparison src/share/vm/memory/defNewGeneration.cpp @ 10405:f2110083203d

8005849: JEP 167: Event-Based JVM Tracing Reviewed-by: acorn, coleenp, sla Contributed-by: Karen Kinnear <karen.kinnear@oracle.com>, Bengt Rutisson <bengt.rutisson@oracle.com>, Calvin Cheung <calvin.cheung@oracle.com>, Erik Gahlin <erik.gahlin@oracle.com>, Erik Helin <erik.helin@oracle.com>, Jesper Wilhelmsson <jesper.wilhelmsson@oracle.com>, Keith McGuigan <keith.mcguigan@oracle.com>, Mattias Tobiasson <mattias.tobiasson@oracle.com>, Markus Gronlund <markus.gronlund@oracle.com>, Mikael Auno <mikael.auno@oracle.com>, Nils Eliasson <nils.eliasson@oracle.com>, Nils Loodin <nils.loodin@oracle.com>, Rickard Backman <rickard.backman@oracle.com>, Staffan Larsen <staffan.larsen@oracle.com>, Stefan Karlsson <stefan.karlsson@oracle.com>, Yekaterina Kantserova <yekaterina.kantserova@oracle.com>
author sla
date Mon, 10 Jun 2013 11:30:51 +0200
parents 001ec9515f84
children 71180a6e5080
comparison
equal deleted inserted replaced
10404:d0add7016434 10405:f2110083203d
1 /* 1 /*
2 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
23 */ 23 */
24 24
25 #include "precompiled.hpp" 25 #include "precompiled.hpp"
26 #include "gc_implementation/shared/collectorCounters.hpp" 26 #include "gc_implementation/shared/collectorCounters.hpp"
27 #include "gc_implementation/shared/gcPolicyCounters.hpp" 27 #include "gc_implementation/shared/gcPolicyCounters.hpp"
28 #include "gc_implementation/shared/gcHeapSummary.hpp"
29 #include "gc_implementation/shared/gcTimer.hpp"
30 #include "gc_implementation/shared/gcTraceTime.hpp"
31 #include "gc_implementation/shared/gcTrace.hpp"
28 #include "gc_implementation/shared/spaceDecorator.hpp" 32 #include "gc_implementation/shared/spaceDecorator.hpp"
29 #include "memory/defNewGeneration.inline.hpp" 33 #include "memory/defNewGeneration.inline.hpp"
30 #include "memory/gcLocker.inline.hpp" 34 #include "memory/gcLocker.inline.hpp"
31 #include "memory/genCollectedHeap.hpp" 35 #include "memory/genCollectedHeap.hpp"
32 #include "memory/genOopClosures.inline.hpp" 36 #include "memory/genOopClosures.inline.hpp"
221 compute_space_boundaries(0, SpaceDecorator::Clear, SpaceDecorator::Mangle); 225 compute_space_boundaries(0, SpaceDecorator::Clear, SpaceDecorator::Mangle);
222 update_counters(); 226 update_counters();
223 _next_gen = NULL; 227 _next_gen = NULL;
224 _tenuring_threshold = MaxTenuringThreshold; 228 _tenuring_threshold = MaxTenuringThreshold;
225 _pretenure_size_threshold_words = PretenureSizeThreshold >> LogHeapWordSize; 229 _pretenure_size_threshold_words = PretenureSizeThreshold >> LogHeapWordSize;
230
231 _gc_timer = new (ResourceObj::C_HEAP, mtGC) STWGCTimer();
226 } 232 }
227 233
228 void DefNewGeneration::compute_space_boundaries(uintx minimum_eden_size, 234 void DefNewGeneration::compute_space_boundaries(uintx minimum_eden_size,
229 bool clear_space, 235 bool clear_space,
230 bool mangle_space) { 236 bool mangle_space) {
556 void DefNewGeneration::collect(bool full, 562 void DefNewGeneration::collect(bool full,
557 bool clear_all_soft_refs, 563 bool clear_all_soft_refs,
558 size_t size, 564 size_t size,
559 bool is_tlab) { 565 bool is_tlab) {
560 assert(full || size > 0, "otherwise we don't want to collect"); 566 assert(full || size > 0, "otherwise we don't want to collect");
567
561 GenCollectedHeap* gch = GenCollectedHeap::heap(); 568 GenCollectedHeap* gch = GenCollectedHeap::heap();
569
570 _gc_timer->register_gc_start(os::elapsed_counter());
571 DefNewTracer gc_tracer;
572 gc_tracer.report_gc_start(gch->gc_cause(), _gc_timer->gc_start());
573
562 _next_gen = gch->next_gen(this); 574 _next_gen = gch->next_gen(this);
563 assert(_next_gen != NULL, 575 assert(_next_gen != NULL,
564 "This must be the youngest gen, and not the only gen"); 576 "This must be the youngest gen, and not the only gen");
565 577
566 // If the next generation is too full to accomodate promotion 578 // If the next generation is too full to accommodate promotion
567 // from this generation, pass on collection; let the next generation 579 // from this generation, pass on collection; let the next generation
568 // do it. 580 // do it.
569 if (!collection_attempt_is_safe()) { 581 if (!collection_attempt_is_safe()) {
570 if (Verbose && PrintGCDetails) { 582 if (Verbose && PrintGCDetails) {
571 gclog_or_tty->print(" :: Collection attempt not safe :: "); 583 gclog_or_tty->print(" :: Collection attempt not safe :: ");
575 } 587 }
576 assert(to()->is_empty(), "Else not collection_attempt_is_safe"); 588 assert(to()->is_empty(), "Else not collection_attempt_is_safe");
577 589
578 init_assuming_no_promotion_failure(); 590 init_assuming_no_promotion_failure();
579 591
580 TraceTime t1(GCCauseString("GC", gch->gc_cause()), PrintGC && !PrintGCDetails, true, gclog_or_tty); 592 GCTraceTime t1(GCCauseString("GC", gch->gc_cause()), PrintGC && !PrintGCDetails, true, NULL);
581 // Capture heap used before collection (for printing). 593 // Capture heap used before collection (for printing).
582 size_t gch_prev_used = gch->used(); 594 size_t gch_prev_used = gch->used();
595
596 gch->trace_heap_before_gc(&gc_tracer);
583 597
584 SpecializationStats::clear(); 598 SpecializationStats::clear();
585 599
586 // These can be shared for all code paths 600 // These can be shared for all code paths
587 IsAliveClosure is_alive(this); 601 IsAliveClosure is_alive(this);
629 evacuate_followers.do_void(); 643 evacuate_followers.do_void();
630 644
631 FastKeepAliveClosure keep_alive(this, &scan_weak_ref); 645 FastKeepAliveClosure keep_alive(this, &scan_weak_ref);
632 ReferenceProcessor* rp = ref_processor(); 646 ReferenceProcessor* rp = ref_processor();
633 rp->setup_policy(clear_all_soft_refs); 647 rp->setup_policy(clear_all_soft_refs);
648 const ReferenceProcessorStats& stats =
634 rp->process_discovered_references(&is_alive, &keep_alive, &evacuate_followers, 649 rp->process_discovered_references(&is_alive, &keep_alive, &evacuate_followers,
635 NULL); 650 NULL, _gc_timer);
636 if (!promotion_failed()) { 651 gc_tracer.report_gc_reference_stats(stats);
652
653 if (!_promotion_failed) {
637 // Swap the survivor spaces. 654 // Swap the survivor spaces.
638 eden()->clear(SpaceDecorator::Mangle); 655 eden()->clear(SpaceDecorator::Mangle);
639 from()->clear(SpaceDecorator::Mangle); 656 from()->clear(SpaceDecorator::Mangle);
640 if (ZapUnusedHeapArea) { 657 if (ZapUnusedHeapArea) {
641 // This is now done here because of the piece-meal mangling which 658 // This is now done here because of the piece-meal mangling which
678 from()->set_next_compaction_space(to()); 695 from()->set_next_compaction_space(to());
679 gch->set_incremental_collection_failed(); 696 gch->set_incremental_collection_failed();
680 697
681 // Inform the next generation that a promotion failure occurred. 698 // Inform the next generation that a promotion failure occurred.
682 _next_gen->promotion_failure_occurred(); 699 _next_gen->promotion_failure_occurred();
700 gc_tracer.report_promotion_failed(_promotion_failed_info);
683 701
684 // Reset the PromotionFailureALot counters. 702 // Reset the PromotionFailureALot counters.
685 NOT_PRODUCT(Universe::heap()->reset_promotion_should_fail();) 703 NOT_PRODUCT(Universe::heap()->reset_promotion_should_fail();)
686 } 704 }
687 // set new iteration safe limit for the survivor spaces 705 // set new iteration safe limit for the survivor spaces
688 from()->set_concurrent_iteration_safe_limit(from()->top()); 706 from()->set_concurrent_iteration_safe_limit(from()->top());
689 to()->set_concurrent_iteration_safe_limit(to()->top()); 707 to()->set_concurrent_iteration_safe_limit(to()->top());
690 SpecializationStats::print(); 708 SpecializationStats::print();
691 709
692 // We need to use a monotonically non-deccreasing time in ms 710 // We need to use a monotonically non-decreasing time in ms
693 // or we will see time-warp warnings and os::javaTimeMillis() 711 // or we will see time-warp warnings and os::javaTimeMillis()
694 // does not guarantee monotonicity. 712 // does not guarantee monotonicity.
695 jlong now = os::javaTimeNanos() / NANOSECS_PER_MILLISEC; 713 jlong now = os::javaTimeNanos() / NANOSECS_PER_MILLISEC;
696 update_time_of_last_gc(now); 714 update_time_of_last_gc(now);
715
716 gch->trace_heap_after_gc(&gc_tracer);
717 gc_tracer.report_tenuring_threshold(tenuring_threshold());
718
719 _gc_timer->register_gc_end(os::elapsed_counter());
720
721 gc_tracer.report_gc_end(_gc_timer->gc_end(), _gc_timer->time_partitions());
697 } 722 }
698 723
699 class RemoveForwardPointerClosure: public ObjectClosure { 724 class RemoveForwardPointerClosure: public ObjectClosure {
700 public: 725 public:
701 void do_object(oop obj) { 726 void do_object(oop obj) {
703 } 728 }
704 }; 729 };
705 730
706 void DefNewGeneration::init_assuming_no_promotion_failure() { 731 void DefNewGeneration::init_assuming_no_promotion_failure() {
707 _promotion_failed = false; 732 _promotion_failed = false;
733 _promotion_failed_info.reset();
708 from()->set_next_compaction_space(NULL); 734 from()->set_next_compaction_space(NULL);
709 } 735 }
710 736
711 void DefNewGeneration::remove_forwarding_pointers() { 737 void DefNewGeneration::remove_forwarding_pointers() {
712 RemoveForwardPointerClosure rspc; 738 RemoveForwardPointerClosure rspc;
724 _objs_with_preserved_marks.clear(true); 750 _objs_with_preserved_marks.clear(true);
725 _preserved_marks_of_objs.clear(true); 751 _preserved_marks_of_objs.clear(true);
726 } 752 }
727 753
728 void DefNewGeneration::preserve_mark(oop obj, markOop m) { 754 void DefNewGeneration::preserve_mark(oop obj, markOop m) {
729 assert(promotion_failed() && m->must_be_preserved_for_promotion_failure(obj), 755 assert(_promotion_failed && m->must_be_preserved_for_promotion_failure(obj),
730 "Oversaving!"); 756 "Oversaving!");
731 _objs_with_preserved_marks.push(obj); 757 _objs_with_preserved_marks.push(obj);
732 _preserved_marks_of_objs.push(m); 758 _preserved_marks_of_objs.push(m);
733 } 759 }
734 760
742 if (PrintPromotionFailure && !_promotion_failed) { 768 if (PrintPromotionFailure && !_promotion_failed) {
743 gclog_or_tty->print(" (promotion failure size = " SIZE_FORMAT ") ", 769 gclog_or_tty->print(" (promotion failure size = " SIZE_FORMAT ") ",
744 old->size()); 770 old->size());
745 } 771 }
746 _promotion_failed = true; 772 _promotion_failed = true;
773 _promotion_failed_info.register_copy_failure(old->size());
747 preserve_mark_if_necessary(old, old->mark()); 774 preserve_mark_if_necessary(old, old->mark());
748 // forward to self 775 // forward to self
749 old->forward_to(old); 776 old->forward_to(old);
750 777
751 _promo_failure_scan_stack.push(old); 778 _promo_failure_scan_stack.push(old);
960 eden()->set_top_for_allocations(); 987 eden()->set_top_for_allocations();
961 to()->set_top_for_allocations(); 988 to()->set_top_for_allocations();
962 from()->set_top_for_allocations(); 989 from()->set_top_for_allocations();
963 } 990 }
964 991
992 void DefNewGeneration::ref_processor_init() {
993 Generation::ref_processor_init();
994 }
995
965 996
966 void DefNewGeneration::update_counters() { 997 void DefNewGeneration::update_counters() {
967 if (UsePerfData) { 998 if (UsePerfData) {
968 _eden_counters->update_all(); 999 _eden_counters->update_all();
969 _from_counters->update_all(); 1000 _from_counters->update_all();