java.lang.OutOfMemoryError:GC overhead limit exceeded
我遇到这样的问题,本地部署时抛出异常java.lang.OutOfMemoryError:GC overhead limit exceeded导致服务起不来,查看日志发现加载了太多资源到内存,本地的性能也不好,gc时间消耗的较多。解决这种问题两种方法是,增加参数,-XX:-UseGCOverheadLimit,关闭这个特性,同时增加heap大小,-Xmx1024m。这样坑可以填了!!!但是原因是什么呢?
OOM大家都知道,就是JVM内存溢出了,那GC overhead limit exceed呢?
GC overhead limt exceed检查是Hotspot VM 1.6定义的一个策略,通过统计GC时间来预测是否要OOM了,提前抛出异常,防止OOM发生。Sun 官方对此的定义是:“并行/并发回收器在GC回收时间过长时会抛出OutOfMemroyError。过长的定义是,超过98%的时间用来做GC并且回收了不到2%的堆内存。用来避免内存过小造成应用不能正常工作。“
听起来没啥用...预测OOM有用!你想想,gc多次运行,但是没有回收到空间,很多对象还存在,那么很可能就会出现oom,那么这个异常就是提前爆出来的。起初开来这玩意只能用来Catch住释放内存资源,避免应用挂掉。后来发现一般情况下这个策略不能拯救你的应用,但是可以在应用挂掉之前做最后的挣扎,比如数据保存或者保存现场(Heap Dump)。
而且有些时候这个策略还会带来问题,比如加载某个大的内存数据时频繁OOM。
假如你也生产环境中遇到了这个问题,在不知道原因时不要简单的猜测和规避。可以通过-verbose:gc -XX:+PrintGCDetails看下到底什么原因造成了异常。通常原因都是因为old区占用过多导致频繁Full GC,最终导致GC overhead limit exceed。如果gc log不够可以借助于JProfile等工具查看内存的占用,old区是否有内存泄露。分析内存泄露还有一个方法-XX:+HeapDumpOnOutOfMemoryError,这样OOM时会自动做Heap Dump,可以拿MAT来排查了。还要留意young区,如果有过多短暂对象分配,可能也会抛这个异常。
日志的信息不难理解,就是每次gc时打条日志,记录GC的类型,前后大小和时间。举个例子。
33.125: [GC [DefNew: 16000K->16000K(16192K), 0.0000574 secs][Tenured: 2973K->2704K(16384K), 0.1012650 secs] 18973K->2704K(32576K), 0.1015066 secs]
100.667:[Full GC [Tenured: 0K->210K(10240K), 0.0149142 secs] 4603K->210K(19456K), [Perm : 2999K->2999K(21248K)], 0.0150007 secs]
GC和Full GC代表gc的停顿类型,Full GC代表stop-the-world。箭头两边是gc前后的区空间大小,分别是young区、tenured区和perm区,括号里是该区的总大小。冒号前面是gc发生的时间,单位是秒,从jvm启动开始计算。DefNew代表Serial收集器,为Default New Generation的缩写,类似的还有PSYoungGen,代表Parallel Scavenge收集器。这样可以通过分析日志找到导致GC overhead limit exceeded的原因,通过调节相应的参数解决问题。
文中涉及到的名词解释,
Eden Space:堆内存池,大多数对象在这里分配内存空间。
Survivor Space:堆内存池,存储在Eden Space的gc中存活下来的对象。
Tenured Generation:堆内存池,存储Survivor Space中存活过几次gc的对象。
Permanent Generation:非堆空间,存储的是class和method对象。
Code Cache:非堆空间,JVM用来存储编译和存储native code。
最后附上GC overhead limit exceed HotSpot的实现:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
bool print_gc_overhead_limit_would_be_exceeded = false ;
if (is_full_gc) {
if (gc_cost() > gc_cost_limit &&
free_in_old_gen < ( size_t ) mem_free_old_limit &&
free_in_eden < ( size_t ) mem_free_eden_limit) {
// Collections, on average, are taking too much time, and
// gc_cost() > gc_cost_limit
// we have too little space available after a full gc.
// total_free_limit < mem_free_limit
// where
// total_free_limit is the free space available in
// both generations
// total_mem is the total space available for allocation
// in both generations (survivor spaces are not included
// just as they are not included in eden_limit).
// mem_free_limit is a fraction of total_mem judged to be an
// acceptable amount that is still unused.
// The heap can ask for the value of this variable when deciding
// whether to thrown an OutOfMemory error.
// Note that the gc time limit test only works for the collections
// of the young gen + tenured gen and not for collections of the
// permanent gen. That is because the calculation of the space
// freed by the collection is the free space in the young gen +
// tenured gen.
// At this point the GC overhead limit is being exceeded.
inc_gc_overhead_limit_count();
if (UseGCOverheadLimit) {
if (gc_overhead_limit_count() >=
AdaptiveSizePolicyGCTimeLimitThreshold){
// All conditions have been met for throwing an out-of-memory
set_gc_overhead_limit_exceeded( true );
// Avoid consecutive OOM due to the gc time limit by resetting
// the counter.
reset_gc_overhead_limit_count();
} else {
// The required consecutive collections which exceed the
// GC time limit may or may not have been reached. We
// are approaching that condition and so as not to
// throw an out-of-memory before all SoftRef's have been
// cleared, set _should_clear_all_soft_refs in CollectorPolicy.
// The clearing will be done on the next GC.
bool near_limit = gc_overhead_limit_near();
if (near_limit) {
collector_policy->set_should_clear_all_soft_refs( true );
if (PrintGCDetails && Verbose) {
gclog_or_tty->print_cr( " Nearing GC overhead limit, "
"will be clearing all SoftReference" );
}
}
}
}
// Set this even when the overhead limit will not
// cause an out-of-memory. Diagnostic message indicating
// that the overhead limit is being exceeded is sometimes
// printed.
print_gc_overhead_limit_would_be_exceeded = true ;
} else {
// Did not exceed overhead limits
reset_gc_overhead_limit_count();
}
}
|
参照&延伸阅读:
http://javaeesupportpatterns.blogspot.com/2012/01/gc-overhead-limit-exceeded-understand.html
http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html
http://reins.altervista.org/java/gc1.4.2_example.html
http://stackoverflow.com/questions/2129044/java-heap-terminology-young-old-and-permanent-generations
http://book.51cto.com/art/201306/399236.htm
https://blogs.oracle.com/jonthecollector/entry/presenting_the_permanent_generation
java.lang.OutOfMemoryError:GC overhead limit exceeded相关推荐
- java.lang.OutOfMemoryError:GC overhead limit exceeded填坑心得
该文章出自:http://www.cnblogs.com/hucn/p/3572384.html 分析工具:http://www.blogjava.net/jjshcc/archive/2014/03 ...
- java.lang.OutOfMemoryError:GC overhead limit exceeded解决方法
异常如下:Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded 一.解 ...
- Eclipse报错:gc overhead limit exceeded eclipse
Eclipse报错:gc overhead limit exceeded eclipse 原因是Eclipse默认配置内存太小需要更改Eclipse安装文件夹下的eclipse.ini文件. 1.打开 ...
- spark程序运行异常:java.lang.OutOfMemoryError: GC overhead limit exceeded
此次异常是在集群上运行的spark程序日志中发现的.由于这个异常导致sparkcontext被终止,以致于任务失败: 出现的一些原因 参考:GC overhead limit exceeded jav ...
- IDEA 编译项目时报:java.lang.OutOfMemoryError:GC overhead limit exceeded
1.问题简述 在Intellij IDEA下编译Java项目,报错:java.lang.OutOfMemoryError: com.sun.tools.javac.api.ClientCodeWrap ...
- IDEA运行工程时报错:java: java.lang.OutOfMemoryError: GC overhead limit exceeded
背景:在运行公司的工程的时候,提示:"java: java.lang.OutOfMemoryError: GC overhead limit exceeded",从字面意思我们可以 ...
- java.lang.OutOfMemoryError: GC overhead limit exceeded
今天现场weblogic报java.lang.OutOfMemoryError: GC overhead limit exceeded,在metalink查了下,有明白解释,要设置一个JVM參数.只是 ...
- What means the error-message 'java.lang.OutOfMemoryError: GC overhead limit exceeded' in Java?
转国内的: 一.异常如下:Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exce ...
- Spark读取HDFS上的Snappy压缩文件所导致的内存溢出问题 java.lang.OutOfMemoryError: GC overhead limit exceeded
报错java.lang.OutOfMemoryError: GC overhead limit exceeded HDFS上有一些每天增长的文件,使用Snappy压缩,突然某天OOM了 1.原因: 因 ...
最新文章
- 时间序列举例--------协方差+相关系数+随机游走+平稳性
- 深拷贝与浅拷贝、空类与空数组
- strtok_r 和 strsep 使用实例
- (十三)RabbitMQ使用详解
- (二叉树DFS)下落的树叶
- Android Studio 导入 so 简明教程:通过一个示例让你理解整个过程
- mysql2005安装asp_asp连接sql server2005数据库
- NPDP第五章 工具与度量
- 单龙芯3A3000-7A1000PMON研究学习-(13)撸起袖子干-make的过程
- 苹果手机微信声音小怎么调大声_怎么把手机声音变大,试试这种方法
- 圆锥母线,弧长,面积计算公式
- springboot项目版本升级
- amigo幸运字符什么意思_机器视觉之halcon入门(4)-字符识别
- 9、Linux文本处理三剑客之sed命令
- 安利自己读CS博士的鸡汤
- 每天学命令deletePlaceBlockage
- 【python】如何画简单的图
- 配置局域网内电脑快速传输数据
- 关于工厂类app的一些想法
- 为什么说品牌推广离不开软文营销呢?一文告诉你软文营销的优势
热门文章
- Weka的-3.6.10的C4.5与Quinlan教授的C4.5算法的区别
- ValueError: cannot index a corpus with zero features (you must specify either `num_features` or a no
- 深度学习神经网络:改善与优化的方法
- oracle 删除用户 递归,ORACLE递归查询遍历详解
- java 304_分析HTTP请求返回304状态码
- 下载文章图片 php,PHP下载文章中的图片+处理文章中的字符
- ios UITableView顶部向下偏移
- CORS解决WebApi跨域问题(转)
- 在 Linux 上使用 Meld 比较文件夹
- UML类图的6大关系