Skip to content

Commit 154e1d6

Browse files
committedJan 22, 2021
8259009: G1 heap summary should be shown in "Heap Parameters" window on HSDB
Reviewed-by: cjplummer, tschatzl
1 parent acbcde8 commit 154e1d6

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed
 

‎src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/g1/G1CollectedHeap.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -156,7 +156,7 @@ public void printOn(PrintStream tty) {
156156
tty.println(" region size " + (HeapRegion.grainBytes() / 1024) + "K");
157157

158158
HeapSummary sum = new HeapSummary();
159-
sum.printG1HeapSummary(this);
159+
sum.printG1HeapSummary(tty, this);
160160
}
161161

162162
public void printRegionDetails(PrintStream tty) {

‎src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/tools/HeapSummary.java

+30-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
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.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,6 +24,7 @@
2424

2525
package sun.jvm.hotspot.tools;
2626

27+
import java.io.*;
2728
import java.util.*;
2829
import sun.jvm.hotspot.gc.epsilon.*;
2930
import sun.jvm.hotspot.gc.g1.*;
@@ -239,48 +240,60 @@ private void printSpace(ContiguousSpace space) {
239240
}
240241

241242
public void printG1HeapSummary(G1CollectedHeap g1h) {
243+
printG1HeapSummary(System.out, g1h);
244+
}
245+
246+
public void printG1HeapSummary(PrintStream tty, G1CollectedHeap g1h) {
242247
G1MonitoringSupport g1mm = g1h.g1mm();
243248
long edenSpaceRegionNum = g1mm.edenSpaceRegionNum();
244249
long survivorSpaceRegionNum = g1mm.survivorSpaceRegionNum();
245250
HeapRegionSetBase oldSet = g1h.oldSet();
246251
HeapRegionSetBase archiveSet = g1h.archiveSet();
247252
HeapRegionSetBase humongousSet = g1h.humongousSet();
248253
long oldGenRegionNum = oldSet.length() + archiveSet.length() + humongousSet.length();
249-
printG1Space("G1 Heap:", g1h.n_regions(),
254+
printG1Space(tty, "G1 Heap:", g1h.n_regions(),
250255
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,
253258
g1mm.edenSpaceUsed(), g1mm.edenSpaceCommitted());
254-
printG1Space("Survivor Space:", survivorSpaceRegionNum,
259+
printG1Space(tty, "Survivor Space:", survivorSpaceRegionNum,
255260
g1mm.survivorSpaceUsed(), g1mm.survivorSpaceCommitted());
256-
printG1Space("G1 Old Generation:", oldGenRegionNum,
261+
printG1Space(tty, "G1 Old Generation:", oldGenRegionNum,
257262
g1mm.oldGenUsed(), g1mm.oldGenCommitted());
258263
}
259264

260-
private void printG1Space(String spaceName, long regionNum,
265+
private void printG1Space(PrintStream tty, String spaceName, long regionNum,
261266
long used, long capacity) {
262267
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);
268273
double occPerc = (capacity > 0) ? (double) used * 100.0 / capacity : 0.0;
269-
System.out.println(alignment + occPerc + "% used");
274+
tty.println(alignment + occPerc + "% used");
270275
}
271276

272-
private static final double FACTOR = 1024*1024;
273277
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) {
274283
if (value < 0) {
275-
System.out.println(alignment + title + (value >>> 20) + " MB");
284+
tty.println(alignment + title + (value >>> 20) + " MB");
276285
} else {
277286
double mb = value/FACTOR;
278-
System.out.println(alignment + title + value + " (" + mb + "MB)");
287+
tty.println(alignment + title + value + " (" + mb + "MB)");
279288
}
280289
}
281290

282291
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);
284297
}
285298

286299
private long getFlagValue(String name, Map flagMap) {

0 commit comments

Comments
 (0)
Please sign in to comment.