< prev index next >
src/hotspot/share/services/memReporter.cpp
Print this page
rev 53982 : Thread stack tracking
@@ -24,10 +24,11 @@
#include "precompiled.hpp"
#include "memory/allocation.hpp"
#include "services/mallocTracker.hpp"
#include "services/memReporter.hpp"
+#include "services/threadStackTracker.hpp"
#include "services/virtualMemoryTracker.hpp"
#include "utilities/globalDefinitions.hpp"
size_t MemReporterBase::reserved_total(const MallocMemory* malloc, const VirtualMemory* vm) const {
return malloc->malloc_size() + malloc->arena_size() + vm->reserved();
@@ -44,15 +45,17 @@
}
void MemReporterBase::print_malloc(size_t amount, size_t count, MEMFLAGS flag) const {
const char* scale = current_scale();
outputStream* out = output();
+ const char* alloc_type = (flag == mtThreadStack) ? "" : "malloc=";
+
if (flag != mtNone) {
- out->print("(malloc=" SIZE_FORMAT "%s type=%s",
+ out->print("(%s" SIZE_FORMAT "%s type=%s", alloc_type,
amount_in_current_scale(amount), scale, NMTUtil::flag_to_name(flag));
} else {
- out->print("(malloc=" SIZE_FORMAT "%s",
+ out->print("(%s" SIZE_FORMAT "%s", alloc_type,
amount_in_current_scale(amount), scale);
}
if (count > 0) {
out->print(" #" SIZE_FORMAT "", count);
@@ -124,14 +127,21 @@
size_t reserved_amount = reserved_total (malloc_memory, virtual_memory);
size_t committed_amount = committed_total(malloc_memory, virtual_memory);
// Count thread's native stack in "Thread" category
if (flag == mtThread) {
+ if (ThreadStackTracker::track_as_vm()) {
const VirtualMemory* thread_stack_usage =
(const VirtualMemory*)_vm_snapshot->by_type(mtThreadStack);
reserved_amount += thread_stack_usage->reserved();
committed_amount += thread_stack_usage->committed();
+ } else {
+ const MallocMemory* thread_stack_usage =
+ (const MallocMemory*)_malloc_snapshot->by_type(mtThreadStack);
+ reserved_amount += thread_stack_usage->malloc_size();
+ committed_amount += thread_stack_usage->malloc_size();
+ }
} else if (flag == mtNMT) {
// Count malloc headers in "NMT" category
reserved_amount += _malloc_snapshot->malloc_overhead()->size();
committed_amount += _malloc_snapshot->malloc_overhead()->size();
}
@@ -148,16 +158,26 @@
out->print_cr("%27s (classes #" SIZE_FORMAT ")",
" ", (_instance_class_count + _array_class_count));
out->print_cr("%27s ( instance classes #" SIZE_FORMAT ", array classes #" SIZE_FORMAT ")",
" ", _instance_class_count, _array_class_count);
} else if (flag == mtThread) {
- // report thread count
- out->print_cr("%27s (thread #" SIZE_FORMAT ")", " ", _malloc_snapshot->thread_count());
+ if (ThreadStackTracker::track_as_vm()) {
const VirtualMemory* thread_stack_usage =
_vm_snapshot->by_type(mtThreadStack);
+ // report thread count
+ out->print_cr("%27s (thread #" SIZE_FORMAT ")", " ", ThreadStackTracker::thread_count());
out->print("%27s (stack: ", " ");
print_total(thread_stack_usage->reserved(), thread_stack_usage->committed());
+ } else {
+ MallocMemory* thread_stack_memory = _malloc_snapshot->by_type(mtThreadStack);
+ const char* scale = current_scale();
+ // report thread count
+ assert(ThreadStackTracker::thread_count() == 0, "Not used");
+ out->print_cr("%27s (thread #" SIZE_FORMAT ")", " ", thread_stack_memory->malloc_count());
+ out->print("%27s (Stack: " SIZE_FORMAT "%s", " ",
+ amount_in_current_scale(thread_stack_memory->malloc_size()), scale);
+ }
out->print_cr(")");
}
// report malloc'd memory
if (amount_in_current_scale(malloc_memory->malloc_size()) > 0) {
@@ -366,14 +386,15 @@
void MemSummaryDiffReporter::print_malloc_diff(size_t current_amount, size_t current_count,
size_t early_amount, size_t early_count, MEMFLAGS flags) const {
const char* scale = current_scale();
outputStream* out = output();
+ const char* alloc_type = (flags == mtThread) ? "" : "malloc=";
- out->print("malloc=" SIZE_FORMAT "%s", amount_in_current_scale(current_amount), scale);
- // Report type only if it is valid
- if (flags != mtNone) {
+ out->print("%s" SIZE_FORMAT "%s", alloc_type, amount_in_current_scale(current_amount), scale);
+ // Report type only if it is valid and not under "thread" category
+ if (flags != mtNone && flags != mtThread) {
out->print(" type=%s", NMTUtil::flag_to_name(flags));
}
long amount_diff = diff_in_current_scale(current_amount, early_amount);
if (amount_diff != 0) {
@@ -495,19 +516,29 @@
if (thread_count_diff != 0) {
out->print(" %+d", thread_count_diff);
}
out->print_cr(")");
+ out->print("%27s (stack: ", " ");
+ if (ThreadStackTracker::track_as_vm()) {
// report thread stack
const VirtualMemory* current_thread_stack =
_current_baseline.virtual_memory(mtThreadStack);
const VirtualMemory* early_thread_stack =
_early_baseline.virtual_memory(mtThreadStack);
- out->print("%27s (stack: ", " ");
print_virtual_memory_diff(current_thread_stack->reserved(), current_thread_stack->committed(),
early_thread_stack->reserved(), early_thread_stack->committed());
+ } else {
+ const MallocMemory* current_thread_stack =
+ _current_baseline.malloc_memory(mtThreadStack);
+ const MallocMemory* early_thread_stack =
+ _early_baseline.malloc_memory(mtThreadStack);
+
+ print_malloc_diff(current_thread_stack->malloc_size(), current_thread_stack->malloc_count(),
+ early_thread_stack->malloc_size(), early_thread_stack->malloc_count(), flag);
+ }
out->print_cr(")");
}
// Report malloc'd memory
size_t current_malloc_amount = current_malloc->malloc_size();
< prev index next >