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 #include "jvm.h" 26 27 #include "runtime/mutex.hpp" 28 #include "runtime/orderAccess.hpp" 29 #include "runtime/vmThread.hpp" 30 #include "runtime/vm_operations.hpp" 31 #include "services/memBaseline.hpp" 32 #include "services/memReporter.hpp" 33 #include "services/mallocTracker.inline.hpp" 34 #include "services/memTracker.hpp" 35 #include "utilities/defaultStream.hpp" 36 #include "utilities/vmError.hpp" 37 38 #ifdef SOLARIS 39 volatile bool NMT_stack_walkable = false; 40 #else 41 volatile bool NMT_stack_walkable = true; 42 #endif 43 44 volatile NMT_TrackingLevel MemTracker::_tracking_level = NMT_unknown; 45 NMT_TrackingLevel MemTracker::_cmdline_tracking_level = NMT_unknown; 46 47 MemBaseline MemTracker::_baseline; 48 Mutex* MemTracker::_query_lock = NULL; 49 bool MemTracker::_is_nmt_env_valid = true; 50 51 52 NMT_TrackingLevel MemTracker::init_tracking_level() { 53 NMT_TrackingLevel level = NMT_off; 54 char buf[64]; 55 jio_snprintf(buf, sizeof(buf), "NMT_LEVEL_%d", os::current_process_id()); 56 const char *nmt_option = ::getenv(buf); 57 if (nmt_option != NULL) { 58 if (strcmp(nmt_option, "summary") == 0) { 59 level = NMT_summary; 60 } else if (strcmp(nmt_option, "detail") == 0) { 61 level = NMT_detail; 62 } else if (strcmp(nmt_option, "off") != 0) { 63 // The option value is invalid 64 _is_nmt_env_valid = false; 65 } 66 67 // Remove the environment variable to avoid leaking to child processes 68 os::unsetenv(buf); 69 } 70 71 // Construct NativeCallStack::EMPTY_STACK. It may get constructed twice, 72 // but it is benign, the results are the same. 73 ::new ((void*)&NativeCallStack::EMPTY_STACK) NativeCallStack(0, false); 74 75 if (!MallocTracker::initialize(level) || 76 !VirtualMemoryTracker::initialize(level)) { 77 level = NMT_off; 78 } 79 return level; 80 } 81 82 void MemTracker::init() { 83 NMT_TrackingLevel level = tracking_level(); 84 if (level >= NMT_summary) { 85 if (!VirtualMemoryTracker::late_initialize(level)) { 86 shutdown(); 87 return; 88 } | 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 #include "jvm.h" 26 27 #include "runtime/mutex.hpp" 28 #include "runtime/orderAccess.hpp" 29 #include "runtime/vmThread.hpp" 30 #include "runtime/vm_operations.hpp" 31 #include "services/memBaseline.hpp" 32 #include "services/memReporter.hpp" 33 #include "services/mallocTracker.inline.hpp" 34 #include "services/memTracker.hpp" 35 #include "utilities/defaultStream.hpp" 36 #include "utilities/vmError.hpp" 37 38 #ifdef _WINDOWS 39 #include <windows.h> 40 #endif 41 42 #ifdef SOLARIS 43 volatile bool NMT_stack_walkable = false; 44 #else 45 volatile bool NMT_stack_walkable = true; 46 #endif 47 48 volatile NMT_TrackingLevel MemTracker::_tracking_level = NMT_unknown; 49 NMT_TrackingLevel MemTracker::_cmdline_tracking_level = NMT_unknown; 50 51 MemBaseline MemTracker::_baseline; 52 Mutex* MemTracker::_query_lock = NULL; 53 bool MemTracker::_is_nmt_env_valid = true; 54 55 static const size_t buffer_size = 64; 56 57 NMT_TrackingLevel MemTracker::init_tracking_level() { 58 char nmt_env_variable[buffer_size]; 59 jio_snprintf(nmt_env_variable, sizeof(nmt_env_variable), "NMT_LEVEL_%d", os::current_process_id()); 60 const char* nmt_env_value; 61 #ifdef _WINDOWS 62 // Read the NMT environment variable from the PEB instead of the CRT 63 char value[buffer_size]; 64 nmt_env_value = GetEnvironmentVariable(nmt_env_variable, value, (DWORD)sizeof(value)) != 0 ? value : NULL; 65 #else 66 nmt_env_value = ::getenv(nmt_env_variable); 67 #endif 68 NMT_TrackingLevel level = NMT_off; 69 if (nmt_env_value != NULL) { 70 if (strcmp(nmt_env_value, "summary") == 0) { 71 level = NMT_summary; 72 } else if (strcmp(nmt_env_value, "detail") == 0) { 73 level = NMT_detail; 74 } else if (strcmp(nmt_env_value, "off") != 0) { 75 // The value of the environment variable is invalid 76 _is_nmt_env_valid = false; 77 } 78 // Remove the environment variable to avoid leaking to child processes 79 os::unsetenv(nmt_env_variable); 80 } 81 82 // Construct NativeCallStack::EMPTY_STACK. It may get constructed twice, 83 // but it is benign, the results are the same. 84 ::new ((void*)&NativeCallStack::EMPTY_STACK) NativeCallStack(0, false); 85 86 if (!MallocTracker::initialize(level) || 87 !VirtualMemoryTracker::initialize(level)) { 88 level = NMT_off; 89 } 90 return level; 91 } 92 93 void MemTracker::init() { 94 NMT_TrackingLevel level = tracking_level(); 95 if (level >= NMT_summary) { 96 if (!VirtualMemoryTracker::late_initialize(level)) { 97 shutdown(); 98 return; 99 } |