hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp
changeset 37137 62fd3fb4b1b1
parent 37125 188d715655a3
child 37142 5389598424cc
equal deleted inserted replaced
37134:9dd3975ca940 37137:62fd3fb4b1b1
  1767   _survivor_evac_stats("Young", YoungPLABSize, PLABWeight),
  1767   _survivor_evac_stats("Young", YoungPLABSize, PLABWeight),
  1768   _old_evac_stats("Old", OldPLABSize, PLABWeight),
  1768   _old_evac_stats("Old", OldPLABSize, PLABWeight),
  1769   _expand_heap_after_alloc_failure(true),
  1769   _expand_heap_after_alloc_failure(true),
  1770   _old_marking_cycles_started(0),
  1770   _old_marking_cycles_started(0),
  1771   _old_marking_cycles_completed(0),
  1771   _old_marking_cycles_completed(0),
  1772   _heap_summary_sent(false),
       
  1773   _in_cset_fast_test(),
  1772   _in_cset_fast_test(),
  1774   _dirty_cards_region_list(NULL),
  1773   _dirty_cards_region_list(NULL),
  1775   _worker_cset_start_region(NULL),
  1774   _worker_cset_start_region(NULL),
  1776   _worker_cset_start_region_time_stamp(NULL),
  1775   _worker_cset_start_region_time_stamp(NULL),
  1777   _gc_timer_stw(new (ResourceObj::C_HEAP, mtGC) STWGCTimer()),
  1776   _gc_timer_stw(new (ResourceObj::C_HEAP, mtGC) STWGCTimer()),
  1778   _gc_timer_cm(new (ResourceObj::C_HEAP, mtGC) ConcurrentGCTimer()),
  1777   _gc_tracer_stw(new (ResourceObj::C_HEAP, mtGC) G1NewTracer()) {
  1779   _gc_tracer_stw(new (ResourceObj::C_HEAP, mtGC) G1NewTracer()),
       
  1780   _gc_tracer_cm(new (ResourceObj::C_HEAP, mtGC) G1OldTracer()) {
       
  1781 
  1778 
  1782   _workers = new WorkGang("GC Thread", ParallelGCThreads,
  1779   _workers = new WorkGang("GC Thread", ParallelGCThreads,
  1783                           /* are_GC_task_threads */true,
  1780                           /* are_GC_task_threads */true,
  1784                           /* are_ConcurrentGC_threads */false);
  1781                           /* are_ConcurrentGC_threads */false);
  1785   _workers->initialize_workers();
  1782   _workers->initialize_workers();
  2316   // and it's waiting for a full GC to finish will be woken up. It is
  2313   // and it's waiting for a full GC to finish will be woken up. It is
  2317   // waiting in VM_G1IncCollectionPause::doit_epilogue().
  2314   // waiting in VM_G1IncCollectionPause::doit_epilogue().
  2318   FullGCCount_lock->notify_all();
  2315   FullGCCount_lock->notify_all();
  2319 }
  2316 }
  2320 
  2317 
  2321 void G1CollectedHeap::register_concurrent_cycle_start(const Ticks& start_time) {
       
  2322   GCIdMarkAndRestore conc_gc_id_mark;
       
  2323   collector_state()->set_concurrent_cycle_started(true);
       
  2324   _gc_timer_cm->register_gc_start(start_time);
       
  2325 
       
  2326   _gc_tracer_cm->report_gc_start(gc_cause(), _gc_timer_cm->gc_start());
       
  2327   trace_heap_before_gc(_gc_tracer_cm);
       
  2328   _cmThread->set_gc_id(GCId::current());
       
  2329 }
       
  2330 
       
  2331 void G1CollectedHeap::register_concurrent_cycle_end() {
       
  2332   if (collector_state()->concurrent_cycle_started()) {
       
  2333     GCIdMarkAndRestore conc_gc_id_mark(_cmThread->gc_id());
       
  2334     if (_cm->has_aborted()) {
       
  2335       _gc_tracer_cm->report_concurrent_mode_failure();
       
  2336 
       
  2337       // ConcurrentGCTimer will be ended as well.
       
  2338       _cm->register_concurrent_gc_end_and_stop_timer();
       
  2339     } else {
       
  2340       _gc_timer_cm->register_gc_end();
       
  2341     }
       
  2342 
       
  2343     _gc_tracer_cm->report_gc_end(_gc_timer_cm->gc_end(), _gc_timer_cm->time_partitions());
       
  2344 
       
  2345     // Clear state variables to prepare for the next concurrent cycle.
       
  2346     collector_state()->set_concurrent_cycle_started(false);
       
  2347     _heap_summary_sent = false;
       
  2348   }
       
  2349 }
       
  2350 
       
  2351 void G1CollectedHeap::trace_heap_after_concurrent_cycle() {
       
  2352   if (collector_state()->concurrent_cycle_started()) {
       
  2353     // This function can be called when:
       
  2354     //  the cleanup pause is run
       
  2355     //  the concurrent cycle is aborted before the cleanup pause.
       
  2356     //  the concurrent cycle is aborted after the cleanup pause,
       
  2357     //   but before the concurrent cycle end has been registered.
       
  2358     // Make sure that we only send the heap information once.
       
  2359     if (!_heap_summary_sent) {
       
  2360       GCIdMarkAndRestore conc_gc_id_mark(_cmThread->gc_id());
       
  2361       trace_heap_after_gc(_gc_tracer_cm);
       
  2362       _heap_summary_sent = true;
       
  2363     }
       
  2364   }
       
  2365 }
       
  2366 
       
  2367 void G1CollectedHeap::collect(GCCause::Cause cause) {
  2318 void G1CollectedHeap::collect(GCCause::Cause cause) {
  2368   assert_heap_not_locked();
  2319   assert_heap_not_locked();
  2369 
  2320 
  2370   uint gc_count_before;
  2321   uint gc_count_before;
  2371   uint old_marking_count_before;
  2322   uint old_marking_count_before;
  2852 G1HeapSummary G1CollectedHeap::create_g1_heap_summary() {
  2803 G1HeapSummary G1CollectedHeap::create_g1_heap_summary() {
  2853   YoungList* young_list = heap()->young_list();
  2804   YoungList* young_list = heap()->young_list();
  2854 
  2805 
  2855   size_t eden_used_bytes = young_list->eden_used_bytes();
  2806   size_t eden_used_bytes = young_list->eden_used_bytes();
  2856   size_t survivor_used_bytes = young_list->survivor_used_bytes();
  2807   size_t survivor_used_bytes = young_list->survivor_used_bytes();
       
  2808   size_t heap_used = Heap_lock->owned_by_self() ? used() : used_unlocked();
  2857 
  2809 
  2858   size_t eden_capacity_bytes =
  2810   size_t eden_capacity_bytes =
  2859     (g1_policy()->young_list_target_length() * HeapRegion::GrainBytes) - survivor_used_bytes;
  2811     (g1_policy()->young_list_target_length() * HeapRegion::GrainBytes) - survivor_used_bytes;
  2860 
  2812 
  2861   VirtualSpaceSummary heap_summary = create_heap_space_summary();
  2813   VirtualSpaceSummary heap_summary = create_heap_space_summary();
  2862   return G1HeapSummary(heap_summary, used(), eden_used_bytes, eden_capacity_bytes, survivor_used_bytes, num_regions());
  2814   return G1HeapSummary(heap_summary, heap_used, eden_used_bytes,
       
  2815                        eden_capacity_bytes, survivor_used_bytes, num_regions());
  2863 }
  2816 }
  2864 
  2817 
  2865 G1EvacSummary G1CollectedHeap::create_g1_evac_summary(G1EvacStats* stats) {
  2818 G1EvacSummary G1CollectedHeap::create_g1_evac_summary(G1EvacStats* stats) {
  2866   return G1EvacSummary(stats->allocated(), stats->wasted(), stats->undo_wasted(),
  2819   return G1EvacSummary(stats->allocated(), stats->wasted(), stats->undo_wasted(),
  2867                        stats->unused(), stats->used(), stats->region_end_waste(),
  2820                        stats->unused(), stats->used(), stats->region_end_waste(),
  2874   gc_tracer->report_gc_heap_summary(when, heap_summary);
  2827   gc_tracer->report_gc_heap_summary(when, heap_summary);
  2875 
  2828 
  2876   const MetaspaceSummary& metaspace_summary = create_metaspace_summary();
  2829   const MetaspaceSummary& metaspace_summary = create_metaspace_summary();
  2877   gc_tracer->report_metaspace_summary(when, metaspace_summary);
  2830   gc_tracer->report_metaspace_summary(when, metaspace_summary);
  2878 }
  2831 }
  2879 
       
  2880 
  2832 
  2881 G1CollectedHeap* G1CollectedHeap::heap() {
  2833 G1CollectedHeap* G1CollectedHeap::heap() {
  2882   CollectedHeap* heap = Universe::heap();
  2834   CollectedHeap* heap = Universe::heap();
  2883   assert(heap != NULL, "Uninitialized access to G1CollectedHeap::heap()");
  2835   assert(heap != NULL, "Uninitialized access to G1CollectedHeap::heap()");
  2884   assert(heap->kind() == CollectedHeap::G1CollectedHeap, "Not a G1CollectedHeap");
  2836   assert(heap->kind() == CollectedHeap::G1CollectedHeap, "Not a G1CollectedHeap");
  3248 
  3200 
  3249     if (collector_state()->during_initial_mark_pause()) {
  3201     if (collector_state()->during_initial_mark_pause()) {
  3250       // We are about to start a marking cycle, so we increment the
  3202       // We are about to start a marking cycle, so we increment the
  3251       // full collection counter.
  3203       // full collection counter.
  3252       increment_old_marking_cycles_started();
  3204       increment_old_marking_cycles_started();
  3253       register_concurrent_cycle_start(_gc_timer_stw->gc_start());
  3205       _cm->gc_tracer_cm()->set_gc_cause(gc_cause());
  3254     }
  3206     }
  3255 
  3207 
  3256     _gc_tracer_stw->report_yc_type(collector_state()->yc_type());
  3208     _gc_tracer_stw->report_yc_type(collector_state()->yc_type());
  3257 
  3209 
  3258     GCTraceCPUTime tcpu;
  3210     GCTraceCPUTime tcpu;