增加虚拟机参数param配置

Signed-off-by: jao_liu <liujiao44@huawei.com>
This commit is contained in:
jao_liu 2024-08-13 02:01:37 +00:00
parent 841af8ecc1
commit 076c463f7e
3 changed files with 30 additions and 4 deletions

View File

@ -41,10 +41,18 @@ public:
{
switch (heapType) {
case HeapType::WORKER_HEAP:
maxHeapSize_ = DEFAULT_WORKER_HEAP_SIZE;
if (heapSize > LOW_MEMORY && heapSize < DEFAULT_WORKER_HEAP_SIZE) {
maxHeapSize_ = heapSize;
} else {
maxHeapSize_ = DEFAULT_WORKER_HEAP_SIZE;
}
break;
case HeapType::SHARED_HEAP:
maxHeapSize_ = DEFAULT_SHARED_HEAP_SIZE;
if (heapSize > LOW_MEMORY && heapSize < DEFAULT_SHARED_HEAP_SIZE) {
maxHeapSize_ = heapSize;
} else {
maxHeapSize_ = DEFAULT_SHARED_HEAP_SIZE;
};
break;
default:
if (poolSize >= DEFAULT_HEAP_SIZE) {
@ -52,6 +60,9 @@ public:
} else {
maxHeapSize_ = poolSize; // pool is too small, no memory left for worker
}
if (heapSize > LOW_MEMORY && heapSize < DEFAULT_HEAP_SIZE) {
maxHeapSize_ = heapSize;
}
if (heapSize >= DEFAULT_HEAP_SIZE && heapSize <= MAX_HEAP_SIZE) {
maxHeapSize_ = heapSize;
}

View File

@ -117,6 +117,16 @@ EcmaVM *EcmaVM::Create(const JSRuntimeOptions &options)
auto heapType = options.IsWorker() ? EcmaParamConfiguration::HeapType::WORKER_HEAP :
EcmaParamConfiguration::HeapType::DEFAULT_HEAP;
size_t heapSize = options.GetHeapSize();
#if defined(PANDA_TARGET_OHOS) && !defined(STANDALONE_MODE)
switch (heapType) {
case EcmaParamConfiguration::HeapType::WORKER_HEAP:
heapSize = OHOS::system::GetUintParameter<size_t>("persist.ark.heap.workersize", 0) * 1_MB;
break;
default:
heapSize = OHOS::system::GetUintParameter<size_t>("persist.ark.heap.defaultsize", 0) * 1_MB;
break;
}
#endif
auto config = EcmaParamConfiguration(heapType,
MemMapAllocator::GetInstance()->GetCapacity(),
heapSize);

View File

@ -56,6 +56,7 @@
#include "ecmascript/runtime_lock.h"
#include "ecmascript/jit/jit.h"
#include "ecmascript/ohos/ohos_params.h"
#if !WIN_OR_MAC_OR_IOS_PLATFORM
#include "ecmascript/dfx/hprof/heap_profiler_interface.h"
#include "ecmascript/dfx/hprof/heap_profiler.h"
@ -69,7 +70,7 @@
#endif
#if defined(ECMASCRIPT_SUPPORT_SNAPSHOT) && defined(PANDA_TARGET_OHOS) && defined(ENABLE_HISYSEVENT)
#include "parameters.h"
#include "parameter.h"
#include "hisysevent.h"
static constexpr uint32_t DEC_TO_INT = 100;
static size_t g_threshold = OHOS::system::GetUintParameter<size_t>("persist.dfx.leak.threshold", 85);
@ -87,8 +88,12 @@ SharedHeap *SharedHeap::instance_ = nullptr;
void SharedHeap::CreateNewInstance()
{
ASSERT(instance_ == nullptr);
size_t heapShared = 0;
#if defined(ECMASCRIPT_SUPPORT_SNAPSHOT) && defined(PANDA_TARGET_OHOS) && defined(ENABLE_HISYSEVENT)
heapShared = OHOS::system::GetUintParameter<size_t>("persist.ark.heap.sharedsize", 0) * 1_MB;
#endif
EcmaParamConfiguration config(EcmaParamConfiguration::HeapType::SHARED_HEAP,
MemMapAllocator::GetInstance()->GetCapacity());
MemMapAllocator::GetInstance()->GetCapacity(), heapShared);
instance_ = new SharedHeap(config);
}