30 #include "services/memTracker.hpp"
31 #include "utilities/defaultStream.hpp"
32
33 #ifdef SOLARIS
34 volatile bool NMT_stack_walkable = false;
35 #else
36 volatile bool NMT_stack_walkable = true;
37 #endif
38
39 volatile NMT_TrackingLevel MemTracker::_tracking_level = NMT_unknown;
40 NMT_TrackingLevel MemTracker::_cmdline_tracking_level = NMT_unknown;
41
42 MemBaseline MemTracker::_baseline;
43 Mutex* MemTracker::_query_lock = NULL;
44 bool MemTracker::_is_nmt_env_valid = true;
45
46
47 NMT_TrackingLevel MemTracker::init_tracking_level() {
48 NMT_TrackingLevel level = NMT_off;
49 char buf[64];
50 char nmt_option[64];
51 jio_snprintf(buf, sizeof(buf), "NMT_LEVEL_%d", os::current_process_id());
52 if (os::getenv(buf, nmt_option, sizeof(nmt_option))) {
53 if (strcmp(nmt_option, "summary") == 0) {
54 level = NMT_summary;
55 } else if (strcmp(nmt_option, "detail") == 0) {
56 level = NMT_detail;
57 } else if (strcmp(nmt_option, "off") != 0) {
58 // The option value is invalid
59 _is_nmt_env_valid = false;
60 }
61
62 // Remove the environment variable to avoid leaking to child processes
63 os::unsetenv(buf);
64 }
65
66 // Construct NativeCallStack::EMPTY_STACK. It may get constructed twice,
67 // but it is benign, the results are the same.
68 ::new ((void*)&NativeCallStack::EMPTY_STACK) NativeCallStack(0, false);
69
70 if (!MallocTracker::initialize(level) ||
71 !VirtualMemoryTracker::initialize(level)) {
72 level = NMT_off;
294 _bucket_over_threshold ++;
295 }
296 _longest_bucket_length = MAX2(_longest_bucket_length, length);
297 }
298 };
299
300
301 void MemTracker::tuning_statistics(outputStream* out) {
302 // NMT statistics
303 StatisticsWalker walker;
304 MallocSiteTable::walk_malloc_site(&walker);
305 walker.completed();
306
307 out->print_cr("Native Memory Tracking Statistics:");
308 out->print_cr("Malloc allocation site table size: %d", MallocSiteTable::hash_buckets());
309 out->print_cr(" Tracking stack depth: %d", NMT_TrackingStackDepth);
310 NOT_PRODUCT(out->print_cr("Peak concurrent access: %d", MallocSiteTable::access_peak_count());)
311 out->print_cr(" ");
312 walker.report_statistics(out);
313 }
314
|
30 #include "services/memTracker.hpp"
31 #include "utilities/defaultStream.hpp"
32
33 #ifdef SOLARIS
34 volatile bool NMT_stack_walkable = false;
35 #else
36 volatile bool NMT_stack_walkable = true;
37 #endif
38
39 volatile NMT_TrackingLevel MemTracker::_tracking_level = NMT_unknown;
40 NMT_TrackingLevel MemTracker::_cmdline_tracking_level = NMT_unknown;
41
42 MemBaseline MemTracker::_baseline;
43 Mutex* MemTracker::_query_lock = NULL;
44 bool MemTracker::_is_nmt_env_valid = true;
45
46
47 NMT_TrackingLevel MemTracker::init_tracking_level() {
48 NMT_TrackingLevel level = NMT_off;
49 char buf[64];
50 jio_snprintf(buf, sizeof(buf), "NMT_LEVEL_%d", os::current_process_id());
51 const char *nmt_option = ::getenv(buf);
52 if (nmt_option != NULL) {
53 if (strcmp(nmt_option, "summary") == 0) {
54 level = NMT_summary;
55 } else if (strcmp(nmt_option, "detail") == 0) {
56 level = NMT_detail;
57 } else if (strcmp(nmt_option, "off") != 0) {
58 // The option value is invalid
59 _is_nmt_env_valid = false;
60 }
61
62 // Remove the environment variable to avoid leaking to child processes
63 os::unsetenv(buf);
64 }
65
66 // Construct NativeCallStack::EMPTY_STACK. It may get constructed twice,
67 // but it is benign, the results are the same.
68 ::new ((void*)&NativeCallStack::EMPTY_STACK) NativeCallStack(0, false);
69
70 if (!MallocTracker::initialize(level) ||
71 !VirtualMemoryTracker::initialize(level)) {
72 level = NMT_off;
294 _bucket_over_threshold ++;
295 }
296 _longest_bucket_length = MAX2(_longest_bucket_length, length);
297 }
298 };
299
300
301 void MemTracker::tuning_statistics(outputStream* out) {
302 // NMT statistics
303 StatisticsWalker walker;
304 MallocSiteTable::walk_malloc_site(&walker);
305 walker.completed();
306
307 out->print_cr("Native Memory Tracking Statistics:");
308 out->print_cr("Malloc allocation site table size: %d", MallocSiteTable::hash_buckets());
309 out->print_cr(" Tracking stack depth: %d", NMT_TrackingStackDepth);
310 NOT_PRODUCT(out->print_cr("Peak concurrent access: %d", MallocSiteTable::access_peak_count());)
311 out->print_cr(" ");
312 walker.report_statistics(out);
313 }
|