<?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>182923</bug_id>
          
          <creation_ts>2018-02-19 03:01:18 -0800</creation_ts>
          <short_desc>REGRESSION(r227717): Hardcoded page size causing JSC crashes on platforms with page size bigger than 16 KB</short_desc>
          <delta_ts>2018-06-16 12:01:36 -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>JavaScriptCore</component>
          <version>WebKit 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>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Tomas Popela">tpopela</reporter>
          <assigned_to name="Michael Catanzaro">mcatanzaro</assigned_to>
          <cc>berto</cc>
    
    <cc>commit-queue</cc>
    
    <cc>ews-watchlist</cc>
    
    <cc>fpizlo</cc>
    
    <cc>keith_miller</cc>
    
    <cc>mark.lam</cc>
    
    <cc>mcatanzaro</cc>
    
    <cc>msaboff</cc>
    
    <cc>saam</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1400311</commentid>
    <comment_count>0</comment_count>
    <who name="Tomas Popela">tpopela</who>
    <bug_when>2018-02-19 03:01:18 -0800</bug_when>
    <thetext>After r227717 the JSC crashes on architectures that do have 64KB page size with:

1   0x7ffff76b4090 WTFCrash
2   0x7ffff776f0e8 WTF::OSAllocator::decommit(void*, unsigned long)
3   0x7ffff6e7493c JSC::IsoAlignedMemoryAllocator::freeAlignedMemory(void*)
4   0x7ffff6ea00a8 JSC::MarkedBlock::Handle::~Handle()
5   0x7ffff6ea3fe8 JSC::MarkedSpace::freeBlock(JSC::MarkedBlock::Handle*)
6   0x7ffff6dfca70
7   0x7ffff6dfe628
8   0x7ffff6dfcb14 JSC::BlockDirectory::shrink()
9   0x7ffff6ea40c0
10  0x7ffff6eac0ac
11  0x7ffff6ea4114 JSC::MarkedSpace::shrink()
12  0x7ffff6e17e48 JSC::Heap::sweepSynchronously()
13  0x7ffff6e181bc JSC::Heap::collectNow(JSC::Synchronousness, JSC::GCRequest)
14  0x1004d184
15  0x7ffff704cfe0 JSC::LLInt::CLoop::execute(JSC::OpcodeID, void*, JSC::VM*, JSC::ProtoCallFrame*, bool)
16  0x7ffff705e29c vmEntryToJavaScript
17  0x7ffff702c720 JSC::JITCode::execute(JSC::VM*, JSC::ProtoCallFrame*)
18  0x7ffff7007170 JSC::Interpreter::executeProgram(JSC::SourceCode const&amp;, JSC::ExecState*, JSC::JSObject*)
19  0x7ffff729b8a8 JSC::evaluate(JSC::ExecState*, JSC::SourceCode const&amp;, JSC::JSValue, WTF::NakedPtr&lt;JSC::Exception&gt;&amp;)
20  0x1005bb68
21  0x1005d0b8
22  0x1005e5a0
23  0x1005d1a8 jscmain(int, char**)
24  0x1005a3c4 main
25  0x7ffff3685b90
26  0x7ffff3685db8 __libc_start_main

It&apos;s because of

    static constexpr size_t blockSize = 16 * KB;

in MarkedBlock.cpp. Ideally the code should use pageSize() from wtf/PageBlock.h. But the code will need to be changed as the current way (static variable) won&apos;t work. And I don&apos;t know what sollution the JSC devs will prefer. Also I see that it was hardcoded even before, but the code was not crashing (at least in our PPC64(LE) CI).

