OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "src/v8.h" |
| 6 |
| 7 #include "src/context-measure.h" |
| 8 |
| 9 namespace v8 { |
| 10 namespace internal { |
| 11 |
| 12 ContextMeasure::ContextMeasure(Context* context) |
| 13 : context_(context), |
| 14 root_index_map_(context->GetIsolate()), |
| 15 recursion_depth_(0), |
| 16 count_(0), |
| 17 size_(0) { |
| 18 DCHECK(context_->IsNativeContext()); |
| 19 Object* next_link = context_->get(Context::NEXT_CONTEXT_LINK); |
| 20 MeasureObject(context_); |
| 21 MeasureDeferredObjects(); |
| 22 context_->set(Context::NEXT_CONTEXT_LINK, next_link); |
| 23 } |
| 24 |
| 25 |
| 26 bool ContextMeasure::IsShared(HeapObject* object) { |
| 27 if (object->IsScript()) return true; |
| 28 if (object->IsSharedFunctionInfo()) return true; |
| 29 if (object->IsScopeInfo()) return true; |
| 30 if (object->IsCode() && !Code::cast(object)->is_optimized_code()) return true; |
| 31 if (object->IsExecutableAccessorInfo()) return true; |
| 32 if (object->IsWeakCell()) return true; |
| 33 return false; |
| 34 } |
| 35 |
| 36 |
| 37 void ContextMeasure::MeasureObject(HeapObject* object) { |
| 38 if (back_reference_map_.Lookup(object).is_valid()) return; |
| 39 if (root_index_map_.Lookup(object) != RootIndexMap::kInvalidRootIndex) return; |
| 40 if (IsShared(object)) return; |
| 41 back_reference_map_.Add(object, BackReference::DummyReference()); |
| 42 recursion_depth_++; |
| 43 if (recursion_depth_ > kMaxRecursion) { |
| 44 deferred_objects_.Add(object); |
| 45 } else { |
| 46 MeasureAndRecurse(object); |
| 47 } |
| 48 recursion_depth_--; |
| 49 } |
| 50 |
| 51 |
| 52 void ContextMeasure::MeasureDeferredObjects() { |
| 53 while (deferred_objects_.length() > 0) { |
| 54 MeasureAndRecurse(deferred_objects_.RemoveLast()); |
| 55 } |
| 56 } |
| 57 |
| 58 |
| 59 void ContextMeasure::MeasureAndRecurse(HeapObject* object) { |
| 60 int size = object->Size(); |
| 61 count_++; |
| 62 size_ += size; |
| 63 Map* map = object->map(); |
| 64 MeasureObject(map); |
| 65 object->IterateBody(map->instance_type(), size, this); |
| 66 } |
| 67 |
| 68 |
| 69 void ContextMeasure::VisitPointers(Object** start, Object** end) { |
| 70 for (Object** current = start; current < end; current++) { |
| 71 if ((*current)->IsSmi()) continue; |
| 72 MeasureObject(HeapObject::cast(*current)); |
| 73 } |
| 74 } |
| 75 } |
| 76 } // namespace v8::internal |
OLD | NEW |