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