src/hotspot/share/gc/g1/g1HeapTransition.cpp
author mgronlun
Sat, 14 Sep 2019 13:03:44 +0200
branchJEP-349-branch
changeset 58154 060d9d139109
parent 55576 4d193e40e7af
child 59062 6530de931b8e
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35909
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
     1
/*
53985
0da5c17f5e43 8219747: Remove g1_ prefix to g1_remset and g1_policy members in G1CollectedHeap
tschatzl
parents: 52975
diff changeset
     2
 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
35909
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
     4
 *
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
     7
 * published by the Free Software Foundation.
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
     8
 *
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    13
 * accompanied this code).
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    14
 *
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    18
 *
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    21
 * questions.
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    22
 *
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    23
 */
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    24
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    25
#include "precompiled.hpp"
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    26
#include "gc/g1/g1CollectedHeap.hpp"
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    27
#include "gc/g1/g1HeapTransition.hpp"
37985
539c597ee0fa 8154154: Separate G1 specific policy code from the CollectorPolicy class hierarchy
mgerdin
parents: 37099
diff changeset
    28
#include "gc/g1/g1Policy.hpp"
35909
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    29
#include "logging/log.hpp"
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    30
#include "memory/metaspace.hpp"
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    31
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    32
G1HeapTransition::Data::Data(G1CollectedHeap* g1_heap) {
38183
cb68e4923223 8150721: Don't explicitly manage G1 young regions in YoungList
mgerdin
parents: 37985
diff changeset
    33
  _eden_length = g1_heap->eden_regions_count();
cb68e4923223 8150721: Don't explicitly manage G1 young regions in YoungList
mgerdin
parents: 37985
diff changeset
    34
  _survivor_length = g1_heap->survivor_regions_count();
35909
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    35
  _old_length = g1_heap->old_regions_count();
51494
1906adbef2dc 8208498: Put archive regions into a first-class HeapRegionSet
tschatzl
parents: 49389
diff changeset
    36
  _archive_length = g1_heap->archive_regions_count();
35909
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    37
  _humongous_length = g1_heap->humongous_regions_count();
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    38
}
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    39
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    40
G1HeapTransition::G1HeapTransition(G1CollectedHeap* g1_heap) : _g1_heap(g1_heap), _before(g1_heap) { }
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    41
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    42
struct DetailedUsage : public StackObj {
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    43
  size_t _eden_used;
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    44
  size_t _survivor_used;
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    45
  size_t _old_used;
51494
1906adbef2dc 8208498: Put archive regions into a first-class HeapRegionSet
tschatzl
parents: 49389
diff changeset
    46
  size_t _archive_used;
35909
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    47
  size_t _humongous_used;
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    48
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    49
  size_t _eden_region_count;
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    50
  size_t _survivor_region_count;
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    51
  size_t _old_region_count;
51494
1906adbef2dc 8208498: Put archive regions into a first-class HeapRegionSet
tschatzl
parents: 49389
diff changeset
    52
  size_t _archive_region_count;
35909
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    53
  size_t _humongous_region_count;
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    54
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    55
  DetailedUsage() :
51494
1906adbef2dc 8208498: Put archive regions into a first-class HeapRegionSet
tschatzl
parents: 49389
diff changeset
    56
    _eden_used(0), _survivor_used(0), _old_used(0), _archive_used(0), _humongous_used(0),
1906adbef2dc 8208498: Put archive regions into a first-class HeapRegionSet
tschatzl
parents: 49389
diff changeset
    57
    _eden_region_count(0), _survivor_region_count(0), _old_region_count(0),
1906adbef2dc 8208498: Put archive regions into a first-class HeapRegionSet
tschatzl
parents: 49389
diff changeset
    58
    _archive_region_count(0), _humongous_region_count(0) {}
35909
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    59
};
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    60
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    61
class DetailedUsageClosure: public HeapRegionClosure {
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    62
public:
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    63
  DetailedUsage _usage;
48969
jwilhelm
parents: 48890
diff changeset
    64
  bool do_heap_region(HeapRegion* r) {
35909
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    65
    if (r->is_old()) {
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    66
      _usage._old_used += r->used();
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    67
      _usage._old_region_count++;
51494
1906adbef2dc 8208498: Put archive regions into a first-class HeapRegionSet
tschatzl
parents: 49389
diff changeset
    68
    } else if (r->is_archive()) {
1906adbef2dc 8208498: Put archive regions into a first-class HeapRegionSet
tschatzl
parents: 49389
diff changeset
    69
      _usage._archive_used += r->used();
1906adbef2dc 8208498: Put archive regions into a first-class HeapRegionSet
tschatzl
parents: 49389
diff changeset
    70
      _usage._archive_region_count++;
35909
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    71
    } else if (r->is_survivor()) {
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    72
      _usage._survivor_used += r->used();
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    73
      _usage._survivor_region_count++;
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    74
    } else if (r->is_eden()) {
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    75
      _usage._eden_used += r->used();
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    76
      _usage._eden_region_count++;
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    77
    } else if (r->is_humongous()) {
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    78
      _usage._humongous_used += r->used();
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    79
      _usage._humongous_region_count++;
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    80
    } else {
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    81
      assert(r->used() == 0, "Expected used to be 0 but it was " SIZE_FORMAT, r->used());
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    82
    }
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    83
    return false;
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    84
  }
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    85
};
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    86
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    87
void G1HeapTransition::print() {
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    88
  Data after(_g1_heap);
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    89
53985
0da5c17f5e43 8219747: Remove g1_ prefix to g1_remset and g1_policy members in G1CollectedHeap
tschatzl
parents: 52975
diff changeset
    90
  size_t eden_capacity_length_after_gc = _g1_heap->policy()->young_list_target_length() - after._survivor_length;
0da5c17f5e43 8219747: Remove g1_ prefix to g1_remset and g1_policy members in G1CollectedHeap
tschatzl
parents: 52975
diff changeset
    91
  size_t survivor_capacity_length_before_gc = _g1_heap->policy()->max_survivor_regions();
35909
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    92
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    93
  DetailedUsage usage;
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    94
  if (log_is_enabled(Trace, gc, heap)) {
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    95
    DetailedUsageClosure blk;
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    96
    _g1_heap->heap_region_iterate(&blk);
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    97
    usage = blk._usage;
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    98
    assert(usage._eden_region_count == 0, "Expected no eden regions, but got " SIZE_FORMAT, usage._eden_region_count);
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
    99
    assert(usage._survivor_region_count == after._survivor_length, "Expected survivors to be " SIZE_FORMAT " but was " SIZE_FORMAT,
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
   100
        after._survivor_length, usage._survivor_region_count);
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
   101
    assert(usage._old_region_count == after._old_length, "Expected old to be " SIZE_FORMAT " but was " SIZE_FORMAT,
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
   102
        after._old_length, usage._old_region_count);
51494
1906adbef2dc 8208498: Put archive regions into a first-class HeapRegionSet
tschatzl
parents: 49389
diff changeset
   103
    assert(usage._archive_region_count == after._archive_length, "Expected archive to be " SIZE_FORMAT " but was " SIZE_FORMAT,
1906adbef2dc 8208498: Put archive regions into a first-class HeapRegionSet
tschatzl
parents: 49389
diff changeset
   104
        after._archive_length, usage._archive_region_count);
35909
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
   105
    assert(usage._humongous_region_count == after._humongous_length, "Expected humongous to be " SIZE_FORMAT " but was " SIZE_FORMAT,
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
   106
        after._humongous_length, usage._humongous_region_count);
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
   107
  }
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
   108
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
   109
  log_info(gc, heap)("Eden regions: " SIZE_FORMAT "->" SIZE_FORMAT "("  SIZE_FORMAT ")",
37099
3b0caf5e43e0 8151842: Local variables have wrong names after JDK-8148736
brutisso
parents: 35909
diff changeset
   110
                     _before._eden_length, after._eden_length, eden_capacity_length_after_gc);
35909
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
   111
  log_trace(gc, heap)(" Used: 0K, Waste: 0K");
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
   112
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
   113
  log_info(gc, heap)("Survivor regions: " SIZE_FORMAT "->" SIZE_FORMAT "("  SIZE_FORMAT ")",
52975
35e2bbea78b2 8152724: Sum of eden before GC and current survivor capacity may be larger than heap size
tschatzl
parents: 51494
diff changeset
   114
                     _before._survivor_length, after._survivor_length, survivor_capacity_length_before_gc);
35909
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
   115
  log_trace(gc, heap)(" Used: " SIZE_FORMAT "K, Waste: " SIZE_FORMAT "K",
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
   116
      usage._survivor_used / K, ((after._survivor_length * HeapRegion::GrainBytes) - usage._survivor_used) / K);
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
   117
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
   118
  log_info(gc, heap)("Old regions: " SIZE_FORMAT "->" SIZE_FORMAT,
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
   119
                     _before._old_length, after._old_length);
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
   120
  log_trace(gc, heap)(" Used: " SIZE_FORMAT "K, Waste: " SIZE_FORMAT "K",
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
   121
      usage._old_used / K, ((after._old_length * HeapRegion::GrainBytes) - usage._old_used) / K);
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
   122
51494
1906adbef2dc 8208498: Put archive regions into a first-class HeapRegionSet
tschatzl
parents: 49389
diff changeset
   123
  log_info(gc, heap)("Archive regions: " SIZE_FORMAT "->" SIZE_FORMAT,
1906adbef2dc 8208498: Put archive regions into a first-class HeapRegionSet
tschatzl
parents: 49389
diff changeset
   124
                     _before._archive_length, after._archive_length);
1906adbef2dc 8208498: Put archive regions into a first-class HeapRegionSet
tschatzl
parents: 49389
diff changeset
   125
  log_trace(gc, heap)(" Used: " SIZE_FORMAT "K, Waste: " SIZE_FORMAT "K",
1906adbef2dc 8208498: Put archive regions into a first-class HeapRegionSet
tschatzl
parents: 49389
diff changeset
   126
      usage._archive_used / K, ((after._archive_length * HeapRegion::GrainBytes) - usage._archive_used) / K);
1906adbef2dc 8208498: Put archive regions into a first-class HeapRegionSet
tschatzl
parents: 49389
diff changeset
   127
35909
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
   128
  log_info(gc, heap)("Humongous regions: " SIZE_FORMAT "->" SIZE_FORMAT,
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
   129
                     _before._humongous_length, after._humongous_length);
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
   130
  log_trace(gc, heap)(" Used: " SIZE_FORMAT "K, Waste: " SIZE_FORMAT "K",
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
   131
      usage._humongous_used / K, ((after._humongous_length * HeapRegion::GrainBytes) - usage._humongous_used) / K);
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
   132
55576
4d193e40e7af 8223575: add subspace transitions to gc+metaspace=info log lines
tonyp
parents: 53985
diff changeset
   133
  MetaspaceUtils::print_metaspace_change(_before._meta_sizes);
35909
cf5f3c85e179 8148736: Let the G1 heap transition log regions instead of bytes
brutisso
parents:
diff changeset
   134
}