< prev index next >
src/hotspot/share/services/memTracker.cpp
Print this page
*** 33,42 ****
--- 33,46 ----
#include "services/mallocTracker.inline.hpp"
#include "services/memTracker.hpp"
#include "utilities/defaultStream.hpp"
#include "utilities/vmError.hpp"
+ #ifdef _WINDOWS
+ #include <windows.h>
+ #endif
+
#ifdef SOLARIS
volatile bool NMT_stack_walkable = false;
#else
volatile bool NMT_stack_walkable = true;
#endif
*** 46,73 ****
MemBaseline MemTracker::_baseline;
Mutex* MemTracker::_query_lock = NULL;
bool MemTracker::_is_nmt_env_valid = true;
NMT_TrackingLevel MemTracker::init_tracking_level() {
NMT_TrackingLevel level = NMT_off;
! char buf[64];
! jio_snprintf(buf, sizeof(buf), "NMT_LEVEL_%d", os::current_process_id());
! const char *nmt_option = ::getenv(buf);
! if (nmt_option != NULL) {
! if (strcmp(nmt_option, "summary") == 0) {
level = NMT_summary;
! } else if (strcmp(nmt_option, "detail") == 0) {
level = NMT_detail;
! } else if (strcmp(nmt_option, "off") != 0) {
! // The option value is invalid
_is_nmt_env_valid = false;
}
-
// Remove the environment variable to avoid leaking to child processes
! os::unsetenv(buf);
}
// Construct NativeCallStack::EMPTY_STACK. It may get constructed twice,
// but it is benign, the results are the same.
::new ((void*)&NativeCallStack::EMPTY_STACK) NativeCallStack(0, false);
--- 50,84 ----
MemBaseline MemTracker::_baseline;
Mutex* MemTracker::_query_lock = NULL;
bool MemTracker::_is_nmt_env_valid = true;
+ static const size_t buffer_size = 64;
NMT_TrackingLevel MemTracker::init_tracking_level() {
+ char nmt_env_variable[buffer_size];
+ jio_snprintf(nmt_env_variable, sizeof(nmt_env_variable), "NMT_LEVEL_%d", os::current_process_id());
+ const char* nmt_env_value;
+ #ifdef _WINDOWS
+ // Read the NMT environment variable from the PEB instead of the CRT
+ char value[buffer_size];
+ nmt_env_value = GetEnvironmentVariable(nmt_env_variable, value, (DWORD)sizeof(value)) != 0 ? value : NULL;
+ #else
+ nmt_env_value = ::getenv(nmt_env_variable);
+ #endif
NMT_TrackingLevel level = NMT_off;
! if (nmt_env_value != NULL) {
! if (strcmp(nmt_env_value, "summary") == 0) {
level = NMT_summary;
! } else if (strcmp(nmt_env_value, "detail") == 0) {
level = NMT_detail;
! } else if (strcmp(nmt_env_value, "off") != 0) {
! // The value of the environment variable is invalid
_is_nmt_env_valid = false;
}
// Remove the environment variable to avoid leaking to child processes
! os::unsetenv(nmt_env_variable);
}
// Construct NativeCallStack::EMPTY_STACK. It may get constructed twice,
// but it is benign, the results are the same.
::new ((void*)&NativeCallStack::EMPTY_STACK) NativeCallStack(0, false);
< prev index next >