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

Side by Side Diff: Source/wtf/FastMalloc.cpp

Issue 345203007: Remove WTF_USE_SYSTEM_MALLOC (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « Source/config.h ('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 // Copyright (c) 2005, 2007, Google Inc. 1 // Copyright (c) 2005, 2007, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2011 Apple Inc. All rights reserv ed. 3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2011 Apple Inc. All rights reserv ed.
4 // 4 //
5 // Redistribution and use in source and binary forms, with or without 5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are 6 // modification, are permitted provided that the following conditions are
7 // met: 7 // met:
8 // 8 //
9 // * Redistributions of source code must retain the above copyright 9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer. 10 // notice, this list of conditions and the following disclaimer.
(...skipping 13 matching lines...) Expand all
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "wtf/FastMalloc.h" 32 #include "wtf/FastMalloc.h"
33 33
34 #include "wtf/PartitionAlloc.h"
35 #include "wtf/SpinLock.h"
34 #include <string.h> 36 #include <string.h>
35 37
36 namespace WTF { 38 namespace WTF {
37 39
40 static PartitionAllocatorGeneric gPartition;
41 static int gLock = 0;
42 static bool gInitialized = false;
43
38 void* fastZeroedMalloc(size_t n) 44 void* fastZeroedMalloc(size_t n)
39 { 45 {
40 void* result = fastMalloc(n); 46 void* result = fastMalloc(n);
41 memset(result, 0, n); 47 memset(result, 0, n);
42 return result; 48 return result;
43 } 49 }
44 50
45 char* fastStrDup(const char* src) 51 char* fastStrDup(const char* src)
46 { 52 {
47 size_t len = strlen(src) + 1; 53 size_t len = strlen(src) + 1;
48 char* dup = static_cast<char*>(fastMalloc(len)); 54 char* dup = static_cast<char*>(fastMalloc(len));
49 memcpy(dup, src, len); 55 memcpy(dup, src, len);
50 return dup; 56 return dup;
51 } 57 }
52 58
53 FastMallocStatistics fastMallocStatistics() 59 FastMallocStatistics fastMallocStatistics()
54 { 60 {
55 FastMallocStatistics statistics = { 0, 0, 0 }; 61 FastMallocStatistics statistics = { 0, 0, 0 };
56 return statistics; 62 return statistics;
57 } 63 }
58 64
59 } // namespace WTF
60
61 #if USE(SYSTEM_MALLOC)
62
63 #include "wtf/Assertions.h"
64
65 #include <stdlib.h>
66
67 namespace WTF {
68
69 void fastMallocShutdown()
70 {
71 }
72
73 void* fastMalloc(size_t n)
74 {
75 void* result = malloc(n);
76 ASSERT(result); // We expect tcmalloc underneath, which would crash instead of getting here.
77
78 return result;
79 }
80
81 void fastFree(void* p)
82 {
83 free(p);
84 }
85
86 void* fastRealloc(void* p, size_t n)
87 {
88 void* result = realloc(p, n);
89 ASSERT(result); // We expect tcmalloc underneath, which would crash instead of getting here.
90
91 return result;
92 }
93
94 } // namespace WTF
95
96 #else // USE(SYSTEM_MALLOC)
97
98 #include "wtf/PartitionAlloc.h"
99 #include "wtf/SpinLock.h"
100
101 namespace WTF {
102
103 static PartitionAllocatorGeneric gPartition;
104 static int gLock = 0;
105 static bool gInitialized = false;
106
107 void fastMallocShutdown() 65 void fastMallocShutdown()
108 { 66 {
109 gPartition.shutdown(); 67 gPartition.shutdown();
110 } 68 }
111 69
112 void* fastMalloc(size_t n) 70 void* fastMalloc(size_t n)
113 { 71 {
114 if (UNLIKELY(!gInitialized)) { 72 if (UNLIKELY(!gInitialized)) {
115 spinLockLock(&gLock); 73 spinLockLock(&gLock);
116 if (!gInitialized) { 74 if (!gInitialized) {
117 gInitialized = true; 75 gInitialized = true;
118 gPartition.init(); 76 gPartition.init();
119 } 77 }
120 spinLockUnlock(&gLock); 78 spinLockUnlock(&gLock);
121 } 79 }
122 return partitionAllocGeneric(gPartition.root(), n); 80 return partitionAllocGeneric(gPartition.root(), n);
123 } 81 }
124 82
125 void fastFree(void* p) 83 void fastFree(void* p)
126 { 84 {
127 partitionFreeGeneric(gPartition.root(), p); 85 partitionFreeGeneric(gPartition.root(), p);
128 } 86 }
129 87
130 void* fastRealloc(void* p, size_t n) 88 void* fastRealloc(void* p, size_t n)
131 { 89 {
132 return partitionReallocGeneric(gPartition.root(), p, n); 90 return partitionReallocGeneric(gPartition.root(), p, n);
133 } 91 }
134 92
135 } // namespace WTF 93 } // namespace WTF
136
137 #endif // USE(SYSTEM_MALLOC)
OLDNEW
« no previous file with comments | « Source/config.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698