Skip to content

Commit 172fbd8

Browse files
committed
[MERGE #5676 @jackhorton] Reduce code duplication in EngineInterfaceObject
Merge pull request #5676 from jackhorton:engineinterface-cleanup This has been bothering me for a while. This also reduces the size of ChakraCore.dll by 16KiB by removing a bunch of duplicate EntryInfos
2 parents e3d4139 + 650528b commit 172fbd8

15 files changed

+29699
-30008
lines changed

lib/Runtime/Base/JnDirectFields.h

Lines changed: 6 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,6 @@ ENTRY(localeWithoutSubtags)
515515
ENTRY(resolvedOptions)
516516
ENTRY(subTags)
517517
ENTRY(supportedLocalesOf)
518-
ENTRY(tagPublicLibraryCode)
519518
ENTRY(winglob)
520519
ENTRY(platform)
521520
ENTRY(formatToParts)
@@ -646,68 +645,17 @@ ENTRY(arraySpeciesCreate)
646645
ENTRY(arrayCreateDataPropertyOrThrow)
647646

648647
// EngineInterfaceObject built-ins
649-
ENTRY(builtInGlobalObjectEntryIsFinite)
650-
ENTRY(builtInGlobalObjectEntryIsNaN)
651-
ENTRY(builtInGlobalObjectEval)
652-
ENTRY(builtInJavascriptArrayEntryConcat)
653648
ENTRY(builtInJavascriptArrayEntryFilter)
654649
ENTRY(builtInJavascriptArrayEntryForEach)
655650
ENTRY(builtInJavascriptArrayEntryIndexOf)
656-
ENTRY(builtInJavascriptArrayEntryJoin)
657-
ENTRY(builtInJavascriptArrayEntryMap)
658-
ENTRY(builtInJavascriptArrayEntryPush)
659-
ENTRY(builtInJavascriptArrayEntryReduce)
660-
ENTRY(builtInJavascriptArrayEntrySlice)
661-
ENTRY(builtInJavascriptDateEntryGetDate)
662-
ENTRY(builtInJavascriptDateEntryNow)
663-
ENTRY(builtInJavascriptFunctionEntryApply)
664-
ENTRY(builtInJavascriptFunctionEntryBind)
665-
ENTRY(builtInJavascriptObjectCreate)
666-
ENTRY(builtInJavascriptObjectEntryDefineProperty)
667-
ENTRY(builtInJavascriptObjectEntryGetOwnPropertyNames)
668-
ENTRY(builtInJavascriptObjectEntryGetPrototypeOf)
669-
ENTRY(builtInJavascriptObjectEntryHasOwnProperty)
670-
ENTRY(builtInJavascriptObjectEntryIsExtensible)
671-
ENTRY(builtInJavascriptObjectEntryKeys)
672-
ENTRY(builtInJavascriptObjectGetOwnPropertyDescriptor)
673-
ENTRY(builtInJavascriptObjectPreventExtensions)
674-
ENTRY(builtInJavascriptRegExpEntryTest) // TODO(jahorto): is this needed?
675-
ENTRY(builtInJavascriptStringEntryIndexOf)
676-
ENTRY(builtInJavascriptStringEntryMatch)
677-
ENTRY(builtInJavascriptStringEntryRepeat)
678-
ENTRY(builtInJavascriptStringEntryReplace)
679-
ENTRY(builtInJavascriptStringEntrySplit)
680-
ENTRY(builtInJavascriptStringEntrySubstring)
681-
ENTRY(builtInJavascriptStringEntryToLowerCase)
682-
ENTRY(builtInJavascriptStringEntryToUpperCase)
683-
ENTRY(builtInMathAbs)
684-
ENTRY(builtInMathFloor)
685-
ENTRY(builtInMathMax)
686-
ENTRY(builtInMathPow)
687651
ENTRY(EngineInterface)
688-
ENTRY(getErrorMessage)
689-
ENTRY(logDebugMessage)
690-
ENTRY(Object_prototype)
691-
ENTRY(builtInSetPrototype)
692-
ENTRY(builtInGetArrayLength)
693-
ENTRY(builtInRegexMatch)
694652
ENTRY(builtInCallInstanceFunction)
695-
ENTRY(raiseInvalidCurrencyCode)
696-
ENTRY(raiseInvalidDate)
697-
ENTRY(raiseLengthIsTooBig)
698-
ENTRY(raiseLocaleNotWellFormed)
699-
ENTRY(raiseMissingCurrencyCode)
700-
ENTRY(raiseNeedObject)
701-
ENTRY(raiseNeedObjectOfType)
702-
ENTRY(raiseNeedObjectOrString)
703-
ENTRY(raiseNotAConstructor)
704-
ENTRY(raiseNonObjectFromIterable)
705-
ENTRY(raiseObjectIsAlreadyInitialized)
706-
ENTRY(raiseObjectIsNonExtensible)
707-
ENTRY(raiseOptionValueOutOfRange_3)
708-
ENTRY(raiseOptionValueOutOfRange)
709-
ENTRY(raiseThis_NullOrUndefined)
710-
ENTRY(raiseFunctionArgument_NeedFunction)
653+
654+
#define GlobalMathBuiltIn(mathMethod) ENTRY(builtInMath##mathMethod)
655+
#define GlobalBuiltIn(global, method) ENTRY(builtIn##global##Entry##method)
656+
#define BuiltInRaiseException(exceptionType, exceptionID) ENTRY(raise##exceptionID)
657+
#define EngineInterfaceBuiltIn2(propId, nativeMethod) ENTRY(propId)
658+
#include "../Library/EngineInterfaceObjectBuiltIns.h"
711659

712660
// Promise (ChakraFull)
713661
ENTRY(Promise)

lib/Runtime/ByteCode/ByteCodeCacheReleaseFileVersion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
//-------------------------------------------------------------------------------------------------------
55
// NOTE: If there is a merge conflict the correct fix is to make a new GUID.
66

7-
// {DE720CA5-2D6E-4200-B4AB-CCCE40399727}
7+
// {FFAB17C6-6AD9-41BC-AFDA-2DC8E1D4C594}
88
const GUID byteCodeCacheReleaseFileVersion =
9-
{ 0xDE720CA5, 0x2D6E, 0x4200, { 0xB4, 0xAB, 0xCC, 0xCE, 0x40, 0x39, 0x97, 0x27 } };
9+
{ 0xFFAB17C6, 0x6AD9, 0x41BC, { 0xAF, 0xDA, 0x2D, 0xC8, 0xE1, 0xD4, 0xC5, 0x94 } };

lib/Runtime/Library/EngineInterfaceObject.cpp

Lines changed: 20 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -101,36 +101,11 @@ namespace Js
101101
}
102102
}
103103

