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
4 changes: 2 additions & 2 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ jobs:
backends: [ V8, JavaScriptCore, QuickJs, Lua, Empty ]
build_type:
- Debug
#- Release
- Release
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
Expand Down Expand Up @@ -150,7 +150,7 @@ jobs:
backends: [ V8, JavaScriptCore, QuickJs, Lua, Empty ]
build_type:
- Debug
#- Release
- Release
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
Expand Down
8 changes: 3 additions & 5 deletions backend/JavaScriptCore/JscScope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@

namespace script::jsc_backend {

JscEngineScope::JscEngineScope(JscEngine& engine)
: unlockPrevious_(&engine), lockGuard_(*engine.virtualMachineLock_) {}
JscEngineScope::JscEngineScope(JscEngine& engine, JscEngine* previous)
: unlockPrevious_(&engine, previous), lockGuard_(*engine.virtualMachineLock_) {}

void JscEngineScope::UnlockPrevious_Ctor(JscEngine* currentEngine,
JscEngineScope::UnlockPrevious& u) {
// we are building new frame, so "current" is actually the previous frame.
auto previous = ::script::EngineScope::currentEngineAs<JscEngine>();
JscEngineScope::UnlockPrevious& u, JscEngine* previous) {
if (previous && previous != currentEngine) {
u.previousEngine_ = previous;
previous->virtualMachineLock_->unlock();
Expand Down
8 changes: 4 additions & 4 deletions backend/JavaScriptCore/JscScope.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class JscEngineScope {
struct UnlockPrevious {
JscEngine* previousEngine_;

explicit UnlockPrevious(JscEngine* currentEngine) : previousEngine_() {
UnlockPrevious_Ctor(currentEngine, *this);
explicit UnlockPrevious(JscEngine* currentEngine, JscEngine* previous) : previousEngine_() {
UnlockPrevious_Ctor(currentEngine, *this, previous);
}

~UnlockPrevious() { UnlockPrevious_Dtor(*this); }
Expand All @@ -40,12 +40,12 @@ class JscEngineScope {
std::lock_guard<std::recursive_mutex> lockGuard_;

public:
explicit JscEngineScope(JscEngine&);
explicit JscEngineScope(JscEngine&, JscEngine*);

~JscEngineScope();

private:
static void UnlockPrevious_Ctor(JscEngine* engine, UnlockPrevious&);
static void UnlockPrevious_Ctor(JscEngine* engine, UnlockPrevious&, JscEngine* previous);

static void UnlockPrevious_Dtor(UnlockPrevious&);
};
Expand Down
4 changes: 2 additions & 2 deletions backend/Lua/LuaScope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ StackFrameScopeImpl::~StackFrameScopeImpl() {
}
}

EngineScopeImpl::EngineScopeImpl(LuaEngine &engine) : lockGuard_(engine.lock_), stack_(engine) {
auto prevEngine = EngineScope::currentEngineAs<LuaEngine>();
EngineScopeImpl::EngineScopeImpl(LuaEngine &engine, LuaEngine *prevEngine)
: lockGuard_(engine.lock_), stack_(engine) {
if (prevEngine && prevEngine != stack_.engine_) {
prevEngine_ = prevEngine;
prevEngine->lock_.unlock();
Expand Down
2 changes: 1 addition & 1 deletion backend/Lua/trait/TraitScope.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class EngineScopeImpl {
StackFrameScopeImpl stack_;

public:
explicit EngineScopeImpl(LuaEngine &);
explicit EngineScopeImpl(LuaEngine &, LuaEngine *);

~EngineScopeImpl();
};
Expand Down
12 changes: 7 additions & 5 deletions backend/QuickJs/QjsEngine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,15 @@ QjsEngine::QjsEngine(std::shared_ptr<utils::MessageQueue> queue, const QjsFactor
: queue_(queue ? std::move(queue) : std::make_shared<utils::MessageQueue>()) {
if (factory) {
std::tie(runtime_, context_) = factory();
assert(runtime_);
assert(context_);
} else {
runtime_ = JS_NewRuntime();
assert(runtime_);
context_ = JS_NewContext(runtime_);
assert(context_);
if (runtime_) {
context_ = JS_NewContext(runtime_);
}
}

if (!runtime_ || !context_) {
throw std::logic_error("QjsEngine: runtime or context is nullptr");
}

initEngineResource();
Expand Down
4 changes: 2 additions & 2 deletions backend/QuickJs/QjsScope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

namespace script::qjs_backend {

EngineScopeImpl::EngineScopeImpl(QjsEngine &current)
: previous_(EngineScope::currentEngineAs<QjsEngine>()), current_(&current) {
EngineScopeImpl::EngineScopeImpl(QjsEngine &current, QjsEngine *prev)
: previous_(prev), current_(&current) {
if (previous_) {
previous_->runtimeLock_.unlock();
}
Expand Down
2 changes: 1 addition & 1 deletion backend/QuickJs/trait/TraitScope.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class EngineScopeImpl {
QjsEngine *current_;

public:
explicit EngineScopeImpl(QjsEngine &);
explicit EngineScopeImpl(QjsEngine &, QjsEngine *);

~EngineScopeImpl();
};
Expand Down
2 changes: 1 addition & 1 deletion backend/Template/trait/TraitScope.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace template_backend {

class EngineScopeImpl {
public:
explicit EngineScopeImpl(TemplateEngine &) {
explicit EngineScopeImpl(TemplateEngine &, TemplateEngine *) {
// enter engine;
}

Expand Down
2 changes: 1 addition & 1 deletion backend/V8/V8Scope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

namespace script::v8_backend {

V8EngineScope::V8EngineScope(V8Engine& engine)
V8EngineScope::V8EngineScope(V8Engine& engine, V8Engine*)
: locker_(engine.isolate_),
isolateScope_(engine.isolate_),
handleScope_(engine.isolate_),
Expand Down
2 changes: 1 addition & 1 deletion backend/V8/V8Scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class V8EngineScope {
v8::Context::Scope contextScope_;

public:
explicit V8EngineScope(V8Engine& engine);
explicit V8EngineScope(V8Engine& engine, V8Engine* previous);

~V8EngineScope() = default;
};
Expand Down
2 changes: 1 addition & 1 deletion backend/WebAssembly/WasmScope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

namespace script::wasm_backend {

WasmEngineScope::WasmEngineScope(WasmEngine &) : stackTop_(-1) {
WasmEngineScope::WasmEngineScope(WasmEngine &, WasmEngine *) : stackTop_(-1) {
#ifdef __EMSCRIPTEN_PTHREADS__
if (wasm_backend::WasmEngine::engineThreadId_ != std::this_thread::get_id()) {
std::ostringstream oss;
Expand Down
2 changes: 1 addition & 1 deletion backend/WebAssembly/trait/TraitScope.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class WasmEngineScope {
int stackTop_;

public:
explicit WasmEngineScope(WasmEngine &);
explicit WasmEngineScope(WasmEngine &, WasmEngine *);

~WasmEngineScope() {
// restore stack top
Expand Down
10 changes: 5 additions & 5 deletions src/Scope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,14 @@ EngineScope::EngineScope(EngineImpl* engine)
static inline EngineScope*& currentScope() { return internal::getThreadLocal(current_); }

EngineScope::EngineScope(EngineScope::InternalEnterEngine, EngineImpl* engine, bool needEnter)
: needEnter_(needEnter && engine != nullptr && engine != currentEngine()),
engineScopeImpl_(),
engine_(engine),
prev_(currentScope()) {
: needEnter_(false), engineScopeImpl_(), engine_(engine), prev_(currentScope()) {
auto currentEngine = prev_ != nullptr ? prev_->engine_ : nullptr;
needEnter_ = needEnter && engine != nullptr && engine != currentEngine;
if (needEnter_) {
if (engine->isDestroying()) {
throw std::logic_error("enter EngineScope with a destroying ScriptEngine");
}
engineScopeImpl_.emplace(*engine);
engineScopeImpl_.emplace(*engine, currentEngine);
}

currentScope() = this;
Expand Down Expand Up @@ -86,6 +85,7 @@ ScriptEngine& EngineScope::currentEngineChecked() {

ExitEngineScope::ExitEngineScope()
: exitEngineScopeImpl_(EngineScope::currentEngineAs<EngineImpl>()),
// enters to a null engine, so EngineScope::currentEngine() == nullptr
nullEngineScope_(EngineScope::InternalEnterEngine{}, nullptr) {}

ExitEngineScope::ExitEngineHolder::ExitEngineHolder(ExitEngineScope::EngineImpl* engine)
Expand Down
2 changes: 1 addition & 1 deletion src/Scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class EngineScope final {
*
* class EngineScopeImpl {
* public:
* EngineScopeImpl(EngineImpl&) {
* EngineScopeImpl(EngineImpl& engine, EngineImpl* prev) {
* // enter engine;
* }
*
Expand Down
9 changes: 5 additions & 4 deletions src/utils/MessageQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

namespace script::utils {

struct ArbitraryData {
struct alignas(std::max_align_t) ArbitraryData {
/** arbitrary data */
int64_t data0 = 0;
int64_t data1 = 0;
Expand Down Expand Up @@ -163,8 +163,7 @@ class InplaceMessage : public Message {
throw std::runtime_error("inplaceObject can only be called once.");
}

auto buffer = static_cast<void*>(static_cast<ArbitraryData*>(this));
auto ptr = new (buffer) T(std::forward<Args>(args)...);
auto ptr = new (alignedStorage()) T(std::forward<Args>(args)...);
cleanupProc = [](Message& self) {
reinterpret_cast<InplaceMessage&>(self).getObject<T>().~T();
};
Expand All @@ -173,12 +172,14 @@ class InplaceMessage : public Message {

template <typename T>
T& getObject() {
return *reinterpret_cast<T*>(static_cast<ArbitraryData*>(this));
return *static_cast<T*>(alignedStorage());
}

private:
InplaceMessage() = default;

void* alignedStorage() { return static_cast<void*>(static_cast<ArbitraryData*>(this)); }

friend class MessageQueue;

friend class MemoryPool<InplaceMessage>;
Expand Down
24 changes: 12 additions & 12 deletions test/cmake/TestEnv.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ if (${SCRIPTX_BACKEND} STREQUAL V8)
set(DEVOPS_LIBS_LIBPATH
"${SCRIPTX_TEST_LIBS}/linux64/v8/libv8_monolith.a"
CACHE STRING "" FORCE)
set(DEVOPS_LIBS_MARCO
V8_COMPRESS_POINTERS
set(DEVOPS_LIBS_MARCO
V8_COMPRESS_POINTERS
CACHE STRING "" FORCE)
elseif (WIN32)
set(DEVOPS_LIBS_INCLUDE
Expand Down Expand Up @@ -105,20 +105,20 @@ elseif (${SCRIPTX_BACKEND} STREQUAL JavaScriptCore)
CACHE STRING "" FORCE)
elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(DEVOPS_LIBS_INCLUDE
"${SCRIPTX_TEST_LIBS}/linux64/jsc/Headers"
"${SCRIPTX_TEST_LIBS}/linux64/jsc/Headers"
CACHE STRING "" FORCE)

set(DEVOPS_LIBS_LIBPATH
#"-Wl,--start-group"
#"-Wl,--start-group"
"${SCRIPTX_TEST_LIBS}/linux64/jsc/libJavaScriptCore.a"
"${SCRIPTX_TEST_LIBS}/linux64/jsc/libWTF.a"
"${SCRIPTX_TEST_LIBS}/linux64/jsc/libbmalloc.a"
"dl"
"icudata"
"icui18n"
"icuuc"
"atomic"
#"-Wl,--end-group"
"${SCRIPTX_TEST_LIBS}/linux64/jsc/libWTF.a"
"${SCRIPTX_TEST_LIBS}/linux64/jsc/libbmalloc.a"
"dl"
"icudata"
"icui18n"
"icuuc"
"atomic"
#"-Wl,--end-group"
CACHE STRING "" FORCE)
elseif (WIN32)
set(DEVOPS_LIBS_INCLUDE
Expand Down