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) {
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,
debug::DebugDelegate* delegate) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
......
......@@ -217,6 +217,7 @@ V8_EXPORT_PRIVATE void SetDebugDelegate(Isolate* isolate,
DebugDelegate* listener);
V8_EXPORT_PRIVATE void TierDownAllModulesPerIsolate(Isolate* isolate);
V8_EXPORT_PRIVATE void TierUpAllModulesPerIsolate(Isolate* isolate);
class AsyncEventDelegate {
public:
......
......@@ -147,6 +147,7 @@ void V8Debugger::disable() {
m_taskWithScheduledBreakPauseRequested = false;
m_pauseOnNextCallRequested = false;
m_pauseOnAsyncCall = false;
v8::debug::TierUpAllModulesPerIsolate(m_isolate);
v8::debug::SetDebugDelegate(m_isolate, nullptr);
m_isolate->RemoveNearHeapLimitCallback(&V8Debugger::nearHeapLimitCallback,
m_originalHeapLimit);
......
......@@ -1430,21 +1430,23 @@ void RecompileNativeModule(Isolate* isolate, NativeModule* native_module,
}
});
// The main thread contributes to the compilation, except if we need
// deterministic compilation; in that case, the single background task will
// execute all compilation.
if (!NeedsDeterministicCompile()) {
while (ExecuteCompilationUnits(
compilation_state->background_compile_token(), isolate->counters(),
kMainThreadTaskId,
tier == ExecutionTier::kLiftoff ? kBaselineOnly : kBaselineOrTopTier)) {
// Continue executing compilation units.
// For tier down only.
if (tier == ExecutionTier::kLiftoff) {
// The main thread contributes to the compilation, except if we need
// deterministic compilation; in that case, the single background task will
// execute all compilation.
if (!NeedsDeterministicCompile()) {
while (ExecuteCompilationUnits(
compilation_state->background_compile_token(), isolate->counters(),
kMainThreadTaskId, kBaselineOnly)) {
// Continue executing compilation units.
}
}
}
// Now wait until baseline recompilation finished.
recompilation_finished_semaphore->Wait();
DCHECK(!compilation_state->failed());
// Now wait until baseline recompilation finished.
recompilation_finished_semaphore->Wait();
DCHECK(!compilation_state->failed());
}
}
AsyncCompileJob::AsyncCompileJob(
......@@ -2522,9 +2524,8 @@ void CompilationStateImpl::InitializeRecompilation(
{
base::MutexGuard guard(&callbacks_mutex_);
// Ensure that we don't trigger recompilation if another recompilation is
// already happening.
DCHECK_EQ(0, outstanding_recompilation_functions_);
// Restart recompilation if another recompilation is already happening.
outstanding_recompilation_functions_ = 0;
// If compilation hasn't started yet then code would be keep as tiered-down
// and don't need to recompile.
if (compilation_progress_.size() > 0) {
......
......@@ -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(
Handle<WasmModuleObject> module_object) {
return module_object->shared_native_module();
......
......@@ -198,6 +198,7 @@ class V8_EXPORT_PRIVATE WasmEngine {
ExecutionTier tier);
void TierDownAllModulesPerIsolate(Isolate* isolate);
void TierUpAllModulesPerIsolate(Isolate* isolate);
// Exports the sharable parts of the given module object so that they can be
// transferred to a different Context/Isolate using the same engine.
......
......@@ -17,27 +17,46 @@ function create_builder(delta = 0) {
return builder;
}
function check(instance) {
function checkTieredDown(instance) {
for (let i = 0; i < num_functions; ++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 Debug = new DebugWrapper();
Debug.enable();
check(instance);
checkTieredDown(instance);
const newInstance = create_builder(num_functions*2).instantiate();
check(newInstance);
checkTieredDown(newInstance);
Debug.disable();
checkTieredUp(instance);
checkTieredUp(newInstance);
// Async.
async function testTierDownToLiftoffAsync() {
Debug.disable();
const asyncInstance = await create_builder(num_functions).asyncInstantiate();
Debug.enable();
check(asyncInstance);
checkTieredDown(asyncInstance);
const newAsyncInstance = await create_builder(num_functions*3).asyncInstantiate();
check(newAsyncInstance);
checkTieredDown(newAsyncInstance);
Debug.disable();
checkTieredUp(asyncInstance);
checkTieredUp(newAsyncInstance);
}
assertPromiseResult(testTierDownToLiftoffAsync());
......@@ -18,21 +18,37 @@ function create_builder(delta = 0) {
return builder;
}
function check(instance) {
%WasmTierDownModule(instance);
function checkTieredDown(instance) {
for (let i = 0; i < num_functions; ++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) {
%WasmTierUpFunction(instance, i);
assertTrue(%IsLiftoffFunction(instance.exports['f' + i]));
}
checkTieredDown(instance);
%WasmTierUpModule(instance);
for (let i = 0; i < num_functions; ++i) {
assertFalse(%IsLiftoffFunction(instance.exports['f' + i]));
}
checkTieredUp(instance);
}
(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