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 3091 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3102 const int element_size = object->IsFixedArray() ? kPointerSize : kDoubleSize; | 3102 const int element_size = object->IsFixedArray() ? kPointerSize : kDoubleSize; |
3103 const int bytes_to_trim = elements_to_trim * element_size; | 3103 const int bytes_to_trim = elements_to_trim * element_size; |
3104 Map* map = object->map(); | 3104 Map* map = object->map(); |
3105 | 3105 |
3106 // For now this trick is only applied to objects in new and paged space. | 3106 // For now this trick is only applied to objects in new and paged space. |
3107 // In large object space the object's start must coincide with chunk | 3107 // In large object space the object's start must coincide with chunk |
3108 // and thus the trick is just not applicable. | 3108 // and thus the trick is just not applicable. |
3109 DCHECK(!lo_space()->Contains(object)); | 3109 DCHECK(!lo_space()->Contains(object)); |
3110 DCHECK(object->map() != fixed_cow_array_map()); | 3110 DCHECK(object->map() != fixed_cow_array_map()); |
3111 | 3111 |
| 3112 // Ensure that the no handle-scope has more than one pointer to the same |
| 3113 // backing-store. |
| 3114 SLOW_DCHECK(CountHandlesForObject(object) <= 1); |
| 3115 |
3112 STATIC_ASSERT(FixedArrayBase::kMapOffset == 0); | 3116 STATIC_ASSERT(FixedArrayBase::kMapOffset == 0); |
3113 STATIC_ASSERT(FixedArrayBase::kLengthOffset == kPointerSize); | 3117 STATIC_ASSERT(FixedArrayBase::kLengthOffset == kPointerSize); |
3114 STATIC_ASSERT(FixedArrayBase::kHeaderSize == 2 * kPointerSize); | 3118 STATIC_ASSERT(FixedArrayBase::kHeaderSize == 2 * kPointerSize); |
3115 | 3119 |
3116 const int len = object->length(); | 3120 const int len = object->length(); |
3117 DCHECK(elements_to_trim <= len); | 3121 DCHECK(elements_to_trim <= len); |
3118 | 3122 |
3119 // Calculate location of new array start. | 3123 // Calculate location of new array start. |
3120 Address new_start = object->address() + bytes_to_trim; | 3124 Address new_start = object->address() + bytes_to_trim; |
3121 | 3125 |
(...skipping 2346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5468 | 5472 |
5469 | 5473 |
5470 void Heap::PrintHandles() { | 5474 void Heap::PrintHandles() { |
5471 PrintF("Handles:\n"); | 5475 PrintF("Handles:\n"); |
5472 PrintHandleVisitor v; | 5476 PrintHandleVisitor v; |
5473 isolate_->handle_scope_implementer()->Iterate(&v); | 5477 isolate_->handle_scope_implementer()->Iterate(&v); |
5474 } | 5478 } |
5475 | 5479 |
5476 #endif | 5480 #endif |
5477 | 5481 |
| 5482 #ifdef ENABLE_SLOW_DCHECKS |
| 5483 |
| 5484 class CountHandleVisitor : public ObjectVisitor { |
| 5485 public: |
| 5486 explicit CountHandleVisitor(Object* object) : object_(object) {} |
| 5487 |
| 5488 void VisitPointers(Object** start, Object** end) override { |
| 5489 for (Object** p = start; p < end; p++) { |
| 5490 if (object_ == reinterpret_cast<Object*>(*p)) count_++; |
| 5491 } |
| 5492 } |
| 5493 |
| 5494 int count() { return count_; } |
| 5495 |
| 5496 private: |
| 5497 Object* object_; |
| 5498 int count_ = 0; |
| 5499 }; |
| 5500 |
| 5501 int Heap::CountHandlesForObject(Object* object) { |
| 5502 CountHandleVisitor v(object); |
| 5503 isolate_->handle_scope_implementer()->Iterate(&v); |
| 5504 return v.count(); |
| 5505 } |
| 5506 #endif |
| 5507 |
5478 class CheckHandleCountVisitor : public ObjectVisitor { | 5508 class CheckHandleCountVisitor : public ObjectVisitor { |
5479 public: | 5509 public: |
5480 CheckHandleCountVisitor() : handle_count_(0) {} | 5510 CheckHandleCountVisitor() : handle_count_(0) {} |
5481 ~CheckHandleCountVisitor() override { | 5511 ~CheckHandleCountVisitor() override { |
5482 CHECK(handle_count_ < HandleScope::kCheckHandleThreshold); | 5512 CHECK(handle_count_ < HandleScope::kCheckHandleThreshold); |
5483 } | 5513 } |
5484 void VisitPointers(Object** start, Object** end) override { | 5514 void VisitPointers(Object** start, Object** end) override { |
5485 handle_count_ += end - start; | 5515 handle_count_ += end - start; |
5486 } | 5516 } |
5487 | 5517 |
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6233 } | 6263 } |
6234 | 6264 |
6235 | 6265 |
6236 // static | 6266 // static |
6237 int Heap::GetStaticVisitorIdForMap(Map* map) { | 6267 int Heap::GetStaticVisitorIdForMap(Map* map) { |
6238 return StaticVisitorBase::GetVisitorId(map); | 6268 return StaticVisitorBase::GetVisitorId(map); |
6239 } | 6269 } |
6240 | 6270 |
6241 } // namespace internal | 6271 } // namespace internal |
6242 } // namespace v8 | 6272 } // namespace v8 |
OLD | NEW |