| 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 10 matching lines...) Expand all Loading... |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #ifndef V8_HEAP_INL_H_ | 28 #ifndef V8_HEAP_INL_H_ |
| 29 #define V8_HEAP_INL_H_ | 29 #define V8_HEAP_INL_H_ |
| 30 | 30 |
| 31 #include <cmath> |
| 32 |
| 31 #include "heap.h" | 33 #include "heap.h" |
| 32 #include "isolate.h" | 34 #include "isolate.h" |
| 33 #include "list-inl.h" | 35 #include "list-inl.h" |
| 34 #include "objects.h" | 36 #include "objects.h" |
| 35 #include "platform.h" | 37 #include "platform.h" |
| 36 #include "v8-counters.h" | 38 #include "v8-counters.h" |
| 37 #include "store-buffer.h" | 39 #include "store-buffer.h" |
| 38 #include "store-buffer-inl.h" | 40 #include "store-buffer-inl.h" |
| 39 | 41 |
| 40 namespace v8 { | 42 namespace v8 { |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 } | 479 } |
| 478 } | 480 } |
| 479 | 481 |
| 480 | 482 |
| 481 void Heap::ScavengePointer(HeapObject** p) { | 483 void Heap::ScavengePointer(HeapObject** p) { |
| 482 ScavengeObject(p, *p); | 484 ScavengeObject(p, *p); |
| 483 } | 485 } |
| 484 | 486 |
| 485 | 487 |
| 486 void Heap::UpdateAllocationSiteFeedback(HeapObject* object) { | 488 void Heap::UpdateAllocationSiteFeedback(HeapObject* object) { |
| 487 if (FLAG_allocation_site_pretenuring && | 489 Heap* heap = object->GetHeap(); |
| 488 AllocationSite::CanTrack(object->map()->instance_type())) { | 490 ASSERT(heap->InNewSpace(object)); |
| 489 AllocationMemento* memento = AllocationMemento::FindForHeapObject( | 491 |
| 490 object, true); | 492 if (!FLAG_allocation_site_pretenuring || |
| 491 if (memento != NULL) { | 493 !heap->new_space_high_promotion_mode_active_ || |
| 492 ASSERT(memento->IsValid()); | 494 !AllocationSite::CanTrack(object->map()->instance_type())) return; |
| 493 bool add_to_scratchpad = | 495 |
| 494 memento->GetAllocationSite()->IncrementMementoFoundCount(); | 496 // Either object is the last object in the from space, or there is another |
| 495 Heap* heap = object->GetIsolate()->heap(); | 497 // object of at least word size (the header map word) following it, so |
| 496 if (add_to_scratchpad && heap->allocation_sites_scratchpad_length < | 498 // suffices to compare ptr and top here. |
| 497 kAllocationSiteScratchpadSize) { | 499 Address ptr = object->address() + object->Size(); |
| 498 heap->allocation_sites_scratchpad[ | 500 Address top = heap->new_space()->FromSpacePageHigh(); |
| 499 heap->allocation_sites_scratchpad_length++] = | 501 ASSERT(ptr == top || ptr + HeapObject::kHeaderSize <= top); |
| 500 memento->GetAllocationSite(); | 502 if (ptr == top) return; |
| 501 } | 503 |
| 502 } | 504 HeapObject* candidate = HeapObject::FromAddress(ptr); |
| 505 if (candidate->map() != heap->allocation_memento_map()) return; |
| 506 |
| 507 AllocationMemento* memento = AllocationMemento::cast(candidate); |
| 508 if (!memento->IsValid()) return; |
| 509 |
| 510 if (memento->GetAllocationSite()->IncrementMementoFoundCount() && |
| 511 heap->allocation_sites_scratchpad_length < |
| 512 kAllocationSiteScratchpadSize) { |
| 513 heap->allocation_sites_scratchpad[ |
| 514 heap->allocation_sites_scratchpad_length++] = |
| 515 memento->GetAllocationSite(); |
| 503 } | 516 } |
| 504 } | 517 } |
| 505 | 518 |
| 506 | 519 |
| 507 void Heap::ScavengeObject(HeapObject** p, HeapObject* object) { | 520 void Heap::ScavengeObject(HeapObject** p, HeapObject* object) { |
| 508 ASSERT(object->GetIsolate()->heap()->InFromSpace(object)); | 521 ASSERT(object->GetIsolate()->heap()->InFromSpace(object)); |
| 509 | 522 |
| 510 // We use the first word (where the map pointer usually is) of a heap | 523 // We use the first word (where the map pointer usually is) of a heap |
| 511 // object to record the forwarding pointer. A forwarding pointer can | 524 // object to record the forwarding pointer. A forwarding pointer can |
| 512 // point to an old space, the code space, or the to space of the new | 525 // point to an old space, the code space, or the to space of the new |
| (...skipping 11 matching lines...) Expand all Loading... |
| 524 | 537 |
| 525 UpdateAllocationSiteFeedback(object); | 538 UpdateAllocationSiteFeedback(object); |
| 526 | 539 |
| 527 // AllocationMementos are unrooted and shouldn't survive a scavenge | 540 // AllocationMementos are unrooted and shouldn't survive a scavenge |
| 528 ASSERT(object->map() != object->GetHeap()->allocation_memento_map()); | 541 ASSERT(object->map() != object->GetHeap()->allocation_memento_map()); |
| 529 // Call the slow part of scavenge object. | 542 // Call the slow part of scavenge object. |
| 530 return ScavengeObjectSlow(p, object); | 543 return ScavengeObjectSlow(p, object); |
| 531 } | 544 } |
| 532 | 545 |
| 533 | 546 |
| 534 bool Heap::CollectGarbage(AllocationSpace space, const char* gc_reason) { | 547 bool Heap::CollectGarbage(AllocationSpace space, |
| 548 const char* gc_reason, |
| 549 const v8::GCCallbackFlags callbackFlags) { |
| 535 const char* collector_reason = NULL; | 550 const char* collector_reason = NULL; |
| 536 GarbageCollector collector = SelectGarbageCollector(space, &collector_reason); | 551 GarbageCollector collector = SelectGarbageCollector(space, &collector_reason); |
| 537 return CollectGarbage(space, collector, gc_reason, collector_reason); | 552 return CollectGarbage( |
| 553 space, collector, gc_reason, collector_reason, callbackFlags); |
| 538 } | 554 } |
| 539 | 555 |
| 540 | 556 |
| 541 MaybeObject* Heap::PrepareForCompare(String* str) { | 557 MaybeObject* Heap::PrepareForCompare(String* str) { |
| 542 // Always flatten small strings and force flattening of long strings | 558 // Always flatten small strings and force flattening of long strings |
| 543 // after we have accumulated a certain amount we failed to flatten. | 559 // after we have accumulated a certain amount we failed to flatten. |
| 544 static const int kMaxAlwaysFlattenLength = 32; | 560 static const int kMaxAlwaysFlattenLength = 32; |
| 545 static const int kFlattenLongThreshold = 16*KB; | 561 static const int kFlattenLongThreshold = 16*KB; |
| 546 | 562 |
| 547 const int length = str->length(); | 563 const int length = str->length(); |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 #ifdef DEBUG | 833 #ifdef DEBUG |
| 818 Isolate* isolate = Isolate::Current(); | 834 Isolate* isolate = Isolate::Current(); |
| 819 isolate->heap()->disallow_allocation_failure_ = old_state_; | 835 isolate->heap()->disallow_allocation_failure_ = old_state_; |
| 820 #endif | 836 #endif |
| 821 } | 837 } |
| 822 | 838 |
| 823 | 839 |
| 824 } } // namespace v8::internal | 840 } } // namespace v8::internal |
| 825 | 841 |
| 826 #endif // V8_HEAP_INL_H_ | 842 #endif // V8_HEAP_INL_H_ |
| OLD | NEW |