默认情况下,并不是等堆内存耗尽,才会报 OutOfMemoryError,而是如果 JVM 觉得 GC 效率不高,也会报这个错误。

那么怎么评价 GC 效率不高呢?来看下源码:

呢?来看下源码gcOverheadChecker.cpp

  1. void GCOverheadChecker::check_gc_overhead_limit(GCOverheadTester* time_overhead,
  2. GCOverheadTester* space_overhead,
  3. bool is_full_gc,
  4. GCCause::Cause gc_cause,
  5. SoftRefPolicy* soft_ref_policy) {
  6. // 忽略显式gc命令,比如System.gc(),或者通过JVMTI命令的gc,或者通过jcmd命令的gc
  7. if (GCCause::is_user_requested_gc(gc_cause) ||
  8. GCCause::is_serviceability_requested_gc(gc_cause)) {
  9. return;
  10. }
  11. bool print_gc_overhead_limit_would_be_exceeded = false;
  12. if (is_full_gc) {
  13. //如果gc时间过长,并且gc回收的空间还是不多
  14. //gc时间占用98%以上为gc时间过长,可以通过 -XX:GCTimeLimit= 配置,参考gc_globals.hpp: GCTimeLimit
  15. //回收空间小于2%为gc回收空间不多,可以通过 -XX:GCHeapFreeLimit= 配置,参考gc_globals.hpp: GCHeapFreeLimit
  16. if (time_overhead->is_exceeded() && space_overhead->is_exceeded()) {
  17. _gc_overhead_limit_count++;
  18. //如果UseGCOverheadLimit这个状态位为开启
  19. //默认情况下,是开启的,可以通过启动参数-XX:-UseGCOverheadLimit关闭,参考:gc_globals.hpp: UseGCOverheadLimit
  20. if (UseGCOverheadLimit) {
  21. //如果超过规定次数,这个次数默认不可配置,必须开启develop编译jdk才能配置,参考gc_globals.hpp: GCOverheadLimitThreshold
  22. if (_gc_overhead_limit_count >= GCOverheadLimitThreshold){
  23. //设置状态位,准备抛出OOM
  24. set_gc_overhead_limit_exceeded(true);
  25. //清空计数
  26. reset_gc_overhead_limit_count();
  27. } else {
  28. //如果还没到达次数,但是也快到达的时候,清空所有的软引用
  29. bool near_limit = gc_overhead_limit_near();
  30. if (near_limit) {
  31. soft_ref_policy->set_should_clear_all_soft_refs(true);
  32. log_trace(gc, ergo)("Nearing GC overhead limit, will be clearing all SoftReference");
  33. }
  34. }
  35. }
  36. //需要打印日志,提示GC效率不高
  37. print_gc_overhead_limit_would_be_exceeded = true;
  38. } else {
  39. // Did not exceed overhead limits
  40. reset_gc_overhead_limit_count();
  41. }
  42. }
  43. if (UseGCOverheadLimit) {
  44. if (gc_overhead_limit_exceeded()) {
  45. log_trace(gc, ergo)("GC is exceeding overhead limit of " UINTX_FORMAT "%%", GCTimeLimit);
  46. reset_gc_overhead_limit_count();
  47. } else if (print_gc_overhead_limit_would_be_exceeded) {
  48. assert(_gc_overhead_limit_count > 0, "Should not be printing");
  49. log_trace(gc, ergo)("GC would exceed overhead limit of " UINTX_FORMAT "%% %d consecutive time(s)",
  50. GCTimeLimit, _gc_overhead_limit_count);
  51. }
  52. }
  53. }

默认配置:gc_globals.hpp

  1. product(bool, UseGCOverheadLimit, true, \
  2. "Use policy to limit of proportion of time spent in GC " \
  3. "before an OutOfMemory error is thrown") \
  4. \
  5. product(uintx, GCTimeLimit, 98, \
  6. "Limit of the proportion of time spent in GC before " \
  7. "an OutOfMemoryError is thrown (used with GCHeapFreeLimit)") \
  8. range(0, 100) \
  9. \
  10. product(uintx, GCHeapFreeLimit, 2, \
  11. "Minimum percentage of free space after a full GC before an " \
  12. "OutOfMemoryError is thrown (used with GCTimeLimit)") \
  13. range(0, 100) \
  14. \
  15. develop(uintx, GCOverheadLimitThreshold, 5, \
  16. "Number of consecutive collections before gc time limit fires") \
  17. range(1, max_uintx)

可以总结出:默认情况下,启用了 UseGCOverheadLimit,连续 5 次,碰到 GC 时间占比超过 98%,GC 回收的内存不足 2% 时,会抛出这个异常。

微信搜索“我的编程喵”关注公众号,每日一刷,轻松提升技术,斩获各种offer:

