| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 } | 89 } |
| 90 | 90 |
| 91 | 91 |
| 92 TEST(MemoryAllocator) { | 92 TEST(MemoryAllocator) { |
| 93 OS::Setup(); | 93 OS::Setup(); |
| 94 Isolate* isolate = Isolate::Current(); | 94 Isolate* isolate = Isolate::Current(); |
| 95 | 95 |
| 96 CHECK(isolate->heap()->ConfigureHeapDefault()); | 96 CHECK(isolate->heap()->ConfigureHeapDefault()); |
| 97 CHECK(isolate->memory_allocator()->Setup(isolate->heap()->MaxReserved())); | 97 CHECK(isolate->memory_allocator()->Setup(isolate->heap()->MaxReserved())); |
| 98 | 98 |
| 99 OldSpace faked_space(isolate->heap()->MaxReserved(), OLD_POINTER_SPACE, | 99 OldSpace faked_space(isolate->heap(), |
| 100 isolate->heap()->MaxReserved(), |
| 101 OLD_POINTER_SPACE, |
| 100 NOT_EXECUTABLE); | 102 NOT_EXECUTABLE); |
| 101 int total_pages = 0; | 103 int total_pages = 0; |
| 102 int requested = 2; | 104 int requested = 2; |
| 103 int allocated; | 105 int allocated; |
| 104 // If we request two pages, we should get one or two. | 106 // If we request two pages, we should get one or two. |
| 105 Page* first_page = | 107 Page* first_page = |
| 106 isolate->memory_allocator()->AllocatePages( | 108 isolate->memory_allocator()->AllocatePages( |
| 107 requested, &allocated, &faked_space); | 109 requested, &allocated, &faked_space); |
| 108 CHECK(first_page->is_valid()); | 110 CHECK(first_page->is_valid()); |
| 109 CHECK(allocated > 0 && allocated <= 2); | 111 CHECK(allocated > 0 && allocated <= 2); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 151 |
| 150 isolate->memory_allocator()->TearDown(); | 152 isolate->memory_allocator()->TearDown(); |
| 151 } | 153 } |
| 152 | 154 |
| 153 | 155 |
| 154 TEST(NewSpace) { | 156 TEST(NewSpace) { |
| 155 OS::Setup(); | 157 OS::Setup(); |
| 156 CHECK(HEAP->ConfigureHeapDefault()); | 158 CHECK(HEAP->ConfigureHeapDefault()); |
| 157 CHECK(Isolate::Current()->memory_allocator()->Setup(HEAP->MaxReserved())); | 159 CHECK(Isolate::Current()->memory_allocator()->Setup(HEAP->MaxReserved())); |
| 158 | 160 |
| 159 NewSpace new_space; | 161 NewSpace new_space(HEAP); |
| 160 | 162 |
| 161 void* chunk = | 163 void* chunk = |
| 162 Isolate::Current()->memory_allocator()->ReserveInitialChunk( | 164 Isolate::Current()->memory_allocator()->ReserveInitialChunk( |
| 163 4 * HEAP->ReservedSemiSpaceSize()); | 165 4 * HEAP->ReservedSemiSpaceSize()); |
| 164 CHECK(chunk != NULL); | 166 CHECK(chunk != NULL); |
| 165 Address start = RoundUp(static_cast<Address>(chunk), | 167 Address start = RoundUp(static_cast<Address>(chunk), |
| 166 2 * HEAP->ReservedSemiSpaceSize()); | 168 2 * HEAP->ReservedSemiSpaceSize()); |
| 167 CHECK(new_space.Setup(start, 2 * HEAP->ReservedSemiSpaceSize())); | 169 CHECK(new_space.Setup(start, 2 * HEAP->ReservedSemiSpaceSize())); |
| 168 CHECK(new_space.HasBeenSetup()); | 170 CHECK(new_space.HasBeenSetup()); |
| 169 | 171 |
| 170 while (new_space.Available() >= Page::kMaxHeapObjectSize) { | 172 while (new_space.Available() >= Page::kMaxHeapObjectSize) { |
| 171 Object* obj = new_space.AllocateRaw(Page::kMaxHeapObjectSize); | 173 Object* obj = new_space.AllocateRaw(Page::kMaxHeapObjectSize); |
| 172 CHECK(!obj->IsFailure()); | 174 CHECK(!obj->IsFailure()); |
| 173 CHECK(new_space.Contains(HeapObject::cast(obj))); | 175 CHECK(new_space.Contains(HeapObject::cast(obj))); |
| 174 } | 176 } |
| 175 | 177 |
| 176 new_space.TearDown(); | 178 new_space.TearDown(); |
| 177 Isolate::Current()->memory_allocator()->TearDown(); | 179 Isolate::Current()->memory_allocator()->TearDown(); |
| 178 } | 180 } |
| 179 | 181 |
| 180 | 182 |
| 181 TEST(OldSpace) { | 183 TEST(OldSpace) { |
| 182 OS::Setup(); | 184 OS::Setup(); |
| 183 CHECK(HEAP->ConfigureHeapDefault()); | 185 CHECK(HEAP->ConfigureHeapDefault()); |
| 184 CHECK(Isolate::Current()->memory_allocator()->Setup(HEAP->MaxReserved())); | 186 CHECK(Isolate::Current()->memory_allocator()->Setup(HEAP->MaxReserved())); |
| 185 | 187 |
| 186 OldSpace* s = new OldSpace(HEAP->MaxOldGenerationSize(), | 188 OldSpace* s = new OldSpace(HEAP, |
| 189 HEAP->MaxOldGenerationSize(), |
| 187 OLD_POINTER_SPACE, | 190 OLD_POINTER_SPACE, |
| 188 NOT_EXECUTABLE); | 191 NOT_EXECUTABLE); |
| 189 CHECK(s != NULL); | 192 CHECK(s != NULL); |
| 190 | 193 |
| 191 void* chunk = | 194 void* chunk = |
| 192 Isolate::Current()->memory_allocator()->ReserveInitialChunk( | 195 Isolate::Current()->memory_allocator()->ReserveInitialChunk( |
| 193 4 * HEAP->ReservedSemiSpaceSize()); | 196 4 * HEAP->ReservedSemiSpaceSize()); |
| 194 CHECK(chunk != NULL); | 197 CHECK(chunk != NULL); |
| 195 Address start = static_cast<Address>(chunk); | 198 Address start = static_cast<Address>(chunk); |
| 196 size_t size = RoundUp(start, 2 * HEAP->ReservedSemiSpaceSize()) - start; | 199 size_t size = RoundUp(start, 2 * HEAP->ReservedSemiSpaceSize()) - start; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 CHECK(!lo->IsEmpty()); | 245 CHECK(!lo->IsEmpty()); |
| 243 | 246 |
| 244 obj = lo->AllocateRaw(lo_size); | 247 obj = lo->AllocateRaw(lo_size); |
| 245 CHECK(obj->IsFailure()); | 248 CHECK(obj->IsFailure()); |
| 246 | 249 |
| 247 lo->TearDown(); | 250 lo->TearDown(); |
| 248 delete lo; | 251 delete lo; |
| 249 | 252 |
| 250 Isolate::Current()->memory_allocator()->TearDown(); | 253 Isolate::Current()->memory_allocator()->TearDown(); |
| 251 } | 254 } |
| OLD | NEW |