Skip to content

Instantly share code, notes, and snippets.

@modeco80
Last active June 24, 2021 23:26
Show Gist options
  • Save modeco80/383ba8e1380676d0fc0bbc480a161341 to your computer and use it in GitHub Desktop.
Save modeco80/383ba8e1380676d0fc0bbc480a161341 to your computer and use it in GitHub Desktop.
Sample script for running Minecraft with OpenJ9 JVM.
@echo off
:: Sample script for running the Minecraft server
:: with high performance tweaks,
:: using the OpenJ9 JVM's alternative GC's and AOT compilation.
setlocal
:: == Tweak variables ==
:: Set this to the directory your server files are.
set SERVERDIR=C:\mcserver
:: Set this to the name of your server JAR.
set SERVERJAR=fabric-server-launch.jar
:: If your JVM isn't in PATH, then this can be set to
:: <OpenJ9 path>\bin\java.
set JVM=java
:: The affinity mask of the Java process.
:: 0x3 is cpu0 + cpu1,
:: meaning it can only ever use 2 CPU cores (200% in top notation)
:: Tweak this for highest performance.
:: You can use https://bitsum.com/tools/cpu-affinity-calculator/ to get values that work here
set AFFMASK=0x3
:: == JVM variables ==
:: OpenJ9 special JVM arguments.
:: These:
::
:: - set up/use the Shenandoah GC
:: (low-pause, so perfect for a server application)
::
:: - set up a named OpenJ9 AOT cache
:: (mostly for preference)
::
:: - puts that cache in the %SERVERDIR%\aot-cache directory
:: (also for preference)
::
:: - Does -Xtune:virtualized (since this is running on a """VPS""", after all)
:: Note that -Xtune:virtualized causes the OpenJ9 AOT to work harder when specifiying it,
:: so we will also get more performance that way.
set OPENJ9ARGS=-XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xshareclasses:name=minecraft,cacheDir=%SERVERDIR%\aot-cache -Xtune:virtualized
:: This is just your bog-standard JVM arguments.
:: We put the OpenJ9 arguments in here as well
set JVMARGS=%OPENJ9ARGS% -Xms1G -Xmx5G
:: Start the server boot loop.
pushd %SERVERDIR%
goto :BootServer
:: :BootServer - Boots the server up, restarting it if crashed.
:BootServer
:: Start the JVM, with the given affinity mask.
start /B /WAIT /AFFINITY %AFFMASK% %JVM% %JVMARGS% -jar %SERVERJAR% nogui
if not %ERRORLEVEL%==0 (
:: In this case, the server probably crashed.
:: Say it crashed, and then reboot the server
echo Server crashed with exit code %ERRORLEVEL% - restarting
goto :BootServer
) else (
:: The server exited successfully, via a `stop` command.
:: Stop the script.
endlocal
popd
exit /b 0
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment