• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 ECMASCRIPT_COMPILER_PGO_TYPE_PGO_TYPE_RECORD_H
17 #define ECMASCRIPT_COMPILER_PGO_TYPE_PGO_TYPE_RECORD_H
18 
19 #include "ecmascript/jit/jit_profiler.h"
20 #include "ecmascript/pgo_profiler/pgo_profiler_decoder.h"
21 #include "ecmascript/pgo_profiler/types/pgo_profiler_type.h"
22 
23 namespace panda::ecmascript::kungfu {
24 using PGOProfilerDecoder = pgo::PGOProfilerDecoder;
25 using PGOHClassTreeDesc = pgo::PGOHClassTreeDesc;
26 using PGODefineOpType = pgo::PGODefineOpType;
27 using PGOProtoTransitionType = pgo::PGOProtoTransitionType;
28 using RootHClassLayoutDesc = pgo::RootHClassLayoutDesc;
29 using PGORWOpType = pgo::PGORWOpType;
30 
31 class PGOTypeRecorder {
32 public:
33     explicit PGOTypeRecorder(const PGOProfilerDecoder &decoder);
34     PUBLIC_API PGOTypeRecorder(const PGOProfilerDecoder &decoder,
35         const JSPandaFile *jsPandaFile, uint32_t methodOffset);
36     ~PGOTypeRecorder() = default;
37 
38     std::vector<ElementsKind> PUBLIC_API GetTransitionElementsKindsForUser(int32_t offset) const;
39     std::vector<ElementsKind> PUBLIC_API GetElementsKindsForUser(int32_t offset) const;
40     ElementsKind PUBLIC_API GetElementsKindForCreater(int32_t offset) const;
41     uint32_t PUBLIC_API GetElementsLength(int32_t offset) const;
42 
43     PGOTypeRef PUBLIC_API GetPGOType(int32_t offset) const;
44 
GetPGODefOpType(int32_t bcOffset)45     inline PGODefineOpType GetPGODefOpType(int32_t bcOffset) const
46     {
47         auto typeIter = bcOffsetPGODefOpTypeMap_.find(bcOffset);
48         if (typeIter == bcOffsetPGODefOpTypeMap_.end()) {
49             return PGODefineOpType(ProfileType::PROFILE_TYPE_NONE);
50         }
51         return *(typeIter->second);
52     }
53 
GetHClassTreeDesc(PGOSampleType type,PGOHClassTreeDesc ** desc)54     inline bool GetHClassTreeDesc(PGOSampleType type, PGOHClassTreeDesc **desc) const
55     {
56         return decoder_.GetHClassTreeDesc(type, desc);
57     }
58 
59     template <typename Callback>
IterateHClassTreeDesc(Callback callback)60     void IterateHClassTreeDesc(Callback callback) const
61     {
62         decoder_.IterateHClassTreeDesc(callback);
63     }
64 
65     template <typename Callback>
IterateProtoTransitionPool(Callback callback)66     void IterateProtoTransitionPool(Callback callback) const
67     {
68         decoder_.IterateProtoTransitionPool(callback);
69     }
70 
InitMap(JITProfiler * jitProfile)71     void InitMap(JITProfiler* jitProfile)
72     {
73         bcOffsetPGOOpTypeMap_ = jitProfile->GetOpTypeMap();
74         bcOffsetPGODefOpTypeMap_ = jitProfile->GetDefOpTypeMap();
75         bcOffsetPGORwTypeMap_ = jitProfile->GetRwTypeMap();
76     }
77 
78     bool IsValidPt(ProfileType type) const;
79 
80 private:
81     const PGOProfilerDecoder &decoder_;
82     std::unordered_map<int32_t, const PGOSampleType*> bcOffsetPGOOpTypeMap_ {};
83     std::unordered_map<int32_t, const PGORWOpType*> bcOffsetPGORwTypeMap_ {};
84     std::unordered_map<int32_t, const PGODefineOpType*> bcOffsetPGODefOpTypeMap_;
85 };
86 }  // panda::ecmascript::kungfu
87 #endif // ECMASCRIPT_COMPILER_PGO_TYPE_PGO_TYPE_RECORD_H
88