Skip to content

Commit

Permalink
8255934: JConsole 14 and greater fails to connect to older JVM
Browse files Browse the repository at this point in the history
Reviewed-by: cjplummer, sspitsyn
  • Loading branch information
Alex Menkov committed Nov 20, 2020
1 parent 86f3602 commit 14de791
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/jdk.jconsole/share/classes/sun/tools/jconsole/SummaryTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.LongSupplier;

import javax.swing.*;

Expand Down Expand Up @@ -257,9 +258,14 @@ synchronized Result formatSummary() {
String[] kbStrings1 =
formatKByteStrings(sunOSMBean.getCommittedVirtualMemorySize());

// getTotalPhysicalMemorySize and getFreePhysicalMemorySize are deprecated,
// but we want be able to get the data for old target VMs (see JDK-8255934).
@SuppressWarnings("deprecation")
String[] kbStrings2 =
formatKByteStrings(sunOSMBean.getTotalMemorySize(),
sunOSMBean.getFreeMemorySize(),
formatKByteStrings(tryToGet(sunOSMBean::getTotalMemorySize,
sunOSMBean::getTotalPhysicalMemorySize),
tryToGet(sunOSMBean::getFreeMemorySize,
sunOSMBean::getFreePhysicalMemorySize),
sunOSMBean.getTotalSwapSpaceSize(),
sunOSMBean.getFreeSwapSpaceSize());

Expand Down Expand Up @@ -317,6 +323,20 @@ synchronized Result formatSummary() {
return result;
}

/**
* Tries to get the specified value from the list of suppliers.
* Returns -1 if all suppliers fail.
*/
private long tryToGet(LongSupplier ... getters) {
for (LongSupplier getter : getters) {
try {
return getter.getAsLong();
} catch (UndeclaredThrowableException e) {
}
}
return -1;
}

private synchronized void append(String str) {
buf.append(str);
}
Expand Down

1 comment on commit 14de791

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.