1 /*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "common_components/heap/space/to_space.h"
17 #include "common_components/heap/space/old_space.h"
18 #if defined(COMMON_SANITIZER_SUPPORT)
19 #include "common_components/base/asan_interface.h"
20 #endif
21
22 namespace common {
DumpRegionStats() const23 void ToSpace::DumpRegionStats() const
24 {
25 size_t tlToRegions = tlToRegionList_.GetRegionCount();
26 size_t tlToUnits = tlToRegionList_.GetUnitCount();
27 size_t tlToSize = tlToUnits * RegionDesc::UNIT_SIZE;
28 size_t allocTLToSize = tlToRegionList_.GetAllocatedSize(false);
29
30 size_t fullToRegions = fullToRegionList_.GetRegionCount();
31 size_t fullToUnits = fullToRegionList_.GetUnitCount();
32 size_t fullToSize = fullToUnits * RegionDesc::UNIT_SIZE;
33 size_t allocfullToSize = fullToRegionList_.GetAllocatedSize();
34
35 size_t units = tlToUnits + fullToUnits;
36 VLOG(DEBUG, "\tto space units: %zu (%zu B)", units, units * RegionDesc::UNIT_SIZE);
37 VLOG(DEBUG, "\t thread-local to-regions %zu: %zu units (%zu B, alloc %zu)",
38 tlToRegions, tlToUnits, tlToSize, allocTLToSize);
39 VLOG(DEBUG, "\t full to-regions %zu: %zu units (%zu B, alloc %zu)",
40 fullToRegions, fullToUnits, fullToSize, allocfullToSize);
41 }
42
GetPromotedTo(OldSpace & mspace)43 void ToSpace::GetPromotedTo(OldSpace& mspace)
44 {
45 // release thread-local to-space regions as they will promote to old-space
46 AllocBufferVisitor visitor = [](AllocationBuffer& tlab) {
47 tlab.ClearRegion<AllocBufferType::TO>();
48 };
49 Heap::GetHeap().GetAllocator().VisitAllocBuffers(visitor);
50
51 mspace.PromoteRegionList(fullToRegionList_);
52 mspace.PromoteRegionList(tlToRegionList_);
53 }
54 } // namespace common
55