| 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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 if (current_allocated < code_range_size / 10) { | 217 if (current_allocated < code_range_size / 10) { |
| 218 // Allocate a block. | 218 // Allocate a block. |
| 219 // Geometrically distributed sizes, greater than | 219 // Geometrically distributed sizes, greater than |
| 220 // Page::kMaxRegularHeapObjectSize (which is greater than code page area). | 220 // Page::kMaxRegularHeapObjectSize (which is greater than code page area). |
| 221 // TODO(gc): instead of using 3 use some contant based on code_range_size | 221 // TODO(gc): instead of using 3 use some contant based on code_range_size |
| 222 // kMaxRegularHeapObjectSize. | 222 // kMaxRegularHeapObjectSize. |
| 223 size_t requested = | 223 size_t requested = |
| 224 (Page::kMaxRegularHeapObjectSize << (Pseudorandom() % 3)) + | 224 (Page::kMaxRegularHeapObjectSize << (Pseudorandom() % 3)) + |
| 225 Pseudorandom() % 5000 + 1; | 225 Pseudorandom() % 5000 + 1; |
| 226 size_t allocated = 0; | 226 size_t allocated = 0; |
| 227 Address base = code_range.AllocateRawMemory(requested, | 227 |
| 228 requested, | 228 // The request size has to be at least 2 code guard pages larger than the |
| 229 &allocated); | 229 // actual commit size. |
| 230 Address base = code_range.AllocateRawMemory( |
| 231 requested, requested - (2 * MemoryAllocator::CodePageGuardSize()), |
| 232 &allocated); |
| 230 CHECK(base != NULL); | 233 CHECK(base != NULL); |
| 231 blocks.Add(::Block(base, static_cast<int>(allocated))); | 234 blocks.Add(::Block(base, static_cast<int>(allocated))); |
| 232 current_allocated += static_cast<int>(allocated); | 235 current_allocated += static_cast<int>(allocated); |
| 233 total_allocated += static_cast<int>(allocated); | 236 total_allocated += static_cast<int>(allocated); |
| 234 } else { | 237 } else { |
| 235 // Free a block. | 238 // Free a block. |
| 236 int index = Pseudorandom() % blocks.length(); | 239 int index = Pseudorandom() % blocks.length(); |
| 237 code_range.FreeRawMemory(blocks[index].base, blocks[index].size); | 240 code_range.FreeRawMemory(blocks[index].base, blocks[index].size); |
| 238 current_allocated -= blocks[index].size; | 241 current_allocated -= blocks[index].size; |
| 239 if (index < blocks.length() - 1) { | 242 if (index < blocks.length() - 1) { |
| 240 blocks[index] = blocks.RemoveLast(); | 243 blocks[index] = blocks.RemoveLast(); |
| 241 } else { | 244 } else { |
| 242 blocks.RemoveLast(); | 245 blocks.RemoveLast(); |
| 243 } | 246 } |
| 244 } | 247 } |
| 245 } | 248 } |
| 246 } | 249 } |
| OLD | NEW |