g1RemSetSummary.cpp 13.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
/*
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 *
 */

#include "precompiled.hpp"
#include "gc_implementation/g1/concurrentG1Refine.hpp"
#include "gc_implementation/g1/concurrentG1RefineThread.hpp"
#include "gc_implementation/g1/heapRegion.hpp"
#include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
#include "gc_implementation/g1/g1RemSet.inline.hpp"
#include "gc_implementation/g1/g1RemSetSummary.hpp"
#include "gc_implementation/g1/heapRegionRemSet.hpp"
#include "runtime/thread.inline.hpp"

class GetRSThreadVTimeClosure : public ThreadClosure {
private:
  G1RemSetSummary* _summary;
  uint _counter;

public:
  GetRSThreadVTimeClosure(G1RemSetSummary * summary) : ThreadClosure(), _summary(summary), _counter(0) {
    assert(_summary != NULL, "just checking");
  }

  virtual void do_thread(Thread* t) {
    ConcurrentG1RefineThread* crt = (ConcurrentG1RefineThread*) t;
    _summary->set_rs_thread_vtime(_counter, crt->vtime_accum());
    _counter++;
  }
};

void G1RemSetSummary::update() {
  _num_refined_cards = remset()->conc_refine_cards();
  DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
  _num_processed_buf_mutator = dcqs.processed_buffers_mut();
  _num_processed_buf_rs_threads = dcqs.processed_buffers_rs_thread();

  _num_coarsenings = HeapRegionRemSet::n_coarsenings();

  ConcurrentG1Refine * cg1r = G1CollectedHeap::heap()->concurrent_g1_refine();
  if (_rs_threads_vtimes != NULL) {
    GetRSThreadVTimeClosure p(this);
    cg1r->worker_threads_do(&p);
  }
  set_sampling_thread_vtime(cg1r->sampling_thread()->vtime_accum());
}

void G1RemSetSummary::set_rs_thread_vtime(uint thread, double value) {
  assert(_rs_threads_vtimes != NULL, "just checking");
  assert(thread < _num_vtimes, "just checking");
  _rs_threads_vtimes[thread] = value;
}

double G1RemSetSummary::rs_thread_vtime(uint thread) const {
  assert(_rs_threads_vtimes != NULL, "just checking");
  assert(thread < _num_vtimes, "just checking");
  return _rs_threads_vtimes[thread];
}

80
void G1RemSetSummary::initialize(G1RemSet* remset) {
81 82 83 84
  assert(_rs_threads_vtimes == NULL, "just checking");
  assert(remset != NULL, "just checking");

  _remset = remset;
85
  _num_vtimes = ConcurrentG1Refine::thread_num();
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
  _rs_threads_vtimes = NEW_C_HEAP_ARRAY(double, _num_vtimes, mtGC);
  memset(_rs_threads_vtimes, 0, sizeof(double) * _num_vtimes);

  update();
}

void G1RemSetSummary::set(G1RemSetSummary* other) {
  assert(other != NULL, "just checking");
  assert(remset() == other->remset(), "just checking");
  assert(_num_vtimes == other->_num_vtimes, "just checking");

  _num_refined_cards = other->num_concurrent_refined_cards();

  _num_processed_buf_mutator = other->num_processed_buf_mutator();
  _num_processed_buf_rs_threads = other->num_processed_buf_rs_threads();

  _num_coarsenings = other->_num_coarsenings;

  memcpy(_rs_threads_vtimes, other->_rs_threads_vtimes, sizeof(double) * _num_vtimes);

  set_sampling_thread_vtime(other->sampling_thread_vtime());
}

