1 /* 2 * Copyright (c) 2025 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 #ifndef COMMON_COMPONENTS_HEAP_COLLECTOR_GCREQUEST_H 16 #define COMMON_COMPONENTS_HEAP_COLLECTOR_GCREQUEST_H 17 18 #include <cstdint> 19 #include <limits> 20 21 #include "common_components/base/globals.h" 22 #include "common_interfaces/base_runtime.h" 23 24 namespace common { 25 // Minimum time between async GC (heuristic, native). 26 constexpr uint64_t MIN_ASYNC_GC_INTERVAL_NS = SECOND_TO_NANO_SECOND; 27 constexpr uint64_t LONG_MIN_HEU_GC_INTERVAL_NS = 200 * MILLI_SECOND_TO_NANO_SECOND; 28 29 struct GCRequest { 30 const GCReason reason; 31 const char* name; // Human-readable names of GC reasons. 32 33 const bool isSync; 34 const bool isConcurrent; 35 36 uint64_t minIntervelNs; 37 uint64_t prevRequestTime; 38 39 inline bool IsFrequentGC() const; 40 inline bool IsFrequentAsyncGC() const; 41 inline bool IsFrequentHeuristicGC() const; 42 bool ShouldBeIgnored() const; 43 IsSyncGCGCRequest44 bool IsSyncGC() const { return isSync; } 45 SetMinIntervalGCRequest46 void SetMinInterval(const uint64_t intervalNs) { minIntervelNs = intervalNs; } SetPrevRequestTimeGCRequest47 void SetPrevRequestTime(uint64_t timestamp) { prevRequestTime = timestamp; } 48 }; 49 50 // Defined in gcRequest.cpp 51 extern GCRequest g_gcRequests[]; 52 } // namespace common 53 54 #endif // COMMON_COMPONENTS_HEAP_COLLECTOR_GC_DEBUGGER_H 55