| 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 #include "src/heap/heap.h" | 5 #include "src/heap/heap.h" |
| 6 | 6 |
| 7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
| 8 #include "src/api.h" | 8 #include "src/api.h" |
| 9 #include "src/ast/scopeinfo.h" | 9 #include "src/ast/scopeinfo.h" |
| 10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
| (...skipping 3118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3129 const int element_size = object->IsFixedArray() ? kPointerSize : kDoubleSize; | 3129 const int element_size = object->IsFixedArray() ? kPointerSize : kDoubleSize; |
| 3130 const int bytes_to_trim = elements_to_trim * element_size; | 3130 const int bytes_to_trim = elements_to_trim * element_size; |
| 3131 Map* map = object->map(); | 3131 Map* map = object->map(); |
| 3132 | 3132 |
| 3133 // For now this trick is only applied to objects in new and paged space. | 3133 // For now this trick is only applied to objects in new and paged space. |
| 3134 // In large object space the object's start must coincide with chunk | 3134 // In large object space the object's start must coincide with chunk |
| 3135 // and thus the trick is just not applicable. | 3135 // and thus the trick is just not applicable. |
| 3136 DCHECK(!lo_space()->Contains(object)); | 3136 DCHECK(!lo_space()->Contains(object)); |
| 3137 DCHECK(object->map() != fixed_cow_array_map()); | 3137 DCHECK(object->map() != fixed_cow_array_map()); |
| 3138 | 3138 |
| 3139 // Ensure that the no handle-scope has more than one pointer to the same |
| 3140 // backing-store. |
| 3141 SLOW_DCHECK(CountHandlesForObject(object) <= 1); |
| 3142 |
| 3139 STATIC_ASSERT(FixedArrayBase::kMapOffset == 0); | 3143 STATIC_ASSERT(FixedArrayBase::kMapOffset == 0); |
| 3140 STATIC_ASSERT(FixedArrayBase::kLengthOffset == kPointerSize); | 3144 STATIC_ASSERT(FixedArrayBase::kLengthOffset == kPointerSize); |
| 3141 STATIC_ASSERT(FixedArrayBase::kHeaderSize == 2 * kPointerSize); | 3145 STATIC_ASSERT(FixedArrayBase::kHeaderSize == 2 * kPointerSize); |
| 3142 | 3146 |
| 3143 const int len = object->length(); | 3147 const int len = object->length(); |
| 3144 DCHECK(elements_to_trim <= len); | 3148 DCHECK(elements_to_trim <= len); |
| 3145 | 3149 |
| 3146 // Calculate location of new array start. | 3150 // Calculate location of new array start. |
| 3147 Address new_start = object->address() + bytes_to_trim; | 3151 Address new_start = object->address() + bytes_to_trim; |
| 3148 | 3152 |
| (...skipping 2503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5652 | 5656 |
| 5653 | 5657 |
| 5654 void Heap::PrintHandles() { | 5658 void Heap::PrintHandles() { |
| 5655 PrintF("Handles:\n"); | 5659 PrintF("Handles:\n"); |
| 5656 PrintHandleVisitor v; | 5660 PrintHandleVisitor v; |
| 5657 isolate_->handle_scope_implementer()->Iterate(&v); | 5661 isolate_->handle_scope_implementer()->Iterate(&v); |
| 5658 } | 5662 } |
| 5659 | 5663 |
| 5660 #endif | 5664 #endif |
| 5661 | 5665 |
| 5666 #ifdef ENABLE_SLOW_DCHECKS |
| 5667 |
| 5668 class CountHandleVisitor : public ObjectVisitor { |
| 5669 public: |
| 5670 explicit CountHandleVisitor(Object* object) : object_(object) {} |
| 5671 |
| 5672 void VisitPointers(Object** start, Object** end) override { |
| 5673 for (Object** p = start; p < end; p++) { |
| 5674 if (object_ == reinterpret_cast<Object*>(*p)) count_++; |
| 5675 } |
| 5676 } |
| 5677 |
| 5678 int count() { return count_; } |
| 5679 |
| 5680 private: |
| 5681 Object* object_; |
| 5682 int count_ = 0; |
| 5683 }; |
| 5684 |
| 5685 int Heap::CountHandlesForObject(Object* object) { |
| 5686 CountHandleVisitor v(object); |
| 5687 isolate_->handle_scope_implementer()->Iterate(&v); |
| 5688 return v.count(); |
| 5689 } |
| 5690 #endif |
| 5691 |
| 5662 class CheckHandleCountVisitor : public ObjectVisitor { | 5692 class CheckHandleCountVisitor : public ObjectVisitor { |
| 5663 public: | 5693 public: |
| 5664 CheckHandleCountVisitor() : handle_count_(0) {} | 5694 CheckHandleCountVisitor() : handle_count_(0) {} |
| 5665 ~CheckHandleCountVisitor() override { | 5695 ~CheckHandleCountVisitor() override { |
| 5666 CHECK(handle_count_ < HandleScope::kCheckHandleThreshold); | 5696 CHECK(handle_count_ < HandleScope::kCheckHandleThreshold); |
| 5667 } | 5697 } |
| 5668 void VisitPointers(Object** start, Object** end) override { | 5698 void VisitPointers(Object** start, Object** end) override { |
| 5669 handle_count_ += end - start; | 5699 handle_count_ += end - start; |
| 5670 } | 5700 } |
| 5671 | 5701 |
| (...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6382 } | 6412 } |
| 6383 | 6413 |
| 6384 | 6414 |
| 6385 // static | 6415 // static |
| 6386 int Heap::GetStaticVisitorIdForMap(Map* map) { | 6416 int Heap::GetStaticVisitorIdForMap(Map* map) { |
| 6387 return StaticVisitorBase::GetVisitorId(map); | 6417 return StaticVisitorBase::GetVisitorId(map); |
| 6388 } | 6418 } |
| 6389 | 6419 |
| 6390 } // namespace internal | 6420 } // namespace internal |
| 6391 } // namespace v8 | 6421 } // namespace v8 |
| OLD | NEW |