Commit b1a482f7 authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Commit Bot

[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: 's avatarMichael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65934}
parent 3390e575
...@@ -333,8 +333,13 @@ bool NativeContextInferrer::InferForJSObject(Isolate* isolate, Map map, ...@@ -333,8 +333,13 @@ bool NativeContextInferrer::InferForJSObject(Isolate* isolate, Map map,
return true; return true;
} }
} }
// TODO(ulan): Add a more precise inference for the case when // The maximum number of steps to perform when looking for the context.
// the current context is the shared 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; return false;
} }
......
...@@ -51,6 +51,7 @@ TEST(NativeContextInferrerJSObject) { ...@@ -51,6 +51,7 @@ TEST(NativeContextInferrerJSObject) {
LocalContext env; LocalContext env;
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
HandleScope scope(isolate); HandleScope scope(isolate);
Handle<NativeContext> native_context = GetNativeContext(isolate, env.local());
v8::Local<v8::Value> result = CompileRun("({a : 10})"); v8::Local<v8::Value> result = CompileRun("({a : 10})");
Handle<Object> object = Utils::OpenHandle(*result); Handle<Object> object = Utils::OpenHandle(*result);
Handle<HeapObject> function = Handle<HeapObject>::cast(object); Handle<HeapObject> function = Handle<HeapObject>::cast(object);
...@@ -58,8 +59,8 @@ TEST(NativeContextInferrerJSObject) { ...@@ -58,8 +59,8 @@ TEST(NativeContextInferrerJSObject) {
Address inferred_context = 0; Address inferred_context = 0;
// TODO(ulan): Enable this test once we have more precise native // TODO(ulan): Enable this test once we have more precise native
// context inference. // context inference.
CHECK( CHECK(inferrer.Infer(isolate, function->map(), *function, &inferred_context));
!inferrer.Infer(isolate, function->map(), *function, &inferred_context)); CHECK_EQ(native_context->ptr(), inferred_context);
} }
TEST(NativeContextStatsMerge) { TEST(NativeContextStatsMerge) {
......
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