Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: test/cctest/test-alloc.cc

Issue 23903008: Drop OS::IsOutsideAllocatedSpace() and move the tracking to the MemoryAllocator. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix invalid calculation of committed memory boundaries. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/v8.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 Block(Address base_arg, int size_arg) 179 Block(Address base_arg, int size_arg)
180 : base(base_arg), size(size_arg) {} 180 : base(base_arg), size(size_arg) {}
181 181
182 Address base; 182 Address base;
183 int size; 183 int size;
184 }; 184 };
185 185
186 186
187 TEST(CodeRange) { 187 TEST(CodeRange) {
188 const int code_range_size = 32*MB; 188 const int code_range_size = 32*MB;
189 OS::SetUp(); 189 CcTest::InitializeVM();
190 Isolate::Current()->InitializeLoggingAndCounters(); 190 CodeRange code_range(reinterpret_cast<Isolate*>(CcTest::isolate()));
191 CodeRange* code_range = new CodeRange(Isolate::Current()); 191 code_range.SetUp(code_range_size);
192 code_range->SetUp(code_range_size);
193 int current_allocated = 0; 192 int current_allocated = 0;
194 int total_allocated = 0; 193 int total_allocated = 0;
195 List<Block> blocks(1000); 194 List<Block> blocks(1000);
196 195
197 while (total_allocated < 5 * code_range_size) { 196 while (total_allocated < 5 * code_range_size) {
198 if (current_allocated < code_range_size / 10) { 197 if (current_allocated < code_range_size / 10) {
199 // Allocate a block. 198 // Allocate a block.
200 // Geometrically distributed sizes, greater than 199 // Geometrically distributed sizes, greater than
201 // Page::kMaxNonCodeHeapObjectSize (which is greater than code page area). 200 // Page::kMaxNonCodeHeapObjectSize (which is greater than code page area).
202 // TODO(gc): instead of using 3 use some contant based on code_range_size 201 // TODO(gc): instead of using 3 use some contant based on code_range_size
203 // kMaxHeapObjectSize. 202 // kMaxHeapObjectSize.
204 size_t requested = 203 size_t requested =
205 (Page::kMaxNonCodeHeapObjectSize << (Pseudorandom() % 3)) + 204 (Page::kMaxNonCodeHeapObjectSize << (Pseudorandom() % 3)) +
206 Pseudorandom() % 5000 + 1; 205 Pseudorandom() % 5000 + 1;
207 size_t allocated = 0; 206 size_t allocated = 0;
208 Address base = code_range->AllocateRawMemory(requested, 207 Address base = code_range.AllocateRawMemory(requested,
209 requested, 208 requested,
210 &allocated); 209 &allocated);
211 CHECK(base != NULL); 210 CHECK(base != NULL);
212 blocks.Add(Block(base, static_cast<int>(allocated))); 211 blocks.Add(Block(base, static_cast<int>(allocated)));
213 current_allocated += static_cast<int>(allocated); 212 current_allocated += static_cast<int>(allocated);
214 total_allocated += static_cast<int>(allocated); 213 total_allocated += static_cast<int>(allocated);
215 } else { 214 } else {
216 // Free a block. 215 // Free a block.
217 int index = Pseudorandom() % blocks.length(); 216 int index = Pseudorandom() % blocks.length();
218 code_range->FreeRawMemory(blocks[index].base, blocks[index].size); 217 code_range.FreeRawMemory(blocks[index].base, blocks[index].size);
219 current_allocated -= blocks[index].size; 218 current_allocated -= blocks[index].size;
220 if (index < blocks.length() - 1) { 219 if (index < blocks.length() - 1) {
221 blocks[index] = blocks.RemoveLast(); 220 blocks[index] = blocks.RemoveLast();
222 } else { 221 } else {
223 blocks.RemoveLast(); 222 blocks.RemoveLast();
224 } 223 }
225 } 224 }
226 } 225 }
227 226
228 code_range->TearDown(); 227 code_range.TearDown();
229 delete code_range;
230 } 228 }
OLDNEW
« no previous file with comments | « src/v8.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698