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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 | 153 |
154 void* chunk = | 154 void* chunk = |
155 MemoryAllocator::ReserveInitialChunk(4 * Heap::ReservedSemiSpaceSize()); | 155 MemoryAllocator::ReserveInitialChunk(4 * Heap::ReservedSemiSpaceSize()); |
156 CHECK(chunk != NULL); | 156 CHECK(chunk != NULL); |
157 Address start = RoundUp(static_cast<Address>(chunk), | 157 Address start = RoundUp(static_cast<Address>(chunk), |
158 2 * Heap::ReservedSemiSpaceSize()); | 158 2 * Heap::ReservedSemiSpaceSize()); |
159 CHECK(new_space.Setup(start, 2 * Heap::ReservedSemiSpaceSize())); | 159 CHECK(new_space.Setup(start, 2 * Heap::ReservedSemiSpaceSize())); |
160 CHECK(new_space.HasBeenSetup()); | 160 CHECK(new_space.HasBeenSetup()); |
161 | 161 |
162 while (new_space.Available() >= Page::kMaxHeapObjectSize) { | 162 while (new_space.Available() >= Page::kMaxHeapObjectSize) { |
163 Object* obj = new_space.AllocateRaw(Page::kMaxHeapObjectSize); | 163 Object* obj = |
164 CHECK(!obj->IsFailure()); | 164 new_space.AllocateRaw(Page::kMaxHeapObjectSize)->ToObjectUnchecked(); |
165 CHECK(new_space.Contains(HeapObject::cast(obj))); | 165 CHECK(new_space.Contains(HeapObject::cast(obj))); |
166 } | 166 } |
167 | 167 |
168 new_space.TearDown(); | 168 new_space.TearDown(); |
169 MemoryAllocator::TearDown(); | 169 MemoryAllocator::TearDown(); |
170 } | 170 } |
171 | 171 |
172 | 172 |
173 TEST(OldSpace) { | 173 TEST(OldSpace) { |
174 CHECK(Heap::ConfigureHeapDefault()); | 174 CHECK(Heap::ConfigureHeapDefault()); |
175 CHECK(MemoryAllocator::Setup(Heap::MaxReserved())); | 175 CHECK(MemoryAllocator::Setup(Heap::MaxReserved())); |
176 | 176 |
177 OldSpace* s = new OldSpace(Heap::MaxOldGenerationSize(), | 177 OldSpace* s = new OldSpace(Heap::MaxOldGenerationSize(), |
178 OLD_POINTER_SPACE, | 178 OLD_POINTER_SPACE, |
179 NOT_EXECUTABLE); | 179 NOT_EXECUTABLE); |
180 CHECK(s != NULL); | 180 CHECK(s != NULL); |
181 | 181 |
182 void* chunk = | 182 void* chunk = |
183 MemoryAllocator::ReserveInitialChunk(4 * Heap::ReservedSemiSpaceSize()); | 183 MemoryAllocator::ReserveInitialChunk(4 * Heap::ReservedSemiSpaceSize()); |
184 CHECK(chunk != NULL); | 184 CHECK(chunk != NULL); |
185 Address start = static_cast<Address>(chunk); | 185 Address start = static_cast<Address>(chunk); |
186 size_t size = RoundUp(start, 2 * Heap::ReservedSemiSpaceSize()) - start; | 186 size_t size = RoundUp(start, 2 * Heap::ReservedSemiSpaceSize()) - start; |
187 | 187 |
188 CHECK(s->Setup(start, size)); | 188 CHECK(s->Setup(start, size)); |
189 | 189 |
190 while (s->Available() > 0) { | 190 while (s->Available() > 0) { |
191 Object* obj = s->AllocateRaw(Page::kMaxHeapObjectSize); | 191 s->AllocateRaw(Page::kMaxHeapObjectSize)->ToObjectUnchecked(); |
192 CHECK(!obj->IsFailure()); | |
193 } | 192 } |
194 | 193 |
195 s->TearDown(); | 194 s->TearDown(); |
196 delete s; | 195 delete s; |
197 MemoryAllocator::TearDown(); | 196 MemoryAllocator::TearDown(); |
198 } | 197 } |
199 | 198 |
200 | 199 |
201 TEST(LargeObjectSpace) { | 200 TEST(LargeObjectSpace) { |
202 CHECK(Heap::Setup(false)); | 201 CHECK(Heap::Setup(false)); |
203 | 202 |
204 LargeObjectSpace* lo = Heap::lo_space(); | 203 LargeObjectSpace* lo = Heap::lo_space(); |
205 CHECK(lo != NULL); | 204 CHECK(lo != NULL); |
206 | 205 |
207 Map* faked_map = reinterpret_cast<Map*>(HeapObject::FromAddress(0)); | 206 Map* faked_map = reinterpret_cast<Map*>(HeapObject::FromAddress(0)); |
208 int lo_size = Page::kPageSize; | 207 int lo_size = Page::kPageSize; |
209 | 208 |
210 Object* obj = lo->AllocateRaw(lo_size); | 209 Object* obj = lo->AllocateRaw(lo_size)->ToObjectUnchecked(); |
211 CHECK(!obj->IsFailure()); | |
212 CHECK(obj->IsHeapObject()); | 210 CHECK(obj->IsHeapObject()); |
213 | 211 |
214 HeapObject* ho = HeapObject::cast(obj); | 212 HeapObject* ho = HeapObject::cast(obj); |
215 ho->set_map(faked_map); | 213 ho->set_map(faked_map); |
216 | 214 |
217 CHECK(lo->Contains(HeapObject::cast(obj))); | 215 CHECK(lo->Contains(HeapObject::cast(obj))); |
218 | 216 |
219 CHECK(lo->FindObject(ho->address()) == obj); | 217 CHECK(lo->FindObject(ho->address()) == obj); |
220 | 218 |
221 CHECK(lo->Contains(ho)); | 219 CHECK(lo->Contains(ho)); |
222 | 220 |
223 while (true) { | 221 while (true) { |
224 intptr_t available = lo->Available(); | 222 intptr_t available = lo->Available(); |
225 obj = lo->AllocateRaw(lo_size); | 223 { MaybeObject* maybe_obj = lo->AllocateRaw(lo_size); |
226 if (obj->IsFailure()) break; | 224 if (!maybe_obj->ToObject(&obj)) break; |
| 225 } |
227 HeapObject::cast(obj)->set_map(faked_map); | 226 HeapObject::cast(obj)->set_map(faked_map); |
228 CHECK(lo->Available() < available); | 227 CHECK(lo->Available() < available); |
229 }; | 228 }; |
230 | 229 |
231 CHECK(!lo->IsEmpty()); | 230 CHECK(!lo->IsEmpty()); |
232 | 231 |
233 obj = lo->AllocateRaw(lo_size); | 232 CHECK(lo->AllocateRaw(lo_size)->IsFailure()); |
234 CHECK(obj->IsFailure()); | |
235 | 233 |
236 lo->TearDown(); | 234 lo->TearDown(); |
237 delete lo; | 235 delete lo; |
238 | 236 |
239 MemoryAllocator::TearDown(); | 237 MemoryAllocator::TearDown(); |
240 } | 238 } |
OLD | NEW |