Provides properties to set the OOM waterline

issues:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I9CHSB

Signed-off-by: rentangyu <rentangyu@huawei.com>
This commit is contained in:
rentangyu 2024-04-09 14:54:58 +08:00
parent 78f90b26a3
commit 2ecc366efe
6 changed files with 46 additions and 2 deletions

View File

@ -26,6 +26,7 @@ namespace panda::ecmascript {
static constexpr size_t DEFAULT_HEAP_SIZE = 448_MB; // Recommended range: 128-448MB
static constexpr size_t DEFAULT_WORKER_HEAP_SIZE = 768_MB; // Recommended range: 128_MB, LargeHeap: 768_MB
static constexpr size_t DEFAULT_SHARED_HEAP_SIZE = 778_MB;
static constexpr size_t MAX_HEAP_SIZE = 1024_MB;
class EcmaParamConfiguration {
public:
@ -35,7 +36,7 @@ public:
SHARED_HEAP
};
EcmaParamConfiguration(HeapType heapType, size_t poolSize)
EcmaParamConfiguration(HeapType heapType, size_t poolSize, size_t heapSize = 1_MB)
{
switch (heapType) {
case HeapType::WORKER_HEAP:
@ -50,6 +51,9 @@ public:
} else {
maxHeapSize_ = poolSize; // pool is too small, no memory left for worker
}
if (heapSize >= DEFAULT_HEAP_SIZE && heapSize <= MAX_HEAP_SIZE) {
maxHeapSize_ = heapSize;
}
}
Initialize();
}

View File

@ -105,8 +105,10 @@ EcmaVM *EcmaVM::Create(const JSRuntimeOptions &options)
Runtime::CreateIfFirstVm(options);
auto heapType = options.IsWorker() ? EcmaParamConfiguration::HeapType::WORKER_HEAP :
EcmaParamConfiguration::HeapType::DEFAULT_HEAP;
size_t heapSize = options.GetHeapSize();
auto config = EcmaParamConfiguration(heapType,
MemMapAllocator::GetInstance()->GetCapacity());
MemMapAllocator::GetInstance()->GetCapacity(),
heapSize);
JSRuntimeOptions newOptions = options;
// only define SUPPORT_ENABLE_ASM_INTERP can enable asm-interpreter
#if !defined(SUPPORT_ENABLE_ASM_INTERP)

View File

@ -386,6 +386,29 @@ public:
}
}
void SetMemConfigProperty(std::string configProperty)
{
if (configProperty != "") {
std::string key;
std::string value;
for (char c : configProperty) {
if (isdigit(c)) {
value += c;
} else {
key += c;
}
}
if (key == "jsHeap") {
heapSize_ = stoi(value) * 1_MB;
}
}
}
size_t GetHeapSize() const
{
return heapSize_;
}
int GetDefaultProperties()
{
return ArkProperties::PARALLEL_GC | ArkProperties::CONCURRENT_MARK | ArkProperties::CONCURRENT_SWEEP |
@ -1665,6 +1688,7 @@ private:
uint32_t forceSharedGc_ {1};
int arkProperties_ = GetDefaultProperties();
std::string arkBundleName_ = {""};
size_t heapSize_ = {0};
uint32_t gcThreadNum_ {7}; // 7: default thread num
uint32_t longPauseTime_ {40}; // 40: default pause time
std::string aotOutputFile_ {""};

View File

@ -195,6 +195,11 @@ public:
arkBundleName_ = bundleName;
}
void SetMemConfigProperty(std::string configProperty)
{
memConfigProperty_ = configProperty;
}
void SetGcThreadNum(size_t num)
{
gcThreadNum_ = num;
@ -321,6 +326,11 @@ private:
return arkBundleName_;
}
std::string GetMemConfigProperty() const
{
return memConfigProperty_;
}
size_t GetGcThreadNum() const
{
return gcThreadNum_;
@ -385,6 +395,7 @@ private:
bool enableCpuprofiler_ {false};
int arkProperties_ {-1};
std::string arkBundleName_ = {""};
std::string memConfigProperty_ = {""};
size_t gcThreadNum_ {DEFAULT_GC_THREAD_NUM};
size_t longPauseTime_ {DEFAULT_LONG_PAUSE_TIME};
bool enableAsmInterpreter_ {true};

View File

@ -3091,6 +3091,7 @@ EcmaVM *JSNApi::CreateJSVM(const RuntimeOption &option)
{
JSRuntimeOptions runtimeOptions;
runtimeOptions.SetArkProperties(option.GetArkProperties());
runtimeOptions.SetMemConfigProperty(option.GetMemConfigProperty());
runtimeOptions.SetArkBundleName(option.GetArkBundleName());
runtimeOptions.SetLongPauseTime(option.GetLongPauseTime());
runtimeOptions.SetGcThreadNum(option.GetGcThreadNum());

View File

@ -58,6 +58,7 @@ HWTEST_F_L0(EcmaVMTest, CreateEcmaVMInTwoWays)
options2.SetEnableForceGC(false);
options2.SetForceFullGC(false);
options2.SetArkProperties(ArkProperties::GC_STATS_PRINT);
options2.SetMemConfigProperty("jsHeap500");
// A non-production gc strategy. Prohibit stw-gc 10 times.
EcmaVM *ecmaVm2 = JSNApi::CreateEcmaVM(options2);
@ -72,6 +73,7 @@ HWTEST_F_L0(EcmaVMTest, CreateEcmaVMInTwoWays)
EXPECT_TRUE(options1Out.EnableForceGC() != options2Out.EnableForceGC());
EXPECT_TRUE(options1Out.ForceFullGC() != options2Out.ForceFullGC());
EXPECT_TRUE(options1Out.GetArkProperties() != options2Out.GetArkProperties());
EXPECT_TRUE(options2Out.GetHeapSize() == 500_MB);
JSNApi::DestroyJSVM(ecmaVm2);
});