WebKit Bugzilla
Attachment 362266 Details for
Bug 194768
: Add version number to cached bytecode
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-194768-20190218093846.patch (text/plain), 9.46 KB, created by
Tadeu Zagallo
on 2019-02-18 00:39:23 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Tadeu Zagallo
Created:
2019-02-18 00:39:23 PST
Size:
9.46 KB
patch
obsolete
>Subversion Revision: 241658 >diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog >index 13f1d17d290f781a0f252eb496b6448f177f474e..2044e9a3fdb942bf46e028ce28f5dd5ca35f1d8c 100644 >--- a/Source/JavaScriptCore/ChangeLog >+++ b/Source/JavaScriptCore/ChangeLog >@@ -1,3 +1,27 @@ >+2019-02-17 Tadeu Zagallo <tzagallo@apple.com> >+ >+ Add version number to cached bytecode >+ https://bugs.webkit.org/show_bug.cgi?id=194768 >+ <rdar://problem/48147968> >+ >+ Reviewed by Saam Barati. >+ >+ Add a version number to the bytecode cache that should be unique per build. >+ >+ * CMakeLists.txt: >+ * DerivedSources-output.xcfilelist: >+ * DerivedSources.make: >+ * runtime/CachedTypes.cpp: >+ (JSC::Encoder::malloc): >+ (JSC::GenericCacheEntry::GenericCacheEntry): >+ (JSC::CacheEntry::CacheEntry): >+ (JSC::CacheEntry::encode): >+ (JSC::CacheEntry::decode const): >+ (JSC::GenericCacheEntry::decode const): >+ (JSC::decodeCodeBlockImpl): >+ * runtime/CodeCache.h: >+ (JSC::CodeCacheMap::fetchFromDiskImpl): >+ > 2019-02-17 Saam Barati <sbarati@apple.com> > > WasmB3IRGenerator models some effects incorrectly >diff --git a/Source/JavaScriptCore/CMakeLists.txt b/Source/JavaScriptCore/CMakeLists.txt >index 2cef93668bac8dff97e705100f86aa735ad5673e..e311ace426a723795afac172f83eace1be890ae1 100644 >--- a/Source/JavaScriptCore/CMakeLists.txt >+++ b/Source/JavaScriptCore/CMakeLists.txt >@@ -228,9 +228,19 @@ add_custom_command( > COMMAND ${RUBY_EXECUTABLE} ${JAVASCRIPTCORE_DIR}/generator/main.rb --bytecodes_h ${DERIVED_SOURCES_JAVASCRIPTCORE_DIR}/Bytecodes.h --init_bytecodes_asm ${DERIVED_SOURCES_JAVASCRIPTCORE_DIR}/InitBytecodes.asm --bytecode_structs_h ${DERIVED_SOURCES_JAVASCRIPTCORE_DIR}/BytecodeStructs.h --bytecode_indices_h ${DERIVED_SOURCES_JAVASCRIPTCORE_DIR}/BytecodeIndices.h ${JAVASCRIPTCORE_DIR}/bytecode/BytecodeList.rb > VERBATIM) > >+ >+if (WTF_OS_MAC_OS_X) >+ execute_process(COMMAND bash -c "date +'%s'" OUTPUT_VARIABLE BUILD_TIME OUTPUT_STRIP_TRAILING_WHITESPACE) >+else () >+ set(BUILD_TIME 0) >+endif () >+ >+file(WRITE ${DERIVED_SOURCES_JAVASCRIPTCORE_DIR}/BytecodeCacheVersion.h "#define JSC_BYTECODE_CACHE_VERSION ${BUILD_TIME}\n") >+ > list(APPEND JavaScriptCore_HEADERS >- ${DERIVED_SOURCES_JAVASCRIPTCORE_DIR}/Bytecodes.h >+ ${DERIVED_SOURCES_JAVASCRIPTCORE_DIR}/BytecodeCacheVersion.h > ${DERIVED_SOURCES_JAVASCRIPTCORE_DIR}/BytecodeStructs.h >+ ${DERIVED_SOURCES_JAVASCRIPTCORE_DIR}/Bytecodes.h > ) > > if (WIN32) >diff --git a/Source/JavaScriptCore/DerivedSources-output.xcfilelist b/Source/JavaScriptCore/DerivedSources-output.xcfilelist >index 9d6b64e92be7d465a6e7134416362f15ba35a382..d2dee4242337789e74bc4c4dff54bf6177a98134 100644 >--- a/Source/JavaScriptCore/DerivedSources-output.xcfilelist >+++ b/Source/JavaScriptCore/DerivedSources-output.xcfilelist >@@ -9,6 +9,7 @@ $(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/AsyncGeneratorPrototype.lut. > $(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/BigIntConstructor.lut.h > $(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/BigIntPrototype.lut.h > $(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/BooleanPrototype.lut.h >+$(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/BytecodeCacheVersion.h > $(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/BytecodeIndices.h > $(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/BytecodeStructs.h > $(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/Bytecodes.h >diff --git a/Source/JavaScriptCore/DerivedSources.make b/Source/JavaScriptCore/DerivedSources.make >index 4d3e429074c12ef54dca25512ac203c593299013..3b5e10540bbbdb22c3bbd704e17bbe49b2866e40 100644 >--- a/Source/JavaScriptCore/DerivedSources.make >+++ b/Source/JavaScriptCore/DerivedSources.make >@@ -356,3 +356,10 @@ WasmB3IRGeneratorInlines.h: $(JavaScriptCore)/wasm/generateWasmB3IRGeneratorInli > all : \ > $(OBJECT_LUT_HEADERS) \ > # >+ >+.PHONY : BytecodeCacheVersion.h >+ >+BytecodeCacheVersion.h: >+ echo "#define JSC_BYTECODE_CACHE_VERSION $(shell date '+%s')" > BytecodeCacheVersion.h >+ >+all : BytecodeCacheVersion.h >diff --git a/Source/JavaScriptCore/runtime/CachedTypes.cpp b/Source/JavaScriptCore/runtime/CachedTypes.cpp >index 8a1dde3130eb552843e8c19bfa0a1b7119da7020..ba29e6ef33c1b8eaeb82076ffbb6d4c159c8ad85 100644 >--- a/Source/JavaScriptCore/runtime/CachedTypes.cpp >+++ b/Source/JavaScriptCore/runtime/CachedTypes.cpp >@@ -26,6 +26,7 @@ > #include "config.h" > #include "CachedTypes.h" > >+#include "BytecodeCacheVersion.h" > #include "BytecodeLivenessAnalysis.h" > #include "JSCast.h" > #include "JSImmutableButterfly.h" >@@ -104,7 +105,7 @@ public: > template<typename T> > T* malloc() > { >- return reinterpret_cast<T*>(malloc(sizeof(T)).buffer()); >+ return new (malloc(sizeof(T)).buffer()) T(); > } > > ptrdiff_t offsetOf(const void* address) >@@ -1986,18 +1987,28 @@ private: > > class GenericCacheEntry { > public: >- std::pair<SourceCodeKey, UnlinkedCodeBlock*> decode(Decoder&) const; >+ bool decode(Decoder&, std::pair<SourceCodeKey, UnlinkedCodeBlock*>&) const; > > protected: >+ GenericCacheEntry(CachedCodeBlockTag tag) >+ : m_tag(tag) >+ { >+ } >+ >+ uint32_t m_cacheVersion { JSC_BYTECODE_CACHE_VERSION }; > CachedCodeBlockTag m_tag; > }; > > template<typename UnlinkedCodeBlockType> > class CacheEntry : public GenericCacheEntry { > public: >+ CacheEntry() >+ : GenericCacheEntry(CachedCodeBlockTypeImpl<UnlinkedCodeBlockType>::tag) >+ { >+ } >+ > void encode(Encoder& encoder, std::pair<SourceCodeKey, const UnlinkedCodeBlockType*> pair) > { >- m_tag = CachedCodeBlockTypeImpl<UnlinkedCodeBlockType>::tag; > m_key.encode(encoder, pair.first); > m_codeBlock.encode(encoder, pair.second); > } >@@ -2005,25 +2016,30 @@ public: > private: > friend GenericCacheEntry; > >- std::pair<SourceCodeKey, UnlinkedCodeBlockType*> decode(Decoder& decoder) const >+ bool decode(Decoder& decoder, std::pair<SourceCodeKey, UnlinkedCodeBlockType*>& result) const > { >+ if (m_cacheVersion != JSC_BYTECODE_CACHE_VERSION) >+ return false; > ASSERT(m_tag == CachedCodeBlockTypeImpl<UnlinkedCodeBlockType>::tag); >+ if (m_tag != CachedCodeBlockTypeImpl<UnlinkedCodeBlockType>::tag) >+ return false; > SourceCodeKey decodedKey; > m_key.decode(decoder, decodedKey); >- return { WTFMove(decodedKey), m_codeBlock.decode(decoder) }; >+ result = { WTFMove(decodedKey), m_codeBlock.decode(decoder) }; >+ return true; > } > > CachedSourceCodeKey m_key; > CachedPtr<CachedCodeBlockType<UnlinkedCodeBlockType>> m_codeBlock; > }; > >-std::pair<SourceCodeKey, UnlinkedCodeBlock*> GenericCacheEntry::decode(Decoder& decoder) const >+bool GenericCacheEntry::decode(Decoder& decoder, std::pair<SourceCodeKey, UnlinkedCodeBlock*>& result) const > { > switch (m_tag) { > case CachedProgramCodeBlockTag: >- return reinterpret_cast<const CacheEntry<UnlinkedProgramCodeBlock>*>(this)->decode(decoder); >+ return reinterpret_cast<const CacheEntry<UnlinkedProgramCodeBlock>*>(this)->decode(decoder, reinterpret_cast<std::pair<SourceCodeKey, UnlinkedProgramCodeBlock*>&>(result)); > case CachedModuleCodeBlockTag: >- return reinterpret_cast<const CacheEntry<UnlinkedModuleProgramCodeBlock>*>(this)->decode(decoder); >+ return reinterpret_cast<const CacheEntry<UnlinkedModuleProgramCodeBlock>*>(this)->decode(decoder, reinterpret_cast<std::pair<SourceCodeKey, UnlinkedModuleProgramCodeBlock*>&>(result)); > case CachedEvalCodeBlockTag: > // We do not cache eval code blocks > RELEASE_ASSERT_NOT_REACHED(); >@@ -2031,7 +2047,7 @@ std::pair<SourceCodeKey, UnlinkedCodeBlock*> GenericCacheEntry::decode(Decoder& > RELEASE_ASSERT_NOT_REACHED(); > #if COMPILER(MSVC) > // Without this, MSVC will complain that this path does not return a value. >- return reinterpret_cast<const CacheEntry<UnlinkedEvalCodeBlock>*>(this)->decode(decoder); >+ return false; > #endif > } > >@@ -2064,7 +2080,8 @@ UnlinkedCodeBlock* decodeCodeBlockImpl(VM& vm, const SourceCodeKey& key, const v > std::pair<SourceCodeKey, UnlinkedCodeBlock*> entry; > { > DeferGC deferGC(vm.heap); >- entry = cachedEntry->decode(decoder); >+ if (!cachedEntry->decode(decoder, entry)) >+ return nullptr; > } > > if (entry.first != key) >diff --git a/Source/JavaScriptCore/runtime/CodeCache.h b/Source/JavaScriptCore/runtime/CodeCache.h >index 7ab80fe201abd8bfd92e95f460fc367bb3848b78..0e41e0211cad9c5db3fcd88adca6433e4eb78e2e 100644 >--- a/Source/JavaScriptCore/runtime/CodeCache.h >+++ b/Source/JavaScriptCore/runtime/CodeCache.h >@@ -41,6 +41,7 @@ > #include "UnlinkedProgramCodeBlock.h" > #include <sys/stat.h> > #include <wtf/Forward.h> >+#include <wtf/Scope.h> > #include <wtf/text/WTFString.h> > > namespace JSC { >@@ -134,19 +135,19 @@ public: > if (fd == -1) > return nullptr; > >- int rc = flock(fd, LOCK_SH | LOCK_NB); >- if (rc) { >+ auto closeFD = makeScopeExit([&] { > close(fd); >+ }); >+ >+ int rc = flock(fd, LOCK_SH | LOCK_NB); >+ if (rc) > return nullptr; >- } > > struct stat sb; > int res = fstat(fd, &sb); > size_t size = static_cast<size_t>(sb.st_size); >- if (res || !size) { >- close(fd); >+ if (res || !size) > return nullptr; >- } > > void* buffer = mmap(nullptr, size, PROT_READ, MAP_PRIVATE, fd, 0); > UnlinkedCodeBlockType* unlinkedCodeBlock = decodeCodeBlock<UnlinkedCodeBlockType>(vm, key, buffer, size);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 194768
:
362264
| 362266