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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 if (current_allocated < code_range_size / 10) { | 197 if (current_allocated < code_range_size / 10) { |
198 // Allocate a block. | 198 // Allocate a block. |
199 // Geometrically distributed sizes, greater than | 199 // Geometrically distributed sizes, greater than |
200 // Page::kMaxNonCodeHeapObjectSize (which is greater than code page area). | 200 // Page::kMaxNonCodeHeapObjectSize (which is greater than code page area). |
201 // TODO(gc): instead of using 3 use some contant based on code_range_size | 201 // TODO(gc): instead of using 3 use some contant based on code_range_size |
202 // kMaxHeapObjectSize. | 202 // kMaxHeapObjectSize. |
203 size_t requested = | 203 size_t requested = |
204 (Page::kMaxNonCodeHeapObjectSize << (Pseudorandom() % 3)) + | 204 (Page::kMaxNonCodeHeapObjectSize << (Pseudorandom() % 3)) + |
205 Pseudorandom() % 5000 + 1; | 205 Pseudorandom() % 5000 + 1; |
206 size_t allocated = 0; | 206 size_t allocated = 0; |
207 Address base = code_range->AllocateRawMemory(requested, | 207 Address base = code_range->AllocateRawMemory(requested, &allocated); |
208 requested, | |
209 &allocated); | |
210 CHECK(base != NULL); | 208 CHECK(base != NULL); |
211 blocks.Add(Block(base, static_cast<int>(allocated))); | 209 blocks.Add(Block(base, static_cast<int>(allocated))); |
212 current_allocated += static_cast<int>(allocated); | 210 current_allocated += static_cast<int>(allocated); |
213 total_allocated += static_cast<int>(allocated); | 211 total_allocated += static_cast<int>(allocated); |
214 } else { | 212 } else { |
215 // Free a block. | 213 // Free a block. |
216 int index = Pseudorandom() % blocks.length(); | 214 int index = Pseudorandom() % blocks.length(); |
217 code_range->FreeRawMemory(blocks[index].base, blocks[index].size); | 215 code_range->FreeRawMemory(blocks[index].base, blocks[index].size); |
218 current_allocated -= blocks[index].size; | 216 current_allocated -= blocks[index].size; |
219 if (index < blocks.length() - 1) { | 217 if (index < blocks.length() - 1) { |
220 blocks[index] = blocks.RemoveLast(); | 218 blocks[index] = blocks.RemoveLast(); |
221 } else { | 219 } else { |
222 blocks.RemoveLast(); | 220 blocks.RemoveLast(); |
223 } | 221 } |
224 } | 222 } |
225 } | 223 } |
226 | 224 |
227 code_range->TearDown(); | 225 code_range->TearDown(); |
228 delete code_range; | 226 delete code_range; |
229 } | 227 } |
OLD | NEW |