void G1RemSetSummary::subtract_from(G1RemSetSummary* other) {
  assert(other != NULL, "just checking");
  assert(remset() == other->remset(), "just checking");
  assert(_num_vtimes == other->_num_vtimes, "just checking");

  _num_refined_cards = other->num_concurrent_refined_cards() - _num_refined_cards;

  _num_processed_buf_mutator = other->num_processed_buf_mutator() - _num_processed_buf_mutator;
  _num_processed_buf_rs_threads = other->num_processed_buf_rs_threads() - _num_processed_buf_rs_threads;

  _num_coarsenings = other->num_coarsenings() - _num_coarsenings;

  for (uint i = 0; i < _num_vtimes; i++) {
    set_rs_thread_vtime(i, other->rs_thread_vtime(i) - rs_thread_vtime(i));
  }

  _sampling_thread_vtime = other->sampling_thread_vtime() - _sampling_thread_vtime;
}

128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
static double percent_of(size_t numerator, size_t denominator) {
  if (denominator != 0) {
    return (double)numerator / denominator * 100.0f;
  } else {
    return 0.0f;
  }
}

static size_t round_to_K(size_t value) {
  return value / K;
}

class RegionTypeCounter VALUE_OBJ_CLASS_SPEC {
private:
  const char* _name;

  size_t _rs_mem_size;
  size_t _cards_occupied;
  size_t _amount;

  size_t _code_root_mem_size;
  size_t _code_root_elems;

  double rs_mem_size_percent_of(size_t total) {
    return percent_of(_rs_mem_size, total);
  }

  double cards_occupied_percent_of(size_t total) {
    return percent_of(_cards_occupied, total);
  }

  double code_root_mem_size_percent_of(size_t total) {
    return percent_of(_code_root_mem_size, total);
  }

  double code_root_elems_percent_of(size_t total) {
    return percent_of(_code_root_elems, total);
  }

  size_t amount() const { return _amount; }

public:

  RegionTypeCounter(const char* name) : _name(name), _rs_mem_size(0), _cards_occupied(0),
    _amount(0), _code_root_mem_size(0), _code_root_elems(0) { }

  void add(size_t rs_mem_size, size_t cards_occupied, size_t code_root_mem_size,
    size_t code_root_elems) {
    _rs_mem_size += rs_mem_size;
    _cards_occupied += cards_occupied;
    _code_root_mem_size += code_root_mem_size;
    _code_root_elems += code_root_elems;
    _amount++;
  }

  size_t rs_mem_size() const { return _rs_mem_size; }
  size_t cards_occupied() const { return _cards_occupied; }

  size_t code_root_mem_size() const { return _code_root_mem_size; }
  size_t code_root_elems() const { return _code_root_elems; }

  void print_rs_mem_info_on(outputStream * out, size_t total) {
190 191
    out->print_cr("    "SIZE_FORMAT_W(8)"K (%5.1f%%) by "SIZE_FORMAT" %s regions",
        round_to_K(rs_mem_size()), rs_mem_size_percent_of(total), amount(), _name);
192 193 194
  }

  void print_cards_occupied_info_on(outputStream * out, size_t total) {
195 196
    out->print_cr("     "SIZE_FORMAT_W(8)" (%5.1f%%) entries by "SIZE_FORMAT" %s regions",
        cards_occupied(), cards_occupied_percent_of(total), amount(), _name);
197 198 199
  }

  void print_code_root_mem_info_on(outputStream * out, size_t total) {
200 201
    out->print_cr("    "SIZE_FORMAT_W(8)"K (%5.1f%%) by "SIZE_FORMAT" %s regions",
        round_to_K(code_root_mem_size()), code_root_mem_size_percent_of(total), amount(), _name);
202 203 204
  }

  void print_code_root_elems_info_on(outputStream * out, size_t total) {
205 206
    out->print_cr("     "SIZE_FORMAT_W(8)" (%5.1f%%) elements by "SIZE_FORMAT" %s regions",
        code_root_elems(), code_root_elems_percent_of(total), amount(), _name);
207 208 209 210
  }
};


