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

Side by Side Diff: third_party/WebKit/Source/platform/heap/CallbackStack.h

Issue 1695653004: Oilpan: Reduce the reserved size of CallbackStacks Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CallbackStack_h 5 #ifndef CallbackStack_h
6 #define CallbackStack_h 6 #define CallbackStack_h
7 7
8 #include "platform/heap/ThreadState.h" 8 #include "platform/heap/ThreadState.h"
9 #include "wtf/Allocator.h" 9 #include "wtf/Allocator.h"
10 #include "wtf/Assertions.h" 10 #include "wtf/Assertions.h"
(...skipping 19 matching lines...) Expand all
30 } 30 }
31 void* object() { return m_object; } 31 void* object() { return m_object; }
32 VisitorCallback callback() { return m_callback; } 32 VisitorCallback callback() { return m_callback; }
33 void call(Visitor* visitor) { m_callback(visitor, m_object); } 33 void call(Visitor* visitor) { m_callback(visitor, m_object); }
34 34
35 private: 35 private:
36 void* m_object; 36 void* m_object;
37 VisitorCallback m_callback; 37 VisitorCallback m_callback;
38 }; 38 };
39 39
40 CallbackStack(); 40 explicit CallbackStack(size_t);
41 ~CallbackStack(); 41 ~CallbackStack();
42 42
43 void clear(); 43 void clear();
44 44
45 Item* allocateEntry(); 45 Item* allocateEntry();
46 Item* pop(); 46 Item* pop();
47 47
48 bool isEmpty() const; 48 bool isEmpty() const;
49 49
50 void invokeEphemeronCallbacks(Visitor*); 50 void invokeEphemeronCallbacks(Visitor*);
51 51
52 #if ENABLE(ASSERT) 52 #if ENABLE(ASSERT)
53 bool hasCallbackForObject(const void*); 53 bool hasCallbackForObject(const void*);
54 #endif 54 #endif
55 55
56 private: 56 private:
57 static const size_t blockSize = 8192;
58
59 class Block { 57 class Block {
60 USING_FAST_MALLOC(Block); 58 USING_FAST_MALLOC(Block);
61 public: 59 public:
62 explicit Block(Block* next) 60 explicit Block(Block*, size_t);
63 : m_limit(&(m_buffer[blockSize])) 61 ~Block();
64 , m_current(&(m_buffer[0]))
65 , m_next(next)
66 {
67 clearUnused();
68 }
69
70 ~Block()
71 {
72 clearUnused();
73 }
74 62
75 void clear(); 63 void clear();
76 64
77 Block* next() const { return m_next; } 65 Block* next() const { return m_next; }
78 void setNext(Block* next) { m_next = next; } 66 void setNext(Block* next) { m_next = next; }
67 size_t blockSize() const { return m_blockSize; }
79 68
80 bool isEmptyBlock() const 69 bool isEmptyBlock() const
81 { 70 {
82 return m_current == &(m_buffer[0]); 71 return m_current == &(m_buffer[0]);
83 } 72 }
84 73
85 size_t size() const
86 {
87 return blockSize - (m_limit - m_current);
88 }
89
90 Item* allocateEntry() 74 Item* allocateEntry()
91 { 75 {
92 if (LIKELY(m_current < m_limit)) 76 if (LIKELY(m_current < m_limit))
93 return m_current++; 77 return m_current++;
94 return nullptr; 78 return nullptr;
95 } 79 }
96 80
97 Item* pop() 81 Item* pop()
98 { 82 {
99 if (UNLIKELY(isEmptyBlock())) 83 if (UNLIKELY(isEmptyBlock()))
100 return nullptr; 84 return nullptr;
101 return --m_current; 85 return --m_current;
102 } 86 }
103 87
104 void invokeEphemeronCallbacks(Visitor*); 88 void invokeEphemeronCallbacks(Visitor*);
105 #if ENABLE(ASSERT) 89 #if ENABLE(ASSERT)
106 bool hasCallbackForObject(const void*); 90 bool hasCallbackForObject(const void*);
107 #endif 91 #endif
108 92
109 private: 93 private:
110 void clearUnused(); 94 void clearUnused();
111 95
112 Item m_buffer[blockSize]; 96 Item* m_buffer;
113 Item* m_limit; 97 Item* m_limit;
114 Item* m_current; 98 Item* m_current;
115 Block* m_next; 99 Block* m_next;
100 size_t m_blockSize;
116 }; 101 };
117 102
118 Item* popSlow(); 103 Item* popSlow();
119 Item* allocateEntrySlow(); 104 Item* allocateEntrySlow();
120 void invokeOldestCallbacks(Block*, Block*, Visitor*); 105 void invokeOldestCallbacks(Block*, Block*, Visitor*);
121 bool hasJustOneBlock() const; 106 bool hasJustOneBlock() const;
122 107
123 Block* m_first; 108 Block* m_first;
124 Block* m_last; 109 Block* m_last;
125 }; 110 };
(...skipping 12 matching lines...) Expand all
138 Item* item = m_first->pop(); 123 Item* item = m_first->pop();
139 if (LIKELY(!!item)) 124 if (LIKELY(!!item))
140 return item; 125 return item;
141 126
142 return popSlow(); 127 return popSlow();
143 } 128 }
144 129
145 } // namespace blink 130 } // namespace blink
146 131
147 #endif // CallbackStack_h 132 #endif // CallbackStack_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698