gcCauses整理

gc causes

  • gcCause.cpp

    switch (cause) {
    case _java_lang_system_gc: return "System.gc()";
    case _full_gc_alot: return "FullGCAlot";
    case _scavenge_alot: return "ScavengeAlot";
    case _allocation_profiler: return "Allocation Profiler";
    case _jvmti_force_gc: return "JvmtiEnv ForceGarbageCollection";
    case _gc_locker: return "GCLocker Initiated GC";
    case _heap_inspection: return "Heap Inspection Initiated GC";
    case _heap_dump: return "Heap Dump Initiated GC";
    case _wb_young_gc: return "WhiteBox Initiated Young GC";
    case _update_allocation_context_stats_inc:
    case _update_allocation_context_stats_full:
    return "Update Allocation Context Stats";
    case _no_gc: return "No GC";
    case _allocation_failure: return "Allocation Failure";
    case _tenured_generation_full: return "Tenured Generation Full";
    case _metadata_GC_threshold: return "Metadata GC Threshold";
    case _cms_generation_full: return "CMS Generation Full";
    case _cms_initial_mark: return "CMS Initial Mark";
    case _cms_final_remark: return "CMS Final Remark";
    case _cms_concurrent_mark: return "CMS Concurrent Mark";
    case _old_generation_expanded_on_last_scavenge:
    return "Old Generation Expanded On Last Scavenge";
    case _old_generation_too_full_to_scavenge:
    return "Old Generation Too Full To Scavenge";
    case _adaptive_size_policy: return "Ergonomics";
    case _g1_inc_collection_pause: return "G1 Evacuation Pause";
    case _g1_humongous_allocation: return "G1 Humongous Allocation";
    case _last_ditch_collection: return "Last ditch collection";
    case _last_gc_cause: return "ILLEGAL VALUE - last gc cause - ILLEGAL VALUE";
    default: return "unknown GCCause";}


  • common occurred and explanation
    • System.gc
      • Something called System.gc().
      • If you are seeing this once an hour it is likely related to the RMI GC interval
        • sun.rmi.dgc.client.gcInterval
        • sun.rmi.dgc.server.gcInterval
        • 两个参数默认都是1hour
        • 关于rmi的distributed garbage collection-gcInterval
          • RMI uses a distributed garbage collection (DGC) algorithm that depends on regular garbage collection (GC) activity to determine if remote objects are candidates for collection. It helps with automatic memory management when remote objects are stored in memory
          • To ensure that the remote objects are collected in a timely fashion, RMI takes the step of triggering a System.gc() on a regular interval. However, in most cases regular GC activity is sufficient for effective DGC.
          • Disabling Explicit Garbage Collections
            • -XX:+DisableExplicitGC(关闭它会影响堆外内存回收)
          • Do both server and client arguments need to be added?
            • The two sun.rmi arguments reflect whether your JVM is running in server or client mode. Depending on the version of your SDK, either mode can be set as the default. It is best to set both options so the argument will be picked up by the JVM
    • Allocation_Profiler
      • Prior to java 8 you would see this if running with the -Xaprof setting. It would be triggered just before the jvm exits. The -Xaprof option was removed in java 8.
      • Aprof
        • Aprof is a Java memory allocation profiler with very low performance impact on the profiled application that can be used (and is used) on highly-loaded server-side applications in production environment. It acts as an agent which transforms class bytecode by inserting counter increments wherever memory allocation is done and tracks a precise size of allocated objects in bytes. It also keeps limited information about allocation context to aid in finding the memory allocation bottlenecks. links
      • aprof-bug
    • JvmtiEnv_ForceGarbageCollection
      • Something called the JVM tool interface function ForceGarbageCollection. Look at the -agentlib param to java to see what agents are configured.(instrument agent?)
      • ForceGarbageCollection
        • http://docs.oracle.com/javase/7/docs/platform/jvmti/jvmti.html
        • jvmtiError ForceGarbageCollection(jvmtiEnv* env)
          • Force the VM to perform a garbage collection. The garbage collection is as complete as possible. This function does not cause finalizers to be run. This function does not return until the garbage collection is finished.
          • Although garbage collection is as complete as possible there is no guarantee that all ObjectFree events will have been sent by the time that this function returns. In particular, an object may be prevented from being freed because it is awaiting finalization.
    • GCLocker_Initiated_GC
      • The GC locker prevents GC from occurring when JNI code is in a critical region. If GC is needed while a thread is in a critical region, then it will allow them to complete, i.e. call the corresponding release function. Other threads will not be permitted to enter a critical region. Once all threads are out of critical regions a GC event will be triggered.
      • jni funcations
        • GetStringCritical, ReleaseStringCritical
        • GetPrimitiveArrayCritical, ReleasePrimitiveArrayCritical
      • c/c++代码里引用jstring, jarray,通过指针引用而不是把数据copy from java heap to native heap为了性能
      • 防止操作时jstring,jarray的指针随gc改变,需要gclocker来pin住gc happen
    • Heap_Inspection_Initiated_GC
      • GC was initiated by an inspection operation on the heap. For example you can trigger this with jmap: jmap -histo:live <pid>
    • Heap_Dump_Initiated_GC
      • GC was initiated before dumping the heap. For example you can trigger this with jmap: jmap -dump:live,format=b,file=heap.out <pid>
        Another common example would be clicking the Heap Dump button on the Monitor tab in jvisualvm.
    • No_GC
      • Used for CMS to indicate concurrent phases.
    • Allocation_Failure
      • Usually this means that there is an allocation request that is bigger than the available space in young generation and will typically be associated with a minor GC.
      • For G1 this will likely be a major GC and it is more common to see G1_Evacuation_Pause for routine minor collections.
      • On linux the jvm will trigger a GC if the kernel indicates there isn't much memory left via mem_notify.
    • CMS_Initial_Mark
      • Initial mark phase of CMS, for more details see Phases of CMS. Unfortunately it doesn't appear to be reported via the mbeans and we just get No_GC.
    • CMS_Final_Remark
      • Remark phase of CMS, for more details see Phases of CMS. Unfortunately it doesn't appear to be reported via the mbeans and we just get No_GC.
    • CMS_Concurrent_Mark
      • Concurrent mark phase of CMS, for more details see Phases of CMS. Unfortunately it doesn't appear to be reported via the mbeans and we just get No_GC.
    • Ergonomics
      • This indicates you are using the adaptive size policy, -XX:+UseAdaptiveSizePolicy and is on by default for recent versions, with the parallel collector (-XX:+UseParallelGC). For more details see The Why of GC Ergonomics.
    • Last_ditch_collection
      • For perm gen (java 7 or earlier) and metaspace (java 8+) a last ditch collection will be triggered if an allocation fails and the memory pool cannot be expanded.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,590评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 86,808评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,151评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,779评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,773评论 5 367
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,656评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,022评论 3 398
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,678评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 41,038评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,659评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,756评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,411评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,005评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,973评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,203评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,053评论 2 350
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,495评论 2 343

推荐阅读更多精彩内容