OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. | 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 24 matching lines...) Expand all Loading... | |
35 #include "core/events/ScopedEventQueue.h" | 35 #include "core/events/ScopedEventQueue.h" |
36 #include "core/layout/svg/LayoutSVGInlineText.h" | 36 #include "core/layout/svg/LayoutSVGInlineText.h" |
37 #include "core/rendering/RenderCombineText.h" | 37 #include "core/rendering/RenderCombineText.h" |
38 #include "core/rendering/RenderText.h" | 38 #include "core/rendering/RenderText.h" |
39 #include "core/svg/SVGForeignObjectElement.h" | 39 #include "core/svg/SVGForeignObjectElement.h" |
40 #include "wtf/text/CString.h" | 40 #include "wtf/text/CString.h" |
41 #include "wtf/text/StringBuilder.h" | 41 #include "wtf/text/StringBuilder.h" |
42 | 42 |
43 namespace blink { | 43 namespace blink { |
44 | 44 |
45 #if ENABLE(OILPAN) | |
46 namespace { | |
47 // If the external string kept by a Text node exceed this threshold length, | |
48 // Oilpan is informed. External allocation amounts owned by heap objects are | |
49 // taken into account when scheduling urgent Oilpan GCs. | |
50 // | |
51 // FIXME: having only Text nodes with strings above an ad-hoc local threshold | |
52 // influence Oilpan's GC behavior isn't a satisfactory long-term solution. | |
53 // But code that allocates a lot of Text nodes in tight loops, and not much more , | |
54 // we do have to trigger Oilpan GCs to avoid PartitionAlloc OOMs. The accounting | |
55 // does add overhead on the allocation of every Text node however, so for now, o nly | |
56 // register those above the given threshold. TBC. | |
57 const size_t stringLengthThreshold = 256; | |
58 | |
59 enum RegistrationMode { AsNew, AsAlive }; | |
60 | |
61 void registerExternalAllocation(size_t length, RegistrationMode mode) | |
haraken
2015/02/23 14:59:08
Nit: I'd slightly prefer having two methods for th
sof
2015/02/23 15:56:07
Done.
| |
62 { | |
63 if (length > stringLengthThreshold) { | |
64 if (mode == AsNew) | |
65 Heap::increaseExternallyAllocatedBytes(length); | |
66 else | |
67 Heap::increaseExternallyAllocatedBytesAlive(length); | |
68 } | |
69 } | |
70 | |
71 } // namespace | |
72 #endif | |
73 | |
45 PassRefPtrWillBeRawPtr<Text> Text::create(Document& document, const String& data ) | 74 PassRefPtrWillBeRawPtr<Text> Text::create(Document& document, const String& data ) |
46 { | 75 { |
76 #if ENABLE(OILPAN) | |
77 registerExternalAllocation(data.length(), AsNew); | |
78 #endif | |
47 return adoptRefWillBeNoop(new Text(document, data, CreateText)); | 79 return adoptRefWillBeNoop(new Text(document, data, CreateText)); |
48 } | 80 } |
49 | 81 |
50 PassRefPtrWillBeRawPtr<Text> Text::createEditingText(Document& document, const S tring& data) | 82 PassRefPtrWillBeRawPtr<Text> Text::createEditingText(Document& document, const S tring& data) |
51 { | 83 { |
84 #if ENABLE(OILPAN) | |
85 registerExternalAllocation(data.length(), AsNew); | |
86 #endif | |
52 return adoptRefWillBeNoop(new Text(document, data, CreateEditingText)); | 87 return adoptRefWillBeNoop(new Text(document, data, CreateEditingText)); |
53 } | 88 } |
54 | 89 |
55 PassRefPtrWillBeRawPtr<Node> Text::mergeNextSiblingNodesIfPossible() | 90 PassRefPtrWillBeRawPtr<Node> Text::mergeNextSiblingNodesIfPossible() |
56 { | 91 { |
57 RefPtrWillBeRawPtr<Node> protect(this); | 92 RefPtrWillBeRawPtr<Node> protect(this); |
58 | 93 |
59 // Remove empty text nodes. | 94 // Remove empty text nodes. |
60 if (!length()) { | 95 if (!length()) { |
61 // Care must be taken to get the next node before removing the current n ode. | 96 // Care must be taken to get the next node before removing the current n ode. |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
401 return; | 436 return; |
402 } | 437 } |
403 textRenderer->setTextWithOffset(dataImpl(), offsetOfReplacedData, lengthOfRe placedData); | 438 textRenderer->setTextWithOffset(dataImpl(), offsetOfReplacedData, lengthOfRe placedData); |
404 } | 439 } |
405 | 440 |
406 PassRefPtrWillBeRawPtr<Text> Text::cloneWithData(const String& data) | 441 PassRefPtrWillBeRawPtr<Text> Text::cloneWithData(const String& data) |
407 { | 442 { |
408 return create(document(), data); | 443 return create(document(), data); |
409 } | 444 } |
410 | 445 |
446 void Text::trace(Visitor* visitor) | |
447 { | |
448 #if ENABLE(OILPAN) | |
449 registerExternalAllocation(m_data.length(), AsAlive); | |
450 #endif | |
451 CharacterData::trace(visitor); | |
452 } | |
453 | |
411 #ifndef NDEBUG | 454 #ifndef NDEBUG |
412 void Text::formatForDebugger(char *buffer, unsigned length) const | 455 void Text::formatForDebugger(char *buffer, unsigned length) const |
413 { | 456 { |
414 StringBuilder result; | 457 StringBuilder result; |
415 String s; | 458 String s; |
416 | 459 |
417 result.append(nodeName()); | 460 result.append(nodeName()); |
418 | 461 |
419 s = data(); | 462 s = data(); |
420 if (s.length() > 0) { | 463 if (s.length() > 0) { |
421 if (result.length()) | 464 if (result.length()) |
422 result.appendLiteral("; "); | 465 result.appendLiteral("; "); |
423 result.appendLiteral("value="); | 466 result.appendLiteral("value="); |
424 result.append(s); | 467 result.append(s); |
425 } | 468 } |
426 | 469 |
427 strncpy(buffer, result.toString().utf8().data(), length - 1); | 470 strncpy(buffer, result.toString().utf8().data(), length - 1); |
428 } | 471 } |
429 #endif | 472 #endif |
430 | 473 |
431 } // namespace blink | 474 } // namespace blink |
OLD | NEW |