< prev index next >

src/hotspot/share/gc/g1/g1HeapTransition.cpp

Print this page
rev 56834 : imported patch 8220312.stat.2
rev 56835 : imported patch 8220312.stat.3


   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.hpp"
  27 #include "gc/g1/g1HeapTransition.hpp"
  28 #include "gc/g1/g1Policy.hpp"
  29 #include "logging/log.hpp"
  30 #include "memory/metaspace.hpp"
  31 
  32 G1HeapTransition::Data::Data(G1CollectedHeap* g1_heap) {
  33   _eden_length = g1_heap->eden_regions_count();
  34   _survivor_length = g1_heap->survivor_regions_count();
  35   _old_length = g1_heap->old_regions_count();
  36   _archive_length = g1_heap->archive_regions_count();
  37   _humongous_length = g1_heap->humongous_regions_count();























  38 }
  39 
  40 G1HeapTransition::G1HeapTransition(G1CollectedHeap* g1_heap) : _g1_heap(g1_heap), _before(g1_heap) { }
  41 
  42 struct DetailedUsage : public StackObj {
  43   size_t _eden_used;
  44   size_t _survivor_used;
  45   size_t _old_used;
  46   size_t _archive_used;
  47   size_t _humongous_used;
  48 
  49   size_t _eden_region_count;
  50   size_t _survivor_region_count;
  51   size_t _old_region_count;
  52   size_t _archive_region_count;
  53   size_t _humongous_region_count;
  54 
  55   DetailedUsage() :
  56     _eden_used(0), _survivor_used(0), _old_used(0), _archive_used(0), _humongous_used(0),
  57     _eden_region_count(0), _survivor_region_count(0), _old_region_count(0),


  67       _usage._old_region_count++;
  68     } else if (r->is_archive()) {
  69       _usage._archive_used += r->used();
  70       _usage._archive_region_count++;
  71     } else if (r->is_survivor()) {
  72       _usage._survivor_used += r->used();
  73       _usage._survivor_region_count++;
  74     } else if (r->is_eden()) {
  75       _usage._eden_used += r->used();
  76       _usage._eden_region_count++;
  77     } else if (r->is_humongous()) {
  78       _usage._humongous_used += r->used();
  79       _usage._humongous_region_count++;
  80     } else {
  81       assert(r->used() == 0, "Expected used to be 0 but it was " SIZE_FORMAT, r->used());
  82     }
  83     return false;
  84   }
  85 };
  86 




























  87 void G1HeapTransition::print() {
  88   Data after(_g1_heap);
  89 
  90   size_t eden_capacity_length_after_gc = _g1_heap->policy()->young_list_target_length() - after._survivor_length;
  91   size_t survivor_capacity_length_before_gc = _g1_heap->policy()->max_survivor_regions();
  92 
  93   DetailedUsage usage;
  94   if (log_is_enabled(Trace, gc, heap)) {
  95     DetailedUsageClosure blk;
  96     _g1_heap->heap_region_iterate(&blk);
  97     usage = blk._usage;
  98     assert(usage._eden_region_count == 0, "Expected no eden regions, but got " SIZE_FORMAT, usage._eden_region_count);
  99     assert(usage._survivor_region_count == after._survivor_length, "Expected survivors to be " SIZE_FORMAT " but was " SIZE_FORMAT,
 100         after._survivor_length, usage._survivor_region_count);
 101     assert(usage._old_region_count == after._old_length, "Expected old to be " SIZE_FORMAT " but was " SIZE_FORMAT,
 102         after._old_length, usage._old_region_count);
 103     assert(usage._archive_region_count == after._archive_length, "Expected archive to be " SIZE_FORMAT " but was " SIZE_FORMAT,
 104         after._archive_length, usage._archive_region_count);
 105     assert(usage._humongous_region_count == after._humongous_length, "Expected humongous to be " SIZE_FORMAT " but was " SIZE_FORMAT,
 106         after._humongous_length, usage._humongous_region_count);
 107   }
 108 
 109   log_info(gc, heap)("Eden regions: " SIZE_FORMAT "->" SIZE_FORMAT "("  SIZE_FORMAT ")",
 110                      _before._eden_length, after._eden_length, eden_capacity_length_after_gc);
 111   log_trace(gc, heap)(" Used: 0K, Waste: 0K");
 112 
 113   log_info(gc, heap)("Survivor regions: " SIZE_FORMAT "->" SIZE_FORMAT "("  SIZE_FORMAT ")",
 114                      _before._survivor_length, after._survivor_length, survivor_capacity_length_before_gc);
 115   log_trace(gc, heap)(" Used: " SIZE_FORMAT "K, Waste: " SIZE_FORMAT "K",
 116       usage._survivor_used / K, ((after._survivor_length * HeapRegion::GrainBytes) - usage._survivor_used) / K);
 117 
 118   log_info(gc, heap)("Old regions: " SIZE_FORMAT "->" SIZE_FORMAT,
 119                      _before._old_length, after._old_length);
 120   log_trace(gc, heap)(" Used: " SIZE_FORMAT "K, Waste: " SIZE_FORMAT "K",
 121       usage._old_used / K, ((after._old_length * HeapRegion::GrainBytes) - usage._old_used) / K);
 122 
 123   log_info(gc, heap)("Archive regions: " SIZE_FORMAT "->" SIZE_FORMAT,
 124                      _before._archive_length, after._archive_length);
 125   log_trace(gc, heap)(" Used: " SIZE_FORMAT "K, Waste: " SIZE_FORMAT "K",
 126       usage._archive_used / K, ((after._archive_length * HeapRegion::GrainBytes) - usage._archive_used) / K);
 127 
 128   log_info(gc, heap)("Humongous regions: " SIZE_FORMAT "->" SIZE_FORMAT,
 129                      _before._humongous_length, after._humongous_length);
 130   log_trace(gc, heap)(" Used: " SIZE_FORMAT "K, Waste: " SIZE_FORMAT "K",
 131       usage._humongous_used / K, ((after._humongous_length * HeapRegion::GrainBytes) - usage._humongous_used) / K);
 132 
 133   MetaspaceUtils::print_metaspace_change(_before._meta_sizes);
 134 }


   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.hpp"
  27 #include "gc/g1/g1HeapTransition.hpp"
  28 #include "gc/g1/g1Policy.hpp"
  29 #include "logging/logStream.hpp"
  30 #include "memory/metaspace.hpp"
  31 
  32 G1HeapTransition::Data::Data(G1CollectedHeap* g1_heap) :
  33   _eden_length(g1_heap->eden_regions_count()),
  34   _survivor_length(g1_heap->survivor_regions_count()),
  35   _old_length(g1_heap->old_regions_count()),
  36   _archive_length(g1_heap->archive_regions_count()),
  37   _humongous_length(g1_heap->humongous_regions_count()),
  38   _eden_length_per_node(NULL),
  39   _survivor_length_per_node(NULL) {
  40 
  41   uint node_count = G1NUMA::numa()->num_active_nodes();
  42 
  43   if (node_count > 1) {
  44     LogTarget(Debug, gc, heap, numa) lt;
  45 
  46     if (lt.is_enabled()) {
  47       _eden_length_per_node = NEW_C_HEAP_ARRAY(uint, node_count, mtGC);
  48       _survivor_length_per_node = NEW_C_HEAP_ARRAY(uint, node_count, mtGC);
  49 
  50       for (uint i = 0; i < node_count; i++) {
  51         _eden_length_per_node[i] = g1_heap->eden_regions_count(i);
  52         _survivor_length_per_node[i] = g1_heap->survivor_regions_count(i);
  53       }
  54     }
  55   }
  56 }
  57 
  58 G1HeapTransition::Data::~Data() {
  59   FREE_C_HEAP_ARRAY(uint, _eden_length_per_node);
  60   FREE_C_HEAP_ARRAY(uint, _survivor_length_per_node);
  61 }
  62 
  63 G1HeapTransition::G1HeapTransition(G1CollectedHeap* g1_heap) : _g1_heap(g1_heap), _before(g1_heap) { }
  64 
  65 struct DetailedUsage : public StackObj {
  66   size_t _eden_used;
  67   size_t _survivor_used;
  68   size_t _old_used;
  69   size_t _archive_used;
  70   size_t _humongous_used;
  71 
  72   size_t _eden_region_count;
  73   size_t _survivor_region_count;
  74   size_t _old_region_count;
  75   size_t _archive_region_count;
  76   size_t _humongous_region_count;
  77 
  78   DetailedUsage() :
  79     _eden_used(0), _survivor_used(0), _old_used(0), _archive_used(0), _humongous_used(0),
  80     _eden_region_count(0), _survivor_region_count(0), _old_region_count(0),


  90       _usage._old_region_count++;
  91     } else if (r->is_archive()) {
  92       _usage._archive_used += r->used();
  93       _usage._archive_region_count++;
  94     } else if (r->is_survivor()) {
  95       _usage._survivor_used += r->used();
  96       _usage._survivor_region_count++;
  97     } else if (r->is_eden()) {
  98       _usage._eden_used += r->used();
  99       _usage._eden_region_count++;
 100     } else if (r->is_humongous()) {
 101       _usage._humongous_used += r->used();
 102       _usage._humongous_region_count++;
 103     } else {
 104       assert(r->used() == 0, "Expected used to be 0 but it was " SIZE_FORMAT, r->used());
 105     }
 106     return false;
 107   }
 108 };
 109 
 110 static void log_regions(const char* msg, size_t before_length, size_t after_length, size_t capacity,
 111                         uint* before_per_node_length, uint* after_per_node_length) {
 112   LogTarget(Info, gc, heap) lt;
 113 
 114   if (lt.is_enabled()) {
 115     LogStream ls(lt);
 116 
 117     ls.print("%s regions: " SIZE_FORMAT "->" SIZE_FORMAT "("  SIZE_FORMAT ")",
 118              msg, before_length, after_length, capacity);
 119     // Not NULL only if gc+heap+numa at Debug level is enabled.
 120     if (before_per_node_length != NULL && after_per_node_length != NULL) {
 121       G1NUMA* numa = G1NUMA::numa();
 122       uint num_nodes = numa->num_active_nodes();
 123       const int* node_ids = numa->node_ids();
 124       ls.print(" (");
 125       for (uint i = 0; i < num_nodes; i++) {
 126         ls.print("%d: %u->%u", node_ids[i], before_per_node_length[i], after_per_node_length[i]);
 127         // Skip adding below if it is the last one.
 128         if (i != num_nodes - 1) {
 129           ls.print(", ");
 130         }
 131       }
 132       ls.print(")");
 133     }
 134     ls.print_cr("");
 135   }
 136 }
 137 
 138 void G1HeapTransition::print() {
 139   Data after(_g1_heap);
 140 
 141   size_t eden_capacity_length_after_gc = _g1_heap->policy()->young_list_target_length() - after._survivor_length;
 142   size_t survivor_capacity_length_before_gc = _g1_heap->policy()->max_survivor_regions();
 143 
 144   DetailedUsage usage;
 145   if (log_is_enabled(Trace, gc, heap)) {
 146     DetailedUsageClosure blk;
 147     _g1_heap->heap_region_iterate(&blk);
 148     usage = blk._usage;
 149     assert(usage._eden_region_count == 0, "Expected no eden regions, but got " SIZE_FORMAT, usage._eden_region_count);
 150     assert(usage._survivor_region_count == after._survivor_length, "Expected survivors to be " SIZE_FORMAT " but was " SIZE_FORMAT,
 151         after._survivor_length, usage._survivor_region_count);
 152     assert(usage._old_region_count == after._old_length, "Expected old to be " SIZE_FORMAT " but was " SIZE_FORMAT,
 153         after._old_length, usage._old_region_count);
 154     assert(usage._archive_region_count == after._archive_length, "Expected archive to be " SIZE_FORMAT " but was " SIZE_FORMAT,
 155         after._archive_length, usage._archive_region_count);
 156     assert(usage._humongous_region_count == after._humongous_length, "Expected humongous to be " SIZE_FORMAT " but was " SIZE_FORMAT,
 157         after._humongous_length, usage._humongous_region_count);
 158   }
 159 
 160   log_regions("Eden", _before._eden_length, after._eden_length, eden_capacity_length_after_gc,
 161               _before._eden_length_per_node, after._eden_length_per_node);
 162   log_trace(gc, heap)(" Used: 0K, Waste: 0K");
 163 
 164   log_regions("Survivor", _before._survivor_length, after._survivor_length, survivor_capacity_length_before_gc,
 165               _before._survivor_length_per_node, after._survivor_length_per_node);
 166   log_trace(gc, heap)(" Used: " SIZE_FORMAT "K, Waste: " SIZE_FORMAT "K",
 167       usage._survivor_used / K, ((after._survivor_length * HeapRegion::GrainBytes) - usage._survivor_used) / K);
 168 
 169   log_info(gc, heap)("Old regions: " SIZE_FORMAT "->" SIZE_FORMAT,
 170                      _before._old_length, after._old_length);
 171   log_trace(gc, heap)(" Used: " SIZE_FORMAT "K, Waste: " SIZE_FORMAT "K",
 172       usage._old_used / K, ((after._old_length * HeapRegion::GrainBytes) - usage._old_used) / K);
 173 
 174   log_info(gc, heap)("Archive regions: " SIZE_FORMAT "->" SIZE_FORMAT,
 175                      _before._archive_length, after._archive_length);
 176   log_trace(gc, heap)(" Used: " SIZE_FORMAT "K, Waste: " SIZE_FORMAT "K",
 177       usage._archive_used / K, ((after._archive_length * HeapRegion::GrainBytes) - usage._archive_used) / K);
 178 
 179   log_info(gc, heap)("Humongous regions: " SIZE_FORMAT "->" SIZE_FORMAT,
 180                      _before._humongous_length, after._humongous_length);
 181   log_trace(gc, heap)(" Used: " SIZE_FORMAT "K, Waste: " SIZE_FORMAT "K",
 182       usage._humongous_used / K, ((after._humongous_length * HeapRegion::GrainBytes) - usage._humongous_used) / K);
 183 
 184   MetaspaceUtils::print_metaspace_change(_before._meta_sizes);
 185 }
< prev index next >