1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_ACE_ENGINE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_ACE_ENGINE_H 18 19 #include <atomic> 20 #include <cstdint> 21 #include <memory> 22 #include <mutex> 23 #include <unordered_map> 24 25 #include "base/utils/macros.h" 26 #include "base/utils/noncopyable.h" 27 #include "core/common/ace_page.h" 28 #include "core/common/container.h" 29 #include "core/common/frontend.h" 30 #include "core/common/watch_dog.h" 31 #include "core/common/window.h" 32 33 namespace OHOS::Ace { 34 35 class AcePage; 36 37 class ACE_FORCE_EXPORT AceEngine { 38 public: 39 ~AceEngine(); 40 41 void AddContainer(int32_t instanceId, const RefPtr<Container>& container); 42 void RemoveContainer(int32_t instanceId); 43 RefPtr<Container> GetContainer(int32_t instanceId); 44 void RegisterToWatchDog(int32_t instanceId, const RefPtr<TaskExecutor>& taskExecutor, bool useUIAsJSThread = false); 45 void UnRegisterFromWatchDog(int32_t instanceId); 46 void BuriedBomb(int32_t instanceId, uint64_t bombId); 47 void DefusingBomb(int32_t instanceId); 48 static AceEngine& Get(); 49 static void InitJsDumpHeadSignal(); 50 void DumpJsHeap(bool isPrivate) const; 51 void DestroyHeapProfiler() const; 52 void ForceFullGC() const; 53 54 void TriggerGarbageCollection(); 55 void NotifyContainers(const std::function<void(const RefPtr<Container>&)>& callback); 56 void NotifyContainersOrderly(const std::function<void(const RefPtr<Container>&)>& callback); 57 bool HasContainer(int32_t containerId) const; 58 59 private: 60 AceEngine(); 61 62 mutable std::shared_mutex mutex_; 63 std::unordered_map<int32_t, RefPtr<Container>> containerMap_; 64 RefPtr<WatchDog> watchDog_; 65 ACE_DISALLOW_COPY_AND_MOVE(AceEngine); 66 }; 67 68 } // namespace OHOS::Ace 69 70 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_ACE_ENGINE_H 71