OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 4311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4322 Handle<JSObject> o = | 4322 Handle<JSObject> o = |
4323 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(result)); | 4323 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(result)); |
4324 CHECK(heap->InOldPointerSpace(o->elements())); | 4324 CHECK(heap->InOldPointerSpace(o->elements())); |
4325 CHECK(heap->InOldPointerSpace(*o)); | 4325 CHECK(heap->InOldPointerSpace(*o)); |
4326 Page* page = Page::FromAddress(o->elements()->address()); | 4326 Page* page = Page::FromAddress(o->elements()->address()); |
4327 CHECK(page->WasSwept() || | 4327 CHECK(page->WasSwept() || |
4328 Marking::IsBlack(Marking::MarkBitFrom(o->elements()))); | 4328 Marking::IsBlack(Marking::MarkBitFrom(o->elements()))); |
4329 } | 4329 } |
4330 | 4330 |
4331 | 4331 |
| 4332 TEST(PromotionQueue) { |
| 4333 i::FLAG_expose_gc = true; |
| 4334 i::FLAG_max_semi_space_size = 2; |
| 4335 CcTest::InitializeVM(); |
| 4336 v8::HandleScope scope(CcTest::isolate()); |
| 4337 Isolate* isolate = CcTest::i_isolate(); |
| 4338 Heap* heap = isolate->heap(); |
| 4339 NewSpace* new_space = heap->new_space(); |
| 4340 |
| 4341 // In this test we will try to overwrite the promotion queue which is at the |
| 4342 // end of to-space. To actually make that possible, we need at least two |
| 4343 // semi-space pages and take advantage of fragementation. |
| 4344 // (1) Grow semi-space to two pages. |
| 4345 // (2) Create a few small long living objects and call the scavenger to |
| 4346 // move them to the other semi-space. |
| 4347 // (3) Create a huge object, i.e., remainder of first semi-space page and |
| 4348 // create another huge object which should be of maximum allocatable memory |
| 4349 // size of the second semi-space page. |
| 4350 // (4) Call the scavenger again. |
| 4351 // What will happen is: the scavenger will promote the objects created in (2) |
| 4352 // and will create promotion queue entries at the end of the second |
| 4353 // semi-space page during the next scavenge when it promotes the objects to |
| 4354 // the old generation. The first allocation of (3) will fill up the first |
| 4355 // semi-space page. The second allocation in (3) will not fit into the first |
| 4356 // semi-space page, but it will overwrite the promotion queue which are in |
| 4357 // the second semi-space page. If the right guards are in place, the promotion |
| 4358 // queue will be evacuated in that case. |
| 4359 |
| 4360 // Grow the semi-space to two pages to make semi-space copy overwrite the |
| 4361 // promotion queue, which will be at the end of the second page. |
| 4362 intptr_t old_capacity = new_space->Capacity(); |
| 4363 new_space->Grow(); |
| 4364 CHECK(new_space->IsAtMaximumCapacity()); |
| 4365 CHECK(2 * old_capacity == new_space->Capacity()); |
| 4366 |
| 4367 // Call the scavenger two times to get an empty new space |
| 4368 heap->CollectGarbage(NEW_SPACE); |
| 4369 heap->CollectGarbage(NEW_SPACE); |
| 4370 |
| 4371 // First create a few objects which will survive a scavenge, and will get |
| 4372 // promoted to the old generation later on. These objects will create |
| 4373 // promotion queue entries at the end of the second semi-space page. |
| 4374 const int number_handles = 12; |
| 4375 Handle<FixedArray> handles[number_handles]; |
| 4376 for (int i = 0; i < number_handles; i++) { |
| 4377 handles[i] = isolate->factory()->NewFixedArray(1, NOT_TENURED); |
| 4378 } |
| 4379 heap->CollectGarbage(NEW_SPACE); |
| 4380 |
| 4381 // Create the first huge object which will exactly fit the first semi-space |
| 4382 // page. |
| 4383 int new_linear_size = static_cast<int>( |
| 4384 *heap->new_space()->allocation_limit_address() - |
| 4385 *heap->new_space()->allocation_top_address()); |
| 4386 int length = new_linear_size / kPointerSize - FixedArray::kHeaderSize; |
| 4387 Handle<FixedArray> first = |
| 4388 isolate->factory()->NewFixedArray(length, NOT_TENURED); |
| 4389 CHECK(heap->InNewSpace(*first)); |
| 4390 |
| 4391 // Create the second huge object of maximum allocatable second semi-space |
| 4392 // page size. |
| 4393 new_linear_size = static_cast<int>( |
| 4394 *heap->new_space()->allocation_limit_address() - |
| 4395 *heap->new_space()->allocation_top_address()); |
| 4396 length = Page::kMaxRegularHeapObjectSize / kPointerSize - |
| 4397 FixedArray::kHeaderSize; |
| 4398 Handle<FixedArray> second = |
| 4399 isolate->factory()->NewFixedArray(length, NOT_TENURED); |
| 4400 CHECK(heap->InNewSpace(*second)); |
| 4401 |
| 4402 // This scavenge will corrupt memory if the promotion queue is not evacuated. |
| 4403 heap->CollectGarbage(NEW_SPACE); |
| 4404 } |
| 4405 |
| 4406 |
4332 #ifdef DEBUG | 4407 #ifdef DEBUG |
4333 TEST(PathTracer) { | 4408 TEST(PathTracer) { |
4334 CcTest::InitializeVM(); | 4409 CcTest::InitializeVM(); |
4335 v8::HandleScope scope(CcTest::isolate()); | 4410 v8::HandleScope scope(CcTest::isolate()); |
4336 | 4411 |
4337 v8::Local<v8::Value> result = CompileRun("'abc'"); | 4412 v8::Local<v8::Value> result = CompileRun("'abc'"); |
4338 Handle<Object> o = v8::Utils::OpenHandle(*result); | 4413 Handle<Object> o = v8::Utils::OpenHandle(*result); |
4339 CcTest::i_isolate()->heap()->TracePathToObject(*o); | 4414 CcTest::i_isolate()->heap()->TracePathToObject(*o); |
4340 } | 4415 } |
4341 #endif // DEBUG | 4416 #endif // DEBUG |
OLD | NEW |