mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-10-07 08:03:29 +00:00
!6601 Reuse unshared constpool count
Merge pull request !6601 from lijiamin/fix
This commit is contained in:
commit
e678fcef20
@ -52,6 +52,8 @@ namespace panda::ecmascript {
|
||||
using PathHelper = base::PathHelper;
|
||||
|
||||
int32_t EcmaContext::unsharedConstpoolCount_ = 0;
|
||||
CUnorderedSet<int32_t> EcmaContext::freeUnsharedConstpoolCount_ {};
|
||||
std::mutex EcmaContext::unsharedConstpoolCountMutex_;
|
||||
|
||||
EcmaContext::EcmaContext(JSThread *thread)
|
||||
: thread_(thread),
|
||||
@ -562,6 +564,14 @@ JSHandle<ConstantPool> EcmaContext::FindOrCreateConstPool(const JSPandaFile *jsP
|
||||
return JSHandle<ConstantPool>(thread_, constpool);
|
||||
}
|
||||
|
||||
void EcmaContext::InsertFreeUnsharedConstpoolCount(JSTaggedValue sharedConstpool)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(unsharedConstpoolCountMutex_);
|
||||
int32_t index = ConstantPool::Cast(sharedConstpool.GetTaggedObject())->GetUnsharedConstpoolIndex().GetInt();
|
||||
ASSERT(0 <= index && index != ConstantPool::CONSTPOOL_TYPE_FLAG && index < UNSHARED_CONSTANTPOOL_COUNT);
|
||||
freeUnsharedConstpoolCount_.insert(index);
|
||||
}
|
||||
|
||||
void EcmaContext::CreateAllConstpool(const JSPandaFile *jsPandaFile)
|
||||
{
|
||||
auto headers = jsPandaFile->GetPandaFile()->GetIndexHeaders();
|
||||
@ -603,8 +613,9 @@ JSHandle<JSTaggedValue> EcmaContext::GetAndClearEcmaUncaughtException() const
|
||||
return exceptionHandle;
|
||||
}
|
||||
|
||||
void EcmaContext::ProcessNativeDelete(const WeakRootVisitor &visitor)
|
||||
void EcmaContext::ProcessNativeDeleteInSharedGC(const WeakRootVisitor &visitor)
|
||||
{
|
||||
// share-gc trigger.
|
||||
auto iterator = cachedSharedConstpools_.begin();
|
||||
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "Constpools:" + std::to_string(cachedSharedConstpools_.size()));
|
||||
while (iterator != cachedSharedConstpools_.end()) {
|
||||
@ -618,6 +629,9 @@ void EcmaContext::ProcessNativeDelete(const WeakRootVisitor &visitor)
|
||||
if (fwd == nullptr) {
|
||||
constpoolIter = constpools.erase(constpoolIter);
|
||||
EraseUnsharedConstpool(constpoolVal);
|
||||
// when shared constpool is not referenced by any objects,
|
||||
// global unshared constpool count can be reuse.
|
||||
InsertFreeUnsharedConstpoolCount(constpoolVal);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -274,7 +274,7 @@ public:
|
||||
|
||||
void HandleUncaughtException(JSTaggedValue exception);
|
||||
void HandleUncaughtException();
|
||||
void ProcessNativeDelete(const WeakRootVisitor &visitor);
|
||||
void ProcessNativeDeleteInSharedGC(const WeakRootVisitor &visitor);
|
||||
void ProcessReferences(const WeakRootVisitor &visitor);
|
||||
JSHandle<GlobalEnv> GetGlobalEnv() const;
|
||||
bool GlobalEnvIsHole()
|
||||
@ -500,6 +500,7 @@ public:
|
||||
return isAotEntry_;
|
||||
}
|
||||
|
||||
void InsertFreeUnsharedConstpoolCount(JSTaggedValue sharedConstpool);
|
||||
void SetUnsharedConstpool(int32_t unsharedConstpoolIndex, JSTaggedValue constpool)
|
||||
{
|
||||
ASSERT(0 <= unsharedConstpoolIndex && unsharedConstpoolIndex < UNSHARED_CONSTANTPOOL_COUNT);
|
||||
@ -508,8 +509,13 @@ public:
|
||||
|
||||
int32_t GetAndIncreaseUnsharedConstpoolCount()
|
||||
{
|
||||
static std::mutex unsharedConstpoolCountMutex_;
|
||||
std::lock_guard<std::mutex> guard(unsharedConstpoolCountMutex_);
|
||||
if (freeUnsharedConstpoolCount_.size() > 0) {
|
||||
auto iter = freeUnsharedConstpoolCount_.begin();
|
||||
int32_t freeCount = *iter;
|
||||
freeUnsharedConstpoolCount_.erase(iter);
|
||||
return freeCount;
|
||||
}
|
||||
return unsharedConstpoolCount_++;
|
||||
}
|
||||
|
||||
@ -566,6 +572,8 @@ private:
|
||||
std::array<JSTaggedValue, UNSHARED_CONSTANTPOOL_COUNT> *unsharedConstpools_ = nullptr;
|
||||
static int32_t unsharedConstpoolCount_; // unshared constpool index.
|
||||
static constexpr int32_t SHARED_CONSTPOOL_KEY_NOT_FOUND = INT32_MAX; // INT32_MAX :invalid value.
|
||||
static CUnorderedSet<int32_t> freeUnsharedConstpoolCount_; // reuse unshared Constpool Count.
|
||||
static std::mutex unsharedConstpoolCountMutex_;
|
||||
|
||||
// for HotReload of module.
|
||||
CMap<CString, JSHandle<JSTaggedValue>> cachedPatchModules_ {};
|
||||
|
@ -84,7 +84,7 @@ void SharedGC::Sweep()
|
||||
|
||||
Runtime::GetInstance()->GCIterateThreadList([&](JSThread *thread) {
|
||||
ASSERT(!thread->IsInRunningState());
|
||||
thread->GetCurrentEcmaContext()->ProcessNativeDelete(gcUpdateWeak);
|
||||
thread->GetCurrentEcmaContext()->ProcessNativeDeleteInSharedGC(gcUpdateWeak);
|
||||
thread->IterateWeakEcmaGlobalStorage(gcUpdateWeak, true);
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user