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

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: Fixes. 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
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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 } 90 }
91 void* ret = ptr; 91 void* ret = ptr;
92 #else 92 #else
93 // Windows is a lot simpler because we've designed around its 93 // Windows is a lot simpler because we've designed around its
94 // coarser-grained alignement. 94 // coarser-grained alignement.
95 void* ret = VirtualAlloc(addr, len, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE ); 95 void* ret = VirtualAlloc(addr, len, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE );
96 if (!ret) 96 if (!ret)
97 ret = VirtualAlloc(0, len, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); 97 ret = VirtualAlloc(0, len, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
98 RELEASE_ASSERT(ret); 98 RELEASE_ASSERT(ret);
99 #endif // OS(POSIX) 99 #endif // OS(POSIX)
100
101 #if CPU(32BIT)
102 SuperPageBitmap::registerSuperPage(ret);
103 #endif
100 return ret; 104 return ret;
101 } 105 }
102 106
103 void freeSuperPages(void* addr, size_t len) 107 void freeSuperPages(void* addr, size_t len)
104 { 108 {
105 ASSERT(!(reinterpret_cast<uintptr_t>(addr) & kSuperPageOffsetMask)); 109 ASSERT(!(reinterpret_cast<uintptr_t>(addr) & kSuperPageOffsetMask));
106 ASSERT(!(len & kSuperPageOffsetMask)); 110 ASSERT(!(len & kSuperPageOffsetMask));
107 #if OS(POSIX) 111 #if OS(POSIX)
108 int ret = munmap(addr, len); 112 int ret = munmap(addr, len);
109 ASSERT(!ret); 113 ASSERT(!ret);
110 #else 114 #else
111 BOOL ret = VirtualFree(addr, 0, MEM_RELEASE); 115 BOOL ret = VirtualFree(addr, 0, MEM_RELEASE);
112 ASSERT(ret); 116 ASSERT(ret);
113 #endif 117 #endif
118
119 #if CPU(32BIT)
120 SuperPageBitmap::unregisterSuperPage(addr);
121 #endif
114 } 122 }
115 123
116 void setSystemPagesInaccessible(void* addr, size_t len) 124 void setSystemPagesInaccessible(void* addr, size_t len)
117 { 125 {
118 ASSERT(!(len & kSystemPageOffsetMask)); 126 ASSERT(!(len & kSystemPageOffsetMask));
119 #if OS(POSIX) 127 #if OS(POSIX)
120 int ret = mprotect(addr, len, PROT_NONE); 128 int ret = mprotect(addr, len, PROT_NONE);
121 ASSERT(!ret); 129 ASSERT(!ret);
122 #else 130 #else
123 BOOL ret = VirtualFree(addr, len, MEM_DECOMMIT); 131 BOOL ret = VirtualFree(addr, len, MEM_DECOMMIT);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 #endif 164 #endif
157 #else // !CPU(X86_64) 165 #else // !CPU(X86_64)
158 // This is a good range on Windows, Linux and Mac. 166 // This is a good range on Windows, Linux and Mac.
159 // Allocates in the 0.5-1.5GB region. 167 // Allocates in the 0.5-1.5GB region.
160 random &= (0x3fffffff & kSuperPageBaseMask); 168 random &= (0x3fffffff & kSuperPageBaseMask);
161 random += 0x20000000; 169 random += 0x20000000;
162 #endif // CPU(X86_64) 170 #endif // CPU(X86_64)
163 return reinterpret_cast<char*>(random); 171 return reinterpret_cast<char*>(random);
164 } 172 }
165 173
174 #if CPU(32BIT)
175 unsigned char SuperPageBitmap::s_bitmap[1 << (32 - kSuperPageShift - 3)];
176
177 void SuperPageBitmap::registerSuperPage(void* ptr)
178 {
179 ASSERT(!isPointerInSuperPage(ptr));
180 uintptr_t raw = reinterpret_cast<uintptr_t>(ptr);
181 size_t idx = raw >> (kSuperPageShift + 3);
Tom Sepez 2013/10/02 16:51:31 same issue here with bit within byte index.
182 size_t bit = raw & 7;
183 s_bitmap[idx] |= (1 << bit);
184 }
185
186 void SuperPageBitmap::unregisterSuperPage(void* ptr)
187 {
188 ASSERT(isPointerInSuperPage(ptr));
189 uintptr_t raw = reinterpret_cast<uintptr_t>(ptr);
190 size_t idx = raw >> (kSuperPageShift + 3);
191 size_t bit = raw & 7;
192 s_bitmap[idx] &= ~(1 << bit);
193 }
194 #endif
195
166 } // namespace WTF 196 } // namespace WTF
167 197
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698