| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 CHECK(p->OffsetToAddress(Page::kPageSize) == p->ObjectAreaEnd()); | 83 CHECK(p->OffsetToAddress(Page::kPageSize) == p->ObjectAreaEnd()); |
| 84 | 84 |
| 85 // test region marking | 85 // test region marking |
| 86 VerifyRegionMarking(page_start); | 86 VerifyRegionMarking(page_start); |
| 87 | 87 |
| 88 DeleteArray(mem); | 88 DeleteArray(mem); |
| 89 } | 89 } |
| 90 | 90 |
| 91 | 91 |
| 92 TEST(MemoryAllocator) { | 92 TEST(MemoryAllocator) { |
| 93 OS::Setup(); |
| 93 Isolate* isolate = Isolate::Current(); | 94 Isolate* isolate = Isolate::Current(); |
| 94 | 95 |
| 95 CHECK(isolate->heap()->ConfigureHeapDefault()); | 96 CHECK(isolate->heap()->ConfigureHeapDefault()); |
| 96 CHECK(isolate->memory_allocator()->Setup(isolate->heap()->MaxReserved())); | 97 CHECK(isolate->memory_allocator()->Setup(isolate->heap()->MaxReserved())); |
| 97 | 98 |
| 98 OldSpace faked_space(isolate->heap()->MaxReserved(), OLD_POINTER_SPACE, | 99 OldSpace faked_space(isolate->heap()->MaxReserved(), OLD_POINTER_SPACE, |
| 99 NOT_EXECUTABLE); | 100 NOT_EXECUTABLE); |
| 100 int total_pages = 0; | 101 int total_pages = 0; |
| 101 int requested = 2; | 102 int requested = 2; |
| 102 int allocated; | 103 int allocated; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 // Freeing pages in the first chunk starting at the first page should free | 145 // Freeing pages in the first chunk starting at the first page should free |
| 145 // the first chunk and return an invalid page. | 146 // the first chunk and return an invalid page. |
| 146 Page* invalid_page = isolate->memory_allocator()->FreePages(first_page); | 147 Page* invalid_page = isolate->memory_allocator()->FreePages(first_page); |
| 147 CHECK(!invalid_page->is_valid()); | 148 CHECK(!invalid_page->is_valid()); |
| 148 | 149 |
| 149 isolate->memory_allocator()->TearDown(); | 150 isolate->memory_allocator()->TearDown(); |
| 150 } | 151 } |
| 151 | 152 |
| 152 | 153 |
| 153 TEST(NewSpace) { | 154 TEST(NewSpace) { |
| 155 OS::Setup(); |
| 154 CHECK(HEAP->ConfigureHeapDefault()); | 156 CHECK(HEAP->ConfigureHeapDefault()); |
| 155 CHECK(Isolate::Current()->memory_allocator()->Setup(HEAP->MaxReserved())); | 157 CHECK(Isolate::Current()->memory_allocator()->Setup(HEAP->MaxReserved())); |
| 156 | 158 |
| 157 NewSpace new_space; | 159 NewSpace new_space; |
| 158 | 160 |
| 159 void* chunk = | 161 void* chunk = |
| 160 Isolate::Current()->memory_allocator()->ReserveInitialChunk( | 162 Isolate::Current()->memory_allocator()->ReserveInitialChunk( |
| 161 4 * HEAP->ReservedSemiSpaceSize()); | 163 4 * HEAP->ReservedSemiSpaceSize()); |
| 162 CHECK(chunk != NULL); | 164 CHECK(chunk != NULL); |
| 163 Address start = RoundUp(static_cast<Address>(chunk), | 165 Address start = RoundUp(static_cast<Address>(chunk), |
| 164 2 * HEAP->ReservedSemiSpaceSize()); | 166 2 * HEAP->ReservedSemiSpaceSize()); |
| 165 CHECK(new_space.Setup(start, 2 * HEAP->ReservedSemiSpaceSize())); | 167 CHECK(new_space.Setup(start, 2 * HEAP->ReservedSemiSpaceSize())); |
| 166 CHECK(new_space.HasBeenSetup()); | 168 CHECK(new_space.HasBeenSetup()); |
| 167 | 169 |
| 168 while (new_space.Available() >= Page::kMaxHeapObjectSize) { | 170 while (new_space.Available() >= Page::kMaxHeapObjectSize) { |
| 169 Object* obj = new_space.AllocateRaw(Page::kMaxHeapObjectSize); | 171 Object* obj = new_space.AllocateRaw(Page::kMaxHeapObjectSize); |
| 170 CHECK(!obj->IsFailure()); | 172 CHECK(!obj->IsFailure()); |
| 171 CHECK(new_space.Contains(HeapObject::cast(obj))); | 173 CHECK(new_space.Contains(HeapObject::cast(obj))); |
| 172 } | 174 } |
| 173 | 175 |
| 174 new_space.TearDown(); | 176 new_space.TearDown(); |
| 175 Isolate::Current()->memory_allocator()->TearDown(); | 177 Isolate::Current()->memory_allocator()->TearDown(); |
| 176 } | 178 } |
| 177 | 179 |
| 178 | 180 |
| 179 TEST(OldSpace) { | 181 TEST(OldSpace) { |
| 182 OS::Setup(); |
| 180 CHECK(HEAP->ConfigureHeapDefault()); | 183 CHECK(HEAP->ConfigureHeapDefault()); |
| 181 CHECK(Isolate::Current()->memory_allocator()->Setup(HEAP->MaxReserved())); | 184 CHECK(Isolate::Current()->memory_allocator()->Setup(HEAP->MaxReserved())); |
| 182 | 185 |
| 183 OldSpace* s = new OldSpace(HEAP->MaxOldGenerationSize(), | 186 OldSpace* s = new OldSpace(HEAP->MaxOldGenerationSize(), |
| 184 OLD_POINTER_SPACE, | 187 OLD_POINTER_SPACE, |
| 185 NOT_EXECUTABLE); | 188 NOT_EXECUTABLE); |
| 186 CHECK(s != NULL); | 189 CHECK(s != NULL); |
| 187 | 190 |
| 188 void* chunk = | 191 void* chunk = |
| 189 Isolate::Current()->memory_allocator()->ReserveInitialChunk( | 192 Isolate::Current()->memory_allocator()->ReserveInitialChunk( |
| 190 4 * HEAP->ReservedSemiSpaceSize()); | 193 4 * HEAP->ReservedSemiSpaceSize()); |
| 191 CHECK(chunk != NULL); | 194 CHECK(chunk != NULL); |
| 192 Address start = static_cast<Address>(chunk); | 195 Address start = static_cast<Address>(chunk); |
| 193 size_t size = RoundUp(start, 2 * HEAP->ReservedSemiSpaceSize()) - start; | 196 size_t size = RoundUp(start, 2 * HEAP->ReservedSemiSpaceSize()) - start; |
| 194 | 197 |
| 195 CHECK(s->Setup(start, size)); | 198 CHECK(s->Setup(start, size)); |
| 196 | 199 |
| 197 while (s->Available() > 0) { | 200 while (s->Available() > 0) { |
| 198 Object* obj = s->AllocateRaw(Page::kMaxHeapObjectSize); | 201 Object* obj = s->AllocateRaw(Page::kMaxHeapObjectSize); |
| 199 CHECK(!obj->IsFailure()); | 202 CHECK(!obj->IsFailure()); |
| 200 } | 203 } |
| 201 | 204 |
| 202 s->TearDown(); | 205 s->TearDown(); |
| 203 delete s; | 206 delete s; |
| 204 Isolate::Current()->memory_allocator()->TearDown(); | 207 Isolate::Current()->memory_allocator()->TearDown(); |
| 205 } | 208 } |
| 206 | 209 |
| 207 | 210 |
| 208 TEST(LargeObjectSpace) { | 211 TEST(LargeObjectSpace) { |
| 212 OS::Setup(); |
| 209 CHECK(HEAP->Setup(false)); | 213 CHECK(HEAP->Setup(false)); |
| 210 | 214 |
| 211 LargeObjectSpace* lo = HEAP->lo_space(); | 215 LargeObjectSpace* lo = HEAP->lo_space(); |
| 212 CHECK(lo != NULL); | 216 CHECK(lo != NULL); |
| 213 | 217 |
| 214 Map* faked_map = reinterpret_cast<Map*>(HeapObject::FromAddress(0)); | 218 Map* faked_map = reinterpret_cast<Map*>(HeapObject::FromAddress(0)); |
| 215 int lo_size = Page::kPageSize; | 219 int lo_size = Page::kPageSize; |
| 216 | 220 |
| 217 Object* obj = lo->AllocateRaw(lo_size); | 221 Object* obj = lo->AllocateRaw(lo_size); |
| 218 CHECK(!obj->IsFailure()); | 222 CHECK(!obj->IsFailure()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 238 CHECK(!lo->IsEmpty()); | 242 CHECK(!lo->IsEmpty()); |
| 239 | 243 |
| 240 obj = lo->AllocateRaw(lo_size); | 244 obj = lo->AllocateRaw(lo_size); |
| 241 CHECK(obj->IsFailure()); | 245 CHECK(obj->IsFailure()); |
| 242 | 246 |
| 243 lo->TearDown(); | 247 lo->TearDown(); |
| 244 delete lo; | 248 delete lo; |
| 245 | 249 |
| 246 Isolate::Current()->memory_allocator()->TearDown(); | 250 Isolate::Current()->memory_allocator()->TearDown(); |
| 247 } | 251 } |
| OLD | NEW |