Commit fe74c4f7 authored by Z Nguyen-Huu's avatar Z Nguyen-Huu Committed by Commit Bot

[wasm] Tierup wasm module on debugger.disable

Bug: v8:10290
Change-Id: I35670fef49a89cd075fb654daec4b55440266673
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2088231
Commit-Queue: Z Nguyen-Huu <duongn@microsoft.com>
Reviewed-by: 's avatarSimon Zünd <szuend@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66634}
parent 8b1a5681
...@@ -9868,6 +9868,11 @@ void debug::TierDownAllModulesPerIsolate(Isolate* v8_isolate) { ...@@ -9868,6 +9868,11 @@ void debug::TierDownAllModulesPerIsolate(Isolate* v8_isolate) {
isolate->wasm_engine()->TierDownAllModulesPerIsolate(isolate); isolate->wasm_engine()->TierDownAllModulesPerIsolate(isolate);
} }
void debug::TierUpAllModulesPerIsolate(Isolate* v8_isolate) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
isolate->wasm_engine()->TierUpAllModulesPerIsolate(isolate);
}
void debug::SetDebugDelegate(Isolate* v8_isolate, void debug::SetDebugDelegate(Isolate* v8_isolate,
debug::DebugDelegate* delegate) { debug::DebugDelegate* delegate) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
......
...@@ -217,6 +217,7 @@ V8_EXPORT_PRIVATE void SetDebugDelegate(Isolate* isolate, ...@@ -217,6 +217,7 @@ V8_EXPORT_PRIVATE void SetDebugDelegate(Isolate* isolate,
DebugDelegate* listener); DebugDelegate* listener);
V8_EXPORT_PRIVATE void TierDownAllModulesPerIsolate(Isolate* isolate); V8_EXPORT_PRIVATE void TierDownAllModulesPerIsolate(Isolate* isolate);
V8_EXPORT_PRIVATE void TierUpAllModulesPerIsolate(Isolate* isolate);
class AsyncEventDelegate { class AsyncEventDelegate {
public: public:
......
...@@ -147,6 +147,7 @@ void V8Debugger::disable() { ...@@ -147,6 +147,7 @@ void V8Debugger::disable() {
m_taskWithScheduledBreakPauseRequested = false; m_taskWithScheduledBreakPauseRequested = false;
m_pauseOnNextCallRequested = false; m_pauseOnNextCallRequested = false;
m_pauseOnAsyncCall = false; m_pauseOnAsyncCall = false;
v8::debug::TierUpAllModulesPerIsolate(m_isolate);
v8::debug::SetDebugDelegate(m_isolate, nullptr); v8::debug::SetDebugDelegate(m_isolate, nullptr);
m_isolate->RemoveNearHeapLimitCallback(&V8Debugger::nearHeapLimitCallback, m_isolate->RemoveNearHeapLimitCallback(&V8Debugger::nearHeapLimitCallback,
m_originalHeapLimit); m_originalHeapLimit);
......
...@@ -1430,21 +1430,23 @@ void RecompileNativeModule(Isolate* isolate, NativeModule* native_module, ...@@ -1430,21 +1430,23 @@ void RecompileNativeModule(Isolate* isolate, NativeModule* native_module,
} }
}); });
// The main thread contributes to the compilation, except if we need // For tier down only.
// deterministic compilation; in that case, the single background task will if (tier == ExecutionTier::kLiftoff) {
// execute all compilation. // The main thread contributes to the compilation, except if we need
if (!NeedsDeterministicCompile()) { // deterministic compilation; in that case, the single background task will
while (ExecuteCompilationUnits( // execute all compilation.
compilation_state->background_compile_token(), isolate->counters(), if (!NeedsDeterministicCompile()) {
kMainThreadTaskId, while (ExecuteCompilationUnits(
tier == ExecutionTier::kLiftoff ? kBaselineOnly : kBaselineOrTopTier)) { compilation_state->background_compile_token(), isolate->counters(),
// Continue executing compilation units. kMainThreadTaskId, kBaselineOnly)) {
// Continue executing compilation units.
}
} }
}
// Now wait until baseline recompilation finished. // Now wait until baseline recompilation finished.
recompilation_finished_semaphore->Wait(); recompilation_finished_semaphore->Wait();
DCHECK(!compilation_state->failed()); DCHECK(!compilation_state->failed());
}
} }
AsyncCompileJob::AsyncCompileJob( AsyncCompileJob::AsyncCompileJob(
...@@ -2522,9 +2524,8 @@ void CompilationStateImpl::InitializeRecompilation( ...@@ -2522,9 +2524,8 @@ void CompilationStateImpl::InitializeRecompilation(
{ {
base::MutexGuard guard(&callbacks_mutex_); base::MutexGuard guard(&callbacks_mutex_);
// Ensure that we don't trigger recompilation if another recompilation is // Restart recompilation if another recompilation is already happening.
// already happening. outstanding_recompilation_functions_ = 0;
DCHECK_EQ(0, outstanding_recompilation_functions_);
// If compilation hasn't started yet then code would be keep as tiered-down // If compilation hasn't started yet then code would be keep as tiered-down
// and don't need to recompile. // and don't need to recompile.
if (compilation_progress_.size() > 0) { if (compilation_progress_.size() > 0) {
......
...@@ -609,6 +609,20 @@ void WasmEngine::TierDownAllModulesPerIsolate(Isolate* isolate) { ...@@ -609,6 +609,20 @@ void WasmEngine::TierDownAllModulesPerIsolate(Isolate* isolate) {
} }
} }
void WasmEngine::TierUpAllModulesPerIsolate(Isolate* isolate) {
std::vector<NativeModule*> native_modules;
{
base::MutexGuard lock(&mutex_);
isolates_[isolate]->keep_tiered_down = false;
for (auto* native_module : isolates_[isolate]->native_modules) {
native_modules.push_back(native_module);
}
}
for (auto* native_module : native_modules) {
native_module->TierUp(isolate);
}
}
std::shared_ptr<NativeModule> WasmEngine::ExportNativeModule( std::shared_ptr<NativeModule> WasmEngine::ExportNativeModule(
Handle<WasmModuleObject> module_object) { Handle<WasmModuleObject> module_object) {
return module_object->shared_native_module(); return module_object->shared_native_module();
......
...@@ -198,6 +198,7 @@ class V8_EXPORT_PRIVATE WasmEngine { ...@@ -198,6 +198,7 @@ class V8_EXPORT_PRIVATE WasmEngine {
ExecutionTier tier); ExecutionTier tier);
void TierDownAllModulesPerIsolate(Isolate* isolate); void TierDownAllModulesPerIsolate(Isolate* isolate);
void TierUpAllModulesPerIsolate(Isolate* isolate);
// Exports the sharable parts of the given module object so that they can be // Exports the sharable parts of the given module object so that they can be
// transferred to a different Context/Isolate using the same engine. // transferred to a different Context/Isolate using the same engine.
......
...@@ -17,27 +17,46 @@ function create_builder(delta = 0) { ...@@ -17,27 +17,46 @@ function create_builder(delta = 0) {
return builder; return builder;
} }
function check(instance) { function checkTieredDown(instance) {
for (let i = 0; i < num_functions; ++i) { for (let i = 0; i < num_functions; ++i) {
assertTrue(%IsLiftoffFunction(instance.exports['f' + i])); assertTrue(%IsLiftoffFunction(instance.exports['f' + i]));
} }
} }
function checkTieredUp(instance) {
// Busy waiting until all functions are tiered up.
let num_liftoff_functions = 0;
while (true) {
num_liftoff_functions = 0;
for (let i = 0; i < num_functions; ++i) {
if (%IsLiftoffFunction(instance.exports['f' + i])) {
num_liftoff_functions++;
}
}
if (num_liftoff_functions == 0) return;
}
}
const instance = create_builder().instantiate(); const instance = create_builder().instantiate();
const Debug = new DebugWrapper(); const Debug = new DebugWrapper();
Debug.enable(); Debug.enable();
check(instance); checkTieredDown(instance);
const newInstance = create_builder(num_functions*2).instantiate(); const newInstance = create_builder(num_functions*2).instantiate();
check(newInstance); checkTieredDown(newInstance);
Debug.disable();
checkTieredUp(instance);
checkTieredUp(newInstance);
// Async. // Async.
async function testTierDownToLiftoffAsync() { async function testTierDownToLiftoffAsync() {
Debug.disable();
const asyncInstance = await create_builder(num_functions).asyncInstantiate(); const asyncInstance = await create_builder(num_functions).asyncInstantiate();
Debug.enable(); Debug.enable();
check(asyncInstance); checkTieredDown(asyncInstance);
const newAsyncInstance = await create_builder(num_functions*3).asyncInstantiate(); const newAsyncInstance = await create_builder(num_functions*3).asyncInstantiate();
check(newAsyncInstance); checkTieredDown(newAsyncInstance);
Debug.disable();
checkTieredUp(asyncInstance);
checkTieredUp(newAsyncInstance);
} }
assertPromiseResult(testTierDownToLiftoffAsync()); assertPromiseResult(testTierDownToLiftoffAsync());
...@@ -18,21 +18,37 @@ function create_builder(delta = 0) { ...@@ -18,21 +18,37 @@ function create_builder(delta = 0) {
return builder; return builder;
} }
function check(instance) { function checkTieredDown(instance) {
%WasmTierDownModule(instance);
for (let i = 0; i < num_functions; ++i) { for (let i = 0; i < num_functions; ++i) {
assertTrue(%IsLiftoffFunction(instance.exports['f' + i])); assertTrue(%IsLiftoffFunction(instance.exports['f' + i]));
} }
}
function checkTieredUp(instance) {
// Busy waiting until all functions are tiered up.
let num_liftoff_functions;
while (true) {
num_liftoff_functions = 0;
for (let i = 0; i < num_functions; ++i) {
if (%IsLiftoffFunction(instance.exports['f' + i])) {
num_liftoff_functions++;
}
}
if (num_liftoff_functions == 0) return;
}
}
function check(instance) {
%WasmTierDownModule(instance);
checkTieredDown(instance);
for (let i = 0; i < num_functions; ++i) { for (let i = 0; i < num_functions; ++i) {
%WasmTierUpFunction(instance, i); %WasmTierUpFunction(instance, i);
assertTrue(%IsLiftoffFunction(instance.exports['f' + i]));
} }
checkTieredDown(instance);
%WasmTierUpModule(instance); %WasmTierUpModule(instance);
for (let i = 0; i < num_functions; ++i) { checkTieredUp(instance);
assertFalse(%IsLiftoffFunction(instance.exports['f' + i]));
}
} }
(function testTierDownToLiftoff() { (function testTierDownToLiftoff() {
......
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