Bug 112762 - Add an assertion to ensure AtomicString from two different threads are not compared
Summary: Add an assertion to ensure AtomicString from two different threads are not co...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Benjamin Poulain
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-19 18:00 PDT by Benjamin Poulain
Modified: 2013-07-15 12:52 PDT (History)
8 users (show)

See Also:


Attachments
Patch (12.46 KB, patch)
2013-03-19 18:03 PDT, Benjamin Poulain
no flags Details | Formatted Diff | Diff
Patch (12.97 KB, patch)
2013-06-27 14:49 PDT, Benjamin Poulain
ap: review+
buildbot: commit-queue-
Details | Formatted Diff | Diff
Archive of layout-test-results from APPLE-EWS-5 for win-future (817.09 KB, application/zip)
2013-06-28 16:48 PDT, Build Bot
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Poulain 2013-03-19 18:00:04 PDT
Add an assertion to ensure AtomicString from two different threads are not compared
Comment 1 Benjamin Poulain 2013-03-19 18:03:57 PDT
Created attachment 193959 [details]
Patch
Comment 2 Benjamin Poulain 2013-03-19 18:07:58 PDT
A tiny step toward more safety debugging WebCore code with threads.

I will have to modify WebCore accordingly (some HashTable use StringImpl* directly).
Comment 3 Eric Seidel (no email) 2013-03-19 18:11:56 PDT
YES  I'm glad you're adding this.  Sad that it's only turned on when that option is turned on.  Maybe this should always be on for Debug?
Comment 4 Eric Seidel (no email) 2013-03-19 18:12:56 PDT
Also, be aware that abarth is in the process of making HTMLNames and friends static Atomic strings, which would allow them to be used in multiple AtomicStringTables, and potentially safe for x-thread compares.
Comment 5 Benjamin Poulain 2013-03-19 18:22:25 PDT
(In reply to comment #3)
> YES  I'm glad you're adding this.  Sad that it's only turned on when that option is turned on.  Maybe this should always be on for Debug?

ASSERT_ATOMIC_STRINGIMPL_THREAD_CONSISTENCY is enabled on !ASSERT_DISABLED
It will be enabled on the vast majority of debug builds.

(In reply to comment #4)
> Also, be aware that abarth is in the process of making HTMLNames and friends static Atomic strings, which would allow them to be used in multiple AtomicStringTables, and potentially safe for x-thread compares.

I am really excited about that work actually :)

When it lands, we will need to change the assertion accordingly (probably just add that a && b must be static).
Comment 6 Adam Barth 2013-03-19 18:42:29 PDT
This looks interesting.  Would be willing to wait on landing this patch until after https://bugs.webkit.org/show_bug.cgi?id=112769 lands?
Comment 7 Benjamin Poulain 2013-03-19 18:49:37 PDT
(In reply to comment #6)
> This looks interesting.  Would be willing to wait on landing this patch until after https://bugs.webkit.org/show_bug.cgi?id=112769 lands?

Not a problem.

But I don't think the 2 patches conflicts. It will just be 1 more condition in the assertion + 1 more initialization in the constructor.
Comment 8 Adam Barth 2013-03-19 19:03:17 PDT
This patch assumes that a string impl is only ever in one atomic string table.  That assumption might or might not remain true after my patch.
Comment 9 Benjamin Poulain 2013-06-27 14:49:36 PDT
Created attachment 205639 [details]
Patch
Comment 10 Build Bot 2013-06-28 16:48:04 PDT
Comment on attachment 205639 [details]
Patch

Attachment 205639 [details] did not pass win-ews (win):
Output: http://webkit-queues.appspot.com/results/998356

New failing tests:
fast/forms/select/popup-closes-on-blur.html
Comment 11 Build Bot 2013-06-28 16:48:07 PDT
Created attachment 205757 [details]
Archive of layout-test-results from APPLE-EWS-5 for win-future

The attached test failures were seen while running run-webkit-tests on the win-ews.
Bot: APPLE-EWS-5  Port: win-future  Platform: CYGWIN_NT-6.1-WOW64-1.7.20-0.266-5-3-i686-32bit
Comment 12 Alexey Proskuryakov 2013-07-15 12:52:15 PDT
Comment on attachment 205639 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=205639&action=review

> Source/WTF/wtf/text/AtomicString.cpp:431
> +    r->setAtomicStringTable(0);

Perhaps not part of this patch, but we really need to assert that we are not removing from the wrong table here.

> Source/WTF/wtf/text/AtomicStringImpl.h:48
> +ALWAYS_INLINE bool safeAtomicEqual(const AtomicStringImpl* a, const AtomicStringImpl* b)

I'm not a fan of "safe" names, they don't really explain much. Perhaps "equalWithThreadingAssertion"? Or just split the assertion into a separate function, and have callers invoke it explicitly before comparing pointers?

The latter seems preferable to me.