| OLD | NEW |
| 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 const int code_range_size = 32*MB; | 185 const int code_range_size = 32*MB; |
| 186 CodeRange::Setup(code_range_size); | 186 CodeRange::Setup(code_range_size); |
| 187 int current_allocated = 0; | 187 int current_allocated = 0; |
| 188 int total_allocated = 0; | 188 int total_allocated = 0; |
| 189 List<Block> blocks(1000); | 189 List<Block> blocks(1000); |
| 190 | 190 |
| 191 while (total_allocated < 5 * code_range_size) { | 191 while (total_allocated < 5 * code_range_size) { |
| 192 if (current_allocated < code_range_size / 10) { | 192 if (current_allocated < code_range_size / 10) { |
| 193 // Allocate a block. | 193 // Allocate a block. |
| 194 // Geometrically distributed sizes, greater than Page::kMaxHeapObjectSize. | 194 // Geometrically distributed sizes, greater than Page::kMaxHeapObjectSize. |
| 195 // TODO (gc) instead of using 3 use some contant based on code_range_size | 195 // TODO(gc): instead of using 3 use some contant based on code_range_size |
| 196 // kMaxHeapObjectSize. | 196 // kMaxHeapObjectSize. |
| 197 size_t requested = (Page::kMaxHeapObjectSize << (Pseudorandom() % 3)) + | 197 size_t requested = (Page::kMaxHeapObjectSize << (Pseudorandom() % 3)) + |
| 198 Pseudorandom() % 5000 + 1; | 198 Pseudorandom() % 5000 + 1; |
| 199 size_t allocated = 0; | 199 size_t allocated = 0; |
| 200 Address base = CodeRange::AllocateRawMemory(requested, &allocated); | 200 Address base = CodeRange::AllocateRawMemory(requested, &allocated); |
| 201 blocks.Add(Block(base, static_cast<int>(allocated))); | 201 blocks.Add(Block(base, static_cast<int>(allocated))); |
| 202 current_allocated += static_cast<int>(allocated); | 202 current_allocated += static_cast<int>(allocated); |
| 203 total_allocated += static_cast<int>(allocated); | 203 total_allocated += static_cast<int>(allocated); |
| 204 } else { | 204 } else { |
| 205 // Free a block. | 205 // Free a block. |
| 206 int index = Pseudorandom() % blocks.length(); | 206 int index = Pseudorandom() % blocks.length(); |
| 207 CodeRange::FreeRawMemory(blocks[index].base, blocks[index].size); | 207 CodeRange::FreeRawMemory(blocks[index].base, blocks[index].size); |
| 208 current_allocated -= blocks[index].size; | 208 current_allocated -= blocks[index].size; |
| 209 if (index < blocks.length() - 1) { | 209 if (index < blocks.length() - 1) { |
| 210 blocks[index] = blocks.RemoveLast(); | 210 blocks[index] = blocks.RemoveLast(); |
| 211 } else { | 211 } else { |
| 212 blocks.RemoveLast(); | 212 blocks.RemoveLast(); |
| 213 } | 213 } |
| 214 } | 214 } |
| 215 } | 215 } |
| 216 | 216 |
| 217 CodeRange::TearDown(); | 217 CodeRange::TearDown(); |
| 218 } | 218 } |
| OLD | NEW |