• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-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 
16 #ifndef PANDA_STS_VM_INTERFACE_H
17 #define PANDA_STS_VM_INTERFACE_H
18 
19 #include "hybrid/vm_interface.h"
20 #include <cstdint>
21 #include <cstddef>
22 #include <functional>
23 
24 namespace arkplatform {
25 
26 class STSVMInterface : public VMInterface {
27 public:
28     static constexpr size_t DEFAULT_XGC_EXECUTORS_COUNT = 2U;
29     using NoWorkPred = std::function<bool()>;
30 
31     STSVMInterface() = default;
32 
33     STSVMInterface(const STSVMInterface &) = delete;
34     void operator=(const STSVMInterface &) = delete;
35 
36     STSVMInterface(STSVMInterface &&) = delete;
37     STSVMInterface &operator=(STSVMInterface &&) = delete;
38 
39     ~STSVMInterface() override = default;
40 
GetVMType()41     VMInterfaceType GetVMType() const override
42     {
43         return STSVMInterface::VMInterfaceType::ETS_VM_IFACE;
44     }
45 
46     /**
47      * @brief executes marking operation of STS VM GC that will be started from gotten object.
48      * @param obj: pointer to object from which marking will be started.
49      */
50     virtual void MarkFromObject(void *obj) = 0;
51     /**
52      * @brief Increment count of threads that will execute XGC. If you use this method in the scope of XGC execution,
53      * new count of threads will be ignored by currect XGC, but will be used in next one.
54      */
55     virtual void OnVMAttach() = 0;
56     /**
57      * @brief Decrement count of threads that will execute XGC. If you use this method in the scope of XGC execution,
58      * new count of threads will be ignored by currect XGC, but will be used in next one.
59      */
60     virtual void OnVMDetach() = 0;
61     /**
62      * @brief Method waits for all threads to start XGC. The count of threads can be changed using methods OnVMAttach
63      * and OnVMDetach. After this method XGC is considered to be running.
64      * @param func: predicate that checks if XGC was interrupted or not
65      * @returns value based on NoWorkPred, can be not only interruption in the common case
66      */
67     virtual bool StartXGCBarrier(const NoWorkPred &func) = 0;
68     /**
69      * @brief Method waits for all threads would call WaitForConcurrentMark.
70      * @param func: predicate that checks if we need to leave barrier to continue marking
71      * @returns true if all threads called this methods. It can return false if VM should try continue marking from new
72      * objects.
73      */
74     virtual bool WaitForConcurrentMark(const NoWorkPred &func) = 0;
75     /// @brief Method waits for all threads would call RemarkStartBarrier
76     virtual void RemarkStartBarrier() = 0;
77     /**
78      * @brief Method waits for all threads would call WaitForRemark.
79      * @param func: predicate that checks if we need to leave barrier to continue marking
80      * @returns true if all threads called this methods. It can return false if VM should try continue marking from new
81      * objects.
82      */
83     virtual bool WaitForRemark(const NoWorkPred &func) = 0;
84     /// @brief Method waits for all threads would call FinishXGCBarrier
85     virtual void FinishXGCBarrier() = 0;
86 };
87 
88 }  // namespace arkplatform
89 
90 #endif  // PANDA_STS_VM_INTERFACE_H
91