Changeset 243869 in webkit
- Timestamp:
- Apr 4, 2019, 8:41:07 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 4 edited
-
JSTests/ChangeLog (modified) (1 diff)
-
JSTests/stress/bytecode-cache-cached-string-impl.js (added)
-
JSTests/stress/bytecode-cache-run-string.js (added)
-
Source/JavaScriptCore/ChangeLog (modified) (1 diff)
-
Source/JavaScriptCore/jsc.cpp (modified) (6 diffs)
-
Source/JavaScriptCore/runtime/CachedTypes.cpp (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/JSTests/ChangeLog
r243851 r243869 1 2019-04-04 Tadeu Zagallo <tzagallo@apple.com> 2 3 Cache bytecode for jsc.cpp helpers and fix CachedStringImpl 4 https://bugs.webkit.org/show_bug.cgi?id=196409 5 6 Reviewed by Saam Barati. 7 8 * stress/bytecode-cache-cached-string-impl.js: Added. 9 (f): 10 (g): 11 * stress/bytecode-cache-run-string.js: Added. 12 1 13 2019-04-03 Robin Morisset <rmorisset@apple.com> 2 14 -
trunk/Source/JavaScriptCore/ChangeLog
r243867 r243869 1 2019-04-04 Tadeu Zagallo <tzagallo@apple.com> 2 3 Cache bytecode for jsc.cpp helpers and fix CachedStringImpl 4 https://bugs.webkit.org/show_bug.cgi?id=196409 5 6 Reviewed by Saam Barati. 7 8 Some of the helpers in jsc.cpp, such as `functionRunString`, were stll using 9 using `makeSource` instead of `jscSource`, which does not use the ShellSourceProvider 10 and therefore does not write the bytecode cache to disk. 11 12 Changing that revealed a bug in bytecode cache. The Encoder keeps a mapping 13 of pointers to offsets of already cached objects, in order to avoid caching 14 the same object twice. Similarly, the Decoder keeps a mapping from offsets 15 to pointers, in order to avoid creating multiple objects in memory for the 16 same cached object. The following was happening: 17 1) A StringImpl* S was cached as CachedPtr<CachedStringImpl> at offset O. We add 18 an entry in the Encoder mapping that S has already been encoded at O. 19 2) We cache StringImpl* S again, but now as CachedPtr<CachedUniquedStringImpl>. 20 We find an entry in the Encoder mapping for S, and return the offset O. However, 21 the object cached at O is a CachedPtr<CachedStringImpl> (i.e. not Uniqued). 22 23 3) When decoding, there are 2 possibilities: 24 3.1) We find S for the first time through a CachedPtr<CachedStringImpl>. In 25 this case, everything works as expected since we add an entry in the decoder 26 mapping from the offset O to the decoded StringImpl* S. The next time we find 27 S through the uniqued version, we'll return the already decoded S. 28 3.2) We find S through a CachedPtr<CachedUniquedStringImpl>. Now we have a 29 problem, since the CachedPtr has the offset of a CachedStringImpl (not uniqued), 30 which has a different shape and we crash. 31 32 We fix this by making CachedStringImpl and CachedUniquedStringImpl share the 33 same implementation. Since it doesn't matter whether a string is uniqued for 34 encoding, and we always decode strings as uniqued either way, they can be used 35 interchangeably. 36 37 * jsc.cpp: 38 (functionRunString): 39 (functionLoadString): 40 (functionDollarAgentStart): 41 (functionCheckModuleSyntax): 42 (runInteractive): 43 * runtime/CachedTypes.cpp: 44 (JSC::CachedUniquedStringImplBase::decode const): 45 (JSC::CachedFunctionExecutable::rareData const): 46 (JSC::CachedCodeBlock::rareData const): 47 (JSC::CachedFunctionExecutable::encode): 48 (JSC::CachedCodeBlock<CodeBlockType>::encode): 49 (JSC::CachedUniquedStringImpl::encode): Deleted. 50 (JSC::CachedUniquedStringImpl::decode const): Deleted. 51 (JSC::CachedStringImpl::encode): Deleted. 52 (JSC::CachedStringImpl::decode const): Deleted. 53 1 54 2019-04-04 Tadeu Zagallo <tzagallo@apple.com> 2 55 -
trunk/Source/JavaScriptCore/jsc.cpp
r243312 r243869 1460 1460 1461 1461 NakedPtr<Exception> exception; 1462 evaluate(globalObject->globalExec(), makeSource(source, exec->callerSourceOrigin()), JSValue(), exception);1462 evaluate(globalObject->globalExec(), jscSource(source, exec->callerSourceOrigin()), JSValue(), exception); 1463 1463 1464 1464 if (exception) { … … 1500 1500 1501 1501 NakedPtr<Exception> evaluationException; 1502 JSValue result = evaluate(globalObject->globalExec(), makeSource(sourceCode, exec->callerSourceOrigin()), JSValue(), evaluationException);1502 JSValue result = evaluate(globalObject->globalExec(), jscSource(sourceCode, exec->callerSourceOrigin()), JSValue(), evaluationException); 1503 1503 if (evaluationException) 1504 1504 throwException(exec, scope, evaluationException); … … 1844 1844 NakedPtr<Exception> evaluationException; 1845 1845 JSValue result; 1846 result = evaluate(globalObject->globalExec(), makeSource(sourceCode, SourceOrigin("worker"_s)), JSValue(), evaluationException);1846 result = evaluate(globalObject->globalExec(), jscSource(sourceCode, SourceOrigin("worker"_s)), JSValue(), evaluationException); 1847 1847 if (evaluationException) 1848 1848 result = evaluationException->value(); … … 2186 2186 2187 2187 ParserError error; 2188 bool validSyntax = checkModuleSyntax(exec, makeSource(source, { }, URL(), TextPosition(), SourceProviderSourceType::Module), error);2188 bool validSyntax = checkModuleSyntax(exec, jscSource(source, { }, URL(), TextPosition(), SourceProviderSourceType::Module), error); 2189 2189 RETURN_IF_EXCEPTION(scope, encodedJSValue()); 2190 2190 stopWatch.stop(); … … 2625 2625 source = source + String::fromUTF8(line); 2626 2626 source = source + '\n'; 2627 checkSyntax(vm, makeSource(source, sourceOrigin), error);2627 checkSyntax(vm, jscSource(source, sourceOrigin), error); 2628 2628 if (!line[0]) { 2629 2629 free(line); … … 2641 2641 2642 2642 NakedPtr<Exception> evaluationException; 2643 JSValue returnValue = evaluate(globalObject->globalExec(), makeSource(source, sourceOrigin), JSValue(), evaluationException);2643 JSValue returnValue = evaluate(globalObject->globalExec(), jscSource(source, sourceOrigin), JSValue(), evaluationException); 2644 2644 #else 2645 2645 printf("%s", interactivePrompt); -
trunk/Source/JavaScriptCore/runtime/CachedTypes.cpp
r243867 r243869 576 576 }; 577 577 578 class CachedUniquedStringImpl : public VariableLengthObject<UniquedStringImpl> { 578 template<typename T> 579 class CachedUniquedStringImplBase : public VariableLengthObject<T> { 579 580 public: 580 581 void encode(Encoder& encoder, const StringImpl& string) … … 632 633 633 634 if (m_is8Bit) 634 return create(this-> buffer<LChar>());635 return create(this-> buffer<UChar>());635 return create(this->template buffer<LChar>()); 636 return create(this->template buffer<UChar>()); 636 637 } 637 638 … … 643 644 }; 644 645 645 class CachedStringImpl : public VariableLengthObject<StringImpl> { 646 public: 647 void encode(Encoder& encoder, const StringImpl& impl) 648 { 649 m_uniquedStringImpl.encode(encoder, impl); 650 } 651 652 StringImpl* decode(Decoder& decoder) const 653 { 654 return m_uniquedStringImpl.decode(decoder); 655 } 656 657 private: 658 CachedUniquedStringImpl m_uniquedStringImpl; 659 }; 646 class CachedUniquedStringImpl : public CachedUniquedStringImplBase<UniquedStringImpl> { }; 647 class CachedStringImpl : public CachedUniquedStringImplBase<StringImpl> { }; 660 648 661 649 class CachedString : public VariableLengthObject<String> { … … 1573 1561 Identifier inferredName(Decoder& decoder) const { return m_inferredName.decode(decoder); } 1574 1562 1575 UnlinkedFunctionExecutable::RareData* rareData(Decoder& decoder) const { return m_rareData.decode AsPtr(decoder); }1563 UnlinkedFunctionExecutable::RareData* rareData(Decoder& decoder) const { return m_rareData.decode(decoder); } 1576 1564 1577 1565 const CachedWriteBarrier<CachedFunctionCodeBlock, UnlinkedFunctionCodeBlock>& unlinkedCodeBlockForCall() const { return m_unlinkedCodeBlockForCall; } … … 1603 1591 unsigned m_derivedContextType: 2; 1604 1592 1605 Cached Optional<CachedFunctionExecutableRareData> m_rareData;1593 CachedPtr<CachedFunctionExecutableRareData> m_rareData; 1606 1594 1607 1595 CachedIdentifier m_name; … … 1656 1644 unsigned codeType() const { return m_codeType; } 1657 1645 1658 UnlinkedCodeBlock::RareData* rareData(Decoder& decoder) const { return m_rareData.decode AsPtr(decoder); }1646 UnlinkedCodeBlock::RareData* rareData(Decoder& decoder) const { return m_rareData.decode(decoder); } 1659 1647 1660 1648 private: … … 1691 1679 CachedMetadataTable m_metadata; 1692 1680 1693 Cached Optional<CachedCodeBlockRareData> m_rareData;1681 CachedPtr<CachedCodeBlockRareData> m_rareData; 1694 1682 1695 1683 CachedString m_sourceURLDirective; … … 1956 1944 m_derivedContextType = executable.m_derivedContextType; 1957 1945 1958 m_rareData.encode(encoder, executable.m_rareData );1946 m_rareData.encode(encoder, executable.m_rareData.get()); 1959 1947 1960 1948 m_name.encode(encoder, executable.name()); … … 2061 2049 2062 2050 m_metadata.encode(encoder, codeBlock.m_metadata.get()); 2063 m_rareData.encode(encoder, codeBlock.m_rareData );2051 m_rareData.encode(encoder, codeBlock.m_rareData.get()); 2064 2052 2065 2053 m_sourceURLDirective.encode(encoder, codeBlock.m_sourceURLDirective.impl());
Note:
See TracChangeset
for help on using the changeset viewer.