Changeset 240210 in webkit


Ignore:
Timestamp:
Jan 20, 2019 3:20:25 AM (5 years ago)
Author:
Tadeu Zagallo
Message:

Cache bytecode to disk
https://bugs.webkit.org/show_bug.cgi?id=192782
<rdar://problem/46084932>

Reviewed by Keith Miller.

Source/JavaScriptCore:

Add the logic to serialize and deserialize the new JSC bytecode. For now,
the cache is only used for tests.

Each class that can be serialized has a counterpart in CachedTypes, which
handles the decoding and encoding. When decoding, the cached objects are
mmap'd from disk, but only used for creating instances of the respective
in-memory version of each object. Ideally, the mmap'd objects should be
used at runtime in the future.

  • CMakeLists.txt:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • Sources.txt:
  • builtins/BuiltinNames.cpp:

(JSC::BuiltinNames::BuiltinNames):

  • builtins/BuiltinNames.h:
  • bytecode/CodeBlock.cpp:

(JSC::CodeBlock::setConstantIdentifierSetRegisters):

  • bytecode/CodeBlock.h:
  • bytecode/HandlerInfo.h:

(JSC::UnlinkedHandlerInfo::UnlinkedHandlerInfo):

  • bytecode/InstructionStream.h:
  • bytecode/UnlinkedCodeBlock.h:

(JSC::UnlinkedCodeBlock::addSetConstant):
(JSC::UnlinkedCodeBlock::constantIdentifierSets):

  • bytecode/UnlinkedEvalCodeBlock.h:
  • bytecode/UnlinkedFunctionCodeBlock.h:
  • bytecode/UnlinkedFunctionExecutable.h:
  • bytecode/UnlinkedGlobalCodeBlock.h:

(JSC::UnlinkedGlobalCodeBlock::UnlinkedGlobalCodeBlock):

  • bytecode/UnlinkedMetadataTable.h:
  • bytecode/UnlinkedModuleProgramCodeBlock.h:
  • bytecode/UnlinkedProgramCodeBlock.h:
  • interpreter/Interpreter.cpp:
  • jsc.cpp:

(functionQuit):
(runJSC):

  • parser/SourceCode.h:
  • parser/SourceCodeKey.h:

(JSC::SourceCodeKey::operator!= const):

  • parser/UnlinkedSourceCode.h:
  • parser/VariableEnvironment.h:
  • runtime/CachedTypes.cpp: Added.

(JSC::Encoder::Allocation::buffer const):
(JSC::Encoder::Allocation::offset const):
(JSC::Encoder::Allocation::Allocation):
(JSC::Encoder::Encoder):
(JSC::Encoder::vm):
(JSC::Encoder::malloc):
(JSC::Encoder::offsetOf):
(JSC::Encoder::cachePtr):
(JSC::Encoder::offsetForPtr):
(JSC::Encoder::release):
(JSC::Encoder::Page::Page):
(JSC::Encoder::Page::malloc):
(JSC::Encoder::Page::buffer const):
(JSC::Encoder::Page::size const):
(JSC::Encoder::Page::getOffset const):
(JSC::Encoder::allocateNewPage):
(JSC::Decoder::Decoder):
(JSC::Decoder::~Decoder):
(JSC::Decoder::vm):
(JSC::Decoder::offsetOf):
(JSC::Decoder::cacheOffset):
(JSC::Decoder::addFinalizer):
(JSC::encode):
(JSC::decode):
(JSC::VariableLengthObject::buffer const):
(JSC::VariableLengthObject::allocate):
(JSC::CachedPtr::encode):
(JSC::CachedPtr::decode const):
(JSC::CachedPtr::operator-> const):
(JSC::CachedPtr::get const):
(JSC::CachedRefPtr::encode):
(JSC::CachedRefPtr::decode const):
(JSC::CachedWriteBarrier::encode):
(JSC::CachedWriteBarrier::decode const):
(JSC::CachedVector::encode):
(JSC::CachedVector::decode const):
(JSC::CachedPair::encode):
(JSC::CachedPair::decode const):
(JSC::CachedHashMap::encode):
(JSC::CachedHashMap::decode const):
(JSC::CachedUniquedStringImpl::encode):
(JSC::CachedUniquedStringImpl::decode const):
(JSC::CachedStringImpl::encode):
(JSC::CachedStringImpl::decode const):
(JSC::CachedString::encode):
(JSC::CachedString::decode const):
(JSC::CachedIdentifier::encode):
(JSC::CachedIdentifier::decode const):
(JSC::CachedOptional::encode):
(JSC::CachedOptional::decode const):
(JSC::CachedOptional::decodeAsPtr const):
(JSC::CachedSimpleJumpTable::encode):
(JSC::CachedSimpleJumpTable::decode const):
(JSC::CachedStringJumpTable::encode):
(JSC::CachedStringJumpTable::decode const):
(JSC::CachedCodeBlockRareData::encode):
(JSC::CachedCodeBlockRareData::decode const):
(JSC::CachedBitVector::encode):
(JSC::CachedBitVector::decode const):
(JSC::CachedHashSet::encode):
(JSC::CachedHashSet::decode const):
(JSC::CachedConstantIdentifierSetEntry::encode):
(JSC::CachedConstantIdentifierSetEntry::decode const):
(JSC::CachedVariableEnvironment::encode):
(JSC::CachedVariableEnvironment::decode const):
(JSC::CachedArray::encode):
(JSC::CachedArray::decode const):
(JSC::CachedScopedArgumentsTable::encode):
(JSC::CachedScopedArgumentsTable::decode const):
(JSC::CachedSymbolTableEntry::encode):
(JSC::CachedSymbolTableEntry::decode const):
(JSC::CachedSymbolTable::encode):
(JSC::CachedSymbolTable::decode const):
(JSC::CachedImmutableButterfly::encode):
(JSC::CachedImmutableButterfly::decode const):
(JSC::CachedRegExp::encode):
(JSC::CachedRegExp::decode const):
(JSC::CachedTemplateObjectDescriptor::encode):
(JSC::CachedTemplateObjectDescriptor::decode const):
(JSC::CachedBigInt::encode):
(JSC::CachedBigInt::decode const):
(JSC::CachedJSValue::encode):
(JSC::CachedJSValue::decode const):
(JSC::CachedInstructionStream::encode):
(JSC::CachedInstructionStream::decode const):
(JSC::CachedMetadataTable::encode):
(JSC::CachedMetadataTable::decode const):
(JSC::CachedSourceOrigin::encode):
(JSC::CachedSourceOrigin::decode const):
(JSC::CachedTextPosition::encode):
(JSC::CachedTextPosition::decode const):
(JSC::CachedSourceProviderShape::encode):
(JSC::CachedSourceProviderShape::decode const):
(JSC::CachedStringSourceProvider::encode):
(JSC::CachedStringSourceProvider::decode const):
(JSC::CachedWebAssemblySourceProvider::encode):
(JSC::CachedWebAssemblySourceProvider::decode const):
(JSC::CachedSourceProvider::encode):
(JSC::CachedSourceProvider::decode const):
(JSC::CachedUnlinkedSourceCodeShape::encode):
(JSC::CachedUnlinkedSourceCodeShape::decode const):
(JSC::CachedSourceCode::encode):
(JSC::CachedSourceCode::decode const):
(JSC::CachedFunctionExecutable::firstLineOffset const):
(JSC::CachedFunctionExecutable::lineCount const):
(JSC::CachedFunctionExecutable::unlinkedFunctionNameStart const):
(JSC::CachedFunctionExecutable::unlinkedBodyStartColumn const):
(JSC::CachedFunctionExecutable::unlinkedBodyEndColumn const):
(JSC::CachedFunctionExecutable::startOffset const):
(JSC::CachedFunctionExecutable::sourceLength const):
(JSC::CachedFunctionExecutable::parametersStartOffset const):
(JSC::CachedFunctionExecutable::typeProfilingStartOffset const):
(JSC::CachedFunctionExecutable::typeProfilingEndOffset const):
(JSC::CachedFunctionExecutable::parameterCount const):
(JSC::CachedFunctionExecutable::features const):
(JSC::CachedFunctionExecutable::sourceParseMode const):
(JSC::CachedFunctionExecutable::isInStrictContext const):
(JSC::CachedFunctionExecutable::hasCapturedVariables const):
(JSC::CachedFunctionExecutable::isBuiltinFunction const):
(JSC::CachedFunctionExecutable::isBuiltinDefaultClassConstructor const):
(JSC::CachedFunctionExecutable::constructAbility const):
(JSC::CachedFunctionExecutable::constructorKind const):
(JSC::CachedFunctionExecutable::functionMode const):
(JSC::CachedFunctionExecutable::scriptMode const):
(JSC::CachedFunctionExecutable::superBinding const):
(JSC::CachedFunctionExecutable::derivedContextType const):
(JSC::CachedFunctionExecutable::name const):
(JSC::CachedFunctionExecutable::ecmaName const):
(JSC::CachedFunctionExecutable::inferredName const):
(JSC::CachedCodeBlock::instructions const):
(JSC::CachedCodeBlock::thisRegister const):
(JSC::CachedCodeBlock::scopeRegister const):
(JSC::CachedCodeBlock::globalObjectRegister const):
(JSC::CachedCodeBlock::sourceURLDirective const):
(JSC::CachedCodeBlock::sourceMappingURLDirective const):
(JSC::CachedCodeBlock::usesEval const):
(JSC::CachedCodeBlock::isStrictMode const):
(JSC::CachedCodeBlock::isConstructor const):
(JSC::CachedCodeBlock::hasCapturedVariables const):
(JSC::CachedCodeBlock::isBuiltinFunction const):
(JSC::CachedCodeBlock::superBinding const):
(JSC::CachedCodeBlock::scriptMode const):
(JSC::CachedCodeBlock::isArrowFunctionContext const):
(JSC::CachedCodeBlock::isClassContext const):
(JSC::CachedCodeBlock::wasCompiledWithDebuggingOpcodes const):
(JSC::CachedCodeBlock::constructorKind const):
(JSC::CachedCodeBlock::derivedContextType const):
(JSC::CachedCodeBlock::evalContextType const):
(JSC::CachedCodeBlock::hasTailCalls const):
(JSC::CachedCodeBlock::lineCount const):
(JSC::CachedCodeBlock::endColumn const):
(JSC::CachedCodeBlock::numVars const):
(JSC::CachedCodeBlock::numCalleeLocals const):
(JSC::CachedCodeBlock::numParameters const):
(JSC::CachedCodeBlock::features const):
(JSC::CachedCodeBlock::parseMode const):
(JSC::CachedCodeBlock::codeType const):
(JSC::CachedCodeBlock::rareData const):
(JSC::CachedProgramCodeBlock::encode):
(JSC::CachedProgramCodeBlock::decode const):
(JSC::CachedModuleCodeBlock::encode):
(JSC::CachedModuleCodeBlock::decode const):
(JSC::CachedEvalCodeBlock::encode):
(JSC::CachedEvalCodeBlock::decode const):
(JSC::CachedFunctionCodeBlock::encode):
(JSC::CachedFunctionCodeBlock::decode const):
(JSC::UnlinkedFunctionCodeBlock::UnlinkedFunctionCodeBlock):
(JSC::UnlinkedCodeBlock::UnlinkedCodeBlock):
(JSC::CachedCodeBlock<CodeBlockType>::decode const):
(JSC::UnlinkedProgramCodeBlock::UnlinkedProgramCodeBlock):
(JSC::UnlinkedModuleProgramCodeBlock::UnlinkedModuleProgramCodeBlock):
(JSC::UnlinkedEvalCodeBlock::UnlinkedEvalCodeBlock):
(JSC::CachedFunctionExecutable::encode):
(JSC::CachedFunctionExecutable::decode const):
(JSC::UnlinkedFunctionExecutable::UnlinkedFunctionExecutable):
(JSC::CachedCodeBlock<CodeBlockType>::encode):
(JSC::CachedSourceCodeKey::encode):
(JSC::CachedSourceCodeKey::decode const):
(JSC::CacheEntry::encode):
(JSC::CacheEntry:: const):
(JSC:: const):
(JSC::encodeCodeBlock):
(JSC::decodeCodeBlockImpl):

  • runtime/CachedTypes.h: Copied from Source/JavaScriptCore/bytecode/UnlinkedGlobalCodeBlock.h.

