JVM:如何查看并设置jvm参数+jinfo+查看详细的jvm参数java-XX

JVM:如何查看jvm设置的参数

查看jvm参数

我们什么都不要管,先来看一下,眼见为实

jps:查看当前java进程id,java本身就是一个进程

[root@hecs-82454 ~]# jps

30101 Jps

27046 jar

[root@hecs-82454 ~]# jinfo -flags 27046

Attaching to process ID 27046, please wait...

Debugger attached successfully.

Server compiler detected.

JVM version is 25.201-b09

Non-default VM flags: -XX:CICompilerCount=2 -XX:InitialHeapSize=31457280 -XX:MaxHeapSize=482344960 -XX:MaxNewSize=160759808 -XX:MinHeapDeltaBytes=196608 -XX:NewSize=10485760 -XX:OldSize=20971520 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops

Command line:

[root@hecs-82454 ~]#

当然,如果你在服务器上有一个java服务在启动,那也可以根据你的服务的id来查看,两者结果是一致的

[root@hecs-82454 ~]# ps -ef |grep java

root 27046 1 0 09:48 ? 00:00:45 java -jar huaweiyun-0.0.1-SNAPSHOT.jar

root 30159 30063 0 20:24 pts/1 00:00:00 grep --color=auto java

[root@hecs-82454 ~]# jinfo -flags 27046

Attaching to process ID 27046, please wait...

Debugger attached successfully.

Server compiler detected.

JVM version is 25.201-b09

Non-default VM flags: -XX:CICompilerCount=2 -XX:InitialHeapSize=31457280 -XX:MaxHeapSize=482344960 -XX:MaxNewSize=160759808 -XX:MinHeapDeltaBytes=196608 -XX:NewSize=10485760 -XX:OldSize=20971520 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops

Command line:

[root@hecs-82454 ~]#

jinfo

看到了上面的之后我们再来了解jinfo命令

-flags pid

打印指定JVM的参数值 ,在上面我们已经看到了

-flag pid

我就要看jvm的某一个参数,偏偏我还能记得住这个参数的名字,那就用这个

[root@hecs-82454 ~]# jps

27046 jar

30283 Jps

[root@hecs-82454 ~]# jinfo -flag MaxNewSize 27046

-XX:MaxNewSize=160759808

[root@hecs-82454 ~]#

-flag = pid

设置指定JVM参数的值

[root@hecs-82454 ~]# jinfo -flag MaxNewSize=31457280 27046

Exception in thread "main" com.sun.tools.attach.AttachOperationFailedException: flag 'MaxNewSize' cannot be changed

at sun.tools.attach.LinuxVirtualMachine.execute(LinuxVirtualMachine.java:229)

at sun.tools.attach.HotSpotVirtualMachine.executeCommand(HotSpotVirtualMachine.java:261)

at sun.tools.attach.HotSpotVirtualMachine.setFlag(HotSpotVirtualMachine.java:234)

at sun.tools.jinfo.JInfo.flag(JInfo.java:134)

at sun.tools.jinfo.JInfo.main(JInfo.java:81)

报错了,为什么呢,因为虽然jinfo支持动态修改参数,但不是所有参数都支持修改,如修改最大堆内存就会异常,emmm,尝试了一下,几乎打印出来的参数好像都不可以修改,但是可以修改一些其他不太重要的参数,这个不重要的参数是怎么来的,下面讲java -XX的时候就可以看到了

[root@hecs-82454 ~]# jinfo -flag MaxHeapFreeRatio 27046

-XX:MaxHeapFreeRatio=70

[root@hecs-82454 ~]# jinfo -flag MaxHeapFreeRatio=71 27046

[root@hecs-82454 ~]# jinfo -flag MaxHeapFreeRatio 27046

-XX:MaxHeapFreeRatio=71

[root@hecs-82454 ~]#

设置JVM参数

-flag [±]name pid

开启或关闭对应名称的参数

[root@hecs-82454 ~]# jinfo -flag PrintGCTimeStamps 27046

-XX:-PrintGCTimeStamps

[root@hecs-82454 ~]# jinfo -flag -PrintGCTimeStamps 27046

[root@hecs-82454 ~]# jinfo -flag PrintGCTimeStamps 27046

-XX:-PrintGCTimeStamps

[root@hecs-82454 ~]# jinfo -flag +PrintGCTimeStamps 27046

[root@hecs-82454 ~]# jinfo -flag PrintGCTimeStamps 27046

-XX:+PrintGCTimeStamps

恕我直言,我没看出区别来,但是其中比较重要的一点是可以启动gc输出

[root@hecs-82454 ~]# jinfo -flag +PrintGC 31440

java -XX 查看更详细的jvm参数

还有可以查看更详细参数的命令

下面这个是查看jvm设置初始值的

[root@hecs-82454 ~]# java -XX:+PrintFlagsInitial

[Global flags]

intx ActiveProcessorCount = -1 {product}

uintx AdaptiveSizeDecrementScaleFactor = 4 {product}

uintx AdaptiveSizeMajorGCDecayTimeScale = 10 {product}

uintx AdaptiveSizePausePolicy = 0 {product}

uintx AdaptiveSizePolicyCollectionCostMargin = 50 {product}

uintx AdaptiveSizePolicyInitializingSteps = 20 {product}

uintx AdaptiveSizePolicyOutputInterval = 0 {product}

uintx AdaptiveSizePolicyWeight = 10 {product}

uintx AdaptiveSizeThroughPutPolicy = 0 {product}

uintx AdaptiveTimeWeight = 25 {product}

bool AdjustConcurrency = false {product}

bool AggressiveHeap = false

。。。。。。。。等等等等,很长很长

[root@hecs-82454 ~]#

比如说,我们就看到了

下面这个查看的是jvm参数的的最终值

[root@hecs-82454 ~]# java -XX:+PrintFlagsFinal

最后这个查看的是被新值覆盖了的参数

[root@hecs-82454 ~]# java -XX:+PrintCommandLineFlags

日本不卡视频一区二区三区-高清版在线影院观看-亚洲AV
古代将军上战场为什么要系着披风?关键时刻用处很大,不能小看