• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #include "ecmascript/snapshot/mem/snapshot_processor.h"
17 
18 #include "ecmascript/base/config.h"
19 #include "ecmascript/builtins/builtins_ark_tools.h"
20 #include "ecmascript/builtins/builtins_array.h"
21 #include "ecmascript/builtins/builtins_arraybuffer.h"
22 #include "ecmascript/builtins/builtins_async_function.h"
23 #include "ecmascript/builtins/builtins_async_generator.h"
24 #include "ecmascript/builtins/builtins_async_iterator.h"
25 #include "ecmascript/builtins/builtins_atomics.h"
26 #include "ecmascript/builtins/builtins_bigint.h"
27 #include "ecmascript/builtins/builtins_boolean.h"
28 #include "ecmascript/builtins/builtins_cjs_exports.h"
29 #include "ecmascript/builtins/builtins_cjs_module.h"
30 #include "ecmascript/builtins/builtins_cjs_require.h"
31 #include "ecmascript/builtins/builtins_dataview.h"
32 #include "ecmascript/builtins/builtins_date.h"
33 #include "ecmascript/builtins/builtins_errors.h"
34 #include "ecmascript/builtins/builtins_finalization_registry.h"
35 #include "ecmascript/builtins/builtins_function.h"
36 #include "ecmascript/builtins/builtins_generator.h"
37 #include "ecmascript/builtins/builtins_global.h"
38 #include "ecmascript/builtins/builtins_iterator.h"
39 #include "ecmascript/builtins/builtins_json.h"
40 #include "ecmascript/builtins/builtins_map.h"
41 #include "ecmascript/builtins/builtins_math.h"
42 #include "ecmascript/builtins/builtins_number.h"
43 #include "ecmascript/builtins/builtins_object.h"
44 #include "ecmascript/builtins/builtins_promise.h"
45 #include "ecmascript/builtins/builtins_promise_handler.h"
46 #include "ecmascript/builtins/builtins_promise_job.h"
47 #include "ecmascript/builtins/builtins_proxy.h"
48 #include "ecmascript/builtins/builtins_reflect.h"
49 #include "ecmascript/builtins/builtins_regexp.h"
50 #include "ecmascript/builtins/builtins_set.h"
51 #include "ecmascript/builtins/builtins_sharedarraybuffer.h"
52 #include "ecmascript/builtins/builtins_string_iterator.h"
53 #include "ecmascript/builtins/builtins_symbol.h"
54 #include "ecmascript/builtins/builtins_typedarray.h"
55 #include "ecmascript/builtins/builtins_weak_map.h"
56 #include "ecmascript/builtins/builtins_weak_ref.h"
57 #include "ecmascript/builtins/builtins_weak_set.h"
58 #include "ecmascript/containers/containers_arraylist.h"
59 #include "ecmascript/containers/containers_deque.h"
60 #include "ecmascript/containers/containers_hashmap.h"
61 #include "ecmascript/containers/containers_hashset.h"
62 #include "ecmascript/containers/containers_lightweightmap.h"
63 #include "ecmascript/containers/containers_lightweightset.h"
64 #include "ecmascript/containers/containers_linked_list.h"
65 #include "ecmascript/containers/containers_list.h"
66 #include "ecmascript/containers/containers_plainarray.h"
67 #include "ecmascript/containers/containers_private.h"
68 #include "ecmascript/containers/containers_queue.h"
69 #include "ecmascript/containers/containers_stack.h"
70 #include "ecmascript/containers/containers_treemap.h"
71 #include "ecmascript/containers/containers_treeset.h"
72 #include "ecmascript/containers/containers_vector.h"
73 #include "ecmascript/containers/containers_bitvector.h"
74 #include "ecmascript/runtime_lock.h"
75 #ifdef ENABLE_NEXT_OPTIMIZATION
76 #include "ecmascript/ecma_string_table_optimization-inl.h"
77 #endif
78 #ifdef ARK_SUPPORT_INTL
79 #include "ecmascript/builtins/builtins_collator.h"
80 #include "ecmascript/builtins/builtins_date_time_format.h"
81 #include "ecmascript/builtins/builtins_displaynames.h"
82 #include "ecmascript/builtins/builtins_intl.h"
83 #include "ecmascript/builtins/builtins_list_format.h"
84 #include "ecmascript/builtins/builtins_locale.h"
85 #include "ecmascript/builtins/builtins_number_format.h"
86 #include "ecmascript/builtins/builtins_plural_rules.h"
87 #include "ecmascript/builtins/builtins_relative_time_format.h"
88 #include "ecmascript/builtins/builtins_segmenter.h"
89 #include "ecmascript/builtins/builtins_segments.h"
90 #include "ecmascript/builtins/builtins_segment_iterator.h"
91 #endif
92 
93 namespace panda::ecmascript {
94 using Number = builtins::BuiltinsNumber;
95 using BuiltinsBigInt = builtins::BuiltinsBigInt;
96 using Object = builtins::BuiltinsObject;
97 using Date = builtins::BuiltinsDate;
98 using Symbol = builtins::BuiltinsSymbol;
99 using Boolean = builtins::BuiltinsBoolean;
100 using BuiltinsMap = builtins::BuiltinsMap;
101 using BuiltinsSet = builtins::BuiltinsSet;
102 using BuiltinsWeakMap = builtins::BuiltinsWeakMap;
103 using BuiltinsWeakSet = builtins::BuiltinsWeakSet;
104 using BuiltinsWeakRef = builtins::BuiltinsWeakRef;
105 using BuiltinsFinalizationRegistry = builtins::BuiltinsFinalizationRegistry;
106 using BuiltinsArray = builtins::BuiltinsArray;
107 using BuiltinsTypedArray = builtins::BuiltinsTypedArray;
108 using BuiltinsIterator = builtins::BuiltinsIterator;
109 using BuiltinsAsyncIterator = builtins::BuiltinsAsyncIterator;
110 using Error = builtins::BuiltinsError;
111 using RangeError = builtins::BuiltinsRangeError;
112 using ReferenceError = builtins::BuiltinsReferenceError;
113 using TypeError = builtins::BuiltinsTypeError;
114 using AggregateError = builtins::BuiltinsAggregateError;
115 using URIError = builtins::BuiltinsURIError;
116 using SyntaxError = builtins::BuiltinsSyntaxError;
117 using EvalError = builtins::BuiltinsEvalError;
118 using OOMError = builtins::BuiltinsOOMError;
119 using ErrorType = base::ErrorType;
120 using Global = builtins::BuiltinsGlobal;
121 using BuiltinsString = builtins::BuiltinsString;
122 using StringIterator = builtins::BuiltinsStringIterator;
123 using RegExp = builtins::BuiltinsRegExp;
124 using Function = builtins::BuiltinsFunction;
125 using Math = builtins::BuiltinsMath;
126 using Atomics = builtins::BuiltinsAtomics;
127 using ArrayBuffer = builtins::BuiltinsArrayBuffer;
128 using SharedArrayBuffer = builtins::BuiltinsSharedArrayBuffer;
129 using Json = builtins::BuiltinsJson;
130 using Proxy = builtins::BuiltinsProxy;
131 using Reflect = builtins::BuiltinsReflect;
132 using AsyncFunction = builtins::BuiltinsAsyncFunction;
133 using GeneratorObject = builtins::BuiltinsGenerator;
134 using AsyncGeneratorObject = builtins::BuiltinsAsyncGenerator;
135 using Promise = builtins::BuiltinsPromise;
136 using BuiltinsPromiseHandler = builtins::BuiltinsPromiseHandler;
137 using BuiltinsPromiseJob = builtins::BuiltinsPromiseJob;
138 using BuiltinsCjsExports = builtins::BuiltinsCjsExports;
139 using BuiltinsCjsModule = builtins::BuiltinsCjsModule;
140 using BuiltinsCjsRequire = builtins::BuiltinsCjsRequire;
141 using ArkTools = builtins::BuiltinsArkTools;
142 using ErrorType = base::ErrorType;
143 using DataView = builtins::BuiltinsDataView;
144 using ArrayList = containers::ContainersArrayList;
145 using HashMap = containers::ContainersHashMap;
146 using HashSet = containers::ContainersHashSet;
147 using LightWeightMap = containers::ContainersLightWeightMap;
148 using LightWeightSet = containers::ContainersLightWeightSet;
149 using TreeMap = containers::ContainersTreeMap;
150 using TreeSet = containers::ContainersTreeSet;
151 using Vector = containers::ContainersVector;
152 using BitVector = containers::ContainersBitVector;
153 using Queue = containers::ContainersQueue;
154 using List = containers::ContainersList;
155 using LinkedList = containers::ContainersLinkedList;
156 using PlainArray = containers::ContainersPlainArray;
157 using Deque = containers::ContainersDeque;
158 using ContainerStack = panda::ecmascript::containers::ContainersStack;
159 using ContainersPrivate = containers::ContainersPrivate;
160 #ifdef ARK_SUPPORT_INTL
161 using DisplayNames = builtins::BuiltinsDisplayNames;
162 using ListFormat = builtins::BuiltinsListFormat;
163 using Intl = builtins::BuiltinsIntl;
164 using Locale = builtins::BuiltinsLocale;
165 using DateTimeFormat = builtins::BuiltinsDateTimeFormat;
166 using NumberFormat = builtins::BuiltinsNumberFormat;
167 using RelativeTimeFormat = builtins::BuiltinsRelativeTimeFormat;
168 using Collator = builtins::BuiltinsCollator;
169 using PluralRules = builtins::BuiltinsPluralRules;
170 using Segmenter = builtins::BuiltinsSegmenter;
171 using Segments = builtins::BuiltinsSegments;
172 #endif
173 
174 // NOLINTNEXTLINE(modernize-avoid-c-arrays)
175 static uintptr_t g_nativeTable[] = {
176     reinterpret_cast<uintptr_t>(nullptr),
177     reinterpret_cast<uintptr_t>(BuiltinsMap::Species),
178     reinterpret_cast<uintptr_t>(StringIterator::Next),
179     reinterpret_cast<uintptr_t>(Function::FunctionPrototypeInvokeSelf),
180     reinterpret_cast<uintptr_t>(Function::FunctionConstructor),
181     reinterpret_cast<uintptr_t>(JSFunction::AccessCallerArgumentsThrowTypeError),
182     reinterpret_cast<uintptr_t>(Function::FunctionPrototypeApply),
183     reinterpret_cast<uintptr_t>(Function::FunctionPrototypeBind),
184     reinterpret_cast<uintptr_t>(Function::FunctionPrototypeCall),
185     reinterpret_cast<uintptr_t>(Function::FunctionPrototypeToString),
186     reinterpret_cast<uintptr_t>(Object::ObjectConstructor),
187     reinterpret_cast<uintptr_t>(Object::FromEntries),
188     reinterpret_cast<uintptr_t>(Error::ErrorConstructor),
189     reinterpret_cast<uintptr_t>(Error::ToString),
190     reinterpret_cast<uintptr_t>(RangeError::RangeErrorConstructor),
191     reinterpret_cast<uintptr_t>(RangeError::ToString),
192     reinterpret_cast<uintptr_t>(ReferenceError::ReferenceErrorConstructor),
193     reinterpret_cast<uintptr_t>(ReferenceError::ToString),
194     reinterpret_cast<uintptr_t>(TypeError::TypeErrorConstructor),
195     reinterpret_cast<uintptr_t>(TypeError::ToString),
196     reinterpret_cast<uintptr_t>(TypeError::ThrowTypeError),
197     reinterpret_cast<uintptr_t>(AggregateError::AggregateErrorConstructor),
198     reinterpret_cast<uintptr_t>(AggregateError::ToString),
199     reinterpret_cast<uintptr_t>(URIError::URIErrorConstructor),
200     reinterpret_cast<uintptr_t>(URIError::ToString),
201     reinterpret_cast<uintptr_t>(SyntaxError::SyntaxErrorConstructor),
202     reinterpret_cast<uintptr_t>(SyntaxError::ToString),
203     reinterpret_cast<uintptr_t>(EvalError::EvalErrorConstructor),
204     reinterpret_cast<uintptr_t>(EvalError::ToString),
205     reinterpret_cast<uintptr_t>(OOMError::OOMErrorConstructor),
206     reinterpret_cast<uintptr_t>(OOMError::ToString),
207     reinterpret_cast<uintptr_t>(Number::NumberConstructor),
208     reinterpret_cast<uintptr_t>(Number::ToExponential),
209     reinterpret_cast<uintptr_t>(Number::ToFixed),
210     reinterpret_cast<uintptr_t>(Number::ToLocaleString),
211     reinterpret_cast<uintptr_t>(Number::ToPrecision),
212     reinterpret_cast<uintptr_t>(Number::ToString),
213     reinterpret_cast<uintptr_t>(Number::ValueOf),
214     reinterpret_cast<uintptr_t>(Number::IsFinite),
215     reinterpret_cast<uintptr_t>(Number::IsInteger),
216     reinterpret_cast<uintptr_t>(Number::IsNaN),
217     reinterpret_cast<uintptr_t>(Number::IsSafeInteger),
218     reinterpret_cast<uintptr_t>(Number::ParseFloat),
219     reinterpret_cast<uintptr_t>(Number::ParseInt),
220     reinterpret_cast<uintptr_t>(Symbol::SymbolConstructor),
221     reinterpret_cast<uintptr_t>(Symbol::For),
222     reinterpret_cast<uintptr_t>(Symbol::KeyFor),
223     reinterpret_cast<uintptr_t>(Symbol::DescriptionGetter),
224     reinterpret_cast<uintptr_t>(Symbol::ToPrimitive),
225     reinterpret_cast<uintptr_t>(Symbol::ToString),
226     reinterpret_cast<uintptr_t>(Symbol::ValueOf),
227     reinterpret_cast<uintptr_t>(Function::FunctionPrototypeHasInstance),
228     reinterpret_cast<uintptr_t>(Date::DateConstructor),
229     reinterpret_cast<uintptr_t>(Date::GetDate),
230     reinterpret_cast<uintptr_t>(Date::GetDay),
231     reinterpret_cast<uintptr_t>(Date::GetFullYear),
232     reinterpret_cast<uintptr_t>(Date::GetHours),
233     reinterpret_cast<uintptr_t>(Date::GetMilliseconds),
234     reinterpret_cast<uintptr_t>(Date::GetMinutes),
235     reinterpret_cast<uintptr_t>(Date::GetMonth),
236     reinterpret_cast<uintptr_t>(Date::GetSeconds),
237     reinterpret_cast<uintptr_t>(Date::GetTime),
238     reinterpret_cast<uintptr_t>(Date::GetTimezoneOffset),
239     reinterpret_cast<uintptr_t>(Date::GetUTCDate),
240     reinterpret_cast<uintptr_t>(Date::GetUTCDay),
241     reinterpret_cast<uintptr_t>(Date::GetUTCFullYear),
242     reinterpret_cast<uintptr_t>(Date::GetUTCHours),
243     reinterpret_cast<uintptr_t>(Date::GetUTCMilliseconds),
244     reinterpret_cast<uintptr_t>(Date::GetUTCMinutes),
245     reinterpret_cast<uintptr_t>(Date::GetUTCMonth),
246     reinterpret_cast<uintptr_t>(Date::GetUTCSeconds),
247     reinterpret_cast<uintptr_t>(Date::SetDate),
248     reinterpret_cast<uintptr_t>(Date::SetFullYear),
249     reinterpret_cast<uintptr_t>(Date::SetHours),
250     reinterpret_cast<uintptr_t>(Date::SetMilliseconds),
251     reinterpret_cast<uintptr_t>(Date::SetMinutes),
252     reinterpret_cast<uintptr_t>(Date::SetMonth),
253     reinterpret_cast<uintptr_t>(Date::SetSeconds),
254     reinterpret_cast<uintptr_t>(Date::SetTime),
255     reinterpret_cast<uintptr_t>(Date::SetUTCDate),
256     reinterpret_cast<uintptr_t>(Date::SetUTCFullYear),
257     reinterpret_cast<uintptr_t>(Date::SetUTCHours),
258     reinterpret_cast<uintptr_t>(Date::SetUTCMilliseconds),
259     reinterpret_cast<uintptr_t>(Date::SetUTCMinutes),
260     reinterpret_cast<uintptr_t>(Date::SetUTCMonth),
261     reinterpret_cast<uintptr_t>(Date::SetUTCSeconds),
262     reinterpret_cast<uintptr_t>(Date::ToDateString),
263     reinterpret_cast<uintptr_t>(Date::ToISOString),
264     reinterpret_cast<uintptr_t>(Date::ToJSON),
265     reinterpret_cast<uintptr_t>(Date::ToLocaleDateString),
266     reinterpret_cast<uintptr_t>(Date::ToLocaleString),
267     reinterpret_cast<uintptr_t>(Date::ToLocaleTimeString),
268     reinterpret_cast<uintptr_t>(Date::ToString),
269     reinterpret_cast<uintptr_t>(Date::ToTimeString),
270     reinterpret_cast<uintptr_t>(Date::ToUTCString),
271     reinterpret_cast<uintptr_t>(Date::ValueOf),
272     reinterpret_cast<uintptr_t>(Date::ToPrimitive),
273     reinterpret_cast<uintptr_t>(Date::Now),
274     reinterpret_cast<uintptr_t>(Date::Parse),
275     reinterpret_cast<uintptr_t>(Date::UTC),
276     reinterpret_cast<uintptr_t>(Object::Assign),
277     reinterpret_cast<uintptr_t>(Object::Create),
278     reinterpret_cast<uintptr_t>(Object::DefineProperties),
279     reinterpret_cast<uintptr_t>(Object::DefineProperty),
280     reinterpret_cast<uintptr_t>(Object::Freeze),
281     reinterpret_cast<uintptr_t>(Object::GetOwnPropertyDescriptor),
282     reinterpret_cast<uintptr_t>(Object::GetOwnPropertyDescriptors),
283     reinterpret_cast<uintptr_t>(Object::GetOwnPropertyNames),
284     reinterpret_cast<uintptr_t>(Object::GetOwnPropertySymbols),
285     reinterpret_cast<uintptr_t>(Object::GetPrototypeOf),
286     reinterpret_cast<uintptr_t>(Object::Is),
287     reinterpret_cast<uintptr_t>(Object::IsExtensible),
288     reinterpret_cast<uintptr_t>(Object::IsFrozen),
289     reinterpret_cast<uintptr_t>(Object::IsSealed),
290     reinterpret_cast<uintptr_t>(Object::Keys),
291     reinterpret_cast<uintptr_t>(Object::Values),
292     reinterpret_cast<uintptr_t>(Object::PreventExtensions),
293     reinterpret_cast<uintptr_t>(Object::Seal),
294     reinterpret_cast<uintptr_t>(Object::SetPrototypeOf),
295     reinterpret_cast<uintptr_t>(Object::HasOwnProperty),
296     reinterpret_cast<uintptr_t>(Object::IsPrototypeOf),
297     reinterpret_cast<uintptr_t>(Object::PropertyIsEnumerable),
298     reinterpret_cast<uintptr_t>(Object::ToLocaleString),
299     reinterpret_cast<uintptr_t>(Object::ToString),
300     reinterpret_cast<uintptr_t>(Object::ValueOf),
301     reinterpret_cast<uintptr_t>(Object::ProtoGetter),
302     reinterpret_cast<uintptr_t>(Object::ProtoSetter),
303     reinterpret_cast<uintptr_t>(Object::CreateRealm),
304     reinterpret_cast<uintptr_t>(Object::Entries),
305     reinterpret_cast<uintptr_t>(Object::HasOwn),
306     reinterpret_cast<uintptr_t>(Boolean::BooleanConstructor),
307     reinterpret_cast<uintptr_t>(Boolean::BooleanPrototypeToString),
308     reinterpret_cast<uintptr_t>(Boolean::BooleanPrototypeValueOf),
309     reinterpret_cast<uintptr_t>(RegExp::RegExpConstructor),
310     reinterpret_cast<uintptr_t>(RegExp::Exec),
311     reinterpret_cast<uintptr_t>(RegExp::Test),
312     reinterpret_cast<uintptr_t>(RegExp::ToString),
313     reinterpret_cast<uintptr_t>(RegExp::GetFlags),
314     reinterpret_cast<uintptr_t>(RegExp::GetSource),
315     reinterpret_cast<uintptr_t>(RegExp::GetGlobal),
316     reinterpret_cast<uintptr_t>(RegExp::GetHasIndices),
317     reinterpret_cast<uintptr_t>(RegExp::GetIgnoreCase),
318     reinterpret_cast<uintptr_t>(RegExp::GetMultiline),
319     reinterpret_cast<uintptr_t>(RegExp::GetDotAll),
320     reinterpret_cast<uintptr_t>(RegExp::GetSticky),
321     reinterpret_cast<uintptr_t>(RegExp::GetUnicode),
322     reinterpret_cast<uintptr_t>(RegExp::Split),
323     reinterpret_cast<uintptr_t>(RegExp::Search),
324     reinterpret_cast<uintptr_t>(RegExp::Match),
325     reinterpret_cast<uintptr_t>(RegExp::MatchAll),
326     reinterpret_cast<uintptr_t>(RegExp::Replace),
327     reinterpret_cast<uintptr_t>(BuiltinsSet::SetConstructor),
328     reinterpret_cast<uintptr_t>(BuiltinsSet::Add),
329     reinterpret_cast<uintptr_t>(BuiltinsSet::Clear),
330     reinterpret_cast<uintptr_t>(BuiltinsSet::Delete),
331     reinterpret_cast<uintptr_t>(BuiltinsSet::Has),
332     reinterpret_cast<uintptr_t>(BuiltinsSet::ForEach),
333     reinterpret_cast<uintptr_t>(BuiltinsSet::Entries),
334     reinterpret_cast<uintptr_t>(BuiltinsSet::Values),
335     reinterpret_cast<uintptr_t>(BuiltinsSet::GetSize),
336     reinterpret_cast<uintptr_t>(BuiltinsSet::Species),
337     reinterpret_cast<uintptr_t>(BuiltinsMap::MapConstructor),
338     reinterpret_cast<uintptr_t>(BuiltinsMap::Set),
339     reinterpret_cast<uintptr_t>(BuiltinsMap::Clear),
340     reinterpret_cast<uintptr_t>(BuiltinsMap::Delete),
341     reinterpret_cast<uintptr_t>(BuiltinsMap::Has),
342     reinterpret_cast<uintptr_t>(BuiltinsMap::Get),
343     reinterpret_cast<uintptr_t>(BuiltinsMap::ForEach),
344     reinterpret_cast<uintptr_t>(BuiltinsMap::Keys),
345     reinterpret_cast<uintptr_t>(BuiltinsMap::Values),
346     reinterpret_cast<uintptr_t>(BuiltinsMap::Entries),
347     reinterpret_cast<uintptr_t>(BuiltinsMap::GetSize),
348     reinterpret_cast<uintptr_t>(BuiltinsWeakMap::WeakMapConstructor),
349     reinterpret_cast<uintptr_t>(BuiltinsWeakMap::Set),
350     reinterpret_cast<uintptr_t>(BuiltinsWeakMap::Delete),
351     reinterpret_cast<uintptr_t>(BuiltinsWeakMap::Has),
352     reinterpret_cast<uintptr_t>(BuiltinsWeakMap::Get),
353     reinterpret_cast<uintptr_t>(BuiltinsWeakSet::WeakSetConstructor),
354     reinterpret_cast<uintptr_t>(BuiltinsWeakSet::Add),
355     reinterpret_cast<uintptr_t>(BuiltinsWeakSet::Delete),
356     reinterpret_cast<uintptr_t>(BuiltinsWeakSet::Has),
357     reinterpret_cast<uintptr_t>(BuiltinsWeakRef::WeakRefConstructor),
358     reinterpret_cast<uintptr_t>(BuiltinsWeakRef::Deref),
359     reinterpret_cast<uintptr_t>(BuiltinsFinalizationRegistry::FinalizationRegistryConstructor),
360     reinterpret_cast<uintptr_t>(BuiltinsFinalizationRegistry::Register),
361     reinterpret_cast<uintptr_t>(BuiltinsFinalizationRegistry::Unregister),
362     reinterpret_cast<uintptr_t>(BuiltinsArray::ArrayConstructor),
363     reinterpret_cast<uintptr_t>(BuiltinsArray::Concat),
364     reinterpret_cast<uintptr_t>(BuiltinsArray::CopyWithin),
365     reinterpret_cast<uintptr_t>(BuiltinsArray::Entries),
366     reinterpret_cast<uintptr_t>(BuiltinsArray::Every),
367     reinterpret_cast<uintptr_t>(BuiltinsArray::Fill),
368     reinterpret_cast<uintptr_t>(BuiltinsArray::Filter),
369     reinterpret_cast<uintptr_t>(BuiltinsArray::Find),
370     reinterpret_cast<uintptr_t>(BuiltinsArray::FindIndex),
371     reinterpret_cast<uintptr_t>(BuiltinsArray::FindLast),
372     reinterpret_cast<uintptr_t>(BuiltinsArray::FindLastIndex),
373     reinterpret_cast<uintptr_t>(BuiltinsArray::ForEach),
374     reinterpret_cast<uintptr_t>(BuiltinsArray::IndexOf),
375     reinterpret_cast<uintptr_t>(BuiltinsArray::Join),
376     reinterpret_cast<uintptr_t>(BuiltinsArray::Keys),
377     reinterpret_cast<uintptr_t>(BuiltinsArray::LastIndexOf),
378     reinterpret_cast<uintptr_t>(BuiltinsArray::Map),
379     reinterpret_cast<uintptr_t>(BuiltinsArray::Pop),
380     reinterpret_cast<uintptr_t>(BuiltinsArray::Push),
381     reinterpret_cast<uintptr_t>(BuiltinsArray::Reduce),
382     reinterpret_cast<uintptr_t>(BuiltinsArray::ReduceRight),
383     reinterpret_cast<uintptr_t>(BuiltinsArray::Reverse),
384     reinterpret_cast<uintptr_t>(BuiltinsArray::Shift),
385     reinterpret_cast<uintptr_t>(BuiltinsArray::Slice),
386     reinterpret_cast<uintptr_t>(BuiltinsArray::Some),
387     reinterpret_cast<uintptr_t>(BuiltinsArray::Sort),
388     reinterpret_cast<uintptr_t>(BuiltinsArray::Splice),
389     reinterpret_cast<uintptr_t>(BuiltinsArray::ToLocaleString),
390     reinterpret_cast<uintptr_t>(BuiltinsArray::ToString),
391     reinterpret_cast<uintptr_t>(BuiltinsArray::Unshift),
392     reinterpret_cast<uintptr_t>(BuiltinsArray::Values),
393     reinterpret_cast<uintptr_t>(BuiltinsArray::From),
394     reinterpret_cast<uintptr_t>(BuiltinsArray::IsArray),
395     reinterpret_cast<uintptr_t>(BuiltinsArray::Of),
396     reinterpret_cast<uintptr_t>(BuiltinsArray::Species),
397     reinterpret_cast<uintptr_t>(BuiltinsArray::Includes),
398     reinterpret_cast<uintptr_t>(BuiltinsArray::Flat),
399     reinterpret_cast<uintptr_t>(BuiltinsArray::FlatMap),
400     reinterpret_cast<uintptr_t>(BuiltinsArray::At),
401     reinterpret_cast<uintptr_t>(BuiltinsArray::ToReversed),
402     reinterpret_cast<uintptr_t>(BuiltinsArray::With),
403     reinterpret_cast<uintptr_t>(BuiltinsArray::ToSorted),
404     reinterpret_cast<uintptr_t>(BuiltinsArray::ToSpliced),
405     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::TypedArrayBaseConstructor),
406     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::CopyWithin),
407     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::Entries),
408     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::Every),
409     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::Fill),
410     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::Filter),
411     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::Find),
412     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::FindIndex),
413     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::FindLast),
414     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::FindLastIndex),
415     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::ForEach),
416     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::IndexOf),
417     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::Join),
418     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::Keys),
419     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::LastIndexOf),
420     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::Map),
421     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::Reduce),
422     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::ReduceRight),
423     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::Reverse),
424     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::Set),
425     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::Slice),
426     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::Some),
427     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::Sort),
428     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::ToSorted),
429     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::Subarray),
430     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::ToLocaleString),
431     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::Values),
432     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::With),
433     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::GetBuffer),
434     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::GetByteLength),
435     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::GetByteOffset),
436     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::GetLength),
437     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::ToStringTag),
438     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::At),
439     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::ToReversed),
440     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::From),
441     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::Of),
442     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::Species),
443     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::Includes),
444     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::Int8ArrayConstructor),
445     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::Uint8ArrayConstructor),
446     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::Uint8ClampedArrayConstructor),
447     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::Int16ArrayConstructor),
448     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::Uint16ArrayConstructor),
449     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::Int32ArrayConstructor),
450     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::Uint32ArrayConstructor),
451     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::Float32ArrayConstructor),
452     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::Float64ArrayConstructor),
453     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::BigInt64ArrayConstructor),
454     reinterpret_cast<uintptr_t>(BuiltinsTypedArray::BigUint64ArrayConstructor),
455     reinterpret_cast<uintptr_t>(BuiltinsString::StringConstructor),
456     reinterpret_cast<uintptr_t>(BuiltinsString::At),
457     reinterpret_cast<uintptr_t>(BuiltinsString::CharAt),
458     reinterpret_cast<uintptr_t>(BuiltinsString::CharCodeAt),
459     reinterpret_cast<uintptr_t>(BuiltinsString::CodePointAt),
460     reinterpret_cast<uintptr_t>(BuiltinsString::IsWellFormed),
461     reinterpret_cast<uintptr_t>(BuiltinsString::ToWellFormed),
462     reinterpret_cast<uintptr_t>(BuiltinsString::Concat),
463     reinterpret_cast<uintptr_t>(BuiltinsString::EndsWith),
464     reinterpret_cast<uintptr_t>(BuiltinsString::Includes),
465     reinterpret_cast<uintptr_t>(BuiltinsString::IndexOf),
466     reinterpret_cast<uintptr_t>(BuiltinsString::LastIndexOf),
467     reinterpret_cast<uintptr_t>(BuiltinsString::LocaleCompare),
468     reinterpret_cast<uintptr_t>(BuiltinsString::Match),
469     reinterpret_cast<uintptr_t>(BuiltinsString::MatchAll),
470     reinterpret_cast<uintptr_t>(BuiltinsString::Normalize),
471     reinterpret_cast<uintptr_t>(BuiltinsString::PadEnd),
472     reinterpret_cast<uintptr_t>(BuiltinsString::PadStart),
473     reinterpret_cast<uintptr_t>(BuiltinsString::Repeat),
474     reinterpret_cast<uintptr_t>(BuiltinsString::Replace),
475     reinterpret_cast<uintptr_t>(BuiltinsString::ReplaceAll),
476     reinterpret_cast<uintptr_t>(BuiltinsString::Search),
477     reinterpret_cast<uintptr_t>(BuiltinsString::Slice),
478     reinterpret_cast<uintptr_t>(BuiltinsString::Split),
479     reinterpret_cast<uintptr_t>(BuiltinsString::StartsWith),
480     reinterpret_cast<uintptr_t>(BuiltinsString::Substring),
481     reinterpret_cast<uintptr_t>(BuiltinsString::SubStr),
482     reinterpret_cast<uintptr_t>(BuiltinsString::ToLocaleLowerCase),
483     reinterpret_cast<uintptr_t>(BuiltinsString::ToLocaleUpperCase),
484     reinterpret_cast<uintptr_t>(BuiltinsString::ToLowerCase),
485     reinterpret_cast<uintptr_t>(BuiltinsString::ToString),
486     reinterpret_cast<uintptr_t>(BuiltinsString::ToUpperCase),
487     reinterpret_cast<uintptr_t>(BuiltinsString::Trim),
488     reinterpret_cast<uintptr_t>(BuiltinsString::TrimStart),
489     reinterpret_cast<uintptr_t>(BuiltinsString::TrimEnd),
490     reinterpret_cast<uintptr_t>(BuiltinsString::TrimLeft),
491     reinterpret_cast<uintptr_t>(BuiltinsString::TrimRight),
492     reinterpret_cast<uintptr_t>(BuiltinsString::ValueOf),
493     reinterpret_cast<uintptr_t>(BuiltinsString::GetStringIterator),
494     reinterpret_cast<uintptr_t>(BuiltinsString::FromCharCode),
495     reinterpret_cast<uintptr_t>(BuiltinsString::FromCodePoint),
496     reinterpret_cast<uintptr_t>(BuiltinsString::Raw),
497     reinterpret_cast<uintptr_t>(BuiltinsString::GetLength),
498     reinterpret_cast<uintptr_t>(ArrayBuffer::ArrayBufferConstructor),
499     reinterpret_cast<uintptr_t>(ArrayBuffer::Slice),
500     reinterpret_cast<uintptr_t>(ArrayBuffer::IsView),
501     reinterpret_cast<uintptr_t>(ArrayBuffer::Species),
502     reinterpret_cast<uintptr_t>(ArrayBuffer::GetByteLength),
503     reinterpret_cast<uintptr_t>(SharedArrayBuffer::SharedArrayBufferConstructor),
504     reinterpret_cast<uintptr_t>(SharedArrayBuffer::IsSharedArrayBuffer),
505     reinterpret_cast<uintptr_t>(SharedArrayBuffer::Species),
506     reinterpret_cast<uintptr_t>(SharedArrayBuffer::GetByteLength),
507     reinterpret_cast<uintptr_t>(SharedArrayBuffer::Slice),
508     reinterpret_cast<uintptr_t>(DataView::DataViewConstructor),
509     reinterpret_cast<uintptr_t>(DataView::GetFloat32),
510     reinterpret_cast<uintptr_t>(DataView::GetFloat64),
511     reinterpret_cast<uintptr_t>(DataView::GetInt8),
512     reinterpret_cast<uintptr_t>(DataView::GetInt16),
513     reinterpret_cast<uintptr_t>(DataView::GetInt32),
514     reinterpret_cast<uintptr_t>(DataView::GetUint8),
515     reinterpret_cast<uintptr_t>(DataView::GetUint16),
516     reinterpret_cast<uintptr_t>(DataView::GetUint32),
517     reinterpret_cast<uintptr_t>(DataView::SetFloat32),
518     reinterpret_cast<uintptr_t>(DataView::SetFloat64),
519     reinterpret_cast<uintptr_t>(DataView::GetBigInt64),
520     reinterpret_cast<uintptr_t>(DataView::GetBigUint64),
521     reinterpret_cast<uintptr_t>(DataView::SetInt8),
522     reinterpret_cast<uintptr_t>(DataView::SetInt16),
523     reinterpret_cast<uintptr_t>(DataView::SetInt32),
524     reinterpret_cast<uintptr_t>(DataView::SetUint8),
525     reinterpret_cast<uintptr_t>(DataView::SetUint16),
526     reinterpret_cast<uintptr_t>(DataView::SetUint32),
527     reinterpret_cast<uintptr_t>(DataView::GetBuffer),
528     reinterpret_cast<uintptr_t>(DataView::GetByteLength),
529     reinterpret_cast<uintptr_t>(DataView::GetOffset),
530     reinterpret_cast<uintptr_t>(DataView::SetBigInt64),
531     reinterpret_cast<uintptr_t>(DataView::SetBigUint64),
532     reinterpret_cast<uintptr_t>(Global::PrintEntrypoint),
533     reinterpret_cast<uintptr_t>(Global::NotSupportEval),
534     reinterpret_cast<uintptr_t>(Global::IsFinite),
535     reinterpret_cast<uintptr_t>(Global::IsNaN),
536     reinterpret_cast<uintptr_t>(Global::DecodeURI),
537     reinterpret_cast<uintptr_t>(Global::DecodeURIComponent),
538     reinterpret_cast<uintptr_t>(Global::EncodeURI),
539     reinterpret_cast<uintptr_t>(Global::EncodeURIComponent),
540     reinterpret_cast<uintptr_t>(Math::Abs),
541     reinterpret_cast<uintptr_t>(Math::Acos),
542     reinterpret_cast<uintptr_t>(Math::Acosh),
543     reinterpret_cast<uintptr_t>(Math::Asin),
544     reinterpret_cast<uintptr_t>(Math::Asinh),
545     reinterpret_cast<uintptr_t>(Math::Atan),
546     reinterpret_cast<uintptr_t>(Math::Atanh),
547     reinterpret_cast<uintptr_t>(Math::Atan2),
548     reinterpret_cast<uintptr_t>(Math::Cbrt),
549     reinterpret_cast<uintptr_t>(Math::Ceil),
550     reinterpret_cast<uintptr_t>(Math::Clz32),
551     reinterpret_cast<uintptr_t>(Math::Cos),
552     reinterpret_cast<uintptr_t>(Math::Cosh),
553     reinterpret_cast<uintptr_t>(Math::Exp),
554     reinterpret_cast<uintptr_t>(Math::Expm1),
555     reinterpret_cast<uintptr_t>(Math::Floor),
556     reinterpret_cast<uintptr_t>(Math::Fround),
557     reinterpret_cast<uintptr_t>(Math::Hypot),
558     reinterpret_cast<uintptr_t>(Math::Imul),
559     reinterpret_cast<uintptr_t>(Math::Log),
560     reinterpret_cast<uintptr_t>(Math::Log1p),
561     reinterpret_cast<uintptr_t>(Math::Log10),
562     reinterpret_cast<uintptr_t>(Math::Log2),
563     reinterpret_cast<uintptr_t>(Math::Max),
564     reinterpret_cast<uintptr_t>(Math::Min),
565     reinterpret_cast<uintptr_t>(Math::Pow),
566     reinterpret_cast<uintptr_t>(Math::Random),
567     reinterpret_cast<uintptr_t>(Math::Round),
568     reinterpret_cast<uintptr_t>(Math::Sign),
569     reinterpret_cast<uintptr_t>(Math::Sin),
570     reinterpret_cast<uintptr_t>(Math::Sinh),
571     reinterpret_cast<uintptr_t>(Math::Sqrt),
572     reinterpret_cast<uintptr_t>(Math::Tan),
573     reinterpret_cast<uintptr_t>(Math::Tanh),
574     reinterpret_cast<uintptr_t>(Math::Trunc),
575     reinterpret_cast<uintptr_t>(Atomics::Wait),
576     reinterpret_cast<uintptr_t>(Atomics::Exchange),
577     reinterpret_cast<uintptr_t>(Atomics::CompareExchange),
578     reinterpret_cast<uintptr_t>(Atomics::IsLockFree),
579     reinterpret_cast<uintptr_t>(Atomics::Store),
580     reinterpret_cast<uintptr_t>(Atomics::Load),
581     reinterpret_cast<uintptr_t>(Atomics::Notify),
582     reinterpret_cast<uintptr_t>(Atomics::Xor),
583     reinterpret_cast<uintptr_t>(Atomics::Or),
584     reinterpret_cast<uintptr_t>(Atomics::Sub),
585     reinterpret_cast<uintptr_t>(Atomics::And),
586     reinterpret_cast<uintptr_t>(Atomics::Add),
587     reinterpret_cast<uintptr_t>(Json::Parse),
588     reinterpret_cast<uintptr_t>(Json::Stringify),
589     reinterpret_cast<uintptr_t>(BuiltinsIterator::Next),
590     reinterpret_cast<uintptr_t>(BuiltinsIterator::Return),
591     reinterpret_cast<uintptr_t>(BuiltinsIterator::Throw),
592     reinterpret_cast<uintptr_t>(BuiltinsIterator::GetIteratorObj),
593     reinterpret_cast<uintptr_t>(BuiltinsAsyncIterator::Next),
594     reinterpret_cast<uintptr_t>(BuiltinsAsyncIterator::Return),
595     reinterpret_cast<uintptr_t>(BuiltinsAsyncIterator::Throw),
596     reinterpret_cast<uintptr_t>(BuiltinsAsyncIterator::GetAsyncIteratorObj),
597     reinterpret_cast<uintptr_t>(JSForInIterator::Next),
598     reinterpret_cast<uintptr_t>(JSRegExpIterator::Next),
599     reinterpret_cast<uintptr_t>(JSSetIterator::Next),
600     reinterpret_cast<uintptr_t>(JSMapIterator::Next),
601     reinterpret_cast<uintptr_t>(JSArrayIterator::Next),
602     reinterpret_cast<uintptr_t>(Proxy::ProxyConstructor),
603     reinterpret_cast<uintptr_t>(Proxy::Revocable),
604     reinterpret_cast<uintptr_t>(Reflect::ReflectApply),
605     reinterpret_cast<uintptr_t>(Reflect::ReflectConstruct),
606     reinterpret_cast<uintptr_t>(Reflect::ReflectDefineProperty),
607     reinterpret_cast<uintptr_t>(Reflect::ReflectDeleteProperty),
608     reinterpret_cast<uintptr_t>(Reflect::ReflectGet),
609     reinterpret_cast<uintptr_t>(Reflect::ReflectGetOwnPropertyDescriptor),
610     reinterpret_cast<uintptr_t>(Reflect::ReflectGetPrototypeOf),
611     reinterpret_cast<uintptr_t>(Reflect::ReflectHas),
612     reinterpret_cast<uintptr_t>(Reflect::ReflectIsExtensible),
613     reinterpret_cast<uintptr_t>(Reflect::ReflectOwnKeys),
614     reinterpret_cast<uintptr_t>(Reflect::ReflectPreventExtensions),
615     reinterpret_cast<uintptr_t>(Reflect::ReflectSet),
616     reinterpret_cast<uintptr_t>(Reflect::ReflectSetPrototypeOf),
617     reinterpret_cast<uintptr_t>(AsyncFunction::AsyncFunctionConstructor),
618     reinterpret_cast<uintptr_t>(GeneratorObject::GeneratorPrototypeNext),
619     reinterpret_cast<uintptr_t>(GeneratorObject::GeneratorPrototypeReturn),
620     reinterpret_cast<uintptr_t>(GeneratorObject::GeneratorPrototypeThrow),
621     reinterpret_cast<uintptr_t>(GeneratorObject::GeneratorFunctionConstructor),
622     reinterpret_cast<uintptr_t>(AsyncGeneratorObject::AsyncGeneratorPrototypeNext),
623     reinterpret_cast<uintptr_t>(AsyncGeneratorObject::AsyncGeneratorPrototypeReturn),
624     reinterpret_cast<uintptr_t>(AsyncGeneratorObject::AsyncGeneratorPrototypeThrow),
625     reinterpret_cast<uintptr_t>(AsyncGeneratorObject::AsyncGeneratorFunctionConstructor),
626     reinterpret_cast<uintptr_t>(Promise::PromiseConstructor),
627     reinterpret_cast<uintptr_t>(Promise::All),
628     reinterpret_cast<uintptr_t>(Promise::Race),
629     reinterpret_cast<uintptr_t>(Promise::Resolve),
630     reinterpret_cast<uintptr_t>(Promise::Reject),
631     reinterpret_cast<uintptr_t>(Promise::Catch),
632     reinterpret_cast<uintptr_t>(Promise::Then),
633     reinterpret_cast<uintptr_t>(Promise::Finally),
634     reinterpret_cast<uintptr_t>(Promise::Any),
635     reinterpret_cast<uintptr_t>(Promise::AllSettled),
636     reinterpret_cast<uintptr_t>(Promise::GetSpecies),
637     reinterpret_cast<uintptr_t>(BuiltinsPromiseJob::PromiseReactionJob),
638     reinterpret_cast<uintptr_t>(BuiltinsPromiseJob::PromiseResolveThenableJob),
639     reinterpret_cast<uintptr_t>(BuiltinsPromiseJob::DynamicImportJob),
640     reinterpret_cast<uintptr_t>(BuiltinsCjsExports::CjsExportsConstructor),
641     reinterpret_cast<uintptr_t>(BuiltinsCjsModule::CjsModuleConstructor),
642     reinterpret_cast<uintptr_t>(BuiltinsCjsModule::Compiler),
643     reinterpret_cast<uintptr_t>(BuiltinsCjsModule::Load),
644     reinterpret_cast<uintptr_t>(BuiltinsCjsModule::Require),
645     reinterpret_cast<uintptr_t>(BuiltinsCjsModule::GetExportsForCircularRequire),
646     reinterpret_cast<uintptr_t>(BuiltinsCjsModule::UpdateChildren),
647     reinterpret_cast<uintptr_t>(BuiltinsCjsModule::ResolveFilename),
648     reinterpret_cast<uintptr_t>(BuiltinsCjsRequire::CjsRequireConstructor),
649     reinterpret_cast<uintptr_t>(BuiltinsCjsRequire::Main),
650     reinterpret_cast<uintptr_t>(BuiltinsCjsRequire::Resolve),
651     reinterpret_cast<uintptr_t>(ArkTools::ObjectDump),
652     reinterpret_cast<uintptr_t>(ArkTools::CompareHClass),
653     reinterpret_cast<uintptr_t>(ArkTools::DumpHClass),
654     reinterpret_cast<uintptr_t>(BuiltinsBigInt::BigIntConstructor),
655     reinterpret_cast<uintptr_t>(BuiltinsBigInt::AsUintN),
656     reinterpret_cast<uintptr_t>(BuiltinsBigInt::AsIntN),
657     reinterpret_cast<uintptr_t>(BuiltinsBigInt::ToLocaleString),
658     reinterpret_cast<uintptr_t>(BuiltinsBigInt::ToString),
659     reinterpret_cast<uintptr_t>(BuiltinsBigInt::ValueOf),
660 #ifdef ARK_SUPPORT_INTL
661     reinterpret_cast<uintptr_t>(DisplayNames::DisplayNamesConstructor),
662     reinterpret_cast<uintptr_t>(DisplayNames::SupportedLocalesOf),
663     reinterpret_cast<uintptr_t>(DisplayNames::Of),
664     reinterpret_cast<uintptr_t>(DisplayNames::ResolvedOptions),
665     reinterpret_cast<uintptr_t>(Intl::GetCanonicalLocales),
666     reinterpret_cast<uintptr_t>(Locale::LocaleConstructor),
667     reinterpret_cast<uintptr_t>(Locale::Maximize),
668     reinterpret_cast<uintptr_t>(Locale::Minimize),
669     reinterpret_cast<uintptr_t>(Locale::ToString),
670     reinterpret_cast<uintptr_t>(Locale::GetBaseName),
671     reinterpret_cast<uintptr_t>(Locale::GetCalendar),
672     reinterpret_cast<uintptr_t>(Locale::GetCaseFirst),
673     reinterpret_cast<uintptr_t>(Locale::GetCollation),
674     reinterpret_cast<uintptr_t>(Locale::GetHourCycle),
675     reinterpret_cast<uintptr_t>(Locale::GetNumeric),
676     reinterpret_cast<uintptr_t>(Locale::GetNumberingSystem),
677     reinterpret_cast<uintptr_t>(Locale::GetLanguage),
678     reinterpret_cast<uintptr_t>(Locale::GetScript),
679     reinterpret_cast<uintptr_t>(Locale::GetRegion),
680     reinterpret_cast<uintptr_t>(DateTimeFormat::DateTimeFormatConstructor),
681     reinterpret_cast<uintptr_t>(DateTimeFormat::SupportedLocalesOf),
682     reinterpret_cast<uintptr_t>(DateTimeFormat::Format),
683     reinterpret_cast<uintptr_t>(DateTimeFormat::FormatToParts),
684     reinterpret_cast<uintptr_t>(DateTimeFormat::ResolvedOptions),
685     reinterpret_cast<uintptr_t>(DateTimeFormat::FormatRange),
686     reinterpret_cast<uintptr_t>(DateTimeFormat::FormatRangeToParts),
687     reinterpret_cast<uintptr_t>(NumberFormat::NumberFormatConstructor),
688     reinterpret_cast<uintptr_t>(NumberFormat::SupportedLocalesOf),
689     reinterpret_cast<uintptr_t>(NumberFormat::Format),
690     reinterpret_cast<uintptr_t>(NumberFormat::FormatToParts),
691     reinterpret_cast<uintptr_t>(NumberFormat::ResolvedOptions),
692     reinterpret_cast<uintptr_t>(RelativeTimeFormat::RelativeTimeFormatConstructor),
693     reinterpret_cast<uintptr_t>(RelativeTimeFormat::SupportedLocalesOf),
694     reinterpret_cast<uintptr_t>(RelativeTimeFormat::Format),
695     reinterpret_cast<uintptr_t>(RelativeTimeFormat::FormatToParts),
696     reinterpret_cast<uintptr_t>(RelativeTimeFormat::ResolvedOptions),
697     reinterpret_cast<uintptr_t>(Collator::CollatorConstructor),
698     reinterpret_cast<uintptr_t>(Collator::SupportedLocalesOf),
699     reinterpret_cast<uintptr_t>(Collator::Compare),
700     reinterpret_cast<uintptr_t>(Collator::ResolvedOptions),
701     reinterpret_cast<uintptr_t>(PluralRules::PluralRulesConstructor),
702     reinterpret_cast<uintptr_t>(PluralRules::SupportedLocalesOf),
703     reinterpret_cast<uintptr_t>(PluralRules::Select),
704     reinterpret_cast<uintptr_t>(PluralRules::ResolvedOptions),
705     reinterpret_cast<uintptr_t>(ListFormat::ListFormatConstructor),
706     reinterpret_cast<uintptr_t>(ListFormat::SupportedLocalesOf),
707     reinterpret_cast<uintptr_t>(ListFormat::Format),
708     reinterpret_cast<uintptr_t>(ListFormat::FormatToParts),
709     reinterpret_cast<uintptr_t>(ListFormat::ResolvedOptions),
710     reinterpret_cast<uintptr_t>(Segmenter::SegmenterConstructor),
711     reinterpret_cast<uintptr_t>(Segmenter::SupportedLocalesOf),
712     reinterpret_cast<uintptr_t>(Segmenter::ResolvedOptions),
713     reinterpret_cast<uintptr_t>(Segmenter::Segment),
714     reinterpret_cast<uintptr_t>(Segments::Containing),
715 #endif
716 
717     // non ECMA standard jsapi containers.
718     reinterpret_cast<uintptr_t>(ContainersPrivate::Load),
719     reinterpret_cast<uintptr_t>(ArrayList::ArrayListConstructor),
720     reinterpret_cast<uintptr_t>(ArrayList::Add),
721     reinterpret_cast<uintptr_t>(ArrayList::Insert),
722     reinterpret_cast<uintptr_t>(ArrayList::Clear),
723     reinterpret_cast<uintptr_t>(ArrayList::Clone),
724     reinterpret_cast<uintptr_t>(ArrayList::Has),
725     reinterpret_cast<uintptr_t>(ArrayList::GetCapacity),
726     reinterpret_cast<uintptr_t>(ArrayList::IncreaseCapacityTo),
727     reinterpret_cast<uintptr_t>(ArrayList::TrimToCurrentLength),
728     reinterpret_cast<uintptr_t>(ArrayList::GetIndexOf),
729     reinterpret_cast<uintptr_t>(ArrayList::IsEmpty),
730     reinterpret_cast<uintptr_t>(ArrayList::GetLastIndexOf),
731     reinterpret_cast<uintptr_t>(ArrayList::RemoveByIndex),
732     reinterpret_cast<uintptr_t>(ArrayList::Remove),
733     reinterpret_cast<uintptr_t>(ArrayList::RemoveByRange),
734     reinterpret_cast<uintptr_t>(ArrayList::ReplaceAllElements),
735     reinterpret_cast<uintptr_t>(ArrayList::SubArrayList),
736     reinterpret_cast<uintptr_t>(ArrayList::ConvertToArray),
737     reinterpret_cast<uintptr_t>(ArrayList::ForEach),
738     reinterpret_cast<uintptr_t>(ArrayList::GetIteratorObj),
739     reinterpret_cast<uintptr_t>(ArrayList::Get),
740     reinterpret_cast<uintptr_t>(ArrayList::Set),
741     reinterpret_cast<uintptr_t>(ArrayList::GetSize),
742     reinterpret_cast<uintptr_t>(JSAPIArrayListIterator::Next),
743     reinterpret_cast<uintptr_t>(HashMap::HashMapConstructor),
744     reinterpret_cast<uintptr_t>(HashMap::HasKey),
745     reinterpret_cast<uintptr_t>(HashMap::HasValue),
746     reinterpret_cast<uintptr_t>(HashMap::Replace),
747     reinterpret_cast<uintptr_t>(HashMap::Keys),
748     reinterpret_cast<uintptr_t>(HashMap::Values),
749     reinterpret_cast<uintptr_t>(HashMap::Entries),
750     reinterpret_cast<uintptr_t>(HashMap::ForEach),
751     reinterpret_cast<uintptr_t>(HashMap::Set),
752     reinterpret_cast<uintptr_t>(HashMap::SetAll),
753     reinterpret_cast<uintptr_t>(HashMap::Remove),
754     reinterpret_cast<uintptr_t>(HashMap::Get),
755     reinterpret_cast<uintptr_t>(HashMap::Clear),
756     reinterpret_cast<uintptr_t>(HashMap::GetLength),
757     reinterpret_cast<uintptr_t>(HashMap::IsEmpty),
758     reinterpret_cast<uintptr_t>(HashSet::HashSetConstructor),
759     reinterpret_cast<uintptr_t>(HashSet::IsEmpty),
760     reinterpret_cast<uintptr_t>(HashSet::Has),
761     reinterpret_cast<uintptr_t>(HashSet::Add),
762     reinterpret_cast<uintptr_t>(HashSet::Remove),
763     reinterpret_cast<uintptr_t>(HashSet::Clear),
764     reinterpret_cast<uintptr_t>(HashSet::GetLength),
765     reinterpret_cast<uintptr_t>(HashSet::Values),
766     reinterpret_cast<uintptr_t>(HashSet::Entries),
767     reinterpret_cast<uintptr_t>(JSAPIHashMapIterator::Next),
768     reinterpret_cast<uintptr_t>(JSAPIHashSetIterator::Next),
769     reinterpret_cast<uintptr_t>(LightWeightMap::HasAll),
770     reinterpret_cast<uintptr_t>(LightWeightMap::HasKey),
771     reinterpret_cast<uintptr_t>(LightWeightMap::HasValue),
772     reinterpret_cast<uintptr_t>(LightWeightMap::IncreaseCapacityTo),
773     reinterpret_cast<uintptr_t>(LightWeightMap::Entries),
774     reinterpret_cast<uintptr_t>(LightWeightMap::Get),
775     reinterpret_cast<uintptr_t>(LightWeightMap::GetIndexOfKey),
776     reinterpret_cast<uintptr_t>(LightWeightMap::GetIndexOfValue),
777     reinterpret_cast<uintptr_t>(LightWeightMap::IsEmpty),
778     reinterpret_cast<uintptr_t>(LightWeightMap::GetKeyAt),
779     reinterpret_cast<uintptr_t>(LightWeightMap::Keys),
780     reinterpret_cast<uintptr_t>(LightWeightMap::SetAll),
781     reinterpret_cast<uintptr_t>(LightWeightMap::Set),
782     reinterpret_cast<uintptr_t>(LightWeightMap::Remove),
783     reinterpret_cast<uintptr_t>(LightWeightMap::RemoveAt),
784     reinterpret_cast<uintptr_t>(LightWeightMap::Clear),
785     reinterpret_cast<uintptr_t>(LightWeightMap::SetValueAt),
786     reinterpret_cast<uintptr_t>(LightWeightMap::ForEach),
787     reinterpret_cast<uintptr_t>(LightWeightMap::ToString),
788     reinterpret_cast<uintptr_t>(LightWeightMap::GetValueAt),
789     reinterpret_cast<uintptr_t>(LightWeightMap::Values),
790     reinterpret_cast<uintptr_t>(JSAPILightWeightMapIterator::Next),
791     reinterpret_cast<uintptr_t>(LightWeightSet::LightWeightSetConstructor),
792     reinterpret_cast<uintptr_t>(LightWeightSet::Add),
793     reinterpret_cast<uintptr_t>(LightWeightSet::AddAll),
794     reinterpret_cast<uintptr_t>(LightWeightSet::IsEmpty),
795     reinterpret_cast<uintptr_t>(LightWeightSet::GetValueAt),
796     reinterpret_cast<uintptr_t>(LightWeightSet::HasAll),
797     reinterpret_cast<uintptr_t>(LightWeightSet::Has),
798     reinterpret_cast<uintptr_t>(LightWeightSet::HasHash),
799     reinterpret_cast<uintptr_t>(LightWeightSet::Equal),
800     reinterpret_cast<uintptr_t>(LightWeightSet::IncreaseCapacityTo),
801     reinterpret_cast<uintptr_t>(LightWeightSet::GetIteratorObj),
802     reinterpret_cast<uintptr_t>(LightWeightSet::Values),
803     reinterpret_cast<uintptr_t>(LightWeightSet::Entries),
804     reinterpret_cast<uintptr_t>(LightWeightSet::ForEach),
805     reinterpret_cast<uintptr_t>(LightWeightSet::GetIndexOf),
806     reinterpret_cast<uintptr_t>(LightWeightSet::Remove),
807     reinterpret_cast<uintptr_t>(LightWeightSet::RemoveAt),
808     reinterpret_cast<uintptr_t>(LightWeightSet::Clear),
809     reinterpret_cast<uintptr_t>(LightWeightSet::ToString),
810     reinterpret_cast<uintptr_t>(LightWeightSet::ToArray),
811     reinterpret_cast<uintptr_t>(LightWeightSet::GetSize),
812     reinterpret_cast<uintptr_t>(JSAPILightWeightSetIterator::Next),
813     reinterpret_cast<uintptr_t>(TreeMap::TreeMapConstructor),
814     reinterpret_cast<uintptr_t>(TreeMap::Set),
815     reinterpret_cast<uintptr_t>(TreeMap::Get),
816     reinterpret_cast<uintptr_t>(TreeMap::Remove),
817     reinterpret_cast<uintptr_t>(TreeMap::GetFirstKey),
818     reinterpret_cast<uintptr_t>(TreeMap::GetLastKey),
819     reinterpret_cast<uintptr_t>(TreeMap::GetLowerKey),
820     reinterpret_cast<uintptr_t>(TreeMap::GetHigherKey),
821     reinterpret_cast<uintptr_t>(TreeMap::HasKey),
822     reinterpret_cast<uintptr_t>(TreeMap::HasValue),
823     reinterpret_cast<uintptr_t>(TreeMap::SetAll),
824     reinterpret_cast<uintptr_t>(TreeMap::Replace),
825     reinterpret_cast<uintptr_t>(TreeMap::Keys),
826     reinterpret_cast<uintptr_t>(TreeMap::Values),
827     reinterpret_cast<uintptr_t>(TreeMap::Entries),
828     reinterpret_cast<uintptr_t>(TreeMap::ForEach),
829     reinterpret_cast<uintptr_t>(TreeMap::Clear),
830     reinterpret_cast<uintptr_t>(TreeMap::IsEmpty),
831     reinterpret_cast<uintptr_t>(TreeMap::GetLength),
832     reinterpret_cast<uintptr_t>(TreeSet::TreeSetConstructor),
833     reinterpret_cast<uintptr_t>(TreeSet::Add),
834     reinterpret_cast<uintptr_t>(TreeSet::Has),
835     reinterpret_cast<uintptr_t>(TreeSet::Remove),
836     reinterpret_cast<uintptr_t>(TreeSet::GetFirstValue),
837     reinterpret_cast<uintptr_t>(TreeSet::GetLastValue),
838     reinterpret_cast<uintptr_t>(TreeSet::GetLowerValue),
839     reinterpret_cast<uintptr_t>(TreeSet::GetHigherValue),
840     reinterpret_cast<uintptr_t>(TreeSet::PopFirst),
841     reinterpret_cast<uintptr_t>(TreeSet::PopLast),
842     reinterpret_cast<uintptr_t>(TreeSet::IsEmpty),
843     reinterpret_cast<uintptr_t>(TreeSet::Values),
844     reinterpret_cast<uintptr_t>(TreeSet::Entries),
845     reinterpret_cast<uintptr_t>(TreeSet::ForEach),
846     reinterpret_cast<uintptr_t>(TreeSet::Clear),
847     reinterpret_cast<uintptr_t>(TreeSet::GetLength),
848     reinterpret_cast<uintptr_t>(JSAPITreeMapIterator::Next),
849     reinterpret_cast<uintptr_t>(JSAPITreeSetIterator::Next),
850     reinterpret_cast<uintptr_t>(Deque::DequeConstructor),
851     reinterpret_cast<uintptr_t>(Deque::InsertFront),
852     reinterpret_cast<uintptr_t>(Deque::InsertEnd),
853     reinterpret_cast<uintptr_t>(Deque::GetFirst),
854     reinterpret_cast<uintptr_t>(Deque::GetLast),
855     reinterpret_cast<uintptr_t>(Deque::Has),
856     reinterpret_cast<uintptr_t>(Deque::PopFirst),
857     reinterpret_cast<uintptr_t>(Deque::PopLast),
858     reinterpret_cast<uintptr_t>(Deque::ForEach),
859     reinterpret_cast<uintptr_t>(Deque::GetIteratorObj),
860     reinterpret_cast<uintptr_t>(Deque::GetSize),
861     reinterpret_cast<uintptr_t>(JSAPIDequeIterator::Next),
862     reinterpret_cast<uintptr_t>(Vector::VectorConstructor),
863     reinterpret_cast<uintptr_t>(Vector::Add),
864     reinterpret_cast<uintptr_t>(Vector::Insert),
865     reinterpret_cast<uintptr_t>(Vector::SetLength),
866     reinterpret_cast<uintptr_t>(Vector::GetCapacity),
867     reinterpret_cast<uintptr_t>(Vector::IncreaseCapacityTo),
868     reinterpret_cast<uintptr_t>(Vector::Get),
869     reinterpret_cast<uintptr_t>(Vector::GetIndexOf),
870     reinterpret_cast<uintptr_t>(Vector::GetIndexFrom),
871     reinterpret_cast<uintptr_t>(Vector::IsEmpty),
872     reinterpret_cast<uintptr_t>(Vector::GetLastElement),
873     reinterpret_cast<uintptr_t>(Vector::GetLastIndexOf),
874     reinterpret_cast<uintptr_t>(Vector::GetLastIndexFrom),
875     reinterpret_cast<uintptr_t>(Vector::Remove),
876     reinterpret_cast<uintptr_t>(Vector::RemoveByIndex),
877     reinterpret_cast<uintptr_t>(Vector::RemoveByRange),
878     reinterpret_cast<uintptr_t>(Vector::Set),
879     reinterpret_cast<uintptr_t>(Vector::SubVector),
880     reinterpret_cast<uintptr_t>(Vector::ToString),
881     reinterpret_cast<uintptr_t>(Vector::GetSize),
882     reinterpret_cast<uintptr_t>(Vector::ForEach),
883     reinterpret_cast<uintptr_t>(Vector::ReplaceAllElements),
884     reinterpret_cast<uintptr_t>(Vector::TrimToCurrentLength),
885     reinterpret_cast<uintptr_t>(Vector::Clear),
886     reinterpret_cast<uintptr_t>(Vector::Clone),
887     reinterpret_cast<uintptr_t>(Vector::Has),
888     reinterpret_cast<uintptr_t>(Vector::GetFirstElement),
889     reinterpret_cast<uintptr_t>(Vector::CopyToArray),
890     reinterpret_cast<uintptr_t>(Vector::ConvertToArray),
891     reinterpret_cast<uintptr_t>(Vector::Sort),
892     reinterpret_cast<uintptr_t>(Vector::GetIteratorObj),
893     reinterpret_cast<uintptr_t>(JSAPIVectorIterator::Next),
894     reinterpret_cast<uintptr_t>(BitVector::BitVectorConstructor),
895     reinterpret_cast<uintptr_t>(BitVector::Push),
896     reinterpret_cast<uintptr_t>(BitVector::Pop),
897     reinterpret_cast<uintptr_t>(BitVector::Has),
898     reinterpret_cast<uintptr_t>(BitVector::SetBitsByRange),
899     reinterpret_cast<uintptr_t>(BitVector::GetBitsByRange),
900     reinterpret_cast<uintptr_t>(BitVector::Resize),
901     reinterpret_cast<uintptr_t>(BitVector::SetAllBits),
902     reinterpret_cast<uintptr_t>(BitVector::GetBitCountByRange),
903     reinterpret_cast<uintptr_t>(BitVector::GetIndexOf),
904     reinterpret_cast<uintptr_t>(BitVector::GetLastIndexOf),
905     reinterpret_cast<uintptr_t>(BitVector::FlipBitByIndex),
906     reinterpret_cast<uintptr_t>(BitVector::FlipBitsByRange),
907     reinterpret_cast<uintptr_t>(BitVector::GetSize),
908     reinterpret_cast<uintptr_t>(BitVector::GetIteratorObj),
909     reinterpret_cast<uintptr_t>(JSAPIBitVectorIterator::Next),
910     reinterpret_cast<uintptr_t>(Queue::QueueConstructor),
911     reinterpret_cast<uintptr_t>(Queue::Add),
912     reinterpret_cast<uintptr_t>(Queue::GetFirst),
913     reinterpret_cast<uintptr_t>(Queue::Pop),
914     reinterpret_cast<uintptr_t>(Queue::ForEach),
915     reinterpret_cast<uintptr_t>(Queue::GetIteratorObj),
916     reinterpret_cast<uintptr_t>(Queue::GetSize),
917     reinterpret_cast<uintptr_t>(JSAPIQueueIterator::Next),
918     reinterpret_cast<uintptr_t>(PlainArray::PlainArrayConstructor),
919     reinterpret_cast<uintptr_t>(PlainArray::Add),
920     reinterpret_cast<uintptr_t>(PlainArray::Clear),
921     reinterpret_cast<uintptr_t>(PlainArray::Clone),
922     reinterpret_cast<uintptr_t>(PlainArray::Has),
923     reinterpret_cast<uintptr_t>(PlainArray::Get),
924     reinterpret_cast<uintptr_t>(PlainArray::GetIteratorObj),
925     reinterpret_cast<uintptr_t>(PlainArray::ForEach),
926     reinterpret_cast<uintptr_t>(PlainArray::ToString),
927     reinterpret_cast<uintptr_t>(PlainArray::GetIndexOfKey),
928     reinterpret_cast<uintptr_t>(PlainArray::GetIndexOfValue),
929     reinterpret_cast<uintptr_t>(PlainArray::IsEmpty),
930     reinterpret_cast<uintptr_t>(PlainArray::GetKeyAt),
931     reinterpret_cast<uintptr_t>(PlainArray::Remove),
932     reinterpret_cast<uintptr_t>(PlainArray::RemoveAt),
933     reinterpret_cast<uintptr_t>(PlainArray::RemoveRangeFrom),
934     reinterpret_cast<uintptr_t>(PlainArray::SetValueAt),
935     reinterpret_cast<uintptr_t>(PlainArray::GetValueAt),
936     reinterpret_cast<uintptr_t>(PlainArray::GetSize),
937     reinterpret_cast<uintptr_t>(JSAPIPlainArrayIterator::Next),
938     reinterpret_cast<uintptr_t>(ContainerStack::StackConstructor),
939     reinterpret_cast<uintptr_t>(ContainerStack::Iterator),
940     reinterpret_cast<uintptr_t>(ContainerStack::IsEmpty),
941     reinterpret_cast<uintptr_t>(ContainerStack::Push),
942     reinterpret_cast<uintptr_t>(ContainerStack::Peek),
943     reinterpret_cast<uintptr_t>(ContainerStack::Pop),
944     reinterpret_cast<uintptr_t>(ContainerStack::Locate),
945     reinterpret_cast<uintptr_t>(ContainerStack::ForEach),
946     reinterpret_cast<uintptr_t>(ContainerStack::GetLength),
947     reinterpret_cast<uintptr_t>(JSAPIStackIterator::Next),
948     reinterpret_cast<uintptr_t>(List::ListConstructor),
949     reinterpret_cast<uintptr_t>(List::Add),
950     reinterpret_cast<uintptr_t>(List::GetFirst),
951     reinterpret_cast<uintptr_t>(List::GetLast),
952     reinterpret_cast<uintptr_t>(List::Insert),
953     reinterpret_cast<uintptr_t>(List::Clear),
954     reinterpret_cast<uintptr_t>(List::RemoveByIndex),
955     reinterpret_cast<uintptr_t>(List::Remove),
956     reinterpret_cast<uintptr_t>(List::Has),
957     reinterpret_cast<uintptr_t>(List::IsEmpty),
958     reinterpret_cast<uintptr_t>(List::Get),
959     reinterpret_cast<uintptr_t>(List::GetIndexOf),
960     reinterpret_cast<uintptr_t>(List::GetLastIndexOf),
961     reinterpret_cast<uintptr_t>(List::Set),
962     reinterpret_cast<uintptr_t>(List::ForEach),
963     reinterpret_cast<uintptr_t>(List::ReplaceAllElements),
964     reinterpret_cast<uintptr_t>(List::GetIteratorObj),
965     reinterpret_cast<uintptr_t>(List::Equal),
966     reinterpret_cast<uintptr_t>(List::Sort),
967     reinterpret_cast<uintptr_t>(List::ConvertToArray),
968     reinterpret_cast<uintptr_t>(List::GetSubList),
969     reinterpret_cast<uintptr_t>(List::Length),
970     reinterpret_cast<uintptr_t>(JSAPIListIterator::Next),
971     reinterpret_cast<uintptr_t>(LinkedList::LinkedListConstructor),
972     reinterpret_cast<uintptr_t>(LinkedList::Add),
973     reinterpret_cast<uintptr_t>(LinkedList::GetFirst),
974     reinterpret_cast<uintptr_t>(LinkedList::GetLast),
975     reinterpret_cast<uintptr_t>(LinkedList::Insert),
976     reinterpret_cast<uintptr_t>(LinkedList::AddFirst),
977     reinterpret_cast<uintptr_t>(LinkedList::Clear),
978     reinterpret_cast<uintptr_t>(LinkedList::Clone),
979     reinterpret_cast<uintptr_t>(LinkedList::Has),
980     reinterpret_cast<uintptr_t>(LinkedList::Get),
981     reinterpret_cast<uintptr_t>(LinkedList::GetIndexOf),
982     reinterpret_cast<uintptr_t>(LinkedList::GetLastIndexOf),
983     reinterpret_cast<uintptr_t>(LinkedList::RemoveByIndex),
984     reinterpret_cast<uintptr_t>(LinkedList::Remove),
985     reinterpret_cast<uintptr_t>(LinkedList::RemoveFirst),
986     reinterpret_cast<uintptr_t>(LinkedList::RemoveLast),
987     reinterpret_cast<uintptr_t>(LinkedList::RemoveFirstFound),
988     reinterpret_cast<uintptr_t>(LinkedList::RemoveLastFound),
989     reinterpret_cast<uintptr_t>(LinkedList::Set),
990     reinterpret_cast<uintptr_t>(LinkedList::ConvertToArray),
991     reinterpret_cast<uintptr_t>(LinkedList::ForEach),
992     reinterpret_cast<uintptr_t>(JSAPILinkedListIterator::Next),
993 
994     // not builtins method
995     reinterpret_cast<uintptr_t>(JSFunction::PrototypeSetter),
996     reinterpret_cast<uintptr_t>(JSFunction::PrototypeGetter),
997     reinterpret_cast<uintptr_t>(JSFunction::NameGetter),
998     reinterpret_cast<uintptr_t>(JSFunction::LengthGetter),
999     reinterpret_cast<uintptr_t>(JSArray::LengthSetter),
1000     reinterpret_cast<uintptr_t>(JSArray::LengthGetter),
1001     reinterpret_cast<uintptr_t>(JSPandaFileManager::GetInstance)
1002 };
1003 
Initialize()1004 void SnapshotProcessor::Initialize()
1005 {
1006     if (g_isEnableCMCGC) {
1007         commonRegionSize_ = common::Heap::GetNormalRegionAvailableSize();
1008         regularObjAllocator_.Initialize(commonRegionSize_);
1009         pinnedObjAllocator_.Initialize(commonRegionSize_);
1010         largeObjAllocator_.Initialize(commonRegionSize_);
1011     } else {
1012         auto heap = const_cast<Heap *>(vm_->GetHeap());
1013         size_t oldSpaceCapacity = heap->GetOldSpace()->GetInitialCapacity();
1014         oldLocalSpace_ = new LocalSpace(heap, oldSpaceCapacity, oldSpaceCapacity);
1015         size_t nonMovableCapacity = heap->GetNonMovableSpace()->GetInitialCapacity();
1016         nonMovableLocalSpace_ = new LocalSpace(heap, nonMovableCapacity, nonMovableCapacity);
1017         size_t machineCodeCapacity = heap->GetMachineCodeSpace()->GetInitialCapacity();
1018         machineCodeLocalSpace_ = new LocalSpace(heap, machineCodeCapacity, machineCodeCapacity);
1019         size_t snapshotSpaceCapacity = heap->GetSnapshotSpace()->GetMaximumCapacity();
1020         snapshotLocalSpace_ = new SnapshotSpace(heap, snapshotSpaceCapacity, snapshotSpaceCapacity);
1021         hugeObjectLocalSpace_ = new HugeObjectSpace(heap, heap->GetHeapRegionAllocator(),
1022                                                     oldSpaceCapacity, oldSpaceCapacity);
1023     }
1024 }
1025 
~SnapshotProcessor()1026 SnapshotProcessor::~SnapshotProcessor()
1027 {
1028     pandaMethod_.clear();
1029     stringVector_.clear();
1030     deserializeStringVector_.clear();
1031     regionIndexMap_.clear();
1032     if (g_isEnableCMCGC) {
1033         return;
1034     }
1035     if (oldLocalSpace_ != nullptr) {
1036         oldLocalSpace_->Reset();
1037         delete oldLocalSpace_;
1038         oldLocalSpace_ = nullptr;
1039     }
1040     if (nonMovableLocalSpace_ != nullptr) {
1041         nonMovableLocalSpace_->Reset();
1042         delete nonMovableLocalSpace_;
1043         nonMovableLocalSpace_ = nullptr;
1044     }
1045     if (machineCodeLocalSpace_ != nullptr) {
1046         machineCodeLocalSpace_->Reset();
1047         delete machineCodeLocalSpace_;
1048         machineCodeLocalSpace_ = nullptr;
1049     }
1050     if (snapshotLocalSpace_ != nullptr) {
1051         snapshotLocalSpace_->Destroy();
1052         delete snapshotLocalSpace_;
1053         snapshotLocalSpace_ = nullptr;
1054     }
1055     if (hugeObjectLocalSpace_ != nullptr) {
1056         hugeObjectLocalSpace_->Destroy();
1057         delete hugeObjectLocalSpace_;
1058         hugeObjectLocalSpace_ = nullptr;
1059     }
1060 }
1061 
StopAllocate()1062 void SnapshotProcessor::StopAllocate()
1063 {
1064     if (g_isEnableCMCGC) {
1065         regularObjAllocator_.StopAllocate(sHeap_);
1066         pinnedObjAllocator_.StopAllocate(sHeap_);
1067         largeObjAllocator_.StopAllocate(sHeap_);
1068     } else {
1069         oldLocalSpace_->Stop();
1070         nonMovableLocalSpace_->Stop();
1071         machineCodeLocalSpace_->Stop();
1072         snapshotLocalSpace_->Stop();
1073     }
1074 }
1075 
WriteObjectToFile(std::fstream & writer)1076 void SnapshotProcessor::WriteObjectToFile(std::fstream &writer)
1077 {
1078     if (g_isEnableCMCGC) {
1079         regularObjAllocator_.WriteToFile(writer);
1080         pinnedObjAllocator_.WriteToFile(writer);
1081         largeObjAllocator_.WriteToFile(writer);
1082     } else {
1083         WriteSpaceObjectToFile(oldLocalSpace_, writer);
1084         WriteSpaceObjectToFile(nonMovableLocalSpace_, writer);
1085         WriteSpaceObjectToFile(machineCodeLocalSpace_, writer);
1086         WriteSpaceObjectToFile(snapshotLocalSpace_, writer);
1087         WriteHugeObjectToFile(hugeObjectLocalSpace_, writer);
1088     }
1089 }
1090 
WriteSpaceObjectToFile(Space * space,std::fstream & writer)1091 void SnapshotProcessor::WriteSpaceObjectToFile(Space* space, std::fstream &writer)
1092 {
1093     size_t regionCount = space->GetRegionCount();
1094     if (regionCount > 0) {
1095         auto lastRegion = space->GetCurrentRegion();
1096         space->EnumerateRegions([this, &writer, lastRegion](Region *current) {
1097             if (current != lastRegion) {
1098                 ASAN_UNPOISON_MEMORY_REGION(reinterpret_cast<void *>(ToUintPtr(current)), DEFAULT_REGION_SIZE);
1099                 ResetRegionUnusedRange(current);
1100                 SnapshotRegionHeadInfo info = GenerateRegionHeadInfo(current);
1101                 // Firstly, serialize the region head information into the file;
1102                 writer.write(reinterpret_cast<char *>(&info), SnapshotRegionHeadInfo::RegionHeadInfoSize());
1103                 // Secondly, write the valid region memory (exclude region head and GC bit set).
1104                 writer.write(reinterpret_cast<char *>(current->packedData_.begin_),
1105                              ToUintPtr(current) + DEFAULT_REGION_SIZE - current->packedData_.begin_);
1106                 writer.flush();
1107             }
1108         });
1109 
1110         SnapshotRegionHeadInfo info = GenerateRegionHeadInfo(lastRegion);
1111         // Firstly, serialize the region object into the file;
1112         writer.write(reinterpret_cast<char *>(&info), SnapshotRegionHeadInfo::RegionHeadInfoSize());
1113         // Secondly, write the valid region memory (exclude region head and GC bit set).
1114         writer.write(reinterpret_cast<char *>(lastRegion->packedData_.begin_),
1115                      lastRegion->highWaterMark_ - lastRegion->packedData_.begin_);
1116         writer.flush();
1117     }
1118 }
1119 
WriteHugeObjectToFile(HugeObjectSpace * space,std::fstream & writer)1120 void SnapshotProcessor::WriteHugeObjectToFile(HugeObjectSpace* space, std::fstream &writer)
1121 {
1122     space->EnumerateRegions([&writer](Region *region) {
1123         SnapshotRegionHeadInfo info;
1124         info.regionIndex_ = SnapshotHelper::GetHugeObjectRegionIndex(region->GetSnapshotData());
1125         size_t objSize = SnapshotHelper::GetHugeObjectSize(region->GetSnapshotData());
1126         info.aliveObjectSize_ = objSize;
1127         // Firstly, serialize the region head information into the file;
1128         writer.write(reinterpret_cast<char *>(&info), SnapshotRegionHeadInfo::RegionHeadInfoSize());
1129         // Secondly, write the valid region memory (exclude region head and GC bit set).
1130         writer.write(reinterpret_cast<char *>(region->packedData_.begin_), objSize);
1131         writer.flush();
1132     });
1133 }
1134 
StatisticsObjectSize()1135 std::vector<size_t> SnapshotProcessor::StatisticsObjectSize()
1136 {
1137     std::vector<size_t> objSizeVector;
1138     if (g_isEnableCMCGC) {
1139         objSizeVector.emplace_back(regularObjAllocator_.GetAllocatedSize());
1140         objSizeVector.emplace_back(pinnedObjAllocator_.GetAllocatedSize());
1141         objSizeVector.emplace_back(largeObjAllocator_.GetAllocatedSize());
1142     } else {
1143         objSizeVector.emplace_back(StatisticsSpaceObjectSize(oldLocalSpace_));
1144         objSizeVector.emplace_back(StatisticsSpaceObjectSize(nonMovableLocalSpace_));
1145         objSizeVector.emplace_back(StatisticsSpaceObjectSize(machineCodeLocalSpace_));
1146         objSizeVector.emplace_back(StatisticsSpaceObjectSize(snapshotLocalSpace_));
1147         objSizeVector.emplace_back(StatisticsHugeObjectSize(hugeObjectLocalSpace_));
1148     }
1149     return objSizeVector;
1150 }
1151 
StatisticsSpaceObjectSize(Space * space)1152 size_t SnapshotProcessor::StatisticsSpaceObjectSize(Space* space)
1153 {
1154     size_t regionCount = space->GetRegionCount();
1155     size_t objSize = 0U;
1156     if (regionCount > 0) {
1157         auto lastRegion = space->GetCurrentRegion();
1158         size_t lastRegionSize = lastRegion->highWaterMark_ - lastRegion->packedData_.begin_;
1159         objSize = (regionCount - 1) * (SnapshotRegionHeadInfo::RegionHeadInfoSize() +
1160             Region::GetRegionAvailableSize()) + SnapshotRegionHeadInfo::RegionHeadInfoSize() + lastRegionSize;
1161     }
1162     return objSize;
1163 }
1164 
StatisticsHugeObjectSize(HugeObjectSpace * space)1165 size_t SnapshotProcessor::StatisticsHugeObjectSize(HugeObjectSpace* space)
1166 {
1167     size_t objSize = 0U;
1168     space->EnumerateRegions([&objSize](Region *region) {
1169         objSize += SnapshotRegionHeadInfo::RegionHeadInfoSize();
1170         uint64_t snapshotData = region->GetSnapshotData();
1171         // huge object size is storaged in region param snapshotData_ high 32 bits
1172         objSize += SnapshotHelper::GetHugeObjectSize(snapshotData);
1173     });
1174     return objSize;
1175 }
1176 
ProcessObjectQueue(CQueue<TaggedObject * > * queue,std::unordered_map<uint64_t,ObjectEncode> * data)1177 void SnapshotProcessor::ProcessObjectQueue(CQueue<TaggedObject *> *queue,
1178                                            std::unordered_map<uint64_t, ObjectEncode> *data)
1179 {
1180     while (!queue->empty()) {
1181         auto taggedObject = queue->front();
1182         if (taggedObject == nullptr) {
1183             break;
1184         }
1185         queue->pop();
1186         SerializeObject(taggedObject, queue, data);
1187     }
1188 
1189     StopAllocate();
1190 }
1191 
AllocateObjectToLocalSpace(Space * space,size_t objectSize)1192 uintptr_t SnapshotProcessor::AllocateObjectToLocalSpace(Space *space, size_t objectSize)
1193 {
1194     uintptr_t newObj = 0;
1195     if (space->GetSpaceType() == MemSpaceType::HUGE_OBJECT_SPACE) {
1196         newObj = reinterpret_cast<HugeObjectSpace *>(space)->Allocate(objectSize, vm_->GetAssociatedJSThread());
1197     } else if (space->GetSpaceType() == MemSpaceType::SNAPSHOT_SPACE) {
1198         newObj = reinterpret_cast<SnapshotSpace *>(space)->Allocate(objectSize);
1199     } else {
1200         newObj = reinterpret_cast<LocalSpace *>(space)->Allocate(objectSize);
1201     }
1202     auto current = space->GetCurrentRegion();
1203     if (newObj == current->GetBegin()) {
1204         // region param snapshotData_ low 32 bits is reused to record regionIndex
1205         uint64_t snapshotData = regionIndex_;
1206         if (current->InHugeObjectSpace()) {
1207             // region param snapshotData_ high 32 bits is reused to record huge object size
1208             snapshotData += SnapshotHelper::EncodeHugeObjectSize(objectSize);
1209         }
1210         current->SetSnapshotData(snapshotData);
1211         regionIndex_++;
1212     }
1213     return newObj;
1214 }
1215 
SetObjectEncodeField(uintptr_t obj,size_t offset,uint64_t value)1216 void SnapshotProcessor::SetObjectEncodeField(uintptr_t obj, size_t offset, uint64_t value)
1217 {
1218     *reinterpret_cast<uint64_t *>(obj + offset) = value;
1219 }
1220 
DeserializeObjectExcludeString(uintptr_t regularObjBegin,size_t regularObjSize,size_t pinnedObjSize,size_t largeObjSize)1221 void SnapshotProcessor::DeserializeObjectExcludeString(uintptr_t regularObjBegin, size_t regularObjSize,
1222                                                        size_t pinnedObjSize, size_t largeObjSize)
1223 {
1224     uintptr_t pinnedObjBegin = regularObjBegin + regularObjSize;
1225     uintptr_t largeObjBegin = pinnedObjBegin + pinnedObjSize;
1226     auto heap = vm_->GetHeap();
1227 
1228     DeserializeSpaceObject(regularObjBegin, regularObjSize, SerializedObjectSpace::REGULAR_SPACE);
1229     DeserializeSpaceObject(pinnedObjBegin, pinnedObjSize, SerializedObjectSpace::PIN_SPACE);
1230     DeserializeSpaceObject(largeObjBegin, largeObjSize, SerializedObjectSpace::LARGE_SPACE);
1231 }
1232 
DeserializeSpaceObject(uintptr_t beginAddr,size_t objSize,SerializedObjectSpace spaceType)1233 void SnapshotProcessor::DeserializeSpaceObject(uintptr_t beginAddr, size_t objSize,
1234                                                SerializedObjectSpace spaceType)
1235 {
1236     uintptr_t endAddr = beginAddr + objSize;
1237     while (beginAddr < endAddr) {
1238         SnapshotRegionHeadInfo *info = ToNativePtr<SnapshotRegionHeadInfo>(beginAddr);
1239         beginAddr += SnapshotRegionHeadInfo::RegionHeadInfoSize();
1240         uintptr_t objectBeginAddr = ToUintPtr(info) + SnapshotRegionHeadInfo::RegionHeadInfoSize();
1241         size_t regionIndex = info->regionIndex_;
1242         size_t liveObjectSize = info->aliveObjectSize_;
1243         uintptr_t regionAddr;
1244         switch (spaceType) {
1245             case SerializedObjectSpace::REGULAR_SPACE:
1246                 regionAddr = common::HeapAllocator::AllocateOldRegion();
1247                 regularRegions_.emplace_back(regionAddr, liveObjectSize);
1248                 break;
1249             case SerializedObjectSpace::PIN_SPACE:
1250                 regionAddr = common::HeapAllocator::AllocatePinnedRegion();
1251                 pinnedRegions_.emplace_back(regionAddr, liveObjectSize);
1252                 break;
1253             case SerializedObjectSpace::LARGE_SPACE:
1254                 regionAddr = common::HeapAllocator::AllocateLargeRegion(objSize);
1255                 largeRegions_.emplace_back(regionAddr, liveObjectSize);
1256                 break;
1257             default:
1258                 LOG_ECMA(FATAL) << "unsupported space type " << static_cast<int>(spaceType);
1259                 UNREACHABLE();
1260         }
1261         regionIndexMap_.emplace(regionIndex, regionAddr);
1262 
1263         if (errno_t ret = memcpy_s(ToVoidPtr(regionAddr), liveObjectSize, ToVoidPtr(beginAddr), liveObjectSize);
1264             ret != EOK) {
1265             LOG_FULL(FATAL) << "memcpy_s failed: " << ret;
1266             UNREACHABLE();
1267         }
1268         if (spaceType != SerializedObjectSpace::LARGE_SPACE) {
1269             uintptr_t top = regionAddr + liveObjectSize;
1270             uintptr_t end = regionAddr + common::Heap::GetNormalRegionAvailableSize();
1271             FreeObject::FillFreeObject(sHeap_, top, end - top);
1272         }
1273         beginAddr += liveObjectSize;
1274     }
1275 }
1276 
DeserializeObjectExcludeString(uintptr_t oldSpaceBegin,size_t oldSpaceObjSize,size_t nonMovableObjSize,size_t machineCodeObjSize,size_t snapshotObjSize,size_t hugeSpaceObjSize)1277 void SnapshotProcessor::DeserializeObjectExcludeString(uintptr_t oldSpaceBegin, size_t oldSpaceObjSize,
1278                                                        size_t nonMovableObjSize, size_t machineCodeObjSize,
1279                                                        size_t snapshotObjSize, size_t hugeSpaceObjSize)
1280 {
1281     uintptr_t nonMovableBegin = oldSpaceBegin + oldSpaceObjSize;
1282     uintptr_t machineCodeBegin = nonMovableBegin + nonMovableObjSize;
1283     uintptr_t snapshotBegin = machineCodeBegin + machineCodeObjSize;
1284     uintptr_t hugeObjBegin = snapshotBegin + snapshotObjSize;
1285     auto heap = vm_->GetHeap();
1286     auto oldSpace = heap->GetOldSpace();
1287     auto nonMovableSpace = heap->GetNonMovableSpace();
1288     auto machineCodeSpace = heap->GetMachineCodeSpace();
1289     auto snapshotSpace = heap->GetSnapshotSpace();
1290     auto hugeObjectSpace = heap->GetHugeObjectSpace();
1291 
1292     DeserializeSpaceObject(oldSpaceBegin, oldSpace, oldSpaceObjSize);
1293     DeserializeSpaceObject(nonMovableBegin, nonMovableSpace, nonMovableObjSize);
1294     DeserializeSpaceObject(machineCodeBegin, machineCodeSpace, machineCodeObjSize);
1295     DeserializeSpaceObject(snapshotBegin, snapshotSpace, snapshotObjSize);
1296     DeserializeHugeSpaceObject(hugeObjBegin, hugeObjectSpace, hugeSpaceObjSize);
1297     snapshotSpace->ResetAllocator();
1298 }
1299 
DeserializeSpaceObject(uintptr_t beginAddr,Space * space,size_t spaceObjSize)1300 void SnapshotProcessor::DeserializeSpaceObject(uintptr_t beginAddr, Space* space, size_t spaceObjSize)
1301 {
1302     size_t numberOfRegions = 0U;
1303     if (spaceObjSize != 0) {
1304         numberOfRegions = (spaceObjSize - 1) / (Region::GetRegionAvailableSize() +
1305             SnapshotRegionHeadInfo::RegionHeadInfoSize()) + 1;
1306     }
1307     for (size_t i = 0; i < numberOfRegions; i++) {
1308         Region *region = vm_->GetHeapRegionAllocator()->AllocateAlignedRegion(
1309             space, DEFAULT_REGION_SIZE, vm_->GetAssociatedJSThread(), const_cast<Heap *>(vm_->GetHeap()));
1310         auto info = ToNativePtr<SnapshotRegionHeadInfo>(beginAddr +
1311             i * (Region::GetRegionAvailableSize() + SnapshotRegionHeadInfo::RegionHeadInfoSize()));
1312         uintptr_t objectBeginAddr = ToUintPtr(info) + SnapshotRegionHeadInfo::RegionHeadInfoSize();
1313         size_t regionIndex = info->regionIndex_;
1314         size_t liveObjectSize = info->aliveObjectSize_;
1315         regionIndexMap_.emplace(regionIndex, ToUintPtr(region));
1316 
1317         ASAN_UNPOISON_MEMORY_REGION(reinterpret_cast<void *>(region->packedData_.begin_), liveObjectSize);
1318         if (errno_t ret = memcpy_s(ToVoidPtr(region->packedData_.begin_),
1319                                    liveObjectSize,
1320                                    ToVoidPtr(objectBeginAddr),
1321                                    liveObjectSize); ret != EOK) {
1322             LOG_FULL(FATAL) << "memcpy_s failed: " << ret;
1323             UNREACHABLE();
1324         }
1325 
1326         // Other information like aliveObject size, highWaterMark etc. in the region object to restore.
1327         region->aliveObject_ = liveObjectSize;
1328         region->highWaterMark_ = region->packedData_.begin_ + liveObjectSize;
1329         region->SetGCFlag(RegionGCFlags::NEED_RELOCATE);
1330 
1331         if (space->GetSpaceType() != MemSpaceType::SNAPSHOT_SPACE) {
1332             auto sparseSpace = reinterpret_cast<SparseSpace *>(space);
1333             sparseSpace->FreeLiveRange(region, region->GetHighWaterMark(), region->GetEnd(), true);
1334             sparseSpace->IncreaseLiveObjectSize(liveObjectSize);
1335             sparseSpace->IncreaseAllocatedSize(liveObjectSize);
1336             sparseSpace->AddRegion(region);
1337         } else {
1338             auto snapshotSpace = reinterpret_cast<SnapshotSpace *>(space);
1339             snapshotSpace->IncreaseLiveObjectSize(liveObjectSize);
1340             snapshotSpace->AddRegion(region);
1341         }
1342     }
1343 }
1344 
DeserializeHugeSpaceObject(uintptr_t beginAddr,HugeObjectSpace * space,size_t hugeSpaceObjSize)1345 void SnapshotProcessor::DeserializeHugeSpaceObject(uintptr_t beginAddr, HugeObjectSpace* space, size_t hugeSpaceObjSize)
1346 {
1347     uintptr_t currentAddr = beginAddr;
1348     uintptr_t endAddr = beginAddr + hugeSpaceObjSize;
1349     while (currentAddr < endAddr) {
1350         auto info = ToNativePtr<SnapshotRegionHeadInfo>(currentAddr);
1351         // Retrieve the data beginning address based on the serialized data format.
1352         uintptr_t copyFrom = ToUintPtr(info) + SnapshotRegionHeadInfo::RegionHeadInfoSize();
1353         size_t objSize = info->aliveObjectSize_;
1354         size_t alignedRegionObjSize = AlignUp(sizeof(Region), static_cast<size_t>(MemAlignment::MEM_ALIGN_REGION));
1355         size_t hugeRegionHeadSize = AlignUp(alignedRegionObjSize + GCBitset::BYTE_PER_WORD,
1356                                             static_cast<size_t>(MemAlignment::MEM_ALIGN_OBJECT));
1357 
1358         ASSERT(objSize > g_maxRegularHeapObjectSize);
1359         size_t alignedHugeRegionSize = AlignUp(objSize + hugeRegionHeadSize, PANDA_POOL_ALIGNMENT_IN_BYTES);
1360         Region *region = vm_->GetHeapRegionAllocator()->AllocateAlignedRegion(
1361             space, alignedHugeRegionSize, vm_->GetAssociatedJSThread(), const_cast<Heap *>(vm_->GetHeap()));
1362         size_t regionIndex = info->regionIndex_;
1363         regionIndexMap_.emplace(regionIndex, ToUintPtr(region));
1364 
1365         ASAN_UNPOISON_MEMORY_REGION(reinterpret_cast<void *>(region->packedData_.begin_), objSize);
1366         if (memcpy_s(ToVoidPtr(region->packedData_.begin_),
1367                      objSize,
1368                      ToVoidPtr(copyFrom),
1369                      objSize) != EOK) {
1370             LOG_FULL(FATAL) << "memcpy_s failed";
1371             UNREACHABLE();
1372         }
1373 
1374         // Other information like aliveObject size, highWaterMark etc. in the region object to restore.
1375         region->aliveObject_ = objSize;
1376         region->highWaterMark_ = region->packedData_.begin_ + objSize;
1377         region->SetGCFlag(RegionGCFlags::NEED_RELOCATE);
1378         space->AddRegion(region);
1379 
1380         currentAddr += SnapshotRegionHeadInfo::RegionHeadInfoSize();
1381         currentAddr += objSize;
1382     }
1383 }
1384 
DeserializeString(uintptr_t stringBegin,uintptr_t stringEnd)1385 void SnapshotProcessor::DeserializeString(uintptr_t stringBegin, uintptr_t stringEnd)
1386 {
1387     EcmaStringTable *stringTable = vm_->GetEcmaStringTable();
1388     JSThread *thread = vm_->GetJSThread();
1389     ASSERT(deserializeStringVector_.empty());
1390     auto hugeSpace = sHeap_->GetHugeObjectSpace();
1391     auto globalConst = const_cast<GlobalEnvConstants *>(thread->GlobalConstants());
1392     auto lineStringClass = globalConst->GetLineStringClass();
1393     while (stringBegin < stringEnd) {
1394         // str is from snapshot file, which is in native heap.
1395         EcmaString *str = reinterpret_cast<EcmaString *>(stringBegin);  // Note str is not in Heap, so no Handle
1396         str->SetClassWithoutBarrier(reinterpret_cast<JSHClass *>(lineStringClass.GetTaggedObject()));
1397         size_t strSize = EcmaStringAccessor(str).ObjectSize();
1398         strSize = AlignUp(strSize, static_cast<size_t>(MemAlignment::MEM_ALIGN_OBJECT));
1399         {
1400             auto hashcode = EcmaStringAccessor(str).GetHashcode(thread);
1401 #if ENABLE_NEXT_OPTIMIZATION
1402             EcmaString *strFromTable = stringTable->GetOrInternString(
1403                 vm_, hashcode,
1404                 [strSize, hugeSpace, thread, str, this]() {
1405                     uintptr_t newObj = 0;
1406                     if (thread->IsEnableCMCGC()) {
1407                         newObj = ToUintPtr(sHeap_->AllocateOldOrHugeObjectNoGC(thread, strSize));
1408                     } else {
1409                         if (UNLIKELY(strSize > g_maxRegularHeapObjectSize)) {
1410                             newObj = hugeSpace->Allocate(thread, strSize);
1411                         } else {
1412                             newObj = this->sHeap_->GetOldSpace()->TryAllocateAndExpand(thread, strSize, true);
1413                         }
1414                     }
1415                     if (newObj == 0) {
1416                         LOG_ECMA_MEM(FATAL) << "Snapshot Allocate OldSharedSpace OOM";
1417                         UNREACHABLE();
1418                     }
1419                     if (memcpy_s(ToVoidPtr(newObj), strSize, str, strSize) != EOK) {
1420                         LOG_FULL(FATAL) << "memcpy_s failed";
1421                         UNREACHABLE();
1422                     }
1423 
1424                     EcmaString *value = reinterpret_cast<EcmaString *>(newObj);
1425                     ASSERT(JSTaggedValue(value).IsInSharedHeap());
1426                     ASSERT(EcmaStringAccessor(value).NotTreeString());
1427                     JSHandle<EcmaString> stringHandle(thread, value);
1428                     return stringHandle;
1429                 },
1430                 [str, thread](BaseString *foundString) {
1431                     ASSERT(EcmaStringAccessor(str).NotTreeString());
1432                     return EcmaStringAccessor::StringsAreEqual(thread, EcmaString::FromBaseString(foundString), str);
1433                 });
1434             ASSERT(strFromTable != nullptr);
1435             deserializeStringVector_.emplace_back(thread, strFromTable);
1436 #else
1437             RuntimeLockHolder locker(thread,
1438                 stringTable->stringTable_[EcmaStringTable::GetTableId(hashcode)].mutex_);
1439             auto strFromTable = stringTable->GetStringThreadUnsafe(thread, str, hashcode);
1440             if (strFromTable) {
1441                 deserializeStringVector_.emplace_back(thread, strFromTable);
1442             } else {
1443                 uintptr_t newObj = 0;
1444                 if (thread->IsEnableCMCGC()) {
1445                     newObj = ToUintPtr(sHeap_->AllocateOldOrHugeObjectNoGC(thread, strSize));
1446                 } else {
1447                     if (UNLIKELY(strSize > g_maxRegularHeapObjectSize)) {
1448                         newObj = hugeSpace->Allocate(thread, strSize);
1449                     } else {
1450                         newObj = sHeap_->GetOldSpace()->TryAllocateAndExpand(thread, strSize, true);
1451                     }
1452                 }
1453                 if (newObj == 0) {
1454                     LOG_ECMA_MEM(FATAL) << "Snapshot Allocate OldSharedSpace OOM";
1455                     UNREACHABLE();
1456                 }
1457                 if (memcpy_s(ToVoidPtr(newObj), strSize, str, strSize) != EOK) {
1458                     LOG_FULL(FATAL) << "memcpy_s failed";
1459                     UNREACHABLE();
1460                 }
1461                 str = reinterpret_cast<EcmaString *>(newObj);
1462                 stringTable->InsertStringToTableWithHashThreadUnsafe(thread, str, hashcode);
1463                 deserializeStringVector_.emplace_back(thread, str);
1464             }
1465 #endif
1466         }
1467         stringBegin += strSize;
1468     }
1469 }
1470 
DeserializePandaMethod(uintptr_t begin,uintptr_t end,MethodLiteral * methods,size_t & methodNums,size_t & others)1471 void SnapshotProcessor::DeserializePandaMethod(uintptr_t begin, uintptr_t end, MethodLiteral *methods,
1472                                                size_t &methodNums, size_t &others)
1473 {
1474     for (size_t i = 0; i < others; i++) {
1475         pandaMethod_.emplace_back(begin);
1476         auto method = reinterpret_cast<Method *>(begin);
1477         if (memcpy_s(methods + (--methodNums), Method::Size(), method, Method::Size()) != EOK) {
1478             LOG_FULL(FATAL) << "memcpy_s failed";
1479             UNREACHABLE();
1480         }
1481         begin += Method::Size();
1482         if (begin >= end) {
1483             others = others - i - 1;
1484         }
1485     }
1486 }
1487 
HandleRootObject(SnapshotType type,uintptr_t rootObjectAddr,size_t objType,size_t & constSpecialIndex)1488 void SnapshotProcessor::HandleRootObject(SnapshotType type, uintptr_t rootObjectAddr,
1489                                          size_t objType, size_t &constSpecialIndex)
1490 {
1491     switch (type) {
1492         case SnapshotType::VM_ROOT: {
1493             if (JSType(objType) == JSType::GLOBAL_ENV) {
1494                 vm_->GetJSThread()->SetGlueGlobalEnv(
1495                     JSTaggedValue(reinterpret_cast<GlobalEnv *>(rootObjectAddr)));
1496             } else if (JSType(objType) == JSType::MICRO_JOB_QUEUE) {
1497                 vm_->SetMicroJobQueue(reinterpret_cast<job::MicroJobQueue *>(rootObjectAddr));
1498             }
1499             root_ = JSTaggedValue(static_cast<JSTaggedType>(rootObjectAddr));
1500             break;
1501         }
1502         case SnapshotType::BUILTINS: {
1503             JSTaggedValue result(static_cast<JSTaggedType>(rootObjectAddr));
1504             auto constants = const_cast<GlobalEnvConstants *>(vm_->GetJSThread()->GlobalConstants());
1505             size_t constCount = constants->GetConstantCount();
1506             while (constants->IsSpecialOrUndefined(constSpecialIndex)) {
1507                 constSpecialIndex++; // Skip special or undefined value
1508             }
1509             if (constSpecialIndex < constCount) {
1510                 constants->SetConstant(ConstantIndex(constSpecialIndex), result);
1511             } else {
1512                 vm_->GetJSThread()->SetGlueGlobalEnv(
1513                     JSTaggedValue(reinterpret_cast<GlobalEnv *>(rootObjectAddr)));
1514             }
1515             constSpecialIndex++;
1516             break;
1517         }
1518         case SnapshotType::AI: {
1519             JSTaggedValue item = JSTaggedValue(static_cast<JSTaggedType>(rootObjectAddr));
1520             LOG_ECMA(INFO) << "SnapshotProcessor isRootObjRelocate: " << isRootObjRelocate_;
1521             if (item.IsHeapObject()) {
1522                 LOG_ECMA(INFO) << "SnapshotProcessor rootObject jstype: "
1523                     << static_cast<uint64_t>(item.GetTaggedObject()->GetClass()->GetObjectType());
1524             }
1525             if (!isRootObjRelocate_ && item.IsTaggedArray()) {
1526                 root_ = item;
1527                 isRootObjRelocate_ = true;
1528             }
1529             break;
1530         }
1531         default:
1532             break;
1533     }
1534 }
1535 
AddRootObjectToAOTFileManager(SnapshotType type,const CString & fileName)1536 void SnapshotProcessor::AddRootObjectToAOTFileManager(SnapshotType type, const CString &fileName)
1537 {
1538     if (type == SnapshotType::AI) {
1539         ASSERT(!root_.IsHole());
1540         AOTFileManager *aotFileManager = vm_->GetAOTFileManager();
1541         aotFileManager->ParseDeserializedData(fileName, root_);
1542     }
1543 }
1544 
SerializeObjectVisitor(SnapshotProcessor * processor,uintptr_t snapshotObj,CQueue<TaggedObject * > * queue,std::unordered_map<uint64_t,ObjectEncode> * data)1545 SnapshotProcessor::SerializeObjectVisitor::SerializeObjectVisitor(SnapshotProcessor *processor, uintptr_t snapshotObj,
1546     CQueue<TaggedObject *> *queue, std::unordered_map<uint64_t, ObjectEncode> *data)
1547     : processor_(processor), snapshotObj_(snapshotObj), queue_(queue), data_(data) {}
1548 
VisitObjectRangeImpl(BaseObject * root,uintptr_t start,uintptr_t endAddr,VisitObjectArea area)1549 void SnapshotProcessor::SerializeObjectVisitor::VisitObjectRangeImpl(BaseObject *root, uintptr_t start,
1550                                                                      uintptr_t endAddr, VisitObjectArea area)
1551 {
1552     int index = 0;
1553     ObjectSlot end(endAddr);
1554     for (ObjectSlot slot(start); slot < end; slot++) {
1555         if (area == VisitObjectArea::NATIVE_POINTER) {
1556             auto nativePointer = *reinterpret_cast<void **>(slot.SlotAddress());
1557             processor_->SetObjectEncodeField(snapshotObj_, slot.SlotAddress() - ToUintPtr(root),
1558                                              processor_->NativePointerToEncodeBit(nativePointer).GetValue());
1559         } else {
1560             if (processor_->VisitObjectBodyWithRep(TaggedObject::Cast(root), slot, snapshotObj_, index, area)) {
1561                 continue;
1562             }
1563             auto fieldAddr = reinterpret_cast<JSTaggedType *>(slot.SlotAddress());
1564             processor_->SetObjectEncodeField(snapshotObj_, slot.SlotAddress() - ToUintPtr(root),
1565                                              processor_->SerializeTaggedField(fieldAddr, queue_, data_));
1566         }
1567     }
1568 }
1569 
SerializeObject(TaggedObject * objectHeader,CQueue<TaggedObject * > * queue,std::unordered_map<uint64_t,ObjectEncode> * data)1570 void SnapshotProcessor::SerializeObject(TaggedObject *objectHeader, CQueue<TaggedObject *> *queue,
1571                                         std::unordered_map<uint64_t, ObjectEncode> *data)
1572 {
1573     auto hclass = objectHeader->GetClass();
1574     JSType objectType = hclass->GetObjectType();
1575     uintptr_t snapshotObj = 0;
1576     if (UNLIKELY(data->find(ToUintPtr(objectHeader)) == data->end())) {
1577         LOG_FULL(FATAL) << "Data map can not find object";
1578         UNREACHABLE();
1579     } else {
1580         snapshotObj = data->find(ToUintPtr(objectHeader))->second.first;
1581     }
1582 
1583     // header
1584     EncodeBit encodeBit = SerializeObjectHeader(objectHeader, static_cast<size_t>(objectType), queue, data);
1585     SetObjectEncodeField(snapshotObj, 0, encodeBit.GetValue());
1586 
1587     SerializeObjectVisitor visitor(this, snapshotObj, queue, data);
1588     ObjectXRay::VisitObjectBody<VisitType::SNAPSHOT_VISIT>(objectHeader, objectHeader->GetClass(), visitor);
1589 }
1590 
VisitObjectBodyWithRep(TaggedObject * root,ObjectSlot slot,uintptr_t obj,int index,VisitObjectArea area)1591 bool SnapshotProcessor::VisitObjectBodyWithRep(TaggedObject *root, ObjectSlot slot, uintptr_t obj, int index,
1592     VisitObjectArea area)
1593 {
1594     JSThread *thread = vm_->GetJSThread();
1595     if (area != VisitObjectArea::IN_OBJECT) {
1596         return false;
1597     }
1598     auto hclass = root->GetClass();
1599     ASSERT(!hclass->IsAllTaggedProp());
1600     auto layout = LayoutInfo::Cast(hclass->GetLayout(thread).GetTaggedObject());
1601     auto attr = layout->GetAttr(thread, index++);
1602     if (attr.GetRepresentation() == Representation::DOUBLE) {
1603         auto fieldAddr = reinterpret_cast<double *>(slot.SlotAddress());
1604         SetObjectEncodeField(obj, slot.SlotAddress() - ToUintPtr(root),
1605                              JSTaggedValue(*fieldAddr).GetRawData());
1606         return true;
1607     } else if (attr.GetRepresentation() == Representation::INT) {
1608         auto fieldAddr = reinterpret_cast<JSTaggedType *>(slot.SlotAddress());
1609         SetObjectEncodeField(obj, slot.SlotAddress() - ToUintPtr(root),
1610                              JSTaggedValue(static_cast<int32_t>(*fieldAddr)).GetRawData());
1611         return true;
1612     }
1613     return false;
1614 }
1615 
Relocate(SnapshotType type,const JSPandaFile * jsPandaFile,uint64_t rootObjSize)1616 void SnapshotProcessor::Relocate(SnapshotType type, const JSPandaFile *jsPandaFile, uint64_t rootObjSize)
1617 {
1618     size_t methodNums = 0;
1619     MethodLiteral *methods = nullptr;
1620     if (jsPandaFile) {
1621         methodNums = jsPandaFile->GetNumMethods();
1622         methods = jsPandaFile->GetMethodLiterals();
1623     }
1624 
1625     if (g_isEnableCMCGC) {
1626         RelocateSpaceObject(regularRegions_, type, methods, methodNums, rootObjSize);
1627         RelocateSpaceObject(pinnedRegions_, type, methods, methodNums, rootObjSize);
1628         RelocateSpaceObject(largeRegions_, type, methods, methodNums, rootObjSize);
1629     } else {
1630         auto heap = vm_->GetHeap();
1631         auto oldSpace = heap->GetOldSpace();
1632         auto nonMovableSpace = heap->GetNonMovableSpace();
1633         auto machineCodeSpace = heap->GetMachineCodeSpace();
1634         auto snapshotSpace = heap->GetSnapshotSpace();
1635         auto hugeObjectSpace = heap->GetHugeObjectSpace();
1636 
1637         RelocateSpaceObject(oldSpace, type, methods, methodNums, rootObjSize);
1638         RelocateSpaceObject(nonMovableSpace, type, methods, methodNums, rootObjSize);
1639         RelocateSpaceObject(machineCodeSpace, type, methods, methodNums, rootObjSize);
1640         RelocateSpaceObject(snapshotSpace, type, methods, methodNums, rootObjSize);
1641         RelocateSpaceObject(hugeObjectSpace, type, methods, methodNums, rootObjSize);
1642     }
1643 }
1644 
RelocateSpaceObject(std::vector<std::pair<uintptr_t,size_t>> & regions,SnapshotType type,MethodLiteral * methods,size_t methodNums,size_t rootObjSize)1645 void SnapshotProcessor::RelocateSpaceObject(std::vector<std::pair<uintptr_t, size_t>> &regions, SnapshotType type,
1646     MethodLiteral* methods, size_t methodNums, size_t rootObjSize)
1647 {
1648     size_t others = 0;
1649     size_t objIndex = 0;
1650     size_t constSpecialIndex = 0;
1651     EcmaStringTable *stringTable = vm_->GetEcmaStringTable();
1652     for (auto [begin, allocated] : regions) {
1653         uintptr_t end = begin + allocated;
1654         while (begin < end) {
1655             if (others != 0) {
1656                 DeserializePandaMethod(begin, end, methods, methodNums, others);
1657                 break;
1658             }
1659             EncodeBit encodeBit(*reinterpret_cast<uint64_t *>(begin));
1660             auto objType = encodeBit.GetObjectType();
1661             if (objType == Constants::MASK_METHOD_SPACE_BEGIN) {
1662                 begin += sizeof(uint64_t);
1663                 others = encodeBit.GetNativePointerOrObjectIndex();
1664                 DeserializePandaMethod(begin, end, methods, methodNums, others);
1665                 break;
1666             }
1667             TaggedObject *objectHeader = reinterpret_cast<TaggedObject *>(begin);
1668             DeserializeClassWord(objectHeader);
1669             DeserializeField(objectHeader);
1670             if (builtinsDeserialize_ &&
1671                 (JSType(objType) >= JSType::STRING_FIRST && JSType(objType) <= JSType::STRING_LAST)) {
1672                 EcmaString *str = reinterpret_cast<EcmaString *>(begin);
1673                 EcmaStringAccessor(str).ClearInternString();
1674                 stringTable->GetOrInternFlattenString(vm_, str);
1675             }
1676             if (objIndex < rootObjSize) {
1677                 HandleRootObject(type, begin, objType, constSpecialIndex);
1678             }
1679             begin = begin + AlignUp(objectHeader->GetSize(),
1680                                     static_cast<size_t>(MemAlignment::MEM_ALIGN_OBJECT));
1681             objIndex++;
1682         }
1683     };
1684 }
1685 
RelocateSpaceObject(Space * space,SnapshotType type,MethodLiteral * methods,size_t methodNums,size_t rootObjSize)1686 void SnapshotProcessor::RelocateSpaceObject(Space* space, SnapshotType type, MethodLiteral* methods,
1687                                             size_t methodNums, size_t rootObjSize)
1688 {
1689     size_t others = 0;
1690     size_t objIndex = 0;
1691     size_t constSpecialIndex = 0;
1692     EcmaStringTable *stringTable = vm_->GetEcmaStringTable();
1693     space->EnumerateRegions([stringTable, &others, &objIndex, &rootObjSize, &constSpecialIndex,
1694                             &type, this, methods, &methodNums](Region *current) {
1695         if (!current->NeedRelocate()) {
1696             return;
1697         }
1698         current->ClearGCFlag(RegionGCFlags::NEED_RELOCATE);
1699         size_t allocated = current->GetAllocatedBytes();
1700         uintptr_t begin = current->GetBegin();
1701         uintptr_t end = begin + allocated;
1702         while (begin < end) {
1703             if (others != 0) {
1704                 DeserializePandaMethod(begin, end, methods, methodNums, others);
1705                 break;
1706             }
1707             EncodeBit encodeBit(*reinterpret_cast<uint64_t *>(begin));
1708             auto objType = encodeBit.GetObjectType();
1709             if (objType == Constants::MASK_METHOD_SPACE_BEGIN) {
1710                 begin += sizeof(uint64_t);
1711                 others = encodeBit.GetNativePointerOrObjectIndex();
1712                 DeserializePandaMethod(begin, end, methods, methodNums, others);
1713                 break;
1714             }
1715             TaggedObject *objectHeader = reinterpret_cast<TaggedObject *>(begin);
1716             DeserializeClassWord(objectHeader);
1717             DeserializeField(objectHeader);
1718             if (builtinsDeserialize_ &&
1719                 (JSType(objType) >= JSType::STRING_FIRST && JSType(objType) <= JSType::STRING_LAST)) {
1720                 EcmaString *str = reinterpret_cast<EcmaString *>(begin);
1721                 EcmaStringAccessor(str).ClearInternString();
1722                 stringTable->GetOrInternFlattenString(vm_, str);
1723             }
1724             if (objIndex < rootObjSize) {
1725                 HandleRootObject(type, begin, objType, constSpecialIndex);
1726             }
1727             begin = begin + AlignUp(objectHeader->GetSize(),
1728                                     static_cast<size_t>(MemAlignment::MEM_ALIGN_OBJECT));
1729             objIndex++;
1730         }
1731     });
1732 }
1733 
SerializeObjectHeader(TaggedObject * objectHeader,size_t objectType,CQueue<TaggedObject * > * queue,std::unordered_map<uint64_t,ObjectEncode> * data)1734 EncodeBit SnapshotProcessor::SerializeObjectHeader(TaggedObject *objectHeader, size_t objectType,
1735                                                    CQueue<TaggedObject *> *queue,
1736                                                    std::unordered_map<uint64_t, ObjectEncode> *data)
1737 {
1738     auto hclass = objectHeader->GetClass();
1739     ASSERT(hclass != nullptr);
1740     EncodeBit encodeBit(0);
1741     if (data->find(ToUintPtr(hclass)) == data->end()) {
1742         encodeBit = EncodeTaggedObject(hclass, queue, data);
1743     } else {
1744         ObjectEncode objectEncodePair = data->find(ToUintPtr(hclass))->second;
1745         encodeBit = objectEncodePair.second;
1746     }
1747     encodeBit.SetObjectType(objectType);
1748     return encodeBit;
1749 }
1750 
SerializeTaggedField(JSTaggedType * tagged,CQueue<TaggedObject * > * queue,std::unordered_map<uint64_t,ObjectEncode> * data)1751 uint64_t SnapshotProcessor::SerializeTaggedField(JSTaggedType *tagged, CQueue<TaggedObject *> *queue,
1752                                                  std::unordered_map<uint64_t, ObjectEncode> *data)
1753 {
1754     JSThread *thread = vm_->GetAssociatedJSThread();
1755     JSTaggedValue taggedValue(Barriers::GetTaggedValue(thread, ToUintPtr(tagged)));
1756     if (taggedValue.IsWeak()) {
1757         taggedValue.RemoveWeakTag();
1758         if (taggedValue.IsJSHClass()) {
1759             EncodeBit encodeBit = GetObjectEncode(taggedValue, queue, data);
1760             encodeBit.SetTSWeakObject();
1761             return encodeBit.GetValue();
1762         }
1763         EncodeBit special(JSTaggedValue::Undefined().GetRawData());
1764         special.SetObjectSpecial();
1765         return special.GetValue();
1766     }
1767 
1768     if (taggedValue.IsSpecial()) {
1769         EncodeBit special(taggedValue.GetRawData());
1770         special.SetObjectSpecial();
1771         return special.GetValue();  // special encode bit
1772     }
1773 
1774     if (!taggedValue.IsHeapObject()) {
1775         return taggedValue.GetRawData();  // not object
1776     }
1777 
1778     EncodeBit encodeBit = GetObjectEncode(taggedValue, queue, data);
1779 
1780     if (taggedValue.IsString()) {
1781         encodeBit.SetReferenceToString(true);
1782     }
1783     return encodeBit.GetValue();  // object
1784 }
1785 
DeserializeTaggedField(uint64_t * value,TaggedObject * root)1786 void SnapshotProcessor::DeserializeTaggedField(uint64_t *value, TaggedObject *root)
1787 {
1788     EncodeBit encodeBit(*value);
1789     if (!builtinsDeserialize_ && encodeBit.IsReference() && encodeBit.IsGlobalConstOrBuiltins()) {
1790         size_t index = encodeBit.GetNativePointerOrObjectIndex();
1791         auto object = vm_->GetSnapshotEnv()->RelocateRootObjectAddr(index);
1792         *value = object;
1793         WriteBarrier<WriteBarrierType::DESERIALIZE>(vm_->GetJSThread(), reinterpret_cast<void *>(value), 0, object);
1794         return;
1795     }
1796 
1797     if (!encodeBit.IsReference()) {
1798         return;
1799     }
1800 
1801     if (encodeBit.IsReference() && !encodeBit.IsSpecial()) {
1802         uintptr_t taggedObjectAddr = TaggedObjectEncodeBitToAddr(encodeBit);
1803         *value = taggedObjectAddr;
1804         if (!g_isEnableCMCGC) {
1805             Region *rootRegion = Region::ObjectAddressToRange(ToUintPtr(root));
1806             Region *valueRegion = Region::ObjectAddressToRange(taggedObjectAddr);
1807             if (rootRegion->InGeneralOldSpace() && valueRegion->InYoungSpace()) {
1808                 // Should align with '8' in 64 and 32 bit platform
1809                 ASSERT((ToUintPtr(value) % static_cast<uint8_t>(MemAlignment::MEM_ALIGN_OBJECT)) == 0);
1810                 rootRegion->InsertOldToNewRSet((uintptr_t)value);
1811             }
1812             if (valueRegion->InSharedSweepableSpace()) {
1813                 if (!rootRegion->InSharedHeap()) {
1814                     rootRegion->InsertLocalToShareRSet((uintptr_t)value);
1815                 }
1816                 // In deserializing can not use barriers, only mark the shared value to prevent markingbit being lost
1817                 if (vm_->GetJSThread()->IsSharedConcurrentMarkingOrFinished()) {
1818                     ASSERT(DaemonThread::GetInstance()->IsConcurrentMarkingOrFinished());
1819                     valueRegion->AtomicMark(reinterpret_cast<void*>(taggedObjectAddr));
1820                 }
1821             }
1822         } else {
1823             size_t offset = ToUintPtr(root) - ToUintPtr(value);
1824             WriteBarrier<WriteBarrierType::AOT_DESERIALIZE>(vm_->GetJSThread(), reinterpret_cast<void *>(root), offset,
1825                 static_cast<JSTaggedType>(taggedObjectAddr));
1826         }
1827         return;
1828     }
1829 
1830     if (encodeBit.IsSpecial()) {
1831         encodeBit.ClearObjectSpecialFlag();
1832         *value = encodeBit.GetValue();
1833     }
1834 }
1835 
DeserializeClassWord(TaggedObject * object)1836 void SnapshotProcessor::DeserializeClassWord(TaggedObject *object)
1837 {
1838     // During AOT deserialization, setting the hclass on an object does not require atomic operations, but a write
1839     // barrier is still needed to track cross-generation references.
1840     EncodeBit encodeBit(*reinterpret_cast<uint64_t *>(object));
1841     if (!builtinsDeserialize_ && encodeBit.IsGlobalConstOrBuiltins()) {
1842         size_t hclassIndex = encodeBit.GetNativePointerOrObjectIndex();
1843         auto globalConst = const_cast<GlobalEnvConstants *>(vm_->GetJSThread()->GlobalConstants());
1844         JSTaggedValue hclassValue = globalConst->GetGlobalConstantObject(hclassIndex);
1845         ASSERT(hclassValue.IsJSHClass());
1846         object->SetClassWithoutBarrier(JSHClass::Cast(hclassValue.GetTaggedObject()));
1847         WriteBarrier<WriteBarrierType::AOT_DESERIALIZE>(vm_->GetJSThread(), object, JSHClass::HCLASS_OFFSET,
1848                                                         hclassValue.GetRawData());
1849         return;
1850     }
1851     uintptr_t hclassAddr = TaggedObjectEncodeBitToAddr(encodeBit);
1852     JSHClass *hclass = reinterpret_cast<JSHClass *>(hclassAddr);
1853     object->SetClassWithoutBarrier(hclass);
1854     WriteBarrier<WriteBarrierType::AOT_DESERIALIZE>(vm_->GetJSThread(), object, JSHClass::HCLASS_OFFSET,
1855                                                     JSTaggedValue(hclass).GetRawData());
1856 }
1857 
DeserializeFieldVisitor(SnapshotProcessor * processor)1858 SnapshotProcessor::DeserializeFieldVisitor::DeserializeFieldVisitor(SnapshotProcessor *processor)
1859     : processor_(processor) {}
1860 
VisitObjectRangeImpl(BaseObject * rootObject,uintptr_t startAddr,uintptr_t endAddr,VisitObjectArea area)1861 void SnapshotProcessor::DeserializeFieldVisitor::VisitObjectRangeImpl(BaseObject *rootObject, uintptr_t startAddr,
1862                                                                       uintptr_t endAddr, VisitObjectArea area)
1863 {
1864     ObjectSlot start(startAddr);
1865     ObjectSlot end(endAddr);
1866     auto root = TaggedObject::Cast(rootObject);
1867     for (ObjectSlot slot = start; slot < end; slot++) {
1868         auto encodeBitAddr = reinterpret_cast<uint64_t *>(slot.SlotAddress());
1869         if (area == VisitObjectArea::NATIVE_POINTER) {
1870             processor_->DeserializeNativePointer(encodeBitAddr);
1871         } else {
1872             processor_->DeserializeTaggedField(encodeBitAddr, root);
1873         }
1874     }
1875 }
1876 
DeserializeField(TaggedObject * objectHeader)1877 void SnapshotProcessor::DeserializeField(TaggedObject *objectHeader)
1878 {
1879     DeserializeFieldVisitor visitor(this);
1880     ObjectXRay::VisitObjectBody<VisitType::SNAPSHOT_VISIT>(objectHeader, objectHeader->GetClass(), visitor);
1881 }
1882 
NativePointerToEncodeBit(void * nativePointer)1883 EncodeBit SnapshotProcessor::NativePointerToEncodeBit(void *nativePointer)
1884 {
1885     EncodeBit native(0);
1886     if (nativePointer != nullptr) {  // nativePointer
1887         size_t index = Constants::MAX_C_POINTER_INDEX;
1888 
1889         if (programSerialize_) {
1890             pandaMethod_.emplace_back(ToUintPtr(nativePointer));
1891             ASSERT(pandaMethod_.size() + GetNativeTableSize() <= Constants::MAX_UINT_16);
1892             ASSERT(pandaMethod_.size() + GetNativeTableSize() > 0);
1893             // NOLINTNEXTLINE(bugprone-narrowing-conversions, cppcoreguidelines-narrowing-conversions)
1894             index = pandaMethod_.size() + GetNativeTableSize() - 1;
1895         } else {
1896             index = SearchNativeMethodIndex(nativePointer);
1897         }
1898 
1899         LOG_ECMA_IF(index > Constants::MAX_C_POINTER_INDEX, FATAL) << "MAX_C_POINTER_INDEX: " << index;
1900         native.SetNativePointerOrObjectIndex(index);
1901     }
1902     return native;
1903 }
1904 
SearchNativeMethodIndex(void * nativePointer)1905 size_t SnapshotProcessor::SearchNativeMethodIndex(void *nativePointer)
1906 {
1907     for (size_t i = 0; i < GetNativeTableSize(); i++) {
1908         if (nativePointer == reinterpret_cast<void *>(g_nativeTable[i])) {
1909             return i;
1910         }
1911     }
1912 
1913     // not found
1914     LOG_FULL(FATAL) << "native method did not register in g_table, please register it first";
1915     UNREACHABLE();
1916 }
1917 
TaggedObjectEncodeBitToAddr(EncodeBit taggedBit)1918 uintptr_t SnapshotProcessor::TaggedObjectEncodeBitToAddr(EncodeBit taggedBit)
1919 {
1920     ASSERT(taggedBit.IsReference());
1921     if (!builtinsDeserialize_ && taggedBit.IsReferenceToString()) {
1922         size_t stringIndex = taggedBit.GetNativePointerOrObjectIndex();
1923         return reinterpret_cast<uintptr_t>(*deserializeStringVector_.at(stringIndex));
1924     }
1925     size_t regionIndex = taggedBit.GetRegionIndex();
1926     if (UNLIKELY(regionIndexMap_.find(regionIndex) == regionIndexMap_.end())) {
1927         LOG_FULL(FATAL) << "Snapshot deserialize can not find region by index";
1928     }
1929     uintptr_t region = regionIndexMap_.find(regionIndex)->second;
1930     size_t objectOffset = taggedBit.GetObjectOffsetInRegion();
1931 
1932     uintptr_t addr = region + objectOffset;
1933     if (taggedBit.IsTSWeakObject()) {
1934         JSTaggedValue object(static_cast<JSTaggedType>(addr));
1935         object.CreateWeakRef();
1936         addr = object.GetRawData();
1937     }
1938     return addr;
1939 }
1940 
DeserializeNativePointer(uint64_t * value)1941 void SnapshotProcessor::DeserializeNativePointer(uint64_t *value)
1942 {
1943     EncodeBit native(*value);
1944     size_t index = native.GetNativePointerOrObjectIndex();
1945     uintptr_t addr = 0U;
1946     size_t nativeTableSize = GetNativeTableSize();
1947     if (index < nativeTableSize) {
1948         addr = g_nativeTable[index];
1949     } else {
1950         addr = pandaMethod_.at(index - nativeTableSize);
1951     }
1952     *value = addr;
1953 }
1954 
SerializePandaFileMethod()1955 void SnapshotProcessor::SerializePandaFileMethod()
1956 {
1957     EncodeBit encodeBit(pandaMethod_.size());
1958     encodeBit.SetObjectType(Constants::MASK_METHOD_SPACE_BEGIN);
1959 
1960     ObjectFactory *factory = vm_->GetFactory();
1961     // panda method space begin
1962     uintptr_t snapshotObj = factory->NewSpaceBySnapshotAllocator(sizeof(uint64_t));
1963     if (snapshotObj == 0) {
1964         LOG_ECMA(ERROR) << "SnapshotAllocator OOM";
1965         return;
1966     }
1967     SetObjectEncodeField(snapshotObj, 0, encodeBit.GetValue());  // methods
1968 
1969     // panda methods
1970     for (auto &it : pandaMethod_) {
1971         // write method
1972         size_t methodObjSize = Method::Size();
1973         uintptr_t methodObj = factory->NewSpaceBySnapshotAllocator(methodObjSize);
1974         if (methodObj == 0) {
1975             LOG_ECMA(ERROR) << "SnapshotAllocator OOM";
1976             return;
1977         }
1978         if (memcpy_s(ToVoidPtr(methodObj), methodObjSize, ToVoidPtr(it), Method::Size()) != EOK) {
1979             LOG_FULL(FATAL) << "memcpy_s failed";
1980             UNREACHABLE();
1981         }
1982     }
1983 }
1984 
GetNewObj(size_t objectSize,TaggedObject * objectHeader)1985 SnapshotProcessor::AllocResult SnapshotProcessor::GetNewObj(size_t objectSize, TaggedObject *objectHeader)
1986 {
1987     if (g_isEnableCMCGC) {
1988         SerializedObjectSpace spaceType = SerializedObjectSpace(
1989             static_cast<int>(common::SerializeUtils::GetSerializeObjectSpace(ToUintPtr(objectHeader))));
1990         switch (spaceType) {
1991             case SerializedObjectSpace::REGULAR_SPACE:
1992                 return regularObjAllocator_.Allocate(objectSize, regionIndex_);
1993             case SerializedObjectSpace::PIN_SPACE:
1994                 return pinnedObjAllocator_.Allocate(objectSize, regionIndex_);
1995             case SerializedObjectSpace::LARGE_SPACE:
1996                 return largeObjAllocator_.Allocate(objectSize, regionIndex_);
1997             default:
1998                 LOG_ECMA(FATAL) << "unsupported space type " << static_cast<int>(spaceType);
1999                 UNREACHABLE();
2000         }
2001     } else {
2002         uintptr_t newObj = GetNewObjAddress(objectSize, objectHeader);
2003         auto currentRegion = Region::ObjectAddressToRange(newObj);
2004         // region snapshotData_ low 32 bits is used to record region index for snapshot
2005         uint64_t snapshotData = currentRegion->GetSnapshotData();
2006         size_t regionIndex = SnapshotHelper::GetHugeObjectRegionIndex(snapshotData);
2007         size_t objOffset = newObj - ToUintPtr(currentRegion);
2008         return {newObj, objOffset, regionIndex};
2009     }
2010 }
2011 
GetNewObjAddress(size_t objectSize,TaggedObject * objectHeader)2012 uintptr_t SnapshotProcessor::GetNewObjAddress(size_t objectSize, TaggedObject *objectHeader)
2013 {
2014     if (builtinsSerialize_) {
2015         return AllocateObjectToLocalSpace(snapshotLocalSpace_, objectSize);
2016     }
2017     auto region = Region::ObjectAddressToRange(objectHeader);
2018     if (region->InYoungOrOldSpace() || region->InSharedOldSpace()) {
2019         return AllocateObjectToLocalSpace(oldLocalSpace_, objectSize);
2020     }
2021     if (region->InMachineCodeSpace()) {
2022         return AllocateObjectToLocalSpace(machineCodeLocalSpace_, objectSize);
2023     }
2024     if (region->InNonMovableSpace() || region->InReadOnlySpace() ||
2025         region->InSharedNonMovableSpace() || region->InSharedReadOnlySpace()) {
2026         return AllocateObjectToLocalSpace(nonMovableLocalSpace_, objectSize);
2027     }
2028     if (region->InHugeObjectSpace() || region->InSharedHugeObjectSpace()) {
2029         return AllocateObjectToLocalSpace(hugeObjectLocalSpace_, objectSize);
2030     }
2031     return AllocateObjectToLocalSpace(snapshotLocalSpace_, objectSize);
2032 }
2033 
EncodeTaggedObject(TaggedObject * objectHeader,CQueue<TaggedObject * > * queue,std::unordered_map<uint64_t,ObjectEncode> * data)2034 EncodeBit SnapshotProcessor::EncodeTaggedObject(TaggedObject *objectHeader, CQueue<TaggedObject *> *queue,
2035                                                 std::unordered_map<uint64_t, ObjectEncode> *data)
2036 {
2037     if (!builtinsSerialize_) {
2038         // String duplicate
2039         if (objectHeader->GetClass()->IsString()) {
2040             ASSERT(stringVector_.size() < Constants::MAX_OBJECT_INDEX);
2041             EncodeBit encodeBit(stringVector_.size());
2042             if (EcmaStringAccessor(objectHeader).IsTreeString()) {
2043                 data->emplace(ToUintPtr(objectHeader), std::make_pair(0U, encodeBit));
2044                 objectHeader = EcmaStringAccessor::FlattenNoGCForSnapshot(vm_, EcmaString::Cast(objectHeader));
2045             }
2046             stringVector_.emplace_back(ToUintPtr(objectHeader));
2047             data->emplace(ToUintPtr(objectHeader), std::make_pair(0U, encodeBit));
2048             return encodeBit;
2049         }
2050 
2051         // builtins object reuse
2052         size_t index = vm_->GetSnapshotEnv()->FindEnvObjectIndex(ToUintPtr(objectHeader));
2053         if (index != SnapshotEnv::MAX_UINT_32) {
2054             EncodeBit encodeBit(index);
2055             encodeBit.SetGlobalConstOrBuiltins();
2056             data->emplace(ToUintPtr(objectHeader), std::make_pair(0U, encodeBit));
2057             return encodeBit;
2058         }
2059     }
2060     auto oldObjHeader = objectHeader;
2061     if (objectHeader->GetClass()->IsString()) {
2062         if (EcmaStringAccessor(objectHeader).IsTreeString()) {
2063             objectHeader = EcmaStringAccessor::FlattenNoGCForSnapshot(vm_, EcmaString::Cast(objectHeader));
2064         }
2065     }
2066     queue->emplace(objectHeader);
2067     size_t objectSize = objectHeader->GetSize();
2068     if (objectSize == 0) {
2069         LOG_ECMA_MEM(FATAL) << "It is a zero object. Not Support.";
2070     }
2071     SnapshotProcessor::AllocResult allocResult = GetNewObj(objectSize, objectHeader);
2072     if (allocResult.address == 0) {
2073         LOG_ECMA_MEM(FATAL) << "Snapshot Allocate OOM";
2074     }
2075     if (memcpy_s(ToVoidPtr(allocResult.address), objectSize, objectHeader, objectSize) != EOK) {
2076         LOG_FULL(FATAL) << "memcpy_s failed";
2077         UNREACHABLE();
2078     }
2079     EncodeBit encodeBit(static_cast<uint64_t>(allocResult.regionIndex));
2080     encodeBit.SetObjectOffsetInRegion(allocResult.offset);
2081     if (oldObjHeader->GetClass()->IsString()) {
2082         if (EcmaStringAccessor(oldObjHeader).IsTreeString()) {
2083             data->emplace(ToUintPtr(oldObjHeader), std::make_pair(0U, encodeBit));
2084         }
2085     }
2086     data->emplace(ToUintPtr(objectHeader), std::make_pair(allocResult.address, encodeBit));
2087     return encodeBit;
2088 }
2089 
GetObjectEncode(JSTaggedValue object,CQueue<TaggedObject * > * queue,std::unordered_map<uint64_t,ObjectEncode> * data)2090 EncodeBit SnapshotProcessor::GetObjectEncode(JSTaggedValue object, CQueue<TaggedObject *> *queue,
2091                                              std::unordered_map<uint64_t, ObjectEncode> *data)
2092 {
2093     JSTaggedType addr = object.GetRawData();
2094     EncodeBit encodeBit(0);
2095 
2096     if (data->find(addr) == data->end()) {
2097         encodeBit = EncodeTaggedObject(object.GetTaggedObject(), queue, data);
2098     } else {
2099         ObjectEncode objectEncodePair = data->find(object.GetRawData())->second;
2100         encodeBit = objectEncodePair.second;
2101     }
2102     return encodeBit;
2103 }
2104 
EncodeTaggedObjectRange(ObjectSlot start,ObjectSlot end,CQueue<TaggedObject * > * queue,std::unordered_map<uint64_t,ObjectEncode> * data)2105 void SnapshotProcessor::EncodeTaggedObjectRange(ObjectSlot start, ObjectSlot end, CQueue<TaggedObject *> *queue,
2106                                                 std::unordered_map<uint64_t, ObjectEncode> *data)
2107 {
2108     while (start < end) {
2109         JSTaggedValue object(start.GetTaggedType());
2110         start++;
2111         if (object.IsHeapObject()) {
2112             EncodeBit encodeBit(0);
2113             if (data->find(object.GetRawData()) == data->end()) {
2114                 encodeBit = EncodeTaggedObject(object.GetTaggedObject(), queue, data);
2115             }
2116         }
2117     }
2118 }
2119 
GetNativeTableSize() const2120 size_t SnapshotProcessor::GetNativeTableSize() const
2121 {
2122     return sizeof(g_nativeTable) / sizeof(g_nativeTable[0]);
2123 }
2124 
GenerateRegionHeadInfo(Region * region)2125 SnapshotRegionHeadInfo SnapshotProcessor::GenerateRegionHeadInfo(Region *region)
2126 {
2127     // Record region head information for deserialize
2128     SnapshotRegionHeadInfo info;
2129     info.regionIndex_ = region->GetSnapshotData();
2130     if (region->InSnapshotSpace()) {
2131         info.aliveObjectSize_ = region->highWaterMark_ - region->packedData_.begin_;
2132     } else {
2133         info.aliveObjectSize_ = region->AliveObject();
2134     }
2135     return info;
2136 }
2137 
ResetRegionUnusedRange(Region * region)2138 void SnapshotProcessor::ResetRegionUnusedRange(Region *region)
2139 {
2140     // memset unused memory to 0
2141     if (region->AliveObject() < region->end_ - region->packedData_.begin_) {
2142         uintptr_t unusedAddrBegin = region->packedData_.begin_ + region->AliveObject();
2143         size_t unusedSize = region->end_ - region->packedData_.begin_ - region->AliveObject();
2144         if (memset_s(reinterpret_cast<void *>(unusedAddrBegin), unusedSize, 0, unusedSize)) {
2145             LOG_FULL(FATAL) << "memset_s failed";
2146             UNREACHABLE();
2147         }
2148     }
2149 }
2150 
Initialize(size_t commonRegionSize)2151 void SnapshotProcessor::AllocateProxy::Initialize(size_t commonRegionSize)
2152 {
2153     commonRegionSize_ = commonRegionSize;
2154 }
2155 
AllocateNewRegion(size_t size,uintptr_t & regionIndex)2156 void SnapshotProcessor::AllocateProxy::AllocateNewRegion(size_t size, uintptr_t &regionIndex)
2157 {
2158     size_t actualSize;
2159     switch (spaceType_) {
2160         case SerializedObjectSpace::REGULAR_SPACE:
2161         case SerializedObjectSpace::PIN_SPACE:
2162             actualSize = commonRegionSize_;
2163             break;
2164         case SerializedObjectSpace::LARGE_SPACE:
2165             actualSize = size;
2166             break;
2167         default:
2168             LOG_ECMA(FATAL) << "unsupported space type " << static_cast<int>(spaceType_);
2169             UNREACHABLE();
2170     }
2171     void *ptr = malloc(actualSize);
2172     if (ptr == nullptr) {
2173         LOG_ECMA(FATAL) << "malloc failed, size = " << actualSize;
2174         UNREACHABLE();
2175     }
2176     uintptr_t start = ToUintPtr(ptr);
2177     uintptr_t end = start + actualSize;
2178     currentRegion_.Reset(start, end, regionIndex++);
2179 }
2180 
Allocate(size_t size,uintptr_t & regionIndex)2181 SnapshotProcessor::AllocResult SnapshotProcessor::AllocateProxy::Allocate(size_t size, uintptr_t &regionIndex)
2182 {
2183     ASSERT(commonRegionSize_ > 0);
2184     AllocResult result = currentRegion_.Allocate(size);
2185     if (result.address != 0) {
2186         ASSERT(result.regionIndex != -1);
2187         return result;
2188     }
2189     if (!currentRegion_.IsEmpty()) {
2190         regions_.push_back(currentRegion_);
2191     }
2192     AllocateNewRegion(size, regionIndex);
2193     ASSERT(!currentRegion_.IsEmpty());
2194     result = currentRegion_.Allocate(size);
2195     ASSERT(result.address != 0);
2196     ASSERT(result.regionIndex != -1);
2197     return result;
2198 }
2199 
StopAllocate(SharedHeap * sHeap)2200 void SnapshotProcessor::AllocateProxy::StopAllocate(SharedHeap *sHeap)
2201 {
2202     if (!currentRegion_.IsEmpty()) {
2203         regions_.push_back(currentRegion_);
2204         currentRegion_.Reset(0, 0, -1);
2205     }
2206     ASSERT(currentRegion_.IsEmpty());
2207     for (RegionProxy &region : regions_) {
2208         ASSERT(!region.IsEmpty());
2209         uintptr_t begin = region.GetBegin();
2210         uintptr_t top = region.GetTop();
2211         uintptr_t end = region.GetEnd();
2212         allocatedSize_ += top - begin;
2213     }
2214     allocatedSize_ += regions_.size() * SnapshotRegionHeadInfo::RegionHeadInfoSize();
2215 }
2216 
WriteToFile(std::fstream & writer)2217 void SnapshotProcessor::AllocateProxy::WriteToFile(std::fstream &writer)
2218 {
2219     for (RegionProxy &region : regions_) {
2220         ASSERT(!region.IsEmpty());
2221         uintptr_t begin = region.GetBegin();
2222         uintptr_t top = region.GetTop();
2223         size_t objSize = top - begin;
2224         size_t regionIndex = region.GetRegionIndex();
2225         SnapshotRegionHeadInfo info {regionIndex, objSize};
2226         // Firstly, serialize the region head information into the file;
2227         writer.write(reinterpret_cast<char *>(&info), SnapshotRegionHeadInfo::RegionHeadInfoSize());
2228         // Secondly, write the valid region memory (exclude region head and GC bit set).
2229         writer.write(reinterpret_cast<char *>(begin), objSize);
2230         writer.flush();
2231     }
2232 }
2233 }  // namespace panda::ecmascript
2234