Changeset 84934 in webkit
- Timestamp:
- Apr 26, 2011 11:31:03 AM (13 years ago)
- Location:
- trunk/Source
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r84911 r84934 1 2011-04-25 Geoffrey Garen <ggaren@apple.com> 2 3 Reviewed by Oliver Hunt. 4 5 Nixed special finalizer handling for WebCore strings 6 https://bugs.webkit.org/show_bug.cgi?id=59425 7 8 SunSpider reports no change. 9 10 Not needed anymore, since weak handles have finalizers. 11 12 * runtime/JSString.cpp: 13 (JSC::JSString::resolveRope): 14 (JSC::JSString::resolveRopeSlowCase): 15 (JSC::JSString::outOfMemory): 16 (JSC::JSString::substringFromRope): 17 (JSC::JSString::replaceCharacter): Updated for removal of union. 18 19 * runtime/JSString.h: 20 (JSC::RopeBuilder::JSString): 21 (JSC::RopeBuilder::~JSString): 22 (JSC::RopeBuilder::appendStringInConstruct): 23 (JSC::RopeBuilder::appendValueInConstructAndIncrementLength): No need for 24 union or special constructor anymore. 25 1 26 2011-04-26 Gabor Loki <loki@webkit.org> 2 27 -
trunk/Source/JavaScriptCore/runtime/JSString.cpp
r84800 r84934 49 49 } 50 50 51 RopeImpl::Fiber currentFiber = m_ other.m_fibers[0];51 RopeImpl::Fiber currentFiber = m_fibers[0]; 52 52 53 53 if ((m_fiberCount > 2) || (RopeImpl::isRope(currentFiber)) 54 || ((m_fiberCount == 2) && (RopeImpl::isRope(m_ other.m_fibers[1])))) {54 || ((m_fiberCount == 2) && (RopeImpl::isRope(m_fibers[1])))) { 55 55 resolveRopeSlowCase(exec, buffer); 56 56 return; … … 64 64 if (m_fiberCount > 1) { 65 65 position += length; 66 currentFiber = m_ other.m_fibers[1];66 currentFiber = m_fibers[1]; 67 67 string = static_cast<StringImpl*>(currentFiber); 68 68 length = string->length(); … … 73 73 ASSERT((buffer + m_length) == position); 74 74 for (unsigned i = 0; i < m_fiberCount; ++i) { 75 RopeImpl::deref(m_ other.m_fibers[i]);76 m_ other.m_fibers[i] = 0;75 RopeImpl::deref(m_fibers[i]); 76 m_fibers[i] = 0; 77 77 } 78 78 m_fiberCount = 0; … … 101 101 RopeImpl::Fiber currentFiber; 102 102 for (unsigned i = 0; i < (m_fiberCount - 1); ++i) 103 workQueue.append(m_ other.m_fibers[i]);104 currentFiber = m_ other.m_fibers[m_fiberCount - 1];103 workQueue.append(m_fibers[i]); 104 currentFiber = m_fibers[m_fiberCount - 1]; 105 105 while (true) { 106 106 if (RopeImpl::isRope(currentFiber)) { … … 123 123 ASSERT(buffer == position); 124 124 for (unsigned i = 0; i < m_fiberCount; ++i) { 125 RopeImpl::deref(m_ other.m_fibers[i]);126 m_ other.m_fibers[i] = 0;125 RopeImpl::deref(m_fibers[i]); 126 m_fibers[i] = 0; 127 127 } 128 128 m_fiberCount = 0; … … 142 142 { 143 143 for (unsigned i = 0; i < m_fiberCount; ++i) { 144 RopeImpl::deref(m_ other.m_fibers[i]);145 m_ other.m_fibers[i] = 0;144 RopeImpl::deref(m_fibers[i]); 145 m_fibers[i] = 0; 146 146 } 147 147 m_fiberCount = 0; … … 170 170 171 171 RopeIterator end; 172 for (RopeIterator it(m_ other.m_fibers.data(), m_fiberCount); it != end; ++it) {172 for (RopeIterator it(m_fibers.data(), m_fiberCount); it != end; ++it) { 173 173 ++fiberCount; 174 174 StringImpl* fiberString = *it; … … 221 221 StringImpl* matchString = 0; 222 222 size_t matchPosition = notFound; 223 for (RopeIterator it(m_ other.m_fibers.data(), m_fiberCount); it != end; ++it) {223 for (RopeIterator it(m_fibers.data(), m_fiberCount); it != end; ++it) { 224 224 ++fiberCount; 225 225 if (matchString) … … 240 240 return throwOutOfMemoryError(exec); 241 241 242 for (RopeIterator it(m_ other.m_fibers.data(), m_fiberCount); it != end; ++it) {242 for (RopeIterator it(m_fibers.data(), m_fiberCount); it != end; ++it) { 243 243 StringImpl* string = *it; 244 244 if (string != matchString) { -
trunk/Source/JavaScriptCore/runtime/JSString.h
r84800 r84934 60 60 JSString* jsOwnedString(ExecState*, const UString&); 61 61 62 typedef void (*JSStringFinalizerCallback)(JSString*, void* context);63 JSString* jsStringWithFinalizer(ExecState*, const UString&, JSStringFinalizerCallback callback, void* context);64 65 62 class JS_EXPORTCLASS JSString : public JSCell { 66 63 public: … … 94 91 if (jsString->isRope()) { 95 92 for (unsigned i = 0; i < jsString->m_fiberCount; ++i) 96 append(jsString->m_ other.m_fibers[i]);93 append(jsString->m_fibers[i]); 97 94 } else 98 95 append(jsString->string()); … … 217 214 , m_fiberCount(1) 218 215 { 219 m_ other.m_fibers[0] = rope.leakRef();216 m_fibers[0] = rope.leakRef(); 220 217 } 221 218 // This constructor constructs a new string by concatenating s1 & s2. … … 299 296 } 300 297 301 JSString(JSGlobalData* globalData, const UString& value, JSStringFinalizerCallback finalizer, void* context)302 : JSCell(*globalData, globalData->stringStructure.get())303 , m_length(value.length())304 , m_value(value)305 , m_fiberCount(0)306 {307 ASSERT(!m_value.isNull());308 // nasty hack because we can't union non-POD types309 m_other.m_finalizerCallback = finalizer;310 m_other.m_finalizerContext = context;311 Heap::heap(this)->reportExtraMemoryCost(value.impl()->cost());312 }313 314 298 ~JSString() 315 299 { 316 300 ASSERT(vptr() == JSGlobalData::jsStringVPtr); 317 if (!m_fiberCount) { 318 if (m_other.m_finalizerCallback) 319 m_other.m_finalizerCallback(this, m_other.m_finalizerContext); 320 } else { 321 unsigned i = 0; 322 do 323 RopeImpl::deref(m_other.m_fibers[i]); 324 while (++i < m_fiberCount); 325 } 301 for (unsigned i = 0; i < m_fiberCount; ++i) 302 RopeImpl::deref(m_fibers[i]); 326 303 } 327 304 … … 372 349 StringImpl* impl = string.impl(); 373 350 impl->ref(); 374 m_ other.m_fibers[index++] = impl;351 m_fibers[index++] = impl; 375 352 } 376 353 … … 379 356 if (jsString->isRope()) { 380 357 for (unsigned i = 0; i < jsString->m_fiberCount; ++i) { 381 RopeImpl::Fiber fiber = jsString->m_ other.m_fibers[i];358 RopeImpl::Fiber fiber = jsString->m_fibers[i]; 382 359 fiber->ref(); 383 m_ other.m_fibers[index++] = fiber;360 m_fibers[index++] = fiber; 384 361 } 385 362 } else … … 399 376 StringImpl* impl = u.impl(); 400 377 impl->ref(); 401 m_ other.m_fibers[index++] = impl;378 m_fibers[index++] = impl; 402 379 m_length += u.length(); 403 380 } … … 424 401 mutable UString m_value; 425 402 mutable unsigned m_fiberCount; 426 // This structure exists to support a temporary workaround for a GC issue. 427 struct JSStringFinalizerStruct { 428 JSStringFinalizerStruct() : m_finalizerCallback(0) {} 429 union { 430 mutable FixedArray<RopeImpl::Fiber, s_maxInternalRopeLength> m_fibers; 431 struct { 432 JSStringFinalizerCallback m_finalizerCallback; 433 void* m_finalizerContext; 434 }; 435 }; 436 } m_other; 403 mutable FixedArray<RopeImpl::Fiber, s_maxInternalRopeLength> m_fibers; 437 404 438 405 bool isRope() const { return m_fiberCount; } … … 445 412 friend JSValue jsString(ExecState* exec, Register* strings, unsigned count); 446 413 friend JSValue jsString(ExecState* exec, JSValue thisValue); 447 friend JSString* jsStringWithFinalizer(ExecState*, const UString&, JSStringFinalizerCallback callback, void* context);448 414 friend JSString* jsSubstring(ExecState* exec, JSString* s, unsigned offset, unsigned length); 449 415 }; … … 525 491 } 526 492 527 inline JSString* jsStringWithFinalizer(ExecState* exec, const UString& s, JSStringFinalizerCallback callback, void* context)528 {529 ASSERT(s.length() && (s.length() > 1 || s.characters()[0] > maxSingleCharacterString));530 JSGlobalData* globalData = &exec->globalData();531 return fixupVPtr(globalData, new (globalData) JSString(globalData, s, callback, context));532 }533 534 493 inline JSString* jsSubstring(ExecState* exec, JSString* s, unsigned offset, unsigned length) 535 494 { -
trunk/Source/WebCore/ChangeLog
r84932 r84934 1 2011-04-25 Geoffrey Garen <ggaren@apple.com> 2 3 Reviewed by Oliver Hunt. 4 5 Nixed special finalizer handling for WebCore strings 6 https://bugs.webkit.org/show_bug.cgi?id=59425 7 8 Not needed anymore, since weak handles have finalizers. 9 10 * WebCore.exp.in: Exports! 11 12 * bindings/js/DOMWrapperWorld.cpp: 13 (WebCore::JSStringOwner::finalize): 14 (WebCore::DOMWrapperWorld::DOMWrapperWorld): Use a weak handle finalizer, 15 so we don't need special treatment anymore. 16 17 * bindings/js/DOMWrapperWorld.h: 18 (WebCore::JSStringOwner::JSStringOwner): 19 (WebCore::DOMWrapperWorld::stringWrapperOwner): Use a HashMap of Weak<T> 20 instead of a WeakGCMap, so we can specify a custom finalizer. 21 22 * bindings/js/JSDOMBinding.cpp: 23 (WebCore::jsStringSlowCase): 24 * bindings/js/JSDOMBinding.h: 25 (WebCore::jsString): Updated for string map change. 26 1 27 2011-04-26 David Kilzer <ddkilzer@apple.com> 2 28 -
trunk/Source/WebCore/WebCore.exp.in
r84769 r84934 1598 1598 __ZN7WebCore16ScriptController20windowScriptNPObjectEv 1599 1599 __ZN7WebCore16ScriptController29cleanupScriptObjectsForPluginEPv 1600 __ZN7WebCore16jsStringSlowCaseEPN3JSC9ExecStateERN S0_9WeakGCMapIPN3WTF10StringImplENS0_8JSStringENS0_33DefaultWeakGCMapFinalizerCallbackIS6_S7_EENS4_10StringHashENS4_10HashTraitsIS6_EEEES6_1600 __ZN7WebCore16jsStringSlowCaseEPN3JSC9ExecStateERN3WTF7HashMapIPNS3_10StringImplENS0_4WeakINS0_8JSStringEEENS3_10StringHashENS3_10HashTraitsIS6_EENSB_IS9_EEEES6_ 1601 1601 __ZN7WebCore17HTMLPlugInElement11getNPObjectEv 1602 1602 __ZNK7WebCore14SecurityOrigin9canAccessEPKS0_ -
trunk/Source/WebCore/bindings/js/DOMWrapperWorld.cpp
r84204 r84934 37 37 } 38 38 39 void JSStringOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) 40 { 41 JSString* jsString = static_cast<JSString*>(handle.get().asCell()); 42 StringImpl* stringImpl = static_cast<StringImpl*>(context); 43 ASSERT_UNUSED(jsString, m_world->m_stringCache.find(stringImpl)->second.get() == jsString); 44 m_world->m_stringCache.remove(stringImpl); 45 } 46 39 47 DOMWrapperWorld::DOMWrapperWorld(JSC::JSGlobalData* globalData, bool isNormal) 40 48 : m_globalData(globalData) 41 49 , m_isNormal(isNormal) 42 50 , m_defaultWrapperOwner(this) 51 , m_stringWrapperOwner(this) 43 52 { 44 53 JSGlobalData::ClientData* clientData = m_globalData->clientData; -
trunk/Source/WebCore/bindings/js/DOMWrapperWorld.h
r84194 r84934 34 34 35 35 typedef HashMap<void*, JSC::Weak<JSDOMWrapper> > DOMObjectWrapperMap; 36 typedef JSC::WeakGCMap<StringImpl*, JSC::JSString> JSStringCache;36 typedef HashMap<StringImpl*, JSC::Weak<JSC::JSString> > JSStringCache; 37 37 38 38 class JSDOMWrapperOwner : public JSC::WeakHandleOwner { … … 46 46 47 47 inline JSDOMWrapperOwner::JSDOMWrapperOwner(DOMWrapperWorld* world) 48 : m_world(world) 49 { 50 } 51 52 class JSStringOwner : public JSC::WeakHandleOwner { 53 public: 54 JSStringOwner(DOMWrapperWorld*); 55 virtual void finalize(JSC::Handle<JSC::Unknown>, void* context); 56 57 private: 58 DOMWrapperWorld* m_world; 59 }; 60 61 inline JSStringOwner::JSStringOwner(DOMWrapperWorld* world) 48 62 : m_world(world) 49 63 { … … 72 86 JSC::JSGlobalData* globalData() const { return m_globalData; } 73 87 JSDOMWrapperOwner* defaultWrapperOwner() { return &m_defaultWrapperOwner; } 88 JSStringOwner* stringWrapperOwner() { return &m_stringWrapperOwner; } 74 89 75 90 protected: … … 81 96 bool m_isNormal; 82 97 JSDOMWrapperOwner m_defaultWrapperOwner; 98 JSStringOwner m_stringWrapperOwner; 83 99 }; 84 100 -
trunk/Source/WebCore/bindings/js/JSDOMBinding.cpp
r84791 r84934 60 60 } 61 61 62 static void stringWrapperDestroyed(JSString*, void* context)63 {64 StringImpl* cacheKey = static_cast<StringImpl*>(context);65 cacheKey->deref();66 }67 68 62 JSValue jsStringSlowCase(ExecState* exec, JSStringCache& stringCache, StringImpl* stringImpl) 69 63 { 70 JSString* wrapper = jsStringWithFinalizer(exec, UString(stringImpl), stringWrapperDestroyed, stringImpl); 71 stringCache.set(exec->globalData(), stringImpl, wrapper); 72 // ref explicitly instead of using a RefPtr-keyed hashtable because the wrapper can 73 // outlive the cache, so the stringImpl has to match the wrapper's lifetime. 74 stringImpl->ref(); 64 JSString* wrapper = jsString(exec, UString(stringImpl)); 65 stringCache.add(stringImpl, Weak<JSString>(exec->globalData(), wrapper, currentWorld(exec)->stringWrapperOwner(), stringImpl)); 75 66 return wrapper; 76 67 } -
trunk/Source/WebCore/bindings/js/JSDOMBinding.h
r84812 r84934 309 309 310 310 JSStringCache& stringCache = currentWorld(exec)->m_stringCache; 311 if (JSC::JSString* wrapper = stringCache.get(stringImpl)) 312 return wrapper; 311 JSStringCache::iterator it = stringCache.find(stringImpl); 312 if (it != stringCache.end()) 313 return it->second.get(); 313 314 314 315 return jsStringSlowCase(exec, stringCache, stringImpl);
Note: See TracChangeset
for help on using the changeset viewer.