JVM 报 GC Overhead limit exceeded 是什么意思?的更多相关文章

  1. JVM--你常见的jvm 异常有哪些? 代码演示:StackOverflowError , utOfMemoryError: Java heap space , OutOfMemoryError: GC overhead limit exceeded, Direct buffer memory, Unable_to_create_new_native_Thread, Metaspace

    直接上代码: public class Test001 { public static void main(String[] args) { //java.lang.StackOverflowErro ...

  2. eclipse一直报An internal error occurred during: "Building workspace". GC overhead limit exceeded

    最近导入到eclipse里的工程挺大的,每次eclipse启动之后都回update workspace,然后就一直报: An internal error occurred during: " ...

  3. android studio 解析Excel数据格式导入poi-3.17.jar时的一系列报错及处理Failed resolution of: Ljavax/xml/stream/XMLEventFactory,duplicate entry: org/apache/xmlbeans/xml/stream/Location.class,GC overhead limit exceeded

    在org官网下载的poi jar包,导入到studio compile files('libs/poi-3.17.jar') compile files('libs/poi-ooxml-3.17.ja ...

  4. troubleshooting-sqoop mysql导入hive 报:GC overhead limit exceeded

    Halting due to Out Of Memory Error...18/09/13 21:42:17 INFO mapreduce.Job: Task Id : attempt_1536756 ...

  5. oozie: GC overhead limit exceeded 解决方法

    1.异常表现形式 1)  提示信息      Error java.lang.OutOfMemoryError: GC overhead limit exceeded 2)提示出错      Erro ...

  6. java.lang.OutOfMemoryError:GC overhead limit exceeded

    在调测程序时报java.lang.OutOfMemoryError:GC overhead limit exceeded 错误 错误原因:在用程序进行数据切割时报了该错误.由于在本地执行数据切割测试的 ...

  7. Spark 1.4.1中Beeline使用的gc overhead limit exceeded

    最近使用SparkSQL做数据的打平操作,就是把多个表的数据经过关联操作导入到一个表中,这样数据查询的过程中就不需要在多个表中查询了,在数据量大的情况下,这样大大提高了查询效率.   我启动了thri ...

  8. java.lang.OutOfMemoryError GC overhead limit exceeded原因分析及解决方案

    最近一个上线运行良好的项目出现用户无法登录或者执行某个操作时,有卡顿现象.查看了日志,出现了大量的java.lang.OutOfMemoryError: GC overhead limit excee ...

  9. java.lang.OutOfMemoryError:GC overhead limit exceeded填坑心得

    我遇到这样的问题,本地部署时抛出异常java.lang.OutOfMemoryError:GC overhead limit exceeded导致服务起不来,查看日志发现加载了太多资源到内存,本地的性 ...

随机推荐

  1. 使用pushplus+python实现亚马逊到货消息推送微信

    xbox series和ps5发售以来,国内黄牛价格一直居高不下.虽然海外amazon上ps5补货很少而且基本撑不过一分钟,但是xbox series系列明显要好抢很多. 日亚.德亚的xbox ser ...

  2. 冷饭新炒:理解JDK中UUID的底层实现

    前提 UUID是Universally Unique IDentifier的缩写,翻译为通用唯一标识符或者全局唯一标识符.对于UUID的描述,下面摘录一下规范文件A Universally Uniqu ...

  3. Scalable Go Scheduler Design Doc

    https://docs.google.com/document/d/1TTj4T2JO42uD5ID9e89oa0sLKhJYD0Y_kqxDv3I3XMw/ Scalable Go Schedul ...

  4. secure hashes message digests 安全哈希 消息摘要

    hashlib --- 安全哈希与消息摘要 - Python 3.8.3 文档 https://docs.python.org/zh-cn/3.8/library/hashlib.html hashl ...

  5. 监听套接字描述字 已连接套接字描述字 和打电话的情形非常不一样的地方 完成了 TCP 三次握手,操作系统内核就为这个客户生成一个已连接套接字

    1. accept: 电话铃响起了-- 当客户端的连接请求到达时,服务器端应答成功,连接建立,这个时候操作系统内核需要把这个事件通知到应用程序,并让应用程序感知到这个连接.这个过程,就好比电信运营商完 ...

  6. 学习Python之路

    陆续学习python已经有一段时间了,但是真正的安下心来学习还是在最近的一个月时间里,虽然每天学习的时间很有限,但是通过点滴的学习让自己感到从未有过的充实,完全打掉了以往认学学习一门语言难于登天的心理 ...

  7. HTML 5 学习第二课

    元素:<p>+++++++++</P> 全部内容 标签:<P></P> 属性:标签内部的内容 eg:<img src=" "& ...

  8. Dbeaver 连接 phoenix

    Dbeaver 连接 phoenix 1.新建连接 2.选择连接类型Phoenix 3.设置驱动 4.准备驱动包 5.添加驱动 6.添加 Zookeeper Base Path 7.找到驱动类 8.配 ...

  9. trunk

    今天我们一起聊trunk(接vlan之后),一台switch我们用vlan就可以划分vlan(虚拟局域网),但是2台switch该怎么办呢? 实验环境搭建 switch0 : enable //切换到 ...

  10. 2.centos 7清空文件和文件夹

    1.清空文件 测试文件:a.txt 1)方法一,[root@centos test]# > a.txt [root@centos test]# cat a.txt 1hjbfao hjkl23o ...