|
32 | 32 | import java.text.*;
|
33 | 33 | import java.util.*;
|
34 | 34 | import java.util.concurrent.*;
|
| 35 | +import java.util.function.LongSupplier; |
35 | 36 |
|
36 | 37 | import javax.swing.*;
|
37 | 38 |
|
@@ -257,9 +258,14 @@ synchronized Result formatSummary() {
|
257 | 258 | String[] kbStrings1 =
|
258 | 259 | formatKByteStrings(sunOSMBean.getCommittedVirtualMemorySize());
|
259 | 260 |
|
| 261 | + // getTotalPhysicalMemorySize and getFreePhysicalMemorySize are deprecated, |
| 262 | + // but we want be able to get the data for old target VMs (see JDK-8255934). |
| 263 | + @SuppressWarnings("deprecation") |
260 | 264 | String[] kbStrings2 =
|
261 |
| - formatKByteStrings(sunOSMBean.getTotalMemorySize(), |
262 |
| - sunOSMBean.getFreeMemorySize(), |
| 265 | + formatKByteStrings(tryToGet(sunOSMBean::getTotalMemorySize, |
| 266 | + sunOSMBean::getTotalPhysicalMemorySize), |
| 267 | + tryToGet(sunOSMBean::getFreeMemorySize, |
| 268 | + sunOSMBean::getFreePhysicalMemorySize), |
263 | 269 | sunOSMBean.getTotalSwapSpaceSize(),
|
264 | 270 | sunOSMBean.getFreeSwapSpaceSize());
|
265 | 271 |
|
@@ -317,6 +323,20 @@ synchronized Result formatSummary() {
|
317 | 323 | return result;
|
318 | 324 | }
|
319 | 325 |
|
| 326 | + /** |
| 327 | + * Tries to get the specified value from the list of suppliers. |
| 328 | + * Returns -1 if all suppliers fail. |
| 329 | + */ |
| 330 | + private long tryToGet(LongSupplier ... getters) { |
| 331 | + for (LongSupplier getter : getters) { |
| 332 | + try { |
| 333 | + return getter.getAsLong(); |
| 334 | + } catch (UndeclaredThrowableException e) { |
| 335 | + } |
| 336 | + } |
| 337 | + return -1; |
| 338 | + } |
| 339 | + |
320 | 340 | private synchronized void append(String str) {
|
321 | 341 | buf.append(str);
|
322 | 342 | }
|
|
0 commit comments