1. 杂类
http://www.oracle.com/technetwork/java/faq-140837.html
* -XX:+UseParallelGC : 和传统的新生代GC一样,只是可以进行并行标记处理。 可通过-XX:ParallelGCThreads指定并发线程数,默认值:-XX:ParallelGCThreads =<#cpus < 8 ? #cpus : 3 + ((5 * #cpus) / 8) >
1.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()调用
1.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
1.-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
公司参数列表记录:
1.-server -Xmx2g -Xms2g -Xmn256m -XX:PermSize=128m
2.-Xss256k
3.-XX:+DisableExplicitGC
4.-XX:+UseConcMarkSweepGC
5.-XX:+CMSParallelRemarkEnabled
6.-XX:+UseCMSCompactAtFullCollection
7.-XX:LargePageSizeInBytes=128m
8.-XX:+UseFastAccessorMethods
9.-XX:+UseCMSInitiatingOccupancyOnly
10.-XX:CMSInitiatingOccupancyFraction=70
3. G1介绍
http://www.oracle.com/technetwork/java/javase/tech/g1-intro-jsp-135488.html
jdk 1.6.14中首次引入了G1.
G1的特点描述:
- 并发性和并行性。 充分利用系统硬件资源,多核多CPU的资源,通过多线程并发和并行技术,尽量减少“stop-the-world”,也就是系统停顿时间。
- 代收集。 和普通的GC收集器一样,区分young对象和old对象为不同的收集策略。针对young区关注的是存活的对象,因为young大多数都是需要被GC回收的。
- 压缩。 不同于CMS收集,G1垃圾收集器一直都会对heap区做压缩,避免内存碎片的产生。
- 可预测性。G1相比于CMS针对GC的“stop-the-world”的有更好的可预测性,主要归功于G1的压缩避免内存碎片对GC pause time的影响,G1还有相应的预测模型,通过许多方式,尽量去满足一个pause time的预期。
- G1没有严格的young,old区的划分,它将整个heap区当作是一个连续的物理内存块进行处理。这样G1可以很方便,很灵活的进行对象的拷贝和移动。
- G1同样有from/to的survivors regoins
- G1和CMS一样会有 concurrent marking phase,通过并发从root对象进行存活对象进行标记,但是它与CMS相比,没有concurrent sweeping phase处理
- -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC (开启使用G1 GC)
- -XX:MaxGCPauseMillis =50 (for a pause time target of 50ms)
- -XX:GCPauseIntervalMillis =200 (for a pause interval target of 200ms)
-XX:+G1YoungGenSize=512m
(for a 512 megabyte young generation) 这里搞不明白,是G1重新划分新生代?还是仅仅只是在GC中划分的区域。-
-XX:SurvivorRatio=6 调整surivor regoins的大小
-XX:+G1ParallelRSetUpdatingEnabled -XX:+G1ParallelRSetScanningEnabled 不知道干吗的,先记着
4. gc相关调试参数:
打印GC时间参数: -verbose:gc -XX:+PrintGCTimeStamps -XX:+PrintGCDetails -Xloggc:/home/test/logs/gc.log
.
1.49.414: [GC [PSYoungGen: 10480K->0K(524160K)] 11272K->792K(2097024K), 0.0002270 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
详细暂停时间参数: -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算法参数搭配不合理,会出现类似错误:
Could not create the Java virtual machine.