-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathBackendApi.h
338 lines (300 loc) · 11.2 KB
/
BackendApi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft Corporation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#pragma once
#if DYNAMIC_INTERPRETER_THUNK
#define DefaultEntryThunk Js::InterpreterStackFrame::DelayDynamicInterpreterThunk
#define AsmJsDefaultEntryThunk Js::InterpreterStackFrame::AsmJsDelayDynamicInterpreterThunk
#else
#define DefaultEntryThunk Js::InterpreterStackFrame::InterpreterThunk
#endif
#define ProfileEntryThunk Js::ScriptContext::DebugProfileProbeThunk
#define DefaultDeferredParsingThunk Js::JavascriptFunction::DeferredParsingThunk
#if defined(ENABLE_SCRIPT_PROFILING) || defined(ENABLE_SCRIPT_DEBUGGING)
#define ProfileDeferredParsingThunk Js::ScriptContext::ProfileModeDeferredParsingThunk
#endif
#define DefaultDeferredDeserializeThunk Js::JavascriptFunction::DeferredDeserializeThunk
#define ProfileDeferredDeserializeThunk Js::ScriptContext::ProfileModeDeferredDeserializeThunk
#if ENABLE_NATIVE_CODEGEN
class NativeCodeGenerator;
class ThreadContext;
struct CodeGenWorkItem;
class NativeCodeData;
class ThreadContextInfo;
class StackSym;
class Func;
struct InlinedFrameLayout;
typedef intptr_t IntConstType;
typedef uintptr_t UIntConstType;
typedef double FloatConstType;
#include "EmitBuffer.h"
#include "InterpreterThunkEmitter.h"
#include "JITThunkEmitter.h"
#include "BackendOpCodeAttr.h"
#include "BackendOpCodeAttrAsmJs.h"
#include "CodeGenNumberAllocator.h"
#include "NativeCodeData.h"
#include "JnHelperMethod.h"
#include "IRType.h"
#include "InlineeFrameInfo.h"
#include "CodeGenAllocators.h"
NativeCodeGenerator * NewNativeCodeGenerator(Js::ScriptContext * nativeCodeGen);
void DeleteNativeCodeGenerator(NativeCodeGenerator * nativeCodeGen);
void CloseNativeCodeGenerator(NativeCodeGenerator* nativeCodeGen);
bool IsClosedNativeCodeGenerator(NativeCodeGenerator* nativeCodeGen);
void SetProfileModeNativeCodeGen(NativeCodeGenerator *pNativeCodeGen, BOOL fSet);
void UpdateNativeCodeGeneratorForDebugMode(NativeCodeGenerator* nativeCodeGen);
CriticalSection *GetNativeCodeGenCriticalSection(NativeCodeGenerator *pNativeCodeGen);
bool TryReleaseNonHiPriWorkItem(Js::ScriptContext* scriptContext, CodeGenWorkItem* workItem);
void NativeCodeGenEnterScriptStart(NativeCodeGenerator * nativeCodeGen);
void FreeNativeCodeGenAllocation(Js::ScriptContext* scriptContext, Js::JavascriptMethod codeAddress, Js::JavascriptMethod thunkAddress);
InProcCodeGenAllocators* GetForegroundAllocator(NativeCodeGenerator * nativeCodeGen, PageAllocator* pageallocator);
void GenerateFunction(NativeCodeGenerator * nativeCodeGen, Js::FunctionBody * functionBody, Js::ScriptFunction * function = NULL);
void GenerateLoopBody(NativeCodeGenerator * nativeCodeGen, Js::FunctionBody * functionBody, Js::LoopHeader * loopHeader, Js::EntryPointInfo* entryPointInfo, uint localCount, Js::Var localSlots[]);
#ifdef ENABLE_PREJIT
void GenerateAllFunctions(NativeCodeGenerator * nativeCodeGen, Js::FunctionBody * fn);
#endif
#ifdef IR_VIEWER
Js::Var RejitIRViewerFunction(NativeCodeGenerator *nativeCodeGen, Js::FunctionBody *fn, Js::ScriptContext *scriptContext);
#endif
#ifdef ALLOW_JIT_REPRO
HRESULT JitFromEncodedWorkItem(NativeCodeGenerator *nativeCodeGen, _In_reads_(bufferSize) const byte* buffer, _In_ uint bufferSize);
#endif
BOOL IsIntermediateCodeGenThunk(Js::JavascriptMethod codeAddress);
BOOL IsAsmJsCodeGenThunk(Js::JavascriptMethod codeAddress);
typedef Js::JavascriptMethod (*CheckCodeGenFunction)(Js::ScriptFunction * function);
CheckCodeGenFunction GetCheckCodeGenFunction(Js::JavascriptMethod codeAddress);
Js::JavascriptMethod GetCheckCodeGenThunk();
#ifdef ASMJS_PLAT
Js::JavascriptMethod GetCheckAsmJsCodeGenThunk();
#endif
uint GetBailOutRegisterSaveSlotCount();
uint GetBailOutReserveSlotCount();
#if DBG
void CheckIsExecutable(Js::RecyclableObject * function, Js::JavascriptMethod entryPoint);
#endif
#ifdef PROFILE_EXEC
namespace Js
{
class ScriptContextProfiler;
};
void CreateProfilerNativeCodeGen(NativeCodeGenerator * nativeCodeGen, Js::ScriptContextProfiler * profiler);
void ProfilePrintNativeCodeGen(NativeCodeGenerator * nativeCodeGen);
void SetProfilerFromNativeCodeGen(NativeCodeGenerator * toNativeCodeGen, NativeCodeGenerator * fromNativeCodeGen);
#endif
void DeleteNativeCodeData(NativeCodeData * data);
#else
inline BOOL IsIntermediateCodeGenThunk(Js::JavascriptMethod codeAddress) { return false; }
inline BOOL IsAsmJsCodeGenThunk(Js::JavascriptMethod codeAddress) { return false; }
#endif
#if _M_X64
extern "C" void * amd64_ReturnFromCallWithFakeFrame();
#endif
struct InlinedFrameLayout
{
Js::InlineeCallInfo callInfo;
Js::JavascriptFunction *function;
Js::Var arguments; // The arguments object.
//Js::Var argv[0]; // Here it would be embedded arguments array (callInfo.count elements)
// but can't have 0-size arr in base class, so we define it in derived class.
Js::Var* GetArguments()
{
return (Js::Var*)(this + 1);
}
template<class Fn>
void MapArgs(Fn callback)
{
Js::Var* arguments = this->GetArguments();
for (uint i = 0; i < callInfo.Count; i++)
{
callback(i, (Js::Var*)((uintptr_t*)arguments + i));
}
}
InlinedFrameLayout* Next()
{
InlinedFrameLayout *next = (InlinedFrameLayout *)(this->GetArguments() + this->callInfo.Count);
return next;
}
};
class BailOutRecord;
struct LazyBailOutRecord
{
uint32 offset;
BailOutRecord* bailOutRecord;
LazyBailOutRecord() : offset(0), bailOutRecord(nullptr) {}
LazyBailOutRecord(uint32 offset, BailOutRecord* record) :
offset(offset), bailOutRecord(record)
{}
#if DBG
void Dump(Js::FunctionBody* functionBody) const;
#endif
};
struct StackFrameConstants
{
#if defined(_M_IX86)
static const size_t StackCheckCodeHeightThreadBound = 35;
static const size_t StackCheckCodeHeightNotThreadBound = 47;
static const size_t StackCheckCodeHeightWithInterruptProbe = 53;
#elif defined(_M_X64)
static const size_t StackCheckCodeHeightThreadBound = 57;
static const size_t StackCheckCodeHeightNotThreadBound = 62;
static const size_t StackCheckCodeHeightWithInterruptProbe = 68;
#elif defined(_M_ARM)
static const size_t StackCheckCodeHeight = 64;
static const size_t StackCheckCodeHeightThreadBound = StackFrameConstants::StackCheckCodeHeight;
static const size_t StackCheckCodeHeightNotThreadBound = StackFrameConstants::StackCheckCodeHeight;
static const size_t StackCheckCodeHeightWithInterruptProbe = StackFrameConstants::StackCheckCodeHeight;
#elif defined(_M_ARM64)
static const size_t StackCheckCodeHeight = 58*2;
static const size_t StackCheckCodeHeightThreadBound = StackFrameConstants::StackCheckCodeHeight;
static const size_t StackCheckCodeHeightNotThreadBound = StackFrameConstants::StackCheckCodeHeight;
static const size_t StackCheckCodeHeightWithInterruptProbe = StackFrameConstants::StackCheckCodeHeight;
#endif
};
struct NativeResourceIds
{
static const short SourceCodeResourceNameId = 0x64;
static const short ByteCodeResourceNameId = 0x65;
static const short NativeMapResourceNameId = 0x66;
static const short NativeThrowMapResourceNameId = 0x67;
};
#if defined(_M_IX86)
struct ThunkConstants
{
static const size_t ThunkInstructionSize = 2;
static const size_t ThunkSize = 6;
};
#endif
enum LibraryValue {
ValueInvalid,
ValueUndeclBlockVar,
ValueEmptyString,
ValueUndefined,
ValueNull,
ValueTrue,
ValueFalse,
ValueNegativeZero,
ValueNumberTypeStatic,
ValueStringTypeStatic,
ValueSymbolTypeStatic,
ValueObjectType,
ValueObjectHeaderInlinedType,
ValueRegexType,
ValueArrayConstructor,
ValuePositiveInfinity,
ValueNaN,
ValueJavascriptArrayType,
ValueNativeIntArrayType,
ValueNativeFloatArrayType,
ValueConstructorCacheDefaultInstance,
ValueAbsDoubleCst,
ValueUintConvertConst,
ValueBuiltinFunctions,
ValueJnHelperMethods,
ValueCharStringCache
};
enum VTableValue {
//#if !_M_X64 TODO: OOP JIT, can we make this arch specific again?
VtableJavascriptNumber,
//#endif
VtableDynamicObject,
VtableInvalid,
VtablePropertyString,
VtableLazyJSONString,
VtableLiteralStringWithPropertyStringPtr,
VtableJavascriptBoolean,
VtableJavascriptArray,
VtableInt8Array,
VtableUint8Array,
VtableUint8ClampedArray,
VtableInt16Array,
VtableUint16Array,
VtableInt32Array,
VtableUint32Array,
VtableFloat32Array,
VtableFloat64Array,
VtableJavascriptPixelArray,
VtableInt64Array,
VtableUint64Array,
VtableBoolArray,
VtableCharArray,
VtableInt8VirtualArray,
VtableUint8VirtualArray,
VtableUint8ClampedVirtualArray,
VtableInt16VirtualArray,
VtableUint16VirtualArray,
VtableInt32VirtualArray,
VtableUint32VirtualArray,
VtableFloat32VirtualArray,
VtableFloat64VirtualArray,
VtableNativeIntArray,
#if ENABLE_COPYONACCESS_ARRAY
VtableCopyOnAccessNativeIntArray,
#endif
VtableNativeFloatArray,
VtableJavascriptNativeIntArray,
VtableJavascriptRegExp,
VtableScriptFunction,
VtableScriptFunctionWithHomeObj,
VtableScriptFunctionWithComputedName,
VtableScriptFunctionWithHomeObjAndComputedName,
// Generator/Async functions
VtableJavascriptGeneratorFunction,
VtableVirtualJavascriptGeneratorFunctionWithHomeObj,
VtableVirtualJavascriptGeneratorFunctionWithComputedName,
VtableVirtualJavascriptGeneratorFunctionWithHomeObjAndComputedName,
VtableJavascriptAsyncFunction,
VtableJavascriptAsyncGeneratorFunction,
VtableStackScriptFunction,
VtableAsmJsScriptFunctionWithComputedName,
VtableScriptFunctionWithInlineCacheAndHomeObj,
VtableScriptFunctionWithInlineCacheAndComputedName,
VtableScriptFunctionWithInlineCacheHomeObjAndComputedName,
VtableConcatStringMulti,
VtableCompoundString,
// SIMD_JS
VtableSimd128F4,
VtableSimd128I4,
VtableSimd128I8,
VtableSimd128I16,
VtableSimd128U4,
VtableSimd128U8,
VtableSimd128U16,
Count
};
#if DBG_DUMP || defined(ENABLE_IR_VIEWER)
const char16 *GetVtableName(VTableValue value);
#endif
enum AuxArrayValue {
AuxPropertyIdArray,
AuxIntArray,
AuxFloatArray,
AuxVarsArray,
AuxVarArrayVarCount,
AuxFuncInfoArray
};
enum OptimizationOverridesValue {
OptimizationOverridesArraySetElementFastPathVtable,
OptimizationOverridesIntArraySetElementFastPathVtable,
OptimizationOverridesFloatArraySetElementFastPathVtable,
OptimizationOverridesSideEffects
};
enum FunctionBodyValue {
FunctionBodyConstantVar,
FunctionBodyNestedFuncReference,
FunctionBodyReferencedPropertyId,
FunctionBodyPropertyIdFromCacheId,
FunctionBodyLiteralRegex,
FunctionBodyStringTemplateCallsiteRef
};
enum ScriptContextValue {
ScriptContextNumberAllocator,
ScriptContextCharStringCache,
ScriptContextRecycler,
ScriptContextOptimizationOverrides
};
enum NumberAllocatorValue {
NumberAllocatorEndAddress,
NumberAllocatorFreeObjectList
};