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 #if PLATFORM_NATIVE_STACK_WALKING_SUPPORTED
57 level = NMT_detail;
58 #else
59 level = NMT_summary;
60 #endif // PLATFORM_NATIVE_STACK_WALKING_SUPPORTED
61 } else if (strcmp(nmt_option, "off") != 0) {
62 // The option value is invalid
63 _is_nmt_env_valid = false;
64 }
65
66 // Remove the environment variable to avoid leaking to child processes
67 os::unsetenv(buf);
68 }
69
70 // Construct NativeCallStack::EMPTY_STACK. It may get constructed twice,
71 // but it is benign, the results are the same.
72 ::new ((void*)&NativeCallStack::EMPTY_STACK) NativeCallStack(0, false);
306 _bucket_over_threshold ++;
307 }
308 _longest_bucket_length = MAX2(_longest_bucket_length, length);
309 }
310 };
311
312
313 void MemTracker::tuning_statistics(outputStream* out) {
314 // NMT statistics
315 StatisticsWalker walker;
316 MallocSiteTable::walk_malloc_site(&walker);
317 walker.completed();
318
319 out->print_cr("Native Memory Tracking Statistics:");
320 out->print_cr("Malloc allocation site table size: %d", MallocSiteTable::hash_buckets());
321 out->print_cr(" Tracking stack depth: %d", NMT_TrackingStackDepth);
322 NOT_PRODUCT(out->print_cr("Peak concurrent access: %d", MallocSiteTable::access_peak_count());)
323 out->print_cr(" ");
324 walker.report_statistics(out);
325 }
326
|
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 #if PLATFORM_NATIVE_STACK_WALKING_SUPPORTED
57 level = NMT_detail;
58 #else
59 level = NMT_summary;
60 #endif // PLATFORM_NATIVE_STACK_WALKING_SUPPORTED
61 } else if (strcmp(nmt_option, "off") != 0) {
62 // The option value is invalid
63 _is_nmt_env_valid = false;
64 }
65
66 // Remove the environment variable to avoid leaking to child processes
67 os::unsetenv(buf);
68 }
69
70 // Construct NativeCallStack::EMPTY_STACK. It may get constructed twice,
71 // but it is benign, the results are the same.
72 ::new ((void*)&NativeCallStack::EMPTY_STACK) NativeCallStack(0, false);
306 _bucket_over_threshold ++;
307 }
308 _longest_bucket_length = MAX2(_longest_bucket_length, length);
309 }
310 };
311
312
313 void MemTracker::tuning_statistics(outputStream* out) {
314 // NMT statistics
315 StatisticsWalker walker;
316 MallocSiteTable::walk_malloc_site(&walker);
317 walker.completed();
318
319 out->print_cr("Native Memory Tracking Statistics:");
320 out->print_cr("Malloc allocation site table size: %d", MallocSiteTable::hash_buckets());
321 out->print_cr(" Tracking stack depth: %d", NMT_TrackingStackDepth);
322 NOT_PRODUCT(out->print_cr("Peak concurrent access: %d", MallocSiteTable::access_peak_count());)
323 out->print_cr(" ");
324 walker.report_statistics(out);
325 }
|