(JSC::decodeCodeBlock):

  • runtime/CodeCache.cpp:

(JSC::CodeCacheMap::pruneSlowCase):
(JSC::CodeCache::getUnlinkedGlobalCodeBlock):
(JSC::CodeCache::getUnlinkedGlobalFunctionExecutable):
(JSC::CodeCache::write):

  • runtime/CodeCache.h:

(JSC::CodeCacheMap::begin):
(JSC::CodeCacheMap::end):
(JSC::CodeCacheMap::fetchFromDiskImpl):
(JSC::CodeCacheMap::findCacheAndUpdateAge):
(JSC::writeCodeBlock):

  • runtime/JSBigInt.cpp:
  • runtime/JSBigInt.h:
  • runtime/Options.cpp:

(JSC::recomputeDependentOptions):

  • runtime/Options.h:
  • runtime/RegExp.h:
  • runtime/ScopedArgumentsTable.h:
  • runtime/StackFrame.h:
  • runtime/StructureInlines.h:
  • runtime/SymbolTable.h:

Source/WTF:

BitVectors have to be friends with JSC::CacheBitVector to allow
serializing its buffer as part of the bytecode cache encoding.

  • wtf/BitVector.h:

Tools:

Add test helper to execute bytecode-cache tests: it executes each test
twice, the first with JSC_diskCachePath set to a temporary directory
and second with JSC_forceDiskCache=true (in addition to the cache path)
to guarantee that only the disk cache is being used and no new
UnlinkedCodeBlocks are being created.

  • Scripts/jsc-stress-test-helpers/bytecode-cache-test-helper: Added.
  • Scripts/run-jsc-stress-tests:
