OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 CodeRange code_range(reinterpret_cast<Isolate*>(CcTest::isolate())); | 213 CodeRange code_range(reinterpret_cast<Isolate*>(CcTest::isolate())); |
214 code_range.SetUp(code_range_size); | 214 code_range.SetUp(code_range_size); |
215 size_t current_allocated = 0; | 215 size_t current_allocated = 0; |
216 size_t total_allocated = 0; | 216 size_t total_allocated = 0; |
217 List< ::Block> blocks(1000); | 217 List< ::Block> blocks(1000); |
218 | 218 |
219 while (total_allocated < 5 * code_range_size) { | 219 while (total_allocated < 5 * code_range_size) { |
220 if (current_allocated < code_range_size / 10) { | 220 if (current_allocated < code_range_size / 10) { |
221 // Allocate a block. | 221 // Allocate a block. |
222 // Geometrically distributed sizes, greater than | 222 // Geometrically distributed sizes, greater than |
223 // Page::kMaxRegularHeapObjectSize (which is greater than code page area). | 223 // kMaxRegularHeapObjectSize (which is greater than code page area). |
224 // TODO(gc): instead of using 3 use some contant based on code_range_size | 224 // TODO(gc): instead of using 3 use some contant based on code_range_size |
225 // kMaxRegularHeapObjectSize. | 225 // kMaxRegularHeapObjectSize. |
226 size_t requested = | 226 size_t requested = (kMaxRegularHeapObjectSize << (Pseudorandom() % 3)) + |
227 (Page::kMaxRegularHeapObjectSize << (Pseudorandom() % 3)) + | 227 Pseudorandom() % 5000 + 1; |
228 Pseudorandom() % 5000 + 1; | |
229 size_t allocated = 0; | 228 size_t allocated = 0; |
230 | 229 |
231 // The request size has to be at least 2 code guard pages larger than the | 230 // The request size has to be at least 2 code guard pages larger than the |
232 // actual commit size. | 231 // actual commit size. |
233 Address base = code_range.AllocateRawMemory( | 232 Address base = code_range.AllocateRawMemory( |
234 requested, requested - (2 * MemoryAllocator::CodePageGuardSize()), | 233 requested, requested - (2 * MemoryAllocator::CodePageGuardSize()), |
235 &allocated); | 234 &allocated); |
236 CHECK(base != NULL); | 235 CHECK(base != NULL); |
237 blocks.Add(::Block(base, static_cast<int>(allocated))); | 236 blocks.Add(::Block(base, static_cast<int>(allocated))); |
238 current_allocated += static_cast<int>(allocated); | 237 current_allocated += static_cast<int>(allocated); |
239 total_allocated += static_cast<int>(allocated); | 238 total_allocated += static_cast<int>(allocated); |
240 } else { | 239 } else { |
241 // Free a block. | 240 // Free a block. |
242 int index = Pseudorandom() % blocks.length(); | 241 int index = Pseudorandom() % blocks.length(); |
243 code_range.FreeRawMemory(blocks[index].base, blocks[index].size); | 242 code_range.FreeRawMemory(blocks[index].base, blocks[index].size); |
244 current_allocated -= blocks[index].size; | 243 current_allocated -= blocks[index].size; |
245 if (index < blocks.length() - 1) { | 244 if (index < blocks.length() - 1) { |
246 blocks[index] = blocks.RemoveLast(); | 245 blocks[index] = blocks.RemoveLast(); |
247 } else { | 246 } else { |
248 blocks.RemoveLast(); | 247 blocks.RemoveLast(); |
249 } | 248 } |
250 } | 249 } |
251 } | 250 } |
252 } | 251 } |
OLD | NEW |