Revision: 8601
Author:   [email protected]
Date:     Mon Jul 11 07:03:21 2011
Log:      Remove heap protection support.

It does not currently work and when it did work we never got it fast
enough to be useful.

[email protected]

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

Modified:
 /branches/bleeding_edge/src/flag-definitions.h
 /branches/bleeding_edge/src/handles.cc
 /branches/bleeding_edge/src/heap.cc
 /branches/bleeding_edge/src/heap.h
 /branches/bleeding_edge/src/platform-cygwin.cc
 /branches/bleeding_edge/src/platform-freebsd.cc
 /branches/bleeding_edge/src/platform-linux.cc
 /branches/bleeding_edge/src/platform-macos.cc
 /branches/bleeding_edge/src/platform-nullos.cc
 /branches/bleeding_edge/src/platform-openbsd.cc
 /branches/bleeding_edge/src/platform-solaris.cc
 /branches/bleeding_edge/src/platform-win32.cc
 /branches/bleeding_edge/src/platform.h
 /branches/bleeding_edge/src/spaces-inl.h
 /branches/bleeding_edge/src/spaces.cc
 /branches/bleeding_edge/src/spaces.h
 /branches/bleeding_edge/src/vm-state-inl.h

=======================================
--- /branches/bleeding_edge/src/flag-definitions.h      Thu Jun 30 04:52:00 2011
+++ /branches/bleeding_edge/src/flag-definitions.h      Mon Jul 11 07:03:21 2011
@@ -490,19 +490,6 @@
 DEFINE_string(logfile, "v8.log", "Specify the name of the log file.")
 DEFINE_bool(ll_prof, false, "Enable low-level linux profiler.")

-//
-// Heap protection flags
-// Using heap protection requires ENABLE_LOGGING_AND_PROFILING as well.
-//
-#ifdef ENABLE_HEAP_PROTECTION
-#undef FLAG
-#define FLAG FLAG_FULL
-
-DEFINE_bool(protect_heap, false,
-            "Protect/unprotect V8's heap when leaving/entring the VM.")
-
-#endif
-
 //
 // Disassembler only flags
 //
=======================================
--- /branches/bleeding_edge/src/handles.cc      Thu Jun 30 04:11:19 2011
+++ /branches/bleeding_edge/src/handles.cc      Mon Jul 11 07:03:21 2011
@@ -543,11 +543,6 @@
 // associated with the wrapper and get rid of both the wrapper and the
 // handle.
 static void ClearWrapperCache(Persistent<v8::Value> handle, void*) {
-#ifdef ENABLE_HEAP_PROTECTION
-  // Weak reference callbacks are called as if from outside V8.  We
-  // need to reeenter to unprotect the heap.
-  VMState state(OTHER);
-#endif
   Handle<Object> cache = Utils::OpenHandle(*handle);
   JSValue* wrapper = JSValue::cast(*cache);
   Foreign* foreign = Script::cast(wrapper->value())->wrapper();
=======================================
--- /branches/bleeding_edge/src/heap.cc Mon Jul  4 23:19:53 2011
+++ /branches/bleeding_edge/src/heap.cc Mon Jul 11 07:03:21 2011
@@ -5211,28 +5211,6 @@
for (PagedSpace* space = spaces.next(); space != NULL; space = spaces.next())
     space->Shrink();
 }
-
-
-#ifdef ENABLE_HEAP_PROTECTION
-
-void Heap::Protect() {
-  if (HasBeenSetup()) {
-    AllSpaces spaces;
- for (Space* space = spaces.next(); space != NULL; space = spaces.next())
-      space->Protect();
-  }
-}
-
-
-void Heap::Unprotect() {
-  if (HasBeenSetup()) {
-    AllSpaces spaces;
- for (Space* space = spaces.next(); space != NULL; space = spaces.next())
-      space->Unprotect();
-  }
-}
-
-#endif


