• 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 #ifndef ECMASCRIPT_COMPILER_AOT_SNAPSHOT_AOT_SNAPSHOT_H
16 #define ECMASCRIPT_COMPILER_AOT_SNAPSHOT_AOT_SNAPSHOT_H
17 
18 #include "ecmascript/compiler/aot_snapshot/snapshot_global_data.h"
19 #include "ecmascript/compiler/bytecode_info_collector.h"
20 #include "ecmascript/ecma_vm.h"
21 #include "ecmascript/object_factory.h"
22 #include "ecmascript/js_runtime_options.h"
23 
24 namespace panda::ecmascript::kungfu {
25 class AOTSnapshot {
26 public:
AOTSnapshot(EcmaVM * vm)27     explicit AOTSnapshot(EcmaVM *vm)
28         : vm_(vm), factory_(vm->GetFactory()), thread_(vm_->GetJSThread()) {}
29 
Iterate(RootVisitor & v)30     void Iterate(RootVisitor &v)
31     {
32         snapshotData_.Iterate(v);
33     }
34 
GetSnapshotData()35     JSTaggedValue GetSnapshotData() const
36     {
37         return snapshotData_.GetData();
38     }
39 
StoreSymbolInfo(JSHandle<TaggedArray> info)40     void StoreSymbolInfo(JSHandle<TaggedArray> info)
41     {
42         snapshotData_.StoreSymbolInfo(info);
43     }
44 
GetSymbolInfo()45     JSTaggedValue GetSymbolInfo() const
46     {
47         return snapshotData_.GetSymbolInfo();
48     }
49 
StoreHClassInfo(JSHandle<TaggedArray> info)50     void StoreHClassInfo(JSHandle<TaggedArray> info)
51     {
52         snapshotData_.StoreHClassInfo(info);
53     }
54 
StoreArrayInfo(JSHandle<TaggedArray> info)55     void StoreArrayInfo(JSHandle<TaggedArray> info)
56     {
57         snapshotData_.StoreArrayInfo(info);
58     }
59 
StoreProtoTransTableInfo(JSHandle<JSTaggedValue> info)60     void StoreProtoTransTableInfo(JSHandle<JSTaggedValue> info)
61     {
62         snapshotData_.StoreProtoTransTableInfo(info);
63     }
64 
GetArrayInfo()65     JSTaggedValue GetArrayInfo()
66     {
67         return snapshotData_.GetArrayInfo();
68     }
69 
StoreConstantIndexInfo(JSHandle<TaggedArray> info)70     void StoreConstantIndexInfo(JSHandle<TaggedArray> info)
71     {
72         snapshotData_.StoreConstantIndexInfo(info);
73     }
74 
75     void InitSnapshot(uint32_t compileFilesCount);
76 
77     void PUBLIC_API StoreConstantPoolInfo(BytecodeInfoCollector *bcInfoCollector);
78 
ResolveSnapshotData(const CMap<std::pair<std::string,uint32_t>,uint32_t> & methodToEntryIndexMap)79     void ResolveSnapshotData(const CMap<std::pair<std::string, uint32_t>, uint32_t> &methodToEntryIndexMap)
80     {
81         snapshotData_.ResolveSnapshotData(thread_, methodToEntryIndexMap);
82     }
83 
84 private:
85     JSHandle<ConstantPool> NewSnapshotConstantPool(uint32_t cacheSize);
86 
87     void GenerateSnapshotConstantPools(
88         const CMap<int32_t, JSTaggedValue> &allConstantPools, const CString &fileName, uint32_t fileIndex);
89 
90     EcmaVM *vm_ {nullptr};
91     ObjectFactory *factory_ {nullptr};
92     JSThread *thread_ {nullptr};
93     SnapshotGlobalData snapshotData_ {};
94 };
95 }  // panda::ecmascript::kungfu
96 #endif // ECMASCRIPT_COMPILER_AOT_SNAPSHOT_AOT_SNAPSHOT_H
97