fix: issue with 64 bit OS not using correct runtime when using 32 bit Java

This commit is contained in:
Ryan Dowling 2021-07-31 10:33:03 +10:00
parent 2fcb4285a2
commit 317662afcc
No known key found for this signature in database
GPG key ID: 5539FCDB88950EFD
8 changed files with 25 additions and 14 deletions

2
.vscode/launch.json vendored
View file

@ -10,7 +10,7 @@
"cwd": "${workspaceFolder}/testLauncher",
"preLaunchTask": "makeTestLauncherDirectory",
"args": "--debug --debug-level 5 --disable-error-reporting --no-launcher-update",
},
{
"type": "java",

View file

@ -10,5 +10,6 @@ This changelog only contains the changes that are unreleased. For changes for in
### Fixes
- Update the LaunchServer.bat script to make it "simpler" to change Java path
- Issue with 64 bit OS not using correct runtime when using 32 bit Java
### Misc

View file

@ -425,7 +425,7 @@ public class App {
LogManager.info("Java Path: " + settings.javaPath);
LogManager.info("64 Bit Java: " + OS.is64Bit());
LogManager.info("64 Bit Java: " + Java.is64Bit());
int maxRam = OS.getMaximumRam();
LogManager.info("RAM Available: " + (maxRam == 0 ? "Unknown" : maxRam + "MB"));

View file

@ -141,7 +141,7 @@ public class Launcher {
PackManager.removeUnusedImages(); // remove unused pack images
if (OS.isWindows() && !OS.is64Bit() && OS.isWindows64Bit()) {
if (OS.isWindows() && !Java.is64Bit() && OS.is64Bit()) {
LogManager.warn("You're using 32 bit Java on a 64 bit Windows install!");
int ret = DialogManager.yesNoDialog().setTitle(GetText.tr("Running 32 Bit Java on 64 Bit Windows"))

View file

@ -105,7 +105,7 @@ public class JavaInstanceSettingsTab extends JPanel {
JPanel initialMemoryPanel = new JPanel();
initialMemoryPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 0));
if (!OS.is64Bit()) {
if (!Java.is64Bit()) {
initialMemoryPanel.add(initialMemoryLabelWarning);
}
initialMemoryPanel.add(initialMemoryLabel);

View file

@ -110,7 +110,7 @@ public class JavaSettingsTab extends AbstractSettingsTab implements Relocalizati
JPanel initialMemoryPanel = new JPanel();
initialMemoryPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 0));
if (!OS.is64Bit()) {
if (!Java.is64Bit()) {
initialMemoryPanel.add(initialMemoryLabelWarning);
}
initialMemoryPanel.add(initialMemoryLabel);
@ -141,7 +141,7 @@ public class JavaSettingsTab extends AbstractSettingsTab implements Relocalizati
JPanel maximumMemoryPanel = new JPanel();
maximumMemoryPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 0));
if (!OS.is64Bit()) {
if (!Java.is64Bit()) {
maximumMemoryPanel.add(new JLabelWithHover(WARNING_ICON, new HTMLBuilder().center().split(100).text(GetText
.tr("You're running a 32 bit Java and therefore cannot use more than 1GB of Ram. Please see http://atl.pw/32bit for help."))
.build(), RESTART_BORDER));

View file

@ -46,6 +46,13 @@ public class Java {
return System.getProperty("java.version");
}
/**
* Checks if the Java being used is 64 bit.
*/
public static boolean is64Bit() {
return System.getProperty("sun.arch.data.model").contains("64");
}
/**
* Get the Java version used to run Minecraft.
*

View file

@ -59,6 +59,7 @@ import com.atlauncher.utils.javafinder.JavaInfo;
import oshi.SystemInfo;
import oshi.hardware.GlobalMemory;
import oshi.hardware.HardwareAbstractionLayer;
import oshi.software.os.OperatingSystem;
public enum OS {
LINUX, WINDOWS, OSX;
@ -277,17 +278,19 @@ public enum OS {
}
/**
* Checks if the Java being used is 64 bit.
* Checks if the OS is 64 bit.
*/
public static boolean is64Bit() {
return System.getProperty("sun.arch.data.model").contains("64");
}
try {
SystemInfo systemInfo = OS.getSystemInfo();
OperatingSystem os = systemInfo.getOperatingSystem();
/**
* Checks if Windows is 64 bit.
*/
public static boolean isWindows64Bit() {
return System.getenv("ProgramFiles(x86)") != null;
return os.getBitness() == 64;
} catch (Throwable ignored) {
}
// worse case fallback to checking the Java install
return Java.is64Bit();
}
/**