void Heap::AddGCPrologueCallback(GCPrologueCallback callback, GCType gc_type) {
=======================================
--- /branches/bleeding_edge/src/heap.h  Mon Jul  4 23:19:53 2011
+++ /branches/bleeding_edge/src/heap.h  Mon Jul 11 07:03:21 2011
@@ -408,12 +408,6 @@

   // Uncommit unused semi space.
   bool UncommitFromSpace() { return new_space_.UncommitFromSpace(); }
-
-#ifdef ENABLE_HEAP_PROTECTION
-  // Protect/unprotect the heap by marking all spaces read-only/writable.
-  void Protect();
-  void Unprotect();
-#endif

   // Allocates and initializes a new JavaScript object based on a
   // constructor.
=======================================
--- /branches/bleeding_edge/src/platform-cygwin.cc      Tue Jul  5 08:49:39 2011
+++ /branches/bleeding_edge/src/platform-cygwin.cc      Mon Jul 11 07:03:21 2011
@@ -164,23 +164,6 @@
   USE(result);
   ASSERT(result == 0);
 }
-
-
-#ifdef ENABLE_HEAP_PROTECTION
-
-void OS::Protect(void* address, size_t size) {
-  // TODO(1240712): mprotect has a return value which is ignored here.
-  mprotect(address, size, PROT_READ);
-}
-
-
-void OS::Unprotect(void* address, size_t size, bool is_executable) {
-  // TODO(1240712): mprotect has a return value which is ignored here.
-  int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
-  mprotect(address, size, prot);
-}
-
-#endif


 void OS::Sleep(int milliseconds) {
=======================================
--- /branches/bleeding_edge/src/platform-freebsd.cc     Tue Jul  5 08:49:39 2011
+++ /branches/bleeding_edge/src/platform-freebsd.cc     Mon Jul 11 07:03:21 2011
@@ -179,20 +179,6 @@
   USE(result);
   ASSERT(result == 0);
 }
-
-
-#ifdef ENABLE_HEAP_PROTECTION
-
-void OS::Protect(void* address, size_t size) {
-  UNIMPLEMENTED();
-}
-
-
-void OS::Unprotect(void* address, size_t size, bool is_executable) {
-  UNIMPLEMENTED();
-}
-
-#endif


 void OS::Sleep(int milliseconds) {
=======================================
--- /branches/bleeding_edge/src/platform-linux.cc       Tue Jul  5 08:49:39 2011
+++ /branches/bleeding_edge/src/platform-linux.cc       Mon Jul 11 07:03:21 2011
@@ -388,23 +388,6 @@
   USE(result);
   ASSERT(result == 0);
 }
-
-
-#ifdef ENABLE_HEAP_PROTECTION
-
-void OS::Protect(void* address, size_t size) {
-  // TODO(1240712): mprotect has a return value which is ignored here.
-  mprotect(address, size, PROT_READ);
-}
-
-
-void OS::Unprotect(void* address, size_t size, bool is_executable) {
-  // TODO(1240712): mprotect has a return value which is ignored here.
-  int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
-  mprotect(address, size, prot);
-}
-
-#endif


 void OS::Sleep(int milliseconds) {
=======================================
--- /branches/bleeding_edge/src/platform-macos.cc       Tue Jul  5 08:49:39 2011
+++ /branches/bleeding_edge/src/platform-macos.cc       Mon Jul 11 07:03:21 2011
@@ -167,20 +167,6 @@
   USE(result);
   ASSERT(result == 0);
 }
-
-
-#ifdef ENABLE_HEAP_PROTECTION
-
-void OS::Protect(void* address, size_t size) {
-  UNIMPLEMENTED();
-}
-
-
-void OS::Unprotect(void* address, size_t size, bool is_executable) {
-  UNIMPLEMENTED();
-}
-
-#endif


 void OS::Sleep(int milliseconds) {
=======================================
--- /branches/bleeding_edge/src/platform-nullos.cc      Fri Jun 10 02:54:04 2011
+++ /branches/bleeding_edge/src/platform-nullos.cc      Mon Jul 11 07:03:21 2011
@@ -215,20 +215,6 @@
// TODO(1240712): potential system call return value which is ignored here.
   UNIMPLEMENTED();
 }