211
class HRRSStatsIter: public HeapRegionClosure {
212 213 214 215 216 217
private:
  RegionTypeCounter _young;
  RegionTypeCounter _humonguous;
  RegionTypeCounter _free;
  RegionTypeCounter _old;
  RegionTypeCounter _all;
J
johnc 已提交
218 219 220 221

  size_t _max_rs_mem_sz;
  HeapRegion* _max_rs_mem_sz_region;

222 223 224 225 226 227
  size_t total_rs_mem_sz() const            { return _all.rs_mem_size(); }
  size_t total_cards_occupied() const       { return _all.cards_occupied(); }

  size_t max_rs_mem_sz() const              { return _max_rs_mem_sz; }
  HeapRegion* max_rs_mem_sz_region() const  { return _max_rs_mem_sz_region; }

J
johnc 已提交
228 229
  size_t _max_code_root_mem_sz;
  HeapRegion* _max_code_root_mem_sz_region;
230 231 232 233 234 235 236

  size_t total_code_root_mem_sz() const     { return _all.code_root_mem_size(); }
  size_t total_code_root_elems() const      { return _all.code_root_elems(); }

  size_t max_code_root_mem_sz() const       { return _max_code_root_mem_sz; }
  HeapRegion* max_code_root_mem_sz_region() const { return _max_code_root_mem_sz_region; }

237
public:
238 239 240
  HRRSStatsIter() : _all("All"), _young("Young"), _humonguous("Humonguous"),
    _free("Free"), _old("Old"), _max_code_root_mem_sz_region(NULL), _max_rs_mem_sz_region(NULL),
    _max_rs_mem_sz(0), _max_code_root_mem_sz(0)
241 242 243
  {}

