Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: Source/WebCore/bindings/v8/V8GCController.cpp

Issue 7697013: Merge 93397 (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/835/
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « LayoutTests/platform/chromium/test_expectations.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 if (!root) 279 if (!root)
280 return GroupId(); 280 return GroupId();
281 } else { 281 } else {
282 while (Node* parent = root->parentOrHostNode()) 282 while (Node* parent = root->parentOrHostNode())
283 root = parent; 283 root = parent;
284 } 284 }
285 285
286 return GroupId(root); 286 return GroupId(root);
287 } 287 }
288 288
289 static GroupId calculateGroupId(StyleBase* styleBase)
290 {
291 ASSERT(styleBase);
292 StyleBase* current = styleBase;
293 StyleSheet* styleSheet = 0;
294 while (true) {
295 // Special case: CSSStyleDeclarations might be either inline and in this case
296 // we need to group them with their node or regular ones.
297 if (current->isMutableStyleDeclaration()) {
298 CSSMutableStyleDeclaration* cssMutableStyleDeclaration = static_cast <CSSMutableStyleDeclaration*>(current);
299 if (cssMutableStyleDeclaration->isInlineStyleDeclaration())
300 return calculateGroupId(cssMutableStyleDeclaration->node());
301 // Either we have no parent, or this parent is a CSSRule.
302 ASSERT(cssMutableStyleDeclaration->parent() == cssMutableStyleDeclar ation->parentRule());
303 }
304
305 if (current->isStyleSheet())
306 styleSheet = static_cast<StyleSheet*>(current);
307
308 StyleBase* parent = current->parent();
309 if (!parent)
310 break;
311 current = parent;
312 }
313
314 if (styleSheet) {
315 if (Node* ownerNode = styleSheet->ownerNode())
316 return calculateGroupId(ownerNode);
317 return GroupId(styleSheet);
318 }
319
320 return GroupId(current);
321 }
322
323 class GrouperVisitor : public DOMWrapperMap<Node>::Visitor, public DOMWrapperMap <void>::Visitor { 289 class GrouperVisitor : public DOMWrapperMap<Node>::Visitor, public DOMWrapperMap <void>::Visitor {
324 public: 290 public:
325 void visitDOMWrapper(DOMDataStore* store, Node* node, v8::Persistent<v8::Obj ect> wrapper) 291 void visitDOMWrapper(DOMDataStore* store, Node* node, v8::Persistent<v8::Obj ect> wrapper)
326 { 292 {
327 if (node->hasEventListeners()) { 293 if (node->hasEventListeners()) {
328 Vector<v8::Persistent<v8::Value> > listeners; 294 Vector<v8::Persistent<v8::Value> > listeners;
329 EventListenerIterator iterator(node); 295 EventListenerIterator iterator(node);
330 while (EventListener* listener = iterator.nextListener()) { 296 while (EventListener* listener = iterator.nextListener()) {
331 if (listener->type() != EventListener::JSEventListenerType) 297 if (listener->type() != EventListener::JSEventListenerType)
332 continue; 298 continue;
333 V8AbstractEventListener* v8listener = static_cast<V8AbstractEven tListener*>(listener); 299 V8AbstractEventListener* v8listener = static_cast<V8AbstractEven tListener*>(listener);
334 if (!v8listener->hasExistingListenerObject()) 300 if (!v8listener->hasExistingListenerObject())
335 continue; 301 continue;
336 listeners.append(v8listener->existingListenerObjectPersistentHan dle()); 302 listeners.append(v8listener->existingListenerObjectPersistentHan dle());
337 } 303 }
338 if (!listeners.isEmpty()) 304 if (!listeners.isEmpty())
339 v8::V8::AddImplicitReferences(wrapper, listeners.data(), listene rs.size()); 305 v8::V8::AddImplicitReferences(wrapper, listeners.data(), listene rs.size());
340 } 306 }
341 307
342 GroupId groupId = calculateGroupId(node); 308 GroupId groupId = calculateGroupId(node);
343 if (!groupId) 309 if (!groupId)
344 return; 310 return;
345 m_grouper.append(GrouperItem(groupId, wrapper)); 311 m_grouper.append(GrouperItem(groupId, wrapper));
346 } 312 }
347 313
348 void visitDOMWrapper(DOMDataStore* store, void* object, v8::Persistent<v8::O bject> wrapper) 314 void visitDOMWrapper(DOMDataStore* store, void* object, v8::Persistent<v8::O bject> wrapper)
349 { 315 {
350 WrapperTypeInfo* typeInfo = V8DOMWrapper::domWrapperType(wrapper);
351
352 if (typeInfo->isSubclass(&V8StyleSheetList::info)) {
353 StyleSheetList* styleSheetList = static_cast<StyleSheetList*>(object );
354 GroupId groupId(styleSheetList);
355 if (Document* document = styleSheetList->document())
356 groupId = GroupId(document);
357 m_grouper.append(GrouperItem(groupId, wrapper));
358
359 } else if (typeInfo->isSubclass(&V8DOMImplementation::info)) {
360 DOMImplementation* domImplementation = static_cast<DOMImplementation *>(object);
361 GroupId groupId(domImplementation);
362 if (Document* document = domImplementation->document())
363 groupId = GroupId(document);
364 m_grouper.append(GrouperItem(groupId, wrapper));
365
366 } else if (typeInfo->isSubclass(&V8StyleSheet::info) || typeInfo->isSubc lass(&V8CSSRule::info)) {
367 m_grouper.append(GrouperItem(calculateGroupId(static_cast<StyleBase* >(object)), wrapper));
368
369 } else if (typeInfo->isSubclass(&V8CSSStyleDeclaration::info)) {
370 CSSStyleDeclaration* cssStyleDeclaration = static_cast<CSSStyleDecla ration*>(object);
371
372 GroupId groupId = calculateGroupId(cssStyleDeclaration);
373 m_grouper.append(GrouperItem(groupId, wrapper));
374
375 // Keep alive "dirty" primitive values (i.e. the ones that
376 // have user-added properties) by creating implicit
377 // references between the style declaration and the values
378 // in it.
379 if (cssStyleDeclaration->isMutableStyleDeclaration()) {
380 CSSMutableStyleDeclaration* cssMutableStyleDeclaration = static_ cast<CSSMutableStyleDeclaration*>(cssStyleDeclaration);
381 Vector<v8::Persistent<v8::Value> > values;
382 values.reserveCapacity(cssMutableStyleDeclaration->length());
383 CSSMutableStyleDeclaration::const_iterator end = cssMutableStyle Declaration->end();
384 for (CSSMutableStyleDeclaration::const_iterator it = cssMutableS tyleDeclaration->begin(); it != end; ++it) {
385 v8::Persistent<v8::Object> value = store->domObjectMap().get (it->value());
386 if (!value.IsEmpty() && value->IsDirty())
387 values.append(value);
388 }
389 if (!values.isEmpty())
390 v8::V8::AddImplicitReferences(wrapper, values.data(), values .size());
391 }
392 }
393 } 316 }
394 317
395 void applyGrouping() 318 void applyGrouping()
396 { 319 {
397 // Group by sorting by the group id. 320 // Group by sorting by the group id.
398 std::sort(m_grouper.begin(), m_grouper.end()); 321 std::sort(m_grouper.begin(), m_grouper.end());
399 322
400 for (size_t i = 0; i < m_grouper.size(); ) { 323 for (size_t i = 0; i < m_grouper.size(); ) {
401 // Seek to the next key (or the end of the list). 324 // Seek to the next key (or the end of the list).
402 size_t nextKeyIndex = m_grouper.size(); 325 size_t nextKeyIndex = m_grouper.size();
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 return; 477 return;
555 #endif 478 #endif
556 479
557 int memoryUsageMB = getMemoryUsageInMB(); 480 int memoryUsageMB = getMemoryUsageInMB();
558 if ((memoryUsageMB > lowUsageMB && memoryUsageMB > 2 * workingSetEstimateMB) || (memoryUsageMB > highUsageMB && memoryUsageMB > workingSetEstimateMB + highU sageDeltaMB)) 481 if ((memoryUsageMB > lowUsageMB && memoryUsageMB > 2 * workingSetEstimateMB) || (memoryUsageMB > highUsageMB && memoryUsageMB > workingSetEstimateMB + highU sageDeltaMB))
559 v8::V8::LowMemoryNotification(); 482 v8::V8::LowMemoryNotification();
560 } 483 }
561 484
562 485
563 } // namespace WebCore 486 } // namespace WebCore
OLDNEW
« no previous file with comments | « LayoutTests/platform/chromium/test_expectations.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698