jvm 为什么java -XX:+PrintFlagsFinal和jinfo -flag的最大堆大小值不同

j0pj023g  于 2022-11-07  发布在  Java
关注(0)|答案(1)|浏览(187)

我正在Docker容器中的apline linux系统上运行我的java应用程序,我想找出MaxHeapSize的值,所以我使用了几个命令:java -XX:+PrintFlagsFinal,jinfo -flag MaxHeapSize,jmap -heap,但是输出结果让我感到困惑。jinfo -flag MaxHeapSize,jmap -heap的输出结果是一致的。但是,java -XX:+PrintFlagsFinal的输出结果是different.so为什么会出现这种情况呢?
默认的容器内存限制设置为4096 MiB。
enter image description here
java命令的输出如下所示。(我在图片中标记了一些重要的部分)

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.

enter image description here

smdnsysy

smdnsysy1#

这些不是在比较同一件事。
当运行jmapjstack时,它们将连接到PID为9的现有进程,如第一个jps命令中所列。
当运行java -XX:+PrintFlagsFinal -version时,这将创建一个新的JVM进程,并打印该新进程的信息。请注意,原始PID 9进程有许多额外的标志,这些标志可能会影响计算的堆大小。
为了进行更准确的比较,您可以在容器启动时将-XX:+PrintFlagsFinal标志添加到主命令运行中,我希望它与jinfojmap返回的值匹配。

相关问题