src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hs-gc-chunked-growablearray Sdiff src/share/vm/gc_implementation/g1

src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp

Print this page




1876 }
1877 
1878 // Public methods.
1879 
1880 #ifdef _MSC_VER // the use of 'this' below gets a warning, make it go away
1881 #pragma warning( disable:4355 ) // 'this' : used in base member initializer list
1882 #endif // _MSC_VER
1883 
1884 
1885 G1CollectedHeap::G1CollectedHeap(G1CollectorPolicy* policy_) :
1886   SharedHeap(policy_),
1887   _g1_policy(policy_),
1888   _dirty_card_queue_set(false),
1889   _into_cset_dirty_card_queue_set(false),
1890   _is_alive_closure_cm(this),
1891   _is_alive_closure_stw(this),
1892   _ref_processor_cm(NULL),
1893   _ref_processor_stw(NULL),
1894   _process_strong_tasks(new SubTasksDone(G1H_PS_NumElements)),
1895   _bot_shared(NULL),
1896   _objs_with_preserved_marks(NULL), _preserved_marks_of_objs(NULL),
1897   _evac_failure_scan_stack(NULL) ,
1898   _mark_in_progress(false),
1899   _cg1r(NULL), _summary_bytes_used(0),
1900   _g1mm(NULL),
1901   _refine_cte_cl(NULL),
1902   _full_collection(false),
1903   _free_list("Master Free List"),
1904   _secondary_free_list("Secondary Free List"),
1905   _old_set("Old Set"),
1906   _humongous_set("Master Humongous Set"),
1907   _free_regions_coming(false),
1908   _young_list(new YoungList(this)),
1909   _gc_time_stamp(0),
1910   _retained_old_gc_alloc_region(NULL),
1911   _survivor_plab_stats(YoungPLABSize, PLABWeight),
1912   _old_plab_stats(OldPLABSize, PLABWeight),
1913   _expand_heap_after_alloc_failure(true),
1914   _surviving_young_words(NULL),
1915   _old_marking_cycles_started(0),
1916   _old_marking_cycles_completed(0),


