v8/test/inspector/task-runner.cc

147 lines
4.6 KiB
C++
Raw Normal View History

// Copyright 2016 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.
#include "test/inspector/task-runner.h"
Reland "[include] Split out v8.h" This is a reland of d1b27019d3bf86360ea838c317f8505fac6d3a7e Fixes include: Adding missing file to bazel build Forward-declaring classing before friend-classing them to fix win/gcc Add missing v8-isolate.h include for vtune builds Original change's description: > [include] Split out v8.h > > This moves every single class/function out of include/v8.h into a > separate header in include/, which v8.h then includes so that > externally nothing appears to have changed. > > Every include of v8.h from inside v8 has been changed to a more > fine-grained include. > > Previously inline functions defined at the bottom of v8.h would call > private non-inline functions in the V8 class. Since that class is now > in v8-initialization.h and is rarely included (as that would create > dependency cycles), this is not possible and so those methods have been > moved out of the V8 class into the namespace v8::api_internal. > > None of the previous files in include/ now #include v8.h, which means > if embedders were relying on this transitive dependency then it will > give compile failures. > > v8-inspector.h does depend on v8-scripts.h for the time being to ensure > that Chrome continue to compile but that change will be reverted once > those transitive #includes in chrome are changed to include it directly. > > Full design: > https://docs.google.com/document/d/1rTD--I8hCAr-Rho1WTumZzFKaDpEp0IJ8ejZtk4nJdA/edit?usp=sharing > > Bug: v8:11965 > Change-Id: I53b84b29581632710edc80eb11f819c2097a2877 > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3097448 > Reviewed-by: Yang Guo <yangguo@chromium.org> > Reviewed-by: Camillo Bruni <cbruni@chromium.org> > Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> > Reviewed-by: Leszek Swirski <leszeks@chromium.org> > Reviewed-by: Michael Lippautz <mlippautz@chromium.org> > Commit-Queue: Dan Elphick <delphick@chromium.org> > Cr-Commit-Position: refs/heads/main@{#76424} Cq-Include-Trybots: luci.v8.try:v8_linux_vtunejit Bug: v8:11965 Change-Id: I99f5d3a73bf8fe25b650adfaf9567dc4e44a09e6 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3113629 Reviewed-by: Leszek Swirski <leszeks@chromium.org> Reviewed-by: Camillo Bruni <cbruni@chromium.org> Reviewed-by: Michael Lippautz <mlippautz@chromium.org> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> Reviewed-by: Simon Zünd <szuend@chromium.org> Commit-Queue: Dan Elphick <delphick@chromium.org> Cr-Commit-Position: refs/heads/main@{#76460}
2021-08-23 13:01:06 +00:00
#include "include/v8-exception.h"
#include "include/v8-local-handle.h"
#include "include/v8-primitive.h"
#include "src/flags/flags.h"
#include "src/init/v8.h"
#include "src/libplatform/default-platform.h"
#include "src/utils/locked-queue-inl.h"
#if !defined(_WIN32) && !defined(_WIN64)
#include <unistd.h>
#endif // !defined(_WIN32) && !defined(_WIN64)
namespace v8 {
namespace internal {
namespace {
void ReportUncaughtException(v8::Isolate* isolate,
const v8::TryCatch& try_catch) {
CHECK(try_catch.HasCaught());
v8::HandleScope handle_scope(isolate);
std::string message =
*v8::String::Utf8Value(isolate, try_catch.Message()->Get());
int line = try_catch.Message()
->GetLineNumber(isolate->GetCurrentContext())
.FromJust();
std::string source_line = *v8::String::Utf8Value(
isolate, try_catch.Message()
->GetSourceLine(isolate->GetCurrentContext())
.ToLocalChecked());
fprintf(stderr, "Unhandled exception: %s @%s[%d]\n", message.data(),
source_line.data(), line);
}
} // namespace
TaskRunner::TaskRunner(
InspectorIsolateData::SetupGlobalTasks setup_global_tasks,
CatchExceptions catch_exceptions, v8::base::Semaphore* ready_semaphore,
v8::StartupData* startup_data, WithInspector with_inspector)
: Thread(Options("Task Runner")),
setup_global_tasks_(std::move(setup_global_tasks)),
startup_data_(startup_data),
with_inspector_(with_inspector),
catch_exceptions_(catch_exceptions),
ready_semaphore_(ready_semaphore),
data_(nullptr),
process_queue_semaphore_(0),
nested_loop_count_(0),
is_terminated_(0) {
CHECK(Start());
}
TaskRunner::~TaskRunner() {}
void TaskRunner::Run() {
data_.reset(new InspectorIsolateData(this, std::move(setup_global_tasks_),
startup_data_, with_inspector_));
if (ready_semaphore_) ready_semaphore_->Signal();
RunMessageLoop(false);
}
void TaskRunner::RunMessageLoop(bool only_protocol) {
int loop_number = ++nested_loop_count_;
while (nested_loop_count_ == loop_number && !is_terminated_) {
std::unique_ptr<TaskRunner::Task> task = GetNext(only_protocol);
if (!task) return;
v8::Isolate::Scope isolate_scope(isolate());
v8::TryCatch try_catch(isolate());
if (catch_exceptions_ == kStandardPropagateUncaughtExceptions) {
try_catch.SetVerbose(true);
}
task->Run(data_.get());
if (catch_exceptions_ == kFailOnUncaughtExceptions &&
try_catch.HasCaught()) {
ReportUncaughtException(isolate(), try_catch);
base::OS::ExitProcess(0);
}
try_catch.Reset();
task.reset();
// Also pump isolate's foreground task queue to ensure progress.
// This can be removed once https://crbug.com/v8/10747 is fixed.
// TODO(10748): Enable --stress-incremental-marking after the existing
// tests are fixed.
if (!i::v8_flags.stress_incremental_marking) {
while (v8::platform::PumpMessageLoop(
Reland "[wasm][inspector][test] Add more tests for code offsets" This is a reland of 4719dae1a4ab2067120cf0dbab89514adf662b73. The "V8 Linux64 TSAN - stress-incremental-marking" bot adds the --stress-incremental-marking flag for all variants, hence the SKIP in the status file was not triggered. We just explicitly disable the --stress-incremental-marking flag for the two new tests. This works for the "stress_incremental_marking" variant as well as the specific bot. Original change's description: > [wasm][inspector][test] Add more tests for code offsets > > The code offsets are sometimes wrong when compiled with streaming > compilation. Thus add more tests for synchronous, asynchronous, and > streaming compilation. The reported code offsets should all match. This > will be fixed in a follow-up CL. > > In order to make asynchronous WebAssembly compilation finish, the > inspector-test executable needs to pump the message loop before waiting > for new tasks to come in, just as other executables like d8. > This is added in this CL, but because of another bug this is skipped in > the stress-incremental-marking variant. Hence the new tests are also > skipped there. > > R=szuend@chromium.org > CC=ahaas@chromium.org > > Bug: chromium:1150303, v8:10748 > Change-Id: Ie1d63c8d6795e61627d838b7fa7b21e6728befc0 > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2562382 > Reviewed-by: Andreas Haas <ahaas@chromium.org> > Commit-Queue: Clemens Backes <clemensb@chromium.org> > Cr-Commit-Position: refs/heads/master@{#71483} Bug: chromium:1150303 Bug: v8:10748 Change-Id: I9adb9fc0250fab5c43dc85b695f4d338a9c7183c Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2565128 Reviewed-by: Andreas Haas <ahaas@chromium.org> Commit-Queue: Clemens Backes <clemensb@chromium.org> Cr-Commit-Position: refs/heads/master@{#71492}
2020-11-30 13:45:16 +00:00
v8::internal::V8::GetCurrentPlatform(), isolate(),
isolate()->HasPendingBackgroundTasks()
? platform::MessageLoopBehavior::kWaitForWork
: platform::MessageLoopBehavior::kDoNotWait)) {
}
}
}
}
static void RunMessageLoopInInterrupt(v8::Isolate* isolate, void* task_runner) {
TaskRunner* runner = reinterpret_cast<TaskRunner*>(task_runner);
runner->RunMessageLoop(true);
}
void TaskRunner::InterruptForMessages() {
isolate()->RequestInterrupt(&RunMessageLoopInInterrupt, this);
}
void TaskRunner::QuitMessageLoop() {
DCHECK_LT(0, nested_loop_count_);
--nested_loop_count_;
}
void TaskRunner::Append(std::unique_ptr<Task> task) {
queue_.Enqueue(std::move(task));
process_queue_semaphore_.Signal();
}
void TaskRunner::Terminate() {
is_terminated_++;
isolate()->TerminateExecution();
process_queue_semaphore_.Signal();
}
std::unique_ptr<TaskRunner::Task> TaskRunner::GetNext(bool only_protocol) {
for (;;) {
if (is_terminated_) return nullptr;
if (only_protocol) {
std::unique_ptr<Task> task;
if (queue_.Dequeue(&task)) {
if (task->is_priority_task()) return task;
deferred_queue_.Enqueue(std::move(task));
}
} else {
std::unique_ptr<Task> task;
if (deferred_queue_.Dequeue(&task)) return task;
if (queue_.Dequeue(&task)) return task;
}
process_queue_semaphore_.Wait();
}
}
} // namespace internal
} // namespace v8