From b6132405f9f67cdebb1ad1f9349a51b4b76ab196 Mon Sep 17 00:00:00 2001 From: landerlyoung Date: Sat, 20 May 2023 15:44:36 +0800 Subject: [PATCH 1/2] Version 3.4.0 (2023-05): 1. `[V8]` **BEHAVIOR CHANGE:** `V8Platform` now being a singleton, not ref-counted by `V8Engine`s anymore. 2. `[V8]` add support for V8 version 11.4 3. `[V8]` add test support for V8 arm64 --- CHANGELOG.md | 12 +++++++++--- VERSION | 2 +- backend/V8/V8Engine.cc | 3 --- backend/V8/V8Platform.cc | 33 +++++++++++++++++++++++++------- backend/V8/V8Platform.h | 13 ++++++------- backend/V8/trait/TraitIncludes.h | 4 ++-- src/version.h | 6 +++--- test/cmake/TestEnv.cmake | 26 +++++++++++++++++++------ 8 files changed, 67 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6716540..7d41c568 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,13 @@ + +Version 3.4.0 (2023-05): +1. `[V8]` **BEHAVIOR CHANGE:** `V8Platform` now being a singleton, not ref-counted by `V8Engine`s any more. +2. `[V8]` add support for V8 version 11.4 +3. `[V8]` add test support for V8 arm64 + --- -Version 3.3.0 (2023-03): -[V8] add support for V8 version 10.8 -[V8] add support for node.js version 19.8.1 +Version 3.3.1 (2023-03): +1. `[V8]` add support for V8 version 10.8 +2. `[V8]` add support for node.js version 19.8.1 --- Version 3.3.0 (2023-03): diff --git a/VERSION b/VERSION index 712bd5a6..fbcbf738 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.3.1 \ No newline at end of file +3.4.0 \ No newline at end of file diff --git a/backend/V8/V8Engine.cc b/backend/V8/V8Engine.cc index b76b43c9..f04c3111 100644 --- a/backend/V8/V8Engine.cc +++ b/backend/V8/V8Engine.cc @@ -31,9 +31,6 @@ V8Engine::V8Engine(std::shared_ptr mq, const std::function& isolateFactory) : v8Platform_(V8Platform::getPlatform()), messageQueue_(mq ? std::move(mq) : std::make_shared()) { - // init v8 - v8::V8::Initialize(); - // create isolation if (isolateFactory) { isolate_ = isolateFactory(); diff --git a/backend/V8/V8Platform.cc b/backend/V8/V8Platform.cc index a55c7209..07138764 100644 --- a/backend/V8/V8Platform.cc +++ b/backend/V8/V8Platform.cc @@ -1,6 +1,6 @@ /* * Tencent is pleased to support the open source community by making ScriptX available. - * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -108,17 +108,21 @@ class MessageQueueTaskRunner : public v8::TaskRunner { V8Platform::EngineData::EngineData() : messageQueueRunner(std::make_shared()) {} -std::weak_ptr V8Platform::weakInstance_; +// lock_ should be declared before singletonInstance_ +// because singletonInstance_ depends on lock_ +// so the initialize order should be lock_ -> singletonInstance_ +// while the de-initialize order be singletonInstance_ -> lock_ +// reference: "Dynamic initialization' rule 3 +// https://en.cppreference.com/w/cpp/language/initialization std::mutex V8Platform::lock_; +std::shared_ptr V8Platform::singletonInstance_; std::shared_ptr V8Platform::getPlatform() { std::lock_guard lock(lock_); - auto ins = weakInstance_.lock(); - if (!ins) { - ins = std::shared_ptr(new V8Platform()); - weakInstance_ = ins; + if (!singletonInstance_) { + singletonInstance_ = std::shared_ptr(new V8Platform()); } - return ins; + return singletonInstance_; } void V8Platform::addEngineInstance(v8::Isolate* isolate, script::v8_backend::V8Engine* engine) { @@ -134,13 +138,28 @@ void V8Platform::removeEngineInstance(v8::Isolate* isolate) { } } +// the following comment from v8/src/init.cc AdvanceStartupState function +// the calling order are strongly enforced by v8 +// +// Ensure the following order: +// v8::V8::InitializePlatform(platform); +// v8::V8::Initialize(); +// v8::Isolate* isolate = v8::Isolate::New(...); +// ... +// isolate->Dispose(); +// v8::V8::Dispose(); +// v8::V8::DisposePlatform(); + V8Platform::V8Platform() : defaultPlatform_(v8::platform::NewDefaultPlatform()) { // constructor is called inside lock_guard of lock_ v8::V8::InitializePlatform(this); + v8::V8::Initialize(); } V8Platform::~V8Platform() { std::lock_guard lock(lock_); + v8::V8::Dispose(); + #if SCRIPTX_V8_VERSION_AT_LEAST(10, 0) v8::V8::DisposePlatform(); #else diff --git a/backend/V8/V8Platform.h b/backend/V8/V8Platform.h index a21873cd..161103bd 100644 --- a/backend/V8/V8Platform.h +++ b/backend/V8/V8Platform.h @@ -1,6 +1,6 @@ /* * Tencent is pleased to support the open source community by making ScriptX available. - * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -79,11 +79,7 @@ class V8Platform : public v8::Platform { return defaultPlatform_->GetTracingController(); } - v8::PageAllocator* GetPageAllocator() override { - // V8 has a bug around this, we always return null to use the default one - // return defaultPlatform_->GetPageAllocator(); - return nullptr; - } + v8::PageAllocator* GetPageAllocator() override { return defaultPlatform_->GetPageAllocator(); } // v8::Platform::PostJob, introduced since 8.4 // https://chromium.googlesource.com/v8/v8/+/05b6268126c1435d1c964ef81799728088b72c76 @@ -129,7 +125,7 @@ class V8Platform : public v8::Platform { private: static std::mutex lock_; - static std::weak_ptr weakInstance_; + static std::shared_ptr singletonInstance_; struct EngineData { // auto created in the default ctor @@ -140,6 +136,9 @@ class V8Platform : public v8::Platform { std::unordered_map engineMap_; public: + /** + * @return the VERY ONE AND ONLY platform + */ static std::shared_ptr getPlatform(); void addEngineInstance(v8::Isolate* isolate, V8Engine* engine); diff --git a/backend/V8/trait/TraitIncludes.h b/backend/V8/trait/TraitIncludes.h index ccadfc01..4c4458ab 100644 --- a/backend/V8/trait/TraitIncludes.h +++ b/backend/V8/trait/TraitIncludes.h @@ -1,6 +1,6 @@ /* * Tencent is pleased to support the open source community by making ScriptX available. - * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ #include "../V8Scope.h" #include "../V8Scope.hpp" -// intenal used marcos +// internal used marcos #undef SCRIPTX_V8_VERSION_AT_LEAST #undef SCRIPTX_V8_VERSION_AT_MOST #undef SCRIPTX_V8_VERSION_BETWEEN diff --git a/src/version.h b/src/version.h index 65c22883..3a16fc5f 100644 --- a/src/version.h +++ b/src/version.h @@ -19,10 +19,10 @@ // ScriptX version config files // auto generated from the file VERSION -#define SCRIPTX_VERSION_STRING "3.3.1" +#define SCRIPTX_VERSION_STRING "3.4.0" #define SCRIPTX_VERSION_MAJOR 3 -#define SCRIPTX_VERSION_MINOR 3 -#define SCRIPTX_VERSION_PATCH 1 +#define SCRIPTX_VERSION_MINOR 4 +#define SCRIPTX_VERSION_PATCH 0 namespace script { diff --git a/test/cmake/TestEnv.cmake b/test/cmake/TestEnv.cmake index 9f9398d9..1d582f2a 100644 --- a/test/cmake/TestEnv.cmake +++ b/test/cmake/TestEnv.cmake @@ -56,12 +56,26 @@ if (${SCRIPTX_BACKEND} STREQUAL V8) "${SCRIPTX_TEST_LIBS}/v8/mac/include" CACHE STRING "" FORCE) elseif (APPLE) - set(DEVOPS_LIBS_INCLUDE - "${SCRIPTX_TEST_LIBS}/v8/mac/include" - CACHE STRING "" FORCE) - set(DEVOPS_LIBS_LIBPATH - "${SCRIPTX_TEST_LIBS}/v8/mac/libv8_monolith.a" - CACHE STRING "" FORCE) + if (CMAKE_SYSTEM_PROCESSOR STREQUAL arm64) + set(DEVOPS_LIBS_INCLUDE + "${SCRIPTX_TEST_LIBS}/v8/mac_arm64/include" + CACHE STRING "" FORCE) + set(DEVOPS_LIBS_LIBPATH + "${SCRIPTX_TEST_LIBS}/v8/mac_arm64/libv8_monolith.a" + CACHE STRING "" FORCE) + set(DEVOPS_LIBS_MARCO + V8_COMPRESS_POINTERS + V8_ATOMIC_OBJECT_FIELD_WRITES + V8_SHARED_RO_HEAP + CACHE STRING "" FORCE) + else () + set(DEVOPS_LIBS_INCLUDE + "${SCRIPTX_TEST_LIBS}/v8/mac/include" + CACHE STRING "" FORCE) + set(DEVOPS_LIBS_LIBPATH + "${SCRIPTX_TEST_LIBS}/v8/mac/libv8_monolith.a" + CACHE STRING "" FORCE) + endif () elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux") # v8 8.8 set(DEVOPS_LIBS_INCLUDE From 0d846c1be3b93440c0b79e8ae0d60c093260b6cb Mon Sep 17 00:00:00 2001 From: landerlyoung Date: Sat, 20 May 2023 15:59:31 +0800 Subject: [PATCH 2/2] update GitHub action "Mirror to Tencent Code" --- .github/workflows/sync_to_tencent_code.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sync_to_tencent_code.yml b/.github/workflows/sync_to_tencent_code.yml index 254bdd93..a18ad9c3 100644 --- a/.github/workflows/sync_to_tencent_code.yml +++ b/.github/workflows/sync_to_tencent_code.yml @@ -9,12 +9,13 @@ jobs: timeout-minutes: 30 runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 - name: mirror-repository - uses: spyoungtech/mirror-action@v0.4.3 + uses: spyoungtech/mirror-action@v0.6.0 with: REMOTE: 'https://git.code.tencent.com/Tencent_Open_Source/ScriptX.git' GIT_USERNAME: ${{ secrets.TENCENT_CODE_GIT_USERNAME }} GIT_PASSWORD: ${{ secrets.TENCENT_CODE_GIT_PASSWORD }} + DEBUG: true