< prev index next >

src/share/vm/gc/g1/g1YoungRemSetSamplingThread.cpp

Print this page
rev 10311 : 8151178 Move the collection set out of the G1 collector policy
Reviewed-by:
rev 10312 : imported patch remove-cset-from-name


   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc/g1/g1CollectedHeap.inline.hpp"
  27 #include "gc/g1/g1CollectorPolicy.hpp"

  28 #include "gc/g1/g1YoungRemSetSamplingThread.hpp"
  29 #include "gc/g1/heapRegion.inline.hpp"
  30 #include "gc/g1/heapRegionRemSet.hpp"
  31 #include "gc/g1/suspendibleThreadSet.hpp"
  32 #include "runtime/mutexLocker.hpp"
  33 
  34 void G1YoungRemSetSamplingThread::run() {
  35   initialize_in_thread();
  36   wait_for_universe_init();
  37 
  38   run_service();
  39 
  40   terminate();
  41 }
  42 
  43 void G1YoungRemSetSamplingThread::stop() {
  44   // it is ok to take late safepoints here, if needed
  45   {
  46     MutexLockerEx mu(Terminator_lock);
  47     _should_terminate = true;


  97 }
  98 
  99 void G1YoungRemSetSamplingThread::sample_young_list_rs_lengths() {
 100   SuspendibleThreadSetJoiner sts;
 101   G1CollectedHeap* g1h = G1CollectedHeap::heap();
 102   G1CollectorPolicy* g1p = g1h->g1_policy();
 103   if (g1p->adaptive_young_list_length()) {
 104     int regions_visited = 0;
 105     HeapRegion* hr = g1h->young_list()->first_region();
 106     size_t sampled_rs_lengths = 0;
 107 
 108     while (hr != NULL) {
 109       size_t rs_length = hr->rem_set()->occupied();
 110       sampled_rs_lengths += rs_length;
 111 
 112       // The current region may not yet have been added to the
 113       // incremental collection set (it gets added when it is
 114       // retired as the current allocation region).
 115       if (hr->in_collection_set()) {
 116         // Update the collection set policy information for this region
 117         g1p->update_incremental_cset_info(hr, rs_length);
 118       }
 119 
 120       ++regions_visited;
 121 
 122       // we try to yield every time we visit 10 regions
 123       if (regions_visited == 10) {
 124         if (sts.should_yield()) {
 125           sts.yield();
 126           // A gc may have occurred and our sampling data is stale and further
 127           // traversal of the young list is unsafe
 128           return;
 129         }
 130         regions_visited = 0;
 131       }
 132       hr = hr->get_next_young_region();
 133     }
 134     g1p->revise_young_list_target_length_if_necessary(sampled_rs_lengths);
 135   }
 136 }


   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc/g1/g1CollectedHeap.inline.hpp"
  27 #include "gc/g1/g1CollectorPolicy.hpp"
  28 #include "gc/g1/g1CollectionSet.hpp"
  29 #include "gc/g1/g1YoungRemSetSamplingThread.hpp"
  30 #include "gc/g1/heapRegion.inline.hpp"
  31 #include "gc/g1/heapRegionRemSet.hpp"
  32 #include "gc/g1/suspendibleThreadSet.hpp"
  33 #include "runtime/mutexLocker.hpp"
  34 
  35 void G1YoungRemSetSamplingThread::run() {
  36   initialize_in_thread();
  37   wait_for_universe_init();
  38 
  39   run_service();
  40 
  41   terminate();
  42 }
  43 
  44 void G1YoungRemSetSamplingThread::stop() {
  45   // it is ok to take late safepoints here, if needed
  46   {
  47     MutexLockerEx mu(Terminator_lock);
  48     _should_terminate = true;


  98 }
  99 
 100 void G1YoungRemSetSamplingThread::sample_young_list_rs_lengths() {
 101   SuspendibleThreadSetJoiner sts;
 102   G1CollectedHeap* g1h = G1CollectedHeap::heap();
 103   G1CollectorPolicy* g1p = g1h->g1_policy();
 104   if (g1p->adaptive_young_list_length()) {
 105     int regions_visited = 0;
 106     HeapRegion* hr = g1h->young_list()->first_region();
 107     size_t sampled_rs_lengths = 0;
 108 
 109     while (hr != NULL) {
 110       size_t rs_length = hr->rem_set()->occupied();
 111       sampled_rs_lengths += rs_length;
 112 
 113       // The current region may not yet have been added to the
 114       // incremental collection set (it gets added when it is
 115       // retired as the current allocation region).
 116       if (hr->in_collection_set()) {
 117         // Update the collection set policy information for this region
 118         g1h->collection_set()->update_young_region_prediction(hr, rs_length);
 119       }
 120 
 121       ++regions_visited;
 122 
 123       // we try to yield every time we visit 10 regions
 124       if (regions_visited == 10) {
 125         if (sts.should_yield()) {
 126           sts.yield();
 127           // A gc may have occurred and our sampling data is stale and further
 128           // traversal of the young list is unsafe
 129           return;
 130         }
 131         regions_visited = 0;
 132       }
 133       hr = hr->get_next_young_region();
 134     }
 135     g1p->revise_young_list_target_length_if_necessary(sampled_rs_lengths);
 136   }
 137 }
< prev index next >