Commit 782ec0f2 authored by Sigurdur Asgeirsson's avatar Sigurdur Asgeirsson Committed by Commit Bot

V8 per-frame memory, get isolated world and host IDs for each context.

Bug: 998546
Change-Id: I1a356768fad7914992631ce1d740029c8f61d39c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2213885Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarJoe Mason <joenotcharles@chromium.org>
Commit-Queue: Sigurður Ásgeirsson <siggi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772313}
parent a6c2b0da
......@@ -5,6 +5,7 @@
#include "chrome/renderer/performance_manager/decorators/v8_per_frame_memory_reporter_impl.h"
#include "content/public/common/isolated_world_ids.h"
#include "extensions/renderer/script_injection.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/public/web/web_local_frame_client.h"
......@@ -51,11 +52,7 @@ class FrameAssociatedMeasurementDelegate : public v8::MeasureMemoryDelegate {
blink::WebLocalFrame* frame =
blink::WebLocalFrame::FrameForContext(context);
// TODO(siggi): Expose a way to get the WorldId for a context in
// blink/public somewhere. The WorldId is already exposed at that
// level except only in the WebLocalFrameClient callbacks.
// From the WorldId it's then possible to resolve the host ID.
if (!frame || context != frame->MainWorldScriptContext()) {
if (!frame) {
// TODO(siggi): It would be prefereable to count the V8SchemaRegistry
// context's overhead with unassociated_bytes, but at present there
// isn't a public API that allows this distinction.
......@@ -63,18 +60,25 @@ class FrameAssociatedMeasurementDelegate : public v8::MeasureMemoryDelegate {
result->unassociated_context_bytes_used += size;
} else {
base::UnguessableToken token = frame->Client()->GetDevToolsFrameToken();
DCHECK(!base::Contains(result->associated_memory, token));
mojom::PerFrameV8MemoryUsageData* per_frame_resources =
result->associated_memory[token].get();
if (!per_frame_resources) {
auto new_resources = mojom::PerFrameV8MemoryUsageData::New();
per_frame_resources = new_resources.get();
result->associated_memory[token] = std::move(new_resources);
}
mojom::V8IsolatedWorldMemoryUsagePtr isolated_world_usage =
mojom::V8IsolatedWorldMemoryUsage::New();
isolated_world_usage->bytes_used = size;
mojom::PerFrameV8MemoryUsageDataPtr per_frame_resources =
mojom::PerFrameV8MemoryUsageData::New();
per_frame_resources
->associated_bytes[content::ISOLATED_WORLD_ID_GLOBAL] =
int32_t world_id = frame->GetScriptContextWorldId(context);
isolated_world_usage->host_id =
extensions::ScriptInjection::GetHostIdForIsolatedWorld(world_id);
DCHECK(
!base::Contains(per_frame_resources->associated_bytes, world_id));
per_frame_resources->associated_bytes[world_id] =
std::move(isolated_world_usage);
result->associated_memory[token] = std::move(per_frame_resources);
}
}
......
......@@ -337,6 +337,10 @@ class WebLocalFrame : public WebFrame {
// be calling this API.
virtual v8::Local<v8::Context> MainWorldScriptContext() const = 0;
// Returns the world ID associated with |script_context|.
virtual int32_t GetScriptContextWorldId(
v8::Local<v8::Context> script_context) const = 0;
// Executes script in the context of the current page and returns the value
// that the script evaluated to with callback. Script execution can be
// suspend.
......
......@@ -4567,6 +4567,11 @@ TEST_F(WebFrameTest, ContextNotificationsIsolatedWorlds) {
ASSERT_NE(web_view_helper.LocalMainFrame()->MainWorldScriptContext(),
v8::Local<v8::Context>::New(isolate, notification->context));
// Check that the context we got has the right isolated world id.
ASSERT_EQ(isolated_world_id,
web_view_helper.LocalMainFrame()->GetScriptContextWorldId(
v8::Local<v8::Context>::New(isolate, notification->context)));
web_view_helper.Reset();
// We should have gotten three release notifications (one for each of the
......
......@@ -941,6 +941,12 @@ v8::Local<v8::Context> WebLocalFrameImpl::MainWorldScriptContext() const {
return script_state->GetContext();
}
int32_t WebLocalFrameImpl::GetScriptContextWorldId(
v8::Local<v8::Context> script_context) const {
DCHECK_EQ(this, FrameForContext(script_context));
return DOMWrapperWorld::World(script_context).GetWorldId();
}
v8::Local<v8::Object> WebLocalFrameImpl::GlobalProxy() const {
return MainWorldScriptContext()->Global();
}
......
......@@ -159,6 +159,8 @@ class CORE_EXPORT WebLocalFrameImpl final
int argc,
v8::Local<v8::Value> argv[]) override;
v8::Local<v8::Context> MainWorldScriptContext() const override;
int32_t GetScriptContextWorldId(
v8::Local<v8::Context> script_context) const override;
void RequestExecuteScriptAndReturnValue(const WebScriptSource&,
bool user_gesture,
WebScriptExecutionCallback*) override;
......
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