Bug 36519 - JSGlobalContextRelease is unnecessarily slow

Reviewed by Oliver Hunt.

Since [ http://trac.webkit.org/changeset/35917 ], calling
JSGlobalContextRelease always triggers a GC heap collection
(if not a full destroy). As per 35917's changelog "This is
only really necessary when the (JSGlobalObject's) last
reference is released, but there is no way to determine that,
and no harm in collecting slightly more often."
        
Well, we now know of cases of API clients who are harmed by
the performance penalty of collecting too often, so it's time
to add a way to determine whether a call to JSGlobalContextRelease
is removing the last protect from it's global object.  If further
protects are retaining the global object (likely from other
JSGlobalContextRefs), then don't trigger a GC collection.

* API/JSContextRef.cpp:
* runtime/Collector.cpp:
(JSC::Heap::unprotect): return a boolean indicating that the value is now unprotected.
* runtime/Collector.h:
* wtf/HashCountedSet.h:
(WTF::::remove): return a boolean indicating whether the value was removed from the set.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@56435 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/JavaScriptCore/runtime/Collector.cpp b/JavaScriptCore/runtime/Collector.cpp
index 47e2fa3..2859290 100644
--- a/JavaScriptCore/runtime/Collector.cpp
+++ b/JavaScriptCore/runtime/Collector.cpp
@@ -980,15 +980,15 @@
     m_protectedValues.add(k.asCell());
 }
 
-void Heap::unprotect(JSValue k)
+bool Heap::unprotect(JSValue k)
 {
     ASSERT(k);
     ASSERT(JSLock::currentThreadIsHoldingLock() || !m_globalData->isSharedInstance);
 
     if (!k.isCell())
-        return;
+        return false;
 
-    m_protectedValues.remove(k.asCell());
+    return m_protectedValues.remove(k.asCell());
 }
 
 void Heap::markProtectedObjects(MarkStack& markStack)