-
-
-#ifdef ENABLE_HEAP_PROTECTION
-
-void OS::Protect(void* address, size_t size) {
-  UNIMPLEMENTED();
-}
-
-
-void OS::Unprotect(void* address, size_t size, bool is_executable) {
-  UNIMPLEMENTED();
-}
-
-#endif


 void OS::Sleep(int milliseconds) {
=======================================
--- /branches/bleeding_edge/src/platform-openbsd.cc     Tue Jul  5 08:49:39 2011
+++ /branches/bleeding_edge/src/platform-openbsd.cc     Mon Jul 11 07:03:21 2011
@@ -177,20 +177,6 @@
   USE(result);
   ASSERT(result == 0);
 }
-
-
-#ifdef ENABLE_HEAP_PROTECTION
-
-void OS::Protect(void* address, size_t size) {
-  UNIMPLEMENTED();
-}
-
-
-void OS::Unprotect(void* address, size_t size, bool is_executable) {
-  UNIMPLEMENTED();
-}
-
-#endif


 void OS::Sleep(int milliseconds) {
=======================================
--- /branches/bleeding_edge/src/platform-solaris.cc     Tue Jul  5 08:49:39 2011
+++ /branches/bleeding_edge/src/platform-solaris.cc     Mon Jul 11 07:03:21 2011
@@ -190,23 +190,6 @@
   USE(result);
   ASSERT(result == 0);
 }
-
-
-#ifdef ENABLE_HEAP_PROTECTION
-
-void OS::Protect(void* address, size_t size) {
-  // TODO(1240712): mprotect has a return value which is ignored here.
-  mprotect(address, size, PROT_READ);
-}
-
-
-void OS::Unprotect(void* address, size_t size, bool is_executable) {
-  // TODO(1240712): mprotect has a return value which is ignored here.
-  int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
-  mprotect(address, size, prot);
-}
-
-#endif


 void OS::Sleep(int milliseconds) {
=======================================
--- /branches/bleeding_edge/src/platform-win32.cc       Wed Jul  6 05:29:21 2011
+++ /branches/bleeding_edge/src/platform-win32.cc       Mon Jul 11 07:03:21 2011
@@ -937,25 +937,6 @@
   VirtualFree(address, 0, MEM_RELEASE);
   USE(size);
 }
-
-
-#ifdef ENABLE_HEAP_PROTECTION
-
-void OS::Protect(void* address, size_t size) {
- // TODO(1240712): VirtualProtect has a return value which is ignored here.
-  DWORD old_protect;
-  VirtualProtect(address, size, PAGE_READONLY, &old_protect);
-}
-
-
-void OS::Unprotect(void* address, size_t size, bool is_executable) {
- // TODO(1240712): VirtualProtect has a return value which is ignored here. - DWORD new_protect = is_executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE;
-  DWORD old_protect;
-  VirtualProtect(address, size, new_protect, &old_protect);
-}
-
-#endif


 void OS::Sleep(int milliseconds) {
=======================================
--- /branches/bleeding_edge/src/platform.h      Wed Jun 22 03:13:10 2011
+++ /branches/bleeding_edge/src/platform.h      Mon Jul 11 07:03:21 2011
@@ -206,12 +206,6 @@
   // Get the Alignment guaranteed by Allocate().
   static size_t AllocateAlignment();

-#ifdef ENABLE_HEAP_PROTECTION
-  // Protect/unprotect a block of memory by marking it read-only/writable.
-  static void Protect(void* address, size_t size);
-  static void Unprotect(void* address, size_t size, bool is_executable);
-#endif
-
   // Returns an indication of whether a pointer is in a space that
   // has been allocated by Allocate().  This method may conservatively
   // always return false, but giving more accurate information may
=======================================
--- /branches/bleeding_edge/src/spaces-inl.h    Tue Mar 22 04:50:39 2011
+++ /branches/bleeding_edge/src/spaces-inl.h    Mon Jul 11 07:03:21 2011
@@ -376,35 +376,6 @@
   Address start = static_cast<Address>(initial_chunk_->address());
   return (start <= address) && (address < start + initial_chunk_->size());
 }
