Skip to content

Commit

Permalink
[MERGE #5676 @jackhorton] Reduce code duplication in EngineInterfaceO…
Browse files Browse the repository at this point in the history
…bject

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
  • Loading branch information
jackhorton committed Sep 14, 2018
2 parents e3d4139 + 650528b commit 172fbd8
Show file tree
Hide file tree
Showing 15 changed files with 29,699 additions and 30,008 deletions.
64 changes: 6 additions & 58 deletions lib/Runtime/Base/JnDirectFields.h
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,6 @@ ENTRY(localeWithoutSubtags)
ENTRY(resolvedOptions)
ENTRY(subTags)
ENTRY(supportedLocalesOf)
ENTRY(tagPublicLibraryCode)
ENTRY(winglob)
ENTRY(platform)
ENTRY(formatToParts)
Expand Down Expand Up @@ -646,68 +645,17 @@ ENTRY(arraySpeciesCreate)
ENTRY(arrayCreateDataPropertyOrThrow)

// EngineInterfaceObject built-ins
ENTRY(builtInGlobalObjectEntryIsFinite)
ENTRY(builtInGlobalObjectEntryIsNaN)
ENTRY(builtInGlobalObjectEval)
ENTRY(builtInJavascriptArrayEntryConcat)
ENTRY(builtInJavascriptArrayEntryFilter)
ENTRY(builtInJavascriptArrayEntryForEach)
ENTRY(builtInJavascriptArrayEntryIndexOf)
ENTRY(builtInJavascriptArrayEntryJoin)
ENTRY(builtInJavascriptArrayEntryMap)
ENTRY(builtInJavascriptArrayEntryPush)
ENTRY(builtInJavascriptArrayEntryReduce)
ENTRY(builtInJavascriptArrayEntrySlice)
ENTRY(builtInJavascriptDateEntryGetDate)
ENTRY(builtInJavascriptDateEntryNow)
ENTRY(builtInJavascriptFunctionEntryApply)
ENTRY(builtInJavascriptFunctionEntryBind)
ENTRY(builtInJavascriptObjectCreate)
ENTRY(builtInJavascriptObjectEntryDefineProperty)
ENTRY(builtInJavascriptObjectEntryGetOwnPropertyNames)
ENTRY(builtInJavascriptObjectEntryGetPrototypeOf)
ENTRY(builtInJavascriptObjectEntryHasOwnProperty)
ENTRY(builtInJavascriptObjectEntryIsExtensible)
ENTRY(builtInJavascriptObjectEntryKeys)
ENTRY(builtInJavascriptObjectGetOwnPropertyDescriptor)
ENTRY(builtInJavascriptObjectPreventExtensions)
ENTRY(builtInJavascriptRegExpEntryTest) // TODO(jahorto): is this needed?
ENTRY(builtInJavascriptStringEntryIndexOf)
ENTRY(builtInJavascriptStringEntryMatch)
ENTRY(builtInJavascriptStringEntryRepeat)
ENTRY(builtInJavascriptStringEntryReplace)
ENTRY(builtInJavascriptStringEntrySplit)
ENTRY(builtInJavascriptStringEntrySubstring)
ENTRY(builtInJavascriptStringEntryToLowerCase)
ENTRY(builtInJavascriptStringEntryToUpperCase)
ENTRY(builtInMathAbs)
ENTRY(builtInMathFloor)
ENTRY(builtInMathMax)
ENTRY(builtInMathPow)
ENTRY(EngineInterface)
ENTRY(getErrorMessage)
ENTRY(logDebugMessage)
ENTRY(Object_prototype)
ENTRY(builtInSetPrototype)
ENTRY(builtInGetArrayLength)
ENTRY(builtInRegexMatch)
ENTRY(builtInCallInstanceFunction)
ENTRY(raiseInvalidCurrencyCode)
ENTRY(raiseInvalidDate)
ENTRY(raiseLengthIsTooBig)
ENTRY(raiseLocaleNotWellFormed)
ENTRY(raiseMissingCurrencyCode)
ENTRY(raiseNeedObject)
ENTRY(raiseNeedObjectOfType)
ENTRY(raiseNeedObjectOrString)
ENTRY(raiseNotAConstructor)
ENTRY(raiseNonObjectFromIterable)
ENTRY(raiseObjectIsAlreadyInitialized)
ENTRY(raiseObjectIsNonExtensible)
ENTRY(raiseOptionValueOutOfRange_3)
ENTRY(raiseOptionValueOutOfRange)
ENTRY(raiseThis_NullOrUndefined)
ENTRY(raiseFunctionArgument_NeedFunction)

#define GlobalMathBuiltIn(mathMethod) ENTRY(builtInMath##mathMethod)
#define GlobalBuiltIn(global, method) ENTRY(builtIn##global##Entry##method)
#define BuiltInRaiseException(exceptionType, exceptionID) ENTRY(raise##exceptionID)
#define EngineInterfaceBuiltIn2(propId, nativeMethod) ENTRY(propId)
#include "../Library/EngineInterfaceObjectBuiltIns.h"

// Promise (ChakraFull)
ENTRY(Promise)
Expand Down
4 changes: 2 additions & 2 deletions lib/Runtime/ByteCode/ByteCodeCacheReleaseFileVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
//-------------------------------------------------------------------------------------------------------
// NOTE: If there is a merge conflict the correct fix is to make a new GUID.

// {DE720CA5-2D6E-4200-B4AB-CCCE40399727}
// {FFAB17C6-6AD9-41BC-AFDA-2DC8E1D4C594}
const GUID byteCodeCacheReleaseFileVersion =
{ 0xDE720CA5, 0x2D6E, 0x4200, { 0xB4, 0xAB, 0xCC, 0xCE, 0x40, 0x39, 0x97, 0x27 } };
{ 0xFFAB17C6, 0x6AD9, 0x41BC, { 0xAF, 0xDA, 0x2D, 0xC8, 0xE1, 0xD4, 0xC5, 0x94 } };
97 changes: 20 additions & 77 deletions lib/Runtime/Library/EngineInterfaceObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,36 +101,11 @@ namespace Js
}
}

