diff --git a/Ghidra/RuntimeScripts/Linux/ghidraRun b/Ghidra/RuntimeScripts/Linux/ghidraRun index 51f8497e48..906fc02ac4 100755 --- a/Ghidra/RuntimeScripts/Linux/ghidraRun +++ b/Ghidra/RuntimeScripts/Linux/ghidraRun @@ -15,6 +15,9 @@ MAXMEM_DEFAULT= GHIDRA_MAXMEM=${GHIDRA_MAXMEM:=${MAXMEM_DEFAULT}} GHIDRA_GUI_MAXMEM=${GHIDRA_GUI_MAXMEM:=${GHIDRA_MAXMEM}} +# Apply Java options from externally set environment variables +VMARG_LIST="${GHIDRA_JAVA_OPTIONS} ${GHIDRA_GUI_JAVA_OPTIONS} " + # Resolve symbolic link if present and get the directory this script lives in. # NOTE: "readlink -f" is best but works on Linux only, "readlink" will only work if your PWD # contains the link you are calling (which is the best we can do on macOS), and the "echo" is the @@ -23,4 +26,4 @@ SCRIPT_FILE="$(readlink -f "$0" 2>/dev/null || readlink "$0" 2>/dev/null || echo SCRIPT_DIR="${SCRIPT_FILE%/*}" # Launch Ghidra -"${SCRIPT_DIR}"/support/launch.sh bg jdk Ghidra "${GHIDRA_GUI_MAXMEM}" "" ghidra.GhidraRun "$@" +"${SCRIPT_DIR}"/support/launch.sh bg jdk Ghidra "${GHIDRA_GUI_MAXMEM}" "${VMARG_LIST}" ghidra.GhidraRun "$@" diff --git a/Ghidra/RuntimeScripts/Linux/support/analyzeHeadless b/Ghidra/RuntimeScripts/Linux/support/analyzeHeadless index 369979e9cc..342d69c7a6 100755 --- a/Ghidra/RuntimeScripts/Linux/support/analyzeHeadless +++ b/Ghidra/RuntimeScripts/Linux/support/analyzeHeadless @@ -16,6 +16,14 @@ MAXMEM_DEFAULT=2G GHIDRA_MAXMEM=${GHIDRA_MAXMEM:=${MAXMEM_DEFAULT}} GHIDRA_HEADLESS_MAXMEM=${GHIDRA_HEADLESS_MAXMEM:=${GHIDRA_MAXMEM}} +# Limit the # of garbage collection and JIT compiler threads in case many headless +# instances are run in parallel. By default, Java will assign one thread per core +# which does not scale well on servers with many cores. +VMARG_LIST="-XX:ParallelGCThreads=2 -XX:CICompilerCount=2 -Djava.awt.headless=true" + +# Apply Java options from externally set environment variables +VMARG_LIST="${VMARG_LIST} ${GHIDRA_JAVA_OPTIONS} ${GHIDRA_HEADLESS_JAVA_OPTIONS}" + # Launch mode can be changed to one of the following: fg, debug, debug-suspend LAUNCH_MODE=fg @@ -23,11 +31,6 @@ LAUNCH_MODE=fg # NOTE: This variable is ignored if not launching in a debugging mode. DEBUG_ADDRESS=127.0.0.1:13002 -# Limit the # of garbage collection and JIT compiler threads in case many headless -# instances are run in parallel. By default, Java will assign one thread per core -# which does not scale well on servers with many cores. -VMARG_LIST="-XX:ParallelGCThreads=2 -XX:CICompilerCount=2 -Djava.awt.headless=true " - # Resolve symbolic link if present and get the directory this script lives in. # NOTE: "readlink -f" is best but works on Linux only, "readlink" will only work if your PWD # contains the link you are calling (which is the best we can do on macOS), and the "echo" is the diff --git a/Ghidra/RuntimeScripts/Linux/support/bsim b/Ghidra/RuntimeScripts/Linux/support/bsim index 007ccb0532..c8bbcdb776 100755 --- a/Ghidra/RuntimeScripts/Linux/support/bsim +++ b/Ghidra/RuntimeScripts/Linux/support/bsim @@ -13,11 +13,15 @@ MAXMEM_DEFAULT= GHIDRA_MAXMEM=${GHIDRA_MAXMEM:=${MAXMEM_DEFAULT}} GHIDRA_BSIM_MAXMEM=${GHIDRA_BSIM_MAXMEM:=${GHIDRA_MAXMEM}} +# Force Java headless mode +VMARG_LIST="-Djava.awt.headless=true" + +# Apply Java options from externally set environment variables +VMARG_LIST="${VMARG_LIST} ${GHIDRA_JAVA_OPTIONS} ${GHIDRA_BSIM_JAVA_OPTIONS}" + # launch mode (fg, bg, debug, debug-suspend) LAUNCH_MODE=fg -VMARG_LIST="-Djava.awt.headless=true " - # Resolve symbolic link if present and get the directory this script lives in. # NOTE: "readlink -f" is best but works on Linux only, "readlink" will only work if your PWD # contains the link you are calling (which is the best we can do on macOS), and the "echo" is the diff --git a/Ghidra/RuntimeScripts/Linux/support/ghidraDebug b/Ghidra/RuntimeScripts/Linux/support/ghidraDebug index 3055f78d4f..2b7e46abd5 100755 --- a/Ghidra/RuntimeScripts/Linux/support/ghidraDebug +++ b/Ghidra/RuntimeScripts/Linux/support/ghidraDebug @@ -15,6 +15,9 @@ MAXMEM_DEFAULT= GHIDRA_MAXMEM=${GHIDRA_MAXMEM:=${MAXMEM_DEFAULT}} GHIDRA_GUI_MAXMEM=${GHIDRA_GUI_MAXMEM:=${GHIDRA_MAXMEM}} +# Apply Java options from externally set environment variables +VMARG_LIST="${GHIDRA_JAVA_OPTIONS} ${GHIDRA_GUI_JAVA_OPTIONS} " + # Debug launch mode can be changed to one of the following: debug, debug-suspend LAUNCH_MODE=debug @@ -31,4 +34,4 @@ SCRIPT_DIR="${SCRIPT_FILE%/*}" # Launch Ghidra in debug mode # DEBUG_ADDRESS set via environment for launch.sh -DEBUG_ADDRESS=${DEBUG_ADDRESS} "${SCRIPT_DIR}"/launch.sh "${LAUNCH_MODE}" jdk Ghidra "${GHIDRA_GUI_MAXMEM}" "" ghidra.GhidraRun "$@" +DEBUG_ADDRESS=${DEBUG_ADDRESS} "${SCRIPT_DIR}"/launch.sh "${LAUNCH_MODE}" jdk Ghidra "${GHIDRA_GUI_MAXMEM}" "${VMARG_LIST}" ghidra.GhidraRun "$@" diff --git a/Ghidra/RuntimeScripts/Linux/support/jshellRun b/Ghidra/RuntimeScripts/Linux/support/jshellRun index 8c661e8ad4..fa9eda6a0c 100755 --- a/Ghidra/RuntimeScripts/Linux/support/jshellRun +++ b/Ghidra/RuntimeScripts/Linux/support/jshellRun @@ -15,6 +15,9 @@ MAXMEM_DEFAULT= GHIDRA_MAXMEM=${GHIDRA_MAXMEM:=${MAXMEM_DEFAULT}} GHIDRA_JSHELL_MAXMEM=${GHIDRA_JSHELL_MAXMEM:=${GHIDRA_MAXMEM}} +# Apply Java options from externally set environment variables +VMARG_LIST="${GHIDRA_JAVA_OPTIONS} ${GHIDRA_JSHELL_JAVA_OPTIONS} " + # Resolve symbolic link if present and get the directory this script lives in. # NOTE: "readlink -f" is best but works on Linux only, "readlink" will only work if your PWD # contains the link you are calling (which is the best we can do on macOS), and the "echo" is the @@ -23,4 +26,4 @@ SCRIPT_FILE="$(readlink -f "$0" 2>/dev/null || readlink "$0" 2>/dev/null || echo SCRIPT_DIR="${SCRIPT_FILE%/*}" # Launch Ghidra -"${SCRIPT_DIR}"/launch.sh fg jdk Ghidra-JShell "${GHIDRA_JSHELL_MAXMEM}" "" ghidra.JShellRun "$@" +"${SCRIPT_DIR}"/launch.sh fg jdk Ghidra-JShell "${GHIDRA_JSHELL_MAXMEM}" "${VMARG_LIST}" ghidra.JShellRun "$@" diff --git a/Ghidra/RuntimeScripts/Linux/support/jythonRun b/Ghidra/RuntimeScripts/Linux/support/jythonRun index a3cacd5591..89cf5b4bf5 100755 --- a/Ghidra/RuntimeScripts/Linux/support/jythonRun +++ b/Ghidra/RuntimeScripts/Linux/support/jythonRun @@ -15,6 +15,14 @@ MAXMEM_DEFAULT= GHIDRA_MAXMEM=${GHIDRA_MAXMEM:=${MAXMEM_DEFAULT}} GHIDRA_JYTHON_MAXMEM=${GHIDRA_JYTHON_MAXMEM:=${GHIDRA_MAXMEM}} +# Limit the # of garbage collection and JIT compiler threads in case many python +# instances are run in parallel. By default, Java will assign one thread per core +# which does not scale well on servers with many cores. +VMARG_LIST="-XX:ParallelGCThreads=2 -XX:CICompilerCount=2 -Djava.awt.headless=true" + +# Apply Java options from externally set environment variables +VMARG_LIST="${VMARG_LIST} ${GHIDRA_JAVA_OPTIONS} ${GHIDRA_JYTHON_JAVA_OPTIONS}" + # Launch mode can be changed to one of the following: fg, debug, debug-suspend LAUNCH_MODE=fg @@ -22,15 +30,6 @@ LAUNCH_MODE=fg # NOTE: This variable is ignored if not launching in a debugging mode. DEBUG_ADDRESS=127.0.0.1:13002 -# Limit the # of garbage collection and JIT compiler threads in case many python -# instances are run in parallel. By default, Java will assign one thread per core -# which does not scale well on servers with many cores. -VMARG_LIST="-XX:ParallelGCThreads=2 " -VMARG_LIST+="-XX:CICompilerCount=2 " - -# Prevent the shell losing focus when Ghidra initializes -VMARG_LIST+="-Djava.awt.headless=true " - # Resolve symbolic link if present and get the directory this script lives in. # NOTE: "readlink -f" is best but works on Linux only, "readlink" will only work if your PWD # contains the link you are calling (which is the best we can do on macOS), and the "echo" is the diff --git a/Ghidra/RuntimeScripts/Windows/ghidraRun.bat b/Ghidra/RuntimeScripts/Windows/ghidraRun.bat index a662ef642b..a27cf8bbd7 100644 --- a/Ghidra/RuntimeScripts/Windows/ghidraRun.bat +++ b/Ghidra/RuntimeScripts/Windows/ghidraRun.bat @@ -29,5 +29,8 @@ set MAXMEM_DEFAULT= if not defined GHIDRA_MAXMEM set "GHIDRA_MAXMEM=%MAXMEM_DEFAULT%" if not defined GHIDRA_GUI_MAXMEM set "GHIDRA_GUI_MAXMEM=%GHIDRA_MAXMEM%" -call "%~dp0support\launch.bat" bg jdk Ghidra "%GHIDRA_GUI_MAXMEM%" "" ghidra.GhidraRun %* +:: Apply Java options from externally set environment variables +set VMARG_LIST=%GHIDRA_JAVA_OPTIONS% %GHIDRA_GUI_JAVA_OPTIONS% + +call "%~dp0support\launch.bat" bg jdk Ghidra "%GHIDRA_GUI_MAXMEM%" "%VMARG_LIST%" ghidra.GhidraRun %* diff --git a/Ghidra/RuntimeScripts/Windows/support/analyzeHeadless.bat b/Ghidra/RuntimeScripts/Windows/support/analyzeHeadless.bat index dfdbb0ee0b..3a56cfeebb 100644 --- a/Ghidra/RuntimeScripts/Windows/support/analyzeHeadless.bat +++ b/Ghidra/RuntimeScripts/Windows/support/analyzeHeadless.bat @@ -30,6 +30,14 @@ set MAXMEM_DEFAULT=2G if not defined GHIDRA_MAXMEM set "GHIDRA_MAXMEM=%MAXMEM_DEFAULT%" if not defined GHIDRA_HEADLESS_MAXMEM set "GHIDRA_HEADLESS_MAXMEM=%GHIDRA_MAXMEM%" +:: Limit the # of garbage collection and JIT compiler threads in case many headless +:: instances are run in parallel. By default, Java will assign one thread per core +:: which does not scale well on servers with many cores. +set VMARG_LIST=-XX:ParallelGCThreads=2 -XX:CICompilerCount=2 + +:: Apply Java options from externally set environment variables +set VMARG_LIST=%VMARG_LIST% %GHIDRA_JAVA_OPTIONS% %GHIDRA_HEADLESS_JAVA_OPTIONS% + :: Launch mode can be changed to one of the following: :: fg, debug, debug-suspend set LAUNCH_MODE=fg @@ -38,11 +46,6 @@ set LAUNCH_MODE=fg :: NOTE: This variable is ignored if not launching in a debugging mode. set DEBUG_ADDRESS=127.0.0.1:13002 -:: Limit the # of garbage collection and JIT compiler threads in case many headless -:: instances are run in parallel. By default, Java will assign one thread per core -:: which does not scale well on servers with many cores. -set VMARG_LIST=-XX:ParallelGCThreads=2 -XX:CICompilerCount=2 - :: Store current path (%0 gets modified below by SHIFT) set "SCRIPT_DIR=%~dp0" diff --git a/Ghidra/RuntimeScripts/Windows/support/bsim.bat b/Ghidra/RuntimeScripts/Windows/support/bsim.bat index fda7fed12d..2d2927cbf9 100644 --- a/Ghidra/RuntimeScripts/Windows/support/bsim.bat +++ b/Ghidra/RuntimeScripts/Windows/support/bsim.bat @@ -29,6 +29,9 @@ set MAXMEM_DEFAULT= if not defined GHIDRA_MAXMEM set "GHIDRA_MAXMEM=%MAXMEM_DEFAULT%" if not defined GHIDRA_BSIM_MAXMEM set "GHIDRA_BSIM_MAXMEM=%GHIDRA_MAXMEM%" +:: Apply Java options from externally set environment variables +set VMARG_LIST=%GHIDRA_JAVA_OPTIONS% %GHIDRA_BSIM_JAVA_OPTIONS% + :: launch mode (fg, bg, debug, debug-suspend) set LAUNCH_MODE=fg @@ -42,4 +45,4 @@ set LAUNCH_MODE=fg set "LAUNCH_DIR=%~dp0" set "LAUNCH_DIR=%LAUNCH_DIR:~0,-1%" -call "%LAUNCH_DIR%\launch.bat" %LAUNCH_MODE% jdk BSim "%GHIDRA_BSIM_MAXMEM%" "" ghidra.features.bsim.query.ingest.BSimLaunchable %* +call "%LAUNCH_DIR%\launch.bat" %LAUNCH_MODE% jdk BSim "%GHIDRA_BSIM_MAXMEM%" "%VMARG_LIST%" ghidra.features.bsim.query.ingest.BSimLaunchable %* diff --git a/Ghidra/RuntimeScripts/Windows/support/ghidraDebug.bat b/Ghidra/RuntimeScripts/Windows/support/ghidraDebug.bat index 3d5412270a..19d081f3a6 100644 --- a/Ghidra/RuntimeScripts/Windows/support/ghidraDebug.bat +++ b/Ghidra/RuntimeScripts/Windows/support/ghidraDebug.bat @@ -29,6 +29,9 @@ set MAXMEM_DEFAULT= if not defined GHIDRA_MAXMEM set "GHIDRA_MAXMEM=%MAXMEM_DEFAULT%" if not defined GHIDRA_GUI_MAXMEM set "GHIDRA_GUI_MAXMEM=%GHIDRA_MAXMEM%" +:: Apply Java options from externally set environment variables +set VMARG_LIST=%GHIDRA_JAVA_OPTIONS% %GHIDRA_GUI_JAVA_OPTIONS% + :: Debug launch mode can be changed to one of the following: :: debug, debug-suspend set LAUNCH_MODE=debug @@ -37,4 +40,4 @@ set LAUNCH_MODE=debug :: NOTE: This variable is ignored if not launching in a debugging mode. set DEBUG_ADDRESS=127.0.0.1:18001 -call "%~dp0launch.bat" %LAUNCH_MODE% jdk Ghidra "%GHIDRA_GUI_MAXMEM%" "" ghidra.GhidraRun %* +call "%~dp0launch.bat" %LAUNCH_MODE% jdk Ghidra "%GHIDRA_GUI_MAXMEM%" "%VMARG_LIST%" ghidra.GhidraRun %* diff --git a/Ghidra/RuntimeScripts/Windows/support/jshellRun.bat b/Ghidra/RuntimeScripts/Windows/support/jshellRun.bat index 0503252c75..923df154cd 100644 --- a/Ghidra/RuntimeScripts/Windows/support/jshellRun.bat +++ b/Ghidra/RuntimeScripts/Windows/support/jshellRun.bat @@ -29,5 +29,8 @@ set MAXMEM_DEFAULT= if not defined GHIDRA_MAXMEM set "GHIDRA_MAXMEM=%MAXMEM_DEFAULT%" if not defined GHIDRA_JSHELL_MAXMEM set "GHIDRA_JSHELL_MAXMEM=%GHIDRA_MAXMEM%" -call "%~dp0launch.bat" fg jdk Ghidra-JShell "%GHIDRA_JSHELL_MAXMEM%" "" ghidra.JShellRun %* +:: Apply Java options from externally set environment variables +set VMARG_LIST=%GHIDRA_JAVA_OPTIONS% %GHIDRA_JSHELL_JAVA_OPTIONS% + +call "%~dp0launch.bat" fg jdk Ghidra-JShell "%GHIDRA_JSHELL_MAXMEM%" "%VMARG_LIST%" ghidra.JShellRun %* diff --git a/Ghidra/RuntimeScripts/Windows/support/jythonRun.bat b/Ghidra/RuntimeScripts/Windows/support/jythonRun.bat index 1a306db339..f76fcbab0e 100644 --- a/Ghidra/RuntimeScripts/Windows/support/jythonRun.bat +++ b/Ghidra/RuntimeScripts/Windows/support/jythonRun.bat @@ -29,6 +29,14 @@ set MAXMEM_DEFAULT= if not defined GHIDRA_MAXMEM set "GHIDRA_MAXMEM=%MAXMEM_DEFAULT%" if not defined GHIDRA_JYTHON_MAXMEM set "GHIDRA_JYTHON_MAXMEM=%GHIDRA_MAXMEM%" +:: Limit the # of garbage collection and JIT compiler threads in case many headless +:: instances are run in parallel. By default, Java will assign one thread per core +:: which does not scale well on servers with many cores. +set VMARG_LIST=-XX:ParallelGCThreads=2 -XX:CICompilerCount=2 + +:: Apply Java options from externally set environment variables +set VMARG_LIST=%VMARG_LIST% %GHIDRA_JAVA_OPTIONS% %GHIDRA_JYTHON_JAVA_OPTIONS% + :: Launch mode can be changed to one of the following: :: fg, debug, debug-suspend set LAUNCH_MODE=fg @@ -37,10 +45,4 @@ set LAUNCH_MODE=fg :: NOTE: This variable is ignored if not launching in a debugging mode. set DEBUG_ADDRESS=127.0.0.1:13002 -:: Limit the # of garbage collection and JIT compiler threads in case many headless -:: instances are run in parallel. By default, Java will assign one thread per core -:: which does not scale well on servers with many cores. -set VMARG_LIST=-XX:ParallelGCThreads=2 -set VMARG_LIST=%VMARG_LIST% -XX:CICompilerCount=2 - call "%~dp0launch.bat" %LAUNCH_MODE% jdk Ghidra-Jython "%GHIDRA_JYTHON_MAXMEM%" "%VMARG_LIST%" ghidra.jython.JythonRun %* diff --git a/Ghidra/RuntimeScripts/Windows/support/launch.bat b/Ghidra/RuntimeScripts/Windows/support/launch.bat index f317f53dd4..c016e5394f 100644 --- a/Ghidra/RuntimeScripts/Windows/support/launch.bat +++ b/Ghidra/RuntimeScripts/Windows/support/launch.bat @@ -65,10 +65,13 @@ if not "%SUPPORT_DIR:!=%"=="%SUPPORT_DIR%" ( :: Delay the expansion of our loop items below since the value is being updated as the loop works setlocal enabledelayedexpansion +set VMARGS_FROM_CALLER= +set VMARGS_FROM_LAUNCH_BAT= +set VMARGS_FROM_LAUNCH_PROPS= + :: :: Parse arguments :: -set VMARG_LIST= set ARGS= set /A INDEX=0 :shift_loop @@ -79,7 +82,7 @@ IF DEFINED ARG ( ) else if "!INDEX!"=="2" ( if "%~1" == "jre" (set JAVA_TYPE_ARG=-java_home) else (set JAVA_TYPE_ARG=-jdk_home) ) else if "!INDEX!"=="3" ( set APPNAME=%~1 ) else if "!INDEX!"=="4" ( set MAXMEM=%~1 - ) else if "!INDEX!"=="5" ( if not "%~1"=="" set VMARG_LIST=%~1 + ) else if "!INDEX!"=="5" ( if not "%~1"=="" set VMARGS_FROM_CALLER=%~1 ) else if "!INDEX!"=="6" ( set CLASSNAME=%~1 ) else set ARGS=!ARGS! "%~1" @@ -124,7 +127,7 @@ set "DEBUG_LOG4J=%INSTALL_DIR%\Ghidra\RuntimeScripts\Common\support\debug.log4j. :: This is to force Java to use the USERPROFILE directory for user.home if exist "%USERPROFILE%" ( - set VMARG_LIST=%VMARG_LIST% -Duser.home="%USERPROFILE%" + set VMARGS_FROM_LAUNCH_BAT=%VMARGS_FROM_LAUNCH_BAT% -Duser.home="%USERPROFILE%" ) :: check for java based upon PATH @@ -179,11 +182,11 @@ for /f "delims=*" %%i in ('call "%JAVA_CMD%" -cp "%LS_CPATH%" LaunchSupport "%IN ) :: Get the configurable VM arguments from the launch properties -for /f "delims=*" %%i in ('call "%JAVA_CMD%" -cp "%LS_CPATH%" LaunchSupport "%INSTALL_DIR%" -vmargs') do set VMARG_LIST=!VMARG_LIST! %%i +for /f "delims=*" %%i in ('call "%JAVA_CMD%" -cp "%LS_CPATH%" LaunchSupport "%INSTALL_DIR%" -vmargs') do set VMARGS_FROM_LAUNCH_PROPS=!VMARGS_FROM_LAUNCH_PROPS! %%i :: Set Max Heap Size if specified if not "%MAXMEM%"=="" ( - set VMARG_LIST=%VMARG_LIST% -Xmx%MAXMEM% + set VMARGS_FROM_LAUNCH_BAT=%VMARGS_FROM_LAUNCH_BAT% -Xmx%MAXMEM% ) set BACKGROUND=n @@ -204,8 +207,8 @@ if "%DEBUG%"=="y" ( set DEBUG_ADDRESS=127.0.0.1:18001 ) - set VMARG_LIST=!VMARG_LIST! -Dlog4j.configurationFile="!DEBUG_LOG4J!" - set VMARG_LIST=!VMARG_LIST! -agentlib:jdwp=transport=dt_socket,server=y,suspend=!SUSPEND!,address=!DEBUG_ADDRESS! + set VMARGS_FROM_LAUNCH_BAT=!VMARGS_FROM_LAUNCH_BAT! -Dlog4j.configurationFile="!DEBUG_LOG4J!" + set VMARGS_FROM_LAUNCH_BAT=!VMARGS_FROM_LAUNCH_BAT! -agentlib:jdwp=transport=dt_socket,server=y,suspend=!SUSPEND!,address=!DEBUG_ADDRESS! goto continue4 ) @@ -223,7 +226,7 @@ exit /B 1 :continue4 -set CMD_ARGS=%FORCE_JAVA_VERSION% %JAVA_USER_HOME_DIR_OVERRIDE% %VMARG_LIST% -cp "%CPATH%" ghidra.Ghidra %CLASSNAME% %ARGS% +set CMD_ARGS=%FORCE_JAVA_VERSION% %JAVA_USER_HOME_DIR_OVERRIDE% %VMARGS_FROM_LAUNCH_PROPS% %VMARGS_FROM_LAUNCH_BAT% %VMARGS_FROM_CALLER% -cp "%CPATH%" ghidra.Ghidra %CLASSNAME% %ARGS% if "%BACKGROUND%"=="y" ( set JAVA_CMD=!JAVA_CMD!w