<?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>45794</bug_id>
          
          <creation_ts>2010-09-14 17:38:47 -0700</creation_ts>
          <short_desc>[BREWMP] Don&apos;t use new in static initializers</short_desc>
          <delta_ts>2010-09-21 11:21:04 -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>528+ (Nightly build)</version>
          <rep_platform>Other</rep_platform>
          <op_sys>Other</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>
          
          <blocked>33564</blocked>
          <everconfirmed>0</everconfirmed>
          <reporter name="Kwang Yul Seo">skyul</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>darin</cc>
    
    <cc>eric</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>279274</commentid>
    <comment_count>0</comment_count>
    <who name="Kwang Yul Seo">skyul</who>
    <bug_when>2010-09-14 17:38:47 -0700</bug_when>
    <thetext>Calling new in static initializers causes a crash in Brew MP because Brew MP heap is not yet initialized at this time.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>279279</commentid>
    <comment_count>1</comment_count>
      <attachid>67625</attachid>
    <who name="Kwang Yul Seo">skyul</who>
    <bug_when>2010-09-14 17:43:57 -0700</bug_when>
    <thetext>Created attachment 67625
Patch

I know this patch is ugly by adding PLATFORM guard. However, if I remove new here, it causes a crash in other ports. See bug 23681 for the reason. Any smart solution here?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>279412</commentid>
    <comment_count>2</comment_count>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2010-09-14 23:49:24 -0700</bug_when>
    <thetext>I don&apos;t understand how this changes things.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>279421</commentid>
    <comment_count>3</comment_count>
    <who name="Kwang Yul Seo">skyul</who>
    <bug_when>2010-09-15 00:06:24 -0700</bug_when>
    <thetext>(In reply to comment #2)
&gt; I don&apos;t understand how this changes things.

1) static HashSet&lt;Structure*&gt;&amp; ignoreSet = *(new HashSet&lt;Structure*&gt;);

allocates the HashSet memory in the heap.
 

2) static HashSet&lt;Structure*&gt; ignoreSet;

allocates the HashSet memory in the data section.


BMP heap is not yet initialized at C++ static initialization time. So it is illegal to call new (which eventually calls Brew MP&apos;s MALLOC) in static initializers.

2) never calls MALLOC. So it is okay.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>279596</commentid>
    <comment_count>4</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2010-09-15 10:10:56 -0700</bug_when>
    <thetext>But the project doesn’t allow global initializers anyway, so this should never come up.

What’s an example of an object where this happens?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>279603</commentid>
    <comment_count>5</comment_count>
    <who name="Kwang Yul Seo">skyul</who>
    <bug_when>2010-09-15 10:24:46 -0700</bug_when>
    <thetext>(In reply to comment #4)
&gt; But the project doesn’t allow global initializers anyway, so this should never come up.
&gt; 
&gt; What’s an example of an object where this happens?

Yes, I know WebKit does not use global initializers. However, there are a few places where global initializers are used to count memory leaks. This happens only in Debug build.


For example, in JavaScriptCore/runtime/Structure.cpp

static Mutex&amp; ignoreSetMutex = *(new Mutex);

static HashSet&lt;Structure*&gt;&amp; ignoreSet = *(new HashSet&lt;Structure*&gt;);

static HashSet&lt;Structure*&gt;&amp; liveStructureSet = *(new HashSet&lt;Structure*&gt;);

The above three lines call new in global initializers.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>280945</commentid>
    <comment_count>6</comment_count>
    <who name="Kwang Yul Seo">skyul</who>
    <bug_when>2010-09-17 15:46:20 -0700</bug_when>
    <thetext>I think the better way to solve this problem is to remove the use of global initializers even in Debug build. We can use lazy initialization in memory leak counting and other statistics. I will come up with new patch.

Close the bug as &quot;won&apos;t fix&quot;.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>67625</attachid>
            <date>2010-09-14 17:43:57 -0700</date>
            <delta_ts>2010-09-21 11:21:04 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>staticinit.patch</filename>
            <type>text/plain</type>
            <size>1632</size>
            <attacher name="Kwang Yul Seo">skyul</attacher>
            
              <data encoding="base64">SW5kZXg6IEphdmFTY3JpcHRDb3JlL0NoYW5nZUxvZwo9PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ci0tLSBKYXZhU2NyaXB0
Q29yZS9DaGFuZ2VMb2cJKHJldmlzaW9uIDY3NTIwKQorKysgSmF2YVNjcmlwdENvcmUvQ2hhbmdl
TG9nCSh3b3JraW5nIGNvcHkpCkBAIC0xLDMgKzEsMTUgQEAKKzIwMTAtMDktMTQgIEt3YW5nIFl1
bCBTZW8gIDxza3l1bEBjb21wYW55MTAwLm5ldD4KKworICAgICAgICBSZXZpZXdlZCBieSBOT0JP
RFkgKE9PUFMhKS4KKworICAgICAgICBbQlJFV01QXSBEb24ndCB1c2UgbmV3IGluIHN0YXRpYyBp
bml0aWFsaXplcnMKKyAgICAgICAgaHR0cHM6Ly9idWdzLndlYmtpdC5vcmcvc2hvd19idWcuY2dp
P2lkPTQ1Nzk0CisKKyAgICAgICAgQ2FsbGluZyBuZXcgaW4gc3RhdGljIGluaXRpYWxpemVycyBj
YXVzZXMgYSBjcmFzaCBpbiBCcmV3IE1QIGJlY2F1c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