Ai
52 Star 223 Fork 1.1K

OpenHarmony/arkcompiler_ets_runtime
关闭

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
sustaining_js_handle.cpp 3.47 KB
一键复制 编辑 原始数据 按行查看 历史
杨云飞 提交于 2025-05-15 14:27 +08:00 . context需求挑单
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ecmascript/sustaining_js_handle.h"
#include "ecmascript/jit/jit_thread.h"
#include "ecmascript/jit/jit_task.h"
namespace panda::ecmascript {
SustainingJSHandle::SustainingJSHandle(EcmaVM *vm) : vm_(vm)
{
vm_->AddSustainingJSHandle(this);
}
SustainingJSHandle::~SustainingJSHandle()
{
vm_->RemoveSustainingJSHandle(this);
for (auto block : handleBlocks_) {
delete block;
}
handleBlocks_.clear();
}
uintptr_t SustainingJSHandle::GetJsHandleSlot(const JitThread *jitThread, JSTaggedType value)
{
// new handle from jit current task sustaining jshandle
auto jitTask = jitThread->GetCurrentTask();
ASSERT(jitTask != nullptr);
auto sustainingJSHandle = jitTask->GetSustainingJSHandle();
ASSERT(sustainingJSHandle != nullptr);
return sustainingJSHandle->GetJsHandleSlot(value);
}
uintptr_t SustainingJSHandle::GetJsHandleSlot(JSTaggedType value)
{
if (blockNext_ == blockLimit_) {
Expand();
}
ASSERT(blockNext_ != blockLimit_);
*blockNext_ = value;
uintptr_t slot = reinterpret_cast<uintptr_t>(blockNext_);
blockNext_++;
return slot;
}
uintptr_t SustainingJSHandle::Expand()
{
auto block = new std::array<JSTaggedType, BLOCK_SIZE>();
handleBlocks_.push_back(block);
blockNext_ = &block->data()[0];
blockLimit_ = &block->data()[BLOCK_SIZE];
return reinterpret_cast<uintptr_t>(blockNext_);
}
void SustainingJSHandle::Iterate(RootVisitor &v)
{
size_t size = handleBlocks_.size();
for (size_t i = 0; i < size; ++i) {
auto block = handleBlocks_.at(i);
auto start = block->data();
auto end = (i != (size - 1)) ? &(block->data()[BLOCK_SIZE]) : blockNext_;
v.VisitRangeRoot(Root::ROOT_HANDLE, ObjectSlot(ToUintPtr(start)), ObjectSlot(ToUintPtr(end)));
}
}
void SustainingJSHandleList::AddSustainingJSHandle(SustainingJSHandle *sustainingJSHandle)
{
LockHolder lock(mutex_);
if (sustainingJSHandle == nullptr) {
return;
}
if (listHead_ == nullptr) {
listHead_ = sustainingJSHandle;
return;
}
sustainingJSHandle->next_ = listHead_;
listHead_->pre_ = sustainingJSHandle;
listHead_ = sustainingJSHandle;
}
void SustainingJSHandleList::RemoveSustainingJSHandle(SustainingJSHandle *sustainingJSHandle)
{
LockHolder lock(mutex_);
if (sustainingJSHandle == nullptr) {
return;
}
auto next = sustainingJSHandle->next_;
auto pre = sustainingJSHandle->pre_;
if (pre != nullptr) {
pre->next_ = next;
}
if (next != nullptr) {
next->pre_ = pre;
}
if (listHead_ == sustainingJSHandle) {
listHead_ = sustainingJSHandle->next_;
}
}
void SustainingJSHandleList::Iterate(RootVisitor &v)
{
LockHolder lock(mutex_);
for (auto handles = listHead_; handles != nullptr; handles = handles->next_) {
handles->Iterate(v);
}
}
} // namespace panda::ecmascript
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/openharmony/arkcompiler_ets_runtime.git
git@gitee.com:openharmony/arkcompiler_ets_runtime.git
openharmony
arkcompiler_ets_runtime
arkcompiler_ets_runtime
master

搜索帮助