< prev index next >

src/share/vm/services/memTracker.cpp

Print this page


   1 /*
   2  * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  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  *


  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 
   1 /*
   2  * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  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  *


  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 }

< prev index next >