1 /**
2 * Copyright (c) 2023 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 "card_handler.h"
17 #include "runtime/mem/gc/gc_barrier_set.h"
18 #include "runtime/mem/object_helpers-inl.h"
19 #include "runtime/mem/rem_set-inl.h"
20
21 namespace panda::mem {
Handle(CardTable::CardPtr cardPtr)22 bool CardHandler::Handle(CardTable::CardPtr cardPtr)
23 {
24 bool result = true;
25 auto *startAddress = ToVoidPtr(cardTable_->GetCardStartAddress(cardPtr));
26 LOG(DEBUG, GC) << "HandleCard card: " << cardTable_->GetMemoryRange(cardPtr);
27
28 // clear card before we process it, because parallel mutator thread can make a write and we would miss it
29 cardPtr->Clear();
30
31 ASSERT_DO(IsHeapSpace(PoolManager::GetMmapMemPool()->GetSpaceTypeForAddr(startAddress)),
32 std::cerr << "Invalid space type for the " << startAddress << std::endl);
33 auto *region = AddrToRegion(startAddress);
34 ASSERT(region != nullptr);
35 ASSERT(region->GetLiveBitmap() != nullptr);
36 auto *endAddress = ToVoidPtr(cardTable_->GetCardEndAddress(cardPtr));
37 auto visitor = [this, &result, startAddress, endAddress](void *mem) {
38 auto objectHeader = static_cast<ObjectHeader *>(mem);
39 if (objectHeader->ClassAddr<BaseClass>() != nullptr) {
40 // Class may be null when we are visiting a card and at the same time a new non-movable
41 // object is allocated in the memory region covered by the card.
42 result = HandleObject(objectHeader, startAddress, endAddress);
43 return result;
44 }
45 return true;
46 };
47 if (region->HasFlag(RegionFlag::IS_LARGE_OBJECT)) {
48 region->GetLiveBitmap()->CallForMarkedChunkInHumongousRegion<true>(ToVoidPtr(region->Begin()), visitor);
49 } else {
50 region->GetLiveBitmap()->IterateOverMarkedChunkInRangeInterruptible<true>(startAddress, endAddress, visitor);
51 }
52 return result;
53 }
54 } // namespace panda::mem
55