• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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_COMPILATION_ENV_H
17 #define ECMASCRIPT_COMPILER_COMPILATION_ENV_H
18 
19 #include "ecmascript/global_env.h"
20 #include "ecmascript/js_handle.h"
21 #include "ecmascript/jspandafile/method_literal.h"
22 #include "ecmascript/pgo_profiler/pgo_utils.h"
23 
24 namespace panda::ecmascript {
25 namespace kungfu {
26     class PGOTypeManager;
27     class LazyDeoptAllDependencies;
28 };
29 class ConstantPool;
30 namespace pgo {
31 class PGOProfiler;
32 };
33 class JSThread;
34 
35 class CompilationEnv {
36 public:
37     CompilationEnv(EcmaVM *vm);
38     virtual ~CompilationEnv() = default;
IsJitCompiler()39     virtual bool IsJitCompiler() const
40     {
41         return false;
42     }
43 
IsAotCompiler()44     virtual bool IsAotCompiler() const
45     {
46         return false;
47     }
48 
49     virtual kungfu::LazyDeoptAllDependencies *GetDependencies() const = 0;
50 
GetEcmaVM()51     EcmaVM *GetEcmaVM() const
52     {
53         return vm_;
54     }
55 
GetJSThread()56     JSThread *GetJSThread() const
57     {
58         return thread_;
59     }
60 
GetPTManager()61     kungfu::PGOTypeManager *GetPTManager() const
62     {
63         return ptManager_;
64     }
65 
66     NativeAreaAllocator *GetNativeAreaAllocator() const;
67     virtual JSRuntimeOptions &GetJSOptions() const = 0;
68     virtual std::shared_ptr<pgo::PGOProfiler> GetPGOProfiler() const;
69 
70     // thread
71     virtual GlobalEnvField GetArrayHClassIndex(ElementsKind kind, bool isProtoType) const = 0;
72     virtual const BuiltinHClassEntries &GetBuiltinHClassEntries() const = 0;
73     virtual JSHClass *GetBuiltinPrototypeHClass(BuiltinTypeId type) const = 0;
74 
75     // context
76     virtual JSTaggedValue FindConstpool(const JSPandaFile *jsPandaFile, panda_file::File::EntityId id) const = 0;
77     virtual JSTaggedValue FindConstpool(const JSPandaFile *jsPandaFile, int32_t index) const = 0;
78     virtual JSTaggedValue FindOrCreateUnsharedConstpool(const uint32_t methodOffset) const = 0;
79     virtual JSTaggedValue FindOrCreateUnsharedConstpool(JSTaggedValue sharedConstpool) const = 0;
80     virtual JSHandle<ConstantPool> FindOrCreateConstPool(const JSPandaFile *jsPandaFile,
81         panda_file::File::EntityId id) = 0;
82     virtual JSTaggedValue GetConstantPoolByMethodOffset(const uint32_t methodOffset) const = 0;
83 
84     // ConstantPool
85     virtual JSTaggedValue GetArrayLiteralFromCache(JSTaggedValue constpool, uint32_t index, CString entry) const = 0;
86     virtual JSTaggedValue GetObjectLiteralFromCache(JSTaggedValue constpool, uint32_t index, CString entry) const = 0;
87     virtual JSTaggedValue GetMethodFromCache(JSTaggedValue constpool, uint32_t index) const = 0;
88     virtual panda_file::File::EntityId GetIdFromCache(JSTaggedValue constpool, uint32_t index) const = 0;
89     virtual JSTaggedValue GetStringFromConstantPool(const uint32_t methodOffset, const uint16_t cpIdx,
90         bool allowAlloc = true) const = 0;
91 
92     // GlobalEnv
93     virtual JSHandle<GlobalEnv> GetGlobalEnv() const = 0;
94 
95     // GlobalConstants
96     virtual const GlobalEnvConstants *GlobalConstants() const = 0;
97 
98     virtual JSHandle<JSTaggedValue> NewJSHandle(JSTaggedValue value) const = 0;
99 
100     virtual bool SupportHeapConstant() const = 0;
101 
102     virtual bool SupportIntrinsic() const = 0;
103 
104     virtual bool SupportNonExistIC() const = 0;
105 
GetHostThread()106     virtual JSThread *GetHostThread() const
107     {
108         ASSERT(0);
109         return nullptr;
110     }
111 
GetJSPandaFile()112     virtual JSPandaFile *GetJSPandaFile() const
113     {
114         ASSERT(0);
115         return nullptr;
116     }
117 
GetMethodLiteral()118     virtual MethodLiteral *GetMethodLiteral() const
119     {
120         ASSERT(0);
121         return nullptr;
122     }
123 
ProcessMethod(MethodLiteral * method,const JSPandaFile * jsPandaFile)124     virtual void ProcessMethod(MethodLiteral *method, const JSPandaFile *jsPandaFile) const
125     {
126         ASSERT(0);
127     }
128 
GetMethodPcStart()129     virtual const uint8_t *GetMethodPcStart() const
130     {
131         ASSERT(0);
132         return nullptr;
133     }
134 
GetMethodAbcId()135     virtual pgo::ApEntityId GetMethodAbcId() const
136     {
137         ASSERT(0);
138         return 0;
139     }
140 
141 protected:
142     EcmaVM *vm_ {nullptr};
143     JSThread *thread_ {nullptr};
144     kungfu::PGOTypeManager *ptManager_ {nullptr};
145 };
146 } // namespace panda::ecmascript
147 #endif  // ECMASCRIPT_COMPILER_COMPILATION_ENV_H
148