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 #include "precompiled.hpp"
25
26 #include "memory/allocation.hpp"
27 #include "services/mallocTracker.hpp"
28 #include "services/memReporter.hpp"
29 #include "services/threadStackTracker.hpp"
30 #include "services/virtualMemoryTracker.hpp"
31 #include "utilities/globalDefinitions.hpp"
32
33 size_t MemReporterBase::reserved_total(const MallocMemory* malloc, const VirtualMemory* vm) const {
34 return malloc->malloc_size() + malloc->arena_size() + vm->reserved();
35 }
36
37 size_t MemReporterBase::committed_total(const MallocMemory* malloc, const VirtualMemory* vm) const {
38 return malloc->malloc_size() + malloc->arena_size() + vm->committed();
39 }
40
41 void MemReporterBase::print_total(size_t reserved, size_t committed) const {
42 const char* scale = current_scale();
43 output()->print("reserved=" SIZE_FORMAT "%s, committed=" SIZE_FORMAT "%s",
44 amount_in_current_scale(reserved), scale, amount_in_current_scale(committed), scale);
45 }
46
192
193 if (amount_in_current_scale(malloc_memory->arena_size()) > 0) {
194 print_arena_line(malloc_memory->arena_size(), malloc_memory->arena_count());
195 }
196
197 if (flag == mtNMT &&
198 amount_in_current_scale(_malloc_snapshot->malloc_overhead()->size()) > 0) {
199 out->print_cr("%27s (tracking overhead=" SIZE_FORMAT "%s)", " ",
200 amount_in_current_scale(_malloc_snapshot->malloc_overhead()->size()), scale);
201 } else if (flag == mtClass) {
202 // Metadata information
203 report_metadata(Metaspace::NonClassType);
204 if (Metaspace::using_class_space()) {
205 report_metadata(Metaspace::ClassType);
206 }
207 }
208 out->print_cr(" ");
209 }
210 }
211
212 void MemSummaryReporter::report_metadata(Metaspace::MetadataType type) const {
213 assert(type == Metaspace::NonClassType || type == Metaspace::ClassType,
214 "Invalid metadata type");
215 const char* name = (type == Metaspace::NonClassType) ?
216 "Metadata: " : "Class space:";
217
218 outputStream* out = output();
219 const char* scale = current_scale();
220 size_t committed = MetaspaceUtils::committed_bytes(type);
221 size_t used = MetaspaceUtils::used_bytes(type);
222 size_t free = (MetaspaceUtils::capacity_bytes(type) - used)
223 + MetaspaceUtils::free_chunks_total_bytes(type)
224 + MetaspaceUtils::free_in_vs_bytes(type);
225
226 assert(committed >= used + free, "Sanity");
227 size_t waste = committed - (used + free);
228
229 out->print_cr("%27s ( %s)", " ", name);
230 out->print("%27s ( ", " ");
231 print_total(MetaspaceUtils::reserved_bytes(type), committed);
232 out->print_cr(")");
233 out->print_cr("%27s ( used=" SIZE_FORMAT "%s)", " ", amount_in_current_scale(used), scale);
234 out->print_cr("%27s ( free=" SIZE_FORMAT "%s)", " ", amount_in_current_scale(free), scale);
235 out->print_cr("%27s ( waste=" SIZE_FORMAT "%s =%2.2f%%)", " ", amount_in_current_scale(waste),
236 scale, ((float)waste * 100)/committed);
237 }
238
239 void MemDetailReporter::report_detail() {
240 // Start detail report
241 outputStream* out = output();
242 out->print_cr("Details:\n");
243
244 report_malloc_sites();
245 report_virtual_memory_allocation_sites();
246 }
247
248 void MemDetailReporter::report_malloc_sites() {
249 MallocSiteIterator malloc_itr = _baseline.malloc_sites(MemBaseline::by_size);
250 if (malloc_itr.is_empty()) return;
251
582 if (overhead_diff != 0) {
583 out->print(" %+ld%s", overhead_diff, scale);
584 }
585 out->print_cr(")");
586 } else if (flag == mtClass) {
587 assert(current_ms != NULL && early_ms != NULL, "Sanity");
588 print_metaspace_diff(current_ms, early_ms);
589 }
590 out->print_cr(" ");
591 }
592 }
593
594 void MemSummaryDiffReporter::print_metaspace_diff(const MetaspaceSnapshot* current_ms,
595 const MetaspaceSnapshot* early_ms) const {
596 print_metaspace_diff(Metaspace::NonClassType, current_ms, early_ms);
597 if (Metaspace::using_class_space()) {
598 print_metaspace_diff(Metaspace::ClassType, current_ms, early_ms);
599 }
600 }
601
602 void MemSummaryDiffReporter::print_metaspace_diff(Metaspace::MetadataType type,
603 const MetaspaceSnapshot* current_ms,
604 const MetaspaceSnapshot* early_ms) const {
605 const char* name = (type == Metaspace::NonClassType) ?
606 "Metadata: " : "Class space:";
607
608 outputStream* out = output();
609 const char* scale = current_scale();
610
611 out->print_cr("%27s ( %s)", " ", name);
612 out->print("%27s ( ", " ");
613 print_virtual_memory_diff(current_ms->reserved_in_bytes(type),
614 current_ms->committed_in_bytes(type),
615 early_ms->reserved_in_bytes(type),
616 early_ms->committed_in_bytes(type));
617 out->print_cr(")");
618
619 long diff_used = diff_in_current_scale(current_ms->used_in_bytes(type),
620 early_ms->used_in_bytes(type));
621 long diff_free = diff_in_current_scale(current_ms->free_in_bytes(type),
622 early_ms->free_in_bytes(type));
623
624 size_t current_waste = current_ms->committed_in_bytes(type)
625 - (current_ms->used_in_bytes(type) + current_ms->free_in_bytes(type));
626 size_t early_waste = early_ms->committed_in_bytes(type)
627 - (early_ms->used_in_bytes(type) + early_ms->free_in_bytes(type));
628 long diff_waste = diff_in_current_scale(current_waste, early_waste);
629
630 // Diff used
631 out->print("%27s ( used=" SIZE_FORMAT "%s", " ",
632 amount_in_current_scale(current_ms->used_in_bytes(type)), scale);
633 if (diff_used != 0) {
634 out->print(" %+ld%s", diff_used, scale);
635 }
636 out->print_cr(")");
637
638 // Diff free
639 out->print("%27s ( free=" SIZE_FORMAT "%s", " ",
640 amount_in_current_scale(current_ms->free_in_bytes(type)), scale);
641 if (diff_free != 0) {
642 out->print(" %+ld%s", diff_free, scale);
643 }
644 out->print_cr(")");
645
646
647 // Diff waste
648 out->print("%27s ( waste=" SIZE_FORMAT "%s =%2.2f%%", " ",
649 amount_in_current_scale(current_waste), scale,
650 ((float)current_waste * 100) / current_ms->committed_in_bytes(type));
651 if (diff_waste != 0) {
652 out->print(" %+ld%s", diff_waste, scale);
653 }
654 out->print_cr(")");
655 }
656
657 void MemDetailDiffReporter::report_diff() {
658 MemSummaryDiffReporter::report_diff();
659 diff_malloc_sites();
660 diff_virtual_memory_sites();
661 }
662
663 void MemDetailDiffReporter::diff_malloc_sites() const {
664 MallocSiteIterator early_itr = _early_baseline.malloc_sites(MemBaseline::by_site_and_type);
665 MallocSiteIterator current_itr = _current_baseline.malloc_sites(MemBaseline::by_site_and_type);
666
667 const MallocSite* early_site = early_itr.next();
668 const MallocSite* current_site = current_itr.next();
669
670 while (early_site != NULL || current_site != NULL) {
|
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 #include "precompiled.hpp"
25
26
27 #include "memory/allocation.hpp"
28 #include "memory/metaspace.hpp"
29 #include "memory/metaspace/metaspaceEnums.hpp"
30 #include "services/mallocTracker.hpp"
31 #include "services/memReporter.hpp"
32 #include "services/threadStackTracker.hpp"
33 #include "services/virtualMemoryTracker.hpp"
34 #include "utilities/globalDefinitions.hpp"
35
36 size_t MemReporterBase::reserved_total(const MallocMemory* malloc, const VirtualMemory* vm) const {
37 return malloc->malloc_size() + malloc->arena_size() + vm->reserved();
38 }
39
40 size_t MemReporterBase::committed_total(const MallocMemory* malloc, const VirtualMemory* vm) const {
41 return malloc->malloc_size() + malloc->arena_size() + vm->committed();
42 }
43
44 void MemReporterBase::print_total(size_t reserved, size_t committed) const {
45 const char* scale = current_scale();
46 output()->print("reserved=" SIZE_FORMAT "%s, committed=" SIZE_FORMAT "%s",
47 amount_in_current_scale(reserved), scale, amount_in_current_scale(committed), scale);
48 }
49
195
196 if (amount_in_current_scale(malloc_memory->arena_size()) > 0) {
197 print_arena_line(malloc_memory->arena_size(), malloc_memory->arena_count());
198 }
199
200 if (flag == mtNMT &&
201 amount_in_current_scale(_malloc_snapshot->malloc_overhead()->size()) > 0) {
202 out->print_cr("%27s (tracking overhead=" SIZE_FORMAT "%s)", " ",
203 amount_in_current_scale(_malloc_snapshot->malloc_overhead()->size()), scale);
204 } else if (flag == mtClass) {
205 // Metadata information
206 report_metadata(Metaspace::NonClassType);
207 if (Metaspace::using_class_space()) {
208 report_metadata(Metaspace::ClassType);
209 }
210 }
211 out->print_cr(" ");
212 }
213 }
214
215 void MemSummaryReporter::report_metadata(Metaspace::MetadataType mdType) const {
216 DEBUG_ONLY(metaspace::check_valid_mdtype(mdType));
217 const char* const name = metaspace::describe_mdtype(mdType);
218
219 outputStream* out = output();
220 const char* scale = current_scale();
221 size_t committed = MetaspaceUtils::committed_bytes(mdType);
222 size_t used = MetaspaceUtils::used_bytes(mdType);
223 size_t free = 0; //
224 // TODO think this thru. What is free in this context?
225 // (MetaspaceUtils::capacity_bytes(type) - used)
226 // + MetaspaceUtils::free_chunks_total_bytes(type)
227 // + MetaspaceUtils::free_in_vs_bytes(type);
228
229 assert(committed >= used + free, "Sanity");
230 size_t waste = committed - (used + free);
231
232 out->print_cr("%27s ( %s)", " ", name);
233 out->print("%27s ( ", " ");
234 print_total(MetaspaceUtils::reserved_bytes(mdType), committed);
235 out->print_cr(")");
236 out->print_cr("%27s ( used=" SIZE_FORMAT "%s)", " ", amount_in_current_scale(used), scale);
237 out->print_cr("%27s ( free=" SIZE_FORMAT "%s)", " ", amount_in_current_scale(free), scale);
238 out->print_cr("%27s ( waste=" SIZE_FORMAT "%s =%2.2f%%)", " ", amount_in_current_scale(waste),
239 scale, ((float)waste * 100)/committed);
240 }
241
242 void MemDetailReporter::report_detail() {
243 // Start detail report
244 outputStream* out = output();
245 out->print_cr("Details:\n");
246
247 report_malloc_sites();
248 report_virtual_memory_allocation_sites();
249 }
250
251 void MemDetailReporter::report_malloc_sites() {
252 MallocSiteIterator malloc_itr = _baseline.malloc_sites(MemBaseline::by_size);
253 if (malloc_itr.is_empty()) return;
254
585 if (overhead_diff != 0) {
586 out->print(" %+ld%s", overhead_diff, scale);
587 }
588 out->print_cr(")");
589 } else if (flag == mtClass) {
590 assert(current_ms != NULL && early_ms != NULL, "Sanity");
591 print_metaspace_diff(current_ms, early_ms);
592 }
593 out->print_cr(" ");
594 }
595 }
596
597 void MemSummaryDiffReporter::print_metaspace_diff(const MetaspaceSnapshot* current_ms,
598 const MetaspaceSnapshot* early_ms) const {
599 print_metaspace_diff(Metaspace::NonClassType, current_ms, early_ms);
600 if (Metaspace::using_class_space()) {
601 print_metaspace_diff(Metaspace::ClassType, current_ms, early_ms);
602 }
603 }
604
605 void MemSummaryDiffReporter::print_metaspace_diff(Metaspace::MetadataType mdType,
606 const MetaspaceSnapshot* current_ms,
607 const MetaspaceSnapshot* early_ms) const {
608 DEBUG_ONLY(metaspace::check_valid_mdtype(mdType));
609 const char* const name = metaspace::describe_mdtype(mdType);
610
611 outputStream* out = output();
612 const char* scale = current_scale();
613
614 out->print_cr("%27s ( %s)", " ", name);
615 out->print("%27s ( ", " ");
616 print_virtual_memory_diff(current_ms->reserved_in_bytes(mdType),
617 current_ms->committed_in_bytes(mdType),
618 early_ms->reserved_in_bytes(mdType),
619 early_ms->committed_in_bytes(mdType));
620 out->print_cr(")");
621
622 long diff_used = diff_in_current_scale(current_ms->used_in_bytes(mdType),
623 early_ms->used_in_bytes(mdType));
624 long diff_free = diff_in_current_scale(current_ms->free_in_bytes(mdType),
625 early_ms->free_in_bytes(mdType));
626
627 size_t current_waste = current_ms->committed_in_bytes(mdType)
628 - (current_ms->used_in_bytes(mdType) + current_ms->free_in_bytes(mdType));
629 size_t early_waste = early_ms->committed_in_bytes(mdType)
630 - (early_ms->used_in_bytes(mdType) + early_ms->free_in_bytes(mdType));
631 long diff_waste = diff_in_current_scale(current_waste, early_waste);
632
633 // Diff used
634 out->print("%27s ( used=" SIZE_FORMAT "%s", " ",
635 amount_in_current_scale(current_ms->used_in_bytes(mdType)), scale);
636 if (diff_used != 0) {
637 out->print(" %+ld%s", diff_used, scale);
638 }
639 out->print_cr(")");
640
641 // Diff free
642 out->print("%27s ( free=" SIZE_FORMAT "%s", " ",
643 amount_in_current_scale(current_ms->free_in_bytes(mdType)), scale);
644 if (diff_free != 0) {
645 out->print(" %+ld%s", diff_free, scale);
646 }
647 out->print_cr(")");
648
649
650 // Diff waste
651 out->print("%27s ( waste=" SIZE_FORMAT "%s =%2.2f%%", " ",
652 amount_in_current_scale(current_waste), scale,
653 ((float)current_waste * 100) / current_ms->committed_in_bytes(mdType));
654 if (diff_waste != 0) {
655 out->print(" %+ld%s", diff_waste, scale);
656 }
657 out->print_cr(")");
658 }
659
660 void MemDetailDiffReporter::report_diff() {
661 MemSummaryDiffReporter::report_diff();
662 diff_malloc_sites();
663 diff_virtual_memory_sites();
664 }
665
666 void MemDetailDiffReporter::diff_malloc_sites() const {
667 MallocSiteIterator early_itr = _early_baseline.malloc_sites(MemBaseline::by_site_and_type);
668 MallocSiteIterator current_itr = _current_baseline.malloc_sites(MemBaseline::by_site_and_type);
669
670 const MallocSite* early_site = early_itr.next();
671 const MallocSite* current_site = current_itr.next();
672
673 while (early_site != NULL || current_site != NULL) {
|