Two tiny refactorings: Removed a bit of copy-n-paste. Moved LargeObjectChunk::Free...
authorsvenpanne@chromium.org <svenpanne@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 25 Aug 2011 13:35:15 +0000 (13:35 +0000)
committersvenpanne@chromium.org <svenpanne@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 25 Aug 2011 13:35:15 +0000 (13:35 +0000)
Review URL: http://codereview.chromium.org/7744023

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9017 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/spaces-inl.h
src/spaces.cc
src/spaces.h

index 283156c41af154af4f67ea24104633fc8745b6e7..069d01db247a6adaeeafef71ea720da3106c68eb 100644 (file)
@@ -433,23 +433,6 @@ MaybeObject* PagedSpace::MCAllocateRaw(int size_in_bytes) {
 }
 
 
-// -----------------------------------------------------------------------------
-// LargeObjectChunk
-
-Address LargeObjectChunk::GetStartAddress() {
-  // Round the chunk address up to the nearest page-aligned address
-  // and return the heap object in that page.
-  Page* page = Page::FromAddress(RoundUp(address(), Page::kPageSize));
-  return page->ObjectAreaStart();
-}
-
-
-void LargeObjectChunk::Free(Executability executable) {
-  Isolate* isolate =
-      Page::FromAddress(RoundUp(address(), Page::kPageSize))->heap_->isolate();
-  isolate->memory_allocator()->FreeRawMemory(address(), size(), executable);
-}
-
 // -----------------------------------------------------------------------------
 // NewSpace
 
index cc9038dc67490b7cbac2ee28b46936c4355ab3ce..63f743258fc94117b5d40f18847a7f6c9fa3e6d5 100644 (file)
@@ -2722,12 +2722,17 @@ LargeObjectChunk* LargeObjectChunk::New(int size_in_bytes,
 
   LargeObjectChunk* chunk = reinterpret_cast<LargeObjectChunk*>(mem);
   chunk->size_ = size;
-  Page* page = Page::FromAddress(RoundUp(chunk->address(), Page::kPageSize));
-  page->heap_ = isolate->heap();
+  chunk->GetPage()->heap_ = isolate->heap();
   return chunk;
 }
 
 
+void LargeObjectChunk::Free(Executability executable) {
+  Isolate* isolate = GetPage()->heap_->isolate();
+  isolate->memory_allocator()->FreeRawMemory(address(), size(), executable);
+}
+
+
 int LargeObjectChunk::ChunkSizeFor(int size_in_bytes) {
   int os_alignment = static_cast<int>(OS::AllocateAlignment());
   if (os_alignment < Page::kPageSize) {
@@ -2761,8 +2766,7 @@ void LargeObjectSpace::TearDown() {
     LargeObjectChunk* chunk = first_chunk_;
     first_chunk_ = first_chunk_->next();
     LOG(heap()->isolate(), DeleteEvent("LargeObjectChunk", chunk->address()));
-    Page* page = Page::FromAddress(RoundUp(chunk->address(), Page::kPageSize));
-    Executability executable = page->PageExecutability();
+    Executability executable = chunk->GetPage()->PageExecutability();
     ObjectSpace space = kObjectSpaceLoSpace;
     if (executable == EXECUTABLE) space = kObjectSpaceCodeSpace;
     size_t size = chunk->size();
@@ -2805,7 +2809,7 @@ MaybeObject* LargeObjectSpace::AllocateRawInternal(int requested_size,
   first_chunk_ = chunk;
 
   // Initialize page header.
-  Page* page = Page::FromAddress(RoundUp(chunk->address(), Page::kPageSize));
+  Page* page = chunk->GetPage();
   Address object_address = page->ObjectAreaStart();
 
   // Clear the low order bit of the second word in the page to flag it as a
@@ -2943,9 +2947,7 @@ void LargeObjectSpace::FreeUnmarkedObjects() {
       previous = current;
       current = current->next();
     } else {
-      Page* page = Page::FromAddress(RoundUp(current->address(),
-                                     Page::kPageSize));
-      Executability executable = page->PageExecutability();
+      Executability executable = current->GetPage()->PageExecutability();
       Address chunk_address = current->address();
       size_t chunk_size = current->size();
 
index 006c882c1b3cb841b4e24b4676ad2bb6eb081352..908cd300e2b8d42c6201005e883ef32012a0a212 100644 (file)
@@ -2144,7 +2144,7 @@ class LargeObjectChunk {
   static LargeObjectChunk* New(int size_in_bytes, Executability executable);
 
   // Free the memory associated with the chunk.
-  inline void Free(Executability executable);
+  void Free(Executability executable);
 
   // Interpret a raw address as a large object chunk.
   static LargeObjectChunk* FromAddress(Address address) {
@@ -2154,13 +2154,17 @@ class LargeObjectChunk {
   // Returns the address of this chunk.
   Address address() { return reinterpret_cast<Address>(this); }
 
+  Page* GetPage() {
+    return Page::FromAddress(RoundUp(address(), Page::kPageSize));
+  }
+
   // Accessors for the fields of the chunk.
   LargeObjectChunk* next() { return next_; }
   void set_next(LargeObjectChunk* chunk) { next_ = chunk; }
   size_t size() { return size_ & ~Page::kPageFlagMask; }
 
   // Compute the start address in the chunk.
-  inline Address GetStartAddress();
+  Address GetStartAddress() { return GetPage()->ObjectAreaStart(); }
 
   // Returns the object in this chunk.
   HeapObject* GetObject() { return HeapObject::FromAddress(GetStartAddress()); }