jvm gc相关

1. 杂类

http://www.oracle.com/technetwork/java/faq-140837.html 

*    -XX:+UseParallelGC : 和传统的新生代GC一样,只是可以进行并行标记处理。 可通过-XX:ParallelGCThreads指定并发线程数,默认值:-XX:ParallelGCThreads =<#cpus < 8 ? #cpus : 3 + ((5 * #cpus) / 8) >

 

 

The new parallel garbage collector is similar to the young generation collector in the default garbage collector but uses multiple threads to do the collection. By default on a host with N CPUs, the parallel garbage collector uses N garbage collector threads in the collection. The number of garbage collector threads can be controlled with a command line option (see below). On a host with a single CPU the default garbage collector is used even if the parallel garbage collector has been requested. On a host with 2 cpus the Parallel garbage collector generally performs as well as the default garbage collector and a reduction in the young generation garbage collector pause times can be expected on hosts with more than 2 cpus.

 

* XX:+UseParNewGC: 和UseParallelGC类似,也是并行处理,但实现技术还是不同,据说在新生代的火车模型上有更少的停顿时间。

 

-XX:+ DisableExplicitGC : 禁用system.gc()调用

 

Don't call System.gc(). The system will make the determination of when it's appropriate to do garbage collection and generally has the information necessary to do a much better job of initiating a garbage collection. If you are having problems with the garbage collection (pause times or frequency), consider adjusting the size of the generations.

 

* -XX:+AggressiveOpts 加快编译 

 

* -XX:+UseBiasedLocking 锁机制的性能改善。

 

* -Xss=256k

-Xss 是线程栈的大小, 这个参数需要严格的测试, 一般小的应用, 如果栈不是很深, 应该是128k够用的, 不过,我们的应用调用深度比较大, 还需要做详细的测试。 这个选项对性能的影响比较大。 建议使用256K的大小.

 

2. CMS介绍

文章:http://www.iteye.com/topic/473874

 

 

-XX:+CMSParallelRemarkEnabled : 在和UseParNewGC一起使用的情况下,尽量减少mark的时间

 

-XX:+UseConcMarkSweepGC : 指定在Old Generation使用concurrent gc

 

-XX:+UseCMSCompactAtFullCollection : 在使用concurrent gc的情况下,防止memory fragmention

 

-XX:CMSInitiatingOccupancyFraction=n : 指示在old generation在使用了n%的后,触发cms gc

 

-XX:+UseCMSInitiatingOccupancyOnly : 指示只有在old generation在使用了初始化的比例后启动cms gc

 

 

公司参数列表记录:

-server -Xmx2g -Xms2g -Xmn256m -XX:PermSize=128m
-Xss256k
-XX:+DisableExplicitGC
-XX:+UseConcMarkSweepGC
-XX:+CMSParallelRemarkEnabled
-XX:+UseCMSCompactAtFullCollection
-XX:LargePageSizeInBytes=128m
-XX:+UseFastAccessorMethods
-XX:+UseCMSInitiatingOccupancyOnly
-XX:CMSInitiatingOccupancyFraction=70

 

 

3. G1介绍

 

http://www.oracle.com/technetwork/java/javase/tech/g1-intro-jsp-135488.html

 

jdk 1.6.14中首次引入了G1. 

 

G1的特点描述: 

 

  1. 并发性和并行性。 充分利用系统硬件资源,多核多CPU的资源,通过多线程并发和并行技术,尽量减少“stop-the-world”,也就是系统停顿时间。
  2. 代收集。 和普通的GC收集器一样,区分young对象和old对象为不同的收集策略。针对young区关注的是存活的对象,因为young大多数都是需要被GC回收的。
  3. 压缩。 不同于CMS收集,G1垃圾收集器一直都会对heap区做压缩,避免内存碎片的产生。
  4. 可预测性。G1相比于CMS针对GC的“stop-the-world”的有更好的可预测性,主要归功于G1的压缩避免内存碎片对GC pause time的影响,G1还有相应的预测模型,通过许多方式,尽量去满足一个pause time的预期。
G1和CMS不同点:
  1. G1没有严格的young,old区的划分,它将整个heap区当作是一个连续的物理内存块进行处理。这样G1可以很方便,很灵活的进行对象的拷贝和移动。
  2. G1同样有from/to的survivors regoins
  3. G1和CMS一样会有 concurrent marking phase,通过并发从root对象进行存活对象进行标记,但是它与CMS相比,没有concurrent sweeping phase处理

G1相关参数:
  1. -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC (开启使用G1 GC)
  2. -XX:MaxGCPauseMillis =50 (for a pause time target of 50ms)
  3. -XX:GCPauseIntervalMillis =200 (for a pause interval target of 200ms)
  4. -XX:+G1YoungGenSize=512m  (for a 512 megabyte young generation) 这里搞不明白,是G1重新划分新生代?还是仅仅只是在GC中划分的区域。
  5.  -XX:SurvivorRatio=6 调整surivor regoins的大小
  6. -XX:+G1ParallelRSetUpdatingEnabled -XX:+G1ParallelRSetScanningEnabled 不知道干吗的,先记着


4. gc相关调试参数:


打印GC时间参数: -verbose:gc -XX:+PrintGCTimeStamps -XX:+PrintGCDetails -Xloggc:/home/test/logs/gc.log

49.414: [GC [PSYoungGen: 10480K->0K(524160K)] 11272K->792K(2097024K), 0.0002270 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
显示在程序运行的49.414发生了Minor的垃圾收集,前一段数据针对新生区,从10480K整理为0k,新生区总大小为524160K,程序暂停了0.2ms,而后一段数据针对整个堆。

详细暂停时间参数: -XX:+PrintGCApplicationConcurrentTime -XX:+PrintGCApplicationStoppedTime
 

5. GC算法组合

GC的算法
复制(Copying)
标记-清除(Mark-Sweep)
标记-清除-整理(Mark-Sweep-Compact)
 

 

三种垃圾收集器
Serial GC
Parallel GC/Parallel Old GC
Concurrent Mark-Sweep GC (CMS)

 

GC算法组合:

 

说明:

  • UseSerialGC:"Serial" + "Serial Old"
  • UseParNewGC:"ParNew" + "Serial Old"
  • UseConcMarkSweepGC:"ParNew" + "CMS" + "Serial Old". "CMS" is used most of the time to collect the tenured generation. "Serial Old" is used when a concurrent mode failure occurs.
  • UseParallelGC:"Parallel Scavenge" + "Serial Old"
  • UseParallelOldGC:"Parallel Scavenge" + "Parallel Old"

如果GC算法参数搭配不合理,会出现类似错误:

写道
Conflicting collector combinations in option list; please refer to the release notes for the combinations allowed
Could not create the Java virtual machine.

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值