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

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

Issue 542073: * Improve the interface to the memory-reservation functionality.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 10 years, 11 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/spaces.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 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 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 v8::Persistent<v8::Context> env = v8::Context::New(); 272 v8::Persistent<v8::Context> env = v8::Context::New();
273 env->Enter(); 273 env->Enter();
274 274
275 const char* c_source = "\"1234\".length"; 275 const char* c_source = "\"1234\".length";
276 v8::Local<v8::String> source = v8::String::New(c_source); 276 v8::Local<v8::String> source = v8::String::New(c_source);
277 v8::Local<v8::Script> script = v8::Script::Compile(source); 277 v8::Local<v8::Script> script = v8::Script::Compile(source);
278 CHECK_EQ(4, script->Run()->Int32Value()); 278 CHECK_EQ(4, script->Run()->Int32Value());
279 } 279 }
280 280
281 281
282 class FileByteSink : public SnapshotByteSink {
283 public:
284 explicit FileByteSink(const char* snapshot_file) {
285 fp_ = OS::FOpen(snapshot_file, "wb");
286 if (fp_ == NULL) {
287 PrintF("Unable to write to snapshot file \"%s\"\n", snapshot_file);
288 exit(1);
289 }
290 }
291 virtual ~FileByteSink() {
292 if (fp_ != NULL) {
293 fclose(fp_);
294 }
295 }
296 virtual void Put(int byte, const char* description) {
297 if (fp_ != NULL) {
298 fputc(byte, fp_);
299 }
300 }
301
302 private:
303 FILE* fp_;
304 };
305
306
307 TEST(PartialSerialization) {
308 Serializer::Enable();
309 v8::V8::Initialize();
310 v8::Persistent<v8::Context> env = v8::Context::New();
311 env->Enter();
312
313 v8::HandleScope handle_scope;
314 v8::Local<v8::String> foo = v8::String::New("foo");
315
316 FileByteSink file(FLAG_testing_serialization_file);
317 Serializer ser(&file);
318 i::Handle<i::String> internal_foo = v8::Utils::OpenHandle(*foo);
319 Object* raw_foo = *internal_foo;
320 ser.SerializePartial(&raw_foo);
321 }
322
323
282 TEST(LinearAllocation) { 324 TEST(LinearAllocation) {
283 v8::V8::Initialize(); 325 v8::V8::Initialize();
284 NewSpace* new_space = Heap::new_space();
285 PagedSpace* old_pointer_space = Heap::old_pointer_space();
286 PagedSpace* old_data_space = Heap::old_data_space();
287 PagedSpace* code_space = Heap::code_space();
288 PagedSpace* map_space = Heap::map_space();
289 PagedSpace* cell_space = Heap::cell_space();
290 int new_space_max = 512 * KB; 326 int new_space_max = 512 * KB;
291 for (int size = 1000; size < 5 * MB; size += size >> 1) { 327 for (int size = 1000; size < 5 * MB; size += size >> 1) {
292 bool gc_performed = true; 328 int new_space_size = (size < new_space_max) ? size : new_space_max;
293 while (gc_performed) { 329 Heap::ReserveSpace(
294 gc_performed = false; 330 new_space_size,
295 if (size < new_space_max) { 331 size, // Old pointer space.
296 if (!new_space->ReserveSpace(size)) { 332 size, // Old data space.
297 Heap::CollectGarbage(size, NEW_SPACE); 333 size, // Code space.
298 gc_performed = true; 334 size, // Map space.
299 CHECK(new_space->ReserveSpace(size)); 335 size, // Cell space.
300 } 336 size); // Large object space.
301 } 337 LinearAllocationScope linear_allocation_scope;
302 if (!old_pointer_space->ReserveSpace(size)) {
303 Heap::CollectGarbage(size, OLD_POINTER_SPACE);
304 gc_performed = true;
305 CHECK(old_pointer_space->ReserveSpace(size));
306 }
307 if (!(old_data_space->ReserveSpace(size))) {
308 Heap::CollectGarbage(size, OLD_DATA_SPACE);
309 gc_performed = true;
310 CHECK(old_data_space->ReserveSpace(size));
311 }
312 if (!(code_space->ReserveSpace(size))) {
313 Heap::CollectGarbage(size, CODE_SPACE);
314 gc_performed = true;
315 CHECK(code_space->ReserveSpace(size));
316 }
317 if (!(map_space->ReserveSpace(size))) {
318 Heap::CollectGarbage(size, MAP_SPACE);
319 gc_performed = true;
320 CHECK(map_space->ReserveSpace(size));
321 }
322 if (!(cell_space->ReserveSpace(size))) {
323 Heap::CollectGarbage(size, CELL_SPACE);
324 gc_performed = true;
325 CHECK(cell_space->ReserveSpace(size));
326 }
327 }
328 LinearAllocationScope scope;
329 const int kSmallFixedArrayLength = 4; 338 const int kSmallFixedArrayLength = 4;
330 const int kSmallFixedArraySize = 339 const int kSmallFixedArraySize =
331 FixedArray::kHeaderSize + kSmallFixedArrayLength * kPointerSize; 340 FixedArray::kHeaderSize + kSmallFixedArrayLength * kPointerSize;
332 const int kSmallStringLength = 16; 341 const int kSmallStringLength = 16;
333 const int kSmallStringSize = 342 const int kSmallStringSize =
334 SeqAsciiString::kHeaderSize + kSmallStringLength; 343 SeqAsciiString::kHeaderSize + kSmallStringLength;
335 const int kMapSize = Map::kSize; 344 const int kMapSize = Map::kSize;
336 345
337 if (size < new_space_max) { 346 Object* new_last = NULL;
338 Object* new_last = NULL; 347 for (int i = 0;
339 for (int i = 0; 348 i + kSmallFixedArraySize <= new_space_size;
340 i + kSmallFixedArraySize <= size; i += kSmallFixedArraySize) { 349 i += kSmallFixedArraySize) {
341 Object* o = Heap::AllocateFixedArray(kSmallFixedArrayLength); 350 Object* obj = Heap::AllocateFixedArray(kSmallFixedArrayLength);
342 if (new_last != NULL) { 351 if (new_last != NULL) {
343 CHECK_EQ(reinterpret_cast<char*>(o), 352 CHECK_EQ(reinterpret_cast<char*>(obj),
344 reinterpret_cast<char*>(new_last) + kSmallFixedArraySize); 353 reinterpret_cast<char*>(new_last) + kSmallFixedArraySize);
345 }
346 new_last = o;
347 } 354 }
355 new_last = obj;
348 } 356 }
349 357
350 Object* new_pointer = NULL; 358 Object* pointer_last = NULL;
351 for (int i = 0; 359 for (int i = 0;
352 i + kSmallFixedArraySize <= size; 360 i + kSmallFixedArraySize <= size;
353 i += kSmallFixedArraySize) { 361 i += kSmallFixedArraySize) {
354 Object* o = Heap::AllocateFixedArray(kSmallFixedArrayLength, TENURED); 362 Object* obj = Heap::AllocateFixedArray(kSmallFixedArrayLength, TENURED);
355 int old_page_fullness = i % Page::kPageSize; 363 int old_page_fullness = i % Page::kPageSize;
356 int page_fullness = (i + kSmallFixedArraySize) % Page::kPageSize; 364 int page_fullness = (i + kSmallFixedArraySize) % Page::kPageSize;
357 if (page_fullness < old_page_fullness || 365 if (page_fullness < old_page_fullness ||
358 page_fullness > Page::kObjectAreaSize) { 366 page_fullness > Page::kObjectAreaSize) {
359 i = RoundUp(i, Page::kPageSize); 367 i = RoundUp(i, Page::kPageSize);
360 new_pointer = NULL; 368 pointer_last = NULL;
361 } 369 }
362 if (new_pointer != NULL) { 370 if (pointer_last != NULL) {
363 CHECK_EQ(reinterpret_cast<char*>(o), 371 CHECK_EQ(reinterpret_cast<char*>(obj),
364 reinterpret_cast<char*>(new_pointer) + kSmallFixedArraySize); 372 reinterpret_cast<char*>(pointer_last) + kSmallFixedArraySize);
365 } 373 }
366 new_pointer = o; 374 pointer_last = obj;
367 } 375 }
368 376
369 new_pointer = NULL; 377 Object* data_last = NULL;
370 for (int i = 0; i + kSmallStringSize <= size; i += kSmallStringSize) { 378 for (int i = 0; i + kSmallStringSize <= size; i += kSmallStringSize) {
371 Object* o = Heap::AllocateRawAsciiString(kSmallStringLength, TENURED); 379 Object* obj = Heap::AllocateRawAsciiString(kSmallStringLength, TENURED);
372 int old_page_fullness = i % Page::kPageSize; 380 int old_page_fullness = i % Page::kPageSize;
373 int page_fullness = (i + kSmallStringSize) % Page::kPageSize; 381 int page_fullness = (i + kSmallStringSize) % Page::kPageSize;
374 if (page_fullness < old_page_fullness || 382 if (page_fullness < old_page_fullness ||
375 page_fullness > Page::kObjectAreaSize) { 383 page_fullness > Page::kObjectAreaSize) {
376 i = RoundUp(i, Page::kPageSize); 384 i = RoundUp(i, Page::kPageSize);
377 new_pointer = NULL; 385 data_last = NULL;
378 } 386 }
379 if (new_pointer != NULL) { 387 if (data_last != NULL) {
380 CHECK_EQ(reinterpret_cast<char*>(o), 388 CHECK_EQ(reinterpret_cast<char*>(obj),
381 reinterpret_cast<char*>(new_pointer) + kSmallStringSize); 389 reinterpret_cast<char*>(data_last) + kSmallStringSize);
382 } 390 }
383 new_pointer = o; 391 data_last = obj;
384 } 392 }
385 393
386 new_pointer = NULL; 394 Object* map_last = NULL;
387 for (int i = 0; i + kMapSize <= size; i += kMapSize) { 395 for (int i = 0; i + kMapSize <= size; i += kMapSize) {
388 Object* o = Heap::AllocateMap(JS_OBJECT_TYPE, 42 * kPointerSize); 396 Object* obj = Heap::AllocateMap(JS_OBJECT_TYPE, 42 * kPointerSize);
389 int old_page_fullness = i % Page::kPageSize; 397 int old_page_fullness = i % Page::kPageSize;
390 int page_fullness = (i + kMapSize) % Page::kPageSize; 398 int page_fullness = (i + kMapSize) % Page::kPageSize;
391 if (page_fullness < old_page_fullness || 399 if (page_fullness < old_page_fullness ||
392 page_fullness > Page::kObjectAreaSize) { 400 page_fullness > Page::kObjectAreaSize) {
393 i = RoundUp(i, Page::kPageSize); 401 i = RoundUp(i, Page::kPageSize);
394 new_pointer = NULL; 402 map_last = NULL;
395 } 403 }
396 if (new_pointer != NULL) { 404 if (map_last != NULL) {
397 CHECK_EQ(reinterpret_cast<char*>(o), 405 CHECK_EQ(reinterpret_cast<char*>(obj),
398 reinterpret_cast<char*>(new_pointer) + kMapSize); 406 reinterpret_cast<char*>(map_last) + kMapSize);
399 } 407 }
400 new_pointer = o; 408 map_last = obj;
401 } 409 }
402 410
403 if (size > Page::kObjectAreaSize) { 411 if (size > Page::kObjectAreaSize) {
404 // Support for reserving space in large object space is not there yet, 412 // Support for reserving space in large object space is not there yet,
405 // but using an always-allocate scope is fine for now. 413 // but using an always-allocate scope is fine for now.
406 AlwaysAllocateScope always; 414 AlwaysAllocateScope always;
407 int large_object_array_length = 415 int large_object_array_length =
408 (size - FixedArray::kHeaderSize) / kPointerSize; 416 (size - FixedArray::kHeaderSize) / kPointerSize;
409 new_pointer = Heap::AllocateFixedArray(large_object_array_length, 417 Object* obj = Heap::AllocateFixedArray(large_object_array_length,
410 TENURED); 418 TENURED);
411 ASSERT(!new_pointer->IsFailure()); 419 CHECK(!obj->IsFailure());
412 } 420 }
413 } 421 }
414 } 422 }
415 423
416 424
417 TEST(TestThatAlwaysSucceeds) { 425 TEST(TestThatAlwaysSucceeds) {
418 } 426 }
419 427
420 428
421 TEST(TestThatAlwaysFails) { 429 TEST(TestThatAlwaysFails) {
422 bool ArtificialFailure = false; 430 bool ArtificialFailure = false;
423 CHECK(ArtificialFailure); 431 CHECK(ArtificialFailure);
424 } 432 }
425 433
426 434
427 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) { 435 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) {
428 bool ArtificialFailure2 = false; 436 bool ArtificialFailure2 = false;
429 CHECK(ArtificialFailure2); 437 CHECK(ArtificialFailure2);
430 } 438 }
OLDNEW
« no previous file with comments | « src/spaces.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698