-
-
-#ifdef ENABLE_HEAP_PROTECTION
-
-void MemoryAllocator::Protect(Address start, size_t size) {
-  OS::Protect(start, size);
-}
-
-
-void MemoryAllocator::Unprotect(Address start,
-                                size_t size,
-                                Executability executable) {
-  OS::Unprotect(start, size, executable);
-}
-
-
-void MemoryAllocator::ProtectChunkFromPage(Page* page) {
-  int id = GetChunkId(page);
-  OS::Protect(chunks_[id].address(), chunks_[id].size());
-}
-
-
-void MemoryAllocator::UnprotectChunkFromPage(Page* page) {
-  int id = GetChunkId(page);
-  OS::Unprotect(chunks_[id].address(), chunks_[id].size(),
-                chunks_[id].owner()->executable() == EXECUTABLE);
-}
-
-#endif


// --------------------------------------------------------------------------
=======================================
--- /branches/bleeding_edge/src/spaces.cc       Thu Jun  9 03:03:35 2011
+++ /branches/bleeding_edge/src/spaces.cc       Mon Jul 11 07:03:21 2011
@@ -866,30 +866,6 @@
   first_page_ = NULL;
   accounting_stats_.Clear();
 }
-
-
-#ifdef ENABLE_HEAP_PROTECTION
-
-void PagedSpace::Protect() {
-  Page* page = first_page_;
-  while (page->is_valid()) {
-    Isolate::Current()->memory_allocator()->ProtectChunkFromPage(page);
-    page = Isolate::Current()->memory_allocator()->
-        FindLastPageInSameChunk(page)->next_page();
-  }
-}
-
-
-void PagedSpace::Unprotect() {
-  Page* page = first_page_;
-  while (page->is_valid()) {
-    Isolate::Current()->memory_allocator()->UnprotectChunkFromPage(page);
-    page = Isolate::Current()->memory_allocator()->
-        FindLastPageInSameChunk(page)->next_page();
-  }
-}
-
-#endif


 void PagedSpace::MarkAllPagesClean() {
@@ -1256,24 +1232,6 @@
   to_space_.TearDown();
   from_space_.TearDown();
 }
-
-
-#ifdef ENABLE_HEAP_PROTECTION
-
-void NewSpace::Protect() {
-  heap()->isolate()->memory_allocator()->Protect(ToSpaceLow(), Capacity());
- heap()->isolate()->memory_allocator()->Protect(FromSpaceLow(), Capacity());
-}
-
-
-void NewSpace::Unprotect() {
- heap()->isolate()->memory_allocator()->Unprotect(ToSpaceLow(), Capacity(),
-                                                   to_space_.executable());
- heap()->isolate()->memory_allocator()->Unprotect(FromSpaceLow(), Capacity(), - from_space_.executable());
-}
-
-#endif


 void NewSpace::Flip() {
@@ -2807,31 +2765,6 @@
   page_count_ = 0;
   objects_size_ = 0;
 }
-
-
-#ifdef ENABLE_HEAP_PROTECTION
-
-void LargeObjectSpace::Protect() {
-  LargeObjectChunk* chunk = first_chunk_;
-  while (chunk != NULL) {
-    heap()->isolate()->memory_allocator()->Protect(chunk->address(),
-                                                   chunk->size());
-    chunk = chunk->next();
-  }
-}
-
-
-void LargeObjectSpace::Unprotect() {
-  LargeObjectChunk* chunk = first_chunk_;
-  while (chunk != NULL) {
-    bool is_code = chunk->GetObject()->IsCode();
-    heap()->isolate()->memory_allocator()->Unprotect(chunk->address(),
-        chunk->size(), is_code ? EXECUTABLE : NOT_EXECUTABLE);
-    chunk = chunk->next();
-  }
-}
-
-#endif


 MaybeObject* LargeObjectSpace::AllocateRawInternal(int requested_size,
=======================================
--- /branches/bleeding_edge/src/spaces.h        Thu May  5 23:50:20 2011
+++ /branches/bleeding_edge/src/spaces.h        Mon Jul 11 07:03:21 2011
@@ -379,12 +379,6 @@
   // Returns size of objects. Can differ from the allocated size
   // (e.g. see LargeObjectSpace).
   virtual intptr_t SizeOfObjects() { return Size(); }
-
-#ifdef ENABLE_HEAP_PROTECTION
-  // Protect/unprotect the space by marking it read-only/writable.
-  virtual void Protect() = 0;
-  virtual void Unprotect() = 0;
-#endif

 #ifdef DEBUG
   virtual void Print() = 0;
@@ -641,17 +635,6 @@
                                   Page** last_page,
                                   Page** last_page_in_use);

