代码拉取完成,页面将自动刷新
/*
* 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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。