v8/src/context-measure.h
yangguo 0a1a714f7e Introduce object visitor to estimate the size of a native context.
This is only an estimate since it counts objects that could be shared,
for example strings, cow arrays, heap numbers, etc.

It however ignores objects that could be shared, but may only be used
by the context to be measured, for example shared function infos,
script objects, scope infos, etc.

R=jochen@chromium.org

Review URL: https://codereview.chromium.org/1268333004

Cr-Commit-Position: refs/heads/master@{#30029}
2015-08-05 14:07:33 +00:00

48 lines
1.0 KiB
C++

// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_CONTEXT_MEASURE_H_
#define V8_CONTEXT_MEASURE_H_
#include "src/snapshot/serialize.h"
namespace v8 {
namespace internal {
class ContextMeasure : public ObjectVisitor {
public:
explicit ContextMeasure(Context* context);
int Size() { return size_; }
int Count() { return count_; }
void VisitPointers(Object** start, Object** end);
private:
void MeasureObject(HeapObject* object);
void MeasureDeferredObjects();
void MeasureAndRecurse(HeapObject* object);
bool IsShared(HeapObject* object);
Context* context_;
BackReferenceMap back_reference_map_;
RootIndexMap root_index_map_;
static const int kMaxRecursion = 16;
int recursion_depth_;
List<HeapObject*> deferred_objects_;
int count_;
int size_;
DisallowHeapAllocation no_gc_;
DISALLOW_COPY_AND_ASSIGN(ContextMeasure);
};
}
} // namespace v8::internal
#endif // V8_CONTEXT_MEASURE_H_