src/share/vm/services/mallocTracker.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8058818 Sdiff src/share/vm/services

src/share/vm/services/mallocTracker.cpp

Print this page




 123   if (to == NMT_detail) {
 124     assert(from == NMT_minimal || from == NMT_summary, "Just check");
 125     return MallocSiteTable::initialize();
 126   } else if (from == NMT_detail) {
 127     assert(to == NMT_minimal || to == NMT_summary, "Just check");
 128     MallocSiteTable::shutdown();
 129   }
 130   return true;
 131 }
 132 
 133 // Record a malloc memory allocation
 134 void* MallocTracker::record_malloc(void* malloc_base, size_t size, MEMFLAGS flags,
 135   const NativeCallStack& stack, NMT_TrackingLevel level) {
 136   void*         memblock;      // the address for user data
 137   MallocHeader* header = NULL;
 138 
 139   if (malloc_base == NULL) {
 140     return NULL;
 141   }
 142 
 143   // Check malloc size, size has to <= MAX_MALLOC_SIZE. This is only possible on 32-bit
 144   // systems, when malloc size >= 1GB, but is is safe to assume it won't happen.
 145   if (size > MAX_MALLOC_SIZE) {
 146     fatal("Should not use malloc for big memory block, use virtual memory instead");
 147   }
 148   // Uses placement global new operator to initialize malloc header
 149   switch(level) {
 150     case NMT_off:
 151       return malloc_base;
 152     case NMT_minimal: {
 153       MallocHeader* hdr = ::new (malloc_base) MallocHeader();
 154       break;
 155     }
 156     case NMT_summary: {

 157       header = ::new (malloc_base) MallocHeader(size, flags);
 158       break;
 159     }
 160     case NMT_detail: {

 161       header = ::new (malloc_base) MallocHeader(size, flags, stack);
 162       break;
 163     }
 164     default:
 165       ShouldNotReachHere();
 166   }
 167   memblock = (void*)((char*)malloc_base + sizeof(MallocHeader));
 168 
 169   // The alignment check: 8 bytes alignment for 32 bit systems.
 170   //                      16 bytes alignment for 64-bit systems.
 171   assert(((size_t)memblock & (sizeof(size_t) * 2 - 1)) == 0, "Alignment check");
 172 
 173   // Sanity check
 174   assert(get_memory_tracking_level(memblock) == level,
 175     "Wrong tracking level");
 176 
 177 #ifdef ASSERT
 178   if (level > NMT_minimal) {
 179     // Read back
 180     assert(get_size(memblock) == size,   "Wrong size");


 123   if (to == NMT_detail) {
 124     assert(from == NMT_minimal || from == NMT_summary, "Just check");
 125     return MallocSiteTable::initialize();
 126   } else if (from == NMT_detail) {
 127     assert(to == NMT_minimal || to == NMT_summary, "Just check");
 128     MallocSiteTable::shutdown();
 129   }
 130   return true;
 131 }
 132 
 133 // Record a malloc memory allocation
 134 void* MallocTracker::record_malloc(void* malloc_base, size_t size, MEMFLAGS flags,
 135   const NativeCallStack& stack, NMT_TrackingLevel level) {
 136   void*         memblock;      // the address for user data
 137   MallocHeader* header = NULL;
 138 
 139   if (malloc_base == NULL) {
 140     return NULL;
 141   }
 142 





 143   // Uses placement global new operator to initialize malloc header
 144   switch(level) {
 145     case NMT_off:
 146       return malloc_base;
 147     case NMT_minimal: {
 148       MallocHeader* hdr = ::new (malloc_base) MallocHeader();
 149       break;
 150     }
 151     case NMT_summary: {
 152       assert(size <= MAX_MALLOC_SIZE, "malloc size overrun for NMT");
 153       header = ::new (malloc_base) MallocHeader(size, flags);
 154       break;
 155     }
 156     case NMT_detail: {
 157       assert(size <= MAX_MALLOC_SIZE, "malloc size overrun for NMT");
 158       header = ::new (malloc_base) MallocHeader(size, flags, stack);
 159       break;
 160     }
 161     default:
 162       ShouldNotReachHere();
 163   }
 164   memblock = (void*)((char*)malloc_base + sizeof(MallocHeader));
 165 
 166   // The alignment check: 8 bytes alignment for 32 bit systems.
 167   //                      16 bytes alignment for 64-bit systems.
 168   assert(((size_t)memblock & (sizeof(size_t) * 2 - 1)) == 0, "Alignment check");
 169 
 170   // Sanity check
 171   assert(get_memory_tracking_level(memblock) == level,
 172     "Wrong tracking level");
 173 
 174 #ifdef ASSERT
 175   if (level > NMT_minimal) {
 176     // Read back
 177     assert(get_size(memblock) == size,   "Wrong size");
src/share/vm/services/mallocTracker.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File