44 */ 45 class MemBaseline VALUE_OBJ_CLASS_SPEC { 46 public: 47 enum BaselineThreshold { 48 SIZE_THRESHOLD = K // Only allocation size over this threshold will be baselined. 49 }; 50 51 enum BaselineType { 52 Not_baselined, 53 Summary_baselined, 54 Detail_baselined 55 }; 56 57 enum SortingOrder { 58 by_address, // by memory address 59 by_size, // by memory size 60 by_site // by call site where the memory is allocated from 61 }; 62 63 private: 64 // All baseline data is stored in this arena 65 Arena* _arena; 66 67 // Summary information 68 MallocMemorySnapshot* _malloc_memory_snapshot; 69 VirtualMemorySnapshot* _virtual_memory_snapshot; 70 71 size_t _class_count; 72 73 // Allocation sites information 74 // Malloc allocation sites 75 LinkedListImpl<MallocSite, ResourceObj::ARENA> 76 _malloc_sites; 77 78 // All virtual memory allocations 79 LinkedListImpl<ReservedMemoryRegion, ResourceObj::ARENA> 80 _virtual_memory_allocations; 81 82 // Virtual memory allocations by allocation sites, always in by_address 83 // order 84 LinkedListImpl<VirtualMemoryAllocationSite, ResourceObj::ARENA> 85 _virtual_memory_sites; 86 87 SortingOrder _malloc_sites_order; 88 SortingOrder _virtual_memory_sites_order; 89 90 BaselineType _baseline_type; 91 92 public: 93 // create a memory baseline 94 MemBaseline(): 95 _baseline_type(Not_baselined), 96 _class_count(0), 97 _arena(NULL), 98 _malloc_memory_snapshot(NULL), 99 _virtual_memory_snapshot(NULL), 100 _malloc_sites(NULL) { 101 } 102 103 ~MemBaseline() { 104 reset(); 105 if (_arena != NULL) { 106 delete _arena; 107 } 108 } 109 110 bool baseline(bool summaryOnly = true); 111 112 BaselineType baseline_type() const { return _baseline_type; } 113 114 MallocMemorySnapshot* malloc_memory_snapshot() const { 115 return _malloc_memory_snapshot; 116 } 117 118 VirtualMemorySnapshot* virtual_memory_snapshot() const { 119 return _virtual_memory_snapshot; 120 } 121 122 MallocSiteIterator malloc_sites(SortingOrder order); 123 VirtualMemorySiteIterator virtual_memory_sites(SortingOrder order); 124 125 // Virtual memory allocation iterator always returns in virtual memory 126 // base address order. 127 VirtualMemoryAllocationIterator virtual_memory_allocations() { 128 assert(!_virtual_memory_allocations.is_empty(), "Not detail baseline"); 129 return VirtualMemoryAllocationIterator(_virtual_memory_allocations.head()); 130 } 131 132 // Total reserved memory = total malloc'd memory + total reserved virtual 133 // memory 134 size_t total_reserved_memory() const { 135 assert(baseline_type() != Not_baselined, "Not yet baselined"); 136 assert(_virtual_memory_snapshot != NULL, "No virtual memory snapshot"); 137 assert(_malloc_memory_snapshot != NULL, "No malloc memory snapshot"); 138 size_t amount = _malloc_memory_snapshot->total() + 139 _virtual_memory_snapshot->total_reserved(); 140 return amount; 141 } 142 143 // Total committed memory = total malloc'd memory + total committed 144 // virtual memory 145 size_t total_committed_memory() const { 146 assert(baseline_type() != Not_baselined, "Not yet baselined"); 147 assert(_virtual_memory_snapshot != NULL, 148 "Not a snapshot"); 149 size_t amount = _malloc_memory_snapshot->total() + 150 _virtual_memory_snapshot->total_committed(); 151 return amount; 152 } 153 154 size_t total_arena_memory() const { 155 assert(baseline_type() != Not_baselined, "Not yet baselined"); 156 assert(_malloc_memory_snapshot != NULL, "Not yet baselined"); 157 return _malloc_memory_snapshot->total_arena(); 158 } 159 160 size_t malloc_tracking_overhead() const { 161 assert(baseline_type() != Not_baselined, "Not yet baselined"); 162 return _malloc_memory_snapshot->malloc_overhead()->size(); 163 } 164 165 const MallocMemory* malloc_memory(MEMFLAGS flag) const { 166 assert(_malloc_memory_snapshot != NULL, "Not a snapshot"); 167 return _malloc_memory_snapshot->by_type(flag); 168 } 169 170 const VirtualMemory* virtual_memory(MEMFLAGS flag) const { 171 assert(_virtual_memory_snapshot != NULL, "Not a snapshot"); 172 return _virtual_memory_snapshot->by_type(flag); 173 } 174 175 176 size_t class_count() const { 177 assert(baseline_type() != Not_baselined, "Not yet baselined"); 178 return _class_count; 179 } 180 181 size_t thread_count() const { 182 assert(baseline_type() != Not_baselined, "Not yet baselined"); 183 assert(_malloc_memory_snapshot != NULL, "Baselined?"); 184 return _malloc_memory_snapshot->thread_count(); 185 } 186 187 // reset the baseline for reuse 188 void reset() { 189 _baseline_type = Not_baselined; 190 _malloc_memory_snapshot = NULL; 191 _virtual_memory_snapshot = NULL; 192 _class_count = 0; 193 194 _malloc_sites = NULL; 195 _virtual_memory_sites = NULL; 196 _virtual_memory_allocations = NULL; 197 198 if (_arena != NULL) { 199 _arena->destruct_contents(); 200 } 201 } 202 203 private: 204 // Baseline summary information 205 bool baseline_summary(); 206 207 // Baseline allocation sites (detail tracking only) 208 bool baseline_allocation_sites(); 209 210 // Aggregate virtual memory allocation by allocation sites 211 bool aggregate_virtual_memory_allocation_sites(); 212 213 Arena* arena() { return _arena; } 214 215 // Sorting allocation sites in different orders 216 // Sort allocation sites in size order 217 void malloc_sites_to_size_order(); 218 // Sort allocation sites in call site address order 219 void malloc_sites_to_allocation_site_order(); 220 221 // Sort allocation sites in reserved size order 222 void virtual_memory_sites_to_size_order(); 223 // Sort allocation sites in call site address order 224 void virtual_memory_sites_to_reservation_site_order(); 225 }; 226 227 #endif // INCLUDE_NMT 228 229 #endif // SHARE_VM_SERVICES_MEM_BASELINE_HPP | 44 */ 45 class MemBaseline VALUE_OBJ_CLASS_SPEC { 46 public: 47 enum BaselineThreshold { 48 SIZE_THRESHOLD = K // Only allocation size over this threshold will be baselined. 49 }; 50 51 enum BaselineType { 52 Not_baselined, 53 Summary_baselined, 54 Detail_baselined 55 }; 56 57 enum SortingOrder { 58 by_address, // by memory address 59 by_size, // by memory size 60 by_site // by call site where the memory is allocated from 61 }; 62 63 private: 64 // Summary information 65 MallocMemorySnapshot _malloc_memory_snapshot; 66 VirtualMemorySnapshot _virtual_memory_snapshot; 67 68 size_t _class_count; 69 70 // Allocation sites information 71 // Malloc allocation sites 72 LinkedListImpl<MallocSite> _malloc_sites; 73 74 // All virtual memory allocations 75 LinkedListImpl<ReservedMemoryRegion> _virtual_memory_allocations; 76 77 // Virtual memory allocations by allocation sites, always in by_address 78 // order 79 LinkedListImpl<VirtualMemoryAllocationSite> _virtual_memory_sites; 80 81 SortingOrder _malloc_sites_order; 82 SortingOrder _virtual_memory_sites_order; 83 84 BaselineType _baseline_type; 85 86 public: 87 // create a memory baseline 88 MemBaseline(): 89 _baseline_type(Not_baselined), 90 _class_count(0) { 91 } 92 93 ~MemBaseline() { 94 reset(); 95 } 96 97 bool baseline(bool summaryOnly = true); 98 99 BaselineType baseline_type() const { return _baseline_type; } 100 101 MallocMemorySnapshot* malloc_memory_snapshot() { 102 return &_malloc_memory_snapshot; 103 } 104 105 VirtualMemorySnapshot* virtual_memory_snapshot() { 106 return &_virtual_memory_snapshot; 107 } 108 109 MallocSiteIterator malloc_sites(SortingOrder order); 110 VirtualMemorySiteIterator virtual_memory_sites(SortingOrder order); 111 112 // Virtual memory allocation iterator always returns in virtual memory 113 // base address order. 114 VirtualMemoryAllocationIterator virtual_memory_allocations() { 115 assert(!_virtual_memory_allocations.is_empty(), "Not detail baseline"); 116 return VirtualMemoryAllocationIterator(_virtual_memory_allocations.head()); 117 } 118 119 // Total reserved memory = total malloc'd memory + total reserved virtual 120 // memory 121 size_t total_reserved_memory() const { 122 assert(baseline_type() != Not_baselined, "Not yet baselined"); 123 size_t amount = _malloc_memory_snapshot.total() + 124 _virtual_memory_snapshot.total_reserved(); 125 return amount; 126 } 127 128 // Total committed memory = total malloc'd memory + total committed 129 // virtual memory 130 size_t total_committed_memory() const { 131 assert(baseline_type() != Not_baselined, "Not yet baselined"); 132 size_t amount = _malloc_memory_snapshot.total() + 133 _virtual_memory_snapshot.total_committed(); 134 return amount; 135 } 136 137 size_t total_arena_memory() const { 138 assert(baseline_type() != Not_baselined, "Not yet baselined"); 139 return _malloc_memory_snapshot.total_arena(); 140 } 141 142 size_t malloc_tracking_overhead() const { 143 assert(baseline_type() != Not_baselined, "Not yet baselined"); 144 MemBaseline* bl = const_cast<MemBaseline*>(this); 145 return bl->_malloc_memory_snapshot.malloc_overhead()->size(); 146 } 147 148 MallocMemory* malloc_memory(MEMFLAGS flag) { 149 assert(baseline_type() != Not_baselined, "Not yet baselined"); 150 return _malloc_memory_snapshot.by_type(flag); 151 } 152 153 VirtualMemory* virtual_memory(MEMFLAGS flag) { 154 assert(baseline_type() != Not_baselined, "Not yet baselined"); 155 return _virtual_memory_snapshot.by_type(flag); 156 } 157 158 159 size_t class_count() const { 160 assert(baseline_type() != Not_baselined, "Not yet baselined"); 161 return _class_count; 162 } 163 164 size_t thread_count() const { 165 assert(baseline_type() != Not_baselined, "Not yet baselined"); 166 return _malloc_memory_snapshot.thread_count(); 167 } 168 169 // reset the baseline for reuse 170 void reset() { 171 _baseline_type = Not_baselined; 172 _malloc_memory_snapshot.reset(); 173 _virtual_memory_snapshot.reset(); 174 _class_count = 0; 175 176 _malloc_sites.clear(); 177 _virtual_memory_sites.clear(); 178 _virtual_memory_allocations.clear(); 179 } 180 181 private: 182 // Baseline summary information 183 bool baseline_summary(); 184 185 // Baseline allocation sites (detail tracking only) 186 bool baseline_allocation_sites(); 187 188 // Aggregate virtual memory allocation by allocation sites 189 bool aggregate_virtual_memory_allocation_sites(); 190 191 // Sorting allocation sites in different orders 192 // Sort allocation sites in size order 193 void malloc_sites_to_size_order(); 194 // Sort allocation sites in call site address order 195 void malloc_sites_to_allocation_site_order(); 196 197 // Sort allocation sites in reserved size order 198 void virtual_memory_sites_to_size_order(); 199 // Sort allocation sites in call site address order 200 void virtual_memory_sites_to_reservation_site_order(); 201 }; 202 203 #endif // INCLUDE_NMT 204 205 #endif // SHARE_VM_SERVICES_MEM_BASELINE_HPP |