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