Changeset 231889 in webkit
- Timestamp:
- May 16, 2018 10:21:41 PM (6 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r231888 r231889 1 2018-05-16 Saam Barati <sbarati@apple.com> 2 3 UnlinkedFunctionExecutable doesn't need a parent source override field since it's only used for default class constructors 4 https://bugs.webkit.org/show_bug.cgi?id=185637 5 6 Reviewed by Keith Miller. 7 8 We had this general mechanism for overriding an UnlinkedFunctionExecutable's parent 9 source code. However, we were only using this for default class constructors. There 10 are only two types of default class constructors. This patch makes it so that 11 we just store this information inside of a single bit, and ask for the source 12 code as needed instead of holding it in a nullable field that is 24 bytes in size. 13 14 This brings UnlinkedFunctionExecutable's size down from 184 bytes to 160 bytes. 15 This has the consequence of making it allocated out of a 160 byte size class 16 instead of a 224 byte size class. This should bring down its memory footprint 17 by ~40%. 18 19 * builtins/BuiltinExecutables.cpp: 20 (JSC::BuiltinExecutables::defaultConstructorSourceCode): 21 (JSC::BuiltinExecutables::createDefaultConstructor): 22 (JSC::BuiltinExecutables::createExecutable): 23 * builtins/BuiltinExecutables.h: 24 * bytecode/UnlinkedFunctionExecutable.cpp: 25 (JSC::UnlinkedFunctionExecutable::UnlinkedFunctionExecutable): 26 (JSC::UnlinkedFunctionExecutable::link): 27 * bytecode/UnlinkedFunctionExecutable.h: 28 * runtime/CodeCache.cpp: 29 (JSC::CodeCache::getUnlinkedGlobalFunctionExecutable): 30 1 31 2018-05-16 Saam Barati <sbarati@apple.com> 2 32 -
trunk/Source/JavaScriptCore/builtins/BuiltinExecutables.cpp
r230105 r231889 1 1 /* 2 * Copyright (C) 2014-201 7Apple Inc. All rights reserved.2 * Copyright (C) 2014-2018 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 43 43 } 44 44 45 const SourceCode& BuiltinExecutables::defaultConstructorSourceCode(ConstructorKind constructorKind) 46 { 47 switch (constructorKind) { 48 case ConstructorKind::None: 49 RELEASE_ASSERT_NOT_REACHED(); 50 case ConstructorKind::Base: { 51 static NeverDestroyed<const String> baseConstructorCode(MAKE_STATIC_STRING_IMPL("(function () { })")); 52 static LazyNeverDestroyed<SourceCode> result; 53 static std::once_flag onceFlag; 54 std::call_once(onceFlag, [&] { 55 result.construct(makeSource(baseConstructorCode, { })); 56 }); 57 return result; 58 } 59 case ConstructorKind::Extends: { 60 static NeverDestroyed<const String> derivedConstructorCode(MAKE_STATIC_STRING_IMPL("(function (...args) { super(...args); })")); 61 static LazyNeverDestroyed<SourceCode> result; 62 static std::once_flag onceFlag; 63 std::call_once(onceFlag, [&] { 64 result.construct(makeSource(derivedConstructorCode, { })); 65 }); 66 return result; 67 } 68 } 69 } 70 45 71 UnlinkedFunctionExecutable* BuiltinExecutables::createDefaultConstructor(ConstructorKind constructorKind, const Identifier& name) 46 72 { 47 static NeverDestroyed<const String> baseConstructorCode(MAKE_STATIC_STRING_IMPL("(function () { })"));48 static NeverDestroyed<const String> derivedConstructorCode(MAKE_STATIC_STRING_IMPL("(function (...args) { super(...args); })"));49 73 50 74 switch (constructorKind) { … … 52 76 break; 53 77 case ConstructorKind::Base: 54 return createExecutable(m_vm, makeSource(baseConstructorCode, { }), name, constructorKind, ConstructAbility::CanConstruct);55 78 case ConstructorKind::Extends: 56 return createExecutable(m_vm, makeSource(derivedConstructorCode, { }), name, constructorKind, ConstructAbility::CanConstruct);79 return createExecutable(m_vm, defaultConstructorSourceCode(constructorKind), name, constructorKind, ConstructAbility::CanConstruct); 57 80 } 58 81 ASSERT_NOT_REACHED(); … … 74 97 JSTextPosition positionBeforeLastNewline; 75 98 ParserError error; 76 bool isParsingDefaultConstructor = constructorKind != ConstructorKind::None; 77 JSParserBuiltinMode builtinMode = isParsingDefaultConstructor ? JSParserBuiltinMode::NotBuiltin : JSParserBuiltinMode::Builtin; 78 UnlinkedFunctionKind kind = isParsingDefaultConstructor ? UnlinkedNormalFunction : UnlinkedBuiltinFunction; 79 SourceCode parentSourceOverride = isParsingDefaultConstructor ? source : SourceCode(); 99 bool isBuiltinDefaultClassConstructor = constructorKind != ConstructorKind::None; 100 JSParserBuiltinMode builtinMode = isBuiltinDefaultClassConstructor ? JSParserBuiltinMode::NotBuiltin : JSParserBuiltinMode::Builtin; 101 UnlinkedFunctionKind kind = isBuiltinDefaultClassConstructor ? UnlinkedNormalFunction : UnlinkedBuiltinFunction; 80 102 std::unique_ptr<ProgramNode> program = parse<ProgramNode>( 81 103 &vm, source, Identifier(), builtinMode, … … 106 128 metadata->overrideName(name); 107 129 VariableEnvironment dummyTDZVariables; 108 UnlinkedFunctionExecutable* functionExecutable = UnlinkedFunctionExecutable::create(&vm, source, metadata, kind, constructAbility, JSParserScriptMode::Classic, dummyTDZVariables, DerivedContextType::None, WTFMove(parentSourceOverride));130 UnlinkedFunctionExecutable* functionExecutable = UnlinkedFunctionExecutable::create(&vm, source, metadata, kind, constructAbility, JSParserScriptMode::Classic, dummyTDZVariables, DerivedContextType::None, isBuiltinDefaultClassConstructor); 109 131 return functionExecutable; 110 132 } -
trunk/Source/JavaScriptCore/builtins/BuiltinExecutables.h
r230105 r231889 1 1 /* 2 * Copyright (C) 2014 Apple Inc. All rights reserved.2 * Copyright (C) 2014-2018 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 50 50 #undef EXPOSE_BUILTIN_SOURCES 51 51 52 static const SourceCode& defaultConstructorSourceCode(ConstructorKind); 52 53 UnlinkedFunctionExecutable* createDefaultConstructor(ConstructorKind, const Identifier& name); 53 54 -
trunk/Source/JavaScriptCore/bytecode/UnlinkedFunctionExecutable.cpp
r231477 r231889 1 1 /* 2 * Copyright (C) 2012-201 3, 2015-2016Apple Inc. All Rights Reserved.2 * Copyright (C) 2012-2018 Apple Inc. All Rights Reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 27 27 #include "UnlinkedFunctionExecutable.h" 28 28 29 #include "BuiltinExecutables.h" 29 30 #include "BytecodeGenerator.h" 30 31 #include "ClassInfo.h" … … 41 42 namespace JSC { 42 43 43 static_assert(sizeof(UnlinkedFunctionExecutable) <= 256, "UnlinkedFunctionExecutable should fit in a 256-byte cell.");44 static_assert(sizeof(UnlinkedFunctionExecutable) <= 160, "UnlinkedFunctionExecutable should fit in a 160-byte cell. If you increase the size of this class, consider making a size class that perfectly fits it."); 44 45 45 46 const ClassInfo UnlinkedFunctionExecutable::s_info = { "UnlinkedFunctionExecutable", nullptr, nullptr, nullptr, CREATE_METHOD_TABLE(UnlinkedFunctionExecutable) }; … … 77 78 } 78 79 79 UnlinkedFunctionExecutable::UnlinkedFunctionExecutable(VM* vm, Structure* structure, const SourceCode& parentSource, SourceCode&& parentSourceOverride, FunctionMetadataNode* node, UnlinkedFunctionKind kind, ConstructAbility constructAbility, JSParserScriptMode scriptMode, VariableEnvironment& parentScopeTDZVariables, DerivedContextType derivedContextType)80 UnlinkedFunctionExecutable::UnlinkedFunctionExecutable(VM* vm, Structure* structure, const SourceCode& parentSource, FunctionMetadataNode* node, UnlinkedFunctionKind kind, ConstructAbility constructAbility, JSParserScriptMode scriptMode, VariableEnvironment& parentScopeTDZVariables, DerivedContextType derivedContextType, bool isBuiltinDefaultClassConstructor) 80 81 : Base(*vm, structure) 81 82 , m_firstLineOffset(node->firstLine() - parentSource.firstLine().oneBasedInt()) … … 95 96 , m_hasCapturedVariables(false) 96 97 , m_isBuiltinFunction(kind == UnlinkedBuiltinFunction) 98 , m_isBuiltinDefaultClassConstructor(isBuiltinDefaultClassConstructor) 97 99 , m_constructAbility(static_cast<unsigned>(constructAbility)) 98 100 , m_constructorKind(static_cast<unsigned>(node->constructorKind())) … … 104 106 , m_ecmaName(node->ecmaName()) 105 107 , m_inferredName(node->inferredName()) 106 , m_parentSourceOverride(WTFMove(parentSourceOverride))107 108 , m_classSource(node->classSource()) 108 109 , m_parentScopeTDZVariables(vm->m_compactVariableMap->get(parentScopeTDZVariables)) … … 115 116 ASSERT(m_superBinding == static_cast<unsigned>(node->superBinding())); 116 117 ASSERT(m_derivedContextType == static_cast<unsigned>(derivedContextType)); 118 ASSERT(!(m_isBuiltinDefaultClassConstructor && constructorKind() == ConstructorKind::None)); 117 119 } 118 120 … … 133 135 FunctionExecutable* UnlinkedFunctionExecutable::link(VM& vm, const SourceCode& passedParentSource, std::optional<int> overrideLineNumber, Intrinsic intrinsic) 134 136 { 135 const SourceCode& parentSource = m_parentSourceOverride.isNull() ? passedParentSource : m_parentSourceOverride;137 const SourceCode& parentSource = !m_isBuiltinDefaultClassConstructor ? passedParentSource : BuiltinExecutables::defaultConstructorSourceCode(constructorKind()); 136 138 unsigned firstLine = parentSource.firstLine().oneBasedInt() + m_firstLineOffset; 137 139 unsigned startOffset = parentSource.startOffset() + m_startOffset; -
trunk/Source/JavaScriptCore/bytecode/UnlinkedFunctionExecutable.h
r231477 r231889 1 1 /* 2 * Copyright (C) 2012-201 6Apple Inc. All Rights Reserved.2 * Copyright (C) 2012-2018 Apple Inc. All Rights Reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 59 59 static const unsigned StructureFlags = Base::StructureFlags | StructureIsImmortal; 60 60 61 static UnlinkedFunctionExecutable* create(VM* vm, const SourceCode& source, FunctionMetadataNode* node, UnlinkedFunctionKind unlinkedFunctionKind, ConstructAbility constructAbility, JSParserScriptMode scriptMode, VariableEnvironment& parentScopeTDZVariables, DerivedContextType derivedContextType, SourceCode&& parentSourceOverride = SourceCode())61 static UnlinkedFunctionExecutable* create(VM* vm, const SourceCode& source, FunctionMetadataNode* node, UnlinkedFunctionKind unlinkedFunctionKind, ConstructAbility constructAbility, JSParserScriptMode scriptMode, VariableEnvironment& parentScopeTDZVariables, DerivedContextType derivedContextType, bool isBuiltinDefaultClassConstructor = false) 62 62 { 63 63 UnlinkedFunctionExecutable* instance = new (NotNull, allocateCell<UnlinkedFunctionExecutable>(vm->heap)) 64 UnlinkedFunctionExecutable(vm, vm->unlinkedFunctionExecutableStructure.get(), source, WTFMove(parentSourceOverride), node, unlinkedFunctionKind, constructAbility, scriptMode, parentScopeTDZVariables, derivedContextType);64 UnlinkedFunctionExecutable(vm, vm->unlinkedFunctionExecutableStructure.get(), source, node, unlinkedFunctionKind, constructAbility, scriptMode, parentScopeTDZVariables, derivedContextType, isBuiltinDefaultClassConstructor); 65 65 instance->finishCreation(*vm); 66 66 return instance; … … 140 140 141 141 private: 142 UnlinkedFunctionExecutable(VM*, Structure*, const SourceCode&, SourceCode&& parentSourceOverride, FunctionMetadataNode*, UnlinkedFunctionKind, ConstructAbility, JSParserScriptMode, VariableEnvironment&, JSC::DerivedContextType);142 UnlinkedFunctionExecutable(VM*, Structure*, const SourceCode&, FunctionMetadataNode*, UnlinkedFunctionKind, ConstructAbility, JSParserScriptMode, VariableEnvironment&, JSC::DerivedContextType, bool isBuiltinDefaultClassConstructor); 143 143 144 144 unsigned m_firstLineOffset; … … 158 158 unsigned m_hasCapturedVariables : 1; 159 159 unsigned m_isBuiltinFunction : 1; 160 unsigned m_isBuiltinDefaultClassConstructor : 1; 160 161 unsigned m_constructAbility: 1; 161 162 unsigned m_constructorKind : 2; … … 171 172 Identifier m_ecmaName; 172 173 Identifier m_inferredName; 173 SourceCode m_parentSourceOverride;174 174 SourceCode m_classSource; 175 175 -
trunk/Source/JavaScriptCore/runtime/CodeCache.cpp
r231018 r231889 151 151 metadata->overrideName(name); 152 152 metadata->setEndPosition(positionBeforeLastNewline); 153 // The Function constructor only has access to global variables, so no variables will be under TDZ. 153 // The Function constructor only has access to global variables, so no variables will be under TDZ unless they're 154 // in the global lexical environment, which we always TDZ check accesses from. 154 155 VariableEnvironment emptyTDZVariables; 155 156 ConstructAbility constructAbility = constructAbilityForParseMode(metadata->parseMode());
Note: See TracChangeset
for help on using the changeset viewer.