<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>147110</bug_id>
          
          <creation_ts>2015-07-20 08:24:02 -0700</creation_ts>
          <short_desc>Possible fix for JSC api test failures in debug mode after r187020.</short_desc>
          <delta_ts>2015-07-20 12:41:39 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Web Template Framework</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>peavo</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>achristensen</cc>
    
    <cc>benjamin</cc>
    
    <cc>bfulgham</cc>
    
    <cc>cmarcelo</cc>
    
    <cc>commit-queue</cc>
    
    <cc>ddkilzer</cc>
    
    <cc>fpizlo</cc>
    
    <cc>ggaren</cc>
    
    <cc>mark.lam</cc>
    
    <cc>msaboff</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1110624</commentid>
    <comment_count>0</comment_count>
    <who name="">peavo</who>
    <bug_when>2015-07-20 08:24:02 -0700</bug_when>
    <thetext>After r187020, a debug assertion is failing during JSC api tests:

ASSERTION FAILED: !identifierByPthreadHandle(pthreadHandle)
/Volumes/Data/slave/mavericks-cloop-debug/build/Source/WTF/wtf/ThreadingPthreads.cpp(154) : ThreadIdentifier WTF::establishIdentifierForPthreadHandle(const pthread_t &amp;)
1   0x1078e1510 WTFCrash
2   0x10793cac7 WTF::establishIdentifierForPthreadHandle(_opaque_pthread_t* const&amp;)
3   0x10793c730 WTF::createThreadInternal(void (*)(void*), void*, char const*)
4   0x10793af57 WTF::createThread(char const*, std::__1::function&lt;void ()&gt;)
5   0x10793b0b5 WTF::createThread(void (*)(void*), void*, char const*)
6   0x107446317 JSC::GCThreadSharedData::GCThreadSharedData(JSC::VM*)
7   0x107445c7d JSC::GCThreadSharedData::GCThreadSharedData(JSC::VM*)
8   0x107451a44 JSC::Heap::Heap(JSC::VM*, JSC::HeapType)
9   0x1074517b3 JSC::Heap::Heap(JSC::VM*, JSC::HeapType)
10  0x10788b80f JSC::VM::VM(JSC::VM::VMType, JSC::HeapType)
11  0x10788b731 JSC::VM::VM(JSC::VM::VMType, JSC::HeapType)
12  0x10788ea0c JSC::VM::createContextGroup(JSC::HeapType)
13  0x107554ceb JSContextGroupCreate
14  0x107647885 -[JSVirtualMachine init]
15  0x10755356d -[JSContext init]
16  0x1072739dd currentThisInsideBlockGetterTest()
17  0x107294888 testObjectiveCAPIMain()
18  0x1072859e4 testObjectiveCAPI
19  0x10727bec3 main
20  0x7fff9439c5fd start</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1110627</commentid>
    <comment_count>1</comment_count>
      <attachid>257095</attachid>
    <who name="">peavo</who>
    <bug_when>2015-07-20 08:32:29 -0700</bug_when>
    <thetext>Created attachment 257095
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1110636</commentid>
    <comment_count>2</comment_count>
    <who name="">peavo</who>
    <bug_when>2015-07-20 09:25:39 -0700</bug_when>
    <thetext>I have not been able to verify that this patch fixes the tests, since Windows is not using pthreads.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1110638</commentid>
    <comment_count>3</comment_count>
      <attachid>257095</attachid>
    <who name="Mark Lam">mark.lam</who>
    <bug_when>2015-07-20 09:36:33 -0700</bug_when>
    <thetext>Comment on attachment 257095
Patch