4198   assert(check_cset_heap_region_claim_values(HeapRegion::InitialClaimValue), "sanity");
4199 
4200   G1ParRemoveSelfForwardPtrsTask rsfp_task(this);
4201 
4202   if (G1CollectedHeap::use_parallel_gc_threads()) {
4203     set_par_threads();
4204     workers()->run_task(&rsfp_task);
4205     set_par_threads(0);
4206   } else {
4207     rsfp_task.work(0);
4208   }
4209 
4210   assert(check_cset_heap_region_claim_values(HeapRegion::ParEvacFailureClaimValue), "sanity");
4211 
4212   // Reset the claim values in the regions in the collection set.
4213   reset_cset_heap_region_claim_values();
4214 
4215   assert(check_cset_heap_region_claim_values(HeapRegion::InitialClaimValue), "sanity");
4216 
4217   // Now restore saved marks, if any.
4218   if (_objs_with_preserved_marks != NULL) {
4219     assert(_preserved_marks_of_objs != NULL, "Both or none.");
4220     guarantee(_objs_with_preserved_marks->length() ==
4221               _preserved_marks_of_objs->length(), "Both or none.");
4222     for (int i = 0; i < _objs_with_preserved_marks->length(); i++) {
4223       oop obj   = _objs_with_preserved_marks->at(i);
4224       markOop m = _preserved_marks_of_objs->at(i);
4225       obj->set_mark(m);
4226     }
4227 
4228     // Delete the preserved marks growable arrays (allocated on the C heap).
4229     delete _objs_with_preserved_marks;
4230     delete _preserved_marks_of_objs;
4231     _objs_with_preserved_marks = NULL;
4232     _preserved_marks_of_objs = NULL;
4233   }
4234 }
4235 
4236 void G1CollectedHeap::push_on_evac_failure_scan_stack(oop obj) {
4237   _evac_failure_scan_stack->push(obj);
4238 }
4239 
4240 void G1CollectedHeap::drain_evac_failure_scan_stack() {
4241   assert(_evac_failure_scan_stack != NULL, "precondition");
4242 
4243   while (_evac_failure_scan_stack->length() > 0) {
4244      oop obj = _evac_failure_scan_stack->pop();
4245      _evac_failure_closure->set_region(heap_region_containing(obj));
4246      obj->oop_iterate_backwards(_evac_failure_closure);
4247   }
4248 }
4249 
4250 oop
4251 G1CollectedHeap::handle_evacuation_failure_par(OopsInHeapRegionClosure* cl,
4252                                                oop old) {
4253   assert(obj_in_cs(old),


4296   if (!r->evacuation_failed()) {
4297     r->set_evacuation_failed(true);
4298     _hr_printer.evac_failure(r);
4299   }
4300 
4301   push_on_evac_failure_scan_stack(old);
4302 
4303   if (!_drain_in_progress) {
4304     // prevent recursion in copy_to_survivor_space()
4305     _drain_in_progress = true;
4306     drain_evac_failure_scan_stack();
4307     _drain_in_progress = false;
4308   }
4309 }
4310 
4311 void G1CollectedHeap::preserve_mark_if_necessary(oop obj, markOop m) {
4312   assert(evacuation_failed(), "Oversaving!");
4313   // We want to call the "for_promotion_failure" version only in the
4314   // case of a promotion failure.
4315   if (m->must_be_preserved_for_promotion_failure(obj)) {
4316     if (_objs_with_preserved_marks == NULL) {
4317       assert(_preserved_marks_of_objs == NULL, "Both or none.");
4318       _objs_with_preserved_marks =
4319         new (ResourceObj::C_HEAP, mtGC) GrowableArray<oop>(40, true);
4320       _preserved_marks_of_objs =
4321         new (ResourceObj::C_HEAP, mtGC) GrowableArray<markOop>(40, true);
4322     }
4323     _objs_with_preserved_marks->push(obj);
4324     _preserved_marks_of_objs->push(m);
4325   }
4326 }
4327 
4328 HeapWord* G1CollectedHeap::par_allocate_during_gc(GCAllocPurpose purpose,
4329                                                   size_t word_size) {
4330   if (purpose == GCAllocForSurvived) {
4331     HeapWord* result = survivor_attempt_allocation(word_size);
4332     if (result != NULL) {
4333       return result;
4334     } else {
4335       // Let's try to allocate in the old gen in case we can fit the
4336       // object there.
4337       return old_attempt_allocation(word_size);
4338     }
4339   } else {
4340     assert(purpose ==  GCAllocForTenured, "sanity");
4341     HeapWord* result = old_attempt_allocation(word_size);
4342     if (result != NULL) {
4343       return result;
4344     } else {




1876 }
1877 
1878 // Public methods.
1879 
1880 #ifdef _MSC_VER // the use of 'this' below gets a warning, make it go away
1881 #pragma warning( disable:4355 ) // 'this' : used in base member initializer list
1882 #endif // _MSC_VER
1883 
1884 
1885 G1CollectedHeap::G1CollectedHeap(G1CollectorPolicy* policy_) :
1886   SharedHeap(policy_),
1887   _g1_policy(policy_),
1888   _dirty_card_queue_set(false),
1889   _into_cset_dirty_card_queue_set(false),
1890   _is_alive_closure_cm(this),
1891   _is_alive_closure_stw(this),
1892   _ref_processor_cm(NULL),
1893   _ref_processor_stw(NULL),
1894   _process_strong_tasks(new SubTasksDone(G1H_PS_NumElements)),
1895   _bot_shared(NULL),

1896   _evac_failure_scan_stack(NULL) ,
1897   _mark_in_progress(false),
1898   _cg1r(NULL), _summary_bytes_used(0),
1899   _g1mm(NULL),
1900   _refine_cte_cl(NULL),
1901   _full_collection(false),
1902   _free_list("Master Free List"),
1903   _secondary_free_list("Secondary Free List"),
1904   _old_set("Old Set"),
1905   _humongous_set("Master Humongous Set"),
1906   _free_regions_coming(false),
1907   _young_list(new YoungList(this)),
1908   _gc_time_stamp(0),
1909   _retained_old_gc_alloc_region(NULL),
1910   _survivor_plab_stats(YoungPLABSize, PLABWeight),
1911   _old_plab_stats(OldPLABSize, PLABWeight),
1912   _expand_heap_after_alloc_failure(true),
1913   _surviving_young_words(NULL),
1914   _old_marking_cycles_started(0),
1915   _old_marking_cycles_completed(0),


4197   assert(check_cset_heap_region_claim_values(HeapRegion::InitialClaimValue), "sanity");
4198 
4199   G1ParRemoveSelfForwardPtrsTask rsfp_task(this);
4200 
4201   if (G1CollectedHeap::use_parallel_gc_threads()) {
4202     set_par_threads();
4203     workers()->run_task(&rsfp_task);
4204     set_par_threads(0);
4205   } else {
4206     rsfp_task.work(0);
4207   }
4208 
4209   assert(check_cset_heap_region_claim_values(HeapRegion::ParEvacFailureClaimValue), "sanity");
4210 
4211   // Reset the claim values in the regions in the collection set.
4212   reset_cset_heap_region_claim_values();
4213 
4214   assert(check_cset_heap_region_claim_values(HeapRegion::InitialClaimValue), "sanity");
4215 
4216   // Now restore saved marks, if any.
4217   guarantee(_objs_with_preserved_marks.size() ==
4218             _preserved_marks_of_objs.size(), "Both or none.");
4219   while (!_objs_with_preserved_marks.is_empty()) {
4220     oop obj = _objs_with_preserved_marks.pop();
4221     markOop m = _preserved_marks_of_objs.pop();


4222     obj->set_mark(m);
4223   }
4224   _objs_with_preserved_marks.clear(true);
4225   _preserved_marks_of_objs.clear(true);





4226 }
4227 
4228 void G1CollectedHeap::push_on_evac_failure_scan_stack(oop obj) {
4229   _evac_failure_scan_stack->push(obj);
4230 }
4231 
4232 void G1CollectedHeap::drain_evac_failure_scan_stack() {
4233   assert(_evac_failure_scan_stack != NULL, "precondition");
4234 
4235   while (_evac_failure_scan_stack->length() > 0) {
4236      oop obj = _evac_failure_scan_stack->pop();
4237      _evac_failure_closure->set_region(heap_region_containing(obj));
4238      obj->oop_iterate_backwards(_evac_failure_closure);
4239   }
4240 }
4241 
4242 oop
4243 G1CollectedHeap::handle_evacuation_failure_par(OopsInHeapRegionClosure* cl,
4244                                                oop old) {
4245   assert(obj_in_cs(old),


4288   if (!r->evacuation_failed()) {
4289     r->set_evacuation_failed(true);
4290     _hr_printer.evac_failure(r);
4291   }
4292 
4293   push_on_evac_failure_scan_stack(old);
4294 
4295   if (!_drain_in_progress) {
4296     // prevent recursion in copy_to_survivor_space()
4297     _drain_in_progress = true;
4298     drain_evac_failure_scan_stack();
4299     _drain_in_progress = false;
4300   }
4301 }
4302 
4303 void G1CollectedHeap::preserve_mark_if_necessary(oop obj, markOop m) {
4304   assert(evacuation_failed(), "Oversaving!");
4305   // We want to call the "for_promotion_failure" version only in the
4306   // case of a promotion failure.
4307   if (m->must_be_preserved_for_promotion_failure(obj)) {
4308     _objs_with_preserved_marks.push(obj);
4309     _preserved_marks_of_objs.push(m);







4310   }
4311 }
4312 
4313 HeapWord* G1CollectedHeap::par_allocate_during_gc(GCAllocPurpose purpose,
4314                                                   size_t word_size) {
4315   if (purpose == GCAllocForSurvived) {
4316     HeapWord* result = survivor_attempt_allocation(word_size);
4317     if (result != NULL) {
4318       return result;
4319     } else {
4320       // Let's try to allocate in the old gen in case we can fit the
4321       // object there.
4322       return old_attempt_allocation(word_size);
4323     }
4324   } else {
4325     assert(purpose ==  GCAllocForTenured, "sanity");
4326     HeapWord* result = old_attempt_allocation(word_size);
4327     if (result != NULL) {
4328       return result;
4329     } else {


src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File