mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-10-07 08:03:29 +00:00
6e5a7e8362
details: 1. use hilog in ohos device 2. use panda logger in host issue: https://gitee.com/openharmony/ark_js_runtime/issues/I5FR5J Signed-off-by: wengchangcheng <wengchangcheng@huawei.com> Change-Id: I6f5de00751154bdb6aac3101515961a3a4432e80
157 lines
5.9 KiB
C++
157 lines
5.9 KiB
C++
/*
|
|
* Copyright (c) 2021 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.
|
|
*/
|
|
|
|
#ifndef ECMASCRIPT_MEM_PARALLEL_MARKER_H
|
|
#define ECMASCRIPT_MEM_PARALLEL_MARKER_H
|
|
|
|
#include "ecmascript/js_hclass.h"
|
|
#include "ecmascript/mem/gc_bitset.h"
|
|
#include "ecmascript/mem/object_xray.h"
|
|
#include "ecmascript/mem/slots.h"
|
|
#include "ecmascript/mem/work_manager.h"
|
|
|
|
namespace panda::ecmascript {
|
|
class Heap;
|
|
class Region;
|
|
class TaggedObject;
|
|
|
|
static constexpr uint32_t MAIN_THREAD_INDEX = 0;
|
|
|
|
class Marker {
|
|
public:
|
|
explicit Marker(Heap *heap);
|
|
virtual ~Marker() = default;
|
|
|
|
virtual void Initialize()
|
|
{
|
|
LOG_GC(DEBUG) << "Marker::Initialize do nothing";
|
|
}
|
|
|
|
void MarkRoots(uint32_t threadId);
|
|
void ProcessOldToNew(uint32_t threadId); // for HPPGC only semi mode
|
|
void ProcessOldToNew(uint32_t threadId, Region *region); // for SemiGC
|
|
void ProcessSnapshotRSet(uint32_t threadId); // for SemiGC
|
|
|
|
virtual void ProcessMarkStack([[maybe_unused]] uint32_t threadId)
|
|
{
|
|
LOG_GC(FATAL) << "can not call this method";
|
|
}
|
|
|
|
protected:
|
|
// non move
|
|
virtual inline void MarkObject([[maybe_unused]] uint32_t threadId, [[maybe_unused]] TaggedObject *object)
|
|
{
|
|
LOG_GC(FATAL) << "can not call this method";
|
|
}
|
|
|
|
virtual inline SlotStatus MarkObject([[maybe_unused]] uint32_t threadId, [[maybe_unused]] TaggedObject *object,
|
|
[[maybe_unused]] ObjectSlot slot) // move
|
|
{
|
|
LOG_GC(FATAL) << "can not call this method";
|
|
return SlotStatus::KEEP_SLOT;
|
|
}
|
|
|
|
virtual inline void HandleOldToNewRSet(uint32_t threadId, Region *region) = 0;
|
|
virtual inline void HandleRoots(uint32_t threadId, [[maybe_unused]] Root type, ObjectSlot slot) = 0;
|
|
virtual inline void HandleRangeRoots(uint32_t threadId, [[maybe_unused]] Root type, ObjectSlot start,
|
|
ObjectSlot end) = 0;
|
|
virtual inline void RecordWeakReference([[maybe_unused]] uint32_t threadId, [[maybe_unused]] JSTaggedType *ref)
|
|
{
|
|
LOG_GC(FATAL) << "can not call this method";
|
|
}
|
|
|
|
Heap *heap_ {nullptr};
|
|
ObjectXRay objXRay_ {nullptr};
|
|
WorkManager *workManager_ {nullptr};
|
|
};
|
|
|
|
class NonMovableMarker : public Marker {
|
|
public:
|
|
explicit NonMovableMarker(Heap *heap) : Marker(heap) {}
|
|
|
|
protected:
|
|
void ProcessMarkStack(uint32_t threadId) override;
|
|
inline void MarkObject(uint32_t threadId, TaggedObject *object) override;
|
|
inline void HandleRoots(uint32_t threadId, [[maybe_unused]] Root type, ObjectSlot slot) override;
|
|
inline void HandleRangeRoots(uint32_t threadId, [[maybe_unused]] Root type, ObjectSlot start,
|
|
ObjectSlot end) override;
|
|
|
|
inline void HandleOldToNewRSet(uint32_t threadId, Region *region) override;
|
|
inline void RecordWeakReference(uint32_t threadId, JSTaggedType *ref) override;
|
|
};
|
|
|
|
class MovableMarker : public Marker {
|
|
public:
|
|
explicit MovableMarker(Heap *heap) : Marker(heap) {}
|
|
|
|
protected:
|
|
inline void HandleRoots(uint32_t threadId, [[maybe_unused]] Root type, ObjectSlot slot) override;
|
|
inline void HandleRangeRoots(uint32_t threadId, [[maybe_unused]] Root type, ObjectSlot start,
|
|
ObjectSlot end) override;
|
|
virtual inline SlotStatus EvacuateObject(uint32_t threadId, TaggedObject *object, const MarkWord &markWord,
|
|
ObjectSlot slot) = 0;
|
|
|
|
inline void HandleOldToNewRSet(uint32_t threadId, Region *region) override;
|
|
|
|
inline uintptr_t AllocateDstSpace(uint32_t threadId, size_t size, bool &shouldPromote);
|
|
inline void UpdateForwardAddressIfSuccess(uint32_t threadId, TaggedObject *object, JSHClass *klass,
|
|
uintptr_t toAddress, size_t size, const MarkWord &markWord,
|
|
ObjectSlot slot, bool isPromoted = false);
|
|
inline bool UpdateForwardAddressIfFailed(TaggedObject *object, uintptr_t toAddress, size_t size, ObjectSlot slot);
|
|
};
|
|
|
|
class SemiGCMarker : public MovableMarker {
|
|
public:
|
|
explicit SemiGCMarker(Heap *heap) : MovableMarker(heap) {}
|
|
|
|
void Initialize() override;
|
|
|
|
protected:
|
|
void ProcessMarkStack(uint32_t threadId) override;
|
|
inline SlotStatus MarkObject(uint32_t threadId, TaggedObject *object, ObjectSlot slot) override;
|
|
inline SlotStatus EvacuateObject(uint32_t threadId, TaggedObject *object, const MarkWord &markWord,
|
|
ObjectSlot slot) override;
|
|
inline void RecordWeakReference(uint32_t threadId, JSTaggedType *ref) override;
|
|
|
|
private:
|
|
inline bool ShouldBePromoted(TaggedObject *object);
|
|
|
|
uintptr_t waterLine_ {0};
|
|
};
|
|
|
|
class CompressGCMarker : public MovableMarker {
|
|
public:
|
|
explicit CompressGCMarker(Heap *heap) : MovableMarker(heap) {}
|
|
void SetAppSpawn(bool flag)
|
|
{
|
|
isAppSpawn_ = flag;
|
|
}
|
|
|
|
protected:
|
|
void ProcessMarkStack(uint32_t threadId) override;
|
|
inline SlotStatus MarkObject(uint32_t threadId, TaggedObject *object, ObjectSlot slot) override;
|
|
|
|
inline SlotStatus EvacuateObject(uint32_t threadId, TaggedObject *object, const MarkWord &markWord,
|
|
ObjectSlot slot) override;
|
|
inline uintptr_t AllocateReadOnlySpace(size_t size);
|
|
inline void RecordWeakReference(uint32_t threadId, JSTaggedType *ref) override;
|
|
|
|
private:
|
|
bool isAppSpawn_ {false};
|
|
os::memory::Mutex mutex_;
|
|
};
|
|
} // namespace panda::ecmascript
|
|
#endif // ECMASCRIPT_MEM_PARALLEL_MARKER_H
|