Bug 45794 - [BREWMP] Don't use new in static initializers
Summary: [BREWMP] Don't use new in static initializers
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Other Other
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks: 33564
  Show dependency treegraph
 
Reported: 2010-09-14 17:38 PDT by Kwang Yul Seo
Modified: 2010-09-21 11:21 PDT (History)
2 users (show)

See Also:


Attachments
Patch (1.59 KB, patch)
2010-09-14 17:43 PDT, Kwang Yul Seo
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kwang Yul Seo 2010-09-14 17:38:47 PDT
Calling new in static initializers causes a crash in Brew MP because Brew MP heap is not yet initialized at this time.
Comment 1 Kwang Yul Seo 2010-09-14 17:43:57 PDT
Created attachment 67625 [details]
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?
Comment 2 Eric Seidel (no email) 2010-09-14 23:49:24 PDT
I don't understand how this changes things.
Comment 3 Kwang Yul Seo 2010-09-15 00:06:24 PDT
(In reply to comment #2)
> I don't understand how this changes things.

1) static HashSet<Structure*>& ignoreSet = *(new HashSet<Structure*>);

allocates the HashSet memory in the heap.
 

2) static HashSet<Structure*> 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's MALLOC) in static initializers.

2) never calls MALLOC. So it is okay.
Comment 4 Darin Adler 2010-09-15 10:10:56 PDT
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?
Comment 5 Kwang Yul Seo 2010-09-15 10:24:46 PDT
(In reply to comment #4)
> 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?

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& ignoreSetMutex = *(new Mutex);

static HashSet<Structure*>& ignoreSet = *(new HashSet<Structure*>);

static HashSet<Structure*>& liveStructureSet = *(new HashSet<Structure*>);

The above three lines call new in global initializers.
Comment 6 Kwang Yul Seo 2010-09-17 15:46:20 PDT
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 "won't fix".