104-
NoProfileFunctionInfo EngineInterfaceObject::EntryInfo::GetErrorMessage(FORCE_NO_WRITE_BARRIER_TAG(EngineInterfaceObject::Entry_GetErrorMessage));
105-
NoProfileFunctionInfo EngineInterfaceObject::EntryInfo::LogDebugMessage(FORCE_NO_WRITE_BARRIER_TAG(EngineInterfaceObject::Entry_LogDebugMessage));
106-
NoProfileFunctionInfo EngineInterfaceObject::EntryInfo::TagPublicLibraryCode(FORCE_NO_WRITE_BARRIER_TAG(EngineInterfaceObject::Entry_TagPublicLibraryCode));
107-
NoProfileFunctionInfo EngineInterfaceObject::EntryInfo::SetPrototype(FORCE_NO_WRITE_BARRIER_TAG(EngineInterfaceObject::Entry_SetPrototype));
108-
NoProfileFunctionInfo EngineInterfaceObject::EntryInfo::GetArrayLength(FORCE_NO_WRITE_BARRIER_TAG(EngineInterfaceObject::Entry_GetArrayLength));
109-
NoProfileFunctionInfo EngineInterfaceObject::EntryInfo::RegexMatch(FORCE_NO_WRITE_BARRIER_TAG(EngineInterfaceObject::Entry_RegexMatch));
110-
111-
#ifndef GlobalBuiltIn
112-
#define GlobalBuiltIn(global, method) \
113-
NoProfileFunctionInfo EngineInterfaceObject::EntryInfo::BuiltIn_##global##_##method##(FORCE_NO_WRITE_BARRIER_TAG(global##::##method##)); \
114-
115-
#define GlobalBuiltInConstructor(global)
116-
117-
#define BuiltInRaiseException(exceptionType, exceptionID) \
118-
NoProfileFunctionInfo EngineInterfaceObject::EntryInfo::BuiltIn_raise##exceptionID(FORCE_NO_WRITE_BARRIER_TAG(EngineInterfaceObject::Entry_BuiltIn_raise##exceptionID)); \
119-
120-
#define BuiltInRaiseException1(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID)
121-
#define BuiltInRaiseException2(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID)
122-
#define BuiltInRaiseException3(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID##_3)
123-
104+
// initialize EngineInterfaceObject::EntryInfo
105+
#define EngineInterfaceBuiltIn2(propId, nativeMethod) NoProfileFunctionInfo EngineInterfaceObject::EntryInfo::nativeMethod(FORCE_NO_WRITE_BARRIER_TAG(EngineInterfaceObject::Entry_##nativeMethod));
106+
#define BuiltInRaiseException(exceptionType, exceptionID) NoProfileFunctionInfo EngineInterfaceObject::EntryInfo::BuiltIn_raise##exceptionID(FORCE_NO_WRITE_BARRIER_TAG(EngineInterfaceObject::Entry_BuiltIn_raise##exceptionID));
124107
#include "EngineInterfaceObjectBuiltIns.h"
125108

