< prev index next >

src/share/vm/runtime/perfMemory.cpp

Print this page




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

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

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


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




  34 #include "runtime/perfData.hpp"
  35 #include "runtime/perfMemory.hpp"
  36 #include "runtime/safepoint.hpp"
  37 #include "runtime/statSampler.hpp"
  38 #include "utilities/globalDefinitions.hpp"
  39 
  40 // Prefix of performance data file.
  41 const char               PERFDATA_NAME[] = "hsperfdata";
  42 
  43 // Add 1 for the '_' character between PERFDATA_NAME and pid. The '\0' terminating
  44 // character will be included in the sizeof(PERFDATA_NAME) operation.
  45 static const size_t PERFDATA_FILENAME_LEN = sizeof(PERFDATA_NAME) +
  46                                             UINT_CHARS + 1;
  47 
  48 char*                    PerfMemory::_start = NULL;
  49 char*                    PerfMemory::_end = NULL;
  50 char*                    PerfMemory::_top = NULL;
  51 size_t                   PerfMemory::_capacity = 0;
  52 jint                     PerfMemory::_initialized = false;
  53 PerfDataPrologue*        PerfMemory::_prologue = NULL;
  54 bool                     PerfMemory::_destroyed = false;
  55 
  56 void perfMemory_init() {
  57 
  58   if (!UsePerfData) return;
  59 
  60   PerfMemory::initialize();
  61 }
  62 
  63 void perfMemory_exit() {
  64 
  65   if (!UsePerfData) return;
  66   if (!PerfMemory::is_initialized()) return;
  67   if (PerfMemory::is_destroyed()) 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   _destroyed = true;




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


< prev index next >