|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
24 | 24 |
|
25 | 25 | package sun.jvm.hotspot.tools;
|
26 | 26 |
|
| 27 | +import java.io.*; |
27 | 28 | import java.util.*;
|
28 | 29 | import sun.jvm.hotspot.gc.epsilon.*;
|
29 | 30 | import sun.jvm.hotspot.gc.g1.*;
|
@@ -239,48 +240,60 @@ private void printSpace(ContiguousSpace space) {
|
239 | 240 | }
|
240 | 241 |
|
241 | 242 | public void printG1HeapSummary(G1CollectedHeap g1h) {
|
| 243 | + printG1HeapSummary(System.out, g1h); |
| 244 | + } |
| 245 | + |
| 246 | + public void printG1HeapSummary(PrintStream tty, G1CollectedHeap g1h) { |
242 | 247 | G1MonitoringSupport g1mm = g1h.g1mm();
|
243 | 248 | long edenSpaceRegionNum = g1mm.edenSpaceRegionNum();
|
244 | 249 | long survivorSpaceRegionNum = g1mm.survivorSpaceRegionNum();
|
245 | 250 | HeapRegionSetBase oldSet = g1h.oldSet();
|
246 | 251 | HeapRegionSetBase archiveSet = g1h.archiveSet();
|
247 | 252 | HeapRegionSetBase humongousSet = g1h.humongousSet();
|
248 | 253 | long oldGenRegionNum = oldSet.length() + archiveSet.length() + humongousSet.length();
|
249 |
| - printG1Space("G1 Heap:", g1h.n_regions(), |
| 254 | + printG1Space(tty, "G1 Heap:", g1h.n_regions(), |
250 | 255 | g1h.used(), g1h.capacity());
|
251 |
| - System.out.println("G1 Young Generation:"); |
252 |
| - printG1Space("Eden Space:", edenSpaceRegionNum, |
| 256 | + tty.println("G1 Young Generation:"); |
| 257 | + printG1Space(tty, "Eden Space:", edenSpaceRegionNum, |
253 | 258 | g1mm.edenSpaceUsed(), g1mm.edenSpaceCommitted());
|
254 |
| - printG1Space("Survivor Space:", survivorSpaceRegionNum, |
| 259 | + printG1Space(tty, "Survivor Space:", survivorSpaceRegionNum, |
255 | 260 | g1mm.survivorSpaceUsed(), g1mm.survivorSpaceCommitted());
|
256 |
| - printG1Space("G1 Old Generation:", oldGenRegionNum, |
| 261 | + printG1Space(tty, "G1 Old Generation:", oldGenRegionNum, |
257 | 262 | g1mm.oldGenUsed(), g1mm.oldGenCommitted());
|
258 | 263 | }
|
259 | 264 |
|
260 |
| - private void printG1Space(String spaceName, long regionNum, |
| 265 | + private void printG1Space(PrintStream tty, String spaceName, long regionNum, |
261 | 266 | long used, long capacity) {
|
262 | 267 | long free = capacity - used;
|
263 |
| - System.out.println(spaceName); |
264 |
| - printValue("regions = ", regionNum); |
265 |
| - printValMB("capacity = ", capacity); |
266 |
| - printValMB("used = ", used); |
267 |
| - printValMB("free = ", free); |
| 268 | + tty.println(spaceName); |
| 269 | + printValue(tty, "regions = ", regionNum); |
| 270 | + printValMB(tty, "capacity = ", capacity); |
| 271 | + printValMB(tty, "used = ", used); |
| 272 | + printValMB(tty, "free = ", free); |
268 | 273 | double occPerc = (capacity > 0) ? (double) used * 100.0 / capacity : 0.0;
|
269 |
| - System.out.println(alignment + occPerc + "% used"); |
| 274 | + tty.println(alignment + occPerc + "% used"); |
270 | 275 | }
|
271 | 276 |
|
272 |
| - private static final double FACTOR = 1024*1024; |
273 | 277 | private void printValMB(String title, long value) {
|
| 278 | + printValMB(System.out, title, value); |
| 279 | + } |
| 280 | + |
| 281 | + private static final double FACTOR = 1024*1024; |
| 282 | + private void printValMB(PrintStream tty, String title, long value) { |
274 | 283 | if (value < 0) {
|
275 |
| - System.out.println(alignment + title + (value >>> 20) + " MB"); |
| 284 | + tty.println(alignment + title + (value >>> 20) + " MB"); |
276 | 285 | } else {
|
277 | 286 | double mb = value/FACTOR;
|
278 |
| - System.out.println(alignment + title + value + " (" + mb + "MB)"); |
| 287 | + tty.println(alignment + title + value + " (" + mb + "MB)"); |
279 | 288 | }
|
280 | 289 | }
|
281 | 290 |
|
282 | 291 | private void printValue(String title, long value) {
|
283 |
| - System.out.println(alignment + title + value); |
| 292 | + printValue(System.out, title, value); |
| 293 | + } |
| 294 | + |
| 295 | + private void printValue(PrintStream tty, String title, long value) { |
| 296 | + tty.println(alignment + title + value); |
284 | 297 | }
|
285 | 298 |
|
286 | 299 | private long getFlagValue(String name, Map flagMap) {
|
|
0 commit comments