Merge V8 5.2.361.47  DO NOT MERGE

https://chromium.googlesource.com/v8/v8/+/5.2.361.47

FPIIM-449

Change-Id: Ibec421b85a9b88cb3a432ada642e469fe7e78346
(cherry picked from commit bcf72ee8e3b26f1d0726869c7ddb3921c68b09a8)
diff --git a/test/cctest/heap/test-spaces.cc b/test/cctest/heap/test-spaces.cc
index a7cf161..da364c5 100644
--- a/test/cctest/heap/test-spaces.cc
+++ b/test/cctest/heap/test-spaces.cc
@@ -107,13 +107,12 @@
 class TestMemoryAllocatorScope {
  public:
   TestMemoryAllocatorScope(Isolate* isolate, MemoryAllocator* allocator)
-      : isolate_(isolate),
-        old_allocator_(isolate->memory_allocator_) {
-    isolate->memory_allocator_ = allocator;
+      : isolate_(isolate), old_allocator_(isolate->heap()->memory_allocator()) {
+    isolate->heap()->memory_allocator_ = allocator;
   }
 
   ~TestMemoryAllocatorScope() {
-    isolate_->memory_allocator_ = old_allocator_;
+    isolate_->heap()->memory_allocator_ = old_allocator_;
   }
 
  private:
@@ -129,12 +128,12 @@
  public:
   TestCodeRangeScope(Isolate* isolate, CodeRange* code_range)
       : isolate_(isolate),
-        old_code_range_(isolate->code_range_) {
-    isolate->code_range_ = code_range;
+        old_code_range_(isolate->heap()->memory_allocator()->code_range()) {
+    isolate->heap()->memory_allocator()->code_range_ = code_range;
   }
 
   ~TestCodeRangeScope() {
-    isolate_->code_range_ = old_code_range_;
+    isolate_->heap()->memory_allocator()->code_range_ = old_code_range_;
   }
 
  private:
@@ -153,50 +152,49 @@
                               size_t second_commit_area_size,
                               Executability executable) {
   MemoryAllocator* memory_allocator = new MemoryAllocator(isolate);
-  CHECK(memory_allocator->SetUp(heap->MaxReserved(),
-                                heap->MaxExecutableSize()));
-  TestMemoryAllocatorScope test_allocator_scope(isolate, memory_allocator);
-  TestCodeRangeScope test_code_range_scope(isolate, code_range);
+  CHECK(memory_allocator->SetUp(heap->MaxReserved(), heap->MaxExecutableSize(),
+                                0));
+  {
+    TestMemoryAllocatorScope test_allocator_scope(isolate, memory_allocator);
+    TestCodeRangeScope test_code_range_scope(isolate, code_range);
 
-  size_t header_size = (executable == EXECUTABLE)
-                       ? MemoryAllocator::CodePageGuardStartOffset()
-                       : MemoryChunk::kObjectStartOffset;
-  size_t guard_size = (executable == EXECUTABLE)
-                       ? MemoryAllocator::CodePageGuardSize()
-                       : 0;
+    size_t header_size = (executable == EXECUTABLE)
+                             ? MemoryAllocator::CodePageGuardStartOffset()
+                             : MemoryChunk::kObjectStartOffset;
+    size_t guard_size =
+        (executable == EXECUTABLE) ? MemoryAllocator::CodePageGuardSize() : 0;
 
-  MemoryChunk* memory_chunk = memory_allocator->AllocateChunk(reserve_area_size,
-                                                              commit_area_size,
-                                                              executable,
-                                                              NULL);
-  size_t alignment = code_range != NULL && code_range->valid()
-                         ? MemoryChunk::kAlignment
-                         : base::OS::CommitPageSize();
-  size_t reserved_size =
-      ((executable == EXECUTABLE))
-          ? RoundUp(header_size + guard_size + reserve_area_size + guard_size,
-                    alignment)
-          : RoundUp(header_size + reserve_area_size,
-                    base::OS::CommitPageSize());
-  CHECK(memory_chunk->size() == reserved_size);
-  CHECK(memory_chunk->area_start() < memory_chunk->address() +
-                                     memory_chunk->size());
-  CHECK(memory_chunk->area_end() <= memory_chunk->address() +
-                                    memory_chunk->size());
-  CHECK(static_cast<size_t>(memory_chunk->area_size()) == commit_area_size);
+    MemoryChunk* memory_chunk = memory_allocator->AllocateChunk(
+        reserve_area_size, commit_area_size, executable, NULL);
+    size_t alignment = code_range != NULL && code_range->valid()
+                           ? MemoryChunk::kAlignment
+                           : base::OS::CommitPageSize();
+    size_t reserved_size =
+        ((executable == EXECUTABLE))
+            ? RoundUp(header_size + guard_size + reserve_area_size + guard_size,
+                      alignment)
+            : RoundUp(header_size + reserve_area_size,
+                      base::OS::CommitPageSize());
+    CHECK(memory_chunk->size() == reserved_size);
+    CHECK(memory_chunk->area_start() <
+          memory_chunk->address() + memory_chunk->size());
+    CHECK(memory_chunk->area_end() <=
+          memory_chunk->address() + memory_chunk->size());
+    CHECK(static_cast<size_t>(memory_chunk->area_size()) == commit_area_size);
 
-  Address area_start = memory_chunk->area_start();
+    Address area_start = memory_chunk->area_start();
 
-  memory_chunk->CommitArea(second_commit_area_size);
-  CHECK(area_start == memory_chunk->area_start());
-  CHECK(memory_chunk->area_start() < memory_chunk->address() +
-                                     memory_chunk->size());
-  CHECK(memory_chunk->area_end() <= memory_chunk->address() +
-                                    memory_chunk->size());
-  CHECK(static_cast<size_t>(memory_chunk->area_size()) ==
-      second_commit_area_size);
+    memory_chunk->CommitArea(second_commit_area_size);
+    CHECK(area_start == memory_chunk->area_start());
+    CHECK(memory_chunk->area_start() <
+          memory_chunk->address() + memory_chunk->size());
+    CHECK(memory_chunk->area_end() <=
+          memory_chunk->address() + memory_chunk->size());
+    CHECK(static_cast<size_t>(memory_chunk->area_size()) ==
+          second_commit_area_size);
 
-  memory_allocator->Free(memory_chunk);
+    memory_allocator->Free<MemoryAllocator::kFull>(memory_chunk);
+  }
   memory_allocator->TearDown();
   delete memory_allocator;
 }
@@ -207,8 +205,8 @@
   Heap* heap = isolate->heap();
   const int pageSize = Page::kPageSize;
   MemoryAllocator* memory_allocator = new MemoryAllocator(isolate);
-  CHECK(
-      memory_allocator->SetUp(heap->MaxReserved(), heap->MaxExecutableSize()));
+  CHECK(memory_allocator->SetUp(heap->MaxReserved(), heap->MaxExecutableSize(),
+                                0));
   TestMemoryAllocatorScope test_allocator_scope(isolate, memory_allocator);
   CodeRange* code_range = new CodeRange(isolate);
   const size_t code_range_size = 4 * pageSize;
@@ -310,19 +308,19 @@
 
   MemoryAllocator* memory_allocator = new MemoryAllocator(isolate);
   CHECK(memory_allocator != nullptr);
-  CHECK(memory_allocator->SetUp(heap->MaxReserved(),
-                                heap->MaxExecutableSize()));
+  CHECK(memory_allocator->SetUp(heap->MaxReserved(), heap->MaxExecutableSize(),
+                                0));
   TestMemoryAllocatorScope test_scope(isolate, memory_allocator);
 
   {
     int total_pages = 0;
     OldSpace faked_space(heap, OLD_SPACE, NOT_EXECUTABLE);
-    Page* first_page = memory_allocator->AllocatePage<Page>(
+    Page* first_page = memory_allocator->AllocatePage(
         faked_space.AreaSize(), static_cast<PagedSpace*>(&faked_space),
         NOT_EXECUTABLE);
 
     first_page->InsertAfter(faked_space.anchor()->prev_page());
-    CHECK(first_page->is_valid());
+    CHECK(Page::IsValid(first_page));
     CHECK(first_page->next_page() == faked_space.anchor());
     total_pages++;
 
@@ -331,10 +329,10 @@
     }
 
     // Again, we should get n or n - 1 pages.
-    Page* other = memory_allocator->AllocatePage<Page>(
+    Page* other = memory_allocator->AllocatePage(
         faked_space.AreaSize(), static_cast<PagedSpace*>(&faked_space),
         NOT_EXECUTABLE);
-    CHECK(other->is_valid());
+    CHECK(Page::IsValid(other));
     total_pages++;
     other->InsertAfter(first_page);
     int page_count = 0;
@@ -345,7 +343,7 @@
     CHECK(total_pages == page_count);
 
     Page* second_page = first_page->next_page();
-    CHECK(second_page->is_valid());
+    CHECK(Page::IsValid(second_page));
 
     // OldSpace's destructor will tear down the space and free up all pages.
   }
@@ -358,8 +356,8 @@
   Isolate* isolate = CcTest::i_isolate();
   Heap* heap = isolate->heap();
   MemoryAllocator* memory_allocator = new MemoryAllocator(isolate);
-  CHECK(memory_allocator->SetUp(heap->MaxReserved(),
-                                heap->MaxExecutableSize()));
+  CHECK(memory_allocator->SetUp(heap->MaxReserved(), heap->MaxExecutableSize(),
+                                0));
   TestMemoryAllocatorScope test_scope(isolate, memory_allocator);
 
   NewSpace new_space(heap);
@@ -385,8 +383,8 @@
   Isolate* isolate = CcTest::i_isolate();
   Heap* heap = isolate->heap();
   MemoryAllocator* memory_allocator = new MemoryAllocator(isolate);
-  CHECK(memory_allocator->SetUp(heap->MaxReserved(),
-                                heap->MaxExecutableSize()));
+  CHECK(memory_allocator->SetUp(heap->MaxReserved(), heap->MaxExecutableSize(),
+                                0));
   TestMemoryAllocatorScope test_scope(isolate, memory_allocator);
 
   OldSpace* s = new OldSpace(heap, OLD_SPACE, NOT_EXECUTABLE);
@@ -409,8 +407,8 @@
   Heap* heap = isolate->heap();
   MemoryAllocator* memory_allocator = new MemoryAllocator(isolate);
   CHECK(memory_allocator != nullptr);
-  CHECK(
-      memory_allocator->SetUp(heap->MaxReserved(), heap->MaxExecutableSize()));
+  CHECK(memory_allocator->SetUp(heap->MaxReserved(), heap->MaxExecutableSize(),
+                                0));
   TestMemoryAllocatorScope test_scope(isolate, memory_allocator);
 
   CompactionSpace* compaction_space =