summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-13 02:24:08 -0800
committerFuwn <[email protected]>2026-02-13 04:13:49 -0800
commit0d6fb4c116fefb36cbd60a7f17d280cf899c43fb (patch)
treef3c3c7be5dbb2685a60a0b35a4e59e771b3f1a24
parentfeat: Reimplement core I/O and system information native methods with pure Java (diff)
downloadworldsplayer-0d6fb4c116fefb36cbd60a7f17d280cf899c43fb.tar.xz
worldsplayer-0d6fb4c116fefb36cbd60a7f17d280cf899c43fb.zip
fix: Use real system memory via OperatingSystemMXBean
Replaces JVM Runtime heap values with actual system physical/swap memory from com.sun.management.OperatingSystemMXBean, matching the Win32 GlobalMemoryStatus values the originals returned.
-rw-r--r--NET/worlds/console/StatMemNode.java12
-rw-r--r--NET/worlds/core/SystemInfo.java13
2 files changed, 12 insertions, 13 deletions
diff --git a/NET/worlds/console/StatMemNode.java b/NET/worlds/console/StatMemNode.java
index b5031dd..903bf0d 100644
--- a/NET/worlds/console/StatMemNode.java
+++ b/NET/worlds/console/StatMemNode.java
@@ -5,6 +5,8 @@ import java.awt.List;
public class StatMemNode extends StatMan implements MainCallback {
private static StatMemNode _singleInstance = new StatMemNode();
+ private static final com.sun.management.OperatingSystemMXBean operatingSystemMXBean =
+ (com.sun.management.OperatingSystemMXBean) java.lang.management.ManagementFactory.getOperatingSystemMXBean();
private int _lastTime;
private static final int TITLE = 0;
private static final int BLANK1 = 1;
@@ -103,11 +105,9 @@ public class StatMemNode extends StatMan implements MainCallback {
}
public void updateMemoryStatus() {
- Runtime runtime = Runtime.getRuntime();
-
- this._totPhysMem = (int)runtime.maxMemory();
- this._availPhysMem = (int)runtime.freeMemory();
- this._totPageMem = (int)runtime.totalMemory();
- this._availPageMem = (int)(runtime.maxMemory() - (runtime.totalMemory() - runtime.freeMemory()));
+ this._totPhysMem = (int)operatingSystemMXBean.getTotalPhysicalMemorySize();
+ this._availPhysMem = (int)operatingSystemMXBean.getFreePhysicalMemorySize();
+ this._totPageMem = (int)operatingSystemMXBean.getTotalSwapSpaceSize();
+ this._availPageMem = (int)operatingSystemMXBean.getFreeSwapSpaceSize();
}
}
diff --git a/NET/worlds/core/SystemInfo.java b/NET/worlds/core/SystemInfo.java
index 8a138aa..594c88d 100644
--- a/NET/worlds/core/SystemInfo.java
+++ b/NET/worlds/core/SystemInfo.java
@@ -7,6 +7,8 @@ import java.io.PrintStream;
public class SystemInfo implements MainCallback, MainTerminalCallback {
private static SystemInfo instance = new SystemInfo();
+ private static final com.sun.management.OperatingSystemMXBean operatingSystemMXBean =
+ (com.sun.management.OperatingSystemMXBean) java.lang.management.ManagementFactory.getOperatingSystemMXBean();
private long _lastFrame = 0L;
private long _lastReport = 0L;
private long _min;
@@ -111,22 +113,19 @@ public class SystemInfo implements MainCallback, MainTerminalCallback {
}
public static int GetTotalPhysicalMemory() {
- return (int)(Runtime.getRuntime().maxMemory() / 1024L);
+ return (int)(operatingSystemMXBean.getTotalPhysicalMemorySize() / 1024L);
}
public static int GetAvailPhysicalMemory() {
- return (int)(Runtime.getRuntime().freeMemory() / 1024L);
+ return (int)(operatingSystemMXBean.getFreePhysicalMemorySize() / 1024L);
}
public static int GetTotalPagedMemory() {
- return (int)(Runtime.getRuntime().totalMemory() / 1024L);
+ return (int)(operatingSystemMXBean.getTotalSwapSpaceSize() / 1024L);
}
public static int GetAvailPagedMemory() {
- Runtime runtime = Runtime.getRuntime();
- long availableMemory = runtime.maxMemory() - (runtime.totalMemory() - runtime.freeMemory());
-
- return (int)(availableMemory / 1024L);
+ return (int)(operatingSystemMXBean.getFreeSwapSpaceSize() / 1024L);
}
public static String GetPlatformID() {