| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #define V8_IMMINENT_DEPRECATION_WARNINGS | 29 #define V8_IMMINENT_DEPRECATION_WARNINGS |
| 30 | 30 |
| 31 #include <stdlib.h> | 31 #include <stdlib.h> |
| 32 | 32 |
| 33 #include "src/base/platform/platform.h" | 33 #include "src/base/platform/platform.h" |
| 34 #include "src/snapshot/snapshot.h" | 34 #include "src/snapshot/snapshot.h" |
| 35 #include "src/v8.h" | 35 #include "src/v8.h" |
| 36 #include "test/cctest/cctest.h" | 36 #include "test/cctest/cctest.h" |
| 37 #include "test/cctest/heap-tester.h" | 37 #include "test/cctest/heap-tester.h" |
| 38 | 38 |
| 39 using namespace v8::internal; | 39 namespace v8 { |
| 40 namespace internal { |
| 40 | 41 |
| 41 #if 0 | 42 #if 0 |
| 42 static void VerifyRegionMarking(Address page_start) { | 43 static void VerifyRegionMarking(Address page_start) { |
| 43 #ifdef ENABLE_CARDMARKING_WRITE_BARRIER | 44 #ifdef ENABLE_CARDMARKING_WRITE_BARRIER |
| 44 Page* p = Page::FromAddress(page_start); | 45 Page* p = Page::FromAddress(page_start); |
| 45 | 46 |
| 46 p->SetRegionMarks(Page::kAllRegionsCleanMarks); | 47 p->SetRegionMarks(Page::kAllRegionsCleanMarks); |
| 47 | 48 |
| 48 for (Address addr = p->ObjectAreaStart(); | 49 for (Address addr = p->ObjectAreaStart(); |
| 49 addr < p->ObjectAreaEnd(); | 50 addr < p->ObjectAreaEnd(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 CHECK(p->OffsetToAddress(Page::kPageSize) == p->ObjectAreaEnd()); | 98 CHECK(p->OffsetToAddress(Page::kPageSize) == p->ObjectAreaEnd()); |
| 98 | 99 |
| 99 // test region marking | 100 // test region marking |
| 100 VerifyRegionMarking(page_start); | 101 VerifyRegionMarking(page_start); |
| 101 | 102 |
| 102 DeleteArray(mem); | 103 DeleteArray(mem); |
| 103 } | 104 } |
| 104 #endif | 105 #endif |
| 105 | 106 |
| 106 | 107 |
| 107 namespace v8 { | |
| 108 namespace internal { | |
| 109 | |
| 110 // Temporarily sets a given allocator in an isolate. | 108 // Temporarily sets a given allocator in an isolate. |
| 111 class TestMemoryAllocatorScope { | 109 class TestMemoryAllocatorScope { |
| 112 public: | 110 public: |
| 113 TestMemoryAllocatorScope(Isolate* isolate, MemoryAllocator* allocator) | 111 TestMemoryAllocatorScope(Isolate* isolate, MemoryAllocator* allocator) |
| 114 : isolate_(isolate), | 112 : isolate_(isolate), |
| 115 old_allocator_(isolate->memory_allocator_) { | 113 old_allocator_(isolate->memory_allocator_) { |
| 116 isolate->memory_allocator_ = allocator; | 114 isolate->memory_allocator_ = allocator; |
| 117 } | 115 } |
| 118 | 116 |
| 119 ~TestMemoryAllocatorScope() { | 117 ~TestMemoryAllocatorScope() { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 141 isolate_->code_range_ = old_code_range_; | 139 isolate_->code_range_ = old_code_range_; |
| 142 } | 140 } |
| 143 | 141 |
| 144 private: | 142 private: |
| 145 Isolate* isolate_; | 143 Isolate* isolate_; |
| 146 CodeRange* old_code_range_; | 144 CodeRange* old_code_range_; |
| 147 | 145 |
| 148 DISALLOW_COPY_AND_ASSIGN(TestCodeRangeScope); | 146 DISALLOW_COPY_AND_ASSIGN(TestCodeRangeScope); |
| 149 }; | 147 }; |
| 150 | 148 |
| 151 } // namespace internal | |
| 152 } // namespace v8 | |
| 153 | |
| 154 | 149 |
| 155 static void VerifyMemoryChunk(Isolate* isolate, | 150 static void VerifyMemoryChunk(Isolate* isolate, |
| 156 Heap* heap, | 151 Heap* heap, |
| 157 CodeRange* code_range, | 152 CodeRange* code_range, |
| 158 size_t reserve_area_size, | 153 size_t reserve_area_size, |
| 159 size_t commit_area_size, | 154 size_t commit_area_size, |
| 160 size_t second_commit_area_size, | 155 size_t second_commit_area_size, |
| 161 Executability executable) { | 156 Executability executable) { |
| 162 MemoryAllocator* memory_allocator = new MemoryAllocator(isolate); | 157 MemoryAllocator* memory_allocator = new MemoryAllocator(isolate); |
| 163 CHECK(memory_allocator->SetUp(heap->MaxReserved(), | 158 CHECK(memory_allocator->SetUp(heap->MaxReserved(), |
| 164 heap->MaxExecutableSize())); | 159 heap->MaxExecutableSize())); |
| 165 TestMemoryAllocatorScope test_allocator_scope(isolate, memory_allocator); | 160 TestMemoryAllocatorScope test_allocator_scope(isolate, memory_allocator); |
| 166 TestCodeRangeScope test_code_range_scope(isolate, code_range); | 161 TestCodeRangeScope test_code_range_scope(isolate, code_range); |
| 167 | 162 |
| 168 size_t header_size = (executable == EXECUTABLE) | 163 size_t header_size = (executable == EXECUTABLE) |
| 169 ? MemoryAllocator::CodePageGuardStartOffset() | 164 ? MemoryAllocator::CodePageGuardStartOffset() |
| 170 : MemoryChunk::kObjectStartOffset; | 165 : MemoryChunk::kObjectStartOffset; |
| 171 size_t guard_size = (executable == EXECUTABLE) | 166 size_t guard_size = (executable == EXECUTABLE) |
| 172 ? MemoryAllocator::CodePageGuardSize() | 167 ? MemoryAllocator::CodePageGuardSize() |
| 173 : 0; | 168 : 0; |
| 174 | 169 |
| 175 MemoryChunk* memory_chunk = memory_allocator->AllocateChunk(reserve_area_size, | 170 MemoryChunk* memory_chunk = memory_allocator->AllocateChunk(reserve_area_size, |
| 176 commit_area_size, | 171 commit_area_size, |
| 177 executable, | 172 executable, |
| 178 NULL); | 173 NULL); |
| 179 size_t alignment = code_range != NULL && code_range->valid() ? | 174 size_t alignment = code_range != NULL && code_range->valid() |
| 180 MemoryChunk::kAlignment : v8::base::OS::CommitPageSize(); | 175 ? MemoryChunk::kAlignment |
| 176 : base::OS::CommitPageSize(); |
| 181 size_t reserved_size = | 177 size_t reserved_size = |
| 182 ((executable == EXECUTABLE)) | 178 ((executable == EXECUTABLE)) |
| 183 ? RoundUp(header_size + guard_size + reserve_area_size + guard_size, | 179 ? RoundUp(header_size + guard_size + reserve_area_size + guard_size, |
| 184 alignment) | 180 alignment) |
| 185 : RoundUp(header_size + reserve_area_size, | 181 : RoundUp(header_size + reserve_area_size, |
| 186 v8::base::OS::CommitPageSize()); | 182 base::OS::CommitPageSize()); |
| 187 CHECK(memory_chunk->size() == reserved_size); | 183 CHECK(memory_chunk->size() == reserved_size); |
| 188 CHECK(memory_chunk->area_start() < memory_chunk->address() + | 184 CHECK(memory_chunk->area_start() < memory_chunk->address() + |
| 189 memory_chunk->size()); | 185 memory_chunk->size()); |
| 190 CHECK(memory_chunk->area_end() <= memory_chunk->address() + | 186 CHECK(memory_chunk->area_end() <= memory_chunk->address() + |
| 191 memory_chunk->size()); | 187 memory_chunk->size()); |
| 192 CHECK(static_cast<size_t>(memory_chunk->area_size()) == commit_area_size); | 188 CHECK(static_cast<size_t>(memory_chunk->area_size()) == commit_area_size); |
| 193 | 189 |
| 194 Address area_start = memory_chunk->area_start(); | 190 Address area_start = memory_chunk->area_start(); |
| 195 | 191 |
| 196 memory_chunk->CommitArea(second_commit_area_size); | 192 memory_chunk->CommitArea(second_commit_area_size); |
| (...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 CHECK_EQ(observer1.count(), 16); // no more notifications. | 877 CHECK_EQ(observer1.count(), 16); // no more notifications. |
| 882 CHECK_EQ(observer2.count(), 3); // this one is still active. | 878 CHECK_EQ(observer2.count(), 3); // this one is still active. |
| 883 | 879 |
| 884 new_space->RemoveInlineAllocationObserver(&observer2); | 880 new_space->RemoveInlineAllocationObserver(&observer2); |
| 885 AllocateUnaligned(new_space, 384); | 881 AllocateUnaligned(new_space, 384); |
| 886 CHECK_EQ(observer1.count(), 16); | 882 CHECK_EQ(observer1.count(), 16); |
| 887 CHECK_EQ(observer2.count(), 3); | 883 CHECK_EQ(observer2.count(), 3); |
| 888 } | 884 } |
| 889 isolate->Dispose(); | 885 isolate->Dispose(); |
| 890 } | 886 } |
| 887 |
| 888 } // namespace internal |
| 889 } // namespace v8 |
| OLD | NEW |