Filip (or other JSC devs) can you please look at this?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1400339</commentid>
    <comment_count>1</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2018-02-19 05:40:36 -0800</bug_when>
    <thetext>It is inaccurate to say that this hardcodes page size. On Mac, the pages are 4KB and this logic all works.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1400355</commentid>
    <comment_count>2</comment_count>
    <who name="Tomas Popela">tpopela</who>
    <bug_when>2018-02-19 07:05:10 -0800</bug_when>
    <thetext>(In reply to Filip Pizlo from comment #1)
&gt; It is inaccurate to say that this hardcodes page size. On Mac, the pages are
&gt; 4KB and this logic all works.

Yes I know, but I wrote &quot;crashes on architectures that do have 64KB page size&quot;. I will update the bug title to reflect that</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1400359</commentid>
    <comment_count>3</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2018-02-19 07:30:03 -0800</bug_when>
    <thetext>It’s not accurate to say that MarkedBlock::blockSize is a hardcoded page size. It’s not a page size at all. It’s the block size. 

The solution is certainly not to make blockSize a runtime thing. Block size needs to be a constant.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1406202</commentid>
    <comment_count>4</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2018-03-13 12:56:54 -0700</bug_when>
    <thetext>Tom, do you have a patch that you want to propose for this? Ideally something that does *not* require us to roll out r227717. Even if it&apos;s just adding #if CPU() guards around the blockSize declaration.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1406204</commentid>
    <comment_count>5</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2018-03-13 12:59:29 -0700</bug_when>
    <thetext>(In reply to Michael Catanzaro from comment #4)
&gt; Tom, do you have a patch that you want to propose for this? Ideally
&gt; something that does *not* require us to roll out r227717. Even if it&apos;s just
&gt; adding #if CPU() guards around the blockSize declaration.

I don&apos;t think that rolling out r227717 is an option.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1406213</commentid>
    <comment_count>6</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2018-03-13 13:12:47 -0700</bug_when>
    <thetext>(In reply to Filip Pizlo from comment #5)
&gt; I don&apos;t think that rolling out r227717 is an option.

Yeah, we shouldn&apos;t need to. We&apos;re currently using this patch downstream:

https://src.fedoraproject.org/cgit/rpms/webkit2gtk3.git/tree/page-size.patch

So, without understanding anything about the code, this would work:

#if CPU(PPC64) || CPU(PPC64LE) || CPU(PPC) || CPU(S390) || CPU(S390X)
    static constexpr size_t blockSize = 64 * KB;
#else
    static constexpr size_t blockSize = 16 * KB;
#endif

We would need to add new WTF_CPU definitions for s390 and s390x.

It would be nicer if this were not needed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1406363</commentid>
    <comment_count>7</comment_count>
    <who name="Tomas Popela">tpopela</who>
    <bug_when>2018-03-14 00:39:13 -0700</bug_when>
    <thetext>(In reply to Michael Catanzaro from comment #6)
&gt; (In reply to Filip Pizlo from comment #5)
&gt; &gt; I don&apos;t think that rolling out r227717 is an option.
&gt; 
&gt; Yeah, we shouldn&apos;t need to. We&apos;re currently using this patch downstream:
&gt; 
&gt; https://src.fedoraproject.org/cgit/rpms/webkit2gtk3.git/tree/page-size.patch
&gt; 
&gt; So, without understanding anything about the code, this would work:
&gt; 
&gt; #if CPU(PPC64) || CPU(PPC64LE) || CPU(PPC) || CPU(S390) || CPU(S390X)
&gt;     static constexpr size_t blockSize = 64 * KB;
&gt; #else
&gt;     static constexpr size_t blockSize = 16 * KB;
&gt; #endif
&gt; 
&gt; We would need to add new WTF_CPU definitions for s390 and s390x.
&gt; 
&gt; It would be nicer if this were not needed.

This is not the exactly right solution (as I wrote in the downstream comment that it&apos;s a silly workaround) - the page size should be obtained with pageSize() from WTF that is platform agnostic. I just know that blockSize needs to be aligned with the page size, but I really don&apos;t how to &quot;easily&quot; do it, without bigger changes in the code that I really don&apos;t quite understand..</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1406371</commentid>
    <comment_count>8</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2018-03-14 06:29:27 -0700</bug_when>
    <thetext>(In reply to Tomas Popela from comment #7)
&gt; (In reply to Michael Catanzaro from comment #6)
&gt; &gt; (In reply to Filip Pizlo from comment #5)
&gt; &gt; &gt; I don&apos;t think that rolling out r227717 is an option.
&gt; &gt; 
&gt; &gt; Yeah, we shouldn&apos;t need to. We&apos;re currently using this patch downstream:
&gt; &gt; 
&gt; &gt; https://src.fedoraproject.org/cgit/rpms/webkit2gtk3.git/tree/page-size.patch
&gt; &gt; 
&gt; &gt; So, without understanding anything about the code, this would work:
&gt; &gt; 
&gt; &gt; #if CPU(PPC64) || CPU(PPC64LE) || CPU(PPC) || CPU(S390) || CPU(S390X)
&gt; &gt;     static constexpr size_t blockSize = 64 * KB;
&gt; &gt; #else
&gt; &gt;     static constexpr size_t blockSize = 16 * KB;
&gt; &gt; #endif
&gt; &gt; 
&gt; &gt; We would need to add new WTF_CPU definitions for s390 and s390x.
&gt; &gt; 
&gt; &gt; It would be nicer if this were not needed.
&gt; 
&gt; This is not the exactly right solution (as I wrote in the downstream comment
&gt; that it&apos;s a silly workaround) - the page size should be obtained with
&gt; pageSize() from WTF that is platform agnostic. I just know that blockSize
&gt; needs to be aligned with the page size, but I really don&apos;t how to &quot;easily&quot;
&gt; do it, without bigger changes in the code that I really don&apos;t quite
&gt; understand..

As I said before, blockSize really should not be gotten from pageSize because it needs to be a compile time constant. The right solution is to overestimate the blockSize or create an abstraction where GC blocks can allocate blockSize even if pageSize is bigger.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1433726</commentid>
    <comment_count>9</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2018-06-16 10:11:57 -0700</bug_when>
    <thetext>After chatting with Caitlin about this, and based on Filip&apos;s comments that the block size must be a compile-time constant and not computed from page size, I propose we just take the simple Fedora patch:

(In reply to Michael Catanzaro from comment #6)
&gt; #if CPU(PPC64) || CPU(PPC64LE) || CPU(PPC) || CPU(UNKNOWN)
&gt;     static constexpr size_t blockSize = 64 * KB;
&gt; #else
&gt;     static constexpr size_t blockSize = 16 * KB;
&gt; #endif

We can also define it at the CMake level and allow overriding it, but that makes cross-compiling more difficult and does not seem useful.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1433728</commentid>
    <comment_count>10</comment_count>
      <attachid>342883</attachid>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2018-06-16 10:16:44 -0700</bug_when>
    <thetext>Created attachment 342883
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1433729</commentid>
    <comment_count>11</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2018-06-16 10:17:51 -0700</bug_when>
    <thetext>(In reply to Tomas Popela from comment #7)
&gt; This is not the exactly right solution (as I wrote in the downstream comment
&gt; that it&apos;s a silly workaround) - the page size should be obtained with
&gt; pageSize() from WTF that is platform agnostic.

I think it&apos;s the right solution because Filip has expressed a requirement that blockSize be constant and not computed at runtime.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1433743</commentid>
    <comment_count>12</comment_count>
      <attachid>342883</attachid>
    <who name="Mark Lam">mark.lam</who>
    <bug_when>2018-06-16 11:21:00 -0700</bug_when>
    <thetext>Comment on attachment 342883
Patch

r=me</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1433749</commentid>
    <comment_count>13</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2018-06-16 11:33:59 -0700</bug_when>
    <thetext>Note that I&apos;m assuming overestimating block size will only be a performance issue for CPU(UNKNOWN), and not a correctness issue.

We used to have WTF_CPU_S390 and WTF_CPU_S390X before WTF_CPU_UNKNOWN, which could be brought back if need be (they also need the 64 KB block size), but I assume it&apos;s not needed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1433756</commentid>
    <comment_count>14</comment_count>
      <attachid>342883</attachid>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2018-06-16 12:00:21 -0700</bug_when>
    <thetext>Comment on attachment 342883
Patch

Clearing flags on attachment: 342883

Committed r232909: &lt;https://trac.webkit.org/changeset/232909&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1433757</commentid>
    <comment_count>15</comment_count>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2018-06-16 12:00:23 -0700</bug_when>
    <thetext>All reviewed patches have been landed.  Closing bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1433758</commentid>
    <comment_count>16</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2018-06-16 12:01:36 -0700</bug_when>
    <thetext>&lt;rdar://problem/41188975&gt;</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>342883</attachid>
            <date>2018-06-16 10:16:44 -0700</date>
            <delta_ts>2018-06-16 12:00:21 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-182923-20180616121643.patch</filename>
            <type>text/plain</type>
            <size>1808</size>
            <attacher name="Michael Catanzaro">mcatanzaro</attacher>
            
              <data encoding="base64">U3VidmVyc2lvbiBSZXZpc2lvbjogMjMyODk1CmRpZmYgLS1naXQgYS9Tb3VyY2UvSmF2YVNjcmlw
dENvcmUvQ2hhbmdlTG9nIGIvU291cmNlL0phdmFTY3JpcHRDb3JlL0NoYW5nZUxvZwppbmRleCA4
MjY5NTEwY2NjY2Y5ZTg3YTFiNTY2YjVhNDU1ZDgyZjZlNWJkODUyLi41ZWIwMTNkOTM1Y2IxMjhm
MjAwOWZiOTZkMDQ4Y2NhOTcyZDM0OGNkIDEwMDY0NAotLS0gYS9Tb3VyY2UvSmF2YVNjcmlwdENv
cmUvQ2hhbmdlTG9nCisrKyBiL1NvdXJjZS9KYXZhU2NyaXB0Q29yZS9DaGFuZ2VMb2cKQEAgLTEs
MyArMSwxNSBAQAorMjAxOC0wNi0xNiAgTWljaGFlbCBDYXRhbnphcm8gIDxtY2F0YW56YXJvQ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