freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

art運行時垃圾收集過程分析(編輯修改稿)

2025-07-26 08:07 本頁面
 

【文章內(nèi)容簡介】 // Increment everybody39。s suspend count (except our own). for (const autoamp。 thread : list_) { if (thread == self) { continue。 } ...... threadModifySuspendCount(self, +1, false)。 } } } // Block on the mutator lock until all Runnable threads release their share of access. if HAVE_TIMED_RWLOCK // Timeout if we wait more than 30 seconds. if (UNLIKELY(!Locks::mutator_lock_ExclusiveLockWithTimeout(self, 30 * 1000, 0))) { UnsafeLogFatalForThreadSuspendAllTimeout(self)。 } else Locks::mutator_lock_ExclusiveLock(self)。 endif ...... } 這個函數(shù)定義在文件art/runtime/。 所有的ART運行時線程都保存在ThreadList類的成員變量list_描述的一個列表,遍歷這個列表時,需要獲取Lock類的成員變量thread_list_lock_描述的一個互斥鎖。 ThreadList類有一個成員變量suspend_all_count_,用來描述全局的線程掛起計數(shù)器。在所有的ART運行時線程掛起期間,如果有新的線程將自己注冊為ART運行時線程,那么它也會將自己掛起來,而判斷所有的ART運行時線程是不是處于掛起期間,就是通過ThreadList類的成員變量suspend_all_count_的值是否大于0進行的。因此,ThreadList類的成員函數(shù)SuspendAll在掛起所有的ART運行時線程之前,會將ThreadList類的成員變量suspend_all_count_的值增加1。 接下來,ThreadList類的成員函數(shù)SuspendAll遍歷所有的ART運行時線程,并且調(diào)用Thread類的成員函數(shù)ModifySuspendCount將它內(nèi)部的線程計算數(shù)器增加1,如下所示:[cpp] view plain copy 在CODE上查看代碼片派生到我的代碼片void Thread::AtomicSetFlag(ThreadFlag flag) { android_atomic_or(flag, amp。)。 } void Thread::AtomicClearFlag(ThreadFlag flag) { android_atomic_and(1 ^ flag, amp。)。 } ...... void Thread::ModifySuspendCount(Thread* self, int delta, bool for_debugger) { ...... suspend_count_ += delta。 ...... if (suspend_count_ == 0) { AtomicClearFlag(kSuspendRequest)。 } else { AtomicSetFlag(kSuspendRequest)。 } } 這三個函數(shù)定義在文件art/runtime/。 Thread類的成員函數(shù)ModifySuspendCount的實現(xiàn)很簡單,它主要就是將成員變量suspend_count_的值增加delta,并且判斷增加后的值是否等于0。如果等于0,就調(diào)用成員函數(shù)AtomicClearFlag將另外一個成員變量state_and_flags_的int值的kSuspendRequest位清0,表示線程沒有掛起請求。否則的話,就調(diào)用成員函數(shù)AtomicSetFlag將成員變量state_and_flags_的int值的kSuspendRequest位置1,表示線程有掛起請求。 回到前面ThreadList類的成員函數(shù)SuspendAll中,全局ART運行時線程掛起計數(shù)器和每一個ART運行時線程內(nèi)部的線程掛起計數(shù)器的操作都是需要在獲取Locks類的靜態(tài)成員變量thread_suspend_count_lock_描述的一個互斥鎖的前提下進行的。 最后,ThreadList類的成員函數(shù)SuspendAll通過獲取Locks類的靜態(tài)成員變量mutator_lock_描述的一個讀寫鎖的寫訪問來等待所有的ART運行時線程掛起的。這是如何做到的呢?在前面一文中,我們提到,ART運行時提供給由DEX字節(jié)碼翻譯而來的本地機器代碼使用的一個函數(shù)表中,包含了一個pCheckSuspend函數(shù)指針,該函數(shù)指針指向了函數(shù)CheckSuspendFromCode。于是,每一個ART運行時線程在執(zhí)行本地機器代碼的過程中,就會周期性地通過調(diào)用函數(shù)CheckSuspendFromCode來檢查自己是否需要掛起。這一點與前面一文分析的Dalvik虛擬機線程掛起的過程是類似的。 函數(shù)CheckSuspendFromCode的實現(xiàn)如下所示:[cpp] view plain copy 在CODE上查看代碼片派生到我的代碼片void CheckSuspendFromCode(Thread* thread) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { ...... CheckSuspend(thread)。 } 這個函數(shù)定義在文件art/runtime/entrypoints/quick/。 函數(shù)CheckSuspendFromCode調(diào)用另外一個函數(shù)CheckSuspend檢查當前線程是否需要掛起,后者的實現(xiàn)如下所示:[cpp] view plain copy 在CODE上查看代碼片派生到我的代碼片static inline void CheckSuspend(Thread* thread) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { for (。) { if (threadReadFlag(kCheckpointRequest)) { threadRunCheckpointFunction()。 threadAtomicClearFlag(kCheckpointRequest)。 } else if (threadReadFlag(kSuspendRequest)) { threadFullSuspendCheck()。 } else { break。 } } } 這個函數(shù)定義在文件art/runtime/entrypoints/。 從上面的分析可以知道,如果當前線程的線程掛起計數(shù)器不等于0,那么它內(nèi)部的一個標記位kSuspendRequest被設(shè)置為1。這時候函數(shù)CheckSuspend就會調(diào)用Thread類的成員函數(shù)FullSuspendCheck來將自己掛起。此外,函數(shù)CheckSuspend還會檢查線程內(nèi)部的另外一個標記位kCheckpointRequest是否被設(shè)置為1。如果被設(shè)置為1的話,那么就說明線程有一個Check Point需要執(zhí)行,這時候就會先調(diào)用Thread類的成員函數(shù)RunCheckpointFunction運行該Check Point,接著再將線程內(nèi)部的標記位kCheckpointRequest清0。關(guān)于線程的Check Point,我們后面再分析。 Thread類的成員函數(shù)FullSuspendCheck的實現(xiàn)如下所示:[cpp] view plain copy 在CODE上查看代碼片派生到我的代碼片void Thread::FullSuspendCheck() { ...... // Make thread appear suspended to other threads, release mutator_lock_. TransitionFromRunnableToSuspended(kSuspended)。 // Transition back to runnable noting requests to suspend, reacquire share on mutator_lock_. TransitionFromSuspendedToRunnable()。 ...... } 這個函數(shù)定義在文件art/runtime/。 Thread類的成員函數(shù)FullSuspendCheck首先是調(diào)用成員函數(shù)TransitionFromRunnableToSuspended將自己從運行狀態(tài)修改為掛起狀態(tài),接著再調(diào)用成員函數(shù)TransitionFromSuspendedToRunnable將自己從掛起狀態(tài)修改為運行狀態(tài)。通過Thread類的這兩個神奇的成員函數(shù),就實現(xiàn)了將當前線程掛起的功能。接下來我們就繼續(xù)分析它們是怎么實現(xiàn)的。 Thread類的成員函數(shù)TransitionFromRunnableToSuspended的實現(xiàn)如下所示:[cpp] view plain copy 在CODE上查看代碼片派生到我的代碼片inline void Thread::TransitionFromRunnableToSuspended(ThreadState new_state) { ...... union StateAndFlags old_state_and_flags。 union StateAndFlags new_state_and_flags。 do { old_state_and_flags = state_and_flags_。 // Copy over flags and try to clear the checkpoint bit if it is set. = amp。 ~kCheckpointRequest。 = new_state。 // CAS the value without a memory barrier, that will occur in the unlock below. } while (UNLIKELY(android_atomic_cas(, , amp。) != 0))。 // If we toggled the checkpoint flag we must have cleared it. uint16_t flag_change = ^ 。 if (UNLIKELY((flag_change amp。 kCheckpointRequest) != 0)) { RunCheckpointFunction()。 } // Release share on mutator_lock_. Locks::mutator_lock_SharedUnlock(this)。 } 這個函數(shù)定義在文件art/runtime/。 線程的狀態(tài)和標記位均保存在Thread類的成員變量state_and_flags_描述的一個Union結(jié)構(gòu)體中。Thread類的成員函數(shù)TransitionFromRunnableToSuspended首先是將線程舊的狀態(tài)和標志位保存起來,然后再清空它的kCheckpointRequest標志位,以及將它的狀態(tài)設(shè)置為參數(shù)new_state描述的狀態(tài),即kSuspended狀態(tài)。 設(shè)置好線程新的標記位和狀態(tài)之后,Thread類的成員函數(shù)TransitionFromRunnableToSuspended再檢查線程原來的標記位kCheckpointRequest是否等于1。如果等于1的話,那么在釋放Locks類的靜態(tài)成員變量mutator_lock_描述的一個讀寫鎖的讀訪問之前,先調(diào)用Thread類的成員函數(shù)RunCheckpointFunction來執(zhí)行線程的Check Point。 Thread類的成員函數(shù)TransitionFromSuspendedToRunnable的實現(xiàn)如下所示:[cpp] view plain copy 在CODE上查看代碼片派生到我的代碼片inline ThreadState Thread::TransitionFromSuspendedToRunnable() { bool done = false。 union StateAndFlags old_state_and_fla
點擊復(fù)制文檔內(nèi)容
外語相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖片鄂ICP備17016276號-1