第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定

Android GC相關(guān)

標(biāo)簽:
Android

GC原因不一样,GC效果不一样

/art/runtime/gc/gc_cause.h

// What caused the GC?
 enum GcCause {
          // Invalid GC cause used as a placeholder.
          kGcCauseNone,
          // GC triggered by a failed allocation. Thread doing allocation is blocked waiting for GC before
          // retrying allocation.
          kGcCauseForAlloc,
          // A background GC trying to ensure there is free memory ahead of allocations.
          kGcCauseBackground,
          // An explicit System.gc() call.
          kGcCauseExplicit,
          // GC triggered for a native allocation when NativeAllocationGcWatermark is exceeded.
          // (This may be a blocking GC depending on whether we run a non-concurrent collector).
          kGcCauseForNativeAlloc,
          // GC triggered for a collector transition.
          kGcCauseCollectorTransition,
          // Not a real GC cause, used when we disable moving GC (currently for GetPrimitiveArrayCritical).
          kGcCauseDisableMovingGc,
          // Not a real GC cause, used when we trim the heap.
          kGcCauseTrim,
          // Not a real GC cause, used to implement exclusion between GC and instrumentation.
          kGcCauseInstrumentation,
          // Not a real GC cause, used to add or remove app image spaces.
          kGcCauseAddRemoveAppImageSpace,
          // Not a real GC cause, used to implement exclusion between GC and debugger.
          kGcCauseDebugger,
          // GC triggered for background transition when both foreground and background collector are CMS.
          kGcCauseHomogeneousSpaceCompact,
          // Class linker cause, used to guard filling art methods with special values.
          kGcCauseClassLinker,
          // Not a real GC cause, used to implement exclusion between code cache metadata and GC.
          kGcCauseJitCodeCache,
          // Not a real GC cause, used to add or remove system-weak holders.
          kGcCauseAddRemoveSystemWeakHolder,
          // Not a real GC cause, used to prevent hprof running in the middle of GC.
          kGcCauseHprof,
          // Not a real GC cause, used to prevent GetObjectsAllocated running in the middle of GC.
          kGcCauseGetObjectsAllocated,
          // GC cause for the profile saver.
          kGcCauseProfileSaver,
        };

常见GC类型

1.kGcCauseForAlloc:在分配内存时内存不够情况下引起的GC,这种情况下GC会stop World。Stop World 是由于并发GC时,其他线程都会停止。

Android中开发者可以用的GC类型

2.kGcCauseBackground:当内存达到一定阈值的时候引发GC,这个时候是一个后台GC,不会引起Stop World。系统低内存时候才用该处理方式

   private fun forceGC() {
        val myClass = classLoader.loadClass("com.android.internal.os.BinderInternal")
        val newInstanceMethod = myClass.getDeclaredMethod("forceGc",String::class.java)
        newInstanceMethod.isAccessible = true
        newInstanceMethod.invoke(null, "bg")
    }

3.kGcCauseExplicit:显示调用时进行的GC,如果ART打开了这个选项,在system.gc时会进行GC。System.gc() 或者 Runtime.getRuntime().gc();

4.如果有root权限, 执行adb shell kill -10 pid也可以调用GC, 在linux kill命令中状态10表示SIGUSR1,调用的是signal_catcher.cc的HandleSigUrs1函数。

點擊查看更多內(nèi)容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
移動開發(fā)工程師
手記
粉絲
1萬
獲贊與收藏
137

關(guān)注作者,訂閱最新文章

閱讀免費教程

  • 推薦
  • 評論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評論
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊有機(jī)會得

100積分直接送

付費專欄免費學(xué)

大額優(yōu)惠券免費領(lǐng)

立即參與 放棄機(jī)會
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

舉報

0/150
提交
取消