| 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 168 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 void *base; | 181 void *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 = 16*MB; | 187 const int code_range_size = 16*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::kPageSize. | 199 // Geometrically distributed sizes, greater than Page::kPageSize. |
| 198 size_t requested = (Page::kPageSize << (Pseudorandom() % 6)) + | 200 size_t requested = (Page::kPageSize << (Pseudorandom() % 6)) + |
| 199 Pseudorandom() % 5000 + 1; | 201 Pseudorandom() % 5000 + 1; |
| 200 size_t allocated = 0; | 202 size_t allocated = 0; |
| 201 void* base = Isolate::Current()->code_range()-> | 203 void* base = code_range->AllocateRawMemory(requested, &allocated); |
| 202 AllocateRawMemory(requested, &allocated); | |
| 203 CHECK(base != NULL); | 204 CHECK(base != NULL); |
| 204 blocks.Add(Block(base, static_cast<int>(allocated))); | 205 blocks.Add(Block(base, static_cast<int>(allocated))); |
| 205 current_allocated += static_cast<int>(allocated); | 206 current_allocated += static_cast<int>(allocated); |
| 206 total_allocated += static_cast<int>(allocated); | 207 total_allocated += static_cast<int>(allocated); |
| 207 } else { | 208 } else { |
| 208 // Free a block. | 209 // Free a block. |
| 209 int index = Pseudorandom() % blocks.length(); | 210 int index = Pseudorandom() % blocks.length(); |
| 210 Isolate::Current()->code_range()->FreeRawMemory( | 211 code_range->FreeRawMemory(blocks[index].base, blocks[index].size); |
| 211 blocks[index].base, blocks[index].size); | |
| 212 current_allocated -= blocks[index].size; | 212 current_allocated -= blocks[index].size; |
| 213 if (index < blocks.length() - 1) { | 213 if (index < blocks.length() - 1) { |
| 214 blocks[index] = blocks.RemoveLast(); | 214 blocks[index] = blocks.RemoveLast(); |
| 215 } else { | 215 } else { |
| 216 blocks.RemoveLast(); | 216 blocks.RemoveLast(); |
| 217 } | 217 } |
| 218 } | 218 } |
| 219 } | 219 } |
| 220 | 220 |
| 221 Isolate::Current()->code_range()->TearDown(); | 221 code_range->TearDown(); |
| 222 delete code_range; |
| 222 } | 223 } |
| OLD | NEW |