본문 바로가기

리눅스

[리눅스] JVM(JAVA) Option

728x90

리눅스 JVM(JAVA) Option

테스트 환경

$ cat /etc/redhat-release
Red Hat Enterprise Linux release 8.4 (Ootpa)

$ getconf LONG_BIT
64

$ java --version
openjdk 17.0.1 2021-10-19
OpenJDK Runtime Environment (build 17.0.1+12-39)
OpenJDK 64-Bit Server VM (build 17.0.1+12-39, mixed mode, sharing)

테스트 환경 메모리 사이즈(물리적 메모리=2GB)

$ cat /proc/meminfo | grep MemTotal
MemTotal:        2035832 kB

힙 사이즈(heap size)

- 초기 힙 크기 : 물리적 메모리의 1/64
- 최대 힙 크기 : 물리적 메모리의 1/4

- 힙 사이즈를 동일하게 설정하는 이유는 힙 사이즈를 변경하기 위해 런타임 기간에 발생하는 불필요한 오버헤드를 줄이기 위함.

https://docs.oracle.com/en/java/javase/11/gctuning/ergonomics.html#GUID-DB4CAE94-2041-4A16-90EC-6AE3D91EC1F1

Java Default Heap/MetaspaceSize(Perm Size) 확인하기

java -XX:+PrintFlagsFinal -version 2>&1 | egrep -i 'heapsize|metaspacesize' 명령으로 확인

$ java -XX:+PrintFlagsFinal -version 2>&1 | egrep -i 'heapsize|metaspacesize'
   size_t ErgoHeapSizeLimit                        = 0                                         {product} {default}
   size_t HeapSizePerGCThread                      = 43620760                                  {product} {default}
   size_t InitialHeapSize                          = 33554432                                  {product} {ergonomic}
   size_t LargePageHeapSizeThreshold               = 134217728                                 {product} {default}
   size_t MaxHeapSize                              = 522190848                                 {product} {ergonomic}
   size_t MaxMetaspaceSize                         = 18446744073709551615                      {product} {default}
   size_t MetaspaceSize                            = 22020096                                  {product} {default}
   size_t MinHeapSize                              = 8388608                                   {product} {ergonomic}
    uintx NonNMethodCodeHeapSize                   = 5826188                                {pd product} {ergonomic}
    uintx NonProfiledCodeHeapSize                  = 122916026                              {pd product} {ergonomic}
    uintx ProfiledCodeHeapSize                     = 122916026                              {pd product} {ergonomic}
   size_t SoftMaxHeapSize                          = 522190848                              {manageable} {ergonomic}
옵션 사이트(kb)    
InitialHeapSize 33554432    
MaxHeapSize 522190848    
MetaspaceSize 22020096    
MaxMetaspaceSize 18446744073709551615    

힙 사이즈(heap size) 조정 방법

java help

$ java -help
Usage: java [options] <mainclass> [args...]
...
    -X            print help on extra options to the error stream

java 옵션(-X)

 -Xms=<size> 초기 Java 힙 크기 설정
 -Xmx=<size> 최대 Java 힙 크기 설정

 -XX:MetaspaceSize=<size> Metaspace Default Size 설정
 -XX:MaxMetaspaceSize=<size> Metaspace Max Size 설정

$ java -X

    -Xbatch           disable background compilation
    -Xbootclasspath/a:<directories and zip/jar files separated by :>
                      append to end of bootstrap class path
    -Xcheck:jni       perform additional checks for JNI functions
    -Xcomp            forces compilation of methods on first invocation
    -Xdebug           does nothing. Provided for backward compatibility.
    -Xdiag            show additional diagnostic messages
    -Xfuture          enable strictest checks, anticipating future default.
                      This option is deprecated and may be removed in a
                      future release.
    -Xint             interpreted mode execution only
    -Xinternalversion
                      displays more detailed JVM version information than the
                      -version option
    -Xlog:<opts>      Configure or enable logging with the Java Virtual
                      Machine (JVM) unified logging framework. Use -Xlog:help
                      for details.
    -Xloggc:<file>    log GC status to a file with time stamps.
                      This option is deprecated and may be removed in a
                      future release. It is replaced by -Xlog:gc:<file>.
    -Xmixed           mixed mode execution (default)
    -Xmn<size>        sets the initial and maximum size (in bytes) of the heap
                      for the young generation (nursery)
    -Xms<size>        set initial Java heap size
    -Xmx<size>        set maximum Java heap size
    -Xnoclassgc       disable class garbage collection
    -Xrs              reduce use of OS signals by Java/VM (see documentation)
    -Xshare:auto      use shared class data if possible (default)
    -Xshare:off       do not attempt to use shared class data
    -Xshare:on        require using shared class data, otherwise fail.
                      This is a testing option and may lead to intermittent
                      failures. It should not be used in production environments.
    -XshowSettings    show all settings and continue
    -XshowSettings:all
                      show all settings and continue
    -XshowSettings:locale
                      show all locale related settings and continue
    -XshowSettings:properties
                      show all property settings and continue
    -XshowSettings:vm
                      show all vm related settings and continue
    -XshowSettings:system
                      (Linux Only) show host system or container
                      configuration and continue
    -Xss<size>        set java thread stack size
    -Xverify          sets the mode of the bytecode verifier
                      Note that option -Xverify:none is deprecated and
                      may be removed in a future release.
    --add-reads <module>=<target-module>(,<target-module>)*
                      updates <module> to read <target-module>, regardless
                      of module declaration.
                      <target-module> can be ALL-UNNAMED to read all unnamed
                      modules.
    --add-exports <module>/<package>=<target-module>(,<target-module>)*
                      updates <module> to export <package> to <target-module>,
                      regardless of module declaration.
                      <target-module> can be ALL-UNNAMED to export to all
                      unnamed modules.
    --add-opens <module>/<package>=<target-module>(,<target-module>)*
                      updates <module> to open <package> to
                      <target-module>, regardless of module declaration.
    --limit-modules <module name>[,<module name>...]
                      limit the universe of observable modules
    --patch-module <module>=<file>(:<file>)*
                      override or augment a module with classes and resources
                      in JAR files or directories.
    --source <version>
                      set the version of the source in source-file mode.

These extra options are subject to change without notice.

JVM 메모리 구조

Heap Memory, Metaspace Memory(Off-Heap)

728x90