Weak GC maps should be easier to use
authorggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Jan 2013 20:38:10 +0000 (20:38 +0000)
committerggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Jan 2013 20:38:10 +0000 (20:38 +0000)
commitfe813e75bdc47544f0ab5335b3c18aa9702b2d68
tree6f172af9ea678a267135c9d713dcbc37d40f4372
parentb16d3c3f9ff867974d45b40d586fa6a905cc6bf5
Weak GC maps should be easier to use
https://bugs.webkit.org/show_bug.cgi?id=107312

Reviewed by Sam Weinig.

../JavaScriptCore:

This patch changes WeakGCMap to not use a WeakImpl finalizer to remove
items from the map, and to instead have the map automatically remove
stale items itself upon insertion. This has a few advantages:

(1) WeakGCMap is now compatible with all the specializations you would
use for HashMap.

(2) There's no need for clients to write special finalization munging
functions.

(3) Clients can specify custom value finalizers if they like.

* JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCoreExports.def: Def!

* API/JSWeakObjectMapRefPrivate.cpp: Setter no longer requires a global
data, since we've reduced interdependency.

* heap/Handle.h: No more need to forward declare, since we've reduced
interdependency.

* heap/Weak.h:
(Weak): Use explicit so we can assign directly to a weak map iterator
without ambiguity between Weak<T> and PassWeak<T>.

* runtime/Structure.cpp:
(JSC::StructureTransitionTable::add): See above.

* runtime/Structure.h:
(JSC):
* runtime/StructureTransitionTable.h:
(StructureTransitionTable): Bad code goes away, programmer happy.

* runtime/WeakGCMap.h:
(JSC):
(WeakGCMap):
(JSC::WeakGCMap::WeakGCMap):
(JSC::WeakGCMap::set):
(JSC::WeakGCMap::add):
(JSC::WeakGCMap::find):
(JSC::WeakGCMap::contains):
(JSC::WeakGCMap::gcMap):
(JSC::WeakGCMap::gcMapIfNeeded): Inherit from HashMap and override any
function that might observe a Weak<T> that has died, just enough to
make such items appear as if they are not in the table.

../WebCore:

Since weak GC maps are so easy to use now, let's use them for the DOM
string cache.

* WebCore.exp.in:
* bindings/js/DOMWrapperWorld.cpp:
(WebCore):
(WebCore::DOMWrapperWorld::DOMWrapperWorld):
* bindings/js/DOMWrapperWorld.h:
(WebCore):
(WebCore::DOMWrapperWorld::globalData):
(DOMWrapperWorld):
* bindings/js/JSDOMBinding.cpp:
(WebCore):
* bindings/js/JSDOMBinding.h:
(WebCore):
(WebCore::jsStringWithCache):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@140194 268f45cc-cd09-0410-ab3c-d52691b4dbfc
15 files changed:
Source/JavaScriptCore/API/JSWeakObjectMapRefPrivate.cpp
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCoreExports.def
Source/JavaScriptCore/heap/Handle.h
Source/JavaScriptCore/heap/Weak.h
Source/JavaScriptCore/runtime/Structure.cpp
Source/JavaScriptCore/runtime/Structure.h
Source/JavaScriptCore/runtime/StructureTransitionTable.h
Source/JavaScriptCore/runtime/WeakGCMap.h
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/bindings/js/DOMWrapperWorld.cpp
Source/WebCore/bindings/js/DOMWrapperWorld.h
Source/WebCore/bindings/js/JSDOMBinding.cpp
Source/WebCore/bindings/js/JSDOMBinding.h