Skip to content

Commit a359397

Browse files
committed
GH-434 max value for renderers must be a positive number
1 parent 9f9472d commit a359397

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

visualvm/sampler/src/org/graalvm/visualvm/sampler/memory/MemoryView.java

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,6 @@ final class MemoryView extends JPanel {
111111

112112
private List<ClassInfo> classes = new ArrayList<>();
113113
private List<ClassInfo> baseClasses = new ArrayList<>(); // Needed to correctly setup table renderers
114-
// private int totalClasses = -1;
115-
private long totalBytes, baseTotalBytes = -1;
116-
private long totalInstances, baseTotalInstances = -1;
117114

118115

119116
MemoryView(Application application, AbstractSamplerSupport.Refresher refresher, int mode,
@@ -153,46 +150,43 @@ boolean isEmpty() {
153150

154151
void refresh(HeapHistogram histogram) {
155152
if (histogram == null || isPaused()) return;
153+
long bytesMaxValue = 0;
154+
long instancesMaxValue = 0;
156155
forceRefresh = false;
157156

158157
boolean diff = lrDeltasButton.isSelected();
159158
if (diff) {
160159
if (baseClasses == null) {
161160
baseClasses = new ArrayList<>(classes);
162-
baseTotalBytes = totalBytes;
163-
baseTotalInstances = totalInstances;
164161
}
165162

166163
Collection<ClassInfo> newClasses = getHistogram(histogram);
167164
classes = computeDeltaClasses(baseClasses, newClasses);
168165

169-
// totalClasses = baseClasses.size() - newClasses.size();
170-
totalBytes = getTotalBytes(histogram) - baseTotalBytes;
171-
totalInstances = getTotalInstances(histogram) - baseTotalInstances;
172-
173166
long maxAbsDiffBytes = 0;
174-
for (ClassInfo cInfo : classes)
167+
long maxAbsDiffInstances = 0;
168+
for (ClassInfo cInfo : classes) {
175169
maxAbsDiffBytes = Math.max(maxAbsDiffBytes, Math.abs(cInfo.getBytes()));
176-
170+
maxAbsDiffInstances = Math.max(maxAbsDiffInstances, Math.abs(cInfo.getInstancesCount()));
171+
}
172+
bytesMaxValue = maxAbsDiffBytes;
173+
instancesMaxValue = maxAbsDiffInstances;
177174
} else {
178175
if (baseClasses != null) {
179176
baseClasses = null;
180-
baseTotalBytes = -1;
181-
baseTotalInstances = -1;
182177
}
183178
classes.clear();
184179
classes.addAll(getHistogram(histogram));
185180

186-
// totalClasses = classes.size();
187-
totalBytes = getTotalBytes(histogram);
188-
totalInstances = getTotalInstances(histogram);
181+
bytesMaxValue = getTotalBytes(histogram);
182+
instancesMaxValue = getTotalInstances(histogram);
189183
}
190184

191185
renderers[0].setDiffMode(diff);
192-
renderers[0].setMaxValue(totalBytes);
186+
renderers[0].setMaxValue(bytesMaxValue);
193187

194188
renderers[1].setDiffMode(diff);
195-
renderers[1].setMaxValue(totalInstances);
189+
renderers[1].setMaxValue(instancesMaxValue);
196190

197191
tableModel.fireTableDataChanged();
198192

0 commit comments

Comments
 (0)