haikuwebkit/Source/WebCore/contentextensions/DFABytecodeCompiler.h

121 lines
4.2 KiB
C
Raw Permalink Normal View History

Compile DFA to bytecode. https://bugs.webkit.org/show_bug.cgi?id=142031 Reviewed by Benjamin Poulain. * WebCore.xcodeproj/project.pbxproj: * contentextensions/ContentExtensionsBackend.cpp: (WebCore::ContentExtensions::ContentExtensionsBackend::setRuleList): (WebCore::ContentExtensions::ContentExtensionsBackend::shouldBlockURL): * contentextensions/ContentExtensionsBackend.h: * contentextensions/DFA.cpp: (WebCore::ContentExtensions::DFA::nextState): Deleted. (WebCore::ContentExtensions::DFA::actions): Deleted. * contentextensions/DFA.h: (WebCore::ContentExtensions::DFA::size): (WebCore::ContentExtensions::DFA::nodeAt): * contentextensions/DFABytecode.h: Added. (WebCore::ContentExtensions::instructionSizeWithArguments): * contentextensions/DFABytecodeCompiler.cpp: Added. (WebCore::ContentExtensions::append): (WebCore::ContentExtensions::set32Bits): (WebCore::ContentExtensions::DFABytecodeCompiler::emitAppendAction): (WebCore::ContentExtensions::DFABytecodeCompiler::emitJump): (WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValue): (WebCore::ContentExtensions::DFABytecodeCompiler::emitTerminate): (WebCore::ContentExtensions::DFABytecodeCompiler::reserveBufferCapacity): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNode): (WebCore::ContentExtensions::DFABytecodeCompiler::compile): * contentextensions/DFABytecodeCompiler.h: Added. (WebCore::ContentExtensions::DFABytecodeCompiler::DFABytecodeCompiler): * contentextensions/DFABytecodeInterpreter.cpp: Added. (WebCore::ContentExtensions::getBits): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret): * contentextensions/DFABytecodeInterpreter.h: Added. (WebCore::ContentExtensions::DFABytecodeInterpreter::DFABytecodeInterpreter): Canonical link: https://commits.webkit.org/160136@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@180769 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-02-27 19:20:27 +00:00
/*
* Copyright (C) 2015 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
Compile DFA to bytecode. https://bugs.webkit.org/show_bug.cgi?id=142031 Reviewed by Benjamin Poulain. * WebCore.xcodeproj/project.pbxproj: * contentextensions/ContentExtensionsBackend.cpp: (WebCore::ContentExtensions::ContentExtensionsBackend::setRuleList): (WebCore::ContentExtensions::ContentExtensionsBackend::shouldBlockURL): * contentextensions/ContentExtensionsBackend.h: * contentextensions/DFA.cpp: (WebCore::ContentExtensions::DFA::nextState): Deleted. (WebCore::ContentExtensions::DFA::actions): Deleted. * contentextensions/DFA.h: (WebCore::ContentExtensions::DFA::size): (WebCore::ContentExtensions::DFA::nodeAt): * contentextensions/DFABytecode.h: Added. (WebCore::ContentExtensions::instructionSizeWithArguments): * contentextensions/DFABytecodeCompiler.cpp: Added. (WebCore::ContentExtensions::append): (WebCore::ContentExtensions::set32Bits): (WebCore::ContentExtensions::DFABytecodeCompiler::emitAppendAction): (WebCore::ContentExtensions::DFABytecodeCompiler::emitJump): (WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValue): (WebCore::ContentExtensions::DFABytecodeCompiler::emitTerminate): (WebCore::ContentExtensions::DFABytecodeCompiler::reserveBufferCapacity): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNode): (WebCore::ContentExtensions::DFABytecodeCompiler::compile): * contentextensions/DFABytecodeCompiler.h: Added. (WebCore::ContentExtensions::DFABytecodeCompiler::DFABytecodeCompiler): * contentextensions/DFABytecodeInterpreter.cpp: Added. (WebCore::ContentExtensions::getBits): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret): * contentextensions/DFABytecodeInterpreter.h: Added. (WebCore::ContentExtensions::DFABytecodeInterpreter::DFABytecodeInterpreter): Canonical link: https://commits.webkit.org/160136@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@180769 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-02-27 19:20:27 +00:00
#if ENABLE(CONTENT_EXTENSIONS)
#include "DFABytecode.h"
#include <wtf/Vector.h>
namespace WebCore {
namespace ContentExtensions {
Use less memory when compiling content extensions. https://bugs.webkit.org/show_bug.cgi?id=144051 Patch by Alex Christensen <achristensen@webkit.org> on 2015-04-23 Reviewed by Darin Adler and Benjamin Poulain. Source/WebCore: No change in functionality, correctness already covered by existing tests. Before this patch, a DFANode contained a HashSet of transitions. Large vectors of DFANodes made many small HashSets, which was inefficient use of memory. We now put all the actions and transitions into one big compact Vector and each node owns ranges in that vector. * contentextensions/CombinedURLFilters.cpp: (WebCore::ContentExtensions::recursiveMemoryUsed): (WebCore::ContentExtensions::CombinedURLFilters::memoryUsed): * contentextensions/CombinedURLFilters.h: * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/ContentExtensionsDebugging.h: * contentextensions/DFA.cpp: (WebCore::ContentExtensions::DFA::memoryUsed): (WebCore::ContentExtensions::DFANode::actions): (WebCore::ContentExtensions::DFANode::transitions): (WebCore::ContentExtensions::DFANode::fallbackTransitionDestination): (WebCore::ContentExtensions::DFANode::changeFallbackTransition): (WebCore::ContentExtensions::DFANode::addFallbackTransition): (WebCore::ContentExtensions::DFANode::containsTransition): (WebCore::ContentExtensions::DFANode::kill): (WebCore::ContentExtensions::DFA::minimize): (WebCore::ContentExtensions::DFA::DFA): Deleted. (WebCore::ContentExtensions::DFA::operator=): Deleted. * contentextensions/DFA.h: * contentextensions/DFABytecodeCompiler.cpp: (WebCore::ContentExtensions::DFABytecodeCompiler::compileNode): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNodeTransitions): (WebCore::ContentExtensions::DFABytecodeCompiler::compile): * contentextensions/DFABytecodeCompiler.h: * contentextensions/DFAMinimizer.cpp: (WebCore::ContentExtensions::DFAMinimizer::minimize): * contentextensions/DFAMinimizer.h: * contentextensions/DFANode.h: (WebCore::ContentExtensions::DFANode::isKilled): (WebCore::ContentExtensions::DFANode::hasFallbackTransition): (WebCore::ContentExtensions::DFANode::hasActions): (WebCore::ContentExtensions::DFANode::transitionsLength): (WebCore::ContentExtensions::DFANode::actionsLength): (WebCore::ContentExtensions::DFANode::actionsStart): (WebCore::ContentExtensions::DFANode::setActions): (WebCore::ContentExtensions::DFANode::setTransitions): (WebCore::ContentExtensions::DFANode::resetTransitions): (WebCore::ContentExtensions::DFANode::transitionsStart): (WebCore::ContentExtensions::DFANode::setHasFallbackTransitionWithoutChangingDFA): * contentextensions/NFA.cpp: (WebCore::ContentExtensions::NFA::memoryUsed): * contentextensions/NFA.h: * contentextensions/NFAToDFA.cpp: (WebCore::ContentExtensions::NodeIdSetToUniqueNodeIdSetSource::NodeIdSetToUniqueNodeIdSetSource): (WebCore::ContentExtensions::NodeIdSetToUniqueNodeIdSetTranslator::translate): (WebCore::ContentExtensions::getOrCreateDFANode): (WebCore::ContentExtensions::NFAToDFA::convert): Tools: * TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp: (TestWebKitAPI::TEST_F): * TestWebKitAPI/Tests/WebCore/DFAMinimizer.cpp: (TestWebKitAPI::countLiveNodes): Canonical link: https://commits.webkit.org/162080@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@183204 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-04-23 19:56:57 +00:00
struct DFA;
Compile character ranges targeting the same state as range check in the bytecode https://bugs.webkit.org/show_bug.cgi?id=142759 Patch by Benjamin Poulain <bpoulain@apple.com> on 2015-03-17 Reviewed by Alex Christensen. Source/WebCore: Previously, character ranges would be compiled as many individual character checks. For example, a transition on "[a-z]" would do 26 character checks + jump, which leads to enormous matchines. With this patch, we find the ranges at lowering time and generate a single instruction for them: "CheckValueRange". This helps making the machine denser when the input use character sets. The second part of this patch goes further in the case where the transitions out of a state cover the entire alphabet. In that case, we create a fallback transition on the fly and remove all the ranges made useless. That case is common when ranges are used with inverse character set (e.g. [^a]+a). * contentextensions/DFABytecode.h: (WebCore::ContentExtensions::instructionSizeWithArguments): * contentextensions/DFABytecodeCompiler.cpp: (WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValueRange): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNode): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNodeTransitions): (WebCore::ContentExtensions::DFABytecodeCompiler::compileCheckForRange): * contentextensions/DFABytecodeCompiler.h: Extend the compiler to detect ranges and lower them as CheckValueRange. * contentextensions/DFABytecodeInterpreter.cpp: (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret): Range checks in the interpreter. * contentextensions/NFA.cpp: (WebCore::ContentExtensions::NFA::setFinal): This assertion does not make sense with the current codebase. Actions are "compressed", it is possible to have two patterns with the same action. * contentextensions/NFAToDFA.cpp: (WebCore::ContentExtensions::simplifyTransitions): A very simple DFA optimization function: it only reduce the strength of ranges. (WebCore::ContentExtensions::NFAToDFA::convert): Tools: * TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp: (TestWebKitAPI::TEST_F): Canonical link: https://commits.webkit.org/160818@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@181663 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-03-17 20:47:42 +00:00
class DFANode;
Compile DFA to bytecode. https://bugs.webkit.org/show_bug.cgi?id=142031 Reviewed by Benjamin Poulain. * WebCore.xcodeproj/project.pbxproj: * contentextensions/ContentExtensionsBackend.cpp: (WebCore::ContentExtensions::ContentExtensionsBackend::setRuleList): (WebCore::ContentExtensions::ContentExtensionsBackend::shouldBlockURL): * contentextensions/ContentExtensionsBackend.h: * contentextensions/DFA.cpp: (WebCore::ContentExtensions::DFA::nextState): Deleted. (WebCore::ContentExtensions::DFA::actions): Deleted. * contentextensions/DFA.h: (WebCore::ContentExtensions::DFA::size): (WebCore::ContentExtensions::DFA::nodeAt): * contentextensions/DFABytecode.h: Added. (WebCore::ContentExtensions::instructionSizeWithArguments): * contentextensions/DFABytecodeCompiler.cpp: Added. (WebCore::ContentExtensions::append): (WebCore::ContentExtensions::set32Bits): (WebCore::ContentExtensions::DFABytecodeCompiler::emitAppendAction): (WebCore::ContentExtensions::DFABytecodeCompiler::emitJump): (WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValue): (WebCore::ContentExtensions::DFABytecodeCompiler::emitTerminate): (WebCore::ContentExtensions::DFABytecodeCompiler::reserveBufferCapacity): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNode): (WebCore::ContentExtensions::DFABytecodeCompiler::compile): * contentextensions/DFABytecodeCompiler.h: Added. (WebCore::ContentExtensions::DFABytecodeCompiler::DFABytecodeCompiler): * contentextensions/DFABytecodeInterpreter.cpp: Added. (WebCore::ContentExtensions::getBits): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret): * contentextensions/DFABytecodeInterpreter.h: Added. (WebCore::ContentExtensions::DFABytecodeInterpreter::DFABytecodeInterpreter): Canonical link: https://commits.webkit.org/160136@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@180769 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-02-27 19:20:27 +00:00
class WEBCORE_EXPORT DFABytecodeCompiler {
Compile DFA to bytecode. https://bugs.webkit.org/show_bug.cgi?id=142031 Reviewed by Benjamin Poulain. * WebCore.xcodeproj/project.pbxproj: * contentextensions/ContentExtensionsBackend.cpp: (WebCore::ContentExtensions::ContentExtensionsBackend::setRuleList): (WebCore::ContentExtensions::ContentExtensionsBackend::shouldBlockURL): * contentextensions/ContentExtensionsBackend.h: * contentextensions/DFA.cpp: (WebCore::ContentExtensions::DFA::nextState): Deleted. (WebCore::ContentExtensions::DFA::actions): Deleted. * contentextensions/DFA.h: (WebCore::ContentExtensions::DFA::size): (WebCore::ContentExtensions::DFA::nodeAt): * contentextensions/DFABytecode.h: Added. (WebCore::ContentExtensions::instructionSizeWithArguments): * contentextensions/DFABytecodeCompiler.cpp: Added. (WebCore::ContentExtensions::append): (WebCore::ContentExtensions::set32Bits): (WebCore::ContentExtensions::DFABytecodeCompiler::emitAppendAction): (WebCore::ContentExtensions::DFABytecodeCompiler::emitJump): (WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValue): (WebCore::ContentExtensions::DFABytecodeCompiler::emitTerminate): (WebCore::ContentExtensions::DFABytecodeCompiler::reserveBufferCapacity): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNode): (WebCore::ContentExtensions::DFABytecodeCompiler::compile): * contentextensions/DFABytecodeCompiler.h: Added. (WebCore::ContentExtensions::DFABytecodeCompiler::DFABytecodeCompiler): * contentextensions/DFABytecodeInterpreter.cpp: Added. (WebCore::ContentExtensions::getBits): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret): * contentextensions/DFABytecodeInterpreter.h: Added. (WebCore::ContentExtensions::DFABytecodeInterpreter::DFABytecodeInterpreter): Canonical link: https://commits.webkit.org/160136@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@180769 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-02-27 19:20:27 +00:00
public:
DFABytecodeCompiler(const DFA& dfa, Vector<DFABytecode>& bytecode)
: m_bytecode(bytecode)
, m_dfa(dfa)
{
}
void compile();
private:
struct Range {
[Content Extensions] Relax restrictions on triggers that match everything. https://bugs.webkit.org/show_bug.cgi?id=145069 Reviewed by Benjamin Poulain. Source/WebCore: Added API tests that cover the new functionality and test for correctness in behavior. * contentextensions/CompiledContentExtension.cpp: (WebCore::ContentExtensions::CompiledContentExtension::globalDisplayNoneSelectors): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::addUniversalActionsToDFA): (WebCore::ContentExtensions::compileRuleList): Put universalActionsWithoutDomains into the DFA from filtersWithoutDomains and put universalActionsWithDomains into the DFA from filtersWithDomains. * contentextensions/ContentExtensionError.cpp: (WebCore::ContentExtensions::contentExtensionErrorCategory): * contentextensions/ContentExtensionError.h: Remove error codes for errors that are not errors any more. * contentextensions/ContentExtensionsBackend.cpp: (WebCore::ContentExtensions::ContentExtensionsBackend::actionsForResourceLoad): * contentextensions/ContentExtensionsBackend.h: * contentextensions/DFABytecode.h: (WebCore::ContentExtensions::instructionSizeWithArguments): * contentextensions/DFABytecodeCompiler.cpp: (WebCore::ContentExtensions::set32Bits): (WebCore::ContentExtensions::DFABytecodeCompiler::emitAppendAction): (WebCore::ContentExtensions::DFABytecodeCompiler::emitJump): (WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValue): (WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValueRange): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNode): (WebCore::ContentExtensions::DFABytecodeCompiler::compile): (WebCore::ContentExtensions::DFABytecodeCompiler::emitTestFlagsAndAppendAction): Deleted. * contentextensions/DFABytecodeCompiler.h: * contentextensions/DFABytecodeInterpreter.cpp: (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretAppendAction): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretTestFlagsAndAppendAction): (WebCore::ContentExtensions::DFABytecodeInterpreter::actionsForDefaultStylesheetFromDFARoot): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret): (WebCore::ContentExtensions::DFABytecodeInterpreter::actionsFromDFARoot): Deleted. * contentextensions/DFABytecodeInterpreter.h: Add a new bytecode AppendActionDefaultStylesheet to mark actions that are css-display-none that need to be put in the default stylesheet to be ignored or not as a whole. css-display-none actions with flags or domain rules and css-display-none actions after ignore-previous-rules actions are not to be in this precompiled stylesheet, but they will be applied as needed per page. The precompiled stylesheet is already applied if no ignore-previous-rules action is triggered. * loader/ResourceLoadInfo.h: Source/WebKit2: * UIProcess/API/APIUserContentExtensionStore.h: Increment version number to reflect changes in DFABytecode. Tools: * TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp: (TestWebKitAPI::TEST_F): Update and add tests for new possibilities with .* Canonical link: https://commits.webkit.org/163223@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@184644 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-05-20 17:56:17 +00:00
Range(uint8_t min, uint8_t max, uint32_t destination, bool caseSensitive)
: min(min)
, max(max)
, destination(destination)
, caseSensitive(caseSensitive)
{
}
uint8_t min;
uint8_t max;
[Content Extensions] Relax restrictions on triggers that match everything. https://bugs.webkit.org/show_bug.cgi?id=145069 Reviewed by Benjamin Poulain. Source/WebCore: Added API tests that cover the new functionality and test for correctness in behavior. * contentextensions/CompiledContentExtension.cpp: (WebCore::ContentExtensions::CompiledContentExtension::globalDisplayNoneSelectors): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::addUniversalActionsToDFA): (WebCore::ContentExtensions::compileRuleList): Put universalActionsWithoutDomains into the DFA from filtersWithoutDomains and put universalActionsWithDomains into the DFA from filtersWithDomains. * contentextensions/ContentExtensionError.cpp: (WebCore::ContentExtensions::contentExtensionErrorCategory): * contentextensions/ContentExtensionError.h: Remove error codes for errors that are not errors any more. * contentextensions/ContentExtensionsBackend.cpp: (WebCore::ContentExtensions::ContentExtensionsBackend::actionsForResourceLoad): * contentextensions/ContentExtensionsBackend.h: * contentextensions/DFABytecode.h: (WebCore::ContentExtensions::instructionSizeWithArguments): * contentextensions/DFABytecodeCompiler.cpp: (WebCore::ContentExtensions::set32Bits): (WebCore::ContentExtensions::DFABytecodeCompiler::emitAppendAction): (WebCore::ContentExtensions::DFABytecodeCompiler::emitJump): (WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValue): (WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValueRange): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNode): (WebCore::ContentExtensions::DFABytecodeCompiler::compile): (WebCore::ContentExtensions::DFABytecodeCompiler::emitTestFlagsAndAppendAction): Deleted. * contentextensions/DFABytecodeCompiler.h: * contentextensions/DFABytecodeInterpreter.cpp: (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretAppendAction): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretTestFlagsAndAppendAction): (WebCore::ContentExtensions::DFABytecodeInterpreter::actionsForDefaultStylesheetFromDFARoot): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret): (WebCore::ContentExtensions::DFABytecodeInterpreter::actionsFromDFARoot): Deleted. * contentextensions/DFABytecodeInterpreter.h: Add a new bytecode AppendActionDefaultStylesheet to mark actions that are css-display-none that need to be put in the default stylesheet to be ignored or not as a whole. css-display-none actions with flags or domain rules and css-display-none actions after ignore-previous-rules actions are not to be in this precompiled stylesheet, but they will be applied as needed per page. The precompiled stylesheet is already applied if no ignore-previous-rules action is triggered. * loader/ResourceLoadInfo.h: Source/WebKit2: * UIProcess/API/APIUserContentExtensionStore.h: Increment version number to reflect changes in DFABytecode. Tools: * TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp: (TestWebKitAPI::TEST_F): Update and add tests for new possibilities with .* Canonical link: https://commits.webkit.org/163223@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@184644 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-05-20 17:56:17 +00:00
uint32_t destination;
bool caseSensitive;
};
[Content Extensions] Use a jump table when consecutive transitions have different targets https://bugs.webkit.org/show_bug.cgi?id=147099 Reviewed by Alex Christensen. Source/WebCore: When handling consecutive single transitions, merge them into a jump table instead of creating many individual CheckValue. From local testing on x86_64, it reduces the bytecode size by about 5% and improve the runtime by about 10%. * contentextensions/DFABytecode.h: (WebCore::ContentExtensions::instructionSizeWithArguments): * contentextensions/DFABytecodeCompiler.cpp: (WebCore::ContentExtensions::DFABytecodeCompiler::extractJumpTable): (WebCore::ContentExtensions::DFABytecodeCompiler::transitions): (WebCore::ContentExtensions::DFABytecodeCompiler::checkForJumpTableMaxBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::compileJumpTable): (WebCore::ContentExtensions::DFABytecodeCompiler::nodeTransitionsMaxBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNodeTransitions): (WebCore::ContentExtensions::DFABytecodeCompiler::ranges): Deleted. * contentextensions/DFABytecodeCompiler.h: * contentextensions/DFABytecodeInterpreter.cpp: (WebCore::ContentExtensions::DFABytecodeInterpreter::interpetJumpTable): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret): * contentextensions/DFABytecodeInterpreter.h: Source/WebKit2: * UIProcess/API/APIUserContentExtensionStore.h: LayoutTests: Add some primitive testing to make sure the code is covered. * http/tests/contentextensions/test-jump-table-bytecode-generation-expected.txt: Added. * http/tests/contentextensions/test-jump-table-bytecode-generation.html: Added. * http/tests/contentextensions/test-jump-table-bytecode-generation.html.json: Added. Canonical link: https://commits.webkit.org/165216@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@187137 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-07-21 23:45:00 +00:00
struct JumpTable {
~JumpTable()
{
ASSERT(min + destinations.size() == static_cast<size_t>(max + 1));
[Content Extensions] Use a jump table when consecutive transitions have different targets https://bugs.webkit.org/show_bug.cgi?id=147099 Reviewed by Alex Christensen. Source/WebCore: When handling consecutive single transitions, merge them into a jump table instead of creating many individual CheckValue. From local testing on x86_64, it reduces the bytecode size by about 5% and improve the runtime by about 10%. * contentextensions/DFABytecode.h: (WebCore::ContentExtensions::instructionSizeWithArguments): * contentextensions/DFABytecodeCompiler.cpp: (WebCore::ContentExtensions::DFABytecodeCompiler::extractJumpTable): (WebCore::ContentExtensions::DFABytecodeCompiler::transitions): (WebCore::ContentExtensions::DFABytecodeCompiler::checkForJumpTableMaxBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::compileJumpTable): (WebCore::ContentExtensions::DFABytecodeCompiler::nodeTransitionsMaxBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNodeTransitions): (WebCore::ContentExtensions::DFABytecodeCompiler::ranges): Deleted. * contentextensions/DFABytecodeCompiler.h: * contentextensions/DFABytecodeInterpreter.cpp: (WebCore::ContentExtensions::DFABytecodeInterpreter::interpetJumpTable): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret): * contentextensions/DFABytecodeInterpreter.h: Source/WebKit2: * UIProcess/API/APIUserContentExtensionStore.h: LayoutTests: Add some primitive testing to make sure the code is covered. * http/tests/contentextensions/test-jump-table-bytecode-generation-expected.txt: Added. * http/tests/contentextensions/test-jump-table-bytecode-generation.html: Added. * http/tests/contentextensions/test-jump-table-bytecode-generation.html.json: Added. Canonical link: https://commits.webkit.org/165216@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@187137 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-07-21 23:45:00 +00:00
ASSERT(min == max || destinations.size() > 1);
}
uint8_t min { 0 };
uint8_t max { 0 };
bool caseSensitive { true };
Vector<uint32_t> destinations;
};
struct Transitions {
Vector<JumpTable> jumpTables;
Vector<Range> ranges;
bool useFallbackTransition { false };
uint32_t fallbackTransitionTarget { std::numeric_limits<uint32_t>::max() };
};
JumpTable extractJumpTable(Vector<Range>&, unsigned first, unsigned last);
Transitions transitions(const DFANode&);
[Content Extensions] Implement branch compaction for DFA bytecode. https://bugs.webkit.org/show_bug.cgi?id=145619 Patch by Alex Christensen <achristensen@webkit.org> on 2015-06-16 Reviewed by Benjamin Poulain. Source/WebCore: This patch adds another pass to the DFABytecodeCompiler which finds where the bytecode from each node would be if it were compiled with no branch compaction, then uses that as a worst-case value to determine how many bytes are needed to store the relative jump distance. Then when linking, it will fill in the value as it already did, but with a variable size jump. The jumps are also now signed distances relative to where the jump is stored. This patch is covered by existing tests, which have many jumps that are near the -128/127 byte boundary, and the switch from 16-bit jumps to 32-bit jumps near the -65536/65535 byte boundary is analogous. * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/DFABytecode.h: (WebCore::ContentExtensions::smallestPossibleJumpSize): (WebCore::ContentExtensions::instructionSizeWithArguments): * contentextensions/DFABytecodeCompiler.cpp: (WebCore::ContentExtensions::append): (WebCore::ContentExtensions::appendZeroes): (WebCore::ContentExtensions::setBits): (WebCore::ContentExtensions::appendActionBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::emitAppendAction): (WebCore::ContentExtensions::DFABytecodeCompiler::longestPossibleJump): (WebCore::ContentExtensions::DFABytecodeCompiler::emitJump): (WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValue): (WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValueRange): (WebCore::ContentExtensions::DFABytecodeCompiler::emitTerminate): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNode): (WebCore::ContentExtensions::DFABytecodeCompiler::compiledNodeMaxBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::ranges): (WebCore::ContentExtensions::DFABytecodeCompiler::checkForRangeMaxBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::compileCheckForRange): (WebCore::ContentExtensions::DFABytecodeCompiler::nodeTransitionsMaxBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNodeTransitions): (WebCore::ContentExtensions::DFABytecodeCompiler::compile): (WebCore::ContentExtensions::set32Bits): Deleted. * contentextensions/DFABytecodeCompiler.h: * contentextensions/DFABytecodeInterpreter.cpp: (WebCore::ContentExtensions::getBits): (WebCore::ContentExtensions::getInstruction): (WebCore::ContentExtensions::jumpSizeInBytes): (WebCore::ContentExtensions::getJumpSize): (WebCore::ContentExtensions::getJumpDistance): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretAppendAction): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretTestFlagsAndAppendAction): (WebCore::ContentExtensions::DFABytecodeInterpreter::actionsForDefaultStylesheetFromDFARoot): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret): * loader/ResourceLoadInfo.h: Source/WebKit2: * UIProcess/API/APIUserContentExtensionStore.h: Increment version number to reflect changes to bytecode. Canonical link: https://commits.webkit.org/164078@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@185621 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-06-16 22:29:19 +00:00
unsigned compiledNodeMaxBytecodeSize(uint32_t index);
void compileNode(uint32_t index, bool root);
unsigned nodeTransitionsMaxBytecodeSize(const DFANode&);
void compileNodeTransitions(uint32_t nodeIndex);
[Content Extensions] Use a jump table when consecutive transitions have different targets https://bugs.webkit.org/show_bug.cgi?id=147099 Reviewed by Alex Christensen. Source/WebCore: When handling consecutive single transitions, merge them into a jump table instead of creating many individual CheckValue. From local testing on x86_64, it reduces the bytecode size by about 5% and improve the runtime by about 10%. * contentextensions/DFABytecode.h: (WebCore::ContentExtensions::instructionSizeWithArguments): * contentextensions/DFABytecodeCompiler.cpp: (WebCore::ContentExtensions::DFABytecodeCompiler::extractJumpTable): (WebCore::ContentExtensions::DFABytecodeCompiler::transitions): (WebCore::ContentExtensions::DFABytecodeCompiler::checkForJumpTableMaxBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::compileJumpTable): (WebCore::ContentExtensions::DFABytecodeCompiler::nodeTransitionsMaxBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNodeTransitions): (WebCore::ContentExtensions::DFABytecodeCompiler::ranges): Deleted. * contentextensions/DFABytecodeCompiler.h: * contentextensions/DFABytecodeInterpreter.cpp: (WebCore::ContentExtensions::DFABytecodeInterpreter::interpetJumpTable): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret): * contentextensions/DFABytecodeInterpreter.h: Source/WebKit2: * UIProcess/API/APIUserContentExtensionStore.h: LayoutTests: Add some primitive testing to make sure the code is covered. * http/tests/contentextensions/test-jump-table-bytecode-generation-expected.txt: Added. * http/tests/contentextensions/test-jump-table-bytecode-generation.html: Added. * http/tests/contentextensions/test-jump-table-bytecode-generation.html.json: Added. Canonical link: https://commits.webkit.org/165216@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@187137 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-07-21 23:45:00 +00:00
unsigned checkForJumpTableMaxBytecodeSize(const JumpTable&);
[Content Extensions] Implement branch compaction for DFA bytecode. https://bugs.webkit.org/show_bug.cgi?id=145619 Patch by Alex Christensen <achristensen@webkit.org> on 2015-06-16 Reviewed by Benjamin Poulain. Source/WebCore: This patch adds another pass to the DFABytecodeCompiler which finds where the bytecode from each node would be if it were compiled with no branch compaction, then uses that as a worst-case value to determine how many bytes are needed to store the relative jump distance. Then when linking, it will fill in the value as it already did, but with a variable size jump. The jumps are also now signed distances relative to where the jump is stored. This patch is covered by existing tests, which have many jumps that are near the -128/127 byte boundary, and the switch from 16-bit jumps to 32-bit jumps near the -65536/65535 byte boundary is analogous. * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/DFABytecode.h: (WebCore::ContentExtensions::smallestPossibleJumpSize): (WebCore::ContentExtensions::instructionSizeWithArguments): * contentextensions/DFABytecodeCompiler.cpp: (WebCore::ContentExtensions::append): (WebCore::ContentExtensions::appendZeroes): (WebCore::ContentExtensions::setBits): (WebCore::ContentExtensions::appendActionBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::emitAppendAction): (WebCore::ContentExtensions::DFABytecodeCompiler::longestPossibleJump): (WebCore::ContentExtensions::DFABytecodeCompiler::emitJump): (WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValue): (WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValueRange): (WebCore::ContentExtensions::DFABytecodeCompiler::emitTerminate): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNode): (WebCore::ContentExtensions::DFABytecodeCompiler::compiledNodeMaxBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::ranges): (WebCore::ContentExtensions::DFABytecodeCompiler::checkForRangeMaxBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::compileCheckForRange): (WebCore::ContentExtensions::DFABytecodeCompiler::nodeTransitionsMaxBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNodeTransitions): (WebCore::ContentExtensions::DFABytecodeCompiler::compile): (WebCore::ContentExtensions::set32Bits): Deleted. * contentextensions/DFABytecodeCompiler.h: * contentextensions/DFABytecodeInterpreter.cpp: (WebCore::ContentExtensions::getBits): (WebCore::ContentExtensions::getInstruction): (WebCore::ContentExtensions::jumpSizeInBytes): (WebCore::ContentExtensions::getJumpSize): (WebCore::ContentExtensions::getJumpDistance): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretAppendAction): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretTestFlagsAndAppendAction): (WebCore::ContentExtensions::DFABytecodeInterpreter::actionsForDefaultStylesheetFromDFARoot): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret): * loader/ResourceLoadInfo.h: Source/WebKit2: * UIProcess/API/APIUserContentExtensionStore.h: Increment version number to reflect changes to bytecode. Canonical link: https://commits.webkit.org/164078@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@185621 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-06-16 22:29:19 +00:00
unsigned checkForRangeMaxBytecodeSize(const Range&);
[Content Extensions] Use a jump table when consecutive transitions have different targets https://bugs.webkit.org/show_bug.cgi?id=147099 Reviewed by Alex Christensen. Source/WebCore: When handling consecutive single transitions, merge them into a jump table instead of creating many individual CheckValue. From local testing on x86_64, it reduces the bytecode size by about 5% and improve the runtime by about 10%. * contentextensions/DFABytecode.h: (WebCore::ContentExtensions::instructionSizeWithArguments): * contentextensions/DFABytecodeCompiler.cpp: (WebCore::ContentExtensions::DFABytecodeCompiler::extractJumpTable): (WebCore::ContentExtensions::DFABytecodeCompiler::transitions): (WebCore::ContentExtensions::DFABytecodeCompiler::checkForJumpTableMaxBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::compileJumpTable): (WebCore::ContentExtensions::DFABytecodeCompiler::nodeTransitionsMaxBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNodeTransitions): (WebCore::ContentExtensions::DFABytecodeCompiler::ranges): Deleted. * contentextensions/DFABytecodeCompiler.h: * contentextensions/DFABytecodeInterpreter.cpp: (WebCore::ContentExtensions::DFABytecodeInterpreter::interpetJumpTable): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret): * contentextensions/DFABytecodeInterpreter.h: Source/WebKit2: * UIProcess/API/APIUserContentExtensionStore.h: LayoutTests: Add some primitive testing to make sure the code is covered. * http/tests/contentextensions/test-jump-table-bytecode-generation-expected.txt: Added. * http/tests/contentextensions/test-jump-table-bytecode-generation.html: Added. * http/tests/contentextensions/test-jump-table-bytecode-generation.html.json: Added. Canonical link: https://commits.webkit.org/165216@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@187137 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-07-21 23:45:00 +00:00
void compileJumpTable(uint32_t nodeIndex, const JumpTable&);
[Content Extensions] Implement branch compaction for DFA bytecode. https://bugs.webkit.org/show_bug.cgi?id=145619 Patch by Alex Christensen <achristensen@webkit.org> on 2015-06-16 Reviewed by Benjamin Poulain. Source/WebCore: This patch adds another pass to the DFABytecodeCompiler which finds where the bytecode from each node would be if it were compiled with no branch compaction, then uses that as a worst-case value to determine how many bytes are needed to store the relative jump distance. Then when linking, it will fill in the value as it already did, but with a variable size jump. The jumps are also now signed distances relative to where the jump is stored. This patch is covered by existing tests, which have many jumps that are near the -128/127 byte boundary, and the switch from 16-bit jumps to 32-bit jumps near the -65536/65535 byte boundary is analogous. * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/DFABytecode.h: (WebCore::ContentExtensions::smallestPossibleJumpSize): (WebCore::ContentExtensions::instructionSizeWithArguments): * contentextensions/DFABytecodeCompiler.cpp: (WebCore::ContentExtensions::append): (WebCore::ContentExtensions::appendZeroes): (WebCore::ContentExtensions::setBits): (WebCore::ContentExtensions::appendActionBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::emitAppendAction): (WebCore::ContentExtensions::DFABytecodeCompiler::longestPossibleJump): (WebCore::ContentExtensions::DFABytecodeCompiler::emitJump): (WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValue): (WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValueRange): (WebCore::ContentExtensions::DFABytecodeCompiler::emitTerminate): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNode): (WebCore::ContentExtensions::DFABytecodeCompiler::compiledNodeMaxBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::ranges): (WebCore::ContentExtensions::DFABytecodeCompiler::checkForRangeMaxBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::compileCheckForRange): (WebCore::ContentExtensions::DFABytecodeCompiler::nodeTransitionsMaxBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNodeTransitions): (WebCore::ContentExtensions::DFABytecodeCompiler::compile): (WebCore::ContentExtensions::set32Bits): Deleted. * contentextensions/DFABytecodeCompiler.h: * contentextensions/DFABytecodeInterpreter.cpp: (WebCore::ContentExtensions::getBits): (WebCore::ContentExtensions::getInstruction): (WebCore::ContentExtensions::jumpSizeInBytes): (WebCore::ContentExtensions::getJumpSize): (WebCore::ContentExtensions::getJumpDistance): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretAppendAction): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretTestFlagsAndAppendAction): (WebCore::ContentExtensions::DFABytecodeInterpreter::actionsForDefaultStylesheetFromDFARoot): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret): * loader/ResourceLoadInfo.h: Source/WebKit2: * UIProcess/API/APIUserContentExtensionStore.h: Increment version number to reflect changes to bytecode. Canonical link: https://commits.webkit.org/164078@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@185621 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-06-16 22:29:19 +00:00
void compileCheckForRange(uint32_t nodeIndex, const Range&);
int32_t longestPossibleJump(uint32_t jumpLocation, uint32_t sourceNodeIndex, uint32_t destinationNodeIndex);
Compile DFA to bytecode. https://bugs.webkit.org/show_bug.cgi?id=142031 Reviewed by Benjamin Poulain. * WebCore.xcodeproj/project.pbxproj: * contentextensions/ContentExtensionsBackend.cpp: (WebCore::ContentExtensions::ContentExtensionsBackend::setRuleList): (WebCore::ContentExtensions::ContentExtensionsBackend::shouldBlockURL): * contentextensions/ContentExtensionsBackend.h: * contentextensions/DFA.cpp: (WebCore::ContentExtensions::DFA::nextState): Deleted. (WebCore::ContentExtensions::DFA::actions): Deleted. * contentextensions/DFA.h: (WebCore::ContentExtensions::DFA::size): (WebCore::ContentExtensions::DFA::nodeAt): * contentextensions/DFABytecode.h: Added. (WebCore::ContentExtensions::instructionSizeWithArguments): * contentextensions/DFABytecodeCompiler.cpp: Added. (WebCore::ContentExtensions::append): (WebCore::ContentExtensions::set32Bits): (WebCore::ContentExtensions::DFABytecodeCompiler::emitAppendAction): (WebCore::ContentExtensions::DFABytecodeCompiler::emitJump): (WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValue): (WebCore::ContentExtensions::DFABytecodeCompiler::emitTerminate): (WebCore::ContentExtensions::DFABytecodeCompiler::reserveBufferCapacity): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNode): (WebCore::ContentExtensions::DFABytecodeCompiler::compile): * contentextensions/DFABytecodeCompiler.h: Added. (WebCore::ContentExtensions::DFABytecodeCompiler::DFABytecodeCompiler): * contentextensions/DFABytecodeInterpreter.cpp: Added. (WebCore::ContentExtensions::getBits): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret): * contentextensions/DFABytecodeInterpreter.h: Added. (WebCore::ContentExtensions::DFABytecodeInterpreter::DFABytecodeInterpreter): Canonical link: https://commits.webkit.org/160136@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@180769 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-02-27 19:20:27 +00:00
[Content Extensions] Relax restrictions on triggers that match everything. https://bugs.webkit.org/show_bug.cgi?id=145069 Reviewed by Benjamin Poulain. Source/WebCore: Added API tests that cover the new functionality and test for correctness in behavior. * contentextensions/CompiledContentExtension.cpp: (WebCore::ContentExtensions::CompiledContentExtension::globalDisplayNoneSelectors): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::addUniversalActionsToDFA): (WebCore::ContentExtensions::compileRuleList): Put universalActionsWithoutDomains into the DFA from filtersWithoutDomains and put universalActionsWithDomains into the DFA from filtersWithDomains. * contentextensions/ContentExtensionError.cpp: (WebCore::ContentExtensions::contentExtensionErrorCategory): * contentextensions/ContentExtensionError.h: Remove error codes for errors that are not errors any more. * contentextensions/ContentExtensionsBackend.cpp: (WebCore::ContentExtensions::ContentExtensionsBackend::actionsForResourceLoad): * contentextensions/ContentExtensionsBackend.h: * contentextensions/DFABytecode.h: (WebCore::ContentExtensions::instructionSizeWithArguments): * contentextensions/DFABytecodeCompiler.cpp: (WebCore::ContentExtensions::set32Bits): (WebCore::ContentExtensions::DFABytecodeCompiler::emitAppendAction): (WebCore::ContentExtensions::DFABytecodeCompiler::emitJump): (WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValue): (WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValueRange): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNode): (WebCore::ContentExtensions::DFABytecodeCompiler::compile): (WebCore::ContentExtensions::DFABytecodeCompiler::emitTestFlagsAndAppendAction): Deleted. * contentextensions/DFABytecodeCompiler.h: * contentextensions/DFABytecodeInterpreter.cpp: (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretAppendAction): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretTestFlagsAndAppendAction): (WebCore::ContentExtensions::DFABytecodeInterpreter::actionsForDefaultStylesheetFromDFARoot): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret): (WebCore::ContentExtensions::DFABytecodeInterpreter::actionsFromDFARoot): Deleted. * contentextensions/DFABytecodeInterpreter.h: Add a new bytecode AppendActionDefaultStylesheet to mark actions that are css-display-none that need to be put in the default stylesheet to be ignored or not as a whole. css-display-none actions with flags or domain rules and css-display-none actions after ignore-previous-rules actions are not to be in this precompiled stylesheet, but they will be applied as needed per page. The precompiled stylesheet is already applied if no ignore-previous-rules action is triggered. * loader/ResourceLoadInfo.h: Source/WebKit2: * UIProcess/API/APIUserContentExtensionStore.h: Increment version number to reflect changes in DFABytecode. Tools: * TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp: (TestWebKitAPI::TEST_F): Update and add tests for new possibilities with .* Canonical link: https://commits.webkit.org/163223@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@184644 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-05-20 17:56:17 +00:00
void emitAppendAction(uint64_t);
[Content Extensions] Implement branch compaction for DFA bytecode. https://bugs.webkit.org/show_bug.cgi?id=145619 Patch by Alex Christensen <achristensen@webkit.org> on 2015-06-16 Reviewed by Benjamin Poulain. Source/WebCore: This patch adds another pass to the DFABytecodeCompiler which finds where the bytecode from each node would be if it were compiled with no branch compaction, then uses that as a worst-case value to determine how many bytes are needed to store the relative jump distance. Then when linking, it will fill in the value as it already did, but with a variable size jump. The jumps are also now signed distances relative to where the jump is stored. This patch is covered by existing tests, which have many jumps that are near the -128/127 byte boundary, and the switch from 16-bit jumps to 32-bit jumps near the -65536/65535 byte boundary is analogous. * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/DFABytecode.h: (WebCore::ContentExtensions::smallestPossibleJumpSize): (WebCore::ContentExtensions::instructionSizeWithArguments): * contentextensions/DFABytecodeCompiler.cpp: (WebCore::ContentExtensions::append): (WebCore::ContentExtensions::appendZeroes): (WebCore::ContentExtensions::setBits): (WebCore::ContentExtensions::appendActionBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::emitAppendAction): (WebCore::ContentExtensions::DFABytecodeCompiler::longestPossibleJump): (WebCore::ContentExtensions::DFABytecodeCompiler::emitJump): (WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValue): (WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValueRange): (WebCore::ContentExtensions::DFABytecodeCompiler::emitTerminate): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNode): (WebCore::ContentExtensions::DFABytecodeCompiler::compiledNodeMaxBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::ranges): (WebCore::ContentExtensions::DFABytecodeCompiler::checkForRangeMaxBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::compileCheckForRange): (WebCore::ContentExtensions::DFABytecodeCompiler::nodeTransitionsMaxBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNodeTransitions): (WebCore::ContentExtensions::DFABytecodeCompiler::compile): (WebCore::ContentExtensions::set32Bits): Deleted. * contentextensions/DFABytecodeCompiler.h: * contentextensions/DFABytecodeInterpreter.cpp: (WebCore::ContentExtensions::getBits): (WebCore::ContentExtensions::getInstruction): (WebCore::ContentExtensions::jumpSizeInBytes): (WebCore::ContentExtensions::getJumpSize): (WebCore::ContentExtensions::getJumpDistance): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretAppendAction): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretTestFlagsAndAppendAction): (WebCore::ContentExtensions::DFABytecodeInterpreter::actionsForDefaultStylesheetFromDFARoot): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret): * loader/ResourceLoadInfo.h: Source/WebKit2: * UIProcess/API/APIUserContentExtensionStore.h: Increment version number to reflect changes to bytecode. Canonical link: https://commits.webkit.org/164078@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@185621 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-06-16 22:29:19 +00:00
void emitJump(uint32_t sourceNodeIndex, uint32_t destinationNodeIndex);
void emitCheckValue(uint8_t value, uint32_t sourceNodeIndex, uint32_t destinationNodeIndex, bool caseSensitive);
void emitCheckValueRange(uint8_t lowValue, uint8_t highValue, uint32_t sourceNodeIndex, uint32_t destinationNodeIndex, bool caseSensitive);
Compile DFA to bytecode. https://bugs.webkit.org/show_bug.cgi?id=142031 Reviewed by Benjamin Poulain. * WebCore.xcodeproj/project.pbxproj: * contentextensions/ContentExtensionsBackend.cpp: (WebCore::ContentExtensions::ContentExtensionsBackend::setRuleList): (WebCore::ContentExtensions::ContentExtensionsBackend::shouldBlockURL): * contentextensions/ContentExtensionsBackend.h: * contentextensions/DFA.cpp: (WebCore::ContentExtensions::DFA::nextState): Deleted. (WebCore::ContentExtensions::DFA::actions): Deleted. * contentextensions/DFA.h: (WebCore::ContentExtensions::DFA::size): (WebCore::ContentExtensions::DFA::nodeAt): * contentextensions/DFABytecode.h: Added. (WebCore::ContentExtensions::instructionSizeWithArguments): * contentextensions/DFABytecodeCompiler.cpp: Added. (WebCore::ContentExtensions::append): (WebCore::ContentExtensions::set32Bits): (WebCore::ContentExtensions::DFABytecodeCompiler::emitAppendAction): (WebCore::ContentExtensions::DFABytecodeCompiler::emitJump): (WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValue): (WebCore::ContentExtensions::DFABytecodeCompiler::emitTerminate): (WebCore::ContentExtensions::DFABytecodeCompiler::reserveBufferCapacity): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNode): (WebCore::ContentExtensions::DFABytecodeCompiler::compile): * contentextensions/DFABytecodeCompiler.h: Added. (WebCore::ContentExtensions::DFABytecodeCompiler::DFABytecodeCompiler): * contentextensions/DFABytecodeInterpreter.cpp: Added. (WebCore::ContentExtensions::getBits): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret): * contentextensions/DFABytecodeInterpreter.h: Added. (WebCore::ContentExtensions::DFABytecodeInterpreter::DFABytecodeInterpreter): Canonical link: https://commits.webkit.org/160136@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@180769 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-02-27 19:20:27 +00:00
void emitTerminate();
Vector<DFABytecode>& m_bytecode;
const DFA& m_dfa;
[Content Extensions] Implement branch compaction for DFA bytecode. https://bugs.webkit.org/show_bug.cgi?id=145619 Patch by Alex Christensen <achristensen@webkit.org> on 2015-06-16 Reviewed by Benjamin Poulain. Source/WebCore: This patch adds another pass to the DFABytecodeCompiler which finds where the bytecode from each node would be if it were compiled with no branch compaction, then uses that as a worst-case value to determine how many bytes are needed to store the relative jump distance. Then when linking, it will fill in the value as it already did, but with a variable size jump. The jumps are also now signed distances relative to where the jump is stored. This patch is covered by existing tests, which have many jumps that are near the -128/127 byte boundary, and the switch from 16-bit jumps to 32-bit jumps near the -65536/65535 byte boundary is analogous. * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/DFABytecode.h: (WebCore::ContentExtensions::smallestPossibleJumpSize): (WebCore::ContentExtensions::instructionSizeWithArguments): * contentextensions/DFABytecodeCompiler.cpp: (WebCore::ContentExtensions::append): (WebCore::ContentExtensions::appendZeroes): (WebCore::ContentExtensions::setBits): (WebCore::ContentExtensions::appendActionBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::emitAppendAction): (WebCore::ContentExtensions::DFABytecodeCompiler::longestPossibleJump): (WebCore::ContentExtensions::DFABytecodeCompiler::emitJump): (WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValue): (WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValueRange): (WebCore::ContentExtensions::DFABytecodeCompiler::emitTerminate): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNode): (WebCore::ContentExtensions::DFABytecodeCompiler::compiledNodeMaxBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::ranges): (WebCore::ContentExtensions::DFABytecodeCompiler::checkForRangeMaxBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::compileCheckForRange): (WebCore::ContentExtensions::DFABytecodeCompiler::nodeTransitionsMaxBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNodeTransitions): (WebCore::ContentExtensions::DFABytecodeCompiler::compile): (WebCore::ContentExtensions::set32Bits): Deleted. * contentextensions/DFABytecodeCompiler.h: * contentextensions/DFABytecodeInterpreter.cpp: (WebCore::ContentExtensions::getBits): (WebCore::ContentExtensions::getInstruction): (WebCore::ContentExtensions::jumpSizeInBytes): (WebCore::ContentExtensions::getJumpSize): (WebCore::ContentExtensions::getJumpDistance): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretAppendAction): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretTestFlagsAndAppendAction): (WebCore::ContentExtensions::DFABytecodeInterpreter::actionsForDefaultStylesheetFromDFARoot): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret): * loader/ResourceLoadInfo.h: Source/WebKit2: * UIProcess/API/APIUserContentExtensionStore.h: Increment version number to reflect changes to bytecode. Canonical link: https://commits.webkit.org/164078@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@185621 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-06-16 22:29:19 +00:00
Vector<uint32_t> m_maxNodeStartOffsets;
[Content Extensions] Relax restrictions on triggers that match everything. https://bugs.webkit.org/show_bug.cgi?id=145069 Reviewed by Benjamin Poulain. Source/WebCore: Added API tests that cover the new functionality and test for correctness in behavior. * contentextensions/CompiledContentExtension.cpp: (WebCore::ContentExtensions::CompiledContentExtension::globalDisplayNoneSelectors): * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::addUniversalActionsToDFA): (WebCore::ContentExtensions::compileRuleList): Put universalActionsWithoutDomains into the DFA from filtersWithoutDomains and put universalActionsWithDomains into the DFA from filtersWithDomains. * contentextensions/ContentExtensionError.cpp: (WebCore::ContentExtensions::contentExtensionErrorCategory): * contentextensions/ContentExtensionError.h: Remove error codes for errors that are not errors any more. * contentextensions/ContentExtensionsBackend.cpp: (WebCore::ContentExtensions::ContentExtensionsBackend::actionsForResourceLoad): * contentextensions/ContentExtensionsBackend.h: * contentextensions/DFABytecode.h: (WebCore::ContentExtensions::instructionSizeWithArguments): * contentextensions/DFABytecodeCompiler.cpp: (WebCore::ContentExtensions::set32Bits): (WebCore::ContentExtensions::DFABytecodeCompiler::emitAppendAction): (WebCore::ContentExtensions::DFABytecodeCompiler::emitJump): (WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValue): (WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValueRange): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNode): (WebCore::ContentExtensions::DFABytecodeCompiler::compile): (WebCore::ContentExtensions::DFABytecodeCompiler::emitTestFlagsAndAppendAction): Deleted. * contentextensions/DFABytecodeCompiler.h: * contentextensions/DFABytecodeInterpreter.cpp: (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretAppendAction): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretTestFlagsAndAppendAction): (WebCore::ContentExtensions::DFABytecodeInterpreter::actionsForDefaultStylesheetFromDFARoot): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret): (WebCore::ContentExtensions::DFABytecodeInterpreter::actionsFromDFARoot): Deleted. * contentextensions/DFABytecodeInterpreter.h: Add a new bytecode AppendActionDefaultStylesheet to mark actions that are css-display-none that need to be put in the default stylesheet to be ignored or not as a whole. css-display-none actions with flags or domain rules and css-display-none actions after ignore-previous-rules actions are not to be in this precompiled stylesheet, but they will be applied as needed per page. The precompiled stylesheet is already applied if no ignore-previous-rules action is triggered. * loader/ResourceLoadInfo.h: Source/WebKit2: * UIProcess/API/APIUserContentExtensionStore.h: Increment version number to reflect changes in DFABytecode. Tools: * TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp: (TestWebKitAPI::TEST_F): Update and add tests for new possibilities with .* Canonical link: https://commits.webkit.org/163223@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@184644 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-05-20 17:56:17 +00:00
Vector<uint32_t> m_nodeStartOffsets;
Compile DFA to bytecode. https://bugs.webkit.org/show_bug.cgi?id=142031 Reviewed by Benjamin Poulain. * WebCore.xcodeproj/project.pbxproj: * contentextensions/ContentExtensionsBackend.cpp: (WebCore::ContentExtensions::ContentExtensionsBackend::setRuleList): (WebCore::ContentExtensions::ContentExtensionsBackend::shouldBlockURL): * contentextensions/ContentExtensionsBackend.h: * contentextensions/DFA.cpp: (WebCore::ContentExtensions::DFA::nextState): Deleted. (WebCore::ContentExtensions::DFA::actions): Deleted. * contentextensions/DFA.h: (WebCore::ContentExtensions::DFA::size): (WebCore::ContentExtensions::DFA::nodeAt): * contentextensions/DFABytecode.h: Added. (WebCore::ContentExtensions::instructionSizeWithArguments): * contentextensions/DFABytecodeCompiler.cpp: Added. (WebCore::ContentExtensions::append): (WebCore::ContentExtensions::set32Bits): (WebCore::ContentExtensions::DFABytecodeCompiler::emitAppendAction): (WebCore::ContentExtensions::DFABytecodeCompiler::emitJump): (WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValue): (WebCore::ContentExtensions::DFABytecodeCompiler::emitTerminate): (WebCore::ContentExtensions::DFABytecodeCompiler::reserveBufferCapacity): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNode): (WebCore::ContentExtensions::DFABytecodeCompiler::compile): * contentextensions/DFABytecodeCompiler.h: Added. (WebCore::ContentExtensions::DFABytecodeCompiler::DFABytecodeCompiler): * contentextensions/DFABytecodeInterpreter.cpp: Added. (WebCore::ContentExtensions::getBits): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret): * contentextensions/DFABytecodeInterpreter.h: Added. (WebCore::ContentExtensions::DFABytecodeInterpreter::DFABytecodeInterpreter): Canonical link: https://commits.webkit.org/160136@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@180769 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-02-27 19:20:27 +00:00
[Content Extensions] Implement branch compaction for DFA bytecode. https://bugs.webkit.org/show_bug.cgi?id=145619 Patch by Alex Christensen <achristensen@webkit.org> on 2015-06-16 Reviewed by Benjamin Poulain. Source/WebCore: This patch adds another pass to the DFABytecodeCompiler which finds where the bytecode from each node would be if it were compiled with no branch compaction, then uses that as a worst-case value to determine how many bytes are needed to store the relative jump distance. Then when linking, it will fill in the value as it already did, but with a variable size jump. The jumps are also now signed distances relative to where the jump is stored. This patch is covered by existing tests, which have many jumps that are near the -128/127 byte boundary, and the switch from 16-bit jumps to 32-bit jumps near the -65536/65535 byte boundary is analogous. * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * contentextensions/DFABytecode.h: (WebCore::ContentExtensions::smallestPossibleJumpSize): (WebCore::ContentExtensions::instructionSizeWithArguments): * contentextensions/DFABytecodeCompiler.cpp: (WebCore::ContentExtensions::append): (WebCore::ContentExtensions::appendZeroes): (WebCore::ContentExtensions::setBits): (WebCore::ContentExtensions::appendActionBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::emitAppendAction): (WebCore::ContentExtensions::DFABytecodeCompiler::longestPossibleJump): (WebCore::ContentExtensions::DFABytecodeCompiler::emitJump): (WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValue): (WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValueRange): (WebCore::ContentExtensions::DFABytecodeCompiler::emitTerminate): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNode): (WebCore::ContentExtensions::DFABytecodeCompiler::compiledNodeMaxBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::ranges): (WebCore::ContentExtensions::DFABytecodeCompiler::checkForRangeMaxBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::compileCheckForRange): (WebCore::ContentExtensions::DFABytecodeCompiler::nodeTransitionsMaxBytecodeSize): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNodeTransitions): (WebCore::ContentExtensions::DFABytecodeCompiler::compile): (WebCore::ContentExtensions::set32Bits): Deleted. * contentextensions/DFABytecodeCompiler.h: * contentextensions/DFABytecodeInterpreter.cpp: (WebCore::ContentExtensions::getBits): (WebCore::ContentExtensions::getInstruction): (WebCore::ContentExtensions::jumpSizeInBytes): (WebCore::ContentExtensions::getJumpSize): (WebCore::ContentExtensions::getJumpDistance): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretAppendAction): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretTestFlagsAndAppendAction): (WebCore::ContentExtensions::DFABytecodeInterpreter::actionsForDefaultStylesheetFromDFARoot): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret): * loader/ResourceLoadInfo.h: Source/WebKit2: * UIProcess/API/APIUserContentExtensionStore.h: Increment version number to reflect changes to bytecode. Canonical link: https://commits.webkit.org/164078@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@185621 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-06-16 22:29:19 +00:00
struct LinkRecord {
DFABytecodeJumpSize jumpSize;
int32_t longestPossibleJump;
uint32_t instructionLocation;
uint32_t jumpLocation;
uint32_t destinationNodeIndex;
};
Vector<LinkRecord> m_linkRecords;
Compile DFA to bytecode. https://bugs.webkit.org/show_bug.cgi?id=142031 Reviewed by Benjamin Poulain. * WebCore.xcodeproj/project.pbxproj: * contentextensions/ContentExtensionsBackend.cpp: (WebCore::ContentExtensions::ContentExtensionsBackend::setRuleList): (WebCore::ContentExtensions::ContentExtensionsBackend::shouldBlockURL): * contentextensions/ContentExtensionsBackend.h: * contentextensions/DFA.cpp: (WebCore::ContentExtensions::DFA::nextState): Deleted. (WebCore::ContentExtensions::DFA::actions): Deleted. * contentextensions/DFA.h: (WebCore::ContentExtensions::DFA::size): (WebCore::ContentExtensions::DFA::nodeAt): * contentextensions/DFABytecode.h: Added. (WebCore::ContentExtensions::instructionSizeWithArguments): * contentextensions/DFABytecodeCompiler.cpp: Added. (WebCore::ContentExtensions::append): (WebCore::ContentExtensions::set32Bits): (WebCore::ContentExtensions::DFABytecodeCompiler::emitAppendAction): (WebCore::ContentExtensions::DFABytecodeCompiler::emitJump): (WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValue): (WebCore::ContentExtensions::DFABytecodeCompiler::emitTerminate): (WebCore::ContentExtensions::DFABytecodeCompiler::reserveBufferCapacity): (WebCore::ContentExtensions::DFABytecodeCompiler::compileNode): (WebCore::ContentExtensions::DFABytecodeCompiler::compile): * contentextensions/DFABytecodeCompiler.h: Added. (WebCore::ContentExtensions::DFABytecodeCompiler::DFABytecodeCompiler): * contentextensions/DFABytecodeInterpreter.cpp: Added. (WebCore::ContentExtensions::getBits): (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret): * contentextensions/DFABytecodeInterpreter.h: Added. (WebCore::ContentExtensions::DFABytecodeInterpreter::DFABytecodeInterpreter): Canonical link: https://commits.webkit.org/160136@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@180769 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-02-27 19:20:27 +00:00
};
} // namespace ContentExtensions
} // namespace WebCore
#endif // ENABLE(CONTENT_EXTENSIONS)