  bool doHeapRegion(HeapRegion* r) {
J
johnc 已提交
244 245 246 247 248 249 250 251 252
    HeapRegionRemSet* hrrs = r->rem_set();

    // HeapRegionRemSet::mem_size() includes the
    // size of the strong code roots
    size_t rs_mem_sz = hrrs->mem_size();
    if (rs_mem_sz > _max_rs_mem_sz) {
      _max_rs_mem_sz = rs_mem_sz;
      _max_rs_mem_sz_region = r;
    }
253
    size_t occupied_cards = hrrs->occupied();
J
johnc 已提交
254
    size_t code_root_mem_sz = hrrs->strong_code_roots_mem_size();
255
    if (code_root_mem_sz > max_code_root_mem_sz()) {
256
      _max_code_root_mem_sz = code_root_mem_sz;
J
johnc 已提交
257
      _max_code_root_mem_sz_region = r;
258
    }
259 260 261
    size_t code_root_elems = hrrs->strong_code_roots_list_length();

    RegionTypeCounter* current = NULL;
262 263 264
    if (r->is_free()) {
      current = &_free;
    } else if (r->is_young()) {
265 266 267
      current = &_young;
    } else if (r->isHumongous()) {
      current = &_humonguous;
268
    } else if (r->is_old()) {
269
      current = &_old;
270 271
    } else {
      ShouldNotReachHere();
272 273 274
    }
    current->add(rs_mem_sz, occupied_cards, code_root_mem_sz, code_root_elems);
    _all.add(rs_mem_sz, occupied_cards, code_root_mem_sz, code_root_elems);
J
johnc 已提交
275

276 277 278
    return false;
  }

279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
  void print_summary_on(outputStream* out) {
    RegionTypeCounter* counters[] = { &_young, &_humonguous, &_free, &_old, NULL };

    out->print_cr("\n Current rem set statistics");
    out->print_cr("  Total per region rem sets sizes = "SIZE_FORMAT"K."
                  " Max = "SIZE_FORMAT"K.",
                  round_to_K(total_rs_mem_sz()), round_to_K(max_rs_mem_sz()));
    for (RegionTypeCounter** current = &counters[0]; *current != NULL; current++) {
      (*current)->print_rs_mem_info_on(out, total_rs_mem_sz());
    }

    out->print_cr("   Static structures = "SIZE_FORMAT"K,"
                  " free_lists = "SIZE_FORMAT"K.",
                  round_to_K(HeapRegionRemSet::static_mem_size()),
                  round_to_K(HeapRegionRemSet::fl_mem_size()));

    out->print_cr("    "SIZE_FORMAT" occupied cards represented.",
                  total_cards_occupied());
    for (RegionTypeCounter** current = &counters[0]; *current != NULL; current++) {
      (*current)->print_cards_occupied_info_on(out, total_cards_occupied());
    }

    // Largest sized rem set region statistics
    HeapRegionRemSet* rem_set = max_rs_mem_sz_region()->rem_set();
    out->print_cr("    Region with largest rem set = "HR_FORMAT", "
                  "size = "SIZE_FORMAT "K, occupied = "SIZE_FORMAT"K.",
                  HR_FORMAT_PARAMS(max_rs_mem_sz_region()),
                  round_to_K(rem_set->mem_size()),
                  round_to_K(rem_set->occupied()));

    // Strong code root statistics
    HeapRegionRemSet* max_code_root_rem_set = max_code_root_mem_sz_region()->rem_set();
    out->print_cr("  Total heap region code root sets sizes = "SIZE_FORMAT"K."
                  "  Max = "SIZE_FORMAT"K.",
                  round_to_K(total_code_root_mem_sz()),
                  round_to_K(max_code_root_rem_set->strong_code_roots_mem_size()));
    for (RegionTypeCounter** current = &counters[0]; *current != NULL; current++) {
      (*current)->print_code_root_mem_info_on(out, total_code_root_mem_sz());
    }

    out->print_cr("    "SIZE_FORMAT" code roots represented.",
                  total_code_root_elems());
    for (RegionTypeCounter** current = &counters[0]; *current != NULL; current++) {
      (*current)->print_code_root_elems_info_on(out, total_code_root_elems());
    }

    out->print_cr("    Region with largest amount of code roots = "HR_FORMAT", "
                  "size = "SIZE_FORMAT "K, num_elems = "SIZE_FORMAT".",
                  HR_FORMAT_PARAMS(max_code_root_mem_sz_region()),
                  round_to_K(max_code_root_rem_set->strong_code_roots_mem_size()),
                  round_to_K(max_code_root_rem_set->strong_code_roots_list_length()));
330
  }
331
};
332 333

void G1RemSetSummary::print_on(outputStream* out) {
334 335
  out->print_cr("\n Recent concurrent refinement statistics");
  out->print_cr("  Processed "SIZE_FORMAT" cards",
336
                num_concurrent_refined_cards());
337 338
  out->print_cr("  Of "SIZE_FORMAT" completed buffers:", num_processed_buf_total());
  out->print_cr("     "SIZE_FORMAT_W(8)" (%5.1f%%) by concurrent RS threads.",
339
                num_processed_buf_total(),
340
                percent_of(num_processed_buf_rs_threads(), num_processed_buf_total()));
341
  out->print_cr("     "SIZE_FORMAT_W(8)" (%5.1f%%) by mutator threads.",
342
                num_processed_buf_mutator(),
343
                percent_of(num_processed_buf_mutator(), num_processed_buf_total()));
344
  out->print_cr("  Did "SIZE_FORMAT" coarsenings.", num_coarsenings());
345 346 347 348 349 350 351 352 353 354 355
  out->print_cr("  Concurrent RS threads times (s)");
  out->print("     ");
  for (uint i = 0; i < _num_vtimes; i++) {
    out->print("    %5.2f", rs_thread_vtime(i));
  }
  out->cr();
  out->print_cr("  Concurrent sampling threads times (s)");
  out->print_cr("         %5.2f", sampling_thread_vtime());

  HRRSStatsIter blk;
  G1CollectedHeap::heap()->heap_region_iterate(&blk);
356
  blk.print_summary_on(out);
357
}