|
57 | 57 | public class NativeMemoryTracking { |
58 | 58 | private static final UnsignedWord ALIGNMENT = WordFactory.unsigned(16); |
59 | 59 | private static final int MAGIC = 0xF0F1F2F3; |
| 60 | + private static final long KB = 1024; |
60 | 61 |
|
61 | 62 | private final NmtMallocMemoryInfo[] mallocCategories; |
62 | 63 | private final NmtVirtualMemoryInfo[] virtualCategories; |
@@ -208,54 +209,81 @@ void recordFree(UnsignedWord size, NmtCategory category) { |
208 | 209 | } |
209 | 210 |
|
210 | 211 | @Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true) |
211 | | - public long getUsedMemory(NmtCategory category) { |
| 212 | + public long getMallocMemory(NmtCategory category) { |
212 | 213 | return getMallocInfo(category).getUsed(); |
213 | 214 | } |
214 | 215 |
|
215 | 216 | @Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true) |
216 | | - public long getPeakUsedMemory(NmtCategory category) { |
| 217 | + public long getMallocCount(NmtCategory category) { |
| 218 | + return getMallocInfo(category).getCount(); |
| 219 | + } |
| 220 | + |
| 221 | + @Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true) |
| 222 | + public long getPeakMallocMemory(NmtCategory category) { |
217 | 223 | return getMallocInfo(category).getPeakUsed(); |
218 | 224 | } |
219 | 225 |
|
220 | 226 | @Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true) |
221 | | - public long getCountAtPeakUsage(NmtCategory category) { |
| 227 | + public long getCountAtPeakMallocMemory(NmtCategory category) { |
222 | 228 | return getMallocInfo(category).getCountAtPeakUsage(); |
223 | 229 | } |
224 | 230 |
|
225 | 231 | @Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true) |
226 | | - public long getTotalCount() { |
| 232 | + public long getTotalMallocCount() { |
227 | 233 | return mallocTotal.getCount(); |
228 | 234 | } |
229 | 235 |
|
230 | 236 | @Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true) |
231 | | - public long getTotalUsedMemory() { |
| 237 | + public long getTotalMallocMemory() { |
232 | 238 | return mallocTotal.getUsed(); |
233 | 239 | } |
234 | 240 |
|
235 | 241 | @Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true) |
236 | | - public long getPeakTotalUsedMemory() { |
| 242 | + public long getPeakTotalMallocMemory() { |
237 | 243 | return mallocTotal.getPeakUsed(); |
238 | 244 | } |
239 | 245 |
|
240 | 246 | @Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true) |
241 | | - public long getCountAtTotalPeakUsage() { |
| 247 | + public long getCountAtPeakTotalMallocMemory() { |
242 | 248 | return mallocTotal.getCountAtPeakUsage(); |
243 | 249 | } |
244 | 250 |
|
245 | | - public long getReservedByCategory(NmtCategory category) { |
| 251 | + @Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true) |
| 252 | + public long getReservedVirtualMemory(NmtCategory category) { |
246 | 253 | return NativeMemoryTracking.singleton().getVirtualInfo(category).getReservedSize(); |
247 | 254 | } |
248 | 255 |
|
249 | | - public long getCommittedByCategory(NmtCategory category) { |
| 256 | + @Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true) |
| 257 | + public long getCommittedVirtualMemory(NmtCategory category) { |
250 | 258 | return getVirtualInfo(category).getCommittedSize(); |
251 | 259 | } |
252 | 260 |
|
253 | | - public long getPeakCommittedByCategory(NmtCategory category) { |
| 261 | + public long getPeakReservedVirtualMemory(NmtCategory category) { |
| 262 | + return getVirtualInfo(category).getPeakReservedSize(); |
| 263 | + } |
| 264 | + |
| 265 | + public long getPeakCommittedVirtualMemory(NmtCategory category) { |
254 | 266 | return getVirtualInfo(category).getPeakCommittedSize(); |
255 | 267 | } |
256 | 268 |
|
257 | | - public long getPeakReservedByCategory(NmtCategory category) { |
258 | | - return getVirtualInfo(category).getPeakReservedSize(); |
| 269 | + @Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true) |
| 270 | + public long getTotalReservedVirtualMemory() { |
| 271 | + return virtualTotal.getReservedSize(); |
| 272 | + } |
| 273 | + |
| 274 | + @Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true) |
| 275 | + public long getTotalCommittedVirtualMemory() { |
| 276 | + return virtualTotal.getCommittedSize(); |
| 277 | + } |
| 278 | + |
| 279 | + @Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true) |
| 280 | + public long getPeakTotalReservedVirtualMemory() { |
| 281 | + return virtualTotal.getPeakReservedSize(); |
| 282 | + } |
| 283 | + |
| 284 | + @Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true) |
| 285 | + public long getPeakTotalCommittedVirtualMemory() { |
| 286 | + return virtualTotal.getPeakCommittedSize(); |
259 | 287 | } |
260 | 288 |
|
261 | 289 | @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) |
@@ -289,32 +317,43 @@ public static RuntimeSupport.Hook shutdownHook() { |
289 | 317 |
|
290 | 318 | private void printStatistics() { |
291 | 319 | if (VMInspectionOptions.PrintNMTStatistics.getValue()) { |
292 | | - System.out.println(); |
293 | | - System.out.println("Native memory tracking"); |
294 | | - System.out.println(" Peak total used memory: " + getPeakTotalUsedMemory() + " bytes"); |
295 | | - System.out.println(" Peak Total committed memory: " + virtualTotal.getPeakCommittedSize() + " bytes"); |
296 | | - System.out.println(" Peak Total reserved memory: " + virtualTotal.getPeakReservedSize() + " bytes"); |
297 | | - System.out.println(" Total alive allocations at peak usage: " + getCountAtTotalPeakUsage()); |
298 | | - System.out.println(" Total used memory: " + getTotalUsedMemory() + " bytes"); |
299 | | - System.out.println(" Total alive allocations: " + getTotalCount()); |
300 | | - System.out.println(" Total committed memory: " + virtualTotal.getCommittedSize() + " bytes"); |
301 | | - System.out.println(" Total reserved memory: " + virtualTotal.getReservedSize() + " bytes"); |
302 | | - |
303 | | - for (int i = 0; i < NmtCategory.values().length; i++) { |
304 | | - String name = NmtCategory.values()[i].getName(); |
305 | | - NmtMallocMemoryInfo info = getMallocInfo(i); |
306 | | - NmtVirtualMemoryInfo vMemInfo = getVirtualInfo(i); |
307 | | - |
308 | | - System.out.println(" " + name + " peak used memory: " + info.getPeakUsed() + " bytes"); |
309 | | - System.out.println(" " + name + " alive allocations at peak: " + info.getCountAtPeakUsage()); |
310 | | - System.out.println(" " + name + " currently used memory: " + info.getUsed() + " bytes"); |
311 | | - System.out.println(" " + name + " currently alive allocations: " + info.getCount()); |
312 | | - System.out.println(" " + name + " committed memory: " + vMemInfo.getCommittedSize()); |
313 | | - System.out.println(" " + name + " reserved memory: " + vMemInfo.getReservedSize()); |
314 | | - System.out.println(" " + name + " peak committed memory: " + vMemInfo.getPeakCommittedSize()); |
315 | | - System.out.println(" " + name + " peak reserved memory: " + vMemInfo.getPeakReservedSize()); |
316 | | - } |
| 320 | + System.out.println(generateReportString()); |
| 321 | + } |
| 322 | + } |
| 323 | + |
| 324 | + public String generateReportString() { |
| 325 | + |
| 326 | + StringBuilder stringBuilder = new StringBuilder(3000); |
| 327 | + |
| 328 | + stringBuilder.append("\n"); |
| 329 | + stringBuilder.append("Native memory tracking").append("\n\n"); |
| 330 | + |
| 331 | + stringBuilder.append("Total").append("\n"); |
| 332 | + long reservedTotal = (getTotalReservedVirtualMemory() + getTotalMallocMemory()) / KB; |
| 333 | + long committedTotal = (getTotalCommittedVirtualMemory() + getTotalMallocMemory()) / KB; |
| 334 | + stringBuilder.append("\t").append("(reserved=").append(reservedTotal).append("KB, committed=").append(committedTotal).append("KB)").append("\n"); |
| 335 | + stringBuilder.append("\t").append("(malloc=").append(getTotalMallocMemory() / KB).append("KB, count=").append(getTotalMallocCount()).append(")").append("\n"); |
| 336 | + stringBuilder.append("\t").append("(peak malloc=").append(getPeakTotalMallocMemory() / KB).append("KB, count at peak=").append(getCountAtPeakTotalMallocMemory()).append(")").append("\n"); |
| 337 | + stringBuilder.append("\t").append("(mmap: reserved=").append(getTotalReservedVirtualMemory() / KB).append("KB, committed=").append(getTotalCommittedVirtualMemory() / KB).append("KB)") |
| 338 | + .append("\n"); |
| 339 | + stringBuilder.append("\t").append("(mmap: peak reserved=").append(getPeakTotalReservedVirtualMemory() / KB).append("KB, peak committed=").append(getPeakTotalCommittedVirtualMemory() / KB) |
| 340 | + .append("KB)").append("\n"); |
| 341 | + |
| 342 | + for (int i = 0; i < NmtCategory.values().length; i++) { |
| 343 | + NmtCategory category = NmtCategory.values()[i]; |
| 344 | + stringBuilder.append(category.getName()).append("\n"); |
| 345 | + long reserved = (getReservedVirtualMemory(category) + getMallocMemory(category)) / KB; |
| 346 | + long committed = (getCommittedVirtualMemory(category) + getMallocMemory(category)) / KB; |
| 347 | + stringBuilder.append("\t").append("(reserved=").append(reserved).append("KB, committed=").append(committed).append("KB)").append("\n"); |
| 348 | + stringBuilder.append("\t").append("(malloc=").append(getMallocMemory(category) / KB).append("KB, count=").append(getMallocCount(category)).append(")").append("\n"); |
| 349 | + stringBuilder.append("\t").append("(peak malloc=").append(getPeakMallocMemory(category) / KB).append("KB, count at peak=").append(getCountAtPeakMallocMemory(category)).append(")") |
| 350 | + .append("\n"); |
| 351 | + stringBuilder.append("\t").append("(mmap: reserved=").append(getReservedVirtualMemory(category) / KB).append("KB, committed=").append(getCommittedVirtualMemory(category) / KB) |
| 352 | + .append("KB)").append("\n"); |
| 353 | + stringBuilder.append("\t").append("(mmap: peak reserved=").append(getPeakReservedVirtualMemory(category) / KB).append("KB, peak committed=") |
| 354 | + .append(getPeakCommittedVirtualMemory(category) / KB).append("KB)").append("\n"); |
317 | 355 | } |
| 356 | + return stringBuilder.toString(); |
318 | 357 | } |
319 | 358 |
|
320 | 359 | private static void teardown() { |
|
0 commit comments