From 93d6e6d422dbabadc56fa48c58441974f07a8ce9 Mon Sep 17 00:00:00 2001 From: md_5 Date: Fri, 14 Dec 2018 10:32:52 +1100 Subject: BUILDTOOLS-431: Detect and warn about low memory. Seems to occur on 32 bit Java installs. --- src/main/java/org/spigotmc/builder/Bootstrap.java | 13 ++++++++++++- src/main/java/org/spigotmc/builder/Builder.java | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/spigotmc/builder/Bootstrap.java b/src/main/java/org/spigotmc/builder/Bootstrap.java index 57a2b78..2a1ceba 100644 --- a/src/main/java/org/spigotmc/builder/Bootstrap.java +++ b/src/main/java/org/spigotmc/builder/Bootstrap.java @@ -1,5 +1,7 @@ package org.spigotmc.builder; +import com.google.common.base.Joiner; + public class Bootstrap { @@ -11,7 +13,7 @@ public class Bootstrap { System.err.println( "Outdated Java detected (" + javaVersion + "). BuildTools requires at least Java 7. Please update Java and try again." ); System.err.println( "You may use java -version to double check your Java version." ); - return; + System.exit( 1 ); } if ( javaVersion.getVersion() < JavaVersion.JAVA_8.getVersion() ) @@ -26,6 +28,15 @@ public class Bootstrap System.err.println( "*** WARNING *** You may use java -version to double check your Java version." ); } + long memoryMb = Runtime.getRuntime().maxMemory() >> 20; + if ( memoryMb < 512 ) + { + System.err.println( "BuildTools requires at least 512M of memory to run (1024M recommended), but has only detected " + memoryMb + "M." ); + System.err.println( "This can often occur if you are running a 32-bit system, or one with low RAM." ); + System.err.println( "Please re-run BuildTools with manually specified memory, e.g: java -Xmx1024M -jar BuildTools.jar " + Joiner.on( ' ' ).join( args ) ); + System.exit( 1 ); + } + Builder.main( args ); } } diff --git a/src/main/java/org/spigotmc/builder/Builder.java b/src/main/java/org/spigotmc/builder/Builder.java index 8a5953e..82bb069 100644 --- a/src/main/java/org/spigotmc/builder/Builder.java +++ b/src/main/java/org/spigotmc/builder/Builder.java @@ -30,6 +30,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintStream; +import java.lang.management.ManagementFactory; import java.net.URI; import java.net.URL; import java.net.URLConnection; @@ -669,7 +670,17 @@ public class Builder } if ( !pb.environment().containsKey( "_JAVA_OPTIONS" ) ) { - pb.environment().put( "_JAVA_OPTIONS", "-Djdk.net.URLClassPath.disableClassPathURLCheck=true" ); + String javaOptions = "-Djdk.net.URLClassPath.disableClassPathURLCheck=true"; + + for ( String arg : ManagementFactory.getRuntimeMXBean().getInputArguments() ) + { + if ( arg.startsWith( "-Xmx" ) ) + { + javaOptions += " " + arg; + } + } + + pb.environment().put( "_JAVA_OPTIONS", javaOptions ); } if ( msysDir != null ) { -- cgit v1.2.3