hotspot/src/share/vm/gc_implementation/g1/g1MarkSweep.cpp
changeset 7923 fc200fcd4e05
parent 7397 5b173b4ca846
child 7924 6cbca8cebf93
equal deleted inserted replaced
7922:e97540c35e38 7923:fc200fcd4e05
     1 /*
     1 /*
     2  * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2001, 2011, 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.
   178   assert(GenMarkSweep::_marking_stack.is_empty(),
   178   assert(GenMarkSweep::_marking_stack.is_empty(),
   179          "stack should be empty by now");
   179          "stack should be empty by now");
   180 }
   180 }
   181 
   181 
   182 class G1PrepareCompactClosure: public HeapRegionClosure {
   182 class G1PrepareCompactClosure: public HeapRegionClosure {
       
   183   G1CollectedHeap* _g1h;
   183   ModRefBarrierSet* _mrbs;
   184   ModRefBarrierSet* _mrbs;
   184   CompactPoint _cp;
   185   CompactPoint _cp;
       
   186   size_t _pre_used;
       
   187   FreeRegionList _free_list;
       
   188   HumongousRegionSet _humongous_proxy_set;
   185 
   189 
   186   void free_humongous_region(HeapRegion* hr) {
   190   void free_humongous_region(HeapRegion* hr) {
   187     HeapWord* bot = hr->bottom();
       
   188     HeapWord* end = hr->end();
   191     HeapWord* end = hr->end();
   189     assert(hr->startsHumongous(),
   192     assert(hr->startsHumongous(),
   190            "Only the start of a humongous region should be freed.");
   193            "Only the start of a humongous region should be freed.");
   191     G1CollectedHeap::heap()->free_region(hr);
   194     _g1h->free_humongous_region(hr, &_pre_used, &_free_list,
       
   195                                 &_humongous_proxy_set, false /* par */);
       
   196     // Do we also need to do this for the continues humongous regions
       
   197     // we just collapsed?
   192     hr->prepare_for_compaction(&_cp);
   198     hr->prepare_for_compaction(&_cp);
   193     // Also clear the part of the card table that will be unused after
   199     // Also clear the part of the card table that will be unused after
   194     // compaction.
   200     // compaction.
   195     _mrbs->clear(MemRegion(hr->compaction_top(), hr->end()));
   201     _mrbs->clear(MemRegion(hr->compaction_top(), end));
   196   }
   202   }
   197 
   203 
   198 public:
   204 public:
   199   G1PrepareCompactClosure(CompactibleSpace* cs) :
   205   G1PrepareCompactClosure(CompactibleSpace* cs)
       
   206   : _g1h(G1CollectedHeap::heap()),
       
   207     _mrbs(G1CollectedHeap::heap()->mr_bs()),
   200     _cp(NULL, cs, cs->initialize_threshold()),
   208     _cp(NULL, cs, cs->initialize_threshold()),
   201     _mrbs(G1CollectedHeap::heap()->mr_bs())
   209     _pre_used(0),
   202   {}
   210     _free_list("Local Free List for G1MarkSweep"),
       
   211     _humongous_proxy_set("G1MarkSweep Humongous Proxy Set") { }
       
   212 
       
   213   void update_sets() {
       
   214     // We'll recalculate total used bytes and recreate the free list
       
   215     // at the end of the GC, so no point in updating those values here.
       
   216     _g1h->update_sets_after_freeing_regions(0, /* pre_used */
       
   217                                             NULL, /* free_list */
       
   218                                             &_humongous_proxy_set,
       
   219                                             false /* par */);
       
   220     _free_list.remove_all();
       
   221   }
       
   222 
   203   bool doHeapRegion(HeapRegion* hr) {
   223   bool doHeapRegion(HeapRegion* hr) {
   204     if (hr->isHumongous()) {
   224     if (hr->isHumongous()) {
   205       if (hr->startsHumongous()) {
   225       if (hr->startsHumongous()) {
   206         oop obj = oop(hr->bottom());
   226         oop obj = oop(hr->bottom());
   207         if (obj->is_gc_marked()) {
   227         if (obj->is_gc_marked()) {
   263     sp = r->next_compaction_space();
   283     sp = r->next_compaction_space();
   264   }
   284   }
   265 
   285 
   266   G1PrepareCompactClosure blk(sp);
   286   G1PrepareCompactClosure blk(sp);
   267   g1h->heap_region_iterate(&blk);
   287   g1h->heap_region_iterate(&blk);
       
   288   blk.update_sets();
   268 
   289 
   269   CompactPoint perm_cp(pg, NULL, NULL);
   290   CompactPoint perm_cp(pg, NULL, NULL);
   270   pg->prepare_for_compaction(&perm_cp);
   291   pg->prepare_for_compaction(&perm_cp);
   271 }
   292 }
   272 
   293