| 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 unsigned int Pseudorandom() { | 166 unsigned int Pseudorandom() { |
| 167 static uint32_t lo = 2345; | 167 static uint32_t lo = 2345; |
| 168 lo = 18273 * (lo & 0xFFFF) + (lo >> 16); // Provably not 0. | 168 lo = 18273 * (lo & 0xFFFF) + (lo >> 16); // Provably not 0. |
| 169 return lo & 0xFFFF; | 169 return lo & 0xFFFF; |
| 170 } | 170 } |
| 171 | 171 |
| 172 | 172 |
| 173 // Plain old data class. Represents a block of allocated memory. | 173 // Plain old data class. Represents a block of allocated memory. |
| 174 class Block { | 174 class Block { |
| 175 public: | 175 public: |
| 176 Block(void* base_arg, int size_arg) | 176 Block(Address base_arg, int size_arg) |
| 177 : base(base_arg), size(size_arg) {} | 177 : base(base_arg), size(size_arg) {} |
| 178 | 178 |
| 179 void *base; | 179 Address base; |
| 180 int size; | 180 int size; |
| 181 }; | 181 }; |
| 182 | 182 |
| 183 | 183 |
| 184 TEST(CodeRange) { | 184 TEST(CodeRange) { |
| 185 const int code_range_size = 16*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::kPageSize. | 194 // Geometrically distributed sizes, greater than Page::kMaxHeapObjectSize. |
| 195 size_t requested = (Page::kPageSize << (Pseudorandom() % 6)) + | 195 // TODO (gc) instead of using 3 use some contant based on code_range_size |
| 196 // kMaxHeapObjectSize. |
| 197 size_t requested = (Page::kMaxHeapObjectSize << (Pseudorandom() % 3)) + |
| 196 Pseudorandom() % 5000 + 1; | 198 Pseudorandom() % 5000 + 1; |
| 197 size_t allocated = 0; | 199 size_t allocated = 0; |
| 198 void* base = CodeRange::AllocateRawMemory(requested, &allocated); | 200 Address base = CodeRange::AllocateRawMemory(requested, &allocated); |
| 199 blocks.Add(Block(base, static_cast<int>(allocated))); | 201 blocks.Add(Block(base, static_cast<int>(allocated))); |
| 200 current_allocated += static_cast<int>(allocated); | 202 current_allocated += static_cast<int>(allocated); |
| 201 total_allocated += static_cast<int>(allocated); | 203 total_allocated += static_cast<int>(allocated); |
| 202 } else { | 204 } else { |
| 203 // Free a block. | 205 // Free a block. |
| 204 int index = Pseudorandom() % blocks.length(); | 206 int index = Pseudorandom() % blocks.length(); |
| 205 CodeRange::FreeRawMemory(blocks[index].base, blocks[index].size); | 207 CodeRange::FreeRawMemory(blocks[index].base, blocks[index].size); |
| 206 current_allocated -= blocks[index].size; | 208 current_allocated -= blocks[index].size; |
| 207 if (index < blocks.length() - 1) { | 209 if (index < blocks.length() - 1) { |
| 208 blocks[index] = blocks.RemoveLast(); | 210 blocks[index] = blocks.RemoveLast(); |
| 209 } else { | 211 } else { |
| 210 blocks.RemoveLast(); | 212 blocks.RemoveLast(); |
| 211 } | 213 } |
| 212 } | 214 } |
| 213 } | 215 } |
| 214 | 216 |
| 215 CodeRange::TearDown(); | 217 CodeRange::TearDown(); |
| 216 } | 218 } |
| OLD | NEW |