Skip to content

Setup custom launch options for IntelliJ IDEA / Android Studio

The settings can be changed by selecting in IntelliJ IDEA or Android Studio
Help -> Edit Custom VM Options (not to be confused with gradle.properties),
if they can't be saved, open them in a text editor in administrator mode

Here's a little explanation of each:

Xms2g:
Sets the initial JVM heap size to 2 gigabytes. This is the minimum size that will be allocated immediately after the JVM starts.

-Xmx8g:
Sets the maximum JVM heap size to 8 gigabytes. This is the limit on the maximum amount of memory that the JVM can use.

-XX:ReservedCodeCacheSize=2g:
Allocates 2 gigabytes for storing compiled code, improving performance by reducing the number of Just-In-Time (JIT) compilations.

-XX:+IgnoreUnrecognizedVMOptions:
Ignores unknown JVM options, which avoids errors when running with options that are not supported by the given JVM version.

-XX:+UseG1GC:
Includes the G1 garbage collector, which is designed to optimize large amounts of memory and minimize latency.

-XX:SoftRefLRUPolicyMSPerMB=50:
Sets the time in milliseconds that soft references will live after they were last accessed for each megabyte of free memory in the heap.

-XX:CICompilerCount=2:
Sets the number of Just-In-Time (JIT) compilers, which can improve startup time and performance when running new code.

-XX:+HeapDumpOnOutOfMemoryError:
If an out of memory error occurs, a heap dump will be created.

-XX:-OmitStackTraceInFastThrow:
Disables an optimization where the exception trace stack may be omitted for repeating exceptions.

-ea:
Enables assertion checks in the JVM.

-Dsun.io.useCanonCaches=false:
Disables caching of canonical paths, which can improve I/O behavior when files change outside the JVM.

-Djdk.http.auth.tunneling.disabledSchemes=””:
Allows the use of all authentication schemes when tunneling HTTP.

-Djdk.attach.allowAttachSelf=true:
Allows the Java virtual machine to attach itself to itself.

-Djdk.module.illegalAccess.silent=true:
Suppresses warnings about illegal API access.

-Dkotlinx.coroutines.debug=off:
Disables debugging of Kotlin coroutines.

-XX:ErrorFile=$USER_HOME/java_error_in_idea_%p.log:
Specifies the path to a file where JVM errors will be written.

-XX:HeapDumpPath=$USER_HOME/java_error_in_idea.hprof:
Specifies the path to save the heap dump when an out-of-memory error occurs.\

— add-opens:
These options remove Java's modularity limitations by allowing access to the internal APIs of the ASM libraries used to work with bytecode.

-javaagent:C:\Program Files\JetBrains\Activate\ja-netfilter.jar=jetbrains:
Points to a Java agent that is embedded into the JVM process to modify

In addition to these parameters, which are usually specified by default, you can also add others

Memory management and garbage collection:

XX:NewRatio=3:
Sets the ratio between the young generation and the old generation of the heap. A value of 3 means that the old generation will be three times larger than the young generation.

-XX:NewSize=512m:
Sets the initial size of the young generation.

-XX:MaxNewSize=1g:
Sets the maximum size of the young generation.

-XX:MaxPermSize=350m:
Sets the maximum size of the permanent generation for JVM versions prior to 8 (in Java 8 and above, this parameter is ignored due to the heap-based string move).

Performance and debugging settings:

XX:+DisableExplicitGC:
Prevents the system from calling garbage collection explicitly via System.gc().

-XX:+PrintGCDetails -XX:+PrintGCTimeStamps -Xloggc:/path/to/gc.log:
Enables detailed garbage collection logging, which can help diagnose performance issues.

-XX:+UseFastAccessorMethods:
Enables optimization of calls to simple methods (accessors).

-XX:+UseCompressedOops:
Enables the use of "compressed" object pointers to reduce memory usage on 64-bit JVMs.

Interface and user experience settings:

Dawt.useSystemAAFontSettings=on:
Enables font smoothing in the style of the operating system.

-Dswing.aatext=true:
Enables improved text antialiasing for Swing-based interfaces.

-Dsun.java2d.renderer=sun.java2d.marlin.MarlinRenderingEngine:
Uses Marlin as the 2D rendering engine, which can improve rendering performance.

Other options:

Dfile.encoding=UTF-8:
Sets the encoding of project files to UTF-8.

-Didea.paths.selector=AndroidStudio4.0:
Specifies a folder for Android Studio settings, plugins and logs, allowing you to have separate settings for different versions of Android Studio.

-Didea.platform.prefix=AndroidStudio:
Specifies the platform prefix, which may be necessary for some plugins.

Possible Garbage Collector options:

Serial GC (-XX:+UseSerialGC):
This is the simplest garbage collector, using single-threaded collection for both the young generation and the old generation of objects. This collector may be suitable for applications with limited resources and small amounts of data.

Parallel GC (-XX:+UseParallelGC):
Uses multiple threads for young generation garbage collection, which improves performance when working with large amounts of data and high throughput processing. It is the standard garbage collector for multi-threaded applications with large amounts of memory.

Concurrent Mark Sweep (CMS) GC (-XX:+UseConcMarkSweepGC):
Designed to reduce pause times caused by garbage collection by doing most of the work in the background. While CMS can process the heap quickly and reduce pause times, it can consume more CPU and memory.

Z Garbage Collector (ZGC) (-XX:+UseZGC):
It is a scalable, low-stalling garbage collector designed for applications that require large amounts of memory (hundreds of gigabytes) and minimal impact of garbage collection on latency. ZGC aims to limit latency to a few milliseconds or less, even when working with large heaps.

Shenandoah GC (-XX:+UseShenandoahGC):
Like ZGC, Shenandoah aims to minimize pause time during garbage collection by running mostly in parallel with program execution. It is designed to reduce latency when working with large amounts of memory.

You can configure memory settings for Android Studio in the tab
Settings -> Appearance & Behavior -> System Settings -> Memory Settings
At the time of writing this article, IntelliJ IDEA did not have this setting

Copyright: Roman Kryvolapov