550 551 void DefNewGeneration::adjust_desired_tenuring_threshold() { 552 // Set the desired survivor size to half the real survivor space 553 _tenuring_threshold = 554 age_table()->compute_tenuring_threshold(to()->capacity()/HeapWordSize); 555 } 556 557 void DefNewGeneration::collect(bool full, 558 bool clear_all_soft_refs, 559 size_t size, 560 bool is_tlab) { 561 assert(full || size > 0, "otherwise we don't want to collect"); 562 563 GenCollectedHeap* gch = GenCollectedHeap::heap(); 564 565 _gc_timer->register_gc_start(os::elapsed_counter()); 566 DefNewTracer gc_tracer; 567 gc_tracer.report_gc_start(gch->gc_cause(), _gc_timer->gc_start()); 568 569 _next_gen = gch->next_gen(this); 570 assert(_next_gen != NULL, 571 "This must be the youngest gen, and not the only gen"); 572 573 // If the next generation is too full to accommodate promotion 574 // from this generation, pass on collection; let the next generation 575 // do it. 576 if (!collection_attempt_is_safe()) { 577 if (Verbose && PrintGCDetails) { 578 gclog_or_tty->print(" :: Collection attempt not safe :: "); 579 } 580 gch->set_incremental_collection_failed(); // Slight lie: we did not even attempt one 581 return; 582 } 583 assert(to()->is_empty(), "Else not collection_attempt_is_safe"); 584 585 init_assuming_no_promotion_failure(); 586 587 GCTraceTime t1(GCCauseString("GC", gch->gc_cause()), PrintGC && !PrintGCDetails, true, NULL); 588 // Capture heap used before collection (for printing). 589 size_t gch_prev_used = gch->used(); 590 591 gch->trace_heap_before_gc(&gc_tracer); 884 885 void DefNewGeneration::reset_scratch() { 886 // If contributing scratch in to_space, mangle all of 887 // to_space if ZapUnusedHeapArea. This is needed because 888 // top is not maintained while using to-space as scratch. 889 if (ZapUnusedHeapArea) { 890 to()->mangle_unused_area_complete(); 891 } 892 } 893 894 bool DefNewGeneration::collection_attempt_is_safe() { 895 if (!to()->is_empty()) { 896 if (Verbose && PrintGCDetails) { 897 gclog_or_tty->print(" :: to is not empty :: "); 898 } 899 return false; 900 } 901 if (_next_gen == NULL) { 902 GenCollectedHeap* gch = GenCollectedHeap::heap(); 903 _next_gen = gch->next_gen(this); 904 assert(_next_gen != NULL, 905 "This must be the youngest gen, and not the only gen"); 906 } 907 return _next_gen->promotion_attempt_is_safe(used()); 908 } 909 910 void DefNewGeneration::gc_epilogue(bool full) { 911 DEBUG_ONLY(static bool seen_incremental_collection_failed = false;) 912 913 assert(!GC_locker::is_active(), "We should not be executing here"); 914 // Check if the heap is approaching full after a collection has 915 // been done. Generally the young generation is empty at 916 // a minimum at the end of a collection. If it is not, then 917 // the heap is approaching full. 918 GenCollectedHeap* gch = GenCollectedHeap::heap(); 919 if (full) { 920 DEBUG_ONLY(seen_incremental_collection_failed = false;) 921 if (!collection_attempt_is_safe() && !_eden_space->is_empty()) { 922 if (Verbose && PrintGCDetails) { 923 gclog_or_tty->print("DefNewEpilogue: cause(%s), full, not safe, set_failed, set_alloc_from, clear_seen", 924 GCCause::to_string(gch->gc_cause())); 925 } | 550 551 void DefNewGeneration::adjust_desired_tenuring_threshold() { 552 // Set the desired survivor size to half the real survivor space 553 _tenuring_threshold = 554 age_table()->compute_tenuring_threshold(to()->capacity()/HeapWordSize); 555 } 556 557 void DefNewGeneration::collect(bool full, 558 bool clear_all_soft_refs, 559 size_t size, 560 bool is_tlab) { 561 assert(full || size > 0, "otherwise we don't want to collect"); 562 563 GenCollectedHeap* gch = GenCollectedHeap::heap(); 564 565 _gc_timer->register_gc_start(os::elapsed_counter()); 566 DefNewTracer gc_tracer; 567 gc_tracer.report_gc_start(gch->gc_cause(), _gc_timer->gc_start()); 568 569 _next_gen = gch->next_gen(this); 570 571 // If the next generation is too full to accommodate promotion 572 // from this generation, pass on collection; let the next generation 573 // do it. 574 if (!collection_attempt_is_safe()) { 575 if (Verbose && PrintGCDetails) { 576 gclog_or_tty->print(" :: Collection attempt not safe :: "); 577 } 578 gch->set_incremental_collection_failed(); // Slight lie: we did not even attempt one 579 return; 580 } 581 assert(to()->is_empty(), "Else not collection_attempt_is_safe"); 582 583 init_assuming_no_promotion_failure(); 584 585 GCTraceTime t1(GCCauseString("GC", gch->gc_cause()), PrintGC && !PrintGCDetails, true, NULL); 586 // Capture heap used before collection (for printing). 587 size_t gch_prev_used = gch->used(); 588 589 gch->trace_heap_before_gc(&gc_tracer); 882 883 void DefNewGeneration::reset_scratch() { 884 // If contributing scratch in to_space, mangle all of 885 // to_space if ZapUnusedHeapArea. This is needed because 886 // top is not maintained while using to-space as scratch. 887 if (ZapUnusedHeapArea) { 888 to()->mangle_unused_area_complete(); 889 } 890 } 891 892 bool DefNewGeneration::collection_attempt_is_safe() { 893 if (!to()->is_empty()) { 894 if (Verbose && PrintGCDetails) { 895 gclog_or_tty->print(" :: to is not empty :: "); 896 } 897 return false; 898 } 899 if (_next_gen == NULL) { 900 GenCollectedHeap* gch = GenCollectedHeap::heap(); 901 _next_gen = gch->next_gen(this); 902 } 903 return _next_gen->promotion_attempt_is_safe(used()); 904 } 905 906 void DefNewGeneration::gc_epilogue(bool full) { 907 DEBUG_ONLY(static bool seen_incremental_collection_failed = false;) 908 909 assert(!GC_locker::is_active(), "We should not be executing here"); 910 // Check if the heap is approaching full after a collection has 911 // been done. Generally the young generation is empty at 912 // a minimum at the end of a collection. If it is not, then 913 // the heap is approaching full. 914 GenCollectedHeap* gch = GenCollectedHeap::heap(); 915 if (full) { 916 DEBUG_ONLY(seen_incremental_collection_failed = false;) 917 if (!collection_attempt_is_safe() && !_eden_space->is_empty()) { 918 if (Verbose && PrintGCDetails) { 919 gclog_or_tty->print("DefNewEpilogue: cause(%s), full, not safe, set_failed, set_alloc_from, clear_seen", 920 GCCause::to_string(gch->gc_cause())); 921 } |