Changeset 244300 in webkit
- Timestamp:
- Apr 15, 2019 3:23:38 PM (5 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r244298 r244300 1 2019-04-15 Tadeu Zagallo <tzagallo@apple.com> 2 3 Bytecode cache should not encode the SourceProvider for UnlinkedFunctionExecutable's classSource 4 https://bugs.webkit.org/show_bug.cgi?id=196878 5 6 Reviewed by Saam Barati. 7 8 Every time we encode an (Unlinked)SourceCode, we encode its SourceProvider, 9 including the full source if it's a StringSourceProvider. This wasn't an issue, 10 since the SourceCode contains a RefPtr to the SourceProvider, and the Encoder 11 would avoid encoding the provider multiple times. With the addition of the 12 incremental cache, each UnlinkedFunctionCodeBlock is encoded in isolation, which 13 means we can no longer deduplicate it and the full program text was being encoded 14 multiple times in the cache. 15 As a work around, this patch adds a custom cached type for encoding the SourceCode 16 without its provider, and later injects the SourceProvider through the Decoder. 17 18 * parser/SourceCode.h: 19 * parser/UnlinkedSourceCode.h: 20 (JSC::UnlinkedSourceCode::provider const): 21 * runtime/CachedTypes.cpp: 22 (JSC::Decoder::Decoder): 23 (JSC::Decoder::create): 24 (JSC::Decoder::provider const): 25 (JSC::CachedSourceCodeWithoutProvider::encode): 26 (JSC::CachedSourceCodeWithoutProvider::decode const): 27 (JSC::decodeCodeBlockImpl): 28 * runtime/CachedTypes.h: 29 1 30 2019-04-15 Robin Morisset <rmorisset@apple.com> 2 31 -
trunk/Source/JavaScriptCore/parser/SourceCode.h
r240255 r244300 35 35 class SourceCode : public UnlinkedSourceCode { 36 36 friend class CachedSourceCode; 37 friend class CachedSourceCodeWithoutProvider; 37 38 38 39 public: -
trunk/Source/JavaScriptCore/parser/UnlinkedSourceCode.h
r243163 r244300 37 37 template<typename SourceType> 38 38 friend class CachedUnlinkedSourceCodeShape; 39 friend class CachedSourceCodeWithoutProvider; 39 40 40 41 public: … … 74 75 bool isHashTableDeletedValue() const { return m_provider.isHashTableDeletedValue(); } 75 76 76 constSourceProvider& provider() const77 SourceProvider& provider() const 77 78 { 78 79 return *m_provider; -
trunk/Source/JavaScriptCore/runtime/CachedTypes.cpp
r244163 r244300 221 221 }; 222 222 223 Decoder::Decoder(VM& vm, Ref<CachedBytecode> cachedBytecode )223 Decoder::Decoder(VM& vm, Ref<CachedBytecode> cachedBytecode, RefPtr<SourceProvider> provider) 224 224 : m_vm(vm) 225 225 , m_cachedBytecode(WTFMove(cachedBytecode)) 226 , m_provider(provider) 226 227 { 227 228 } … … 233 234 } 234 235 235 Ref<Decoder> Decoder::create(VM& vm, Ref<CachedBytecode> cachedBytecode )236 { 237 return adoptRef(*new Decoder(vm, WTFMove(cachedBytecode) ));236 Ref<Decoder> Decoder::create(VM& vm, Ref<CachedBytecode> cachedBytecode, RefPtr<SourceProvider> provider) 237 { 238 return adoptRef(*new Decoder(vm, WTFMove(cachedBytecode), WTFMove(provider))); 238 239 } 239 240 … … 293 294 { 294 295 m_finalizers.append(fn); 296 } 297 298 RefPtr<SourceProvider> Decoder::provider() const 299 { 300 return m_provider; 295 301 } 296 302 … … 1548 1554 }; 1549 1555 1556 class CachedSourceCodeWithoutProvider : public CachedObject<SourceCode> { 1557 public: 1558 void encode(Encoder&, const SourceCode& sourceCode) 1559 { 1560 m_hasProvider = !!sourceCode.provider(); 1561 m_startOffset = sourceCode.startOffset(); 1562 m_endOffset = sourceCode.endOffset(); 1563 m_firstLine = sourceCode.firstLine().zeroBasedInt(); 1564 m_startColumn = sourceCode.startColumn().zeroBasedInt(); 1565 } 1566 1567 void decode(Decoder& decoder, SourceCode& sourceCode) const 1568 { 1569 if (m_hasProvider) 1570 sourceCode.m_provider = decoder.provider(); 1571 sourceCode.m_startOffset = m_startOffset; 1572 sourceCode.m_endOffset = m_endOffset; 1573 sourceCode.m_firstLine = OrdinalNumber::fromZeroBasedInt(m_firstLine); 1574 sourceCode.m_startColumn = OrdinalNumber::fromZeroBasedInt(m_startColumn); 1575 } 1576 1577 private: 1578 bool m_hasProvider; 1579 int m_startOffset; 1580 int m_endOffset; 1581 int m_firstLine; 1582 int m_startColumn; 1583 }; 1584 1550 1585 class CachedFunctionExecutableRareData : public CachedObject<UnlinkedFunctionExecutable::RareData> { 1551 1586 public: … … 1566 1601 1567 1602 private: 1568 CachedSourceCode m_classSource;1603 CachedSourceCodeWithoutProvider m_classSource; 1569 1604 CachedCompactVariableMapHandle m_parentScopeTDZVariables; 1570 1605 }; … … 2298 2333 { 2299 2334 const auto* cachedEntry = bitwise_cast<const GenericCacheEntry*>(cachedBytecode->data()); 2300 Ref<Decoder> decoder = Decoder::create(vm, WTFMove(cachedBytecode) );2335 Ref<Decoder> decoder = Decoder::create(vm, WTFMove(cachedBytecode), &key.source().provider()); 2301 2336 std::pair<SourceCodeKey, UnlinkedCodeBlock*> entry; 2302 2337 { -
trunk/Source/JavaScriptCore/runtime/CachedTypes.h
r244143 r244300 78 78 79 79 public: 80 static Ref<Decoder> create(VM&, Ref<CachedBytecode> );80 static Ref<Decoder> create(VM&, Ref<CachedBytecode>, RefPtr<SourceProvider> = nullptr); 81 81 82 82 ~Decoder(); … … 92 92 void setHandleForEnvironment(CompactVariableEnvironment*, const CompactVariableMap::Handle&); 93 93 void addLeafExecutable(const UnlinkedFunctionExecutable*, ptrdiff_t); 94 RefPtr<SourceProvider> provider() const; 94 95 95 96 template<typename Functor> … … 97 98 98 99 private: 99 Decoder(VM&, Ref<CachedBytecode> );100 Decoder(VM&, Ref<CachedBytecode>, RefPtr<SourceProvider>); 100 101 101 102 VM& m_vm; … … 104 105 Vector<std::function<void()>> m_finalizers; 105 106 HashMap<CompactVariableEnvironment*, CompactVariableMap::Handle> m_environmentToHandleMap; 107 RefPtr<SourceProvider> m_provider; 106 108 }; 107 109
Note: See TracChangeset
for help on using the changeset viewer.