< prev index next >

src/hotspot/share/runtime/perfMemory.cpp

Print this page




  36 #include "runtime/perfMemory.hpp"
  37 #include "runtime/safepoint.hpp"
  38 #include "runtime/statSampler.hpp"
  39 #include "utilities/align.hpp"
  40 #include "utilities/globalDefinitions.hpp"
  41 
  42 // Prefix of performance data file.
  43 const char               PERFDATA_NAME[] = "hsperfdata";
  44 
  45 // Add 1 for the '_' character between PERFDATA_NAME and pid. The '\0' terminating
  46 // character will be included in the sizeof(PERFDATA_NAME) operation.
  47 static const size_t PERFDATA_FILENAME_LEN = sizeof(PERFDATA_NAME) +
  48                                             UINT_CHARS + 1;
  49 
  50 char*                    PerfMemory::_start = NULL;
  51 char*                    PerfMemory::_end = NULL;
  52 char*                    PerfMemory::_top = NULL;
  53 size_t                   PerfMemory::_capacity = 0;
  54 jint                     PerfMemory::_initialized = false;
  55 PerfDataPrologue*        PerfMemory::_prologue = NULL;

  56 
  57 void perfMemory_init() {
  58 
  59   if (!UsePerfData) return;
  60 
  61   PerfMemory::initialize();
  62 }
  63 
  64 void perfMemory_exit() {
  65 
  66   if (!UsePerfData) return;
  67   if (!PerfMemory::is_initialized()) return;

  68 
  69   // Only destroy PerfData objects if we're at a safepoint and the
  70   // StatSampler is not active. Otherwise, we risk removing PerfData
  71   // objects that are currently being used by running JavaThreads
  72   // or the StatSampler. This method is invoked while we are not at
  73   // a safepoint during a VM abort so leaving the PerfData objects
  74   // around may also help diagnose the failure. In rare cases,
  75   // PerfData objects are used in parallel with a safepoint. See
  76   // the work around in PerfDataManager::destroy().
  77   //
  78   if (SafepointSynchronize::is_at_safepoint() && !StatSampler::is_active()) {
  79     PerfDataManager::destroy();
  80   }
  81 
  82   // Remove the persistent external resources, if any. This method
  83   // does not unmap or invalidate any virtual memory allocated during
  84   // initialization.
  85   //
  86   PerfMemory::destroy();
  87 }


 179       warning("PerfMemory Overflow Occurred.\n"
 180               "\tCapacity = " SIZE_FORMAT " bytes"
 181               "  Used = " SIZE_FORMAT " bytes"
 182               "  Overflow = " INT32_FORMAT " bytes"
 183               "\n\tUse -XX:PerfDataMemorySize=<size> to specify larger size.",
 184               PerfMemory::capacity(),
 185               PerfMemory::used(),
 186               _prologue->overflow);
 187     }
 188   }
 189 
 190   if (_start != NULL) {
 191 
 192     // this state indicates that the contiguous memory region was successfully
 193     // and that persistent resources may need to be cleaned up. This is
 194     // expected to be the typical condition.
 195     //
 196     delete_memory_region();
 197   }
 198 
 199   _start = NULL;
 200   _end = NULL;
 201   _top = NULL;
 202   _prologue = NULL;
 203   _capacity = 0;
 204 }
 205 
 206 // allocate an aligned block of memory from the PerfData memory
 207 // region. This method assumes that the PerfData memory region
 208 // was aligned on a double word boundary when created.
 209 //
 210 char* PerfMemory::alloc(size_t size) {
 211 
 212   if (!UsePerfData) return NULL;
 213 
 214   MutexLocker ml(PerfDataMemAlloc_lock);
 215 
 216   assert(_prologue != NULL, "called before initialization");
 217 
 218   // check that there is enough memory for this request
 219   if ((_top + size) >= _end) {
 220 
 221     _prologue->overflow += (jint)size;
 222 
 223     return NULL;




  36 #include "runtime/perfMemory.hpp"
  37 #include "runtime/safepoint.hpp"
  38 #include "runtime/statSampler.hpp"
  39 #include "utilities/align.hpp"
  40 #include "utilities/globalDefinitions.hpp"
  41 
  42 // Prefix of performance data file.
  43 const char               PERFDATA_NAME[] = "hsperfdata";
  44 
  45 // Add 1 for the '_' character between PERFDATA_NAME and pid. The '\0' terminating
  46 // character will be included in the sizeof(PERFDATA_NAME) operation.
  47 static const size_t PERFDATA_FILENAME_LEN = sizeof(PERFDATA_NAME) +
  48                                             UINT_CHARS + 1;
  49 
  50 char*                    PerfMemory::_start = NULL;
  51 char*                    PerfMemory::_end = NULL;
  52 char*                    PerfMemory::_top = NULL;
  53 size_t                   PerfMemory::_capacity = 0;
  54 jint                     PerfMemory::_initialized = false;
  55 PerfDataPrologue*        PerfMemory::_prologue = NULL;
  56 bool                     PerfMemory::_destroyed = false;
  57 
  58 void perfMemory_init() {
  59 
  60   if (!UsePerfData) return;
  61 
  62   PerfMemory::initialize();
  63 }
  64 
  65 void perfMemory_exit() {
  66 
  67   if (!UsePerfData) return;
  68   if (!PerfMemory::is_initialized()) return;
  69   if (PerfMemory::is_destroyed()) return;
  70 
  71   // Only destroy PerfData objects if we're at a safepoint and the
  72   // StatSampler is not active. Otherwise, we risk removing PerfData
  73   // objects that are currently being used by running JavaThreads
  74   // or the StatSampler. This method is invoked while we are not at
  75   // a safepoint during a VM abort so leaving the PerfData objects
  76   // around may also help diagnose the failure. In rare cases,
  77   // PerfData objects are used in parallel with a safepoint. See
  78   // the work around in PerfDataManager::destroy().
  79   //
  80   if (SafepointSynchronize::is_at_safepoint() && !StatSampler::is_active()) {
  81     PerfDataManager::destroy();
  82   }
  83 
  84   // Remove the persistent external resources, if any. This method
  85   // does not unmap or invalidate any virtual memory allocated during
  86   // initialization.
  87   //
  88   PerfMemory::destroy();
  89 }


 181       warning("PerfMemory Overflow Occurred.\n"
 182               "\tCapacity = " SIZE_FORMAT " bytes"
 183               "  Used = " SIZE_FORMAT " bytes"
 184               "  Overflow = " INT32_FORMAT " bytes"
 185               "\n\tUse -XX:PerfDataMemorySize=<size> to specify larger size.",
 186               PerfMemory::capacity(),
 187               PerfMemory::used(),
 188               _prologue->overflow);
 189     }
 190   }
 191 
 192   if (_start != NULL) {
 193 
 194     // this state indicates that the contiguous memory region was successfully
 195     // and that persistent resources may need to be cleaned up. This is
 196     // expected to be the typical condition.
 197     //
 198     delete_memory_region();
 199   }
 200 
 201   _destroyed = true;




 202 }
 203 
 204 // allocate an aligned block of memory from the PerfData memory
 205 // region. This method assumes that the PerfData memory region
 206 // was aligned on a double word boundary when created.
 207 //
 208 char* PerfMemory::alloc(size_t size) {
 209 
 210   if (!UsePerfData) return NULL;
 211 
 212   MutexLocker ml(PerfDataMemAlloc_lock);
 213 
 214   assert(_prologue != NULL, "called before initialization");
 215 
 216   // check that there is enough memory for this request
 217   if ((_top + size) >= _end) {
 218 
 219     _prologue->overflow += (jint)size;
 220 
 221     return NULL;


< prev index next >