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

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

Issue 7945009: Merge experimental/gc branch to the bleeding_edge. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 9 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 | « test/cctest/test-accessors.cc ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 CHECK(!heap->CopyJSObject(JSObject::cast(object))->IsFailure()); 65 CHECK(!heap->CopyJSObject(JSObject::cast(object))->IsFailure());
66 66
67 // Old data space. 67 // Old data space.
68 OldSpace* old_data_space = heap->old_data_space(); 68 OldSpace* old_data_space = heap->old_data_space();
69 static const int kOldDataSpaceFillerSize = ByteArray::SizeFor(0); 69 static const int kOldDataSpaceFillerSize = ByteArray::SizeFor(0);
70 while (old_data_space->Available() > kOldDataSpaceFillerSize) { 70 while (old_data_space->Available() > kOldDataSpaceFillerSize) {
71 CHECK(!heap->AllocateByteArray(0, TENURED)->IsFailure()); 71 CHECK(!heap->AllocateByteArray(0, TENURED)->IsFailure());
72 } 72 }
73 CHECK(!heap->AllocateRawAsciiString(100, TENURED)->IsFailure()); 73 CHECK(!heap->AllocateRawAsciiString(100, TENURED)->IsFailure());
74 74
75 // Old pointer space.
76 OldSpace* old_pointer_space = heap->old_pointer_space();
77 static const int kOldPointerSpaceFillerLength = 10000;
78 static const int kOldPointerSpaceFillerSize = FixedArray::SizeFor(
79 kOldPointerSpaceFillerLength);
80 while (old_pointer_space->Available() > kOldPointerSpaceFillerSize) {
81 CHECK(!heap->AllocateFixedArray(kOldPointerSpaceFillerLength, TENURED)->
82 IsFailure());
83 }
84 CHECK(!heap->AllocateFixedArray(kOldPointerSpaceFillerLength, TENURED)->
85 IsFailure());
86
75 // Large object space. 87 // Large object space.
76 while (!heap->OldGenerationAllocationLimitReached()) { 88 static const int kLargeObjectSpaceFillerLength = 300000;
77 CHECK(!heap->AllocateFixedArray(10000, TENURED)->IsFailure()); 89 static const int kLargeObjectSpaceFillerSize = FixedArray::SizeFor(
90 kLargeObjectSpaceFillerLength);
91 ASSERT(kLargeObjectSpaceFillerSize > heap->MaxObjectSizeInPagedSpace());
92 while (heap->OldGenerationSpaceAvailable() > kLargeObjectSpaceFillerSize) {
93 CHECK(!heap->AllocateFixedArray(kLargeObjectSpaceFillerLength, TENURED)->
94 IsFailure());
78 } 95 }
79 CHECK(!heap->AllocateFixedArray(10000, TENURED)->IsFailure()); 96 CHECK(!heap->AllocateFixedArray(kLargeObjectSpaceFillerLength, TENURED)->
97 IsFailure());
80 98
81 // Map space. 99 // Map space.
82 MapSpace* map_space = heap->map_space(); 100 MapSpace* map_space = heap->map_space();
83 static const int kMapSpaceFillerSize = Map::kSize; 101 static const int kMapSpaceFillerSize = Map::kSize;
84 InstanceType instance_type = JS_OBJECT_TYPE; 102 InstanceType instance_type = JS_OBJECT_TYPE;
85 int instance_size = JSObject::kHeaderSize; 103 int instance_size = JSObject::kHeaderSize;
86 while (map_space->Available() > kMapSpaceFillerSize) { 104 while (map_space->Available() > kMapSpaceFillerSize) {
87 CHECK(!heap->AllocateMap(instance_type, instance_size)->IsFailure()); 105 CHECK(!heap->AllocateMap(instance_type, instance_size)->IsFailure());
88 } 106 }
89 CHECK(!heap->AllocateMap(instance_type, instance_size)->IsFailure()); 107 CHECK(!heap->AllocateMap(instance_type, instance_size)->IsFailure());
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 unsigned int Pseudorandom() { 186 unsigned int Pseudorandom() {
169 static uint32_t lo = 2345; 187 static uint32_t lo = 2345;
170 lo = 18273 * (lo & 0xFFFF) + (lo >> 16); // Provably not 0. 188 lo = 18273 * (lo & 0xFFFF) + (lo >> 16); // Provably not 0.
171 return lo & 0xFFFF; 189 return lo & 0xFFFF;
172 } 190 }
173 191
174 192
175 // Plain old data class. Represents a block of allocated memory. 193 // Plain old data class. Represents a block of allocated memory.
176 class Block { 194 class Block {
177 public: 195 public:
178 Block(void* base_arg, int size_arg) 196 Block(Address base_arg, int size_arg)
179 : base(base_arg), size(size_arg) {} 197 : base(base_arg), size(size_arg) {}
180 198
181 void *base; 199 Address base;
182 int size; 200 int size;
183 }; 201 };
184 202
185 203
186 TEST(CodeRange) { 204 TEST(CodeRange) {
187 const int code_range_size = 16*MB; 205 const int code_range_size = 32*MB;
188 OS::Setup(); 206 OS::Setup();
189 Isolate::Current()->InitializeLoggingAndCounters(); 207 Isolate::Current()->InitializeLoggingAndCounters();
190 CodeRange* code_range = new CodeRange(Isolate::Current()); 208 CodeRange* code_range = new CodeRange(Isolate::Current());
191 code_range->Setup(code_range_size); 209 code_range->Setup(code_range_size);
192 int current_allocated = 0; 210 int current_allocated = 0;
193 int total_allocated = 0; 211 int total_allocated = 0;
194 List<Block> blocks(1000); 212 List<Block> blocks(1000);
195 213
196 while (total_allocated < 5 * code_range_size) { 214 while (total_allocated < 5 * code_range_size) {
197 if (current_allocated < code_range_size / 10) { 215 if (current_allocated < code_range_size / 10) {
198 // Allocate a block. 216 // Allocate a block.
199 // Geometrically distributed sizes, greater than Page::kPageSize. 217 // Geometrically distributed sizes, greater than Page::kMaxHeapObjectSize.
200 size_t requested = (Page::kPageSize << (Pseudorandom() % 6)) + 218 // TODO(gc): instead of using 3 use some contant based on code_range_size
219 // kMaxHeapObjectSize.
220 size_t requested = (Page::kMaxHeapObjectSize << (Pseudorandom() % 3)) +
201 Pseudorandom() % 5000 + 1; 221 Pseudorandom() % 5000 + 1;
202 size_t allocated = 0; 222 size_t allocated = 0;
203 void* base = code_range->AllocateRawMemory(requested, &allocated); 223 Address base = code_range->AllocateRawMemory(requested, &allocated);
204 CHECK(base != NULL); 224 CHECK(base != NULL);
205 blocks.Add(Block(base, static_cast<int>(allocated))); 225 blocks.Add(Block(base, static_cast<int>(allocated)));
206 current_allocated += static_cast<int>(allocated); 226 current_allocated += static_cast<int>(allocated);
207 total_allocated += static_cast<int>(allocated); 227 total_allocated += static_cast<int>(allocated);
208 } else { 228 } else {
209 // Free a block. 229 // Free a block.
210 int index = Pseudorandom() % blocks.length(); 230 int index = Pseudorandom() % blocks.length();
211 code_range->FreeRawMemory(blocks[index].base, blocks[index].size); 231 code_range->FreeRawMemory(blocks[index].base, blocks[index].size);
212 current_allocated -= blocks[index].size; 232 current_allocated -= blocks[index].size;
213 if (index < blocks.length() - 1) { 233 if (index < blocks.length() - 1) {
214 blocks[index] = blocks.RemoveLast(); 234 blocks[index] = blocks.RemoveLast();
215 } else { 235 } else {
216 blocks.RemoveLast(); 236 blocks.RemoveLast();
217 } 237 }
218 } 238 }
219 } 239 }
220 240
221 code_range->TearDown(); 241 code_range->TearDown();
222 delete code_range; 242 delete code_range;
223 } 243 }
OLDNEW
« no previous file with comments | « test/cctest/test-accessors.cc ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698