Settings

Prepend options by environment variables

Select heap size by a percentage of available RAM

Use -XX:MaxRAMPercentage / -XX:MinRAMPercentage / -XX:InitialRAMPercentage

$ java -XX:+PrintFlagsFinal -version | grep RAMPercentage
   double InitialRAMPercentage                     = 1.562500                                  {product} {default}
   double MaxRAMPercentage                         = 25.000000                                 {product} {default}
   double MinRAMPercentage                         = 50.000000                                 {product} {default}
openjdk version "11.0.16.1" 2022-08-12

Container Awareness

openjdk container awareness

Set the TTL for DNS Name Lookups

Use networkaddress.cache.ttl / networkaddress.cache.negative.ttl

sun.net.inetaddr.ttl / sun.net.inetaddr.negative.ttl are the legacy properties. They have the same meaning as networkaddress.cache.ttl / networkaddress.cache.negative.ttl, but preferred way is networkaddress.cache.ttl / networkaddress.cache.negative.ttl.

Monitoring

inspect system properties of running jvm process

jcmd <pid> VM.system_properties

Native Memory Tracking

Enable NMT by -XX:NativeMemoryTracking=[summary | detail] and execute

jcmd <pid> VM.native_memory [summary | detail | baseline | summary.diff | detail.diff | shutdown] [scale= KB | MB | GB]

Count Theads

Check the Safe Memory Reclamation (SMR) info of thread dump. length is count of non-JVM internal threads.

Threads class SMR info:
_java_thread_list=0x00007f7d40428050, length=252, elements={

Note: Enabling NMT causes a 5% -10% performance overhead.

Profiling

Memory management

GC

Direct Buffer & Buffer Pool

Given a direct byte buffer, the Java virtual machine will make a best effort to perform native I/O operations directly upon it. That is, it will attempt to avoid copying the buffer’s content to (or from) an intermediate buffer before (or after) each invocation of one of the underlying operating system’s native I/O operations.

From Direct vs. non-direct buffers

Variable Handles

Check class file major version

javap -verbose JavaClassNameOrPath | grep major

Libraries and tools

Libraries I commonly use for java projects.

Commands

References