| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 | 92 |
| 93 // test remember set | 93 // test remember set |
| 94 VerifyRSet(page_start); | 94 VerifyRSet(page_start); |
| 95 | 95 |
| 96 DeleteArray(mem); | 96 DeleteArray(mem); |
| 97 } | 97 } |
| 98 | 98 |
| 99 | 99 |
| 100 TEST(MemoryAllocator) { | 100 TEST(MemoryAllocator) { |
| 101 CHECK(Heap::ConfigureHeapDefault()); | 101 CHECK(Heap::ConfigureHeapDefault()); |
| 102 CHECK(MemoryAllocator::Setup(Heap::MaxCapacity())); | 102 CHECK(MemoryAllocator::Setup(Heap::MaxReserved())); |
| 103 | 103 |
| 104 OldSpace faked_space(Heap::MaxCapacity(), OLD_POINTER_SPACE, NOT_EXECUTABLE); | 104 OldSpace faked_space(Heap::MaxReserved(), OLD_POINTER_SPACE, NOT_EXECUTABLE); |
| 105 int total_pages = 0; | 105 int total_pages = 0; |
| 106 int requested = 2; | 106 int requested = 2; |
| 107 int allocated; | 107 int allocated; |
| 108 // If we request two pages, we should get one or two. | 108 // If we request two pages, we should get one or two. |
| 109 Page* first_page = | 109 Page* first_page = |
| 110 MemoryAllocator::AllocatePages(requested, &allocated, &faked_space); | 110 MemoryAllocator::AllocatePages(requested, &allocated, &faked_space); |
| 111 CHECK(first_page->is_valid()); | 111 CHECK(first_page->is_valid()); |
| 112 CHECK(allocated > 0 && allocated <= 2); | 112 CHECK(allocated > 0 && allocated <= 2); |
| 113 total_pages += allocated; | 113 total_pages += allocated; |
| 114 | 114 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 // the first chunk and return an invalid page. | 148 // the first chunk and return an invalid page. |
| 149 Page* invalid_page = MemoryAllocator::FreePages(first_page); | 149 Page* invalid_page = MemoryAllocator::FreePages(first_page); |
| 150 CHECK(!invalid_page->is_valid()); | 150 CHECK(!invalid_page->is_valid()); |
| 151 | 151 |
| 152 MemoryAllocator::TearDown(); | 152 MemoryAllocator::TearDown(); |
| 153 } | 153 } |
| 154 | 154 |
| 155 | 155 |
| 156 TEST(NewSpace) { | 156 TEST(NewSpace) { |
| 157 CHECK(Heap::ConfigureHeapDefault()); | 157 CHECK(Heap::ConfigureHeapDefault()); |
| 158 CHECK(MemoryAllocator::Setup(Heap::MaxCapacity())); | 158 CHECK(MemoryAllocator::Setup(Heap::MaxReserved())); |
| 159 | 159 |
| 160 NewSpace new_space; | 160 NewSpace new_space; |
| 161 | 161 |
| 162 void* chunk = | 162 void* chunk = |
| 163 MemoryAllocator::ReserveInitialChunk(2 * Heap::YoungGenerationSize()); | 163 MemoryAllocator::ReserveInitialChunk(4 * Heap::ReservedSemiSpaceSize()); |
| 164 CHECK(chunk != NULL); | 164 CHECK(chunk != NULL); |
| 165 Address start = RoundUp(static_cast<Address>(chunk), | 165 Address start = RoundUp(static_cast<Address>(chunk), |
| 166 Heap::YoungGenerationSize()); | 166 2 * Heap::ReservedSemiSpaceSize()); |
| 167 CHECK(new_space.Setup(start, Heap::YoungGenerationSize())); | 167 CHECK(new_space.Setup(start, 2 * Heap::ReservedSemiSpaceSize())); |
| 168 CHECK(new_space.HasBeenSetup()); | 168 CHECK(new_space.HasBeenSetup()); |
| 169 | 169 |
| 170 while (new_space.Available() >= Page::kMaxHeapObjectSize) { | 170 while (new_space.Available() >= Page::kMaxHeapObjectSize) { |
| 171 Object* obj = new_space.AllocateRaw(Page::kMaxHeapObjectSize); | 171 Object* obj = new_space.AllocateRaw(Page::kMaxHeapObjectSize); |
| 172 CHECK(!obj->IsFailure()); | 172 CHECK(!obj->IsFailure()); |
| 173 CHECK(new_space.Contains(HeapObject::cast(obj))); | 173 CHECK(new_space.Contains(HeapObject::cast(obj))); |
| 174 } | 174 } |
| 175 | 175 |
| 176 new_space.TearDown(); | 176 new_space.TearDown(); |
| 177 MemoryAllocator::TearDown(); | 177 MemoryAllocator::TearDown(); |
| 178 } | 178 } |
| 179 | 179 |
| 180 | 180 |
| 181 TEST(OldSpace) { | 181 TEST(OldSpace) { |
| 182 CHECK(Heap::ConfigureHeapDefault()); | 182 CHECK(Heap::ConfigureHeapDefault()); |
| 183 CHECK(MemoryAllocator::Setup(Heap::MaxCapacity())); | 183 CHECK(MemoryAllocator::Setup(Heap::MaxReserved())); |
| 184 | 184 |
| 185 OldSpace* s = new OldSpace(Heap::OldGenerationSize(), | 185 OldSpace* s = new OldSpace(Heap::MaxOldGenerationSize(), |
| 186 OLD_POINTER_SPACE, | 186 OLD_POINTER_SPACE, |
| 187 NOT_EXECUTABLE); | 187 NOT_EXECUTABLE); |
| 188 CHECK(s != NULL); | 188 CHECK(s != NULL); |
| 189 | 189 |
| 190 void* chunk = | 190 void* chunk = |
| 191 MemoryAllocator::ReserveInitialChunk(2 * Heap::YoungGenerationSize()); | 191 MemoryAllocator::ReserveInitialChunk(4 * Heap::ReservedSemiSpaceSize()); |
| 192 CHECK(chunk != NULL); | 192 CHECK(chunk != NULL); |
| 193 Address start = static_cast<Address>(chunk); | 193 Address start = static_cast<Address>(chunk); |
| 194 size_t size = RoundUp(start, Heap::YoungGenerationSize()) - start; | 194 size_t size = RoundUp(start, 2 * Heap::ReservedSemiSpaceSize()) - start; |
| 195 | 195 |
| 196 CHECK(s->Setup(start, size)); | 196 CHECK(s->Setup(start, size)); |
| 197 | 197 |
| 198 while (s->Available() > 0) { | 198 while (s->Available() > 0) { |
| 199 Object* obj = s->AllocateRaw(Page::kMaxHeapObjectSize); | 199 Object* obj = s->AllocateRaw(Page::kMaxHeapObjectSize); |
| 200 CHECK(!obj->IsFailure()); | 200 CHECK(!obj->IsFailure()); |
| 201 } | 201 } |
| 202 | 202 |
| 203 s->TearDown(); | 203 s->TearDown(); |
| 204 delete s; | 204 delete s; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 CHECK(!lo->IsEmpty()); | 239 CHECK(!lo->IsEmpty()); |
| 240 | 240 |
| 241 obj = lo->AllocateRaw(lo_size); | 241 obj = lo->AllocateRaw(lo_size); |
| 242 CHECK(obj->IsFailure()); | 242 CHECK(obj->IsFailure()); |
| 243 | 243 |
| 244 lo->TearDown(); | 244 lo->TearDown(); |
| 245 delete lo; | 245 delete lo; |
| 246 | 246 |
| 247 MemoryAllocator::TearDown(); | 247 MemoryAllocator::TearDown(); |
| 248 } | 248 } |
| OLD | NEW |