@@ -280,6 +280,29 @@ private static void readCustomEnv(Map<String, String> envMap) throws IOException
280280 reader .close ();
281281 }
282282 }
283+
284+ // Move to it's own function, this gets the allocated ram as an int.
285+ static int getAllocatedMemory (List <String > userArgs ) {
286+ for (String s : userArgs )
287+ if (s .contains ("Xmx" )) {
288+ Matcher matcher = Pattern .compile ("\\ d+" ).matcher (s );
289+
290+ // .find() to prevents IllegalStateException
291+ if (matcher .find ()) {
292+ int multiplier = s .charAt (s .indexOf (matcher .group ()) + 1 ) == 'G' ? 1024 : 1 ;
293+ return (Integer .valueOf (matcher .group ()) * multiplier );
294+ }
295+ }
296+ return 0 ;
297+ }
298+
299+ static boolean isUsingCustomMem (List <String > userArgs ) {
300+ for (String s : userArgs )
301+ if (s .contains ("Xmx" ) || s .contains ("Xms" ))
302+ return true ;
303+ return false ;
304+ }
305+
283306 public static void launchJavaVM (final AppCompatActivity activity , final Runtime runtime , File gameDirectory , final List <String > JVMArgs , final String userArgsString ) throws Throwable {
284307 String runtimeHome = MultiRTUtils .getRuntimeHome (runtime .name ).getAbsolutePath ();
285308
@@ -291,11 +314,8 @@ public static void launchJavaVM(final AppCompatActivity activity, final Runtime
291314 List <String > userArgs = getJavaArgs (activity , runtimeHome , userArgsString );
292315
293316 //Remove arguments that can interfere with the good working of the launcher
294- purgeArg (userArgs ,"-Xms" );
295- purgeArg (userArgs ,"-Xmx" );
296317 purgeArg (userArgs ,"-d32" );
297318 purgeArg (userArgs ,"-d64" );
298- purgeArg (userArgs , "-Xint" );
299319 purgeArg (userArgs , "-XX:+UseTransparentHugePages" );
300320 purgeArg (userArgs , "-XX:+UseLargePagesInMetaspace" );
301321 purgeArg (userArgs , "-XX:+UseLargePages" );
@@ -306,8 +326,10 @@ public static void launchJavaVM(final AppCompatActivity activity, final Runtime
306326 purgeArg (userArgs , "-XX:ActiveProcessorCount" );
307327
308328 //Add automatically generated args
309- userArgs .add ("-Xms" + LauncherPreferences .PREF_RAM_ALLOCATION + "M" );
310- userArgs .add ("-Xmx" + LauncherPreferences .PREF_RAM_ALLOCATION + "M" );
329+ if (!isUsingCustomMem (userArgs )) {
330+ userArgs .add ("-Xms" + LauncherPreferences .PREF_RAM_ALLOCATION + "M" );
331+ userArgs .add ("-Xmx" + LauncherPreferences .PREF_RAM_ALLOCATION + "M" );
332+ }
311333 if (LOCAL_RENDERER != null ) userArgs .add ("-Dorg.lwjgl.opengl.libname=" + graphicsLib );
312334
313335 // Force LWJGL to use the Freetype library intended for it, instead of using the one
@@ -318,7 +340,7 @@ public static void launchJavaVM(final AppCompatActivity activity, final Runtime
318340 userArgs .add ("-XX:ActiveProcessorCount=" + java .lang .Runtime .getRuntime ().availableProcessors ());
319341
320342 userArgs .addAll (JVMArgs );
321- activity .runOnUiThread (() -> Toast .makeText (activity , activity .getString (R .string .autoram_info_msg ,LauncherPreferences . PREF_RAM_ALLOCATION ), Toast .LENGTH_SHORT ).show ());
343+ activity .runOnUiThread (() -> Toast .makeText (activity , activity .getString (R .string .autoram_info_msg ,getAllocatedMemory ( userArgs ) ), Toast .LENGTH_SHORT ).show ());
322344 System .out .println (JVMArgs );
323345
324346 initJavaRuntime (runtimeHome );
0 commit comments