| 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 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 } | 388 } |
| 389 } | 389 } |
| 390 } | 390 } |
| 391 } | 391 } |
| 392 #endif | 392 #endif |
| 393 | 393 |
| 394 | 394 |
| 395 void StoreBuffer::Verify() { | 395 void StoreBuffer::Verify() { |
| 396 #ifdef DEBUG | 396 #ifdef DEBUG |
| 397 VerifyPointers(heap_->old_pointer_space(), | 397 VerifyPointers(heap_->old_pointer_space(), |
| 398 &StoreBuffer::FindPointersToNewSpaceInRegionDontRecord); | 398 &StoreBuffer::FindPointersToNewSpaceInRegion); |
| 399 VerifyPointers(heap_->map_space(), | 399 VerifyPointers(heap_->map_space(), |
| 400 &StoreBuffer::FindPointersToNewSpaceInMapsRegion); | 400 &StoreBuffer::FindPointersToNewSpaceInMapsRegion); |
| 401 VerifyPointers(heap_->lo_space()); | 401 VerifyPointers(heap_->lo_space()); |
| 402 #endif | 402 #endif |
| 403 } | 403 } |
| 404 | 404 |
| 405 | 405 |
| 406 void StoreBuffer::GCEpilogue(GCType type, GCCallbackFlags flags) { | 406 void StoreBuffer::GCEpilogue(GCType type, GCCallbackFlags flags) { |
| 407 // TODO(gc) ISOLATES MERGE | 407 // TODO(gc) ISOLATES MERGE |
| 408 HEAP->store_buffer()->during_gc_ = false; | 408 HEAP->store_buffer()->during_gc_ = false; |
| 409 HEAP->store_buffer()->Verify(); | 409 HEAP->store_buffer()->Verify(); |
| 410 } | 410 } |
| 411 | 411 |
| 412 | 412 |
| 413 template<StoreBuffer::RecordNewSpacePointers record> | |
| 414 void StoreBuffer::FindPointersToNewSpaceInRegion( | 413 void StoreBuffer::FindPointersToNewSpaceInRegion( |
| 415 Address start, Address end, ObjectSlotCallback slot_callback) { | 414 Address start, Address end, ObjectSlotCallback slot_callback) { |
| 416 for (Address slot_address = start; | 415 for (Address slot_address = start; |
| 417 slot_address < end; | 416 slot_address < end; |
| 418 slot_address += kPointerSize) { | 417 slot_address += kPointerSize) { |
| 419 Object** slot = reinterpret_cast<Object**>(slot_address); | 418 Object** slot = reinterpret_cast<Object**>(slot_address); |
| 420 if (heap_->InNewSpace(*slot)) { | 419 if (heap_->InNewSpace(*slot)) { |
| 421 HeapObject* object = reinterpret_cast<HeapObject*>(*slot); | 420 HeapObject* object = reinterpret_cast<HeapObject*>(*slot); |
| 422 ASSERT(object->IsHeapObject()); | 421 ASSERT(object->IsHeapObject()); |
| 423 slot_callback(reinterpret_cast<HeapObject**>(slot), object); | 422 slot_callback(reinterpret_cast<HeapObject**>(slot), object); |
| 424 if (record == kRecord) { | 423 if (heap_->InNewSpace(*slot)) { |
| 425 if (heap_->InNewSpace(*slot)) { | 424 EnterDirectlyIntoStoreBuffer(slot_address); |
| 426 EnterDirectlyIntoStoreBuffer(slot_address); | |
| 427 } | |
| 428 } | 425 } |
| 429 } | 426 } |
| 430 } | 427 } |
| 431 } | 428 } |
| 432 | 429 |
| 433 | 430 |
| 434 void StoreBuffer::FindPointersToNewSpaceInRegionRecord( | |
| 435 StoreBuffer* store_buffer, | |
| 436 Address start, | |
| 437 Address end, | |
| 438 ObjectSlotCallback slot_callback) { | |
| 439 store_buffer->FindPointersToNewSpaceInRegion<kRecord>( | |
| 440 start, end, slot_callback); | |
| 441 } | |
| 442 | |
| 443 | |
| 444 void StoreBuffer::FindPointersToNewSpaceInRegionDontRecord( | |
| 445 StoreBuffer* store_buffer, | |
| 446 Address start, | |
| 447 Address end, | |
| 448 ObjectSlotCallback slot_callback) { | |
| 449 store_buffer->FindPointersToNewSpaceInRegion<kDontRecord>( | |
| 450 start, end, slot_callback); | |
| 451 } | |
| 452 | |
| 453 | |
| 454 // Compute start address of the first map following given addr. | 431 // Compute start address of the first map following given addr. |
| 455 static inline Address MapStartAlign(Address addr) { | 432 static inline Address MapStartAlign(Address addr) { |
| 456 Address page = Page::FromAddress(addr)->ObjectAreaStart(); | 433 Address page = Page::FromAddress(addr)->ObjectAreaStart(); |
| 457 return page + (((addr - page) + (Map::kSize - 1)) / Map::kSize * Map::kSize); | 434 return page + (((addr - page) + (Map::kSize - 1)) / Map::kSize * Map::kSize); |
| 458 } | 435 } |
| 459 | 436 |
| 460 | 437 |
| 461 // Compute end address of the first map preceding given addr. | 438 // Compute end address of the first map preceding given addr. |
| 462 static inline Address MapEndAlign(Address addr) { | 439 static inline Address MapEndAlign(Address addr) { |
| 463 Address page = Page::FromAllocationTop(addr)->ObjectAreaStart(); | 440 Address page = Page::FromAllocationTop(addr)->ObjectAreaStart(); |
| 464 return page + ((addr - page) / Map::kSize * Map::kSize); | 441 return page + ((addr - page) / Map::kSize * Map::kSize); |
| 465 } | 442 } |
| 466 | 443 |
| 467 | 444 |
| 468 void StoreBuffer::FindPointersToNewSpaceInMaps( | 445 void StoreBuffer::FindPointersToNewSpaceInMaps( |
| 469 Address start, | 446 Address start, |
| 470 Address end, | 447 Address end, |
| 471 ObjectSlotCallback slot_callback) { | 448 ObjectSlotCallback slot_callback) { |
| 472 ASSERT(MapStartAlign(start) == start); | 449 ASSERT(MapStartAlign(start) == start); |
| 473 ASSERT(MapEndAlign(end) == end); | 450 ASSERT(MapEndAlign(end) == end); |
| 474 | 451 |
| 475 Address map_address = start; | 452 Address map_address = start; |
| 476 while (map_address < end) { | 453 while (map_address < end) { |
| 477 ASSERT(!heap_->InNewSpace(Memory::Object_at(map_address))); | 454 ASSERT(!heap_->InNewSpace(Memory::Object_at(map_address))); |
| 478 ASSERT(Memory::Object_at(map_address)->IsMap()); | 455 ASSERT(Memory::Object_at(map_address)->IsMap()); |
| 479 | 456 |
| 480 Address pointer_fields_start = map_address + Map::kPointerFieldsBeginOffset; | 457 Address pointer_fields_start = map_address + Map::kPointerFieldsBeginOffset; |
| 481 Address pointer_fields_end = map_address + Map::kPointerFieldsEndOffset; | 458 Address pointer_fields_end = map_address + Map::kPointerFieldsEndOffset; |
| 482 | 459 |
| 483 FindPointersToNewSpaceInRegion<kRecord>(pointer_fields_start, | 460 FindPointersToNewSpaceInRegion(pointer_fields_start, |
| 484 pointer_fields_end, | 461 pointer_fields_end, |
| 485 slot_callback); | 462 slot_callback); |
| 486 map_address += Map::kSize; | 463 map_address += Map::kSize; |
| 487 } | 464 } |
| 488 } | 465 } |
| 489 | 466 |
| 490 | 467 |
| 491 void StoreBuffer::FindPointersToNewSpaceInMapsRegion( | 468 void StoreBuffer::FindPointersToNewSpaceInMapsRegion( |
| 492 StoreBuffer* store_buffer, | |
| 493 Address start, | 469 Address start, |
| 494 Address end, | 470 Address end, |
| 495 ObjectSlotCallback slot_callback) { | 471 ObjectSlotCallback slot_callback) { |
| 496 Address map_aligned_start = MapStartAlign(start); | 472 Address map_aligned_start = MapStartAlign(start); |
| 497 Address map_aligned_end = MapEndAlign(end); | 473 Address map_aligned_end = MapEndAlign(end); |
| 498 | 474 |
| 499 ASSERT(map_aligned_start == start); | 475 ASSERT(map_aligned_start == start); |
| 500 ASSERT(map_aligned_end == end); | 476 ASSERT(map_aligned_end == end); |
| 501 | 477 |
| 502 store_buffer->FindPointersToNewSpaceInMaps(map_aligned_start, | 478 FindPointersToNewSpaceInMaps(map_aligned_start, |
| 503 map_aligned_end, | 479 map_aligned_end, |
| 504 slot_callback); | 480 slot_callback); |
| 505 } | 481 } |
| 506 | 482 |
| 507 | 483 |
| 508 // This function iterates over all the pointers in a paged space in the heap, | 484 // This function iterates over all the pointers in a paged space in the heap, |
| 509 // looking for pointers into new space. Within the pages there may be dead | 485 // looking for pointers into new space. Within the pages there may be dead |
| 510 // objects that have not been overwritten by free spaces or fillers because of | 486 // objects that have not been overwritten by free spaces or fillers because of |
| 511 // lazy sweeping. These dead objects may not contain pointers to new space. | 487 // lazy sweeping. These dead objects may not contain pointers to new space. |
| 512 // The garbage areas that have been swept properly (these will normally be the | 488 // The garbage areas that have been swept properly (these will normally be the |
| 513 // large ones) will be marked with free space and filler map words. In | 489 // large ones) will be marked with free space and filler map words. In |
| 514 // addition any area that has never been used at all for object allocation must | 490 // addition any area that has never been used at all for object allocation must |
| (...skipping 19 matching lines...) Expand all Loading... |
| 534 | 510 |
| 535 while (visitable_end < end_of_page) { | 511 while (visitable_end < end_of_page) { |
| 536 Object* o = *reinterpret_cast<Object**>(visitable_end); | 512 Object* o = *reinterpret_cast<Object**>(visitable_end); |
| 537 // Skip fillers but not things that look like fillers in the special | 513 // Skip fillers but not things that look like fillers in the special |
| 538 // garbage section which can contain anything. | 514 // garbage section which can contain anything. |
| 539 if (o == free_space_map || | 515 if (o == free_space_map || |
| 540 o == two_pointer_filler_map || | 516 o == two_pointer_filler_map || |
| 541 visitable_end == space->top()) { | 517 visitable_end == space->top()) { |
| 542 if (visitable_start != visitable_end) { | 518 if (visitable_start != visitable_end) { |
| 543 // After calling this the special garbage section may have moved. | 519 // After calling this the special garbage section may have moved. |
| 544 (*region_callback)(this, | 520 (this->*region_callback)(visitable_start, |
| 545 visitable_start, | 521 visitable_end, |
| 546 visitable_end, | 522 slot_callback); |
| 547 slot_callback); | |
| 548 if (visitable_end >= space->top() && visitable_end < space->limit()) { | 523 if (visitable_end >= space->top() && visitable_end < space->limit()) { |
| 549 visitable_end = space->limit(); | 524 visitable_end = space->limit(); |
| 550 visitable_start = visitable_end; | 525 visitable_start = visitable_end; |
| 551 continue; | 526 continue; |
| 552 } | 527 } |
| 553 } | 528 } |
| 554 if (visitable_end == space->top() && visitable_end != space->limit()) { | 529 if (visitable_end == space->top() && visitable_end != space->limit()) { |
| 555 visitable_start = visitable_end = space->limit(); | 530 visitable_start = visitable_end = space->limit(); |
| 556 } else { | 531 } else { |
| 557 // At this point we are either at the start of a filler or we are at | 532 // At this point we are either at the start of a filler or we are at |
| 558 // the point where the space->top() used to be before the | 533 // the point where the space->top() used to be before the |
| 559 // visit_pointer_region call above. Either way we can skip the | 534 // visit_pointer_region call above. Either way we can skip the |
| 560 // object at the current spot: We don't promise to visit objects | 535 // object at the current spot: We don't promise to visit objects |
| 561 // allocated during heap traversal, and if space->top() moved then it | 536 // allocated during heap traversal, and if space->top() moved then it |
| 562 // must be because an object was allocated at this point. | 537 // must be because an object was allocated at this point. |
| 563 visitable_start = | 538 visitable_start = |
| 564 visitable_end + HeapObject::FromAddress(visitable_end)->Size(); | 539 visitable_end + HeapObject::FromAddress(visitable_end)->Size(); |
| 565 visitable_end = visitable_start; | 540 visitable_end = visitable_start; |
| 566 } | 541 } |
| 567 } else { | 542 } else { |
| 568 ASSERT(o != free_space_map); | 543 ASSERT(o != free_space_map); |
| 569 ASSERT(o != two_pointer_filler_map); | 544 ASSERT(o != two_pointer_filler_map); |
| 570 ASSERT(visitable_end < space->top() || visitable_end >= space->limit()); | 545 ASSERT(visitable_end < space->top() || visitable_end >= space->limit()); |
| 571 visitable_end += kPointerSize; | 546 visitable_end += kPointerSize; |
| 572 } | 547 } |
| 573 } | 548 } |
| 574 ASSERT(visitable_end == end_of_page); | 549 ASSERT(visitable_end == end_of_page); |
| 575 if (visitable_start != visitable_end) { | 550 if (visitable_start != visitable_end) { |
| 576 (*region_callback)(this, | 551 (this->*region_callback)(visitable_start, |
| 577 visitable_start, | 552 visitable_end, |
| 578 visitable_end, | 553 slot_callback); |
| 579 slot_callback); | |
| 580 } | 554 } |
| 581 } | 555 } |
| 582 | 556 |
| 583 | 557 |
| 584 void StoreBuffer::IteratePointersInStoreBuffer( | 558 void StoreBuffer::IteratePointersInStoreBuffer( |
| 585 ObjectSlotCallback slot_callback) { | 559 ObjectSlotCallback slot_callback) { |
| 586 Address* limit = old_top_; | 560 Address* limit = old_top_; |
| 587 old_top_ = old_start_; | 561 old_top_ = old_start_; |
| 588 { | 562 { |
| 589 DontMoveStoreBufferEntriesScope scope(this); | 563 DontMoveStoreBufferEntriesScope scope(this); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 chunk->set_scan_on_scavenge(false); | 611 chunk->set_scan_on_scavenge(false); |
| 638 if (callback_ != NULL) { | 612 if (callback_ != NULL) { |
| 639 (*callback_)(heap_, chunk, kStoreBufferScanningPageEvent); | 613 (*callback_)(heap_, chunk, kStoreBufferScanningPageEvent); |
| 640 } | 614 } |
| 641 if (chunk->owner() == heap_->lo_space()) { | 615 if (chunk->owner() == heap_->lo_space()) { |
| 642 LargePage* large_page = reinterpret_cast<LargePage*>(chunk); | 616 LargePage* large_page = reinterpret_cast<LargePage*>(chunk); |
| 643 HeapObject* array = large_page->GetObject(); | 617 HeapObject* array = large_page->GetObject(); |
| 644 ASSERT(array->IsFixedArray()); | 618 ASSERT(array->IsFixedArray()); |
| 645 Address start = array->address(); | 619 Address start = array->address(); |
| 646 Address end = start + array->Size(); | 620 Address end = start + array->Size(); |
| 647 const int kLump = 10000; | 621 FindPointersToNewSpaceInRegion(start, end, slot_callback); |
| 648 for (Address current = start; current < end; current += kLump) { | |
| 649 if (chunk->scan_on_scavenge()) { | |
| 650 FindPointersToNewSpaceInRegion<kDontRecord>( | |
| 651 current, | |
| 652 Min(end, current + kLump), | |
| 653 slot_callback); | |
| 654 } else { | |
| 655 FindPointersToNewSpaceInRegion<kRecord>( | |
| 656 current, | |
| 657 Min(end, current + kLump), | |
| 658 slot_callback); | |
| 659 } | |
| 660 } | |
| 661 } else { | 622 } else { |
| 662 Page* page = reinterpret_cast<Page*>(chunk); | 623 Page* page = reinterpret_cast<Page*>(chunk); |
| 663 PagedSpace* owner = reinterpret_cast<PagedSpace*>(page->owner()); | 624 PagedSpace* owner = reinterpret_cast<PagedSpace*>(page->owner()); |
| 664 FindPointersToNewSpaceOnPage( | 625 FindPointersToNewSpaceOnPage( |
| 665 owner, | 626 owner, |
| 666 page, | 627 page, |
| 667 (owner == heap_->map_space() ? | 628 (owner == heap_->map_space() ? |
| 668 &StoreBuffer::FindPointersToNewSpaceInMapsRegion : | 629 &StoreBuffer::FindPointersToNewSpaceInMapsRegion : |
| 669 &StoreBuffer::FindPointersToNewSpaceInRegionRecord), | 630 &StoreBuffer::FindPointersToNewSpaceInRegion), |
| 670 slot_callback); | 631 slot_callback); |
| 671 } | 632 } |
| 672 } | 633 } |
| 673 } | 634 } |
| 674 (*callback_)(heap_, NULL, kStoreBufferScanningPageEvent); | 635 (*callback_)(heap_, NULL, kStoreBufferScanningPageEvent); |
| 675 } | 636 } |
| 676 } | 637 } |
| 677 | 638 |
| 678 | 639 |
| 679 void StoreBuffer::Compact() { | 640 void StoreBuffer::Compact() { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 } | 688 } |
| 728 | 689 |
| 729 | 690 |
| 730 void StoreBuffer::CheckForFullBuffer() { | 691 void StoreBuffer::CheckForFullBuffer() { |
| 731 if (old_limit_ - old_top_ < kStoreBufferSize * 2) { | 692 if (old_limit_ - old_top_ < kStoreBufferSize * 2) { |
| 732 HandleFullness(); | 693 HandleFullness(); |
| 733 } | 694 } |
| 734 } | 695 } |
| 735 | 696 |
| 736 } } // namespace v8::internal | 697 } } // namespace v8::internal |
| OLD | NEW |