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 template <Heap::FindMementoMode mode> | |
471 AllocationMemento* Heap::FindAllocationMemento(HeapObject* object) { | 472 AllocationMemento* Heap::FindAllocationMemento(HeapObject* object) { |
472 // Check if there is potentially a memento behind the object. If | 473 // Check if there is potentially a memento behind the object. If |
473 // the last word of the memento is on another page we return | 474 // the last word of the memento is on another page we return |
474 // immediately. | 475 // immediately. |
475 Address object_address = object->address(); | 476 Address object_address = object->address(); |
476 Address memento_address = object_address + object->Size(); | 477 Address memento_address = object_address + object->Size(); |
477 Address last_memento_word_address = memento_address + kPointerSize; | 478 Address last_memento_word_address = memento_address + kPointerSize; |
478 if (!NewSpacePage::OnSamePage(object_address, last_memento_word_address)) { | 479 if (!NewSpacePage::OnSamePage(object_address, last_memento_word_address)) { |
479 return NULL; | 480 return nullptr; |
480 } | 481 } |
481 | |
482 HeapObject* candidate = HeapObject::FromAddress(memento_address); | 482 HeapObject* candidate = HeapObject::FromAddress(memento_address); |
483 Map* candidate_map = candidate->map(); | 483 Map* candidate_map = candidate->map(); |
484 // This fast check may peek at an uninitialized word. However, the slow check | 484 // 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 | 485 // below (memento_address == top) ensures that this is safe. Mark the word as |
486 // initialized to silence MemorySanitizer warnings. | 486 // initialized to silence MemorySanitizer warnings. |
487 MSAN_MEMORY_IS_INITIALIZED(&candidate_map, sizeof(candidate_map)); | 487 MSAN_MEMORY_IS_INITIALIZED(&candidate_map, sizeof(candidate_map)); |
488 if (candidate_map != allocation_memento_map()) return NULL; | 488 if (candidate_map != allocation_memento_map()) { |
489 return nullptr; | |
490 } | |
491 AllocationMemento* memento_candidate = AllocationMemento::cast(candidate); | |
489 | 492 |
490 // Either the object is the last object in the new space, or there is another | 493 // Depending on what the memento is used for, we might need to perform |
491 // object of at least word size (the header map word) following it, so | 494 // additional checks. |
492 // suffices to compare ptr and top here. Note that technically we do not have | 495 Address top; |
493 // to compare with the current top pointer of the from space page during GC, | 496 switch (mode) { |
494 // since we always install filler objects above the top pointer of a from | 497 case Heap::kForGC: |
495 // space page when performing a garbage collection. However, always performing | 498 return memento_candidate; |
496 // the test makes it possible to have a single, unified version of | 499 case Heap::kForRuntime: |
497 // FindAllocationMemento that is used both by the GC and the mutator. | 500 if (memento_candidate == nullptr) return nullptr; |
498 Address top = NewSpaceTop(); | 501 // Either the object is the last object in the new space, or there is |
499 DCHECK(memento_address == top || | 502 // another object of at least word size (the header map word) following |
500 memento_address + HeapObject::kHeaderSize <= top || | 503 // it, so suffices to compare ptr and top here. |
501 !NewSpacePage::OnSamePage(memento_address, top - 1)); | 504 top = NewSpaceTop(); |
502 if (memento_address == top) return NULL; | 505 DCHECK(memento_address == top || |
503 | 506 memento_address + HeapObject::kHeaderSize <= top || |
504 AllocationMemento* memento = AllocationMemento::cast(candidate); | 507 !NewSpacePage::OnSamePage(memento_address, top - 1)); |
505 if (!memento->IsValid()) return NULL; | 508 if ((memento_address != top) && memento_candidate->IsValid()) { |
506 return memento; | 509 return memento_candidate; |
510 } | |
511 return nullptr; | |
512 default: | |
513 UNREACHABLE(); | |
514 } | |
515 UNREACHABLE(); | |
516 return nullptr; | |
507 } | 517 } |
508 | 518 |
509 | 519 |
520 uint32_t Heap::ObjectHash(Address address) { | |
Hannes Payer (out of office)
2016/01/25 16:04:13
What about moving this function into globals.h? It
Michael Lippautz
2016/01/25 16:26:14
Done.
| |
521 // All objects are at least pointer aligned, so we can remove the trailing | |
522 // zeros. | |
523 return static_cast<uint32_t>(bit_cast<uintptr_t>(address) >> | |
524 kPointerSizeLog2); | |
525 } | |
526 | |
527 | |
510 void Heap::UpdateAllocationSite(HeapObject* object, | 528 void Heap::UpdateAllocationSite(HeapObject* object, |
511 HashMap* pretenuring_feedback) { | 529 HashMap* pretenuring_feedback) { |
512 DCHECK(InFromSpace(object)); | 530 DCHECK(InFromSpace(object)); |
513 if (!FLAG_allocation_site_pretenuring || | 531 if (!FLAG_allocation_site_pretenuring || |
514 !AllocationSite::CanTrack(object->map()->instance_type())) | 532 !AllocationSite::CanTrack(object->map()->instance_type())) |
515 return; | 533 return; |
516 AllocationMemento* memento = FindAllocationMemento(object); | 534 AllocationMemento* memento_candidate = FindAllocationMemento<kForGC>(object); |
517 if (memento == nullptr) return; | 535 if (memento_candidate == nullptr) return; |
518 | |
519 AllocationSite* key = memento->GetAllocationSite(); | |
520 DCHECK(!key->IsZombie()); | |
521 | 536 |
522 if (pretenuring_feedback == global_pretenuring_feedback_) { | 537 if (pretenuring_feedback == global_pretenuring_feedback_) { |
538 // Entering global pretenuring feedback is only used in the scavenger, where | |
539 // we are allowed to actually touch the allocation site. | |
540 if (!memento_candidate->IsValid()) return; | |
541 AllocationSite* site = memento_candidate->GetAllocationSite(); | |
542 DCHECK(!site->IsZombie()); | |
523 // For inserting in the global pretenuring storage we need to first | 543 // For inserting in the global pretenuring storage we need to first |
524 // increment the memento found count on the allocation site. | 544 // increment the memento found count on the allocation site. |
525 if (key->IncrementMementoFoundCount()) { | 545 if (site->IncrementMementoFoundCount()) { |
526 global_pretenuring_feedback_->LookupOrInsert( | 546 global_pretenuring_feedback_->LookupOrInsert(site, |
527 key, static_cast<uint32_t>(bit_cast<uintptr_t>(key))); | 547 ObjectHash(site->address())); |
528 } | 548 } |
529 } else { | 549 } else { |
530 // Any other pretenuring storage than the global one is used as a cache, | 550 // 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. | 551 // to dereference the allocation site and rather have to postpone all checks |
532 HashMap::Entry* e = pretenuring_feedback->LookupOrInsert( | 552 // till actually merging the data. |
533 key, static_cast<uint32_t>(bit_cast<uintptr_t>(key))); | 553 Address key = memento_candidate->GetAllocationSiteUnchecked(); |
554 HashMap::Entry* e = | |
555 pretenuring_feedback->LookupOrInsert(key, ObjectHash(key)); | |
534 DCHECK(e != nullptr); | 556 DCHECK(e != nullptr); |
535 (*bit_cast<intptr_t*>(&e->value))++; | 557 (*bit_cast<intptr_t*>(&e->value))++; |
536 } | 558 } |
537 } | 559 } |
538 | 560 |
539 | 561 |
540 void Heap::RemoveAllocationSitePretenuringFeedback(AllocationSite* site) { | 562 void Heap::RemoveAllocationSitePretenuringFeedback(AllocationSite* site) { |
541 global_pretenuring_feedback_->Remove( | 563 global_pretenuring_feedback_->Remove( |
542 site, static_cast<uint32_t>(bit_cast<uintptr_t>(site))); | 564 site, static_cast<uint32_t>(bit_cast<uintptr_t>(site))); |
543 } | 565 } |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
719 | 741 |
720 void VerifySmisVisitor::VisitPointers(Object** start, Object** end) { | 742 void VerifySmisVisitor::VisitPointers(Object** start, Object** end) { |
721 for (Object** current = start; current < end; current++) { | 743 for (Object** current = start; current < end; current++) { |
722 CHECK((*current)->IsSmi()); | 744 CHECK((*current)->IsSmi()); |
723 } | 745 } |
724 } | 746 } |
725 } // namespace internal | 747 } // namespace internal |
726 } // namespace v8 | 748 } // namespace v8 |
727 | 749 |
728 #endif // V8_HEAP_HEAP_INL_H_ | 750 #endif // V8_HEAP_HEAP_INL_H_ |
OLD | NEW |