Redesign the region flag setting and fix potential bugs within it.

Issue: https://gitee.com/openharmony/ark_js_runtime/issues/I590Z8

Signed-off-by: Yuqiang Xian <xianyuqiang@huawei.com>
This commit is contained in:
Yuqiang Xian 2022-06-01 11:38:56 +08:00
parent 24d55a2923
commit 948029ad0f
11 changed files with 39 additions and 43 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 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
@ -62,6 +62,10 @@ namespace panda::ecmascript {
#define ECMASCRIPT_ENABLE_ACTIVE_CPUPROFILER 0
#endif
#if ECMASCRIPT_ENABLE_ZAP_MEM
constexpr int INVALID_VALUE = 0x7;
#endif
#if defined(PANDA_TARGET_32)
#define ECMASCRIPT_DISABLE_CONCURRENT_MARKING 1
#else

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 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
@ -15,6 +15,8 @@
#include "ecmascript/dfx/hprof/string_hashmap.h"
#include "ecmascript/mem/native_area_allocator.h"
namespace panda::ecmascript {
CString *StringHashMap::FindOrInsertString(CString *string)
{

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 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
@ -665,6 +665,6 @@ bool Heap::IsAlive(TaggedObject *object) const
bool Heap::ContainObject(TaggedObject *object) const
{
Region *region = Region::ObjectAddressToRange(object);
return !region->IsReclaimed();
return region->IsValid();
}
} // namespace panda::ecmascript

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 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
@ -56,7 +56,6 @@ Region *HeapRegionAllocator::AllocateAlignedRegion(Space *space, size_t capacity
void HeapRegionAllocator::FreeRegion(Region *region)
{
auto size = region->GetCapacity();
region->SetReclaimed();
DecreaseAnnoMemoryUsage(size);
#if ECMASCRIPT_ENABLE_ZAP_MEM
if (memset_s(ToVoidPtr(region->GetAllocateBase()), size, INVALID_VALUE, size) != EOK) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 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
@ -61,9 +61,6 @@ private:
NO_COPY_SEMANTIC(HeapRegionAllocator);
NO_MOVE_SEMANTIC(HeapRegionAllocator);
#if ECMASCRIPT_ENABLE_ZAP_MEM
static constexpr int INVALID_VALUE = 0x7;
#endif
std::atomic<size_t> annoMemoryUsage_ {0};
std::atomic<size_t> maxAnnoMemoryUsage_ {0};
};

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 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
@ -149,9 +149,6 @@ private:
NO_COPY_SEMANTIC(NativeAreaAllocator);
NO_MOVE_SEMANTIC(NativeAreaAllocator);
#if ECMASCRIPT_ENABLE_ZAP_MEM
static constexpr int INVALID_VALUE = 0x7;
#endif
Area *cachedArea_ {nullptr};
std::atomic<size_t> nativeMemoryUsage_ {0};
std::atomic<size_t> maxNativeMemoryUsage_ {0};

View File

@ -20,6 +20,7 @@
#include "ecmascript/js_thread.h"
#include "ecmascript/mem/mem.h"
#include "ecmascript/mem/native_area_allocator.h"
namespace panda::ecmascript {
inline RememberedSet *Region::CreateRememberedSet()

View File

@ -18,7 +18,6 @@
#include "ecmascript/mem/free_object_list.h"
#include "ecmascript/mem/gc_bitset.h"
#include "ecmascript/mem/native_area_allocator.h"
#include "ecmascript/mem/remembered_set.h"
#include "securec.h"
@ -27,20 +26,22 @@ namespace ecmascript {
class JSThread;
enum RegionFlags {
NEVER_EVACUATE = 1,
HAS_AGE_MARK = 1 << 1,
BELOW_AGE_MARK = 1 << 2,
IN_YOUNG_SPACE = 1 << 3,
IN_SNAPSHOT_SPACE = 1 << 4,
IN_HUGE_OBJECT_SPACE = 1 << 5,
IN_OLD_SPACE = 1 << 6,
IN_NON_MOVABLE_SPACE = 1 << 7,
IN_MACHINE_CODE_SPACE = 1 << 8,
IN_COLLECT_SET = 1 << 9,
IN_NEW_TO_NEW_SET = 1 << 10,
HAS_BEEN_SWEPT = 1 << 11,
NEED_RELOCATE = 1 << 12,
INVALID = 1 << 13,
UNINITIALIZED = 0,
// We shuold avoid using the lower 3 bits.
// If ZAP_MEM is enabled, the value of the lower 3 bits conflicts with the INVALID_VALUE.
NEVER_EVACUATE = 1 << 3,
HAS_AGE_MARK = 1 << 4,
BELOW_AGE_MARK = 1 << 5,
IN_YOUNG_SPACE = 1 << 6,
IN_SNAPSHOT_SPACE = 1 << 7,
IN_HUGE_OBJECT_SPACE = 1 << 8,
IN_OLD_SPACE = 1 << 9,
IN_NON_MOVABLE_SPACE = 1 << 10,
IN_MACHINE_CODE_SPACE = 1 << 11,
IN_COLLECT_SET = 1 << 12,
IN_NEW_TO_NEW_SET = 1 << 13,
HAS_BEEN_SWEPT = 1 << 14,
NEED_RELOCATE = 1 << 15,
};
static inline bool IsFlagSet(uintptr_t flags, RegionFlags target)
@ -93,7 +94,6 @@ public:
Region(JSThread *thread, uintptr_t allocateBase, uintptr_t begin, uintptr_t end, RegionFlags flags)
: flags_(flags),
thread_(thread),
reclaimed_(false),
allocateBase_(allocateBase),
end_(end),
highWaterMark_(end),
@ -222,14 +222,14 @@ public:
return reinterpret_cast<Region *>(objAddress & ~DEFAULT_REGION_MASK);
}
bool IsReclaimed() const
bool IsValid() const
{
return reclaimed_;
}
void SetReclaimed()
{
reclaimed_ = true;
#if ECMASCRIPT_ENABLE_ZAP_MEM
if (flags_ == INVALID_VALUE) {
return false;
}
#endif
return flags_ != RegionFlags::UNINITIALIZED;
}
bool InYoungSpace() const
@ -489,7 +489,6 @@ private:
* and consequently, the region allocator, the spaces using the region allocator, etc.
*/
JSThread *thread_;
bool reclaimed_ {false};
uintptr_t allocateBase_;
uintptr_t end_;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 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
@ -72,7 +72,7 @@ void Space::EnumerateRegionsWithRecord(const Callback &cb) const
RegionFlags Space::GetRegionFlag() const
{
RegionFlags flags = RegionFlags::INVALID;
RegionFlags flags = RegionFlags::UNINITIALIZED;
switch (spaceType_) {
case MemSpaceType::OLD_SPACE:
case MemSpaceType::LOCAL_SPACE:

View File

@ -396,7 +396,6 @@ void OldSpace::RevertCSet()
void OldSpace::ReclaimCSet()
{
EnumerateCollectRegionSet([this](Region *region) {
region->SetFlag(RegionFlags::INVALID);
region->DeleteCrossRegionRSet();
region->DeleteOldToNewRSet();
region->DeleteSweepingRSet();

View File

@ -897,8 +897,6 @@ void SnapshotProcessor::DeserializeSpaceObject(uintptr_t beginAddr, Space* space
region->oldToNewSet_ = nullptr;
// thread_
region->thread_ = vm_->GetAssociatedJSThread();
// reclaimed_
region->reclaimed_ = false;
/*
* Reset flags according to the space type.