/* * public void runFinalization(boolean forced) * * Requests that the VM runs finalizers for objects on the heap. If the * parameter forced is true, then the VM needs to ensure finalization. * Otherwise this only inspires the VM to make a best-effort attempt to * run finalizers before returning, but it's not guaranteed to actually * do anything. */ static void Dalvik_java_lang_Runtime_runFinalization(const u4* args, JValue* pResult) { bool forced = (args[0] != 0); dvmWaitForHeapWorkerIdle(); if (forced) { // TODO(Google) Need to explicitly implement this, // although dvmWaitForHeapWorkerIdle() // should usually provide the "forced" // behavior already. } RETURN_VOID(); }
/* * Do not return until any pending heap work has finished. This may * or may not happen in the context of the calling thread. * No exceptions will escape. */ void dvmRunFinalizationSync() { if (gDvm.zygote) { assert(!gDvm.heapWorkerReady); /* When in zygote mode, there is no heap worker. * Do the work in the current thread. */ dvmLockMutex(&gDvm.heapWorkerLock); doHeapWork(dvmThreadSelf()); dvmUnlockMutex(&gDvm.heapWorkerLock); } else { /* Outside of zygote mode, we can just ask the * heap worker thread to do the work. */ dvmWaitForHeapWorkerIdle(); } }