Atomic Strings and static vars
It seems that AtomicStrings can't be used in static variables #0 WTF::HashTable<WebCore::StringImpl*, WebCore::StringImpl*, WTF::IdentityExtractor<WebCore::StringImpl*>, WTF::StrHash<WebCore::StringImpl*>, WTF::HashTraits<WebCore::StringImpl*>, WTF::HashTraits<WebCore::StringImpl*> >::invalidateIterators (this=0x0) at HashTable.h:713 #1 0xb7492432 in WTF::HashSet<WebCore::StringImpl*, WTF::StrHash<WebCore::StringImpl*>, WTF::HashTraits<WebCore::StringImpl*> >::add<char const*, WebCore::CStringTranslator> (this=0x0, value=@0xbf9e41b0) at HashTable.h:420 #2 0xb74905eb in WebCore::AtomicString::add (c=0xb7820af2 "Times New Roman") at ../../platform/AtomicString.cpp:90 #3 0xb7762346 in __static_initialization_and_destruction_0 ( __initialize_p=<value optimized out>, __priority=-65536) at AtomicString.h:36 #4 0xb77efb92 in __do_global_ctors_aux () from ../../WebCore/Projects/gdk/libwebcore-gdk.so #5 0xb73cb3bd in _init () from ../../WebCore/Projects/gdk/libwebcore-gdk.so #6 0xb7fdd194 in _dl_rtld_di_serinfo () from /lib/ld-linux.so.2 #7 0xb7fdd2be in _dl_rtld_di_serinfo () from /lib/ld-linux.so.2 #8 0xb7fd27ff in ?? () from /lib/ld-linux.so.2
Correct. The AtomicString hash won't be initialized by the time the constructor is called on a static AtomicString. Thats why you see AtomicString::init(() and HTMLNames::init(), etc. See HTMLNames.cpp to see how we get around this (placement new). -eric On Jun 4, 2006, at 9:02 AM, Mike Emmel wrote:
It seems that AtomicStrings can't be used in static variables
#0 WTF::HashTable<WebCore::StringImpl*, WebCore::StringImpl*, WTF::IdentityExtractor<WebCore::StringImpl*>, WTF::StrHash<WebCore::StringImpl*>, WTF::HashTraits<WebCore::StringImpl*>, WTF::HashTraits<WebCore::StringImpl*> >::invalidateIterators (this=0x0) at HashTable.h:713 #1 0xb7492432 in WTF::HashSet<WebCore::StringImpl*, WTF::StrHash<WebCore::StringImpl*>, WTF::HashTraits<WebCore::StringImpl*> >::add<char const*, WebCore::CStringTranslator> (this=0x0, value=@0xbf9e41b0) at HashTable.h:420 #2 0xb74905eb in WebCore::AtomicString::add (c=0xb7820af2 "Times New Roman") at ../../platform/AtomicString.cpp:90 #3 0xb7762346 in __static_initialization_and_destruction_0 ( __initialize_p=<value optimized out>, __priority=-65536) at AtomicString.h:36 #4 0xb77efb92 in __do_global_ctors_aux () from ../../WebCore/Projects/gdk/libwebcore-gdk.so #5 0xb73cb3bd in _init () from ../../WebCore/Projects/gdk/ libwebcore-gdk.so #6 0xb7fdd194 in _dl_rtld_di_serinfo () from /lib/ld-linux.so.2 #7 0xb7fdd2be in _dl_rtld_di_serinfo () from /lib/ld-linux.so.2 #8 0xb7fd27ff in ?? () from /lib/ld-linux.so.2 _______________________________________________ webkit-dev mailing list webkit-dev@opendarwin.org http://www.opendarwin.org/mailman/listinfo/webkit-dev
FYI, a static AtomicString would be a Bad Thing (TM) anyway, since it would require WebKit to have a static initialization routine for that string. Such a routine increases the start-up time and memory footprint of anything that links against WebKit, which includes just about everything that ships with OS X. (In fact, we have some open bugs about that.) Geoff On Jun 4, 2006, at 9:02 AM, Mike Emmel wrote:
It seems that AtomicStrings can't be used in static variables
#0 WTF::HashTable<WebCore::StringImpl*, WebCore::StringImpl*, WTF::IdentityExtractor<WebCore::StringImpl*>, WTF::StrHash<WebCore::StringImpl*>, WTF::HashTraits<WebCore::StringImpl*>, WTF::HashTraits<WebCore::StringImpl*> >::invalidateIterators (this=0x0) at HashTable.h:713 #1 0xb7492432 in WTF::HashSet<WebCore::StringImpl*, WTF::StrHash<WebCore::StringImpl*>, WTF::HashTraits<WebCore::StringImpl*> >::add<char const*, WebCore::CStringTranslator> (this=0x0, value=@0xbf9e41b0) at HashTable.h:420 #2 0xb74905eb in WebCore::AtomicString::add (c=0xb7820af2 "Times New Roman") at ../../platform/AtomicString.cpp:90 #3 0xb7762346 in __static_initialization_and_destruction_0 ( __initialize_p=<value optimized out>, __priority=-65536) at AtomicString.h:36 #4 0xb77efb92 in __do_global_ctors_aux () from ../../WebCore/Projects/gdk/libwebcore-gdk.so #5 0xb73cb3bd in _init () from ../../WebCore/Projects/gdk/ libwebcore-gdk.so #6 0xb7fdd194 in _dl_rtld_di_serinfo () from /lib/ld-linux.so.2 #7 0xb7fdd2be in _dl_rtld_di_serinfo () from /lib/ld-linux.so.2 #8 0xb7fd27ff in ?? () from /lib/ld-linux.so.2 _______________________________________________ webkit-dev mailing list webkit-dev@opendarwin.org http://www.opendarwin.org/mailman/listinfo/webkit-dev
On Jun 5, 2006, at 7:49 AM, Geoffrey Garen wrote:
FYI, a static AtomicString would be a Bad Thing (TM) anyway, since it would require WebKit to have a static initialization routine for that string. Such a routine increases the start-up time and memory footprint of anything that links against WebKit, which includes just about everything that ships with OS X. (In fact, we have some open bugs about that.)
You can use a static AtomicString inside a function. These types of global variables are initialized the first time the function is called. As Geoff says, because of requirements for the WebKit framework on OS X, global variables outside functions with constructors are not allowed in JavaScriptCore, WebCore, or WebKit. That's why you'll see a lot of globals with, say, a HashMap* type instead of just a HashMap. -- Darin
On 6/5/06, Darin Adler <darin@apple.com> wrote:
On Jun 5, 2006, at 7:49 AM, Geoffrey Garen wrote:
FYI, a static AtomicString would be a Bad Thing (TM) anyway, since it would require WebKit to have a static initialization routine for that string. Such a routine increases the start-up time and memory footprint of anything that links against WebKit, which includes just about everything that ships with OS X. (In fact, we have some open bugs about that.)
You can use a static AtomicString inside a function. These types of global variables are initialized the first time the function is called.
As Geoff says, because of requirements for the WebKit framework on OS X, global variables outside functions with constructors are not allowed in JavaScriptCore, WebCore, or WebKit. That's why you'll see a lot of globals with, say, a HashMap* type instead of just a HashMap.
-- Darin
Not disagreeing but the problem with global statics is technical and has to do with the order or lack thereof of the static constructors. In this case one is missing and in anycase order is never assured technically the static constructor may be on the wrong class. My opinion is you may want to fix the core classes to actually work correctly with global statics this probably means using a different static initializer on another class. The choice to use lazy initialization vs immediate is a different issue but globals should not be prevented by what seems to be a technical bug. I happen to agree with the lazy approach in this case I was thinking I'd use the same string in multiple places therfore the global turned out I did not need too so no biggie. But agian this does not mean the current implementation is correct. Mike
On Jun 5, 2006, at 12:14 PM, Mike Emmel wrote:
the problem with global statics is technical and has to do with the order or lack thereof of the static constructors
I'm not sure what you mean. For our frameworks for Mac OS X we have a constraint for performance reasons, entirely separate from the static initialization order issue. Because of that constraint, the WebKit project rule is "no static initialization at all". Yes, there are some technical issues about doing global static initialization right. But in this project we avoid them since we don't have any for the above reason.
In this case one is missing and in any case order is never assured technically the static constructor may be on the wrong class. My opinion is you may want to fix the core classes to actually work correctly with global statics
I don't think we want to do this, again for performance reasons. We don't want to pay for a global variable fetch and a branch when creating each AtomicString to check to see if the global initialization has been done yet. Instead, we have chosen the approach of not using AtomicString until after the AtomicString::init () function is called. -- Darin
On 6/5/06, Darin Adler <darin@apple.com> wrote:
On Jun 5, 2006, at 12:14 PM, Mike Emmel wrote:
the problem with global statics is technical and has to do with the order or lack thereof of the static constructors
I'm not sure what you mean.
For our frameworks for Mac OS X we have a constraint for performance reasons, entirely separate from the static initialization order issue. Because of that constraint, the WebKit project rule is "no static initialization at all".
No problem.
Yes, there are some technical issues about doing global static initialization right. But in this project we avoid them since we don't have any for the above reason.
In this case one is missing and in any case order is never assured technically the static constructor may be on the wrong class. My opinion is you may want to fix the core classes to actually work correctly with global statics
I don't think we want to do this, again for performance reasons.
We don't want to pay for a global variable fetch and a branch when creating each AtomicString to check to see if the global initialization has been done yet. Instead, we have chosen the approach of not using AtomicString until after the AtomicString::init () function is called.
By moving the static variable to be lazy you have ensured this. My point is that at least for gcc you can use static constructors to initialize AtomicString::init could be called from one of those. Agian I have no problem with all the reasons given to not make heavy use global static atomic string. I would argue that the reasons may not be valid for all possible ports of WebKit. If some one had a valid reason then it would at least intially be port specific. I think its a bug in the implementation that atomic string cannot be used for static variables regardless of OSX and the use cases on osx. If its fixed the patch could even be ifdef'ed to not function on OSX to prevent static variable from sneaking into generic code. I don't like basic stuff like AtomicString being broken its not a good thing. There is nothing wrong with making it work correctly andd efficiently in the case of global static variables and also nothing wrong with ifdefing that support so its not on by default. Later if there is a either port specific or real generic need the support can be turned on. I guess I'm a bit surprised your willing to leave a basic class like AtomicString broken because of current design decisions event if there often (not always) correct. At the very least add a comment to the header. Its tough to wager on a email list but I promise to buy and extra ipod if this is not fixed within the next two years. I don't see me loosing that bet :) Mike
-- Darin
Well I finally looked into the file I was going to create the patch and what do I find in AtomicString.cpp #include "config.h" #if AVOID_STATIC_CONSTRUCTORS #define ATOMICSTRING_HIDE_GLOBALS 1 #endif So someone thought it should be optional. Of course as I pointed out earlier AtomicString is broken so changing this ifdef will break the build. Mike On 6/5/06, Mike Emmel <mike.emmel@gmail.com> wrote:
On 6/5/06, Darin Adler <darin@apple.com> wrote:
On Jun 5, 2006, at 12:14 PM, Mike Emmel wrote:
the problem with global statics is technical and has to do with the order or lack thereof of the static constructors
I'm not sure what you mean.
For our frameworks for Mac OS X we have a constraint for performance reasons, entirely separate from the static initialization order issue. Because of that constraint, the WebKit project rule is "no static initialization at all".
No problem.
Yes, there are some technical issues about doing global static initialization right. But in this project we avoid them since we don't have any for the above reason.
In this case one is missing and in any case order is never assured technically the static constructor may be on the wrong class. My opinion is you may want to fix the core classes to actually work correctly with global statics
I don't think we want to do this, again for performance reasons.
We don't want to pay for a global variable fetch and a branch when creating each AtomicString to check to see if the global initialization has been done yet. Instead, we have chosen the approach of not using AtomicString until after the AtomicString::init () function is called.
By moving the static variable to be lazy you have ensured this. My point is that at least for gcc you can use static constructors to initialize AtomicString::init could be called from one of those.
Agian I have no problem with all the reasons given to not make heavy use global static atomic string. I would argue that the reasons may not be valid for all possible ports of WebKit. If some one had a valid reason then it would at least intially be port specific.
I think its a bug in the implementation that atomic string cannot be used for static variables regardless of OSX and the use cases on osx. If its fixed the patch could even be ifdef'ed to not function on OSX to prevent static variable from sneaking into generic code.
I don't like basic stuff like AtomicString being broken its not a good thing. There is nothing wrong with making it work correctly andd efficiently in the case of global static variables and also nothing wrong with ifdefing that support so its not on by default. Later if there is a either port specific or real generic need the support can be turned on.
I guess I'm a bit surprised your willing to leave a basic class like AtomicString broken because of current design decisions event if there often (not always) correct. At the very least add a comment to the header.
Its tough to wager on a email list but I promise to buy and extra ipod if this is not fixed within the next two years. I don't see me loosing that bet :)
Mike
-- Darin
participants (4)
-
Darin Adler
-
Eric Seidel
-
Geoffrey Garen
-
Mike Emmel