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

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)
Heap Memory와 Metaspace Memory는 Java 애플리케이션에서 메모리 관리를 위해 사용되는 두 가지 다른 메모리 영역입니다.
1. Heap Memory (힙 메모리)
- Heap Memory는 Java 프로그램에서 객체 인스턴스를 저장하고 관리하는 데 사용되는 메모리 영역입니다.
 - Java에서 생성된 모든 객체는 힙 메모리에 할당됩니다.
 - 힙 메모리는 두 부분으로 나뉩니다. Young Generation, Old Generation (또는 Tenured Generation), 그리고 Permanent Generation (Java 7 이전 버전에서) 또는 Metaspace (Java 8 이후 버전에서)로 구성됩니다.
 - Young Generation은 새로 생성된 객체가 할당되는 곳으로, 객체가 빠르게 생성되고 소멸하는 곳입니다. 
Old Generation은 Young Generation에서 살아남은 객체가 이동되는 곳으로, 오랜 시간 동안 살아 있는 객체가 저장됩니다. - Permanent Generation (Java 7 이전) 또는 Metaspace (Java 8 이후)는 클래스 메타데이터와 리플렉션을 통해 생성된 클래스 정보를 저장하는 곳입니다.
 
2. Metaspace Memory (또는 Off-Heap Memory)
- Metaspace는 Java 8 이후 버전에서 Permanent Generation을 대체한 새로운 메모리 영역입니다.
 - Metaspace는 클래스 로딩과 클래스 메타데이터 관리에 사용됩니다.
 - Permanent Generation과 달리 Metaspace는 힙 메모리 영역이 아니며, 일반적인 가비지 컬렉션의 영향을 받지 않습니다.
 - Metaspace의 크기는 필요에 따라 동적으로 확장될 수 있으므로 설정에 의해 제한되지 않습니다.
 - 이것은 클래스로더 및 클래스 메타데이터 관리에 대한 더 유연한 접근을 제공합니다.
 
Off-Heap Memory는 일반적으로 JVM의 힙 메모리 외부에 위치하며, 직접 관리해야 할 수도 있습니다. 이러한 메모리는 Java의 가비지 컬렉션 및 메모리 관리 기능의 대상이 아니므로 메모리 누수와 관련된 문제를 조심해야 합니다. Off-Heap 메모리를 사용하는 경우 메모리 관리 및 해제를 명시적으로 처리해야 하며, 주의 깊은 관리가 필요합니다. 일부 경우에는 성능 향상을 위해 Off-Heap 메모리를 사용하는 것이 유용할 수 있습니다.
'리눅스' 카테고리의 다른 글
| [draft] CentOS 8 미러 서버용 repo(CentOS-Base.repo) 파일 (0) | 2025.10.12 | 
|---|---|
| [draft] stress 명령어 (0) | 2025.10.12 | 
| [draft] sshpass 명령어 (0) | 2025.10.11 | 
| [draft] CentOS 7에서 전원 버튼을 비활성화하는 방법 (0) | 2025.10.11 | 
| [draft] 우분투 배포판 업그레이드 (0) | 2025.10.10 |