Commit 2e6f4329 authored by Aseem Garg's avatar Aseem Garg Committed by Commit Bot

[wasm] fix clear context group for wasm

This CL only clears the wasm translations that correspond to the context
group being reset instead of clearing all.

R=clemensh@chromium.org,kozyatinskiy@chromium.org
BUG=chromium:892864

Cq-Include-Trybots: luci.chromium.try:linux_chromium_headless_rel;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Ib5af0489cbdb7c9b1571cb9cf935fda3bee14015
Reviewed-on: https://chromium-review.googlesource.com/c/1292676Reviewed-by: 's avatarDmitry Gozman <dgozman@chromium.org>
Reviewed-by: 's avatarAlexei Filippov <alph@chromium.org>
Commit-Queue: Aseem Garg <aseemgarg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57302}
parent 894402b3
...@@ -247,10 +247,15 @@ void V8InspectorImpl::contextCollected(int groupId, int contextId) { ...@@ -247,10 +247,15 @@ void V8InspectorImpl::contextCollected(int groupId, int contextId) {
void V8InspectorImpl::resetContextGroup(int contextGroupId) { void V8InspectorImpl::resetContextGroup(int contextGroupId) {
m_consoleStorageMap.erase(contextGroupId); m_consoleStorageMap.erase(contextGroupId);
m_muteExceptionsMap.erase(contextGroupId); m_muteExceptionsMap.erase(contextGroupId);
std::vector<int> contextIdsToClear;
forEachContext(contextGroupId,
[&contextIdsToClear](InspectedContext* context) {
contextIdsToClear.push_back(context->contextId());
});
m_debugger->wasmTranslation()->Clear(m_isolate, contextIdsToClear);
forEachSession(contextGroupId, forEachSession(contextGroupId,
[](V8InspectorSessionImpl* session) { session->reset(); }); [](V8InspectorSessionImpl* session) { session->reset(); });
m_contexts.erase(contextGroupId); m_contexts.erase(contextGroupId);
m_debugger->wasmTranslation()->Clear();
} }
void V8InspectorImpl::idleStarted() { m_isolate->SetIdle(true); } void V8InspectorImpl::idleStarted() { m_isolate->SetIdle(true); }
......
...@@ -175,6 +175,12 @@ class WasmTranslation::TranslatorImpl { ...@@ -175,6 +175,12 @@ class WasmTranslation::TranslatorImpl {
return builder.toString(); return builder.toString();
} }
int GetContextId(v8::Isolate* isolate) {
v8::HandleScope scope(isolate);
v8::Local<v8::debug::WasmScript> script = script_.Get(isolate);
return script->ContextId().FromMaybe(0);
}
private: private:
String16 GetFakeScriptUrl(v8::Isolate* isolate, int func_index) { String16 GetFakeScriptUrl(v8::Isolate* isolate, int func_index) {
v8::Local<v8::debug::WasmScript> script = script_.Get(isolate); v8::Local<v8::debug::WasmScript> script = script_.Get(isolate);
...@@ -267,6 +273,32 @@ void WasmTranslation::Clear() { ...@@ -267,6 +273,32 @@ void WasmTranslation::Clear() {
fake_scripts_.clear(); fake_scripts_.clear();
} }
void WasmTranslation::Clear(v8::Isolate* isolate,
const std::vector<int>& contextIdsToClear) {
for (auto iter = fake_scripts_.begin(); iter != fake_scripts_.end();) {
auto contextId = iter->second->GetContextId(isolate);
auto it = std::find(std::begin(contextIdsToClear),
std::end(contextIdsToClear), contextId);
if (it != std::end(contextIdsToClear)) {
iter = fake_scripts_.erase(iter);
} else {
++iter;
}
}
for (auto iter = wasm_translators_.begin();
iter != wasm_translators_.end();) {
auto contextId = iter->second->GetContextId(isolate);
auto it = std::find(std::begin(contextIdsToClear),
std::end(contextIdsToClear), contextId);
if (it != std::end(contextIdsToClear)) {
iter = wasm_translators_.erase(iter);
} else {
++iter;
}
}
}
const String16& WasmTranslation::GetSource(const String16& script_id, const String16& WasmTranslation::GetSource(const String16& script_id,
int func_index) { int func_index) {
auto it = fake_scripts_.find(script_id); auto it = fake_scripts_.find(script_id);
......
...@@ -32,6 +32,9 @@ class WasmTranslation { ...@@ -32,6 +32,9 @@ class WasmTranslation {
// Clear all registered scripts. // Clear all registered scripts.
void Clear(); void Clear();
// Clear all registered scripts for context group.
void Clear(v8::Isolate* isolate, const std::vector<int>& contextIdsToClear);
// Translate a location as generated by V8 to a location that should be sent // Translate a location as generated by V8 to a location that should be sent
// over protocol. // over protocol.
// Does nothing for locations referencing a script which was not registered // Does nothing for locations referencing a script which was not registered
......
Checks resetting context group with wasm.
{
id : <messageId>
result : {
result : {
description : 3
type : number
value : 3
}
}
}
{
error : {
code : -32000
message : Cannot find context with specified id
}
id : <messageId>
}
// Copyright 2018 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.
InspectorTest.log('Checks resetting context group with wasm.');
utils.load('test/mjsunit/wasm/wasm-constants.js');
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
var builder = new WasmModuleBuilder();
// wasm_B calls wasm_A <param0> times.
builder.addFunction('wasm_func', kSig_i_i)
.addBody([
// clang-format off
kExprGetLocal, 0,
kExprI32Const, 1,
kExprI32Sub,
// clang-format on
])
.exportAs('main');
var module_bytes = builder.toArray();
function instantiate(bytes) {
var buffer = new ArrayBuffer(bytes.length);
var view = new Uint8Array(buffer);
for (var i = 0; i < bytes.length; ++i) {
view[i] = bytes[i] | 0;
}
var module = new WebAssembly.Module(buffer);
// Set global variable.
instance = new WebAssembly.Instance(module);
}
var contextGroup1 = new InspectorTest.ContextGroup();
var session1 = contextGroup1.connect();
session1.setupScriptMap();
let contextGroup2 = new InspectorTest.ContextGroup();
let session2 = contextGroup2.connect();
session2.setupScriptMap();
(async function test() {
await session1.Protocol.Debugger.enable();
await session2.Protocol.Debugger.enable();
session1.Protocol.Runtime.evaluate({
expression: `var instance;(${instantiate.toString()})(${JSON.stringify(module_bytes)})`});
session2.Protocol.Runtime.evaluate({
expression: `var instance;(${instantiate.toString()})(${JSON.stringify(module_bytes)})`});
contextGroup2.reset();
await session1.Protocol.Debugger.onceScriptParsed(2);
InspectorTest.logMessage(await session1.Protocol.Runtime.evaluate({expression: 'instance.exports.main(4)'}));
InspectorTest.logMessage(await session2.Protocol.Runtime.evaluate({expression: 'instance.exports.main(5)'}));
InspectorTest.completeTest();
})();
...@@ -311,6 +311,9 @@ class UtilsExtension : public IsolateData::SetupGlobalTask { ...@@ -311,6 +311,9 @@ class UtilsExtension : public IsolateData::SetupGlobalTask {
utils->Set(ToV8String(isolate, "createContextGroup"), utils->Set(ToV8String(isolate, "createContextGroup"),
v8::FunctionTemplate::New(isolate, v8::FunctionTemplate::New(isolate,
&UtilsExtension::CreateContextGroup)); &UtilsExtension::CreateContextGroup));
utils->Set(
ToV8String(isolate, "resetContextGroup"),
v8::FunctionTemplate::New(isolate, &UtilsExtension::ResetContextGroup));
utils->Set( utils->Set(
ToV8String(isolate, "connectSession"), ToV8String(isolate, "connectSession"),
v8::FunctionTemplate::New(isolate, &UtilsExtension::ConnectSession)); v8::FunctionTemplate::New(isolate, &UtilsExtension::ConnectSession));
...@@ -526,6 +529,18 @@ class UtilsExtension : public IsolateData::SetupGlobalTask { ...@@ -526,6 +529,18 @@ class UtilsExtension : public IsolateData::SetupGlobalTask {
v8::Int32::New(args.GetIsolate(), context_group_id)); v8::Int32::New(args.GetIsolate(), context_group_id));
} }
static void ResetContextGroup(
const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 1 || !args[0]->IsInt32()) {
fprintf(stderr, "Internal error: resetContextGroup(context_group_id).");
Exit();
}
int context_group_id = args[0].As<v8::Int32>()->Value();
RunSyncTask(backend_runner_, [&context_group_id](IsolateData* data) {
data->ResetContextGroup(context_group_id);
});
}
static void ConnectSession(const v8::FunctionCallbackInfo<v8::Value>& args) { static void ConnectSession(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 3 || !args[0]->IsInt32() || !args[1]->IsString() || if (args.Length() != 3 || !args[0]->IsInt32() || !args[1]->IsString() ||
!args[2]->IsFunction()) { !args[2]->IsFunction()) {
......
...@@ -110,6 +110,10 @@ v8::Local<v8::Context> IsolateData::GetContext(int context_group_id) { ...@@ -110,6 +110,10 @@ v8::Local<v8::Context> IsolateData::GetContext(int context_group_id) {
return contexts_[context_group_id].Get(isolate_.get()); return contexts_[context_group_id].Get(isolate_.get());
} }
void IsolateData::ResetContextGroup(int context_group_id) {
inspector_->resetContextGroup(context_group_id);
}
int IsolateData::GetContextGroupId(v8::Local<v8::Context> context) { int IsolateData::GetContextGroupId(v8::Local<v8::Context> context) {
return static_cast<int>( return static_cast<int>(
reinterpret_cast<intptr_t>( reinterpret_cast<intptr_t>(
......
...@@ -35,6 +35,7 @@ class IsolateData : public v8_inspector::V8InspectorClient { ...@@ -35,6 +35,7 @@ class IsolateData : public v8_inspector::V8InspectorClient {
// Setting things up. // Setting things up.
int CreateContextGroup(); int CreateContextGroup();
void ResetContextGroup(int context_group_id);
v8::Local<v8::Context> GetContext(int context_group_id); v8::Local<v8::Context> GetContext(int context_group_id);
int GetContextGroupId(v8::Local<v8::Context> context); int GetContextGroupId(v8::Local<v8::Context> context);
void RegisterModule(v8::Local<v8::Context> context, void RegisterModule(v8::Local<v8::Context> context,
......
...@@ -140,6 +140,10 @@ InspectorTest.ContextGroup = class { ...@@ -140,6 +140,10 @@ InspectorTest.ContextGroup = class {
return new InspectorTest.Session(this); return new InspectorTest.Session(this);
} }
reset() {
utils.resetContextGroup(this.id);
}
setupInjectedScriptEnvironment(session) { setupInjectedScriptEnvironment(session) {
let scriptSource = ''; let scriptSource = '';
let getters = ["length","internalConstructorName","subtype","getProperty", let getters = ["length","internalConstructorName","subtype","getProperty",
......
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