| 1 | /* |
| 2 | * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 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 |
| 7 | * published by the Free Software Foundation. |
| 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.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 | _metaspace_used_bytes = MetaspaceUtils::used_bytes(); |
| 39 | } |
| 40 | |
| 41 | G1HeapTransition::G1HeapTransition(G1CollectedHeap* g1_heap) : _g1_heap(g1_heap), _before(g1_heap) { } |
| 42 | |
| 43 | struct DetailedUsage : public StackObj { |
| 44 | size_t _eden_used; |
| 45 | size_t _survivor_used; |
| 46 | size_t _old_used; |
| 47 | size_t _archive_used; |
| 48 | size_t _humongous_used; |
| 49 | |
| 50 | size_t _eden_region_count; |
| 51 | size_t _survivor_region_count; |
| 52 | size_t _old_region_count; |
| 53 | size_t _archive_region_count; |
| 54 | size_t _humongous_region_count; |
| 55 | |
| 56 | DetailedUsage() : |
| 57 | _eden_used(0), _survivor_used(0), _old_used(0), _archive_used(0), _humongous_used(0), |
| 58 | _eden_region_count(0), _survivor_region_count(0), _old_region_count(0), |
| 59 | _archive_region_count(0), _humongous_region_count(0) {} |
| 60 | }; |
| 61 | |
| 62 | class DetailedUsageClosure: public HeapRegionClosure { |
| 63 | public: |
| 64 | DetailedUsage _usage; |
| 65 | bool do_heap_region(HeapRegion* r) { |
| 66 | if (r->is_old()) { |
| 67 | _usage._old_used += r->used(); |
| 68 | _usage._old_region_count++; |
| 69 | } else if (r->is_archive()) { |
| 70 | _usage._archive_used += r->used(); |
| 71 | _usage._archive_region_count++; |
| 72 | } else if (r->is_survivor()) { |
| 73 | _usage._survivor_used += r->used(); |
| 74 | _usage._survivor_region_count++; |
| 75 | } else if (r->is_eden()) { |
| 76 | _usage._eden_used += r->used(); |
| 77 | _usage._eden_region_count++; |
| 78 | } else if (r->is_humongous()) { |
| 79 | _usage._humongous_used += r->used(); |
| 80 | _usage._humongous_region_count++; |
| 81 | } else { |
| 82 | assert(r->used() == 0, "Expected used to be 0 but it was " SIZE_FORMAT, r->used()); |
| 83 | } |
| 84 | return false; |
| 85 | } |
| 86 | }; |
| 87 | |
| 88 | void G1HeapTransition::print() { |
| 89 | Data after(_g1_heap); |
| 90 | |
| 91 | size_t eden_capacity_length_after_gc = _g1_heap->policy()->young_list_target_length() - after._survivor_length; |
| 92 | size_t survivor_capacity_length_before_gc = _g1_heap->policy()->max_survivor_regions(); |
| 93 | |
| 94 | DetailedUsage usage; |
| 95 | if (log_is_enabled(Trace, gc, heap)) { |
| 96 | DetailedUsageClosure blk; |
| 97 | _g1_heap->heap_region_iterate(&blk); |
| 98 | usage = blk._usage; |
| 99 | assert(usage._eden_region_count == 0, "Expected no eden regions, but got " SIZE_FORMAT, usage._eden_region_count); |
| 100 | assert(usage._survivor_region_count == after._survivor_length, "Expected survivors to be " SIZE_FORMAT " but was " SIZE_FORMAT, |
| 101 | after._survivor_length, usage._survivor_region_count); |
| 102 | assert(usage._old_region_count == after._old_length, "Expected old to be " SIZE_FORMAT " but was " SIZE_FORMAT, |
| 103 | after._old_length, usage._old_region_count); |
| 104 | assert(usage._archive_region_count == after._archive_length, "Expected archive to be " SIZE_FORMAT " but was " SIZE_FORMAT, |
| 105 | after._archive_length, usage._archive_region_count); |
| 106 | assert(usage._humongous_region_count == after._humongous_length, "Expected humongous to be " SIZE_FORMAT " but was " SIZE_FORMAT, |
| 107 | after._humongous_length, usage._humongous_region_count); |
| 108 | } |
| 109 | |
| 110 | log_info(gc, heap)("Eden regions: " SIZE_FORMAT "->" SIZE_FORMAT "(" SIZE_FORMAT ")" , |
| 111 | _before._eden_length, after._eden_length, eden_capacity_length_after_gc); |
| 112 | log_trace(gc, heap)(" Used: 0K, Waste: 0K" ); |
| 113 | |
| 114 | log_info(gc, heap)("Survivor regions: " SIZE_FORMAT "->" SIZE_FORMAT "(" SIZE_FORMAT ")" , |
| 115 | _before._survivor_length, after._survivor_length, survivor_capacity_length_before_gc); |
| 116 | log_trace(gc, heap)(" Used: " SIZE_FORMAT "K, Waste: " SIZE_FORMAT "K" , |
| 117 | usage._survivor_used / K, ((after._survivor_length * HeapRegion::GrainBytes) - usage._survivor_used) / K); |
| 118 | |
| 119 | log_info(gc, heap)("Old regions: " SIZE_FORMAT "->" SIZE_FORMAT, |
| 120 | _before._old_length, after._old_length); |
| 121 | log_trace(gc, heap)(" Used: " SIZE_FORMAT "K, Waste: " SIZE_FORMAT "K" , |
| 122 | usage._old_used / K, ((after._old_length * HeapRegion::GrainBytes) - usage._old_used) / K); |
| 123 | |
| 124 | log_info(gc, heap)("Archive regions: " SIZE_FORMAT "->" SIZE_FORMAT, |
| 125 | _before._archive_length, after._archive_length); |
| 126 | log_trace(gc, heap)(" Used: " SIZE_FORMAT "K, Waste: " SIZE_FORMAT "K" , |
| 127 | usage._archive_used / K, ((after._archive_length * HeapRegion::GrainBytes) - usage._archive_used) / K); |
| 128 | |
| 129 | log_info(gc, heap)("Humongous regions: " SIZE_FORMAT "->" SIZE_FORMAT, |
| 130 | _before._humongous_length, after._humongous_length); |
| 131 | log_trace(gc, heap)(" Used: " SIZE_FORMAT "K, Waste: " SIZE_FORMAT "K" , |
| 132 | usage._humongous_used / K, ((after._humongous_length * HeapRegion::GrainBytes) - usage._humongous_used) / K); |
| 133 | |
| 134 | MetaspaceUtils::print_metaspace_change(_before._metaspace_used_bytes); |
| 135 | } |
| 136 | |