Revision: 2677
Author: [email protected]
Date: Thu Aug 13 05:03:42 2009
Log: - Added simple memory reduction behavior for IdleNotification.
- This also include a one line change approved by lrh.
      http://codereview.chromium.org/164469

Review URL: http://codereview.chromium.org/165448
http://code.google.com/p/v8/source/detail?r=2677

Modified:
  /branches/bleeding_edge/src/flag-definitions.h
  /branches/bleeding_edge/src/heap.cc
  /branches/bleeding_edge/src/heap.h
  /branches/bleeding_edge/src/spaces.h
  /branches/bleeding_edge/src/v8.cc

=======================================
--- /branches/bleeding_edge/src/flag-definitions.h      Fri Jul 31 04:06:17 2009
+++ /branches/bleeding_edge/src/flag-definitions.h      Thu Aug 13 05:03:42 2009
@@ -161,6 +161,9 @@
  DEFINE_bool(collect_maps, true,
              "garbage collect maps from which no objects can be reached")

+// v8.cc
+DEFINE_bool(use_idle_notification, true,
+            "Use idle notification to reduce memory footprint.")
  // ic.cc
  DEFINE_bool(use_ic, true, "use inline caching")

=======================================
--- /branches/bleeding_edge/src/heap.cc Wed Aug 12 06:54:43 2009
+++ /branches/bleeding_edge/src/heap.cc Thu Aug 13 05:03:42 2009
@@ -423,6 +423,20 @@
    Heap::symbol_table()->IterateElements(&verifier);
  #endif  // DEBUG
  }
+
+
+void Heap::EnsureFromSpaceIsCommitted() {
+  if (new_space_.CommitFromSpaceIfNeeded()) return;
+
+  // Committing memory to from space failed.
+  // Try shrinking and try again.
+  Shrink();
+  if (new_space_.CommitFromSpaceIfNeeded()) return;
+
+  // Committing memory to from space failed again.
+  // Memory is exhausted and we will die.
+  V8::FatalProcessOutOfMemory("Committing semi space failed.");
+}


  void Heap::PerformGarbageCollection(AllocationSpace space,
@@ -433,7 +447,7 @@
      ASSERT(!allocation_allowed_);
      global_gc_prologue_callback_();
    }
-
+  EnsureFromSpaceIsCommitted();
    if (collector == MARK_COMPACTOR) {
      MarkCompact(tracer);

=======================================
--- /branches/bleeding_edge/src/heap.h  Mon Aug  3 04:05:26 2009
+++ /branches/bleeding_edge/src/heap.h  Thu Aug 13 05:03:42 2009
@@ -279,6 +279,9 @@
    static Address* NewSpaceAllocationLimitAddress() {
      return new_space_.allocation_limit_address();
    }
+
+  // Uncommit unused semi space.
+  static bool UncommitFromSpace() { return new_space_.UncommitFromSpace();  
}

  #ifdef ENABLE_HEAP_PROTECTION
    // Protect/unprotect the heap by marking all spaces read-only/writable.
@@ -794,6 +797,9 @@
    // Rebuild remembered set in old and map spaces.
    static void RebuildRSets();

+  // Commits from space if it is uncommitted.
+  static void EnsureFromSpaceIsCommitted();
+
    //
    // Support for the API.
    //
=======================================
--- /branches/bleeding_edge/src/spaces.h        Wed Aug 12 06:54:43 2009
+++ /branches/bleeding_edge/src/spaces.h        Thu Aug 13 05:03:42 2009
@@ -367,6 +367,13 @@
    // and false otherwise.
    static bool CommitBlock(Address start, size_t size, Executability  
executable);

+
+  // Uncommit a contiguous block of memory [start..(start+size)[.
+  // start is not NULL, the size is greater than zero, and the
+  // block is contained in the initial chunk.  Returns true if it succeeded
+  // and false otherwise.
+  static bool UncommitBlock(Address start, size_t size);
+
    // Attempts to allocate the requested (non-zero) number of pages from the
    // OS.  Fewer pages might be allocated than requested. If it fails to
    // allocate memory for the OS or cannot allocate a single page, this
@@ -1034,6 +1041,10 @@
      UNREACHABLE();
      return 0;
    }
+
+  bool is_committed() { return committed_; }
+  bool Commit();
+  bool Uncommit();

  #ifdef DEBUG
    virtual void Print();
@@ -1058,6 +1069,8 @@
    uintptr_t object_mask_;
    uintptr_t object_expected_;

+  bool committed_;
+
   public:
    TRACK_MEMORY("SemiSpace")
  };
@@ -1249,6 +1262,17 @@
    void RecordAllocation(HeapObject* obj);
    void RecordPromotion(HeapObject* obj);
  #endif
+
+  // Return whether the operation succeded.
+  bool CommitFromSpaceIfNeeded() {
+    if (from_space_.is_committed()) return true;
+    return from_space_.Commit();
+  }
+
+  bool UncommitFromSpace() {
+    if (!from_space_.is_committed()) return true;
+    return from_space_.Uncommit();
+  }

   private:
    // The current and maximum capacities of a semispace.
=======================================
--- /branches/bleeding_edge/src/v8.cc   Thu Aug 13 02:35:51 2009
+++ /branches/bleeding_edge/src/v8.cc   Thu Aug 13 05:03:42 2009
@@ -157,7 +157,12 @@
  }

  void V8::IdleNotification(bool is_high_priority) {
-  // todo(bak): Reduce memory footprint.
+  if (!FLAG_use_idle_notification) return;
+  // Ignore high priority instances of V8.
+  if (is_high_priority) return;
+
+  // Uncommit unused memory in new space.
+  Heap::UncommitFromSpace();
  }



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

Reply via email to