Add concurrent FinalizeCallback machanism

Signed-off-by: xiongluo <xiongluo@huawei.com>
Change-Id: I82114951fa719f71c03bac723896ae7496bb2f86
This commit is contained in:
xiongluo 2024-04-08 11:16:39 +08:00
parent bcf11cf5a4
commit e0aa63ca45
6 changed files with 17 additions and 4 deletions

View File

@ -475,6 +475,7 @@ void EcmaVM::ProcessNativeDelete(const WeakRootVisitor &visitor)
{
if (!heap_->IsYoungGC()) {
auto iter = nativePointerList_.begin();
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "ProcessNativeDeleteNum:" + std::to_string(nativePointerList_.size()));
while (iter != nativePointerList_.end()) {
JSNativePointer *object = *iter;
auto fwd = visitor(reinterpret_cast<TaggedObject *>(object));
@ -529,7 +530,7 @@ void EcmaVM::ProcessReferences(const WeakRootVisitor &visitor)
heap_->ResetNativeBindingSize();
// array buffer
auto iter = nativePointerList_.begin();
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "ProcessNativeDeleteNum:" + std::to_string(nativePointerList_.size()));
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "ProcessReferencesNum:" + std::to_string(nativePointerList_.size()));
while (iter != nativePointerList_.end()) {
JSNativePointer *object = *iter;
auto fwd = visitor(reinterpret_cast<TaggedObject *>(object));

View File

@ -70,8 +70,6 @@ private:
void *externalPointer = GetExternalPointer();
DeleteEntryPoint deleter = GetDeleter();
if (deleter != nullptr) {
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "ExternalDelete"
+ std::to_string(reinterpret_cast<uintptr_t>(deleter)));
deleter(externalPointer, GetData());
}
}

View File

@ -244,6 +244,9 @@ void JSThread::InvokeWeakNodeNativeFinalizeCallback()
auto callback = callbackPair.first;
(*callback)(callbackPair.second);
}
if (finalizeTaskCallback_ != nullptr) {
finalizeTaskCallback_();
}
runningNativeFinalizeCallbacks_ = false;
}

View File

@ -1198,7 +1198,10 @@ public:
MutatorLock::MutatorLockState GetMutatorLockState() const;
void SetMutatorLockState(MutatorLock::MutatorLockState newState);
#endif
void SetWeakFinalizeTaskCallback(const WeakFinalizeTaskCallback &callback)
{
finalizeTaskCallback_ = callback;
}
private:
NO_COPY_SEMANTIC(JSThread);
NO_MOVE_SEMANTIC(JSThread);
@ -1267,6 +1270,7 @@ private:
WeakClearCallback nativeFinalizeCallBack)> setWeak_;
std::function<uintptr_t(uintptr_t nodeAddr)> clearWeak_;
std::function<bool(uintptr_t addr)> isWeak_;
WeakFinalizeTaskCallback finalizeTaskCallback_ {nullptr};
uint32_t globalNumberCount_ {0};
// Run-time state

View File

@ -89,6 +89,7 @@ struct HmsMap {
using Deleter = void (*)(void *nativePointer, void *data);
using WeakRefClearCallBack = void (*)(void *);
using WeakFinalizeTaskCallback = std::function<void()>;
using EcmaVM = ecmascript::EcmaVM;
using EcmaContext = ecmascript::EcmaContext;
using JSThread = ecmascript::JSThread;
@ -1358,6 +1359,7 @@ public:
static void SetpkgContextInfoList(EcmaVM *vm, const std::map<std::string,
std::vector<std::vector<std::string>>> &list);
static void SetLoop(EcmaVM *vm, void *loop);
static void SetWeakFinalizeTaskCallback(EcmaVM *vm, const WeakFinalizeTaskCallback &callback);
static std::string GetAssetPath(EcmaVM *vm);
static bool InitForConcurrentThread(EcmaVM *vm, ConcurrentCallback cb, void *data);
static bool InitForConcurrentFunction(EcmaVM *vm, Local<JSValueRef> func, void *taskInfo);

View File

@ -2866,6 +2866,11 @@ void JSNApi::SetLoop(EcmaVM *vm, void *loop)
vm->SetLoop(loop);
}
void JSNApi::SetWeakFinalizeTaskCallback(EcmaVM *vm, const WeakFinalizeTaskCallback &callback)
{
vm->GetAssociatedJSThread()->SetWeakFinalizeTaskCallback(callback);
}
std::string JSNApi::GetAssetPath(EcmaVM *vm)
{
return vm->GetAssetPath().c_str();