mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-11-23 18:20:04 +00:00
回退 'Pull Request !5088 : 增加JS对象native内存统计'
This commit is contained in:
parent
f07e9bdc4d
commit
4d9b0609fa
@ -403,7 +403,6 @@ void EcmaVM::ProcessNativeDelete(const WeakRootVisitor &visitor)
|
||||
JSNativePointer *object = *iter;
|
||||
auto fwd = visitor(reinterpret_cast<TaggedObject *>(object));
|
||||
if (fwd == nullptr) {
|
||||
nativeAreaAllocator_->DecreaseNativeSizeStats(object->GetBindingSize(), object->GetNativeFlag());
|
||||
object->Destroy();
|
||||
iter = nativePointerList_.erase(iter);
|
||||
} else {
|
||||
@ -428,7 +427,6 @@ void EcmaVM::ProcessReferences(const WeakRootVisitor &visitor)
|
||||
JSNativePointer *object = *iter;
|
||||
auto fwd = visitor(reinterpret_cast<TaggedObject *>(object));
|
||||
if (fwd == nullptr) {
|
||||
nativeAreaAllocator_->DecreaseNativeSizeStats(object->GetBindingSize(), object->GetNativeFlag());
|
||||
object->Destroy();
|
||||
iter = nativePointerList_.erase(iter);
|
||||
continue;
|
||||
@ -454,7 +452,6 @@ void EcmaVM::RemoveFromNativePointerList(JSNativePointer *pointer)
|
||||
auto iter = std::find(nativePointerList_.begin(), nativePointerList_.end(), pointer);
|
||||
if (iter != nativePointerList_.end()) {
|
||||
JSNativePointer *object = *iter;
|
||||
nativeAreaAllocator_->DecreaseNativeSizeStats(object->GetBindingSize(), object->GetNativeFlag());
|
||||
object->Destroy();
|
||||
nativePointerList_.erase(iter);
|
||||
}
|
||||
|
@ -18,7 +18,6 @@
|
||||
|
||||
#include "ecmascript/ecma_macros.h"
|
||||
#include "ecmascript/mem/tagged_object.h"
|
||||
#include "ecmascript/mem/native_area_allocator.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using DeleteEntryPoint = void (*)(void *, void *);
|
||||
@ -44,7 +43,6 @@ public:
|
||||
SetExternalPointer(nullptr);
|
||||
SetDeleter(nullptr);
|
||||
SetData(nullptr);
|
||||
SetNativeFlag(NativeFlag::NO_DIV);
|
||||
}
|
||||
|
||||
inline void Detach()
|
||||
@ -57,9 +55,8 @@ public:
|
||||
ACCESSORS_NATIVE_FIELD(ExternalPointer, void, POINTER_OFFSET, DELETER_OFFSET);
|
||||
ACCESSORS_PRIMITIVE_FIELD(Deleter, DeleteEntryPoint, DELETER_OFFSET, DATA_OFFSET)
|
||||
ACCESSORS_NATIVE_FIELD(Data, void, DATA_OFFSET, DATA_SIZE_OFFSET);
|
||||
ACCESSORS_PRIMITIVE_FIELD(BindingSize, uint64_t, DATA_SIZE_OFFSET, FLAG_OFFSET);
|
||||
// native memory statistic flag
|
||||
ACCESSORS_PRIMITIVE_FIELD(NativeFlag, NativeFlag, FLAG_OFFSET, LAST_OFFSET);
|
||||
ACCESSORS_PRIMITIVE_FIELD(BindingSize, uint64_t, DATA_SIZE_OFFSET, LAST_OFFSET)
|
||||
|
||||
DEFINE_ALIGN_SIZE(LAST_OFFSET);
|
||||
|
||||
DECL_VISIT_NATIVE_FIELD(POINTER_OFFSET, DATA_SIZE_OFFSET)
|
||||
|
@ -232,20 +232,12 @@ void JSThread::Iterate(const RootVisitor &visitor, const RootRangeVisitor &range
|
||||
if (vm_->GetJSOptions().EnableGlobalLeakCheck()) {
|
||||
IterateHandleWithCheck(visitor, rangeVisitor);
|
||||
} else {
|
||||
size_t globalCount = 0;
|
||||
globalStorage_->IterateUsageGlobal([visitor, &globalCount](Node *node) {
|
||||
globalStorage_->IterateUsageGlobal([visitor](Node *node) {
|
||||
JSTaggedValue value(node->GetObject());
|
||||
if (value.IsHeapObject()) {
|
||||
visitor(ecmascript::Root::ROOT_HANDLE, ecmascript::ObjectSlot(node->GetObjectAddress()));
|
||||
}
|
||||
globalCount++;
|
||||
});
|
||||
static bool hasCheckedGlobalCount = false;
|
||||
static const size_t WARN_GLOBAL_COUNT = 100000;
|
||||
if (!hasCheckedGlobalCount && globalCount >= WARN_GLOBAL_COUNT) {
|
||||
LOG_ECMA(WARN) << "Global reference count is " << globalCount << ",It exceed the upper limit 100000!";
|
||||
hasCheckedGlobalCount = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,6 @@ Area *Chunk::NewArea(size_t size)
|
||||
LOG_ECMA_MEM(FATAL) << "OOM Chunk : NewArea area is nullptr";
|
||||
UNREACHABLE();
|
||||
}
|
||||
allocator_->IncreaseNativeSizeStats(size, NativeFlag::CHUNK_MEM);
|
||||
areaList_.AddNode(area);
|
||||
currentArea_ = area;
|
||||
return area;
|
||||
@ -73,7 +72,6 @@ void Chunk::ReleaseMemory()
|
||||
{
|
||||
while (!areaList_.IsEmpty()) {
|
||||
Area *node = areaList_.PopBack();
|
||||
allocator_->DecreaseNativeSizeStats(node->GetSize(), NativeFlag::CHUNK_MEM);
|
||||
allocator_->FreeArea(node);
|
||||
}
|
||||
ptr_ = 0;
|
||||
|
@ -147,14 +147,8 @@ void GCStats::PrintGCMemoryStatistic()
|
||||
<< STATS_DESCRIPTION_FORMAT("Native memory usage size:")
|
||||
<< STATS_DATA_FORMAT(sizeToMB(nativeAreaAllocator->GetNativeMemoryUsage())) << "MB\n"
|
||||
<< STATS_DESCRIPTION_FORMAT("NativeBindingSize:")
|
||||
<< STATS_DATA_FORMAT(sizeToKB(heap_->GetNativeBindingSize())) << "KB\n"
|
||||
<< STATS_DESCRIPTION_FORMAT("ArrayBufferNativeSize:")
|
||||
<< STATS_DATA_FORMAT(sizeToKB(heap_->GetNativeAreaAllocator()->GetArrayBufferNativeSize()))
|
||||
<< "KB\n"
|
||||
<< STATS_DESCRIPTION_FORMAT("RegExpByteCodeNativeSize:")
|
||||
<< STATS_DATA_FORMAT(sizeToKB(heap_->GetNativeAreaAllocator()->GetRegExpNativeSize())) << "KB\n"
|
||||
<< STATS_DESCRIPTION_FORMAT("ChunkNativeSize:")
|
||||
<< STATS_DATA_FORMAT(sizeToKB(heap_->GetNativeAreaAllocator()->GetChunkNativeSize())) << "KB";
|
||||
<< STATS_DATA_FORMAT(sizeToKB(heap_->GetNativeBindingSize())) << "KB";
|
||||
|
||||
switch (gcType_) {
|
||||
case GCType::STW_YOUNG_GC: {
|
||||
double copiedRate = double(GetRecordData(RecordData::SEMI_ALIVE_SIZE)) /
|
||||
|
@ -44,7 +44,6 @@ class NativeAreaAllocator;
|
||||
class ParallelEvacuator;
|
||||
class PartialGC;
|
||||
class STWYoungGC;
|
||||
enum class NativeFlag : uint8_t;
|
||||
|
||||
using IdleNotifyStatusCallback = std::function<void(bool)>;
|
||||
|
||||
|
@ -25,16 +25,7 @@
|
||||
#include "ecmascript/mem/area.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
||||
enum class NativeFlag : uint8_t {
|
||||
NO_DIV,
|
||||
ARRAY_BUFFER,
|
||||
REGEXP_BTYECODE,
|
||||
CHUNK_MEM,
|
||||
};
|
||||
|
||||
class PUBLIC_API NativeAreaAllocator {
|
||||
|
||||
public:
|
||||
NativeAreaAllocator() = default;
|
||||
virtual ~NativeAreaAllocator()
|
||||
@ -111,69 +102,6 @@ public:
|
||||
return maxNativeMemoryUsage_.load(std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
size_t GetArrayBufferNativeSize() const
|
||||
{
|
||||
return arrayBufferNativeSize_;
|
||||
}
|
||||
|
||||
size_t GetRegExpNativeSize() const
|
||||
{
|
||||
return regExpNativeSize_;
|
||||
}
|
||||
|
||||
size_t GetChunkNativeSize() const
|
||||
{
|
||||
return chunkNativeSize_;
|
||||
}
|
||||
|
||||
void IncreaseNativeSizeStats(size_t size, NativeFlag flag)
|
||||
{
|
||||
if (size == 0 || flag == NativeFlag::NO_DIV) {
|
||||
return;
|
||||
}
|
||||
switch (flag) {
|
||||
case NativeFlag::ARRAY_BUFFER:
|
||||
arrayBufferNativeSize_ += size;
|
||||
break;
|
||||
case NativeFlag::REGEXP_BTYECODE:
|
||||
regExpNativeSize_ += size;
|
||||
break;
|
||||
case NativeFlag::CHUNK_MEM:
|
||||
chunkNativeSize_ += size;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void DecreaseNativeSizeStats(size_t size, NativeFlag flag)
|
||||
{
|
||||
if (size == 0 || flag == NativeFlag::NO_DIV) {
|
||||
return;
|
||||
}
|
||||
switch (flag) {
|
||||
case NativeFlag::ARRAY_BUFFER:
|
||||
arrayBufferNativeSize_ -= size;
|
||||
break;
|
||||
case NativeFlag::REGEXP_BTYECODE:
|
||||
regExpNativeSize_ -= size;
|
||||
break;
|
||||
case NativeFlag::CHUNK_MEM:
|
||||
chunkNativeSize_ -= size;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ModifyNativeSizeStats(size_t preSize, size_t nextSize, NativeFlag flag) {
|
||||
if (flag == NativeFlag::NO_DIV) {
|
||||
return;
|
||||
}
|
||||
DecreaseNativeSizeStats(preSize, flag);
|
||||
IncreaseNativeSizeStats(nextSize, flag);
|
||||
}
|
||||
|
||||
void *Allocate(size_t size)
|
||||
{
|
||||
if (size == 0) {
|
||||
@ -225,10 +153,6 @@ private:
|
||||
Area *cachedArea_ {nullptr};
|
||||
std::atomic<size_t> nativeMemoryUsage_ {0};
|
||||
std::atomic<size_t> maxNativeMemoryUsage_ {0};
|
||||
// native area size stats
|
||||
size_t arrayBufferNativeSize_ {0};
|
||||
size_t regExpNativeSize_ {0};
|
||||
size_t chunkNativeSize_ {0};
|
||||
};
|
||||
} // namespace panda::ecmascript
|
||||
|
||||
|
@ -73,8 +73,7 @@ JSHandle<JSNativePointer> ObjectFactory::NewJSNativePointer(void *externalPointe
|
||||
const DeleteEntryPoint &callBack,
|
||||
void *data,
|
||||
bool nonMovable,
|
||||
size_t nativeBindingsize,
|
||||
NativeFlag flag)
|
||||
size_t nativeBindingsize)
|
||||
{
|
||||
NewObjectHook();
|
||||
TaggedObject *header;
|
||||
@ -89,12 +88,9 @@ JSHandle<JSNativePointer> ObjectFactory::NewJSNativePointer(void *externalPointe
|
||||
obj->SetDeleter(callBack);
|
||||
obj->SetData(data);
|
||||
obj->SetBindingSize(nativeBindingsize);
|
||||
obj->SetNativeFlag(flag);
|
||||
|
||||
|
||||
if (callBack != nullptr) {
|
||||
if (flag == NativeFlag::NO_DIV) {
|
||||
heap_->IncreaseNativeBindingSize(nativeBindingsize);
|
||||
}
|
||||
heap_->IncreaseNativeBindingSize(nativeBindingsize);
|
||||
vm_->PushToNativePointerList(static_cast<JSNativePointer *>(header));
|
||||
}
|
||||
return obj;
|
||||
|
@ -243,8 +243,6 @@ void ObjectFactory::NewJSArrayBufferData(const JSHandle<JSArrayBuffer> &array, i
|
||||
UNREACHABLE();
|
||||
}
|
||||
pointer->ResetExternalPointer(newData);
|
||||
vm_->GetNativeAreaAllocator()->ModifyNativeSizeStats(pointer->GetBindingSize(), size,
|
||||
NativeFlag::ARRAY_BUFFER);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -254,11 +252,9 @@ void ObjectFactory::NewJSArrayBufferData(const JSHandle<JSArrayBuffer> &array, i
|
||||
UNREACHABLE();
|
||||
}
|
||||
JSHandle<JSNativePointer> pointer = NewJSNativePointer(newData, NativeAreaAllocator::FreeBufferFunc,
|
||||
vm_->GetNativeAreaAllocator(), false, size,
|
||||
NativeFlag::ARRAY_BUFFER);
|
||||
vm_->GetNativeAreaAllocator(), false, size);
|
||||
array->SetArrayBufferData(thread_, pointer);
|
||||
array->SetWithNativeAreaAllocator(true);
|
||||
vm_->GetNativeAreaAllocator()->IncreaseNativeSizeStats(length, NativeFlag::ARRAY_BUFFER);
|
||||
}
|
||||
|
||||
void ObjectFactory::NewJSSharedArrayBufferData(const JSHandle<JSArrayBuffer> &array, int32_t length)
|
||||
@ -293,11 +289,9 @@ JSHandle<JSArrayBuffer> ObjectFactory::NewJSArrayBuffer(int32_t length)
|
||||
UNREACHABLE();
|
||||
}
|
||||
JSHandle<JSNativePointer> pointer = NewJSNativePointer(newData, NativeAreaAllocator::FreeBufferFunc,
|
||||
vm_->GetNativeAreaAllocator(), false, length,
|
||||
NativeFlag::ARRAY_BUFFER);
|
||||
vm_->GetNativeAreaAllocator(), false, length);
|
||||
arrayBuffer->SetArrayBufferData(thread_, pointer.GetTaggedValue());
|
||||
arrayBuffer->SetWithNativeAreaAllocator(true);
|
||||
vm_->GetNativeAreaAllocator()->IncreaseNativeSizeStats(length, NativeFlag::ARRAY_BUFFER);
|
||||
}
|
||||
return arrayBuffer;
|
||||
}
|
||||
@ -389,11 +383,9 @@ void ObjectFactory::NewJSRegExpByteCodeData(const JSHandle<JSRegExp> ®exp, vo
|
||||
return;
|
||||
}
|
||||
JSHandle<JSNativePointer> pointer = NewJSNativePointer(newBuffer, NativeAreaAllocator::FreeBufferFunc,
|
||||
vm_->GetNativeAreaAllocator(), false, size,
|
||||
NativeFlag::REGEXP_BTYECODE);
|
||||
vm_->GetNativeAreaAllocator(), false, size);
|
||||
regexp->SetByteCodeBuffer(thread_, pointer.GetTaggedValue());
|
||||
regexp->SetLength(static_cast<uint32_t>(size));
|
||||
vm_->GetNativeAreaAllocator()->IncreaseNativeSizeStats(size, NativeFlag::REGEXP_BTYECODE);
|
||||
}
|
||||
|
||||
JSHandle<JSHClass> ObjectFactory::NewEcmaHClass(uint32_t size, JSType type, const JSHandle<JSTaggedValue> &prototype,
|
||||
|
@ -478,8 +478,7 @@ public:
|
||||
const DeleteEntryPoint &callBack = nullptr,
|
||||
void *data = nullptr,
|
||||
bool nonMovable = false,
|
||||
size_t nativeBindingsize = 0,
|
||||
NativeFlag flag = NativeFlag::NO_DIV);
|
||||
size_t nativeBindingsize = 0);
|
||||
|
||||
JSHandle<JSObject> NewOldSpaceObjLiteralByHClass(const JSHandle<TaggedArray> &properties, size_t length);
|
||||
JSHandle<JSHClass> SetLayoutInObjHClass(const JSHandle<TaggedArray> &properties, size_t length,
|
||||
|
Loading…
Reference in New Issue
Block a user