mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-11-27 12:10:47 +00:00
Add concurrent FinalizeCallback machanism
Signed-off-by: xiongluo <xiongluo@huawei.com> Change-Id: I82114951fa719f71c03bac723896ae7496bb2f86
This commit is contained in:
parent
bcf11cf5a4
commit
e0aa63ca45
@ -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));
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -244,6 +244,9 @@ void JSThread::InvokeWeakNodeNativeFinalizeCallback()
|
||||
auto callback = callbackPair.first;
|
||||
(*callback)(callbackPair.second);
|
||||
}
|
||||
if (finalizeTaskCallback_ != nullptr) {
|
||||
finalizeTaskCallback_();
|
||||
}
|
||||
runningNativeFinalizeCallbacks_ = false;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user