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

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

Issue 25640003: Optimize test for pointer being in a partition on 32-bit. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: More review. Created 7 years, 2 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/wtf/PageAllocator.h ('k') | Source/wtf/PartitionAlloc.h » ('j') | 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) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "wtf/PageAllocator.h" 32 #include "wtf/PageAllocator.h"
33 33
34 #include "wtf/Assertions.h"
35 #include "wtf/CPU.h"
36 #include "wtf/CryptographicallyRandomNumber.h" 34 #include "wtf/CryptographicallyRandomNumber.h"
37 35
38 #if OS(POSIX) 36 #if OS(POSIX)
39 37
40 #include <sys/mman.h> 38 #include <sys/mman.h>
41 39
42 #ifndef MADV_FREE 40 #ifndef MADV_FREE
43 #define MADV_FREE MADV_DONTNEED 41 #define MADV_FREE MADV_DONTNEED
44 #endif 42 #endif
45 43
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 } 88 }
91 void* ret = ptr; 89 void* ret = ptr;
92 #else 90 #else
93 // Windows is a lot simpler because we've designed around its 91 // Windows is a lot simpler because we've designed around its
94 // coarser-grained alignement. 92 // coarser-grained alignement.
95 void* ret = VirtualAlloc(addr, len, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE ); 93 void* ret = VirtualAlloc(addr, len, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE );
96 if (!ret) 94 if (!ret)
97 ret = VirtualAlloc(0, len, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); 95 ret = VirtualAlloc(0, len, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
98 RELEASE_ASSERT(ret); 96 RELEASE_ASSERT(ret);
99 #endif // OS(POSIX) 97 #endif // OS(POSIX)
98
99 SuperPageBitmap::registerSuperPage(ret);
100 return ret; 100 return ret;
101 } 101 }
102 102
103 void freeSuperPages(void* addr, size_t len) 103 void freeSuperPages(void* addr, size_t len)
104 { 104 {
105 ASSERT(!(reinterpret_cast<uintptr_t>(addr) & kSuperPageOffsetMask)); 105 ASSERT(!(reinterpret_cast<uintptr_t>(addr) & kSuperPageOffsetMask));
106 ASSERT(!(len & kSuperPageOffsetMask)); 106 ASSERT(!(len & kSuperPageOffsetMask));
107 #if OS(POSIX) 107 #if OS(POSIX)
108 int ret = munmap(addr, len); 108 int ret = munmap(addr, len);
109 ASSERT(!ret); 109 ASSERT(!ret);
110 #else 110 #else
111 BOOL ret = VirtualFree(addr, 0, MEM_RELEASE); 111 BOOL ret = VirtualFree(addr, 0, MEM_RELEASE);
112 ASSERT(ret); 112 ASSERT(ret);
113 #endif 113 #endif
114
115 SuperPageBitmap::unregisterSuperPage(addr);
114 } 116 }
115 117
116 void setSystemPagesInaccessible(void* addr, size_t len) 118 void setSystemPagesInaccessible(void* addr, size_t len)
117 { 119 {
118 ASSERT(!(len & kSystemPageOffsetMask)); 120 ASSERT(!(len & kSystemPageOffsetMask));
119 #if OS(POSIX) 121 #if OS(POSIX)
120 int ret = mprotect(addr, len, PROT_NONE); 122 int ret = mprotect(addr, len, PROT_NONE);
121 ASSERT(!ret); 123 ASSERT(!ret);
122 #else 124 #else
123 BOOL ret = VirtualFree(addr, len, MEM_DECOMMIT); 125 BOOL ret = VirtualFree(addr, len, MEM_DECOMMIT);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 #endif 158 #endif
157 #else // !CPU(X86_64) 159 #else // !CPU(X86_64)
158 // This is a good range on Windows, Linux and Mac. 160 // This is a good range on Windows, Linux and Mac.
159 // Allocates in the 0.5-1.5GB region. 161 // Allocates in the 0.5-1.5GB region.
160 random &= (0x3fffffff & kSuperPageBaseMask); 162 random &= (0x3fffffff & kSuperPageBaseMask);
161 random += 0x20000000; 163 random += 0x20000000;
162 #endif // CPU(X86_64) 164 #endif // CPU(X86_64)
163 return reinterpret_cast<char*>(random); 165 return reinterpret_cast<char*>(random);
164 } 166 }
165 167
168 #if CPU(32BIT)
169 unsigned char SuperPageBitmap::s_bitmap[1 << (32 - kSuperPageShift - 3)];
170
171 void SuperPageBitmap::registerSuperPage(void* ptr)
172 {
173 ASSERT(!isPointerInSuperPage(ptr));
174 uintptr_t raw = reinterpret_cast<uintptr_t>(ptr);
175 raw >>= kSuperPageShift;
176 size_t idx = raw >> 3;
ojan 2013/10/03 00:44:09 Nit: Here an elsewhere, I'm not sure what "idx" st
177 size_t bit = raw & 7;
178 ASSERT(idx < sizeof(s_bitmap));
179 s_bitmap[idx] |= (1 << bit);
180 }
181
182 void SuperPageBitmap::unregisterSuperPage(void* ptr)
183 {
184 ASSERT(isPointerInSuperPage(ptr));
185 uintptr_t raw = reinterpret_cast<uintptr_t>(ptr);
186 raw >>= kSuperPageShift;
187 size_t idx = raw >> 3;
188 size_t bit = raw & 7;
189 ASSERT(idx < sizeof(s_bitmap));
190 s_bitmap[idx] &= ~(1 << bit);
191 }
192 #endif
193
166 } // namespace WTF 194 } // namespace WTF
167 195
OLDNEW
« no previous file with comments | « Source/wtf/PageAllocator.h ('k') | Source/wtf/PartitionAlloc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698