Revision: 2725
Author: [email protected]
Date: Wed Aug 19 17:07:19 2009
Log: 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.

This patch addresses the last comment in
http://codereview.chromium.org/173016/show

        
Mads Ager 2009/08/19 17:24:23
I would prefer to not use the flags to signal that a compacting collection  
is
requested.

TBR = ager
Review URL: http://codereview.chromium.org/173102
http://code.google.com/p/v8/source/detail?r=2725

Modified:
  /branches/bleeding_edge/include/v8.h
  /branches/bleeding_edge/src/api.cc
  /branches/bleeding_edge/src/heap.cc
  /branches/bleeding_edge/src/heap.h
  /branches/bleeding_edge/src/mark-compact.cc
  /branches/bleeding_edge/src/mark-compact.h

=======================================
--- /branches/bleeding_edge/include/v8.h        Wed Aug 19 08:14:11 2009
+++ /branches/bleeding_edge/include/v8.h        Wed Aug 19 17:07:19 2009
@@ -2284,6 +2284,12 @@
     */
    static void IdleNotification(bool is_high_priority);

+  /**
+   * Optional notification that the system is running low on memory.
+   * V8 uses these notifications to attempt to free memory.
+   */
+  static void LowMemoryNotification();
+
   private:
    V8();

=======================================
--- /branches/bleeding_edge/src/api.cc  Wed Aug 19 08:14:11 2009
+++ /branches/bleeding_edge/src/api.cc  Wed Aug 19 17:07:19 2009
@@ -2604,9 +2604,17 @@
  }


-void  v8::V8::IdleNotification(bool is_high_priority) {
+void v8::V8::IdleNotification(bool is_high_priority) {
    i::V8::IdleNotification(is_high_priority);
  }
+
+
+void v8::V8::LowMemoryNotification() {
+#if defined(ANDROID)
+  i::Heap::CollectAllGarbage(true);
+#endif
+}
+

  const char* v8::V8::GetVersion() {
    static v8::internal::EmbeddedVector<char, 128> buffer;
=======================================
--- /branches/bleeding_edge/src/heap.cc Wed Aug 19 08:14:11 2009
+++ /branches/bleeding_edge/src/heap.cc Wed Aug 19 17:07:19 2009
@@ -315,11 +315,13 @@
  }


-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.
+  MarkCompactCollector::SetForceCompaction(force_compaction);
    CollectGarbage(0, OLD_POINTER_SPACE);
+  MarkCompactCollector::SetForceCompaction(false);
  }


=======================================
--- /branches/bleeding_edge/src/heap.h  Wed Aug 19 08:14:11 2009
+++ /branches/bleeding_edge/src/heap.h  Wed Aug 19 17:07:19 2009
@@ -627,8 +627,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
+  // 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.
=======================================
--- /branches/bleeding_edge/src/mark-compact.cc Thu Jul  9 04:13:08 2009
+++ /branches/bleeding_edge/src/mark-compact.cc Wed Aug 19 17:07:19 2009
@@ -39,6 +39,7 @@
  //  
-------------------------------------------------------------------------
  // MarkCompactCollector

+bool MarkCompactCollector::force_compaction_ = false;
  bool MarkCompactCollector::compacting_collection_ = false;

  int MarkCompactCollector::previous_marked_count_ = 0;
@@ -110,7 +111,7 @@
  #endif
    ASSERT(!FLAG_always_compact || !FLAG_never_compact);

-  compacting_collection_ = FLAG_always_compact;
+  compacting_collection_ = FLAG_always_compact || force_compaction_;

    // We compact the old generation if it gets too fragmented (ie, we could
    // recover an expected amount of space by reclaiming the waste and free
=======================================
--- /branches/bleeding_edge/src/mark-compact.h  Thu Jul  9 05:13:51 2009
+++ /branches/bleeding_edge/src/mark-compact.h  Wed Aug 19 17:07:19 2009
@@ -74,6 +74,12 @@

    // Type of functions to process non-live objects.
    typedef void (*ProcessNonLiveFunction)(HeapObject* object);
+
+  // Set the global force_compaction flag, it must be called before Prepare
+  // to take effect.
+  static void SetForceCompaction(bool value) {
+    force_compaction_ = value;
+  }

    // Prepares for GC by resetting relocation info in old and map spaces and
    // choosing spaces to compact.
@@ -117,6 +123,10 @@
    // The current stage of the collector.
    static CollectorState state_;
  #endif
+
+  // Global flag that forces a compaction.
+  static bool force_compaction_;
+
    // Global flag indicating whether spaces were compacted on the last GC.
    static bool compacting_collection_;


--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to