afredlyj / mynote

idea and note
1 stars 0 forks source link

JVM 相关 #16

Open afredlyj opened 8 years ago

afredlyj commented 8 years ago

GC日志

YGC时,gc日志的年轻代总量是:Eden + 1 Survivor Space,比如:

45575.014: [GC45575.014: [ParNew: 181159K->5136K(349568K), 0.0130460 secs] 208819K->33552K(1922432K), 0.0132140 secs] [Times: user=0.04 sys=0.00, real=0.01 secs] 

可以通过jmap命令查看:

[root@ap3 bin]# jmap -heap 14120
Attaching to process ID 14120, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.79-b02

using parallel threads in the new generation.
using thread-local object allocation.
Concurrent Mark-Sweep GC

Heap Configuration:
   MinHeapFreeRatio = 40
   MaxHeapFreeRatio = 70
   MaxHeapSize      = 2147483648 (2048.0MB)
   NewSize          = 536870912 (512.0MB)
   MaxNewSize       = 536870912 (512.0MB)
   OldSize          = 5439488 (5.1875MB)
   NewRatio         = 2
   SurvivorRatio    = 1
   PermSize         = 67108864 (64.0MB)
   MaxPermSize      = 67108864 (64.0MB)
   G1HeapRegionSize = 0 (0.0MB)

Heap Usage:
New Generation (Eden + 1 Survivor Space):
   capacity = 357957632 (341.375MB)
   used     = 186403760 (177.7684783935547MB)
   free     = 171553872 (163.6065216064453MB)
   52.074252184124404% used
Eden Space:
   capacity = 179044352 (170.75MB)
   used     = 160350320 (152.92198181152344MB)
   free     = 18694032 (17.828018188476562MB)
   89.55899374027727% used
From Space:
   capacity = 178913280 (170.625MB)
   used     = 26053440 (24.84649658203125MB)
   free     = 152859840 (145.77850341796875MB)
   14.562049278846153% used
To Space:
   capacity = 178913280 (170.625MB)
   used     = 0 (0.0MB)
   free     = 178913280 (170.625MB)
   0.0% used
concurrent mark-sweep generation:
   capacity = 1610612736 (1536.0MB)
   used     = 0 (0.0MB)
   free     = 1610612736 (1536.0MB)
   0.0% used
Perm Generation:
   capacity = 67108864 (64.0MB)
   used     = 37763832 (36.01439666748047MB)
   free     = 29345032 (27.98560333251953MB)
   56.27249479293823% used

18889 interned Strings occupying 1689408 bytes.

gc日志中新生代大小为349568K,而JVM启动参数如下:

-Xms2g -Xmx2g -Xmn512m -Xss256K -XX:PermSize=64m -XX:MaxPermSize=64m

Eden 区大小为:512 * (1 / 3) = 170.6 1 Survivor Space大小为:512 * (1 / 3) = 170.6 349568K = Eden 区大小为 + 1 Survivor Space大小 = 170.6 + 170.6

afredlyj commented 7 years ago

Synchronized 原理

http://www.infoq.com/cn/articles/java-se-16-synchronized 更多内容可以参考《深入理解Java虚拟机》P391

Volatile 原理

http://www.infoq.com/cn/articles/ftf-java-volatile