Thanks for your diagnosis of the bug.  However, I do agree with the fix.  Your approach still has a race condition where the same pthreadHandle can be added to the threadMap() twice.  Let me take care of the bug since I can test it on mavericks.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1110639</commentid>
    <comment_count>4</comment_count>
    <who name="Mark Lam">mark.lam</who>
    <bug_when>2015-07-20 09:36:56 -0700</bug_when>
    <thetext>(In reply to comment #3)
&gt; Comment on attachment 257095 [details]
&gt; Patch
&gt; 
&gt; Thanks for your diagnosis of the bug.  However, I do agree with the fix. 
&gt; Your approach still has a race condition where the same pthreadHandle can be
&gt; added to the threadMap() twice.  Let me take care of the bug since I can
&gt; test it on mavericks.

Correction: I *don&apos;t* agree with the fix.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1110640</commentid>
    <comment_count>5</comment_count>
    <who name="">peavo</who>
    <bug_when>2015-07-20 09:38:49 -0700</bug_when>
    <thetext>(In reply to comment #3)
&gt; Comment on attachment 257095 [details]
&gt; Patch
&gt; 
&gt; Thanks for your diagnosis of the bug.  However, I do agree with the fix. 
&gt; Your approach still has a race condition where the same pthreadHandle can be
&gt; added to the threadMap() twice.  Let me take care of the bug since I can
&gt; test it on mavericks.

Ok, thanks :)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1110659</commentid>
    <comment_count>6</comment_count>
    <who name="Mark Lam">mark.lam</who>
    <bug_when>2015-07-20 11:02:04 -0700</bug_when>
    <thetext>I dug into this, and see that Threading.cpp&apos;s threadEntryPoint() should have ensured that currentThread() is not called on the new thread until after the ThreadIdentifier has been established.  Hence, Per&apos;s suspected race condition is not the root cause.  We should roll out r187020 and r187021 until this issue is fixed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1110671</commentid>
    <comment_count>7</comment_count>
    <who name="Mark Lam">mark.lam</who>
    <bug_when>2015-07-20 11:16:05 -0700</bug_when>
    <thetext>Rolled out r187020 and r187021 in r187026: &lt;http://trac.webkit.org/r187026&gt;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1110676</commentid>
    <comment_count>8</comment_count>
    <who name="">peavo</who>
    <bug_when>2015-07-20 11:23:27 -0700</bug_when>
    <thetext>(In reply to comment #7)
&gt; Rolled out r187020 and r187021 in r187026: &lt;http://trac.webkit.org/r187026&gt;.

Thanks for sorting this out, Mark :) And sorry for the noise, I can have a look, and see if I can spot other possible causes for the assert.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1110697</commentid>
    <comment_count>9</comment_count>
    <who name="">peavo</who>
    <bug_when>2015-07-20 11:57:26 -0700</bug_when>
    <thetext>Is this a possible scenario for the assert?

A thread not created with WTF::createThread() calls WTF::currentThread(), and then exits.
Next a thread created with WTF::createThread reuses the pthread_t handle, and then asserts.

For example, I see that JavaScriptCore\API\tests\testapi.mm is creating a thread using just pthread_create:

    @autoreleasepool {
        JSContext *context = [[JSContext alloc] init];
        
        pthread_t threadID;
        pthread_create(&amp;threadID, NULL, &amp;threadMain, (__bridge void*)context);
        pthread_join(threadID, nullptr);
        JSSynchronousGarbageCollectForDebugging([context JSGlobalContextRef]);

        checkResult(@&quot;Did not crash after entering the VM from another thread&quot;, true);
    }</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1110701</commentid>
    <comment_count>10</comment_count>
    <who name="Mark Lam">mark.lam</who>
    <bug_when>2015-07-20 12:05:49 -0700</bug_when>
    <thetext>(In reply to comment #9)
&gt; Is this a possible scenario for the assert?
&gt; 
&gt; A thread not created with WTF::createThread() calls WTF::currentThread(),
&gt; and then exits.
&gt; Next a thread created with WTF::createThread reuses the pthread_t handle,
&gt; and then asserts.

Yes, it looks like this is what&apos;s happening.  I&apos;m currently debugging the issue on Mavericks.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1110713</commentid>
    <comment_count>11</comment_count>
    <who name="Mark Lam">mark.lam</who>
    <bug_when>2015-07-20 12:29:48 -0700</bug_when>
    <thetext>(In reply to comment #10)
&gt; (In reply to comment #9)
&gt; &gt; Is this a possible scenario for the assert?
&gt; &gt; 
&gt; &gt; A thread not created with WTF::createThread() calls WTF::currentThread(),
&gt; &gt; and then exits.
&gt; &gt; Next a thread created with WTF::createThread reuses the pthread_t handle,
&gt; &gt; and then asserts.
&gt; 
&gt; Yes, it looks like this is what&apos;s happening.  I&apos;m currently debugging the
&gt; issue on Mavericks.

The real problem has to do with a thread destructor bug in Mavericks too.  All this brings to light that we should be using std::thread::id on every port except on Windows.  I&apos;ll closed this bug as resolved since we rolled out the offending patches.  I will work on a fix for bug 146448 that still allows Macs to use std::thread::id.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1110717</commentid>
    <comment_count>12</comment_count>
    <who name="">peavo</who>
    <bug_when>2015-07-20 12:41:39 -0700</bug_when>
    <thetext>(In reply to comment #11)
&gt; 
&gt; The real problem has to do with a thread destructor bug in Mavericks too. 
&gt; All this brings to light that we should be using std::thread::id on every
&gt; port except on Windows.  I&apos;ll closed this bug as resolved since we rolled
&gt; out the offending patches.  I will work on a fix for bug 146448 that still
&gt; allows Macs to use std::thread::id.

Thanks!</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>257095</attachid>
            <date>2015-07-20 08:32:29 -0700</date>
            <delta_ts>2015-07-20 09:36:33 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-147110-20150720173022.patch</filename>
            <type>text/plain</type>
            <size>1967</size>
            <attacher>peavo</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9XVEYvQ2hhbmdlTG9nCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KLS0tIFNvdXJjZS9XVEYvQ2hh
bmdlTG9nCShyZXZpc2lvbiAxODcwMjEpCisrKyBTb3VyY2UvV1RGL0NoYW5nZUxvZwkod29ya2lu
ZyBjb3B5KQpAQCAtMSwzICsx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tlciBsb2NrZXIodGhyZWFkTWFwTXV0
ZXgoKSk7CiAgICAgc3RhdGljIFRocmVhZElkZW50aWZpZXIgaWRlbnRpZmllckNvdW50ID0gMTsK
ICAgICB0aHJlYWRNYXAoKS5hZGQoaWRlbnRpZmllckNvdW50LCBzdGQ6Om1ha2VfdW5pcXVlPFB0
aHJlYWRTdGF0ZT4ocHRocmVhZEhhbmRsZSkpOwo=
</data>
<flag name="review"
          id="282213"
          type_id="1"
          status="-"
          setter="mark.lam"
    />
          </attachment>
      

    </bug>

</bugzilla>