NoProfileFunctionInfo EngineInterfaceObject::EntryInfo::GetErrorMessage(FORCE_NO_WRITE_BARRIER_TAG(EngineInterfaceObject::Entry_GetErrorMessage));
NoProfileFunctionInfo EngineInterfaceObject::EntryInfo::LogDebugMessage(FORCE_NO_WRITE_BARRIER_TAG(EngineInterfaceObject::Entry_LogDebugMessage));
NoProfileFunctionInfo EngineInterfaceObject::EntryInfo::TagPublicLibraryCode(FORCE_NO_WRITE_BARRIER_TAG(EngineInterfaceObject::Entry_TagPublicLibraryCode));
NoProfileFunctionInfo EngineInterfaceObject::EntryInfo::SetPrototype(FORCE_NO_WRITE_BARRIER_TAG(EngineInterfaceObject::Entry_SetPrototype));
NoProfileFunctionInfo EngineInterfaceObject::EntryInfo::GetArrayLength(FORCE_NO_WRITE_BARRIER_TAG(EngineInterfaceObject::Entry_GetArrayLength));
NoProfileFunctionInfo EngineInterfaceObject::EntryInfo::RegexMatch(FORCE_NO_WRITE_BARRIER_TAG(EngineInterfaceObject::Entry_RegexMatch));

#ifndef GlobalBuiltIn
#define GlobalBuiltIn(global, method) \
NoProfileFunctionInfo EngineInterfaceObject::EntryInfo::BuiltIn_##global##_##method##(FORCE_NO_WRITE_BARRIER_TAG(global##::##method##)); \

#define GlobalBuiltInConstructor(global)

#define BuiltInRaiseException(exceptionType, exceptionID) \
NoProfileFunctionInfo EngineInterfaceObject::EntryInfo::BuiltIn_raise##exceptionID(FORCE_NO_WRITE_BARRIER_TAG(EngineInterfaceObject::Entry_BuiltIn_raise##exceptionID)); \

#define BuiltInRaiseException1(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID)
#define BuiltInRaiseException2(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID)
#define BuiltInRaiseException3(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID##_3)

// initialize EngineInterfaceObject::EntryInfo
#define EngineInterfaceBuiltIn2(propId, nativeMethod) NoProfileFunctionInfo EngineInterfaceObject::EntryInfo::nativeMethod(FORCE_NO_WRITE_BARRIER_TAG(EngineInterfaceObject::Entry_##nativeMethod));
#define BuiltInRaiseException(exceptionType, exceptionID) NoProfileFunctionInfo EngineInterfaceObject::EntryInfo::BuiltIn_raise##exceptionID(FORCE_NO_WRITE_BARRIER_TAG(EngineInterfaceObject::Entry_BuiltIn_raise##exceptionID));
#include "EngineInterfaceObjectBuiltIns.h"

#undef BuiltInRaiseException
#undef BuiltInRaiseException1
#undef BuiltInRaiseException2
#undef BuiltInRaiseException3
#undef GlobalBuiltInConstructor
#undef GlobalBuiltIn
#endif

