14514f5e3Sopenharmony_ci/* 24514f5e3Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License. 54514f5e3Sopenharmony_ci * You may obtain a copy of the License at 64514f5e3Sopenharmony_ci * 74514f5e3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84514f5e3Sopenharmony_ci * 94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and 134514f5e3Sopenharmony_ci * limitations under the License. 144514f5e3Sopenharmony_ci */ 154514f5e3Sopenharmony_ci 164514f5e3Sopenharmony_ci#ifndef ECMASCRIPT_MEM_SPACE_INL_H 174514f5e3Sopenharmony_ci#define ECMASCRIPT_MEM_SPACE_INL_H 184514f5e3Sopenharmony_ci 194514f5e3Sopenharmony_ci#include "ecmascript/mem/space.h" 204514f5e3Sopenharmony_ci 214514f5e3Sopenharmony_cinamespace panda::ecmascript { 224514f5e3Sopenharmony_civoid Space::AddRegion(Region *region) 234514f5e3Sopenharmony_ci{ 244514f5e3Sopenharmony_ci ASSERT(region != nullptr); 254514f5e3Sopenharmony_ci LOG_ECMA_MEM(DEBUG) << "Add region:" << region << " to " << ToSpaceTypeName(spaceType_); 264514f5e3Sopenharmony_ci regionList_.AddNode(region); 274514f5e3Sopenharmony_ci IncreaseCommitted(region->GetCapacity()); 284514f5e3Sopenharmony_ci IncreaseObjectSize(region->GetSize()); 294514f5e3Sopenharmony_ci} 304514f5e3Sopenharmony_ci 314514f5e3Sopenharmony_civoid Space::RemoveRegion(Region *region) 324514f5e3Sopenharmony_ci{ 334514f5e3Sopenharmony_ci LOG_ECMA_MEM(DEBUG) << "Remove region:" << region << " to " << ToSpaceTypeName(spaceType_); 344514f5e3Sopenharmony_ci regionList_.RemoveNode(region); 354514f5e3Sopenharmony_ci DecreaseCommitted(region->GetCapacity()); 364514f5e3Sopenharmony_ci DecreaseObjectSize(region->GetSize()); 374514f5e3Sopenharmony_ci} 384514f5e3Sopenharmony_ci 394514f5e3Sopenharmony_citemplate<class Callback> 404514f5e3Sopenharmony_civoid Space::EnumerateRegions(const Callback &cb, Region *end) const 414514f5e3Sopenharmony_ci{ 424514f5e3Sopenharmony_ci Region *current = regionList_.GetFirst(); 434514f5e3Sopenharmony_ci if (current == nullptr) { 444514f5e3Sopenharmony_ci return; 454514f5e3Sopenharmony_ci } 464514f5e3Sopenharmony_ci if (end == nullptr) { 474514f5e3Sopenharmony_ci end = regionList_.GetLast(); 484514f5e3Sopenharmony_ci } 494514f5e3Sopenharmony_ci while (current != end) { 504514f5e3Sopenharmony_ci auto next = current->GetNext(); 514514f5e3Sopenharmony_ci cb(current); 524514f5e3Sopenharmony_ci current = next; 534514f5e3Sopenharmony_ci } 544514f5e3Sopenharmony_ci 554514f5e3Sopenharmony_ci if (current != nullptr) { 564514f5e3Sopenharmony_ci cb(current); 574514f5e3Sopenharmony_ci } 584514f5e3Sopenharmony_ci} 594514f5e3Sopenharmony_ci 604514f5e3Sopenharmony_citemplate<class Callback> 614514f5e3Sopenharmony_civoid Space::EnumerateRegionsWithRecord(const Callback &cb) const 624514f5e3Sopenharmony_ci{ 634514f5e3Sopenharmony_ci if (recordRegion_ != nullptr) { 644514f5e3Sopenharmony_ci EnumerateRegions(cb, recordRegion_); 654514f5e3Sopenharmony_ci } 664514f5e3Sopenharmony_ci} 674514f5e3Sopenharmony_ci 684514f5e3Sopenharmony_ciRegionSpaceFlag Space::GetRegionFlag() const 694514f5e3Sopenharmony_ci{ 704514f5e3Sopenharmony_ci RegionSpaceFlag flags = RegionSpaceFlag::UNINITIALIZED; 714514f5e3Sopenharmony_ci switch (spaceType_) { 724514f5e3Sopenharmony_ci case MemSpaceType::OLD_SPACE: 734514f5e3Sopenharmony_ci case MemSpaceType::LOCAL_SPACE: 744514f5e3Sopenharmony_ci flags = RegionSpaceFlag::IN_OLD_SPACE; 754514f5e3Sopenharmony_ci break; 764514f5e3Sopenharmony_ci case MemSpaceType::EDEN_SPACE: 774514f5e3Sopenharmony_ci flags = RegionSpaceFlag::IN_EDEN_SPACE; 784514f5e3Sopenharmony_ci break; 794514f5e3Sopenharmony_ci case MemSpaceType::SEMI_SPACE: 804514f5e3Sopenharmony_ci flags = RegionSpaceFlag::IN_YOUNG_SPACE; 814514f5e3Sopenharmony_ci break; 824514f5e3Sopenharmony_ci case MemSpaceType::HUGE_OBJECT_SPACE: 834514f5e3Sopenharmony_ci flags = RegionSpaceFlag::IN_HUGE_OBJECT_SPACE; 844514f5e3Sopenharmony_ci break; 854514f5e3Sopenharmony_ci case MemSpaceType::MACHINE_CODE_SPACE: 864514f5e3Sopenharmony_ci flags = RegionSpaceFlag::IN_MACHINE_CODE_SPACE; 874514f5e3Sopenharmony_ci break; 884514f5e3Sopenharmony_ci case MemSpaceType::HUGE_MACHINE_CODE_SPACE: 894514f5e3Sopenharmony_ci flags = RegionSpaceFlag::IN_HUGE_MACHINE_CODE_SPACE; 904514f5e3Sopenharmony_ci break; 914514f5e3Sopenharmony_ci case MemSpaceType::NON_MOVABLE: 924514f5e3Sopenharmony_ci flags = RegionSpaceFlag::IN_NON_MOVABLE_SPACE; 934514f5e3Sopenharmony_ci break; 944514f5e3Sopenharmony_ci case MemSpaceType::SNAPSHOT_SPACE: 954514f5e3Sopenharmony_ci flags = RegionSpaceFlag::IN_SNAPSHOT_SPACE; 964514f5e3Sopenharmony_ci break; 974514f5e3Sopenharmony_ci case MemSpaceType::READ_ONLY_SPACE: 984514f5e3Sopenharmony_ci flags = RegionSpaceFlag::IN_READ_ONLY_SPACE; 994514f5e3Sopenharmony_ci break; 1004514f5e3Sopenharmony_ci case MemSpaceType::APPSPAWN_SPACE: 1014514f5e3Sopenharmony_ci flags = RegionSpaceFlag::IN_APPSPAWN_SPACE; 1024514f5e3Sopenharmony_ci break; 1034514f5e3Sopenharmony_ci case MemSpaceType::SHARED_APPSPAWN_SPACE: 1044514f5e3Sopenharmony_ci flags = RegionSpaceFlag::IN_SHARED_APPSPAWN_SPACE; 1054514f5e3Sopenharmony_ci break; 1064514f5e3Sopenharmony_ci case MemSpaceType::SHARED_NON_MOVABLE: 1074514f5e3Sopenharmony_ci flags = RegionSpaceFlag::IN_SHARED_NON_MOVABLE; 1084514f5e3Sopenharmony_ci break; 1094514f5e3Sopenharmony_ci case MemSpaceType::SHARED_OLD_SPACE: 1104514f5e3Sopenharmony_ci case MemSpaceType::SHARED_LOCAL_SPACE: 1114514f5e3Sopenharmony_ci case MemSpaceType::SHARED_COMPRESS_SPACE: 1124514f5e3Sopenharmony_ci flags = RegionSpaceFlag::IN_SHARED_OLD_SPACE; 1134514f5e3Sopenharmony_ci break; 1144514f5e3Sopenharmony_ci case MemSpaceType::SHARED_READ_ONLY_SPACE: 1154514f5e3Sopenharmony_ci flags = RegionSpaceFlag::IN_SHARED_READ_ONLY_SPACE; 1164514f5e3Sopenharmony_ci break; 1174514f5e3Sopenharmony_ci case MemSpaceType::SHARED_HUGE_OBJECT_SPACE: 1184514f5e3Sopenharmony_ci flags = RegionSpaceFlag::IN_SHARED_HUGE_OBJECT_SPACE; 1194514f5e3Sopenharmony_ci break; 1204514f5e3Sopenharmony_ci default: 1214514f5e3Sopenharmony_ci LOG_ECMA(FATAL) << "this branch is unreachable"; 1224514f5e3Sopenharmony_ci UNREACHABLE(); 1234514f5e3Sopenharmony_ci break; 1244514f5e3Sopenharmony_ci } 1254514f5e3Sopenharmony_ci return flags; 1264514f5e3Sopenharmony_ci} 1274514f5e3Sopenharmony_ci} // namespace panda::ecmascript 1284514f5e3Sopenharmony_ci#endif // ECMASCRIPT_MEM_SPACE_INL_H 129