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