Reviewers: bak, Mads Ager, Kasper Lund, Description: Add LowMemoryNotification to the API on Android platform.
Android system provides a unique feature that it sends a notification to the browser in low memory condition, and the browser cleans up cache and frees resources. Forcing a GC in low memory condition can free DOM objects and also can shrink the old spaces. Please review this at http://codereview.chromium.org/173016 SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/ Affected files: M include/v8.h M src/api.cc M src/heap.h M src/heap.cc Index: include/v8.h =================================================================== --- include/v8.h (revision 2709) +++ include/v8.h (working copy) @@ -2243,6 +2243,15 @@ */ static void IdleNotification(bool is_high_priority); +#if defined(ANDROID) + /** + * Android systems sends the browser a notification when it is in low + * memory condition. It is necessary to do a full compact GC to release + * DOM objects and also uncommit pages. + */ + static void LowMemoryNotification(); +#endif + private: V8(); Index: src/api.cc =================================================================== --- src/api.cc (revision 2709) +++ src/api.cc (working copy) @@ -2599,10 +2599,18 @@ } -void v8::V8::IdleNotification(bool is_high_priority) { +void v8::V8::IdleNotification(bool is_high_priority) { i::V8::IdleNotification(is_high_priority); } + +#if defined(ANDROID) +void v8::V8::LowMemoryNotification() { + i::Heap::CollectAllGarbage(true); +} +#endif + + const char* v8::V8::GetVersion() { static v8::internal::EmbeddedVector<char, 128> buffer; v8::internal::Version::GetString(buffer); Index: src/heap.cc =================================================================== --- src/heap.cc (revision 2709) +++ src/heap.cc (working copy) @@ -315,11 +315,14 @@ } -void Heap::CollectAllGarbage() { +void Heap::CollectAllGarbage(bool force_compaction) { // Since we are ignoring the return value, the exact choice of space does // not matter, so long as we do not specify NEW_SPACE, which would not // cause a full GC. + bool saved_always_compact_flag = FLAG_always_compact; + FLAG_always_compact = force_compaction; CollectGarbage(0, OLD_POINTER_SPACE); + FLAG_always_compact = saved_always_compact_flag; } Index: src/heap.h =================================================================== --- src/heap.h (revision 2709) +++ src/heap.h (working copy) @@ -626,8 +626,9 @@ // Returns whether required_space bytes are available after the collection. static bool CollectGarbage(int required_space, AllocationSpace space); - // Performs a full garbage collection. - static void CollectAllGarbage(); + // Performs a full garbage collection. Force compaction if the second + // parameter is true. + static void CollectAllGarbage(bool force_compaction = false); // Performs a full garbage collection if a context has been disposed // since the last time the check was performed. --~--~---------~--~----~------------~-------~--~----~ v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev -~----------~----~----~----~------~----~------~--~---
