• 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_PROFILER_STUB_BUILDER_H
17 #define ECMASCRIPT_COMPILER_PROFILER_STUB_BUILDER_H
18 
19 #include "ecmascript/compiler/profiler_operation.h"
20 #include "ecmascript/compiler/stub_builder.h"
21 
22 namespace panda::ecmascript::kungfu {
23 class ProfilerStubBuilder : public StubBuilder {
24 public:
ProfilerStubBuilder(StubBuilder * parent)25     explicit ProfilerStubBuilder(StubBuilder *parent) : StubBuilder(parent) {}
ProfilerStubBuilder(Environment * env)26     explicit ProfilerStubBuilder(Environment *env) : StubBuilder(env) {}
27     ~ProfilerStubBuilder() override = default;
28     NO_MOVE_SEMANTIC(ProfilerStubBuilder);
29     NO_COPY_SEMANTIC(ProfilerStubBuilder);
GenerateCircuit()30     void GenerateCircuit() override {}
31 
32     void PGOProfiler(GateRef glue, GateRef pc, GateRef func, GateRef profileTypeInfo,
33         const std::vector<GateRef> &values, OperationType type);
34     void ProfileCall(GateRef glue, GateRef pc, GateRef func, GateRef target);
35     void ProfileOpType(GateRef glue, GateRef pc, GateRef func, GateRef profileTypeInfo, GateRef type);
36     void ProfileDefineClass(GateRef glue, GateRef pc, GateRef func, GateRef constructor);
37     void ProfileCreateObject(GateRef glue, GateRef pc, GateRef func, GateRef newObj);
38     void ProfileObjLayout(GateRef glue, GateRef pc, GateRef func, GateRef object, GateRef store);
39 
40     GateRef UpdateTrackTypeInPropAttr(GateRef attr, GateRef value, ProfileOperation callback);
41     void UpdatePropAttrIC(GateRef glue, GateRef receiver, GateRef value, GateRef handler, ProfileOperation callback);
42     void UpdatePropAttrWithValue(GateRef glue, GateRef receiver, GateRef layout, GateRef attr, GateRef attrIndex,
43         GateRef value, ProfileOperation callback);
44 
45 private:
46     static constexpr size_t MAX_PROFILE_CALL_COUNT = 10000;
47     static constexpr size_t MIN_PROFILE_CALL_INTERVAL = 5;
48     static constexpr size_t BITS_OF_WORD = 8;
49     static constexpr size_t HIGH_WORD_OFFSET = 2;
50     static constexpr size_t LOW_WORD_OFFSET = 1;
51     GateRef TaggedToTrackType(GateRef value);
52 };
53 } // namespace panda::ecmascript::kungfu
54 #endif // ECMASCRIPT_COMPILER_PROFILER_STUB_BUILDER_H
55