< prev index next >

src/hotspot/share/services/memTracker.cpp

Print this page
rev 53982 : Thread stack tracking
   1 /*
   2  * Copyright (c) 2012, 2018, 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  *
  23  */
  24 #include "precompiled.hpp"
  25 #include "jvm.h"
  26 
  27 #include "runtime/orderAccess.hpp"
  28 #include "runtime/vmThread.hpp"
  29 #include "runtime/vmOperations.hpp"
  30 #include "services/memBaseline.hpp"
  31 #include "services/memReporter.hpp"
  32 #include "services/mallocTracker.inline.hpp"
  33 #include "services/memTracker.hpp"

  34 #include "utilities/debug.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 bool MemTracker::_is_nmt_env_valid = true;
  53 


  75     } else if (strcmp(nmt_env_value, "detail") == 0) {
  76       level = NMT_detail;
  77     } else if (strcmp(nmt_env_value, "off") != 0) {
  78       // The value of the environment variable is invalid
  79       _is_nmt_env_valid = false;
  80     }
  81     // Remove the environment variable to avoid leaking to child processes
  82     os::unsetenv(nmt_env_variable);
  83   }
  84 
  85   if (!MallocTracker::initialize(level) ||
  86       !VirtualMemoryTracker::initialize(level)) {
  87     level = NMT_off;
  88   }
  89   return level;
  90 }
  91 
  92 void MemTracker::init() {
  93   NMT_TrackingLevel level = tracking_level();
  94   if (level >= NMT_summary) {
  95     if (!VirtualMemoryTracker::late_initialize(level)) {

  96       shutdown();
  97       return;
  98     }
  99   }
 100 }
 101 
 102 bool MemTracker::check_launcher_nmt_support(const char* value) {
 103   if (strcmp(value, "=detail") == 0) {
 104     if (MemTracker::tracking_level() != NMT_detail) {
 105       return false;
 106     }
 107   } else if (strcmp(value, "=summary") == 0) {
 108     if (MemTracker::tracking_level() != NMT_summary) {
 109       return false;
 110     }
 111   } else if (strcmp(value, "=off") == 0) {
 112     if (MemTracker::tracking_level() != NMT_off) {
 113       return false;
 114     }
 115   } else {


 147   // We can only shutdown NMT to minimal tracking level if it is ever on.
 148   if (tracking_level () > NMT_minimal) {
 149     transition_to(NMT_minimal);
 150   }
 151 }
 152 
 153 bool MemTracker::transition_to(NMT_TrackingLevel level) {
 154   NMT_TrackingLevel current_level = tracking_level();
 155 
 156   assert(level != NMT_off || current_level == NMT_off, "Cannot transition NMT to off");
 157 
 158   if (current_level == level) {
 159     return true;
 160   } else if (current_level > level) {
 161     // Downgrade tracking level, we want to lower the tracking level first
 162     _tracking_level = level;
 163     // Make _tracking_level visible immediately.
 164     OrderAccess::fence();
 165     VirtualMemoryTracker::transition(current_level, level);
 166     MallocTracker::transition(current_level, level);

 167   } else {
 168     // Upgrading tracking level is not supported and has never been supported.
 169     // Allocating and deallocating malloc tracking structures is not thread safe and
 170     // leads to inconsistencies unless a lot coarser locks are added.
 171   }
 172   return true;
 173 }
 174 
 175 void MemTracker::report(bool summary_only, outputStream* output) {
 176  assert(output != NULL, "No output stream");
 177   MemBaseline baseline;
 178   if (baseline.baseline(summary_only)) {
 179     if (summary_only) {
 180       MemSummaryReporter rpt(baseline, output);
 181       rpt.report();
 182     } else {
 183       MemDetailReporter rpt(baseline, output);
 184       rpt.report();
 185       output->print("Metaspace:");
 186       // Metadata reporting requires a safepoint, so avoid it if VM is not in good state.


   1 /*
   2  * Copyright (c) 2012, 2019, 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  *
  23  */
  24 #include "precompiled.hpp"
  25 #include "jvm.h"
  26 
  27 #include "runtime/orderAccess.hpp"
  28 #include "runtime/vmThread.hpp"
  29 #include "runtime/vmOperations.hpp"
  30 #include "services/memBaseline.hpp"
  31 #include "services/memReporter.hpp"
  32 #include "services/mallocTracker.inline.hpp"
  33 #include "services/memTracker.hpp"
  34 #include "services/threadStackTracker.hpp"
  35 #include "utilities/debug.hpp"
  36 #include "utilities/defaultStream.hpp"
  37 #include "utilities/vmError.hpp"
  38 
  39 #ifdef _WINDOWS
  40 #include <windows.h>
  41 #endif
  42 
  43 #ifdef SOLARIS
  44   volatile bool NMT_stack_walkable = false;
  45 #else
  46   volatile bool NMT_stack_walkable = true;
  47 #endif
  48 
  49 volatile NMT_TrackingLevel MemTracker::_tracking_level = NMT_unknown;
  50 NMT_TrackingLevel MemTracker::_cmdline_tracking_level = NMT_unknown;
  51 
  52 MemBaseline MemTracker::_baseline;
  53 bool MemTracker::_is_nmt_env_valid = true;
  54 


  76     } else if (strcmp(nmt_env_value, "detail") == 0) {
  77       level = NMT_detail;
  78     } else if (strcmp(nmt_env_value, "off") != 0) {
  79       // The value of the environment variable is invalid
  80       _is_nmt_env_valid = false;
  81     }
  82     // Remove the environment variable to avoid leaking to child processes
  83     os::unsetenv(nmt_env_variable);
  84   }
  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         !ThreadStackTracker::late_initialize(level)) {
  98       shutdown();
  99       return;
 100     }
 101   }
 102 }
 103 
 104 bool MemTracker::check_launcher_nmt_support(const char* value) {
 105   if (strcmp(value, "=detail") == 0) {
 106     if (MemTracker::tracking_level() != NMT_detail) {
 107       return false;
 108     }
 109   } else if (strcmp(value, "=summary") == 0) {
 110     if (MemTracker::tracking_level() != NMT_summary) {
 111       return false;
 112     }
 113   } else if (strcmp(value, "=off") == 0) {
 114     if (MemTracker::tracking_level() != NMT_off) {
 115       return false;
 116     }
 117   } else {


 149   // We can only shutdown NMT to minimal tracking level if it is ever on.
 150   if (tracking_level () > NMT_minimal) {
 151     transition_to(NMT_minimal);
 152   }
 153 }
 154 
 155 bool MemTracker::transition_to(NMT_TrackingLevel level) {
 156   NMT_TrackingLevel current_level = tracking_level();
 157 
 158   assert(level != NMT_off || current_level == NMT_off, "Cannot transition NMT to off");
 159 
 160   if (current_level == level) {
 161     return true;
 162   } else if (current_level > level) {
 163     // Downgrade tracking level, we want to lower the tracking level first
 164     _tracking_level = level;
 165     // Make _tracking_level visible immediately.
 166     OrderAccess::fence();
 167     VirtualMemoryTracker::transition(current_level, level);
 168     MallocTracker::transition(current_level, level);
 169     ThreadStackTracker::transition(current_level, level);
 170   } else {
 171     // Upgrading tracking level is not supported and has never been supported.
 172     // Allocating and deallocating malloc tracking structures is not thread safe and
 173     // leads to inconsistencies unless a lot coarser locks are added.
 174   }
 175   return true;
 176 }
 177 
 178 void MemTracker::report(bool summary_only, outputStream* output) {
 179  assert(output != NULL, "No output stream");
 180   MemBaseline baseline;
 181   if (baseline.baseline(summary_only)) {
 182     if (summary_only) {
 183       MemSummaryReporter rpt(baseline, output);
 184       rpt.report();
 185     } else {
 186       MemDetailReporter rpt(baseline, output);
 187       rpt.report();
 188       output->print("Metaspace:");
 189       // Metadata reporting requires a safepoint, so avoid it if VM is not in good state.


< prev index next >