Changeset 270870 in webkit for trunk/Source/JavaScriptCore/bytecompiler
- Timestamp:
- Dec 15, 2020, 3:18:33 PM (4 years ago)
- Location:
- trunk/Source/JavaScriptCore/bytecompiler
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
r269939 r270870 290 290 } 291 291 292 BytecodeGenerator::BytecodeGenerator(VM& vm, ProgramNode* programNode, UnlinkedProgramCodeBlock* codeBlock, OptionSet<CodeGenerationMode> codeGenerationMode, const CachedTDZStack& parentScopeTDZVariables, ECMAMode ecmaMode)292 BytecodeGenerator::BytecodeGenerator(VM& vm, ProgramNode* programNode, UnlinkedProgramCodeBlock* codeBlock, OptionSet<CodeGenerationMode> codeGenerationMode, const RefPtr<TDZEnvironmentLink>& parentScopeTDZVariables, ECMAMode ecmaMode) 293 293 : BytecodeGeneratorBase(makeUnique<UnlinkedCodeBlockGenerator>(vm, codeBlock), CodeBlock::llintBaselineCalleeSaveSpaceAsVirtualRegisters()) 294 294 , m_codeGenerationMode(codeGenerationMode) … … 305 305 , m_ecmaMode(ecmaMode) 306 306 { 307 ASSERT_UNUSED(parentScopeTDZVariables, !parentScopeTDZVariables .size());307 ASSERT_UNUSED(parentScopeTDZVariables, !parentScopeTDZVariables); 308 308 309 309 m_codeBlock->setNumParameters(1); // Allocate space for "this" … … 337 337 } 338 338 339 BytecodeGenerator::BytecodeGenerator(VM& vm, FunctionNode* functionNode, UnlinkedFunctionCodeBlock* codeBlock, OptionSet<CodeGenerationMode> codeGenerationMode, const CachedTDZStack& parentScopeTDZVariables, ECMAMode ecmaMode)339 BytecodeGenerator::BytecodeGenerator(VM& vm, FunctionNode* functionNode, UnlinkedFunctionCodeBlock* codeBlock, OptionSet<CodeGenerationMode> codeGenerationMode, const RefPtr<TDZEnvironmentLink>& parentScopeTDZVariables, ECMAMode ecmaMode) 340 340 : BytecodeGeneratorBase(makeUnique<UnlinkedCodeBlockGenerator>(vm, codeBlock), CodeBlock::llintBaselineCalleeSaveSpaceAsVirtualRegisters()) 341 341 , m_codeGenerationMode(codeGenerationMode) … … 364 364 int symbolTableConstantIndex = 0; 365 365 366 m_parentScopeTDZStackSize = parentScopeTDZVariables.size(); 367 m_cachedVariablesUnderTDZ = parentScopeTDZVariables; 366 m_cachedParentTDZ = parentScopeTDZVariables; 368 367 369 368 FunctionParameters& parameters = *functionNode->parameters(); … … 840 839 } 841 840 842 BytecodeGenerator::BytecodeGenerator(VM& vm, EvalNode* evalNode, UnlinkedEvalCodeBlock* codeBlock, OptionSet<CodeGenerationMode> codeGenerationMode, const CachedTDZStack& parentScopeTDZVariables, ECMAMode ecmaMode)841 BytecodeGenerator::BytecodeGenerator(VM& vm, EvalNode* evalNode, UnlinkedEvalCodeBlock* codeBlock, OptionSet<CodeGenerationMode> codeGenerationMode, const RefPtr<TDZEnvironmentLink>& parentScopeTDZVariables, ECMAMode ecmaMode) 843 842 : BytecodeGeneratorBase(makeUnique<UnlinkedCodeBlockGenerator>(vm, codeBlock), CodeBlock::llintBaselineCalleeSaveSpaceAsVirtualRegisters()) 844 843 , m_codeGenerationMode(codeGenerationMode) … … 858 857 m_codeBlock->setNumParameters(1); 859 858 860 m_parentScopeTDZStackSize = parentScopeTDZVariables.size(); 861 m_cachedVariablesUnderTDZ = parentScopeTDZVariables; 859 m_cachedParentTDZ = parentScopeTDZVariables; 862 860 863 861 emitEnter(); … … 904 902 } 905 903 906 BytecodeGenerator::BytecodeGenerator(VM& vm, ModuleProgramNode* moduleProgramNode, UnlinkedModuleProgramCodeBlock* codeBlock, OptionSet<CodeGenerationMode> codeGenerationMode, const CachedTDZStack& parentScopeTDZVariables, ECMAMode ecmaMode)904 BytecodeGenerator::BytecodeGenerator(VM& vm, ModuleProgramNode* moduleProgramNode, UnlinkedModuleProgramCodeBlock* codeBlock, OptionSet<CodeGenerationMode> codeGenerationMode, const RefPtr<TDZEnvironmentLink>& parentScopeTDZVariables, ECMAMode ecmaMode) 907 905 : BytecodeGeneratorBase(makeUnique<UnlinkedCodeBlockGenerator>(vm, codeBlock), CodeBlock::llintBaselineCalleeSaveSpaceAsVirtualRegisters()) 908 906 , m_codeGenerationMode(codeGenerationMode) … … 919 917 , m_ecmaMode(ecmaMode) 920 918 { 921 ASSERT_UNUSED(parentScopeTDZVariables, !parentScopeTDZVariables .size());919 ASSERT_UNUSED(parentScopeTDZVariables, !parentScopeTDZVariables); 922 920 923 921 SymbolTable* moduleEnvironmentSymbolTable = SymbolTable::create(m_vm); … … 2169 2167 2170 2168 m_TDZStack.removeLast(); 2171 m_cachedVariablesUnderTDZ.removeLast();2172 2169 } 2173 2170 … … 2851 2848 { 2852 2849 for (unsigned i = m_TDZStack.size(); i--;) { 2853 auto iter = m_TDZStack[i].fi nd(variable.ident().impl());2854 if (iter == m_TDZStack[i]. end())2850 auto iter = m_TDZStack[i].first.find(variable.ident().impl()); 2851 if (iter == m_TDZStack[i].first.end()) 2855 2852 continue; 2856 2853 return iter->value != TDZNecessityLevel::NotNeeded; 2857 2854 } 2858 2855 2859 for (unsigned i = m_parentScopeTDZStackSize; i--;) { 2860 if (m_cachedVariablesUnderTDZ[i].environment().toTDZEnvironment().contains(variable.ident().impl())) 2861 return true; 2862 } 2863 2856 { 2857 TDZEnvironmentLink* environment = m_cachedParentTDZ.get(); 2858 while (environment) { 2859 if (environment->contains(variable.ident().impl())) 2860 return true; 2861 environment = environment->parent(); 2862 } 2863 } 2864 2864 return false; 2865 2865 } … … 2882 2882 RefPtr<UniquedStringImpl> identifier(variable.ident().impl()); 2883 2883 for (unsigned i = m_TDZStack.size(); i--;) { 2884 auto iter = m_TDZStack[i].fi nd(identifier);2885 if (iter != m_TDZStack[i]. end()) {2884 auto iter = m_TDZStack[i].first.find(identifier); 2885 if (iter != m_TDZStack[i].first.end()) { 2886 2886 if (iter->value == TDZNecessityLevel::Optimize) 2887 2887 iter->value = TDZNecessityLevel::NotNeeded; … … 2909 2909 map.add(entry.key, entry.value.isFunction() ? TDZNecessityLevel::NotNeeded : level); 2910 2910 2911 m_TDZStack.append(WTFMove(map)); 2912 m_cachedVariablesUnderTDZ.append({ }); 2913 } 2914 2915 Optional<BytecodeGenerator::CachedTDZStack> BytecodeGenerator::getVariablesUnderTDZ() 2916 { 2911 m_TDZStack.append(TDZStackEntry { WTFMove(map), nullptr }); 2912 } 2913 2914 RefPtr<TDZEnvironmentLink> BytecodeGenerator::getVariablesUnderTDZ() 2915 { 2916 RefPtr<TDZEnvironmentLink> parent = m_cachedParentTDZ; 2917 if (!m_TDZStack.size()) 2918 return parent; 2919 2917 2920 auto assertCacheIsCoherent = [&] { 2918 2921 #if ASSERT_ENABLED 2919 for (size_t i = 0; i < m_cachedVariablesUnderTDZ.size(); ++i) 2920 ASSERT(!!m_cachedVariablesUnderTDZ[i]); 2922 TDZEnvironmentLink* parent = m_cachedParentTDZ.get(); 2923 for (auto& entry : m_TDZStack) { 2924 ASSERT(entry.second); 2925 ASSERT(entry.second->parent() == parent); 2926 parent = entry.second.get(); 2927 } 2921 2928 #endif 2922 2929 }; 2923 2930 2924 RELEASE_ASSERT(m_TDZStack.size() + m_parentScopeTDZStackSize == m_cachedVariablesUnderTDZ.size()); 2925 2926 if (m_cachedVariablesUnderTDZ.isEmpty()) 2927 return WTF::nullopt; 2928 2929 if (m_cachedVariablesUnderTDZ.last()) { 2931 if (m_TDZStack.last().second) { 2930 2932 assertCacheIsCoherent(); 2931 return m_ cachedVariablesUnderTDZ;2932 } 2933 2934 for ( size_t i = m_TDZStack.size(); i--;) {2935 if ( m_cachedVariablesUnderTDZ[i + m_parentScopeTDZStackSize])2936 break;2937 2938 auto& map = m_TDZStack[i];2939 TDZEnvironment environment;2940 for (auto& entry : map) {2941 if (entry.value != TDZNecessityLevel::NotNeeded)2942 environment.add(entry.key.get());2943 } 2944 m_cachedVariablesUnderTDZ[i + m_parentScopeTDZStackSize] = m_vm.m_compactVariableMap->get(environment);2933 return m_TDZStack.last().second; 2934 } 2935 2936 for (auto& entry : m_TDZStack) { 2937 if (!entry.second) { 2938 auto& map = entry.first; 2939 TDZEnvironment environment; 2940 for (auto& entry : map) { 2941 if (entry.value != TDZNecessityLevel::NotNeeded) 2942 environment.add(entry.key.get()); 2943 } 2944 entry.second = TDZEnvironmentLink::create(m_vm.m_compactVariableMap->get(environment), parent); 2945 } 2946 parent = entry.second; 2945 2947 } 2946 2948 2947 2949 assertCacheIsCoherent(); 2948 return m_cachedVariablesUnderTDZ; 2950 2951 return parent; 2949 2952 } 2950 2953 … … 2952 2955 { 2953 2956 preservedStack.m_preservedTDZStack = m_TDZStack; 2954 preservedStack.m_cachedTDZStack = m_cachedVariablesUnderTDZ;2955 2957 } 2956 2958 … … 2958 2960 { 2959 2961 m_TDZStack = preservedStack.m_preservedTDZStack; 2960 m_cachedVariablesUnderTDZ = preservedStack.m_cachedTDZStack;2961 2962 } 2962 2963 -
trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h
r269922 r270870 408 408 public: 409 409 typedef DeclarationStacks::FunctionStack FunctionStack; 410 using CachedTDZStack = Vector<CompactTDZEnvironmentMap::Handle>; 411 412 BytecodeGenerator(VM&, ProgramNode*, UnlinkedProgramCodeBlock*, OptionSet<CodeGenerationMode>, const CachedTDZStack&, ECMAMode); 413 BytecodeGenerator(VM&, FunctionNode*, UnlinkedFunctionCodeBlock*, OptionSet<CodeGenerationMode>, const CachedTDZStack&, ECMAMode); 414 BytecodeGenerator(VM&, EvalNode*, UnlinkedEvalCodeBlock*, OptionSet<CodeGenerationMode>, const CachedTDZStack&, ECMAMode); 415 BytecodeGenerator(VM&, ModuleProgramNode*, UnlinkedModuleProgramCodeBlock*, OptionSet<CodeGenerationMode>, const CachedTDZStack&, ECMAMode); 410 411 BytecodeGenerator(VM&, ProgramNode*, UnlinkedProgramCodeBlock*, OptionSet<CodeGenerationMode>, const RefPtr<TDZEnvironmentLink>&, ECMAMode); 412 BytecodeGenerator(VM&, FunctionNode*, UnlinkedFunctionCodeBlock*, OptionSet<CodeGenerationMode>, const RefPtr<TDZEnvironmentLink>&, ECMAMode); 413 BytecodeGenerator(VM&, EvalNode*, UnlinkedEvalCodeBlock*, OptionSet<CodeGenerationMode>, const RefPtr<TDZEnvironmentLink>&, ECMAMode); 414 BytecodeGenerator(VM&, ModuleProgramNode*, UnlinkedModuleProgramCodeBlock*, OptionSet<CodeGenerationMode>, const RefPtr<TDZEnvironmentLink>&, ECMAMode); 416 415 417 416 ~BytecodeGenerator(); … … 433 432 434 433 template<typename Node, typename UnlinkedCodeBlock> 435 static ParserError generate(VM& vm, Node* node, const SourceCode& sourceCode, UnlinkedCodeBlock* unlinkedCodeBlock, OptionSet<CodeGenerationMode> codeGenerationMode, const CachedTDZStack& parentScopeTDZVariables, ECMAMode ecmaMode)434 static ParserError generate(VM& vm, Node* node, const SourceCode& sourceCode, UnlinkedCodeBlock* unlinkedCodeBlock, OptionSet<CodeGenerationMode> codeGenerationMode, const RefPtr<TDZEnvironmentLink>& parentScopeTDZVariables, ECMAMode ecmaMode) 436 435 { 437 436 MonotonicTime before; … … 1199 1198 } 1200 1199 1201 Optional<CachedTDZStack> getVariablesUnderTDZ();1200 RefPtr<TDZEnvironmentLink> getVariablesUnderTDZ(); 1202 1201 1203 1202 RegisterID* emitConstructVarargs(RegisterID* dst, RegisterID* func, RegisterID* thisRegister, RegisterID* arguments, RegisterID* firstFreeRegister, int32_t firstVarArgOffset, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd, DebuggableCall); … … 1230 1229 RegisterID* emitThrowExpressionTooDeepException(); 1231 1230 1231 using TDZStackEntry = std::pair<TDZMap, RefPtr<TDZEnvironmentLink>>; 1232 1232 1233 class PreservedTDZStack { 1233 1234 private: 1234 Vector<TDZMap> m_preservedTDZStack; 1235 CachedTDZStack m_cachedTDZStack; 1235 Vector<TDZStackEntry> m_preservedTDZStack; 1236 1236 friend class BytecodeGenerator; 1237 1237 }; … … 1265 1265 Vector<LexicalScopeStackEntry> m_lexicalScopeStack; 1266 1266 1267 size_t m_parentScopeTDZStackSize { 0 }; 1268 Vector<TDZMap> m_TDZStack; 1269 CachedTDZStack m_cachedVariablesUnderTDZ; 1267 RefPtr<TDZEnvironmentLink> m_cachedParentTDZ; 1268 Vector<TDZStackEntry> m_TDZStack; 1270 1269 Optional<size_t> m_varScopeLexicalScopeStackIndex; 1271 1270 void pushTDZVariables(const VariableEnvironment&, TDZCheckOptimization, TDZRequirement);
Note:
See TracChangeset
for help on using the changeset viewer.