Commit 76e3fe97 authored by littledan's avatar littledan Committed by Commit bot

[heap] Two minor fixes in EstimatedSize

A couple bugs had led code in one Context to be able to lead to
estimated memory usage in another Context, even in cases that should be
easy to detect.

- Ensure that the pointer to the next context is nulled out while
  recursing over the portion of the heap. It seems like there was
  previously some code to do this partway, but the nulling part
  was left out.
- Skip including maps in the understanding of the Context estimated
  size, as the maps are shared between Contexts and may be reachable
  from other Contexts

Review-Url: https://codereview.chromium.org/2780773002
Cr-Commit-Position: refs/heads/master@{#44208}
parent 759db9fc
......@@ -19,6 +19,8 @@ ContextMeasure::ContextMeasure(Context* context)
size_(0) {
DCHECK(context_->IsNativeContext());
Object* next_link = context_->next_context_link();
context_->set(Context::NEXT_CONTEXT_LINK,
context->GetIsolate()->heap()->undefined_value());
MeasureObject(context_);
MeasureDeferredObjects();
context_->set(Context::NEXT_CONTEXT_LINK, next_link);
......@@ -40,6 +42,9 @@ void ContextMeasure::MeasureObject(HeapObject* object) {
if (reference_map_.Lookup(object).is_valid()) return;
if (root_index_map_.Lookup(object) != RootIndexMap::kInvalidRootIndex) return;
if (IsShared(object)) return;
if (object->IsJSReceiver() &&
*JSReceiver::cast(object)->GetCreationContext() != context_)
return;
reference_map_.Add(object, SerializerReference::DummyReference());
recursion_depth_++;
if (recursion_depth_ > kMaxRecursion) {
......
......@@ -5893,6 +5893,26 @@ TEST(ContextMeasure) {
CHECK_LE(measure.Size(), size_upper_limit);
}
TEST(ContextMeasureNoMap) {
CcTest::InitializeVM();
v8::HandleScope scope(CcTest::isolate());
Local<v8::Context> current_context = CcTest::isolate()->GetCurrentContext();
Local<v8::Context> other_context = v8::Context::New(CcTest::isolate());
CompileRun(current_context, "var x = []");
size_t original_size_current = current_context->EstimatedSize();
size_t original_size_other = other_context->EstimatedSize();
CompileRun(current_context, "x.a = 1;");
size_t new_size_current = current_context->EstimatedSize();
size_t new_size_other = other_context->EstimatedSize();
CHECK_LT(original_size_current, new_size_current);
CHECK_EQ(original_size_other, new_size_other);
}
TEST(ScriptIterator) {
CcTest::InitializeVM();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment