Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_HEAP_HEAP_INL_H_ | 5 #ifndef V8_HEAP_HEAP_INL_H_ |
| 6 #define V8_HEAP_HEAP_INL_H_ | 6 #define V8_HEAP_HEAP_INL_H_ |
| 7 | 7 |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 461 | 461 |
| 462 while (src_slot != end_slot) { | 462 while (src_slot != end_slot) { |
| 463 *dst_slot++ = *src_slot++; | 463 *dst_slot++ = *src_slot++; |
| 464 } | 464 } |
| 465 } else { | 465 } else { |
| 466 MemMove(dst, src, static_cast<size_t>(byte_size)); | 466 MemMove(dst, src, static_cast<size_t>(byte_size)); |
| 467 } | 467 } |
| 468 } | 468 } |
| 469 | 469 |
| 470 | 470 |
| 471 AllocationMemento* Heap::FindAllocationMemento(HeapObject* object) { | 471 AllocationMemento* Heap::FindAllocationMemento(HeapObject* object) { |
|
Hannes Payer (out of office)
2016/01/18 11:46:33
As discussed offline:
There was a reason why there
Michael Lippautz
2016/01/19 14:56:52
Done.
| |
| 472 AllocationMemento* memento_candidate = FindAllocationMementoCandidate(object); | |
| 473 if (memento_candidate == nullptr) return nullptr; | |
| 474 // Either the object is the last object in the new space, or there is another | |
| 475 // object of at least word size (the header map word) following it, so | |
| 476 // suffices to compare ptr and top here. Note that technically we do not have | |
| 477 // to compare with the current top pointer of the from space page during GC, | |
| 478 // since we always install filler objects above the top pointer of a from | |
| 479 // space page when performing a garbage collection. However, always performing | |
| 480 // the test makes it possible to have a single, unified version of | |
| 481 // FindAllocationMemento that is used both by the GC and the mutator. | |
| 482 Address top = NewSpaceTop(); | |
| 483 Address memento_address = memento_candidate->address(); | |
| 484 DCHECK(memento_address == top || | |
| 485 memento_address + HeapObject::kHeaderSize <= top || | |
| 486 !NewSpacePage::OnSamePage(memento_address, top - 1)); | |
| 487 if (memento_address == top) { | |
| 488 return nullptr; | |
| 489 } | |
| 490 if (memento_candidate->IsValid()) { | |
| 491 return memento_candidate; | |
| 492 } | |
| 493 | |
| 494 return nullptr; | |
| 495 } | |
| 496 | |
| 497 | |
| 498 AllocationMemento* Heap::FindAllocationMementoCandidate(HeapObject* object) { | |
| 472 // Check if there is potentially a memento behind the object. If | 499 // Check if there is potentially a memento behind the object. If |
| 473 // the last word of the memento is on another page we return | 500 // the last word of the memento is on another page we return |
| 474 // immediately. | 501 // immediately. |
| 475 Address object_address = object->address(); | 502 Address object_address = object->address(); |
| 476 Address memento_address = object_address + object->Size(); | 503 Address memento_address = object_address + object->Size(); |
| 477 Address last_memento_word_address = memento_address + kPointerSize; | 504 Address last_memento_word_address = memento_address + kPointerSize; |
| 478 if (!NewSpacePage::OnSamePage(object_address, last_memento_word_address)) { | 505 if (!NewSpacePage::OnSamePage(object_address, last_memento_word_address)) { |
| 479 return NULL; | 506 return nullptr; |
| 480 } | 507 } |
| 481 | |
| 482 HeapObject* candidate = HeapObject::FromAddress(memento_address); | 508 HeapObject* candidate = HeapObject::FromAddress(memento_address); |
| 483 Map* candidate_map = candidate->map(); | 509 Map* candidate_map = candidate->map(); |
| 484 // This fast check may peek at an uninitialized word. However, the slow check | 510 // This fast check may peek at an uninitialized word. However, the slow check |
| 485 // below (memento_address == top) ensures that this is safe. Mark the word as | 511 // below (memento_address == top) ensures that this is safe. Mark the word as |
| 486 // initialized to silence MemorySanitizer warnings. | 512 // initialized to silence MemorySanitizer warnings. |
| 487 MSAN_MEMORY_IS_INITIALIZED(&candidate_map, sizeof(candidate_map)); | 513 MSAN_MEMORY_IS_INITIALIZED(&candidate_map, sizeof(candidate_map)); |
| 488 if (candidate_map != allocation_memento_map()) return NULL; | 514 if (candidate_map != allocation_memento_map()) { |
| 489 | 515 return nullptr; |
| 490 // Either the object is the last object in the new space, or there is another | 516 } |
| 491 // object of at least word size (the header map word) following it, so | 517 return AllocationMemento::cast(candidate); |
| 492 // suffices to compare ptr and top here. Note that technically we do not have | |
| 493 // to compare with the current top pointer of the from space page during GC, | |
| 494 // since we always install filler objects above the top pointer of a from | |
| 495 // space page when performing a garbage collection. However, always performing | |
| 496 // the test makes it possible to have a single, unified version of | |
| 497 // FindAllocationMemento that is used both by the GC and the mutator. | |
| 498 Address top = NewSpaceTop(); | |
| 499 DCHECK(memento_address == top || | |
| 500 memento_address + HeapObject::kHeaderSize <= top || | |
| 501 !NewSpacePage::OnSamePage(memento_address, top - 1)); | |
| 502 if (memento_address == top) return NULL; | |
| 503 | |
| 504 AllocationMemento* memento = AllocationMemento::cast(candidate); | |
| 505 if (!memento->IsValid()) return NULL; | |
| 506 return memento; | |
| 507 } | 518 } |
| 508 | 519 |
| 509 | 520 |
| 510 void Heap::UpdateAllocationSite(HeapObject* object, | 521 void Heap::UpdateAllocationSite(HeapObject* object, |
| 511 HashMap* pretenuring_feedback) { | 522 HashMap* pretenuring_feedback) { |
| 512 DCHECK(InFromSpace(object)); | 523 DCHECK(InFromSpace(object)); |
| 513 if (!FLAG_allocation_site_pretenuring || | 524 if (!FLAG_allocation_site_pretenuring || |
| 514 !AllocationSite::CanTrack(object->map()->instance_type())) | 525 !AllocationSite::CanTrack(object->map()->instance_type())) |
| 515 return; | 526 return; |
| 516 AllocationMemento* memento = FindAllocationMemento(object); | 527 AllocationMemento* memento_candidate = FindAllocationMementoCandidate(object); |
| 517 if (memento == nullptr) return; | 528 if (memento_candidate == nullptr) return; |
| 518 | |
| 519 AllocationSite* key = memento->GetAllocationSite(); | |
| 520 DCHECK(!key->IsZombie()); | |
| 521 | 529 |
| 522 if (pretenuring_feedback == global_pretenuring_feedback_) { | 530 if (pretenuring_feedback == global_pretenuring_feedback_) { |
| 531 // Entering global pretenuring feedback is only used in the scavenger, where | |
| 532 // we are allowed to actually touch the allocation site. | |
| 533 if (!memento_candidate->IsValid()) return; | |
| 534 AllocationSite* site = memento_candidate->GetAllocationSite(); | |
| 535 DCHECK(!site->IsZombie()); | |
| 523 // For inserting in the global pretenuring storage we need to first | 536 // For inserting in the global pretenuring storage we need to first |
| 524 // increment the memento found count on the allocation site. | 537 // increment the memento found count on the allocation site. |
| 525 if (key->IncrementMementoFoundCount()) { | 538 if (site->IncrementMementoFoundCount()) { |
| 526 global_pretenuring_feedback_->LookupOrInsert( | 539 global_pretenuring_feedback_->LookupOrInsert( |
| 527 key, static_cast<uint32_t>(bit_cast<uintptr_t>(key))); | 540 site, static_cast<uint32_t>(bit_cast<uintptr_t>(site) >> 3)); |
| 528 } | 541 } |
| 529 } else { | 542 } else { |
| 530 // Any other pretenuring storage than the global one is used as a cache, | 543 // Entering cached feedback is used in the parallel case. We are not allowed |
| 531 // where the count is later on merge in the allocation site. | 544 // to dereference the allocation site and rather have to postpone all checks |
| 545 // till actually merging the data. | |
|
Hannes Payer (out of office)
2016/01/18 11:46:33
We could add a similar DCHECK as above:
low-level
Michael Lippautz
2016/01/19 14:56:52
I would like to avoid touching the address here. T
| |
| 546 Address key = memento_candidate->GetAllocationSiteUnchecked(); | |
| 532 HashMap::Entry* e = pretenuring_feedback->LookupOrInsert( | 547 HashMap::Entry* e = pretenuring_feedback->LookupOrInsert( |
| 533 key, static_cast<uint32_t>(bit_cast<uintptr_t>(key))); | 548 key, static_cast<uint32_t>(bit_cast<uintptr_t>(key) >> 3)); |
| 534 DCHECK(e != nullptr); | 549 DCHECK(e != nullptr); |
| 535 (*bit_cast<intptr_t*>(&e->value))++; | 550 (*bit_cast<intptr_t*>(&e->value))++; |
| 536 } | 551 } |
| 537 } | 552 } |
| 538 | 553 |
| 539 | 554 |
| 540 void Heap::RemoveAllocationSitePretenuringFeedback(AllocationSite* site) { | 555 void Heap::RemoveAllocationSitePretenuringFeedback(AllocationSite* site) { |
| 541 global_pretenuring_feedback_->Remove( | 556 global_pretenuring_feedback_->Remove( |
| 542 site, static_cast<uint32_t>(bit_cast<uintptr_t>(site))); | 557 site, static_cast<uint32_t>(bit_cast<uintptr_t>(site))); |
| 543 } | 558 } |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 719 | 734 |
| 720 void VerifySmisVisitor::VisitPointers(Object** start, Object** end) { | 735 void VerifySmisVisitor::VisitPointers(Object** start, Object** end) { |
| 721 for (Object** current = start; current < end; current++) { | 736 for (Object** current = start; current < end; current++) { |
| 722 CHECK((*current)->IsSmi()); | 737 CHECK((*current)->IsSmi()); |
| 723 } | 738 } |
| 724 } | 739 } |
| 725 } // namespace internal | 740 } // namespace internal |
| 726 } // namespace v8 | 741 } // namespace v8 |
| 727 | 742 |
| 728 #endif // V8_HEAP_HEAP_INL_H_ | 743 #endif // V8_HEAP_HEAP_INL_H_ |
| OLD | NEW |