From 84fec92ef724b3628917bf6ac1e8282353bf9aff Mon Sep 17 00:00:00 2001
From: "eric@webkit.org" <eric@webkit.org@bbb929c8-8fbe-4397-9dbb-9b2b20218538>
Date: Thu, 14 Mar 2013 09:25:01 +0000
Subject: Threaded HTML Parser should limit speculation to avoid using too much
 memory https://bugs.webkit.org/show_bug.cgi?id=112069

Reviewed by Adam Barth.

Source/WebCore:

This is a speculative fix for memory issues seen in:
https://code.google.com/p/chromium/issues/detail?id=180819

This also fixed https://bugs.webkit.org/show_bug.cgi?id=110546
as a side-effect of simplifying the m_currentChunk handling.

We now tell the background html parser every time we start
a chunk on the main thread (instead of end), which greatly
simplified the checkpoint cleanup code from:
https://trac.webkit.org/changeset/145277

The cost for this is now we have more messages going to the
background thread (and postTask acquires a lock to write to the
message queue).  Chromium has more advanced (lock-less) primatives
for message posting, which we'll hopefully add to WebKit in
furture patches.

The outstanding chunks limit has not been tuned.  But it makes sense that
we should not keeping infinite speculative tokens around for
large documents with slow-to-load scripts.

* html/parser/BackgroundHTMLInputStream.cpp:
(WebCore::BackgroundHTMLInputStream::BackgroundHTMLInputStream):
(WebCore::BackgroundHTMLInputStream::invalidateCheckpointsBefore):
(WebCore):
(WebCore::BackgroundHTMLInputStream::rewindTo):
* html/parser/BackgroundHTMLInputStream.h:
(BackgroundHTMLInputStream):
(WebCore::BackgroundHTMLInputStream::outstandingCheckpointCount):
(Checkpoint):
(WebCore::BackgroundHTMLInputStream::Checkpoint::isNull):
(WebCore::BackgroundHTMLInputStream::Checkpoint::clear):
* html/parser/BackgroundHTMLParser.cpp:
(WebCore):
(WebCore::BackgroundHTMLParser::startedChunkWithCheckpoint):
(WebCore::BackgroundHTMLParser::pumpTokenizer):
* html/parser/BackgroundHTMLParser.h:
(BackgroundHTMLParser):
* html/parser/HTMLDocumentParser.cpp:
(WebCore::HTMLDocumentParser::validateSpeculations):
(WebCore::HTMLDocumentParser::discardSpeculationsAndResumeFrom):
(WebCore::HTMLDocumentParser::processParsedChunkFromBackgroundParser):
(WebCore::HTMLDocumentParser::pumpPendingSpeculations):
(WebCore::HTMLDocumentParser::resumeParsingAfterScriptExecution):
* html/parser/HTMLDocumentParser.h:
(HTMLDocumentParser):

LayoutTests:

Test that this fixes https://bugs.webkit.org/show_bug.cgi?id=110546 for the threaded parser.
Ports using the main-thread parser are expected to fail (ASSERT in Debug).

* fast/parser/document-write-partial-entity-before-load-expected.txt: Added.
* fast/parser/document-write-partial-entity-before-load.html: Added.
* fast/parser/external-script-document-write-expected.txt: Added.
* fast/parser/external-script-document-write.html: Added.
* fast/parser/resources/external-script-document-write.js: Added.
* platform/gtk/TestExpectations:
* platform/mac/TestExpectations:
* platform/qt/TestExpectations:


git-svn-id: svn://svn.chromium.org/blink/trunk@145797 bbb929c8-8fbe-4397-9dbb-9b2b20218538
---
 .../LayoutTests/fast/parser/resources/external-script-document-write.js  | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 third_party/WebKit/LayoutTests/fast/parser/resources/external-script-document-write.js

(limited to 'third_party/WebKit/LayoutTests/fast/parser/resources/external-script-document-write.js')

diff --git a/third_party/WebKit/LayoutTests/fast/parser/resources/external-script-document-write.js b/third_party/WebKit/LayoutTests/fast/parser/resources/external-script-document-write.js
new file mode 100644
index 0000000..40e6d56
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/parser/resources/external-script-document-write.js
@@ -0,0 +1 @@
+document.write("<plaintext>");
-- 
cgit v1.1