Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/sync_to_tencent_code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 9 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.1
3.4.0
3 changes: 0 additions & 3 deletions backend/V8/V8Engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ V8Engine::V8Engine(std::shared_ptr<utils::MessageQueue> mq,
const std::function<v8::Isolate*()>& isolateFactory)
: v8Platform_(V8Platform::getPlatform()),
messageQueue_(mq ? std::move(mq) : std::make_shared<utils::MessageQueue>()) {
// init v8
v8::V8::Initialize();

// create isolation
if (isolateFactory) {
isolate_ = isolateFactory();
Expand Down
33 changes: 26 additions & 7 deletions backend/V8/V8Platform.cc
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -108,17 +108,21 @@ class MessageQueueTaskRunner : public v8::TaskRunner {
V8Platform::EngineData::EngineData()
: messageQueueRunner(std::make_shared<MessageQueueTaskRunner>()) {}

std::weak_ptr<V8Platform> 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> V8Platform::singletonInstance_;

std::shared_ptr<V8Platform> V8Platform::getPlatform() {
std::lock_guard<std::mutex> lock(lock_);
auto ins = weakInstance_.lock();
if (!ins) {
ins = std::shared_ptr<V8Platform>(new V8Platform());
weakInstance_ = ins;
if (!singletonInstance_) {
singletonInstance_ = std::shared_ptr<V8Platform>(new V8Platform());
}
return ins;
return singletonInstance_;
}

void V8Platform::addEngineInstance(v8::Isolate* isolate, script::v8_backend::V8Engine* engine) {
Expand All @@ -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<std::mutex> lock(lock_);
v8::V8::Dispose();

#if SCRIPTX_V8_VERSION_AT_LEAST(10, 0)
v8::V8::DisposePlatform();
#else
Expand Down
13 changes: 6 additions & 7 deletions backend/V8/V8Platform.h
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -129,7 +125,7 @@ class V8Platform : public v8::Platform {

private:
static std::mutex lock_;
static std::weak_ptr<V8Platform> weakInstance_;
static std::shared_ptr<V8Platform> singletonInstance_;

struct EngineData {
// auto created in the default ctor
Expand All @@ -140,6 +136,9 @@ class V8Platform : public v8::Platform {
std::unordered_map<v8::Isolate*, EngineData> engineMap_;

public:
/**
* @return the VERY ONE AND ONLY platform
*/
static std::shared_ptr<V8Platform> getPlatform();

void addEngineInstance(v8::Isolate* isolate, V8Engine* engine);
Expand Down
4 changes: 2 additions & 2 deletions backend/V8/trait/TraitIncludes.h
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
26 changes: 20 additions & 6 deletions test/cmake/TestEnv.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down