trigger compress-gc by kill signal

Signed-off-by: lukai <lukai25@huawei.com>
This commit is contained in:
lukai 2021-09-16 19:59:10 +08:00
parent c18add63d8
commit ff103d88b4
2 changed files with 16 additions and 4 deletions

View File

@ -787,6 +787,7 @@ private:
class PUBLIC_API JSNApi {
public:
// JSVM
enum class PUBLIC_API TRIGGER_GC_TYPE : uint8_t { SEMI_GC, OLD_GC, COMPRESS_FULL_GC };
static EcmaVM *CreateJSVM(const RuntimeOption &option);
static void DestoryJSVM(EcmaVM *ecmaVm);
@ -801,8 +802,7 @@ public:
static void ExecutePendingJob(const EcmaVM *vm);
// Memory
static void TriggerGC(const EcmaVM *vm);
static void TriggerGC(const EcmaVM *vm, TRIGGER_GC_TYPE gcType = TRIGGER_GC_TYPE::SEMI_GC);
// Exception
static void ThrowException(const EcmaVM *vm, Local<JSValueRef> error);
static Local<ObjectRef> GetUncaughtException(const EcmaVM *vm);

View File

@ -185,10 +185,22 @@ void JSNApi::DestoryJSVM(EcmaVM *ecmaVm)
}
}
void JSNApi::TriggerGC(const EcmaVM *vm)
void JSNApi::TriggerGC(const EcmaVM *vm, TRIGGER_GC_TYPE gcType)
{
if (vm->GetJSThread() != nullptr && vm->IsInitialized()) {
vm->CollectGarbage(ecmascript::TriggerGCType::SEMI_GC);
switch (gcType) {
case TRIGGER_GC_TYPE::SEMI_GC:
vm->CollectGarbage(ecmascript::TriggerGCType::SEMI_GC);
break;
case TRIGGER_GC_TYPE::OLD_GC:
vm->CollectGarbage(ecmascript::TriggerGCType::OLD_GC);
break;
case TRIGGER_GC_TYPE::COMPRESS_FULL_GC:
vm->CollectGarbage(ecmascript::TriggerGCType::COMPRESS_FULL_GC);
break;
default:
break;
}
}
}