BUILDTOOLS-431: Detect and warn about low memory. Seems to occur on 32 bit Java installs.

This commit is contained in:
md_5 2018-12-14 10:32:52 +11:00
parent f254dfa940
commit 93d6e6d422
2 changed files with 24 additions and 2 deletions

View file

@ -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 );
}
}

View file

@ -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 )
{