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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 | 200 |
201 | 201 |
202 static unsigned int Pseudorandom() { | 202 static unsigned int Pseudorandom() { |
203 static uint32_t lo = 2345; | 203 static uint32_t lo = 2345; |
204 lo = 18273 * (lo & 0xFFFFF) + (lo >> 16); | 204 lo = 18273 * (lo & 0xFFFFF) + (lo >> 16); |
205 return lo & 0xFFFFF; | 205 return lo & 0xFFFFF; |
206 } | 206 } |
207 | 207 |
208 | 208 |
209 TEST(MemoryChunk) { | 209 TEST(MemoryChunk) { |
210 OS::SetUp(); | |
211 Isolate* isolate = Isolate::Current(); | 210 Isolate* isolate = Isolate::Current(); |
212 isolate->InitializeLoggingAndCounters(); | 211 isolate->InitializeLoggingAndCounters(); |
213 Heap* heap = isolate->heap(); | 212 Heap* heap = isolate->heap(); |
214 CHECK(heap->ConfigureHeapDefault()); | 213 CHECK(heap->ConfigureHeapDefault()); |
215 | 214 |
216 size_t reserve_area_size = 1 * MB; | 215 size_t reserve_area_size = 1 * MB; |
217 size_t initial_commit_area_size, second_commit_area_size; | 216 size_t initial_commit_area_size, second_commit_area_size; |
218 | 217 |
219 for (int i = 0; i < 100; i++) { | 218 for (int i = 0; i < 100; i++) { |
220 initial_commit_area_size = Pseudorandom(); | 219 initial_commit_area_size = Pseudorandom(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 code_range, | 256 code_range, |
258 reserve_area_size, | 257 reserve_area_size, |
259 initial_commit_area_size, | 258 initial_commit_area_size, |
260 second_commit_area_size, | 259 second_commit_area_size, |
261 NOT_EXECUTABLE); | 260 NOT_EXECUTABLE); |
262 } | 261 } |
263 } | 262 } |
264 | 263 |
265 | 264 |
266 TEST(MemoryAllocator) { | 265 TEST(MemoryAllocator) { |
267 OS::SetUp(); | |
268 Isolate* isolate = Isolate::Current(); | 266 Isolate* isolate = Isolate::Current(); |
269 isolate->InitializeLoggingAndCounters(); | 267 isolate->InitializeLoggingAndCounters(); |
270 Heap* heap = isolate->heap(); | 268 Heap* heap = isolate->heap(); |
271 CHECK(isolate->heap()->ConfigureHeapDefault()); | 269 CHECK(isolate->heap()->ConfigureHeapDefault()); |
272 | 270 |
273 MemoryAllocator* memory_allocator = new MemoryAllocator(isolate); | 271 MemoryAllocator* memory_allocator = new MemoryAllocator(isolate); |
274 CHECK(memory_allocator->SetUp(heap->MaxReserved(), | 272 CHECK(memory_allocator->SetUp(heap->MaxReserved(), |
275 heap->MaxExecutableSize())); | 273 heap->MaxExecutableSize())); |
276 | 274 |
277 int total_pages = 0; | 275 int total_pages = 0; |
(...skipping 29 matching lines...) Expand all Loading... |
307 Page* second_page = first_page->next_page(); | 305 Page* second_page = first_page->next_page(); |
308 CHECK(second_page->is_valid()); | 306 CHECK(second_page->is_valid()); |
309 memory_allocator->Free(first_page); | 307 memory_allocator->Free(first_page); |
310 memory_allocator->Free(second_page); | 308 memory_allocator->Free(second_page); |
311 memory_allocator->TearDown(); | 309 memory_allocator->TearDown(); |
312 delete memory_allocator; | 310 delete memory_allocator; |
313 } | 311 } |
314 | 312 |
315 | 313 |
316 TEST(NewSpace) { | 314 TEST(NewSpace) { |
317 OS::SetUp(); | |
318 Isolate* isolate = Isolate::Current(); | 315 Isolate* isolate = Isolate::Current(); |
319 isolate->InitializeLoggingAndCounters(); | 316 isolate->InitializeLoggingAndCounters(); |
320 Heap* heap = isolate->heap(); | 317 Heap* heap = isolate->heap(); |
321 CHECK(heap->ConfigureHeapDefault()); | 318 CHECK(heap->ConfigureHeapDefault()); |
322 MemoryAllocator* memory_allocator = new MemoryAllocator(isolate); | 319 MemoryAllocator* memory_allocator = new MemoryAllocator(isolate); |
323 CHECK(memory_allocator->SetUp(heap->MaxReserved(), | 320 CHECK(memory_allocator->SetUp(heap->MaxReserved(), |
324 heap->MaxExecutableSize())); | 321 heap->MaxExecutableSize())); |
325 TestMemoryAllocatorScope test_scope(isolate, memory_allocator); | 322 TestMemoryAllocatorScope test_scope(isolate, memory_allocator); |
326 | 323 |
327 NewSpace new_space(heap); | 324 NewSpace new_space(heap); |
328 | 325 |
329 CHECK(new_space.SetUp(HEAP->ReservedSemiSpaceSize(), | 326 CHECK(new_space.SetUp(HEAP->ReservedSemiSpaceSize(), |
330 HEAP->ReservedSemiSpaceSize())); | 327 HEAP->ReservedSemiSpaceSize())); |
331 CHECK(new_space.HasBeenSetUp()); | 328 CHECK(new_space.HasBeenSetUp()); |
332 | 329 |
333 while (new_space.Available() >= Page::kMaxNonCodeHeapObjectSize) { | 330 while (new_space.Available() >= Page::kMaxNonCodeHeapObjectSize) { |
334 Object* obj = | 331 Object* obj = |
335 new_space.AllocateRaw(Page::kMaxNonCodeHeapObjectSize)-> | 332 new_space.AllocateRaw(Page::kMaxNonCodeHeapObjectSize)-> |
336 ToObjectUnchecked(); | 333 ToObjectUnchecked(); |
337 CHECK(new_space.Contains(HeapObject::cast(obj))); | 334 CHECK(new_space.Contains(HeapObject::cast(obj))); |
338 } | 335 } |
339 | 336 |
340 new_space.TearDown(); | 337 new_space.TearDown(); |
341 memory_allocator->TearDown(); | 338 memory_allocator->TearDown(); |
342 delete memory_allocator; | 339 delete memory_allocator; |
343 } | 340 } |
344 | 341 |
345 | 342 |
346 TEST(OldSpace) { | 343 TEST(OldSpace) { |
347 OS::SetUp(); | |
348 Isolate* isolate = Isolate::Current(); | 344 Isolate* isolate = Isolate::Current(); |
349 isolate->InitializeLoggingAndCounters(); | 345 isolate->InitializeLoggingAndCounters(); |
350 Heap* heap = isolate->heap(); | 346 Heap* heap = isolate->heap(); |
351 CHECK(heap->ConfigureHeapDefault()); | 347 CHECK(heap->ConfigureHeapDefault()); |
352 MemoryAllocator* memory_allocator = new MemoryAllocator(isolate); | 348 MemoryAllocator* memory_allocator = new MemoryAllocator(isolate); |
353 CHECK(memory_allocator->SetUp(heap->MaxReserved(), | 349 CHECK(memory_allocator->SetUp(heap->MaxReserved(), |
354 heap->MaxExecutableSize())); | 350 heap->MaxExecutableSize())); |
355 TestMemoryAllocatorScope test_scope(isolate, memory_allocator); | 351 TestMemoryAllocatorScope test_scope(isolate, memory_allocator); |
356 | 352 |
357 OldSpace* s = new OldSpace(heap, | 353 OldSpace* s = new OldSpace(heap, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 { MaybeObject* maybe_obj = lo->AllocateRaw(lo_size, NOT_EXECUTABLE); | 393 { MaybeObject* maybe_obj = lo->AllocateRaw(lo_size, NOT_EXECUTABLE); |
398 if (!maybe_obj->ToObject(&obj)) break; | 394 if (!maybe_obj->ToObject(&obj)) break; |
399 } | 395 } |
400 CHECK(lo->Available() < available); | 396 CHECK(lo->Available() < available); |
401 }; | 397 }; |
402 | 398 |
403 CHECK(!lo->IsEmpty()); | 399 CHECK(!lo->IsEmpty()); |
404 | 400 |
405 CHECK(lo->AllocateRaw(lo_size, NOT_EXECUTABLE)->IsFailure()); | 401 CHECK(lo->AllocateRaw(lo_size, NOT_EXECUTABLE)->IsFailure()); |
406 } | 402 } |
OLD | NEW |