Fix basic debugging support. Upgrade to V8 8.4 (#15)

* Fix a couple of bugs around the inspector (crash on detach, hang on shutdown with debugger attached, etc.);
* Upgrade to V8 version 8.4;
This commit is contained in:
tudorms 2020-06-08 17:24:00 -07:00 коммит произвёл Julio C. Rocha
Родитель e04f5f2435
Коммит 09a7700a08
14 изменённых файлов: 135 добавлений и 93 удалений

Просмотреть файл

@ -10,6 +10,14 @@ steps:
arguments:
-Components Microsoft.VisualStudio.Component.VC.14.24.x86.x64
-Cleanup:$true
-Collect:$true
-OutputPath:${{parameters.outputPath}}
- task: PublishBuildArtifacts@1
displayName: "Publish vs logs"
inputs:
artifactName: VSLogs
pathtoPublish: ${{parameters.outputPath}}\vslogs.zip
- task: PowerShell@2
displayName: Download and extract depot_tools.zip

Просмотреть файл

@ -1,4 +1,4 @@
{
"version": "0.2.9",
"v8ref": "refs/branch-heads/8.3"
"version": "0.3.0",
"v8ref": "refs/branch-heads/8.4"
}

Просмотреть файл

@ -2,28 +2,31 @@
# Licensed under the MIT license.
param(
[string]$Platform = "x64", #"arm64",
[string]$Configuration = "Debug" # "UWP-Release" "Release-Clang"
[string]$Configuration = "Debug", # "UWP-Release" "Release-Clang"
[bool]$Setup = $true
)
$OutputPath = "$PSScriptRoot\out"
$SourcesPath = $PSScriptRoot
$Platforms = "x64", "x86", "arm64"
$Configurations = "Debug", "Release", "Release-Clang", "EXPERIMENTAL-libcpp-Clang"
$Platforms = "x64", "x86"#, "arm64"
$Configurations = "Debug", "Release", "UWP-Release"#, "Release-Clang", "EXPERIMENTAL-libcpp-Clang"
Write-Host "Downloading environment..."
& ".\scripts\download_depottools.ps1" -SourcesPath $SourcesPath
if ($Setup) {
Write-Host "Downloading environment..."
& ".\scripts\download_depottools.ps1" -SourcesPath $SourcesPath
if (!$?) {
Write-Host "Failed to download depot-tools"
exit 1
}
if (!$?) {
Write-Host "Failed to download depot-tools"
exit 1
}
Write-Host "Fetching code..."
& ".\scripts\fetch_code.ps1" -SourcesPath $SourcesPath -OutputPath $OutputPath -Configuration $Configuration
Write-Host "Fetching code..."
& ".\scripts\fetch_code.ps1" -SourcesPath $SourcesPath -OutputPath $OutputPath -Configuration $Configuration
if (!$?) {
Write-Host "Failed to retrieve the v8 code"
exit 1
if (!$?) {
Write-Host "Failed to retrieve the v8 code"
exit 1
}
}
if ($Platform -like "all") {

Просмотреть файл

@ -1,22 +1,15 @@
param (
[Parameter(Mandatory=$true)]
[string[]] $Components,
[uri] $InstallerUri = "https://download.visualstudio.microsoft.com/download/pr/c4fef23e-cc45-4836-9544-70e213134bc8/1ee5717e9a1e05015756dff77eb27d554a79a6db91f2716d836df368381af9a1/vs_Enterprise.exe",
[uri] $InstallerUri = "https://aka.ms/vs/16/release/vs_enterprise.exe",
[string] $VsInstaller = "${env:System_DefaultWorkingDirectory}\vs_Enterprise.exe",
[string] $VsInstallOutputDir = "${env:System_DefaultWorkingDirectory}\vs",
[System.IO.FileInfo] $VsInstallPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\Enterprise",
[System.IO.FileInfo] $VsInstallerPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer",
[switch] $Collect = $false,
[switch] $Cleanup = $false,
[switch] $UseWebInstaller = $false
[switch] $UseWebInstaller = $false,
[string] $OutputPath = "$PSScriptRoot\out"
)
$Components | ForEach-Object {
@ -74,6 +67,16 @@ if ($UseWebInstaller) {
}
} else {
Write-Host "Downloading latest Bootstrapper to update local installer..."
Invoke-WebRequest -Method Get -Uri $InstallerUri -OutFile $VsInstaller
Start-Process `
-FilePath "$VsInstaller" `
-ArgumentList ( '--update', '--wait', '--quiet' ) `
-Wait `
-PassThru
Write-Host "Running local installer to add requested components..."
Start-Process `
@ -102,6 +105,7 @@ if ($Collect) {
New-Item -ItemType Directory -Force ${env:System_DefaultWorkingDirectory}\vslogs
Expand-Archive -Path ${env:TEMP}\vslogs.zip -DestinationPath ${env:System_DefaultWorkingDirectory}\vslogs\
Copy-Item -Path ${env:TEMP}\vslogs.zip -Destination $OutputPath
Write-Host "VC versions after installation:"
Get-ChildItem -Name "$VsInstallPath\VC\Tools\MSVC\"

Просмотреть файл

@ -1,29 +1,26 @@
diff --git a/config/compiler/BUILD.gn b/config/compiler/BUILD.gn
index 5fa34150a..6e8ac6562 100644
index 01d97a360..6ee2813ef 100644
--- a/config/compiler/BUILD.gn
+++ b/config/compiler/BUILD.gn
@@ -1332,8 +1332,8 @@ config("default_warnings") {
@@ -1312,8 +1312,6 @@ config("default_warnings") {
"/wd4512", # Assignment operator could not be generated.
"/wd4610", # Class can never be instantiated, constructor required.
"/wd4838", # Narrowing conversion. Doesn't seem to be very useful.
- "/wd4995", # 'X': name was marked as #pragma deprecated
- "/wd4996", # Deprecated function warning.
+ #"/wd4995", # 'X': name was marked as #pragma deprecated
+ #"/wd4996", # Deprecated function warning.
# These are variable shadowing warnings that are new in VS2015. We
# should work through these at some point -- they may be removed from
@@ -1637,7 +1637,7 @@ config("no_chromium_code") {
@@ -1612,7 +1610,6 @@ config("no_chromium_code") {
"/W3", # Warning level 3.
"/wd4800", # Disable warning when forcing value to bool.
"/wd4267", # TODO(jschuh): size_t to int.
- "/wd4996", # Deprecated function warning.
+ #"/wd4996", # Deprecated function warning.
]
defines += [
"_CRT_NONSTDC_NO_WARNINGS",
diff --git a/config/win/BUILD.gn b/config/win/BUILD.gn
index 7b44f0e43..5eed0edc9 100644
index 7b44f0e43..3104dbd83 100644
--- a/config/win/BUILD.gn
+++ b/config/win/BUILD.gn
@@ -136,7 +136,12 @@ config("compiler") {
@ -49,10 +46,11 @@ index 7b44f0e43..5eed0edc9 100644
}
}
}
@@ -581,3 +586,10 @@ config("cygprofile_instrumentation") {
@@ -581,3 +586,11 @@ config("cygprofile_instrumentation") {
"-finstrument-functions-after-inlining",
]
}
+
+# Control Flow Guard (CFG)
+config("win_msvc_cfg") {
+ if (!is_clang && !is_debug) {
@ -61,7 +59,7 @@ index 7b44f0e43..5eed0edc9 100644
+ }
+}
diff --git a/toolchain/win/setup_toolchain.py b/toolchain/win/setup_toolchain.py
index fa31688f3..24e7deef9 100644
index 9c936c69d..7d483cf95 100644
--- a/toolchain/win/setup_toolchain.py
+++ b/toolchain/win/setup_toolchain.py
@@ -157,6 +157,8 @@ def _LoadToolchainEnv(cpu, sdk_dir, target_store):
@ -73,17 +71,3 @@ index fa31688f3..24e7deef9 100644
variables = _LoadEnvFromBat(args)
return _ExtractImportantEnvironment(variables)
@@ -279,10 +281,10 @@ def main():
print('include_flags_imsvc = ' + gn_helpers.ToGNString(include_imsvc))
assert vc_lib_path
print('vc_lib_path = ' + gn_helpers.ToGNString(vc_lib_path))
- if (target_store != True):
+ #if (target_store != True):
# Path is assumed to exist for desktop applications.
- assert vc_lib_atlmfc_path, ("Microsoft.VisualStudio.Component.VC.ATLMFC " +
- "is not found, check if it's installed.")
+ #assert vc_lib_atlmfc_path, ("Microsoft.VisualStudio.Component.VC.ATLMFC " +
+ # "is not found, check if it's installed.")
# Possible atlmfc library path gets introduced in the future for store thus
# output result if a result exists.
if (vc_lib_atlmfc_path != ''):

Просмотреть файл

@ -1,8 +1,8 @@
diff --git a/BUILD.gn b/BUILD.gn
index b2dde3f9d7..35d03d5e4b 100644
index 167e63503c..6ea5beaa99 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -3805,11 +3805,18 @@ v8_component("v8_libbase") {
@@ -3902,11 +3902,18 @@ v8_component("v8_libbase") {
defines += [ "_CRT_RAND_S" ] # for rand_s()
@ -26,9 +26,9 @@ index b2dde3f9d7..35d03d5e4b 100644
data_deps += [ "//build/win:runtime_libs" ]
}
@@ -4869,3 +4876,9 @@ if (!build_with_chromium && v8_use_perfetto) {
}
} # host_toolchain
@@ -5068,3 +5075,9 @@ if (!build_with_chromium && v8_use_perfetto) {
]
}
} # if (!build_with_chromium && v8_use_perfetto)
+
+group("jsi") {
@ -36,11 +36,12 @@ index b2dde3f9d7..35d03d5e4b 100644
+ "jsi:v8jsi",
+ ]
+}
\ No newline at end of file
diff --git a/DEPS b/DEPS
index 1bc687beaf..b4204381a5 100644
index 7b38c3dcd0..494a187ed9 100644
--- a/DEPS
+++ b/DEPS
@@ -538,4 +538,15 @@ hooks = [
@@ -540,4 +540,15 @@ hooks = [
'v8/tools/generate-header-include-checks.py',
],
},
@ -57,7 +58,7 @@ index 1bc687beaf..b4204381a5 100644
+ }
]
diff --git a/gni/snapshot_toolchain.gni b/gni/snapshot_toolchain.gni
index b5fb1823b3..01d81d45a6 100644
index b5fb1823b3..b5ddc1aba2 100644
--- a/gni/snapshot_toolchain.gni
+++ b/gni/snapshot_toolchain.gni
@@ -66,6 +66,9 @@ if (v8_snapshot_toolchain == "") {
@ -65,16 +66,16 @@ index b5fb1823b3..01d81d45a6 100644
# in combination with qemu
v8_snapshot_toolchain = current_toolchain
+ } else if (target_os == "winuwp") {
+ # cross compile UWP Windows with host toolchain (for x64 and x86)
+ v8_snapshot_toolchain = host_toolchain
+ # cross compile UWP Windows with host toolchain (for x64 and x86)
+ v8_snapshot_toolchain = host_toolchain
} else if (host_cpu == "x64") {
# This is a cross-compile from an x64 host to either a non-Intel target
# cpu or a different target OS. Clang will always be used by default on the
diff --git a/include/v8.h b/include/v8.h
index 9926b308b1..411b8fe863 100644
index 18d72f1630..fc47f43d1f 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -9092,6 +9092,11 @@ class V8_EXPORT Isolate {
@@ -9068,6 +9068,11 @@ class V8_EXPORT Isolate {
*/
MicrotasksPolicy GetMicrotasksPolicy() const;
@ -86,7 +87,7 @@ index 9926b308b1..411b8fe863 100644
/**
* Adds a callback to notify the host application after
* microtasks were run on the default MicrotaskQueue. The callback is
@@ -9118,6 +9123,10 @@ class V8_EXPORT Isolate {
@@ -9094,6 +9099,10 @@ class V8_EXPORT Isolate {
void RemoveMicrotasksCompletedCallback(
MicrotasksCompletedCallbackWithData callback, void* data = nullptr);
@ -182,10 +183,10 @@ index f3b9a753af..ed9c79a5b3 100644
// handling only unwind info for compatibility.
if (unhandled_exception_callback_g) {
diff --git a/src/snapshot/embedded/platform-embedded-file-writer-base.cc b/src/snapshot/embedded/platform-embedded-file-writer-base.cc
index 7a04a9dfab..4d734f4265 100644
index 1cd402d8ba..c3c9df8fa1 100644
--- a/src/snapshot/embedded/platform-embedded-file-writer-base.cc
+++ b/src/snapshot/embedded/platform-embedded-file-writer-base.cc
@@ -121,7 +121,7 @@ EmbeddedTargetOs ToEmbeddedTargetOs(const char* s) {
@@ -138,7 +138,7 @@ EmbeddedTargetOs ToEmbeddedTargetOs(const char* s) {
return EmbeddedTargetOs::kFuchsia;
} else if (string == "ios" || string == "mac") {
return EmbeddedTargetOs::kMac;
@ -195,10 +196,10 @@ index 7a04a9dfab..4d734f4265 100644
} else {
return EmbeddedTargetOs::kGeneric;
diff --git a/src/torque/declaration-visitor.cc b/src/torque/declaration-visitor.cc
index 5e3c8bbcb2..43f7770aa0 100644
index 6ec1b74df5..3fd90a1c8d 100644
--- a/src/torque/declaration-visitor.cc
+++ b/src/torque/declaration-visitor.cc
@@ -367,7 +367,9 @@ Callable* DeclarationVisitor::Specialize(
@@ -371,7 +371,9 @@ Callable* DeclarationVisitor::Specialize(
}
void PredeclarationVisitor::ResolvePredeclarations() {

Просмотреть файл

@ -25,7 +25,7 @@ target("shared_library", "v8jsi") {
"V8Platform.h",
]
cflags = [ "-DBOOST_ASIO_STANDALONE", "-DBOOST_ASIO_HEADER_ONLY" ]
cflags = [ "-DBOOST_ASIO_STANDALONE", "-DBOOST_ASIO_HEADER_ONLY", "-DUSE_DEFAULT_PLATFORM" ]
if (is_win) {
sources += [

Просмотреть файл

@ -83,13 +83,22 @@ class TaskRunnerAdapter : public v8::TaskRunner {
std::make_unique<TaskAdapter>(std::move(task)), delay_in_seconds);
}
bool IdleTasksEnabled() override {
return taskRunner_->IdleTasksEnabled();
}
void PostIdleTask(std::unique_ptr<v8::IdleTask> task) override {
taskRunner_->postIdleTask(
std::make_unique<IdleTaskAdapter>(std::move(task)));
}
bool IdleTasksEnabled() override {
return taskRunner_->IdleTasksEnabled();
void PostNonNestableTask(std::unique_ptr<v8::Task> task) override {
//TODO: non-nestable
taskRunner_->postTask(std::make_unique<TaskAdapter>(std::move(task)));
}
bool NonNestableTasksEnabled() const override {
return true;
}
private:
@ -456,7 +465,7 @@ v8::Isolate *V8Runtime::CreateNewIsolate() {
std::move(args_.foreground_task_runner));
isolate_->SetData(
v8runtime::ISOLATE_DATA_SLOT,
new v8runtime::IsolateData({&foreground_task_runner_, this}));
new v8runtime::IsolateData({foreground_task_runner_}));
v8::Isolate::Initialize(isolate_, create_params_);
@ -572,6 +581,12 @@ V8Runtime::V8Runtime(V8RuntimeArgs &&args) : args_(std::move(args)) {
}
V8Runtime::~V8Runtime() {
#ifdef _WIN32
if (inspector_agent_ && inspector_agent_->IsStarted()) {
inspector_agent_->stop();
}
#endif
host_object_constructor_.Reset();
context_.Reset();

Просмотреть файл

@ -22,8 +22,6 @@
#include <cstdlib>
#define USE_DEFAULT_PLATFORM
namespace v8runtime {
// Note : Counter implementation based on d8

Просмотреть файл

@ -193,6 +193,15 @@ WorkerThreadsTaskRunner::WorkerThreadsTaskRunner() {
std::thread(&WorkerThreadsTaskRunner::TimerFunc, this).detach();
}
void WorkerThreadsTaskRunner::Shutdown() {
// When this gets called, all threads are already shut down (we're tearing down the process and destroying the global V8Platform)
// TODO: Consider adding a "global runtime shutdown" API to JSI to fit V8's model
worker_stopped_ = true;
timer_stopped_ = true;
}
void WorkerThreadsTaskRunner::PostTask(std::unique_ptr<v8::Task> task) {
{
std::lock_guard<std::mutex> lock(queue_access_mutex_);
@ -225,6 +234,8 @@ void WorkerThreadsTaskRunner::PostDelayedTask(
}
void WorkerThreadsTaskRunner::WorkerFunc() {
worker_stopped_ = false;
while (true) {
std::unique_lock<std::mutex> lock(queue_access_mutex_);
tasks_available_cond_.wait(
@ -248,6 +259,8 @@ void WorkerThreadsTaskRunner::WorkerFunc() {
}
void WorkerThreadsTaskRunner::TimerFunc() {
timer_stopped_ = false;
while (true) {
std::unique_lock<std::mutex> delayed_lock(delayed_queue_access_mutex_);
delayed_tasks_available_cond_.wait(delayed_lock, [this]() {
@ -304,14 +317,15 @@ V8Platform::V8Platform(bool enable_tracing)
std::make_unique<ETWTracingController>(enable_tracing)),
worker_task_runner_(std::make_unique<WorkerThreadsTaskRunner>()) {}
V8Platform::~V8Platform() {}
V8Platform::~V8Platform() {
worker_task_runner_->Shutdown();
}
std::shared_ptr<v8::TaskRunner> V8Platform::GetForegroundTaskRunner(
v8::Isolate *isolate) {
IsolateData *isolate_data =
reinterpret_cast<IsolateData *>(isolate->GetData(ISOLATE_DATA_SLOT));
return *reinterpret_cast<std::shared_ptr<v8::TaskRunner> *>(
(isolate_data->foreground_task_runner_));
return isolate_data->foreground_task_runner_;
}
void V8Platform::CallOnWorkerThread(std::unique_ptr<v8::Task> task) {

Просмотреть файл

@ -16,6 +16,13 @@
namespace v8runtime {
constexpr int ISOLATE_DATA_SLOT = 0;
// Platform needs to map every isolate to this data.
struct IsolateData {
std::shared_ptr<v8::TaskRunner> foreground_task_runner_;
};
class ETWTracingController : public v8::TracingController {
public:
ETWTracingController(bool enabled) : enabled_(enabled) {}
@ -89,6 +96,8 @@ class WorkerThreadsTaskRunner : public v8::TaskRunner {
return false;
}
void Shutdown();
private:
void WorkerFunc();
void TimerFunc();
@ -125,11 +134,11 @@ class WorkerThreadsTaskRunner : public v8::TaskRunner {
// thread.
std::mutex worker_stopped_mutex_;
std::condition_variable worker_stopped_cond_;
bool worker_stopped_{false};
bool worker_stopped_{true};
std::mutex timer_stopped_mutex_;
std::condition_variable timer_stopped_cond_;
bool timer_stopped_{false};
bool timer_stopped_{true};
};
class V8Platform : public v8::Platform {

Просмотреть файл

@ -20,6 +20,8 @@
#include <random>
#include <algorithm>
#include "../V8Platform.h"
namespace inspector {
const char TAG_CONNECT[] = "#connect";
@ -411,6 +413,8 @@ void AgentImpl::Start() {
std::unique_ptr<InspectorAgentDelegate>(&delegate), port_);
server_ = &server;
state_ = State::kAccepting;
// This loops
if (!server.Start()) {
std::abort();
@ -531,7 +535,16 @@ void AgentImpl::PostIncomingMessage(
if (AppendMessage(
&incoming_message_queue_, session_id, Utf8ToStringView(message))) {
platform_.GetForegroundTaskRunner(isolate_)->PostTask(std::make_unique<DispatchOnInspectorBackendTask>(this));
std::shared_ptr<v8::TaskRunner> foregroundTaskRunner;
#ifdef USE_DEFAULT_PLATFORM
// Need to get the foreground runner from the isolate data slot
v8runtime::IsolateData* isolate_data = reinterpret_cast<v8runtime::IsolateData*>(isolate_->GetData(v8runtime::ISOLATE_DATA_SLOT));
foregroundTaskRunner = isolate_data->foreground_task_runner_;
#else
foregroundTaskRunner = platform_.GetForegroundTaskRunner(isolate_);
#endif
foregroundTaskRunner->PostTask(std::make_unique<DispatchOnInspectorBackendTask>(this));
isolate_->RequestInterrupt(InterruptCallback, this);
}
NotifyMessageReceived();

Просмотреть файл

@ -346,9 +346,14 @@ class WsHandler : public ProtocolHandler {
void CancelHandshake() override {}
void OnEof() override {
tcp_.reset();
if (dispose_)
if (tcp_)
{
tcp_.reset();
}
else if (dispose_)
{
delete this;
}
}
void OnData(std::vector<char>* data) override {

Просмотреть файл

@ -87,7 +87,7 @@ struct V8RuntimeArgs {
bool enableInspector{false};
bool waitForDebugger{false};
// chrome-devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=localhost:8888
// chrome-devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=localhost:9229
uint16_t inspectorPort{9229};
size_t initial_heap_size_in_bytes{0};
@ -103,16 +103,4 @@ __attribute__((visibility("default")))
#endif
std::unique_ptr<facebook::jsi::Runtime> __cdecl makeV8Runtime(V8RuntimeArgs &&args);
// TODO :: Following should go to a more private header
constexpr int ISOLATE_DATA_SLOT = 0;
// Platform needs to map every isolate to this data.
struct IsolateData {
void *foreground_task_runner_;
// Weak reference.
void *runtime_;
};
} // namespace v8runtime