-#ifdef ENABLE_HEAP_PROTECTION
-  // Protect/unprotect a block of memory by marking it read-only/writable.
-  inline void Protect(Address start, size_t size);
-  inline void Unprotect(Address start, size_t size,
-                        Executability executable);
-
-  // Protect/unprotect a chunk given a page in the chunk.
-  inline void ProtectChunkFromPage(Page* page);
-  inline void UnprotectChunkFromPage(Page* page);
-#endif
-
 #ifdef DEBUG
   // Reports statistic info of the space.
   void ReportStatistics();
@@ -1157,12 +1140,6 @@
// Ensures that the capacity is at least 'capacity'. Returns false on failure.
   bool EnsureCapacity(int capacity);

-#ifdef ENABLE_HEAP_PROTECTION
-  // Protect/unprotect the space by marking it read-only/writable.
-  void Protect();
-  void Unprotect();
-#endif
-
 #ifdef DEBUG
   // Print meta info and objects in this space.
   virtual void Print();
@@ -1392,12 +1369,6 @@
   bool Commit();
   bool Uncommit();

-#ifdef ENABLE_HEAP_PROTECTION
-  // Protect/unprotect the space by marking it read-only/writable.
-  virtual void Protect() {}
-  virtual void Unprotect() {}
-#endif
-
 #ifdef DEBUG
   virtual void Print();
   virtual void Verify();
@@ -1628,12 +1599,6 @@
   template <typename StringType>
   inline void ShrinkStringAtAllocationBoundary(String* string, int len);

-#ifdef ENABLE_HEAP_PROTECTION
-  // Protect/unprotect the space by marking it read-only/writable.
-  virtual void Protect();
-  virtual void Unprotect();
-#endif
-
 #ifdef DEBUG
   // Verify the active semispace.
   virtual void Verify();
@@ -2296,12 +2261,6 @@
   // may use some memory, leaving less for large objects.
   virtual bool ReserveSpace(int bytes);

-#ifdef ENABLE_HEAP_PROTECTION
-  // Protect/unprotect the space by marking it read-only/writable.
-  void Protect();
-  void Unprotect();
-#endif
-
 #ifdef DEBUG
   virtual void Verify();
   virtual void Print();
=======================================
--- /branches/bleeding_edge/src/vm-state-inl.h  Fri Mar 18 13:35:07 2011
+++ /branches/bleeding_edge/src/vm-state-inl.h  Mon Jul 11 07:03:21 2011
@@ -69,19 +69,6 @@
 #endif

   isolate_->SetCurrentVMState(tag);
-
-#ifdef ENABLE_HEAP_PROTECTION
-  if (FLAG_protect_heap) {
-    if (tag == EXTERNAL) {
-      // We are leaving V8.
-      ASSERT(previous_tag_ != EXTERNAL);
-      isolate_->heap()->Protect();
-    } else if (previous_tag_ = EXTERNAL) {
-      // We are entering V8.
-      isolate_->heap()->Unprotect();
-    }
-  }
-#endif
 }


@@ -96,24 +83,7 @@
   }
 #endif  // ENABLE_LOGGING_AND_PROFILING

-#ifdef ENABLE_HEAP_PROTECTION
-  StateTag tag = isolate_->current_vm_state();
-#endif
-
   isolate_->SetCurrentVMState(previous_tag_);
-
-#ifdef ENABLE_HEAP_PROTECTION
-  if (FLAG_protect_heap) {
-    if (tag == EXTERNAL) {
-      // We are reentering V8.
-      ASSERT(previous_tag_ != EXTERNAL);
-      isolate_->heap()->Unprotect();
-    } else if (previous_tag_ == EXTERNAL) {
-      // We are leaving V8.
-      isolate_->heap()->Protect();
-    }
-  }
-#endif  // ENABLE_HEAP_PROTECTION
 }

 #endif  // ENABLE_VMSTATE_TRACKING

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

Reply via email to