Commit bd5b5e52 authored by bak@chromium.org's avatar bak@chromium.org

- 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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2677 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 06183420
......@@ -161,6 +161,9 @@ DEFINE_bool(trace_gc_verbose, false,
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")
......
......@@ -425,6 +425,20 @@ static void VerifySymbolTable() {
}
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,
GarbageCollector collector,
GCTracer* tracer) {
......@@ -433,7 +447,7 @@ void Heap::PerformGarbageCollection(AllocationSpace space,
ASSERT(!allocation_allowed_);
global_gc_prologue_callback_();
}
EnsureFromSpaceIsCommitted();
if (collector == MARK_COMPACTOR) {
MarkCompact(tracer);
......
......@@ -280,6 +280,9 @@ class Heap : public AllStatic {
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.
static void Protect();
......@@ -794,6 +797,9 @@ class Heap : public AllStatic {
// 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.
//
......
......@@ -367,6 +367,13 @@ class MemoryAllocator : public AllStatic {
// 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
......@@ -1035,6 +1042,10 @@ class SemiSpace : public Space {
return 0;
}
bool is_committed() { return committed_; }
bool Commit();
bool Uncommit();
#ifdef DEBUG
virtual void Print();
virtual void Verify();
......@@ -1058,6 +1069,8 @@ class SemiSpace : public Space {
uintptr_t object_mask_;
uintptr_t object_expected_;
bool committed_;
public:
TRACK_MEMORY("SemiSpace")
};
......@@ -1250,6 +1263,17 @@ class NewSpace : public Space {
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.
int capacity_;
......
......@@ -157,7 +157,12 @@ uint32_t V8::Random() {
}
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();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment