| 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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 // Only the latter two contain non-map-word pointers to heap objects. | 411 // Only the latter two contain non-map-word pointers to heap objects. |
| 412 return ((type & kIsIndirectStringMask) == kIsIndirectStringTag) | 412 return ((type & kIsIndirectStringMask) == kIsIndirectStringTag) |
| 413 ? OLD_POINTER_SPACE | 413 ? OLD_POINTER_SPACE |
| 414 : OLD_DATA_SPACE; | 414 : OLD_DATA_SPACE; |
| 415 } else { | 415 } else { |
| 416 return (type <= LAST_DATA_TYPE) ? OLD_DATA_SPACE : OLD_POINTER_SPACE; | 416 return (type <= LAST_DATA_TYPE) ? OLD_DATA_SPACE : OLD_POINTER_SPACE; |
| 417 } | 417 } |
| 418 } | 418 } |
| 419 | 419 |
| 420 | 420 |
| 421 bool Heap::AllowedToBeMigrated(HeapObject* object, AllocationSpace dst) { | 421 bool Heap::AllowedToBeMigrated(HeapObject* obj, AllocationSpace dst) { |
| 422 // Object migration is governed by the following rules: | 422 // Object migration is governed by the following rules: |
| 423 // | 423 // |
| 424 // 1) Objects in new-space can be migrated to one of the old spaces | 424 // 1) Objects in new-space can be migrated to one of the old spaces |
| 425 // that matches their target space or they stay in new-space. | 425 // that matches their target space or they stay in new-space. |
| 426 // 2) Objects in old-space stay in the same space when migrating. | 426 // 2) Objects in old-space stay in the same space when migrating. |
| 427 // 3) Fillers (two or more words) can migrate due to left-trimming of | 427 // 3) Fillers (two or more words) can migrate due to left-trimming of |
| 428 // fixed arrays in new-space, old-data-space and old-pointer-space. | 428 // fixed arrays in new-space, old-data-space and old-pointer-space. |
| 429 // 4) Fillers (one word) can never migrate, they are skipped by | 429 // 4) Fillers (one word) can never migrate, they are skipped by |
| 430 // incremental marking explicitly to prevent invalid pattern. | 430 // incremental marking explicitly to prevent invalid pattern. |
| 431 // 5) Short external strings can end up in old pointer space when a cons |
| 432 // string in old pointer space is made external (String::MakeExternal). |
| 431 // | 433 // |
| 432 // Since this function is used for debugging only, we do not place | 434 // Since this function is used for debugging only, we do not place |
| 433 // asserts here, but check everything explicitly. | 435 // asserts here, but check everything explicitly. |
| 434 if (object->map() == one_pointer_filler_map()) return false; | 436 if (obj->map() == one_pointer_filler_map()) return false; |
| 435 InstanceType type = object->map()->instance_type(); | 437 InstanceType type = obj->map()->instance_type(); |
| 436 MemoryChunk* chunk = MemoryChunk::FromAddress(object->address()); | 438 MemoryChunk* chunk = MemoryChunk::FromAddress(obj->address()); |
| 437 AllocationSpace src = chunk->owner()->identity(); | 439 AllocationSpace src = chunk->owner()->identity(); |
| 438 switch (src) { | 440 switch (src) { |
| 439 case NEW_SPACE: | 441 case NEW_SPACE: |
| 440 return dst == src || dst == TargetSpaceId(type); | 442 return dst == src || dst == TargetSpaceId(type); |
| 441 case OLD_POINTER_SPACE: | 443 case OLD_POINTER_SPACE: |
| 442 return dst == src && (dst == TargetSpaceId(type) || object->IsFiller()); | 444 return dst == src && |
| 445 (dst == TargetSpaceId(type) || obj->IsFiller() || |
| 446 (obj->IsExternalString() && ExternalString::cast(obj)->is_short())); |
| 443 case OLD_DATA_SPACE: | 447 case OLD_DATA_SPACE: |
| 444 return dst == src && dst == TargetSpaceId(type); | 448 return dst == src && dst == TargetSpaceId(type); |
| 445 case CODE_SPACE: | 449 case CODE_SPACE: |
| 446 return dst == src && type == CODE_TYPE; | 450 return dst == src && type == CODE_TYPE; |
| 447 case MAP_SPACE: | 451 case MAP_SPACE: |
| 448 case CELL_SPACE: | 452 case CELL_SPACE: |
| 449 case PROPERTY_CELL_SPACE: | 453 case PROPERTY_CELL_SPACE: |
| 450 case LO_SPACE: | 454 case LO_SPACE: |
| 451 return false; | 455 return false; |
| 452 } | 456 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 481 } | 485 } |
| 482 | 486 |
| 483 | 487 |
| 484 void Heap::ScavengePointer(HeapObject** p) { | 488 void Heap::ScavengePointer(HeapObject** p) { |
| 485 ScavengeObject(p, *p); | 489 ScavengeObject(p, *p); |
| 486 } | 490 } |
| 487 | 491 |
| 488 | 492 |
| 489 void Heap::UpdateAllocationSiteFeedback(HeapObject* object) { | 493 void Heap::UpdateAllocationSiteFeedback(HeapObject* object) { |
| 490 Heap* heap = object->GetHeap(); | 494 Heap* heap = object->GetHeap(); |
| 491 ASSERT(heap->InNewSpace(object)); | 495 ASSERT(heap->InFromSpace(object)); |
| 492 | 496 |
| 493 if (!FLAG_allocation_site_pretenuring || | 497 if (!FLAG_allocation_site_pretenuring || |
| 494 !heap->new_space_high_promotion_mode_active_ || | |
| 495 !AllocationSite::CanTrack(object->map()->instance_type())) return; | 498 !AllocationSite::CanTrack(object->map()->instance_type())) return; |
| 496 | 499 |
| 497 // Either object is the last object in the from space, or there is another | 500 // Check if there is potentially a memento behind the object. If |
| 498 // object of at least word size (the header map word) following it, so | 501 // the last word of the momento is on another page we return |
| 499 // suffices to compare ptr and top here. | 502 // immediatelly. Note that we do not have to compare with the current |
| 500 Address ptr = object->address() + object->Size(); | 503 // top pointer of the from space page, since we always install filler |
| 501 Address top = heap->new_space()->FromSpacePageHigh(); | 504 // objects above the top pointer of a from space page when performing |
| 502 ASSERT(ptr == top || ptr + HeapObject::kHeaderSize <= top); | 505 // a garbage collection. |
| 503 if (ptr == top) return; | 506 Address object_address = object->address(); |
| 507 Address memento_address = object_address + object->Size(); |
| 508 Address last_memento_word_address = memento_address + kPointerSize; |
| 509 if (!NewSpacePage::OnSamePage(object_address, |
| 510 last_memento_word_address)) { |
| 511 return; |
| 512 } |
| 504 | 513 |
| 505 HeapObject* candidate = HeapObject::FromAddress(ptr); | 514 HeapObject* candidate = HeapObject::FromAddress(memento_address); |
| 506 if (candidate->map() != heap->allocation_memento_map()) return; | 515 if (candidate->map() != heap->allocation_memento_map()) return; |
| 507 | 516 |
| 508 AllocationMemento* memento = AllocationMemento::cast(candidate); | 517 AllocationMemento* memento = AllocationMemento::cast(candidate); |
| 509 if (!memento->IsValid()) return; | 518 if (!memento->IsValid()) return; |
| 510 | 519 |
| 511 if (memento->GetAllocationSite()->IncrementMementoFoundCount() && | 520 if (memento->GetAllocationSite()->IncrementMementoFoundCount()) { |
| 512 heap->allocation_sites_scratchpad_length < | 521 heap->AddAllocationSiteToScratchpad(memento->GetAllocationSite()); |
| 513 kAllocationSiteScratchpadSize) { | |
| 514 heap->allocation_sites_scratchpad[ | |
| 515 heap->allocation_sites_scratchpad_length++] = | |
| 516 memento->GetAllocationSite(); | |
| 517 } | 522 } |
| 518 } | 523 } |
| 519 | 524 |
| 520 | 525 |
| 521 void Heap::ScavengeObject(HeapObject** p, HeapObject* object) { | 526 void Heap::ScavengeObject(HeapObject** p, HeapObject* object) { |
| 522 ASSERT(object->GetIsolate()->heap()->InFromSpace(object)); | 527 ASSERT(object->GetIsolate()->heap()->InFromSpace(object)); |
| 523 | 528 |
| 524 // We use the first word (where the map pointer usually is) of a heap | 529 // We use the first word (where the map pointer usually is) of a heap |
| 525 // object to record the forwarding pointer. A forwarding pointer can | 530 // object to record the forwarding pointer. A forwarding pointer can |
| 526 // point to an old space, the code space, or the to space of the new | 531 // point to an old space, the code space, or the to space of the new |
| (...skipping 16 matching lines...) Expand all Loading... |
| 543 // Call the slow part of scavenge object. | 548 // Call the slow part of scavenge object. |
| 544 return ScavengeObjectSlow(p, object); | 549 return ScavengeObjectSlow(p, object); |
| 545 } | 550 } |
| 546 | 551 |
| 547 | 552 |
| 548 bool Heap::CollectGarbage(AllocationSpace space, | 553 bool Heap::CollectGarbage(AllocationSpace space, |
| 549 const char* gc_reason, | 554 const char* gc_reason, |
| 550 const v8::GCCallbackFlags callbackFlags) { | 555 const v8::GCCallbackFlags callbackFlags) { |
| 551 const char* collector_reason = NULL; | 556 const char* collector_reason = NULL; |
| 552 GarbageCollector collector = SelectGarbageCollector(space, &collector_reason); | 557 GarbageCollector collector = SelectGarbageCollector(space, &collector_reason); |
| 553 return CollectGarbage( | 558 return CollectGarbage(collector, gc_reason, collector_reason, callbackFlags); |
| 554 space, collector, gc_reason, collector_reason, callbackFlags); | |
| 555 } | 559 } |
| 556 | 560 |
| 557 | 561 |
| 558 MaybeObject* Heap::PrepareForCompare(String* str) { | 562 MaybeObject* Heap::PrepareForCompare(String* str) { |
| 559 // Always flatten small strings and force flattening of long strings | 563 // Always flatten small strings and force flattening of long strings |
| 560 // after we have accumulated a certain amount we failed to flatten. | 564 // after we have accumulated a certain amount we failed to flatten. |
| 561 static const int kMaxAlwaysFlattenLength = 32; | 565 static const int kMaxAlwaysFlattenLength = 32; |
| 562 static const int kFlattenLongThreshold = 16*KB; | 566 static const int kFlattenLongThreshold = 16*KB; |
| 563 | 567 |
| 564 const int length = str->length(); | 568 const int length = str->length(); |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 for (Object** current = start; current < end; current++) { | 813 for (Object** current = start; current < end; current++) { |
| 810 if ((*current)->IsHeapObject()) { | 814 if ((*current)->IsHeapObject()) { |
| 811 HeapObject* object = HeapObject::cast(*current); | 815 HeapObject* object = HeapObject::cast(*current); |
| 812 CHECK(object->GetIsolate()->heap()->Contains(object)); | 816 CHECK(object->GetIsolate()->heap()->Contains(object)); |
| 813 CHECK(object->map()->IsMap()); | 817 CHECK(object->map()->IsMap()); |
| 814 } | 818 } |
| 815 } | 819 } |
| 816 } | 820 } |
| 817 | 821 |
| 818 | 822 |
| 823 void VerifySmisVisitor::VisitPointers(Object** start, Object** end) { |
| 824 for (Object** current = start; current < end; current++) { |
| 825 CHECK((*current)->IsSmi()); |
| 826 } |
| 827 } |
| 828 |
| 829 |
| 819 double GCTracer::SizeOfHeapObjects() { | 830 double GCTracer::SizeOfHeapObjects() { |
| 820 return (static_cast<double>(heap_->SizeOfObjects())) / MB; | 831 return (static_cast<double>(heap_->SizeOfObjects())) / MB; |
| 821 } | 832 } |
| 822 | 833 |
| 823 | 834 |
| 824 DisallowAllocationFailure::DisallowAllocationFailure() { | 835 DisallowAllocationFailure::DisallowAllocationFailure() { |
| 825 #ifdef DEBUG | 836 #ifdef DEBUG |
| 826 Isolate* isolate = Isolate::Current(); | 837 Isolate* isolate = Isolate::Current(); |
| 827 old_state_ = isolate->heap()->disallow_allocation_failure_; | 838 old_state_ = isolate->heap()->disallow_allocation_failure_; |
| 828 isolate->heap()->disallow_allocation_failure_ = true; | 839 isolate->heap()->disallow_allocation_failure_ = true; |
| 829 #endif | 840 #endif |
| 830 } | 841 } |
| 831 | 842 |
| 832 | 843 |
| 833 DisallowAllocationFailure::~DisallowAllocationFailure() { | 844 DisallowAllocationFailure::~DisallowAllocationFailure() { |
| 834 #ifdef DEBUG | 845 #ifdef DEBUG |
| 835 Isolate* isolate = Isolate::Current(); | 846 Isolate* isolate = Isolate::Current(); |
| 836 isolate->heap()->disallow_allocation_failure_ = old_state_; | 847 isolate->heap()->disallow_allocation_failure_ = old_state_; |
| 837 #endif | 848 #endif |
| 838 } | 849 } |
| 839 | 850 |
| 840 | 851 |
| 841 } } // namespace v8::internal | 852 } } // namespace v8::internal |
| 842 | 853 |
| 843 #endif // V8_HEAP_INL_H_ | 854 #endif // V8_HEAP_INL_H_ |
| OLD | NEW |