Location:
trunk
Files:
2 added
39 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/CMakeLists.txt

    r240023 r240210  
    834834    runtime/JSGlobalObject.h
    835835    runtime/JSGlobalObjectInlines.h
     836    runtime/JSImmutableButterfly.h
    836837    runtime/JSInternalPromise.h
    837838    runtime/JSInternalPromiseDeferred.h
     
    849850    runtime/JSPromiseConstructor.h
    850851    runtime/JSPromiseDeferred.h
     852    runtime/JSPropertyNameEnumerator.h
    851853    runtime/JSProxy.h
    852854    runtime/JSRunLoopTimer.h
  • trunk/Source/JavaScriptCore/ChangeLog

    r240208 r240210  
     12019-01-20  Tadeu Zagallo  <tzagallo@apple.com>
     2
     3        Cache bytecode to disk
     4        https://bugs.webkit.org/show_bug.cgi?id=192782
     5        <rdar://problem/46084932>
     6
     7        Reviewed by Keith Miller.
     8
     9        Add the logic to serialize and deserialize the new JSC bytecode. For now,
     10        the cache is only used for tests.
     11
     12        Each class that can be serialized has a counterpart in CachedTypes, which
     13        handles the decoding and encoding. When decoding, the cached objects are
     14        mmap'd from disk, but only used for creating instances of the respective
     15        in-memory version of each object. Ideally, the mmap'd objects should be
     16        used at runtime in the future.
     17
     18        * CMakeLists.txt:
     19        * JavaScriptCore.xcodeproj/project.pbxproj:
     20        * Sources.txt:
     21        * builtins/BuiltinNames.cpp:
     22        (JSC::BuiltinNames::BuiltinNames):
     23        * builtins/BuiltinNames.h:
     24        * bytecode/CodeBlock.cpp:
     25        (JSC::CodeBlock::setConstantIdentifierSetRegisters):
     26        * bytecode/CodeBlock.h:
     27        * bytecode/HandlerInfo.h:
     28        (JSC::UnlinkedHandlerInfo::UnlinkedHandlerInfo):
     29        * bytecode/InstructionStream.h:
     30        * bytecode/UnlinkedCodeBlock.h:
     31        (JSC::UnlinkedCodeBlock::addSetConstant):
     32        (JSC::UnlinkedCodeBlock::constantIdentifierSets):
     33        * bytecode/UnlinkedEvalCodeBlock.h:
     34        * bytecode/UnlinkedFunctionCodeBlock.h:
     35        * bytecode/UnlinkedFunctionExecutable.h:
     36        * bytecode/UnlinkedGlobalCodeBlock.h:
     37        (JSC::UnlinkedGlobalCodeBlock::UnlinkedGlobalCodeBlock):
     38        * bytecode/UnlinkedMetadataTable.h:
     39        * bytecode/UnlinkedModuleProgramCodeBlock.h:
     40        * bytecode/UnlinkedProgramCodeBlock.h:
     41        * interpreter/Interpreter.cpp:
     42        * jsc.cpp:
     43        (functionQuit):
     44        (runJSC):
     45        * parser/SourceCode.h:
     46        * parser/SourceCodeKey.h:
     47        (JSC::SourceCodeKey::operator!= const):
     48        * parser/UnlinkedSourceCode.h:
     49        * parser/VariableEnvironment.h:
     50        * runtime/CachedTypes.cpp: Added.
     51        (JSC::Encoder::Allocation::buffer const):
     52        (JSC::Encoder::Allocation::offset const):
     53        (JSC::Encoder::Allocation::Allocation):
     54        (JSC::Encoder::Encoder):
     55        (JSC::Encoder::vm):
     56        (JSC::Encoder::malloc):
     57        (JSC::Encoder::offsetOf):
     58        (JSC::Encoder::cachePtr):
     59        (JSC::Encoder::offsetForPtr):
     60        (JSC::Encoder::release):
     61        (JSC::Encoder::Page::Page):
     62        (JSC::Encoder::Page::malloc):
     63        (JSC::Encoder::Page::buffer const):
     64        (JSC::Encoder::Page::size const):
     65        (JSC::Encoder::Page::getOffset const):
     66        (JSC::Encoder::allocateNewPage):
     67        (JSC::Decoder::Decoder):
     68        (JSC::Decoder::~Decoder):
     69        (JSC::Decoder::vm):
     70        (JSC::Decoder::offsetOf):
     71        (JSC::Decoder::cacheOffset):
     72        (JSC::Decoder::addFinalizer):
     73        (JSC::encode):
     74        (JSC::decode):
     75        (JSC::VariableLengthObject::buffer const):
     76        (JSC::VariableLengthObject::allocate):
     77        (JSC::CachedPtr::encode):
     78        (JSC::CachedPtr::decode const):
     79        (JSC::CachedPtr::operator-> const):
     80        (JSC::CachedPtr::get const):
     81        (JSC::CachedRefPtr::encode):
     82        (JSC::CachedRefPtr::decode const):
     83        (JSC::CachedWriteBarrier::encode):
     84        (JSC::CachedWriteBarrier::decode const):
     85        (JSC::CachedVector::encode):
     86        (JSC::CachedVector::decode const):
     87        (JSC::CachedPair::encode):
     88        (JSC::CachedPair::decode const):
     89        (JSC::CachedHashMap::encode):
     90        (JSC::CachedHashMap::decode const):
     91        (JSC::CachedUniquedStringImpl::encode):
     92        (JSC::CachedUniquedStringImpl::decode const):
     93        (JSC::CachedStringImpl::encode):
     94        (JSC::CachedStringImpl::decode const):
     95        (JSC::CachedString::encode):
     96        (JSC::CachedString::decode const):
     97        (JSC::CachedIdentifier::encode):
     98        (JSC::CachedIdentifier::decode const):
     99        (JSC::CachedOptional::encode):
     100        (JSC::CachedOptional::decode const):
     101        (JSC::CachedOptional::decodeAsPtr const):
     102        (JSC::CachedSimpleJumpTable::encode):
     103        (JSC::CachedSimpleJumpTable::decode const):
     104        (JSC::CachedStringJumpTable::encode):
     105        (JSC::CachedStringJumpTable::decode const):
     106        (JSC::CachedCodeBlockRareData::encode):
     107        (JSC::CachedCodeBlockRareData::decode const):
     108        (JSC::CachedBitVector::encode):
     109        (JSC::CachedBitVector::decode const):
     110        (JSC::CachedHashSet::encode):
     111        (JSC::CachedHashSet::decode const):
     112        (JSC::CachedConstantIdentifierSetEntry::encode):
     113        (JSC::CachedConstantIdentifierSetEntry::decode const):
     114        (JSC::CachedVariableEnvironment::encode):
     115        (JSC::CachedVariableEnvironment::decode const):
     116        (JSC::CachedArray::encode):
     117        (JSC::CachedArray::decode const):
     118        (JSC::CachedScopedArgumentsTable::encode):
     119        (JSC::CachedScopedArgumentsTable::decode const):
     120        (JSC::CachedSymbolTableEntry::encode):
     121        (JSC::CachedSymbolTableEntry::decode const):
     122        (JSC::CachedSymbolTable::encode):
     123        (JSC::CachedSymbolTable::decode const):
     124        (JSC::CachedImmutableButterfly::encode):
     125        (JSC::CachedImmutableButterfly::decode const):
     126        (JSC::CachedRegExp::encode):
     127        (JSC::CachedRegExp::decode const):
     128        (JSC::CachedTemplateObjectDescriptor::encode):
     129        (JSC::CachedTemplateObjectDescriptor::decode const):
     130        (JSC::CachedBigInt::encode):
     131        (JSC::CachedBigInt::decode const):
     132        (JSC::CachedJSValue::encode):
     133        (JSC::CachedJSValue::decode const):
     134        (JSC::CachedInstructionStream::encode):
     135        (JSC::CachedInstructionStream::decode const):
     136        (JSC::CachedMetadataTable::encode):
     137        (JSC::CachedMetadataTable::decode const):
     138        (JSC::CachedSourceOrigin::encode):
     139        (JSC::CachedSourceOrigin::decode const):
     140        (JSC::CachedTextPosition::encode):
     141        (JSC::CachedTextPosition::decode const):
     142        (JSC::CachedSourceProviderShape::encode):
     143        (JSC::CachedSourceProviderShape::decode const):
     144        (JSC::CachedStringSourceProvider::encode):
     145        (JSC::CachedStringSourceProvider::decode const):
     146        (JSC::CachedWebAssemblySourceProvider::encode):
     147        (JSC::CachedWebAssemblySourceProvider::decode const):
     148        (JSC::CachedSourceProvider::encode):
     149        (JSC::CachedSourceProvider::decode const):
     150        (JSC::CachedUnlinkedSourceCodeShape::encode):
     151        (JSC::CachedUnlinkedSourceCodeShape::decode const):
     152        (JSC::CachedSourceCode::encode):
     153        (JSC::CachedSourceCode::decode const):
     154        (JSC::CachedFunctionExecutable::firstLineOffset const):
     155        (JSC::CachedFunctionExecutable::lineCount const):
     156        (JSC::CachedFunctionExecutable::unlinkedFunctionNameStart const):
     157        (JSC::CachedFunctionExecutable::unlinkedBodyStartColumn const):
     158        (JSC::CachedFunctionExecutable::unlinkedBodyEndColumn const):
     159        (JSC::CachedFunctionExecutable::startOffset const):
     160        (JSC::CachedFunctionExecutable::sourceLength const):
     161        (JSC::CachedFunctionExecutable::parametersStartOffset const):
     162        (JSC::CachedFunctionExecutable::typeProfilingStartOffset const):
     163        (JSC::CachedFunctionExecutable::typeProfilingEndOffset const):
     164        (JSC::CachedFunctionExecutable::parameterCount const):
     165        (JSC::CachedFunctionExecutable::features const):
     166        (JSC::CachedFunctionExecutable::sourceParseMode const):
     167        (JSC::CachedFunctionExecutable::isInStrictContext const):
     168        (JSC::CachedFunctionExecutable::hasCapturedVariables const):
     169        (JSC::CachedFunctionExecutable::isBuiltinFunction const):
     170        (JSC::CachedFunctionExecutable::isBuiltinDefaultClassConstructor const):
     171        (JSC::CachedFunctionExecutable::constructAbility const):
     172        (JSC::CachedFunctionExecutable::constructorKind const):
     173        (JSC::CachedFunctionExecutable::functionMode const):
     174        (JSC::CachedFunctionExecutable::scriptMode const):
     175        (JSC::CachedFunctionExecutable::superBinding const):
     176        (JSC::CachedFunctionExecutable::derivedContextType const):
     177        (JSC::CachedFunctionExecutable::name const):
     178        (JSC::CachedFunctionExecutable::ecmaName const):
     179        (JSC::CachedFunctionExecutable::inferredName const):
     180        (JSC::CachedCodeBlock::instructions const):
     181        (JSC::CachedCodeBlock::thisRegister const):
     182        (JSC::CachedCodeBlock::scopeRegister const):
     183        (JSC::CachedCodeBlock::globalObjectRegister const):
     184        (JSC::CachedCodeBlock::sourceURLDirective const):
     185        (JSC::CachedCodeBlock::sourceMappingURLDirective const):
     186        (JSC::CachedCodeBlock::usesEval const):
     187        (JSC::CachedCodeBlock::isStrictMode const):
     188        (JSC::CachedCodeBlock::isConstructor const):
     189        (JSC::CachedCodeBlock::hasCapturedVariables const):
     190        (JSC::CachedCodeBlock::isBuiltinFunction const):
     191        (JSC::CachedCodeBlock::superBinding const):
     192        (JSC::CachedCodeBlock::scriptMode const):
     193        (JSC::CachedCodeBlock::isArrowFunctionContext const):
     194        (JSC::CachedCodeBlock::isClassContext const):
     195        (JSC::CachedCodeBlock::wasCompiledWithDebuggingOpcodes const):
     196        (JSC::CachedCodeBlock::constructorKind const):
     197        (JSC::CachedCodeBlock::derivedContextType const):
     198        (JSC::CachedCodeBlock::evalContextType const):
     199        (JSC::CachedCodeBlock::hasTailCalls const):
     200        (JSC::CachedCodeBlock::lineCount const):
     201        (JSC::CachedCodeBlock::endColumn const):
     202        (JSC::CachedCodeBlock::numVars const):
     203        (JSC::CachedCodeBlock::numCalleeLocals const):
     204        (JSC::CachedCodeBlock::numParameters const):
     205        (JSC::CachedCodeBlock::features const):
     206        (JSC::CachedCodeBlock::parseMode const):
     207        (JSC::CachedCodeBlock::codeType const):
     208        (JSC::CachedCodeBlock::rareData const):
     209        (JSC::CachedProgramCodeBlock::encode):
     210        (JSC::CachedProgramCodeBlock::decode const):
     211        (JSC::CachedModuleCodeBlock::encode):
     212        (JSC::CachedModuleCodeBlock::decode const):
     213        (JSC::CachedEvalCodeBlock::encode):
     214        (JSC::CachedEvalCodeBlock::decode const):
     215        (JSC::CachedFunctionCodeBlock::encode):
     216        (JSC::CachedFunctionCodeBlock::decode const):
     217        (JSC::UnlinkedFunctionCodeBlock::UnlinkedFunctionCodeBlock):
     218        (JSC::UnlinkedCodeBlock::UnlinkedCodeBlock):
     219        (JSC::CachedCodeBlock<CodeBlockType>::decode const):
     220        (JSC::UnlinkedProgramCodeBlock::UnlinkedProgramCodeBlock):
     221        (JSC::UnlinkedModuleProgramCodeBlock::UnlinkedModuleProgramCodeBlock):
     222        (JSC::UnlinkedEvalCodeBlock::UnlinkedEvalCodeBlock):
     223        (JSC::CachedFunctionExecutable::encode):
     224        (JSC::CachedFunctionExecutable::decode const):
     225        (JSC::UnlinkedFunctionExecutable::UnlinkedFunctionExecutable):
     226        (JSC::CachedCodeBlock<CodeBlockType>::encode):
     227        (JSC::CachedSourceCodeKey::encode):
     228        (JSC::CachedSourceCodeKey::decode const):
     229        (JSC::CacheEntry::encode):
     230        (JSC::CacheEntry:: const):
     231        (JSC:: const):
     232        (JSC::encodeCodeBlock):
     233        (JSC::decodeCodeBlockImpl):
     234        * runtime/CachedTypes.h: Copied from Source/JavaScriptCore/bytecode/UnlinkedGlobalCodeBlock.h.
     235        (JSC::decodeCodeBlock):
     236        * runtime/CodeCache.cpp:
     237        (JSC::CodeCacheMap::pruneSlowCase):
     238        (JSC::CodeCache::getUnlinkedGlobalCodeBlock):
     239        (JSC::CodeCache::getUnlinkedGlobalFunctionExecutable):
     240        (JSC::CodeCache::write):
     241        * runtime/CodeCache.h:
     242        (JSC::CodeCacheMap::begin):
     243        (JSC::CodeCacheMap::end):
     244        (JSC::CodeCacheMap::fetchFromDiskImpl):
     245        (JSC::CodeCacheMap::findCacheAndUpdateAge):
     246        (JSC::writeCodeBlock):
     247        * runtime/JSBigInt.cpp:
     248        * runtime/JSBigInt.h:
     249        * runtime/Options.cpp:
     250        (JSC::recomputeDependentOptions):
     251        * runtime/Options.h:
     252        * runtime/RegExp.h:
     253        * runtime/ScopedArgumentsTable.h:
     254        * runtime/StackFrame.h:
     255        * runtime/StructureInlines.h:
     256        * runtime/SymbolTable.h:
     257
    12582019-01-20  Antoine Quint  <graouts@apple.com>
    2259
  • trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r240114 r240210  
    827827                2684D4381C00161C0081D663 /* AirLiveness.h in Headers */ = {isa = PBXBuildFile; fileRef = 2684D4371C00161C0081D663 /* AirLiveness.h */; };
    828828                269D636E1BFBE5D100101B1D /* FTLOutput.h in Headers */ = {isa = PBXBuildFile; fileRef = 269D636D1BFBE5D000101B1D /* FTLOutput.h */; };
    829                 2A05ABD61961DF2400341750 /* JSPropertyNameEnumerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 2A05ABD41961DF2400341750 /* JSPropertyNameEnumerator.h */; };
     829                2A05ABD61961DF2400341750 /* JSPropertyNameEnumerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 2A05ABD41961DF2400341750 /* JSPropertyNameEnumerator.h */; settings = {ATTRIBUTES = (Private, ); }; };
    830830                2A111246192FCE79005EE18D /* CustomGetterSetter.h in Headers */ = {isa = PBXBuildFile; fileRef = 2A111244192FCE79005EE18D /* CustomGetterSetter.h */; settings = {ATTRIBUTES = (Private, ); }; };
    831831                2A48D1911772365B00C65A5F /* APICallbackFunction.h in Headers */ = {isa = PBXBuildFile; fileRef = C211B574176A224D000E2A23 /* APICallbackFunction.h */; };
     
    10631063                53EE01B6218F691600AD1F8D /* JSScript.h in Headers */ = {isa = PBXBuildFile; fileRef = 53EE01B5218F690F00AD1F8D /* JSScript.h */; settings = {ATTRIBUTES = (Private, ); }; };
    10641064                53EE01B8218F7EFF00AD1F8D /* JSScriptInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 53EE01B7218F7EFF00AD1F8D /* JSScriptInternal.h */; };
    1065                 53F11F41209138D700E411A7 /* JSImmutableButterfly.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F11F40209138D700E411A7 /* JSImmutableButterfly.h */; };
     1065                53F11F41209138D700E411A7 /* JSImmutableButterfly.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F11F40209138D700E411A7 /* JSImmutableButterfly.h */; settings = {ATTRIBUTES = (Private, ); }; };
    10661066                53F40E851D58F9770099A1B6 /* WasmSections.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E841D58F9770099A1B6 /* WasmSections.h */; };
    10671067                53F40E8B1D5901BB0099A1B6 /* WasmFunctionParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E8A1D5901BB0099A1B6 /* WasmFunctionParser.h */; };
     
    31293129                14386A761DD6989C008652C4 /* IndirectEvalExecutable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IndirectEvalExecutable.cpp; sourceTree = "<group>"; };
    31303130                14386A771DD6989C008652C4 /* IndirectEvalExecutable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IndirectEvalExecutable.h; sourceTree = "<group>"; };
     3131                143BE26521C857770020CD17 /* CachedTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CachedTypes.h; sourceTree = "<group>"; };
    31313132                1440051F0A531D3B0005F061 /* Node.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Node.h; path = tests/Node.h; sourceTree = "<group>"; };
    31323133                144005200A531D3B0005F061 /* Node.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = Node.c; path = tests/Node.c; sourceTree = "<group>"; };
     
    32433244                14DA818E0D99FD2000B0A4FB /* JSLexicalEnvironment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSLexicalEnvironment.h; sourceTree = "<group>"; };
    32443245                14DA818F0D99FD2000B0A4FB /* JSLexicalEnvironment.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSLexicalEnvironment.cpp; sourceTree = "<group>"; };
     3246                14DAFA4521E3B871004B68F7 /* CachedTypes.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CachedTypes.cpp; sourceTree = "<group>"; };
    32453247                14DE0D680D02431400AACCA2 /* JSGlobalObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = JSGlobalObject.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
    32463248                14DF04D916B3996D0016A513 /* StaticPropertyAnalysis.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StaticPropertyAnalysis.h; sourceTree = "<group>"; };
     
    66016603                                0FB7F38B15ED8E3800F167B2 /* Butterfly.h */,
    66026604                                0FB7F38C15ED8E3800F167B2 /* ButterflyInlines.h */,
     6605                                14DAFA4521E3B871004B68F7 /* CachedTypes.cpp */,
     6606                                143BE26521C857770020CD17 /* CachedTypes.h */,
    66036607                                0FEC3C5F1F379F5300F59B6C /* CagedBarrierPtr.h */,
    66046608                                BCA62DFE0E2826230004F30D /* CallData.cpp */,
  • trunk/Source/JavaScriptCore/Sources.txt

    r240023 r240210  
    714714runtime/BooleanPrototype.cpp
    715715runtime/CallData.cpp
     716runtime/CachedTypes.cpp
    716717runtime/CatchScope.cpp
    717718runtime/ClassInfo.cpp
  • trunk/Source/JavaScriptCore/builtins/BuiltinNames.cpp

    r231565 r240210  
    6464    JSC_FOREACH_BUILTIN_FUNCTION_NAME(INITIALIZE_PUBLIC_TO_PRIVATE_ENTRY)
    6565    JSC_COMMON_PRIVATE_IDENTIFIERS_EACH_PROPERTY_NAME(INITIALIZE_PUBLIC_TO_PRIVATE_ENTRY)
     66    JSC_COMMON_PRIVATE_IDENTIFIERS_EACH_WELL_KNOWN_SYMBOL(INITIALIZE_SYMBOL_PRIVATE_TO_PUBLIC_ENTRY)
    6667    JSC_COMMON_PRIVATE_IDENTIFIERS_EACH_WELL_KNOWN_SYMBOL(INITIALIZE_SYMBOL_PUBLIC_TO_PRIVATE_ENTRY)
    6768    m_privateToPublicMap.add(m_dollarVMPrivateName.impl(), &m_dollarVMName);
  • trunk/Source/JavaScriptCore/builtins/BuiltinNames.h

    r231565 r240210  
    214214// e.g. @iteratorSymbol points to Symbol.iterator in this map rather than to a an actual private name.
    215215// FIXME: This is a weird hack and we shouldn't need to do this.
     216#define INITIALIZE_SYMBOL_PRIVATE_TO_PUBLIC_ENTRY(name) m_privateToPublicMap.add(m_##name##Symbol.impl(), &m_##name##SymbolPrivateIdentifier);
    216217#define INITIALIZE_SYMBOL_PUBLIC_TO_PRIVATE_ENTRY(name) m_publicToPrivateMap.add(m_##name##SymbolPrivateIdentifier.impl(), &m_##name##Symbol);
    217218
  • trunk/Source/JavaScriptCore/bytecode/CodeBlock.cpp

    r240138 r240210  
    870870}
    871871
    872 void CodeBlock::setConstantIdentifierSetRegisters(VM& vm, const Vector<ConstantIndentifierSetEntry>& constants)
     872void CodeBlock::setConstantIdentifierSetRegisters(VM& vm, const Vector<ConstantIdentifierSetEntry>& constants)
    873873{
    874874    auto scope = DECLARE_THROW_SCOPE(vm);
  • trunk/Source/JavaScriptCore/bytecode/CodeBlock.h

    r239879 r240210  
    891891    void updateAllPredictionsAndCountLiveness(unsigned& numberOfLiveNonArgumentValueProfiles, unsigned& numberOfSamplesInProfiles);
    892892
    893     void setConstantIdentifierSetRegisters(VM&, const Vector<ConstantIndentifierSetEntry>& constants);
     893    void setConstantIdentifierSetRegisters(VM&, const Vector<ConstantIdentifierSetEntry>& constants);
    894894
    895895    void setConstantRegisters(const Vector<WriteBarrier<Unknown>>& constants, const Vector<SourceCodeRepresentation>& constantsSourceCodeRepresentation);
  • trunk/Source/JavaScriptCore/bytecode/HandlerInfo.h

    r230748 r240210  
    9090
    9191struct UnlinkedHandlerInfo : public HandlerInfoBase {
     92    UnlinkedHandlerInfo()
     93    {
     94    }
     95
    9296    UnlinkedHandlerInfo(uint32_t start, uint32_t end, uint32_t target, HandlerType handlerType)
    9397    {
  • trunk/Source/JavaScriptCore/bytecode/InstructionStream.h

    r238414 r240210  
    4040
    4141    friend class InstructionStreamWriter;
     42    friend class CachedInstructionStream;
    4243public:
    4344    size_t sizeInBytes() const;
  • trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.h

    r237547 r240210  
    6666struct ExecutableInfo;
    6767
     68template<typename CodeBlockType>
     69class CachedCodeBlock;
     70
    6871typedef unsigned UnlinkedValueProfile;
    6972typedef unsigned UnlinkedArrayProfile;
     
    7174typedef unsigned UnlinkedObjectAllocationProfile;
    7275typedef unsigned UnlinkedLLIntCallLinkInfo;
    73 using ConstantIndentifierSetEntry = std::pair<IdentifierSet, unsigned>;
     76using ConstantIdentifierSetEntry = std::pair<IdentifierSet, unsigned>;
    7477
    7578struct UnlinkedStringJumpTable {
     
    169172        m_constantRegisters.append(WriteBarrier<Unknown>());
    170173        m_constantsSourceCodeRepresentation.append(SourceCodeRepresentation::Other);
    171         m_constantIdentifierSets.append(ConstantIndentifierSetEntry(set, result));
     174        m_constantIdentifierSets.append(ConstantIdentifierSetEntry(set, result));
    172175    }
    173176
     
    203206    }
    204207    const Vector<WriteBarrier<Unknown>>& constantRegisters() { return m_constantRegisters; }
    205     const Vector<ConstantIndentifierSetEntry>& constantIdentifierSets() { return m_constantIdentifierSets; }
     208    const Vector<ConstantIdentifierSetEntry>& constantIdentifierSets() { return m_constantIdentifierSets; }
    206209    const WriteBarrier<Unknown>& constantRegister(int index) const { return m_constantRegisters[index - FirstConstantRegisterIndex]; }
    207210    ALWAYS_INLINE bool isConstantRegisterIndex(int index) const { return index >= FirstConstantRegisterIndex; }
     
    368371protected:
    369372    UnlinkedCodeBlock(VM*, Structure*, CodeType, const ExecutableInfo&, DebuggerMode);
     373
     374    template<typename CodeBlockType>
     375    UnlinkedCodeBlock(Decoder&, Structure*, const CachedCodeBlock<CodeBlockType>&);
     376
    370377    ~UnlinkedCodeBlock();
    371378
     
    378385    friend class BytecodeRewriter;
    379386    friend class BytecodeGenerator;
     387
     388    template<typename CodeBlockType>
     389    friend class CachedCodeBlock;
    380390
    381391    void applyModification(BytecodeRewriter&, InstructionStreamWriter&);
     
    445455    Vector<BitVector> m_bitVectors;
    446456    Vector<WriteBarrier<Unknown>> m_constantRegisters;
    447     Vector<ConstantIndentifierSetEntry> m_constantIdentifierSets;
     457    Vector<ConstantIdentifierSetEntry> m_constantIdentifierSets;
    448458    Vector<SourceCodeRepresentation> m_constantsSourceCodeRepresentation;
    449459    typedef Vector<WriteBarrier<UnlinkedFunctionExecutable>> FunctionExpressionVector;
  • trunk/Source/JavaScriptCore/bytecode/UnlinkedEvalCodeBlock.h

    r215984 r240210  
    3030namespace JSC {
    3131
     32class CachedEvalCodeBlock;
     33
    3234class UnlinkedEvalCodeBlock final : public UnlinkedGlobalCodeBlock {
    3335public:
     
    6062    }
    6163private:
     64    friend CachedEvalCodeBlock;
     65
    6266    UnlinkedEvalCodeBlock(VM* vm, Structure* structure, const ExecutableInfo& info, DebuggerMode debuggerMode)
    6367        : Base(vm, structure, EvalCode, info, debuggerMode)
    6468    {
    6569    }
     70
     71    UnlinkedEvalCodeBlock(Decoder&, const CachedEvalCodeBlock&);
    6672
    6773    Vector<Identifier, 0, UnsafeVectorOverflow> m_variables;
  • trunk/Source/JavaScriptCore/bytecode/UnlinkedFunctionCodeBlock.h

    r208312 r240210  
    3030namespace JSC {
    3131
     32class CachedFunctionCodeBlock;
     33
    3234class UnlinkedFunctionCodeBlock final : public UnlinkedCodeBlock {
    3335public:
     
    4547
    4648private:
     49    friend CachedFunctionCodeBlock;
     50
    4751    UnlinkedFunctionCodeBlock(VM* vm, Structure* structure, CodeType codeType, const ExecutableInfo& info, DebuggerMode debuggerMode)
    4852        : Base(vm, structure, codeType, info, debuggerMode)
    4953    {
    5054    }
     55
     56    UnlinkedFunctionCodeBlock(Decoder&, const CachedFunctionCodeBlock&);
    5157   
    5258public:
  • trunk/Source/JavaScriptCore/bytecode/UnlinkedFunctionExecutable.h

    r239427 r240210  
    4040namespace JSC {
    4141
     42class Decoder;
    4243class FunctionMetadataNode;
    4344class FunctionExecutable;
     
    4546class SourceProvider;
    4647class UnlinkedFunctionCodeBlock;
     48class CachedFunctionExecutable;
    4749
    4850enum UnlinkedFunctionKind {
     
    5557    friend class CodeCache;
    5658    friend class VM;
     59    friend CachedFunctionExecutable;
    5760
    5861    typedef JSCell Base;
     
    148151private:
    149152    UnlinkedFunctionExecutable(VM*, Structure*, const SourceCode&, FunctionMetadataNode*, UnlinkedFunctionKind, ConstructAbility, JSParserScriptMode, VariableEnvironment&,  JSC::DerivedContextType, bool isBuiltinDefaultClassConstructor);
     153    UnlinkedFunctionExecutable(Decoder&, VariableEnvironment&, const CachedFunctionExecutable&);
    150154
    151155    unsigned m_firstLineOffset;
  • trunk/Source/JavaScriptCore/bytecode/UnlinkedGlobalCodeBlock.h

    r208312 r240210  
    3939    {
    4040    }
     41
     42    template<typename CodeBlockType>
     43    UnlinkedGlobalCodeBlock(Decoder& decoder, Structure* structure, const CachedCodeBlock<CodeBlockType>& cachedCodeBlock)
     44        : Base(decoder, structure, cachedCodeBlock)
     45    {
     46    }
    4147};
    4248
  • trunk/Source/JavaScriptCore/bytecode/UnlinkedMetadataTable.h

    r237987 r240210  
    3636    friend class LLIntOffsetsExtractor;
    3737    friend class MetadataTable;
     38    friend class CachedMetadataTable;
    3839
    3940public:
  • trunk/Source/JavaScriptCore/bytecode/UnlinkedModuleProgramCodeBlock.h

    r217645 r240210  
    2929
    3030namespace JSC {
     31
     32class Decoder;
     33class CachedModuleCodeBlock;
    3134
    3235class UnlinkedModuleProgramCodeBlock final : public UnlinkedGlobalCodeBlock {
     
    7578
    7679private:
     80    friend CachedModuleCodeBlock;
     81
    7782    UnlinkedModuleProgramCodeBlock(VM* vm, Structure* structure, const ExecutableInfo& info, DebuggerMode debuggerMode)
    7883        : Base(vm, structure, ModuleCode, info, debuggerMode)
    7984    {
    8085    }
     86
     87    UnlinkedModuleProgramCodeBlock(Decoder&, const CachedModuleCodeBlock&);
    8188
    8289    int m_moduleEnvironmentSymbolTableConstantRegisterOffset { 0 };
  • trunk/Source/JavaScriptCore/bytecode/UnlinkedProgramCodeBlock.h

    r217645 r240210  
    3030namespace JSC {
    3131
     32class CachedProgramCodeBlock;
     33
    3234class UnlinkedProgramCodeBlock final : public UnlinkedGlobalCodeBlock {
    3335public:
     
    5153
    5254private:
     55    friend CachedProgramCodeBlock;
     56
    5357    UnlinkedProgramCodeBlock(VM* vm, Structure* structure, const ExecutableInfo& info, DebuggerMode debuggerMode)
    5458        : Base(vm, structure, GlobalCode, info, debuggerMode)
    5559    {
    5660    }
     61
     62    UnlinkedProgramCodeBlock(Decoder&, const CachedProgramCodeBlock&);
    5763
    5864    VariableEnvironment m_varDeclarations;
  • trunk/Source/JavaScriptCore/interpreter/Interpreter.cpp

    r237547 r240210  
    3636#include "CatchScope.h"
    3737#include "CodeBlock.h"
     38#include "CodeCache.h"
    3839#include "DirectArguments.h"
    3940#include "Heap.h"
  • trunk/Source/JavaScriptCore/jsc.cpp

    r240113 r240210  
    2929#include "CatchScope.h"
    3030#include "CodeBlock.h"
     31#include "CodeCache.h"
    3132#include "Completion.h"
    3233#include "ConfigFile.h"
     
    19891990}
    19901991
    1991 EncodedJSValue JSC_HOST_CALL functionQuit(ExecState*)
    1992 {
     1992EncodedJSValue JSC_HOST_CALL functionQuit(ExecState* exec)
     1993{
     1994    VM& vm = exec->vm();
     1995    vm.codeCache()->write(vm);
     1996
    19931997    jscExit(EXIT_SUCCESS);
    19941998
     
    28772881    }
    28782882
     2883    vm.codeCache()->write(vm);
     2884
    28792885    if (isWorker) {
    28802886        JSLockHolder locker(vm);
  • trunk/Source/JavaScriptCore/parser/SourceCode.h

    r239569 r240210  
    3434
    3535    class SourceCode : public UnlinkedSourceCode {
     36        friend class CachedSourceCode;
     37
    3638    public:
    3739        SourceCode()
  • trunk/Source/JavaScriptCore/parser/SourceCodeKey.h

    r239461 r240210  
    3838
    3939class SourceCodeFlags {
     40    friend class CachedSourceCodeKey;
     41
    4042public:
    4143    SourceCodeFlags() = default;
     
    7173
    7274class SourceCodeKey {
     75    friend class CachedSourceCodeKey;
     76
    7377public:
    7478    SourceCodeKey()
     
    115119    }
    116120
     121    bool operator!=(const SourceCodeKey& other) const
     122    {
     123        return !(*this == other);
     124    }
     125
    117126    struct Hash {
    118127        static unsigned hash(const SourceCodeKey& key) { return key.hash(); }
  • trunk/Source/JavaScriptCore/parser/UnlinkedSourceCode.h

    r227527 r240210  
    3636
    3737    class UnlinkedSourceCode {
     38        template<typename SourceType>
     39        friend class CachedUnlinkedSourceCodeShape;
     40
    3841    public:
    3942        UnlinkedSourceCode()
  • trunk/Source/JavaScriptCore/parser/VariableEnvironment.h

    r231477 r240210  
    117117
    118118private:
     119    friend class CachedVariableEnvironment;
     120
    119121    Map m_map;
    120122    bool m_isEverythingCaptured { false };
  • trunk/Source/JavaScriptCore/runtime/CachedTypes.h

    r240209 r240210  
    11/*
    2  * Copyright (C) 2012-2016 Apple Inc. All Rights Reserved.
     2 * Copyright (C) 2018 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2626#pragma once
    2727
    28 #include "UnlinkedCodeBlock.h"
     28#include "JSCast.h"
     29#include <wtf/MallocPtr.h>
    2930
    3031namespace JSC {
    3132
    32 class UnlinkedGlobalCodeBlock : public UnlinkedCodeBlock {
    33 public:
    34     typedef UnlinkedCodeBlock Base;
     33class SourceCodeKey;
     34class UnlinkedCodeBlock;
    3535
    36 protected:
    37     UnlinkedGlobalCodeBlock(VM* vm, Structure* structure, CodeType codeType, const ExecutableInfo& info, DebuggerMode debuggerMode)
    38         : Base(vm, structure, codeType, info, debuggerMode)
    39     {
    40     }
    41 };
     36std::pair<MallocPtr<uint8_t>, size_t> encodeCodeBlock(VM&, const SourceCodeKey&, const UnlinkedCodeBlock*);
     37UnlinkedCodeBlock* decodeCodeBlockImpl(VM&, const SourceCodeKey&, const void*, size_t);
    4238
     39
     40template<typename UnlinkedCodeBlockType>
     41UnlinkedCodeBlockType* decodeCodeBlock(VM& vm, const SourceCodeKey& key, const void* buffer, size_t size)
     42{
     43    return jsCast<UnlinkedCodeBlockType*>(decodeCodeBlockImpl(vm, key, buffer, size));
    4344}
     45
     46} // namespace JSC
  • trunk/Source/JavaScriptCore/runtime/CodeCache.cpp

    r239427 r240210  
    4444    while (m_size > m_capacity || !canPruneQuickly()) {
    4545        MapType::iterator it = m_map.begin();
     46
     47        writeCodeBlock(*it->value.cell->vm(), it->key, it->value);
     48
    4649        m_size -= it->key.length();
    4750        m_map.remove(it);
     
    6063        vm.controlFlowProfiler() ? ControlFlowProfilerEnabled::Yes : ControlFlowProfilerEnabled::No,
    6164        WTF::nullopt);
    62     SourceCodeValue* cache = m_sourceCode.findCacheAndUpdateAge(key);
    63     if (cache && Options::useCodeCache()) {
    64         UnlinkedCodeBlockType* unlinkedCodeBlock = jsCast<UnlinkedCodeBlockType*>(cache->cell.get());
     65    UnlinkedCodeBlockType* unlinkedCodeBlock = m_sourceCode.findCacheAndUpdateAge<UnlinkedCodeBlockType>(vm, key);
     66    if (unlinkedCodeBlock && Options::useCodeCache()) {
    6567        unsigned lineCount = unlinkedCodeBlock->lineCount();
    6668        unsigned startColumn = unlinkedCodeBlock->startColumn() + source.startColumn().oneBasedInt();
     
    7274        return unlinkedCodeBlock;
    7375    }
    74    
     76
    7577    VariableEnvironment variablesUnderTDZ;
    76     UnlinkedCodeBlockType* unlinkedCodeBlock = generateUnlinkedCodeBlock<UnlinkedCodeBlockType, ExecutableType>(vm, executable, source, strictMode, scriptMode, debuggerMode, error, evalContextType, &variablesUnderTDZ);
     78    unlinkedCodeBlock = generateUnlinkedCodeBlock<UnlinkedCodeBlockType, ExecutableType>(vm, executable, source, strictMode, scriptMode, debuggerMode, error, evalContextType, &variablesUnderTDZ);
    7779
    7880    if (unlinkedCodeBlock && Options::useCodeCache())
     
    111113        vm.controlFlowProfiler() ? ControlFlowProfilerEnabled::Yes : ControlFlowProfilerEnabled::No,
    112114        functionConstructorParametersEndPosition);
    113     SourceCodeValue* cache = m_sourceCode.findCacheAndUpdateAge(key);
    114     if (cache && Options::useCodeCache()) {
    115         UnlinkedFunctionExecutable* executable = jsCast<UnlinkedFunctionExecutable*>(cache->cell.get());
     115    UnlinkedFunctionExecutable* executable = m_sourceCode.findCacheAndUpdateAge<UnlinkedFunctionExecutable>(vm, key);
     116    if (executable && Options::useCodeCache()) {
    116117        source.provider()->setSourceURLDirective(executable->sourceURLDirective());
    117118        source.provider()->setSourceMappingURLDirective(executable->sourceMappingURLDirective());
     
    156157}
    157158
     159void CodeCache::write(VM& vm)
     160{
     161    for (const auto& it : m_sourceCode)
     162        writeCodeBlock(vm, it.key, it.value);
    158163}
     164
     165}
  • trunk/Source/JavaScriptCore/runtime/CodeCache.h

    r239427 r240210  
    2727
    2828#include "BytecodeGenerator.h"
     29#include "CachedTypes.h"
    2930#include "ExecutableInfo.h"
    3031#include "JSCInlines.h"
     
    3839#include "UnlinkedModuleProgramCodeBlock.h"
    3940#include "UnlinkedProgramCodeBlock.h"
     41#include <sys/stat.h>
    4042#include <wtf/Forward.h>
    4143#include <wtf/text/WTFString.h>
     
    9092    }
    9193
    92     SourceCodeValue* findCacheAndUpdateAge(const SourceCodeKey& key)
     94    iterator begin() { return m_map.begin(); }
     95    iterator end() { return m_map.end(); }
     96
     97    template<typename UnlinkedCodeBlockType>
     98    UnlinkedCodeBlockType* fetchFromDiskImpl(VM& vm, const SourceCodeKey& key)
     99    {
     100#if OS(DARWIN)
     101        const char* cachePath = Options::diskCachePath();
     102        if (!cachePath)
     103            return nullptr;
     104
     105        unsigned hash = key.hash();
     106        char filename[512];
     107        int count = snprintf(filename, 512, "%s/%u.cache", cachePath, hash);
     108        if (count < 0 || count > 512)
     109            return nullptr;
     110
     111        int fd = open(filename, O_RDONLY);
     112        if (fd == -1)
     113            return nullptr;
     114
     115        int rc = flock(fd, LOCK_SH | LOCK_NB);
     116        if (rc) {
     117            close(fd);
     118            return nullptr;
     119        }
     120
     121        struct stat sb;
     122        int res = fstat(fd, &sb);
     123        size_t size = static_cast<size_t>(sb.st_size);
     124        if (res || !size)
     125            return nullptr;
     126
     127        const void* buffer = mmap(nullptr, size, PROT_READ, MAP_PRIVATE, fd, 0);
     128        UnlinkedCodeBlockType* unlinkedCodeBlock = decodeCodeBlock<UnlinkedCodeBlockType>(vm, key, buffer, size);
     129
     130        if (!unlinkedCodeBlock)
     131            return nullptr;
     132
     133        addCache(key, SourceCodeValue(vm, unlinkedCodeBlock, m_age));
     134        return unlinkedCodeBlock;
     135#else
     136        UNUSED_PARAM(vm);
     137        UNUSED_PARAM(key);
     138        return nullptr;
     139#endif
     140    }
     141
     142    template<typename UnlinkedCodeBlockType>
     143    std::enable_if_t<std::is_base_of<UnlinkedCodeBlock, UnlinkedCodeBlockType>::value && !std::is_same<UnlinkedCodeBlockType, UnlinkedEvalCodeBlock>::value, UnlinkedCodeBlockType*>
     144    fetchFromDisk(VM& vm, const SourceCodeKey& key)
     145    {
     146        UnlinkedCodeBlockType* codeBlock = fetchFromDiskImpl<UnlinkedCodeBlockType>(vm, key);
     147        if (UNLIKELY(Options::forceDiskCache()))
     148            RELEASE_ASSERT(codeBlock);
     149        return codeBlock;
     150    }
     151
     152    template<typename T>
     153    std::enable_if_t<!std::is_base_of<UnlinkedCodeBlock, T>::value || std::is_same<T, UnlinkedEvalCodeBlock>::value, T*>
     154    fetchFromDisk(VM&, const SourceCodeKey&) { return nullptr; }
     155
     156    template<typename UnlinkedCodeBlockType>
     157    UnlinkedCodeBlockType* findCacheAndUpdateAge(VM& vm, const SourceCodeKey& key)
    93158    {
    94159        prune();
     
    96161        iterator findResult = m_map.find(key);
    97162        if (findResult == m_map.end())
    98             return nullptr;
     163            return fetchFromDisk<UnlinkedCodeBlockType>(vm, key);
    99164
    100165        int64_t age = m_age - findResult->value.age;
     
    116181        m_age += key.length();
    117182
    118         return &findResult->value;
     183        return jsCast<UnlinkedCodeBlockType*>(findResult->value.cell.get());
    119184    }
    120185
     
    198263
    199264    void clear() { m_sourceCode.clear(); }
     265    JS_EXPORT_PRIVATE void write(VM&);
    200266
    201267private:
     
    257323}
    258324
     325ALWAYS_INLINE static void writeCodeBlock(VM& vm, const SourceCodeKey& key, const SourceCodeValue& value)
     326{
     327#if OS(DARWIN)
     328    const char* cachePath = Options::diskCachePath();
     329    if (LIKELY(!cachePath))
     330        return;
     331
     332    UnlinkedCodeBlock* codeBlock = jsDynamicCast<UnlinkedCodeBlock*>(vm, value.cell.get());
     333    if (!codeBlock)
     334        return;
     335
     336    unsigned hash = key.hash();
     337    char filename[512];
     338    int count = snprintf(filename, 512, "%s/%u.cache", cachePath, hash);
     339    if (count < 0 || count > 512)
     340        return;
     341
     342    std::pair<MallocPtr<uint8_t>, size_t> result = encodeCodeBlock(vm, key, codeBlock);
     343
     344    int fd = open(filename, O_CREAT | O_WRONLY, 0666);
     345    int rc = flock(fd, LOCK_EX | LOCK_NB);
     346    if (!rc)
     347        ::write(fd, result.first.get(), result.second);
     348    close(fd);
     349#else
     350    UNUSED_PARAM(vm);
     351    UNUSED_PARAM(key);
     352    UNUSED_PARAM(value);
     353#endif
     354}
     355
     356
    259357} // namespace JSC
  • trunk/Source/JavaScriptCore/runtime/JSBigInt.cpp

    r239427 r240210  
    16891689}
    16901690
    1691 inline size_t JSBigInt::offsetOfData()
    1692 {
    1693     return WTF::roundUpToMultipleOf<sizeof(Digit)>(sizeof(JSBigInt));
    1694 }
    1695 
    16961691template <typename CharType>
    16971692JSBigInt* JSBigInt::parseInt(ExecState* exec, CharType*  data, unsigned length, ErrorParseMode errorParseMode)
     
    17941789
    17951790    return nullptr;
    1796 }
    1797 
    1798 inline JSBigInt::Digit* JSBigInt::dataStorage()
    1799 {
    1800     return reinterpret_cast<Digit*>(reinterpret_cast<char*>(this) + offsetOfData());
    18011791}
    18021792
  • trunk/Source/JavaScriptCore/runtime/JSBigInt.h

    r239427 r240210  
    3939    using Base = JSCell;
    4040    static const unsigned StructureFlags = Base::StructureFlags | StructureIsImmortal | OverridesToThis;
     41    friend class CachedBigInt;
    4142
    4243public:
     
    229230
    230231    static size_t allocationSize(unsigned length);
    231     static size_t offsetOfData();
    232     Digit* dataStorage();
     232    inline static size_t offsetOfData()
     233    {
     234        return WTF::roundUpToMultipleOf<sizeof(Digit)>(sizeof(JSBigInt));
     235    }
     236
     237    inline Digit* dataStorage()
     238    {
     239        return reinterpret_cast<Digit*>(reinterpret_cast<char*>(this) + offsetOfData());
     240    }
    233241
    234242    Digit digit(unsigned);
  • trunk/Source/JavaScriptCore/runtime/Options.cpp

    r238564 r240210  
    518518    Options::useProbeOSRExit() = false;
    519519#endif
     520
     521    if (!Options::useCodeCache())
     522        Options::diskCachePath() = nullptr;
     523
     524    if (!Options::diskCachePath())
     525        Options::forceDiskCache() = false;
    520526}
    521527
  • trunk/Source/JavaScriptCore/runtime/Options.h

    r239188 r240210  
    509509    v(bool, traceLLIntSlowPath, false, Configurable, nullptr) \
    510510    v(bool, traceBaselineJITExecution, false, Normal, nullptr) \
     511    v(optionString, diskCachePath, nullptr, Restricted, "") \
     512    v(bool, forceDiskCache, false, Restricted, "") \
    511513
    512514
  • trunk/Source/JavaScriptCore/runtime/RegExp.h

    r237763 r240210  
    4242
    4343class RegExp final : public JSCell {
     44    friend class CachedRegExp;
     45
    4446public:
    4547    typedef JSCell Base;
  • trunk/Source/JavaScriptCore/runtime/ScopedArgumentsTable.h

    r228500 r240210  
    4040// "delete arguments[i]" or some variant of defineOwnProperty.
    4141class ScopedArgumentsTable final : public JSCell {
     42    friend class CachedScopedArgumentsTable;
     43
    4244public:
    4345    typedef JSCell Base;
  • trunk/Source/JavaScriptCore/runtime/StackFrame.h

    r232314 r240210  
    2626#pragma once
    2727
     28#include "Heap.h"
    2829#include "WasmIndexOrName.h"
    2930#include "WriteBarrier.h"
  • trunk/Source/JavaScriptCore/runtime/StructureInlines.h

    r240023 r240210  
    3232#include "Structure.h"
    3333#include "StructureChain.h"
     34#include "StructureRareDataInlines.h"
    3435
    3536namespace JSC {
  • trunk/Source/JavaScriptCore/runtime/SymbolTable.h

    r233622 r240210  
    7474
    7575struct SymbolTableEntry {
     76    friend class CachedSymbolTableEntry;
     77
    7678private:
    7779    static VarOffset varOffsetFromBits(intptr_t bits)
     
    437439
    438440class SymbolTable final : public JSCell {
     441    friend class CachedSymbolTable;
     442
    439443public:
    440444    typedef JSCell Base;
  • trunk/Source/WTF/ChangeLog

    r240181 r240210  
     12019-01-20  Tadeu Zagallo  <tzagallo@apple.com>
     2
     3        Cache bytecode to disk
     4        https://bugs.webkit.org/show_bug.cgi?id=192782
     5        <rdar://problem/46084932>
     6
     7        Reviewed by Keith Miller.
     8
     9        BitVectors have to be friends with JSC::CacheBitVector to allow
     10        serializing its buffer as part of the bytecode cache encoding.
     11
     12        * wtf/BitVector.h:
     13
    1142019-01-18  Tim Horton  <timothy_horton@apple.com>
    215
  • trunk/Source/WTF/wtf/BitVector.h

    r237099 r240210  
    3434#include <wtf/StdLibExtras.h>
    3535
     36namespace JSC {
     37class CachedBitVector;
     38}
     39
    3640namespace WTF {
    3741
     
    339343       
    340344private:
     345    friend class JSC::CachedBitVector;
     346
    341347    static unsigned bitsInPointer()
    342348    {
  • trunk/Tools/ChangeLog

    r240209 r240210  
     12019-01-20  Tadeu Zagallo  <tzagallo@apple.com>
     2
     3        Cache bytecode to disk
     4        https://bugs.webkit.org/show_bug.cgi?id=192782
     5        <rdar://problem/46084932>
     6
     7        Reviewed by Keith Miller.
     8
     9        Add test helper to execute bytecode-cache tests: it executes each test
     10        twice, the first with JSC_diskCachePath set to a temporary directory
     11        and second with JSC_forceDiskCache=true (in addition to the cache path)
     12        to guarantee that only the disk cache is being used and no new
     13        UnlinkedCodeBlocks are being created.
     14
     15        * Scripts/jsc-stress-test-helpers/bytecode-cache-test-helper: Added.
     16        * Scripts/run-jsc-stress-tests:
     17
    1182019-01-20  chris fleizach  <cfleizach@apple.com>
    219
  • trunk/Tools/Scripts/run-jsc-stress-tests

    r240191 r240210  
    656656end
    657657
     658def runBytecodeCache(*optionalTestSpecificOptions)
     659    unless $hostOS == "darwin"
     660        skip
     661        return
     662    end
     663    options = BASE_OPTIONS + $testSpecificRequiredOptions + FTL_OPTIONS + optionalTestSpecificOptions
     664    addRunCommand("bytecode-cache", ["ruby", (pathToHelpers + "bytecode-cache-test-helper").to_s, pathToVM.to_s, $benchmark.to_s] + options, silentOutputHandler, simpleErrorHandler)
     665end
     666
    658667def runBigIntEnabled(*optionalTestSpecificOptions)
    659668    # FIXME: <rdar://problem/40331121>
     
    752761    else
    753762        runDefault
     763        runBytecodeCache
    754764        if $jitTests
    755765            runNoLLInt
Note: See TracChangeset for help on using the changeset viewer.