126-
#undef BuiltInRaiseException
127-
#undef BuiltInRaiseException1
128-
#undef BuiltInRaiseException2
129-
#undef BuiltInRaiseException3
130-
#undef GlobalBuiltInConstructor
131-
#undef GlobalBuiltIn
132-
#endif
133-
134109
EngineInterfaceObject * EngineInterfaceObject::New(Recycler * recycler, DynamicType * type)
135110
{
136111
EngineInterfaceObject* newObject = NewObject<EngineInterfaceObject>(recycler, type);
@@ -205,48 +180,28 @@ namespace Js
205180

206181
bool EngineInterfaceObject::InitializeCommonNativeInterfaces(DynamicObject* commonNativeInterfaces, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
207182
{
208-
typeHandler->Convert(commonNativeInterfaces, mode, 38);
209-
210-
JavascriptLibrary* library = commonNativeInterfaces->GetScriptContext()->GetLibrary();
211-
212-
#ifndef GlobalBuiltIn
213-
#define GlobalBuiltIn(global, method) \
214-
library->AddFunctionToLibraryObject(commonNativeInterfaces, Js::PropertyIds::builtIn##global##method, &EngineInterfaceObject::EntryInfo::BuiltIn_##global##_##method##, 1); \
215-
216-
#define GlobalBuiltInConstructor(global) SetPropertyOn(commonNativeInterfaces, Js::PropertyIds::##global##, library->Get##global##Constructor());
217-
218-
#define BuiltInRaiseException(exceptionType, exceptionID) \
219-
library->AddFunctionToLibraryObject(commonNativeInterfaces, Js::PropertyIds::raise##exceptionID, &EngineInterfaceObject::EntryInfo::BuiltIn_raise##exceptionID, 1); \
220-
221-
#define BuiltInRaiseException1(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID)
222-
#define BuiltInRaiseException2(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID)
223-
#define BuiltInRaiseException3(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID##_3)
224-
183+
// start with 1 for CallInstanceFunction
184+
int initSlotCapacity = 1;
185+
186+
#define GlobalMathBuiltIn(mathMethod) initSlotCapacity++;
187+
#define GlobalBuiltIn(global, method) initSlotCapacity++;
188+
#define GlobalBuiltInConstructor(global) initSlotCapacity++;
189+
#define BuiltInRaiseException(exceptionType, exceptionID) initSlotCapacity++;
190+
#define EngineInterfaceBuiltIn2(propId, nativeMethod) initSlotCapacity++;
225191
#include "EngineInterfaceObjectBuiltIns.h"
226192

227-
#undef BuiltInRaiseException
228-
#undef BuiltInRaiseException1
229-
#undef BuiltInRaiseException2
230-
#undef BuiltInRaiseException3
231-
#undef GlobalBuiltIn
232-
#undef GlobalBuiltInConstructor
233-
#endif
234-
library->AddFunctionToLibraryObject(commonNativeInterfaces, Js::PropertyIds::builtInJavascriptObjectCreate, &JavascriptObject::EntryInfo::Create, 1);
235-
library->AddFunctionToLibraryObject(commonNativeInterfaces, Js::PropertyIds::builtInJavascriptObjectPreventExtensions, &JavascriptObject::EntryInfo::PreventExtensions, 1);
236-
library->AddFunctionToLibraryObject(commonNativeInterfaces, Js::PropertyIds::builtInJavascriptObjectGetOwnPropertyDescriptor, &JavascriptObject::EntryInfo::GetOwnPropertyDescriptor, 1);
237-
238-
library->AddFunctionToLibraryObject(commonNativeInterfaces, Js::PropertyIds::builtInGlobalObjectEval, &GlobalObject::EntryInfo::Eval, 2);
193+
typeHandler->Convert(commonNativeInterfaces, mode, initSlotCapacity);
239194

240-
library->AddMember(commonNativeInterfaces, PropertyIds::Object_prototype, library->GetObjectPrototype());
195+
JavascriptLibrary* library = commonNativeInterfaces->GetScriptContext()->GetLibrary();
241196

242-
library->AddFunctionToLibraryObject(commonNativeInterfaces, Js::PropertyIds::getErrorMessage, &EngineInterfaceObject::EntryInfo::GetErrorMessage, 1);
243-
library->AddFunctionToLibraryObject(commonNativeInterfaces, Js::PropertyIds::logDebugMessage, &EngineInterfaceObject::EntryInfo::LogDebugMessage, 1);
244-
library->AddFunctionToLibraryObject(commonNativeInterfaces, Js::PropertyIds::tagPublicLibraryCode, &EngineInterfaceObject::EntryInfo::TagPublicLibraryCode, 1);
197+
#define GlobalMathBuiltIn(mathMethod) library->AddFunctionToLibraryObject(commonNativeInterfaces, PropertyIds::builtInMath##mathMethod, &Math::EntryInfo::mathMethod, 1);
198+
#define GlobalBuiltIn(global, method) library->AddFunctionToLibraryObject(commonNativeInterfaces, PropertyIds::builtIn##global##Entry##method, &global::EntryInfo::method, 1);
199+
#define GlobalBuiltInConstructor(global) SetPropertyOn(commonNativeInterfaces, PropertyIds::##global##, library->Get##global##Constructor());
200+
#define BuiltInRaiseException(exceptionType, exceptionID) library->AddFunctionToLibraryObject(commonNativeInterfaces, PropertyIds::raise##exceptionID, &EngineInterfaceObject::EntryInfo::BuiltIn_raise##exceptionID, 1);
201+
#define EngineInterfaceBuiltIn2(propId, nativeMethod) library->AddFunctionToLibraryObject(commonNativeInterfaces, PropertyIds::propId, &EngineInterfaceObject::EntryInfo::nativeMethod, 1);
202+
#include "EngineInterfaceObjectBuiltIns.h"
245203

246-
library->AddFunctionToLibraryObject(commonNativeInterfaces, Js::PropertyIds::builtInSetPrototype, &EngineInterfaceObject::EntryInfo::SetPrototype, 1);
247-
library->AddFunctionToLibraryObject(commonNativeInterfaces, Js::PropertyIds::builtInGetArrayLength, &EngineInterfaceObject::EntryInfo::GetArrayLength, 1);
248-
library->AddFunctionToLibraryObject(commonNativeInterfaces, Js::PropertyIds::builtInRegexMatch, &EngineInterfaceObject::EntryInfo::RegexMatch, 1);
249-
library->AddFunctionToLibraryObject(commonNativeInterfaces, Js::PropertyIds::builtInCallInstanceFunction, &EngineInterfaceObject::EntryInfo::CallInstanceFunction, 1);
204+
library->AddFunctionToLibraryObject(commonNativeInterfaces, PropertyIds::builtInCallInstanceFunction, &EngineInterfaceObject::EntryInfo::CallInstanceFunction, 1);
250205

251206
commonNativeInterfaces->SetHasNoEnumerableProperties(true);
252207

@@ -449,10 +404,6 @@ namespace Js
449404
END_SAFE_REENTRANT_CALL
450405
}
451406

452-
#ifndef GlobalBuiltIn
453-
#define GlobalBuiltIn(global, method)
454-
#define GlobalBuiltInConstructor(global)
455-
456407
#define BuiltInRaiseException(exceptionType, exceptionID) \
457408
Var EngineInterfaceObject::Entry_BuiltIn_raise##exceptionID(RecyclableObject *function, CallInfo callInfo, ...) \
458409
{ \
@@ -502,13 +453,5 @@ namespace Js
502453

503454
#include "EngineInterfaceObjectBuiltIns.h"
504455

505-
#undef BuiltInRaiseException
506-
#undef BuiltInRaiseException1
507-
#undef BuiltInRaiseException2
508-
#undef BuiltInRaiseException3
509-
#undef GlobalBuiltIn
510-
#undef GlobalBuiltInConstructor
511-
#endif
512-
513456
}
514457
#endif // ENABLE_INTL_OBJECT || ENABLE_JS_BUILTINS || ENABLE_PROJECTION

lib/Runtime/Library/EngineInterfaceObject.h

Lines changed: 6 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -91,71 +91,23 @@ namespace Js
9191
class EntryInfo
9292
{
9393
public:
94-
static NoProfileFunctionInfo GetErrorMessage;
95-
static NoProfileFunctionInfo LogDebugMessage;
96-
static NoProfileFunctionInfo TagPublicLibraryCode;
97-
static NoProfileFunctionInfo SetPrototype;
98-
static NoProfileFunctionInfo GetArrayLength;
99-
static NoProfileFunctionInfo RegexMatch;
94+
// CallInstanceFunction is still handled specially because it gets special inline treatment from the JIT
10095
static FunctionInfo CallInstanceFunction;
10196

102-
#ifndef GlobalBuiltIn
103-
#define GlobalBuiltIn(global, method) \
104-
static NoProfileFunctionInfo BuiltIn_##global##_##method##; \
105-
106-
#define GlobalBuiltInConstructor(global)
107-
108-
#define BuiltInRaiseException(exceptionType, exceptionID) \
109-
static NoProfileFunctionInfo BuiltIn_raise##exceptionID;
110-
111-
#define BuiltInRaiseException1(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID)
112-
#define BuiltInRaiseException2(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID)
113-
#define BuiltInRaiseException3(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID##_3)
114-
97+
#define BuiltInRaiseException(exceptionType, exceptionID) static NoProfileFunctionInfo BuiltIn_raise##exceptionID;
98+
#define EngineInterfaceBuiltIn2(propId, nativeMethod) static NoProfileFunctionInfo nativeMethod;
11599
#include "EngineInterfaceObjectBuiltIns.h"
116-
117-
#undef BuiltInRaiseException
118-
#undef BuiltInRaiseException1
119-
#undef BuiltInRaiseException2
120-
#undef BuiltInRaiseException3
121-
#undef GlobalBuiltInConstructor
122-
#undef GlobalBuiltIn
123-
#endif
124100
};
125101

126-
static Var Entry_GetErrorMessage(RecyclableObject *function, CallInfo callInfo, ...);
127-
static Var Entry_LogDebugMessage(RecyclableObject *function, CallInfo callInfo, ...);
128-
static Var Entry_TagPublicLibraryCode(RecyclableObject *function, CallInfo callInfo, ...);
129-
static Var Entry_SetPrototype(RecyclableObject *function, CallInfo callInfo, ...);
130-
static Var Entry_GetArrayLength(RecyclableObject *function, CallInfo callInfo, ...);
131-
static Var Entry_RegexMatch(RecyclableObject *function, CallInfo callInfo, ...);
132102
static Var Entry_CallInstanceFunction(RecyclableObject *function, CallInfo callInfo, ...);
103+
133104
#ifdef ENABLE_PROJECTION
134105
static Var EntryPromise_EnqueueTask(RecyclableObject *function, CallInfo callInfo, ...);
135106
#endif
136107

137-
#ifndef GlobalBuiltIn
138-
#define GlobalBuiltIn(global, method)
139-
140-
#define GlobalBuiltInConstructor(global)
141-
142-
#define BuiltInRaiseException(exceptionType, exceptionID) \
143-
static Var Entry_BuiltIn_raise##exceptionID(RecyclableObject *function, CallInfo callInfo, ...);
144-
145-
#define BuiltInRaiseException1(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID)
146-
#define BuiltInRaiseException2(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID)
147-
#define BuiltInRaiseException3(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID##_3)
148-
108+
#define BuiltInRaiseException(exceptionType, exceptionID) static Var Entry_BuiltIn_raise##exceptionID(RecyclableObject *function, CallInfo callInfo, ...);
109+
#define EngineInterfaceBuiltIn2(propId, nativeMethod) static Var Entry_##nativeMethod(RecyclableObject *function, CallInfo callInfo, ...);
149110
#include "EngineInterfaceObjectBuiltIns.h"
150-
151-
#undef BuiltInRaiseException
152-
#undef BuiltInRaiseException1
153-
#undef BuiltInRaiseException2
154-
#undef BuiltInRaiseException3
155-
#undef GlobalBuiltInConstructor
156-
#undef GlobalBuiltIn
157-
#endif
158-
159111
};
160112
}
161113

0 commit comments

Comments
 (0)