I'm running my java application on apline linux system in docker container, and I wanna find out the value of MaxHeapSize, so I use several command : java -XX: PrintFlagsFinal, jinfo -flag MaxHeapSize , jmap -heap, but the output made me feel confused. The output of jinfo -flag MaxHeapSize , jmap -heap are consistent. However, The output of java -XX: PrintFlagsFinal is different.so why did this happen?
The default container memory Limit setting is 4096MiB.
The output of java commonds is shown below.(I marked some important parts in the picture)
bash-5.0# jps -v
9 jar -Dfile.encoding=utf-8 -XX: UseG1GC -XX: UseStringDeduplication -XX:-OmitStackTraceInFastThrow -XX:MaxRAMPercentage=60.0 -XX:InitialRAMPercentage=20.0 -XX: PrintTenuringDistribution -XX: PrintGCDetails -XX: PrintCommandLineFlags -XX: PrintHeapAtGC -XX: PrintGCDateStamps -XX: PrintGCTimeStamps -Xloggc:log/gc-%t.log -Duser.timezone=Asia/Shanghai -Delastic.apm.service_name=SUPER-STUDENTS -Delastic.apm.environment=k8s-prod-th-zhidao-manhattan -Delastic.apm.server_urls= -Delastic.apm.trace_methods= -Delastic.apm.trace_methods_duration_threshold=100ms -Delastic.apm.application_packages=outfox -Delastic.apm.capture_body=all -Delastic.apm.ignore_message_queues=* -Delastic.apm.profiling_inferred_spans_enabled=true -Delastic.apm.profiling_inferred_spans_sampling_interval=10ms -Delastic.apm.profiling_inferred_spans_min_duration=50ms -Dskywalking.agent.service_name=super-students -Dskywalking.agent.instance_name=super-students-75f964dbbd-5gfnv -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1234
64155 Jps -Dapplication.home=/opt/java/openjdk -Xms8m
bash-5.0# java -XX: PrintFlagsFinal -version | grep -Ei "maxheapsize|maxram"
uintx DefaultMaxRAMFraction = 4 {product}
uintx MaxHeapSize := 1073741824 {product}
uint64_t MaxRAM = 137438953472 {pd product}
uintx MaxRAMFraction = 4 {product}
double MaxRAMPercentage = 25.000000 {product}
openjdk version "1.8.0_282"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_282-b08)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.282-b08, mixed mode)
bash-5.0# jinfo -flag MaxHeapSize 9
-XX:MaxHeapSize=2577399808
bash-5.0# jmap -heap 9
Attaching to process ID 9, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.282-b08
using thread-local object allocation.
Garbage-First (G1) GC with 1 thread(s)
Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 2577399808 (2458.0MB)
NewSize = 1363144 (1.2999954223632812MB)
MaxNewSize = 1545601024 (1474.0MB)
OldSize = 5452592 (5.1999969482421875MB)
NewRatio = 2
SurvivorRatio = 8
MetaspaceSize = 21807104 (20.796875MB)
CompressedClassSpaceSize = 1073741824 (1024.0MB)
MaxMetaspaceSize = 17592186044415 MB
G1HeapRegionSize = 1048576 (1.0MB)
Heap Usage:
G1 Heap:
regions = 2458
capacity = 2577399808 (2458.0MB)
used = 320120112 (305.2903289794922MB)
free = 2257279696 (2152.709671020508MB)
12.420273758319455% used
G1 Young Generation:
Eden Space:
regions = 53
capacity = 654311424 (624.0MB)
used = 55574528 (53.0MB)
free = 598736896 (571.0MB)
8.493589743589743% used
Survivor Space:
regions = 10
capacity = 10485760 (10.0MB)
used = 10485760 (10.0MB)
free = 0 (0.0MB)
100.0% used
G1 Old Generation:
regions = 247
capacity = 389021696 (371.0MB)
used = 254059824 (242.2903289794922MB)
free = 134961872 (128.7096710205078MB)
65.30736630174992% used
63962 interned Strings occupying 6772928 bytes.
CodePudding user response:
These are not comparing the same thing.
When running jmap
or jstack
, these attach to the existing process with PID 9, as listed in the first jps
command.
When running java -XX: PrintFlagsFinal -version
, this creates a new JVM process, and prints the information for that new process. Note that the original PID 9 process has a number of additional flags that can affect the calculated heap size.
For a more accurate comparison, you could add the -XX: PrintFlagsFinal
flags to the main command run when the container starts. I would expect this to match the values returned by jinfo
and jmap
.