EngineInterfaceObject * EngineInterfaceObject::New(Recycler * recycler, DynamicType * type)
{
EngineInterfaceObject* newObject = NewObject<EngineInterfaceObject>(recycler, type);
Expand Down Expand Up @@ -205,48 +180,28 @@ namespace Js

bool EngineInterfaceObject::InitializeCommonNativeInterfaces(DynamicObject* commonNativeInterfaces, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
{
typeHandler->Convert(commonNativeInterfaces, mode, 38);

JavascriptLibrary* library = commonNativeInterfaces->GetScriptContext()->GetLibrary();

#ifndef GlobalBuiltIn
#define GlobalBuiltIn(global, method) \
library->AddFunctionToLibraryObject(commonNativeInterfaces, Js::PropertyIds::builtIn##global##method, &EngineInterfaceObject::EntryInfo::BuiltIn_##global##_##method##, 1); \

#define GlobalBuiltInConstructor(global) SetPropertyOn(commonNativeInterfaces, Js::PropertyIds::##global##, library->Get##global##Constructor());

#define BuiltInRaiseException(exceptionType, exceptionID) \
library->AddFunctionToLibraryObject(commonNativeInterfaces, Js::PropertyIds::raise##exceptionID, &EngineInterfaceObject::EntryInfo::BuiltIn_raise##exceptionID, 1); \

#define BuiltInRaiseException1(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID)
#define BuiltInRaiseException2(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID)
#define BuiltInRaiseException3(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID##_3)

// start with 1 for CallInstanceFunction
int initSlotCapacity = 1;

#define GlobalMathBuiltIn(mathMethod) initSlotCapacity++;
#define GlobalBuiltIn(global, method) initSlotCapacity++;
#define GlobalBuiltInConstructor(global) initSlotCapacity++;
#define BuiltInRaiseException(exceptionType, exceptionID) initSlotCapacity++;
#define EngineInterfaceBuiltIn2(propId, nativeMethod) initSlotCapacity++;
#include "EngineInterfaceObjectBuiltIns.h"

#undef BuiltInRaiseException
#undef BuiltInRaiseException1
#undef BuiltInRaiseException2
#undef BuiltInRaiseException3
#undef GlobalBuiltIn
#undef GlobalBuiltInConstructor
#endif
library->AddFunctionToLibraryObject(commonNativeInterfaces, Js::PropertyIds::builtInJavascriptObjectCreate, &JavascriptObject::EntryInfo::Create, 1);
library->AddFunctionToLibraryObject(commonNativeInterfaces, Js::PropertyIds::builtInJavascriptObjectPreventExtensions, &JavascriptObject::EntryInfo::PreventExtensions, 1);
library->AddFunctionToLibraryObject(commonNativeInterfaces, Js::PropertyIds::builtInJavascriptObjectGetOwnPropertyDescriptor, &JavascriptObject::EntryInfo::GetOwnPropertyDescriptor, 1);

library->AddFunctionToLibraryObject(commonNativeInterfaces, Js::PropertyIds::builtInGlobalObjectEval, &GlobalObject::EntryInfo::Eval, 2);
typeHandler->Convert(commonNativeInterfaces, mode, initSlotCapacity);

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

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

library->AddFunctionToLibraryObject(commonNativeInterfaces, Js::PropertyIds::builtInSetPrototype, &EngineInterfaceObject::EntryInfo::SetPrototype, 1);
library->AddFunctionToLibraryObject(commonNativeInterfaces, Js::PropertyIds::builtInGetArrayLength, &EngineInterfaceObject::EntryInfo::GetArrayLength, 1);
library->AddFunctionToLibraryObject(commonNativeInterfaces, Js::PropertyIds::builtInRegexMatch, &EngineInterfaceObject::EntryInfo::RegexMatch, 1);
library->AddFunctionToLibraryObject(commonNativeInterfaces, Js::PropertyIds::builtInCallInstanceFunction, &EngineInterfaceObject::EntryInfo::CallInstanceFunction, 1);
library->AddFunctionToLibraryObject(commonNativeInterfaces, PropertyIds::builtInCallInstanceFunction, &EngineInterfaceObject::EntryInfo::CallInstanceFunction, 1);

commonNativeInterfaces->SetHasNoEnumerableProperties(true);

Expand Down Expand Up @@ -449,10 +404,6 @@ namespace Js
END_SAFE_REENTRANT_CALL
}

#ifndef GlobalBuiltIn
#define GlobalBuiltIn(global, method)
#define GlobalBuiltInConstructor(global)

#define BuiltInRaiseException(exceptionType, exceptionID) \
Var EngineInterfaceObject::Entry_BuiltIn_raise##exceptionID(RecyclableObject *function, CallInfo callInfo, ...) \
{ \
Expand Down Expand Up @@ -502,13 +453,5 @@ namespace Js

#include "EngineInterfaceObjectBuiltIns.h"

#undef BuiltInRaiseException
#undef BuiltInRaiseException1
#undef BuiltInRaiseException2
#undef BuiltInRaiseException3
#undef GlobalBuiltIn
#undef GlobalBuiltInConstructor
#endif

}
#endif // ENABLE_INTL_OBJECT || ENABLE_JS_BUILTINS || ENABLE_PROJECTION
60 changes: 6 additions & 54 deletions lib/Runtime/Library/EngineInterfaceObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,71 +91,23 @@ namespace Js
class EntryInfo
{
public:
static NoProfileFunctionInfo GetErrorMessage;
static NoProfileFunctionInfo LogDebugMessage;
static NoProfileFunctionInfo TagPublicLibraryCode;
static NoProfileFunctionInfo SetPrototype;
static NoProfileFunctionInfo GetArrayLength;
static NoProfileFunctionInfo RegexMatch;
// CallInstanceFunction is still handled specially because it gets special inline treatment from the JIT
static FunctionInfo CallInstanceFunction;

#ifndef GlobalBuiltIn
#define GlobalBuiltIn(global, method) \
static NoProfileFunctionInfo BuiltIn_##global##_##method##; \

#define GlobalBuiltInConstructor(global)

#define BuiltInRaiseException(exceptionType, exceptionID) \
static NoProfileFunctionInfo BuiltIn_raise##exceptionID;

#define BuiltInRaiseException1(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID)
#define BuiltInRaiseException2(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID)
#define BuiltInRaiseException3(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID##_3)

#define BuiltInRaiseException(exceptionType, exceptionID) static NoProfileFunctionInfo BuiltIn_raise##exceptionID;
#define EngineInterfaceBuiltIn2(propId, nativeMethod) static NoProfileFunctionInfo nativeMethod;
#include "EngineInterfaceObjectBuiltIns.h"

#undef BuiltInRaiseException
#undef BuiltInRaiseException1
#undef BuiltInRaiseException2
#undef BuiltInRaiseException3
#undef GlobalBuiltInConstructor
#undef GlobalBuiltIn
#endif
};

static Var Entry_GetErrorMessage(RecyclableObject *function, CallInfo callInfo, ...);
static Var Entry_LogDebugMessage(RecyclableObject *function, CallInfo callInfo, ...);
static Var Entry_TagPublicLibraryCode(RecyclableObject *function, CallInfo callInfo, ...);
static Var Entry_SetPrototype(RecyclableObject *function, CallInfo callInfo, ...);
static Var Entry_GetArrayLength(RecyclableObject *function, CallInfo callInfo, ...);
static Var Entry_RegexMatch(RecyclableObject *function, CallInfo callInfo, ...);
static Var Entry_CallInstanceFunction(RecyclableObject *function, CallInfo callInfo, ...);

#ifdef ENABLE_PROJECTION
static Var EntryPromise_EnqueueTask(RecyclableObject *function, CallInfo callInfo, ...);
#endif

#ifndef GlobalBuiltIn
#define GlobalBuiltIn(global, method)

#define GlobalBuiltInConstructor(global)

#define BuiltInRaiseException(exceptionType, exceptionID) \
static Var Entry_BuiltIn_raise##exceptionID(RecyclableObject *function, CallInfo callInfo, ...);

#define BuiltInRaiseException1(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID)
#define BuiltInRaiseException2(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID)
#define BuiltInRaiseException3(exceptionType, exceptionID) BuiltInRaiseException(exceptionType, exceptionID##_3)

#define BuiltInRaiseException(exceptionType, exceptionID) static Var Entry_BuiltIn_raise##exceptionID(RecyclableObject *function, CallInfo callInfo, ...);
#define EngineInterfaceBuiltIn2(propId, nativeMethod) static Var Entry_##nativeMethod(RecyclableObject *function, CallInfo callInfo, ...);
#include "EngineInterfaceObjectBuiltIns.h"

#undef BuiltInRaiseException
#undef BuiltInRaiseException1
#undef BuiltInRaiseException2
#undef BuiltInRaiseException3
#undef GlobalBuiltInConstructor
#undef GlobalBuiltIn
#endif

};
}

Expand Down
Loading

0 comments on commit 172fbd8

Please sign in to comment.