[heap] Infer native context for each JSObject for memory measurement

Bug: chromium:973627

Change-Id: Ie9b07075604451636967b69b30f276fb45bc5372
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2011824
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65934}
This commit is contained in:
Ulan Degenbaev 2020-01-21 12:52:35 +01:00 committed by Commit Bot
parent 3390e57553
commit b1a482f714
2 changed files with 10 additions and 4 deletions

View File

@ -333,8 +333,13 @@ bool NativeContextInferrer::InferForJSObject(Isolate* isolate, Map map,
return true;
}
}
// TODO(ulan): Add a more precise inference for the case when
// the current context is the shared context.
// The maximum number of steps to perform when looking for the context.
const int kMaxSteps = 3;
Object maybe_constructor = map.TryGetConstructor(isolate, kMaxSteps);
if (maybe_constructor.IsJSFunction()) {
return InferForJSFunction(JSFunction::cast(maybe_constructor),
native_context);
}
return false;
}

View File

@ -51,6 +51,7 @@ TEST(NativeContextInferrerJSObject) {
LocalContext env;
Isolate* isolate = CcTest::i_isolate();
HandleScope scope(isolate);
Handle<NativeContext> native_context = GetNativeContext(isolate, env.local());
v8::Local<v8::Value> result = CompileRun("({a : 10})");
Handle<Object> object = Utils::OpenHandle(*result);
Handle<HeapObject> function = Handle<HeapObject>::cast(object);
@ -58,8 +59,8 @@ TEST(NativeContextInferrerJSObject) {
Address inferred_context = 0;
// TODO(ulan): Enable this test once we have more precise native
// context inference.
CHECK(
!inferrer.Infer(isolate, function->map(), *function, &inferred_context));
CHECK(inferrer.Infer(isolate, function->map(), *function, &inferred_context));
CHECK_EQ(native_context->ptr(), inferred_context);
}
TEST(NativeContextStatsMerge) {