| OLD | NEW |
| 1 // Copyright 2007-2010 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2010 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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 } | 189 } |
| 190 virtual int Position() { | 190 virtual int Position() { |
| 191 return ftell(fp_); | 191 return ftell(fp_); |
| 192 } | 192 } |
| 193 void WriteSpaceUsed( | 193 void WriteSpaceUsed( |
| 194 int new_space_used, | 194 int new_space_used, |
| 195 int pointer_space_used, | 195 int pointer_space_used, |
| 196 int data_space_used, | 196 int data_space_used, |
| 197 int code_space_used, | 197 int code_space_used, |
| 198 int map_space_used, | 198 int map_space_used, |
| 199 int cell_space_used, | 199 int cell_space_used); |
| 200 int large_space_used); | |
| 201 | 200 |
| 202 private: | 201 private: |
| 203 FILE* fp_; | 202 FILE* fp_; |
| 204 const char* file_name_; | 203 const char* file_name_; |
| 205 }; | 204 }; |
| 206 | 205 |
| 207 | 206 |
| 208 void FileByteSink::WriteSpaceUsed( | 207 void FileByteSink::WriteSpaceUsed( |
| 209 int new_space_used, | 208 int new_space_used, |
| 210 int pointer_space_used, | 209 int pointer_space_used, |
| 211 int data_space_used, | 210 int data_space_used, |
| 212 int code_space_used, | 211 int code_space_used, |
| 213 int map_space_used, | 212 int map_space_used, |
| 214 int cell_space_used, | 213 int cell_space_used) { |
| 215 int large_space_used) { | |
| 216 int file_name_length = StrLength(file_name_) + 10; | 214 int file_name_length = StrLength(file_name_) + 10; |
| 217 Vector<char> name = Vector<char>::New(file_name_length + 1); | 215 Vector<char> name = Vector<char>::New(file_name_length + 1); |
| 218 OS::SNPrintF(name, "%s.size", file_name_); | 216 OS::SNPrintF(name, "%s.size", file_name_); |
| 219 FILE* fp = OS::FOpen(name.start(), "w"); | 217 FILE* fp = OS::FOpen(name.start(), "w"); |
| 220 name.Dispose(); | 218 name.Dispose(); |
| 221 fprintf(fp, "new %d\n", new_space_used); | 219 fprintf(fp, "new %d\n", new_space_used); |
| 222 fprintf(fp, "pointer %d\n", pointer_space_used); | 220 fprintf(fp, "pointer %d\n", pointer_space_used); |
| 223 fprintf(fp, "data %d\n", data_space_used); | 221 fprintf(fp, "data %d\n", data_space_used); |
| 224 fprintf(fp, "code %d\n", code_space_used); | 222 fprintf(fp, "code %d\n", code_space_used); |
| 225 fprintf(fp, "map %d\n", map_space_used); | 223 fprintf(fp, "map %d\n", map_space_used); |
| 226 fprintf(fp, "cell %d\n", cell_space_used); | 224 fprintf(fp, "cell %d\n", cell_space_used); |
| 227 fprintf(fp, "large %d\n", large_space_used); | |
| 228 fclose(fp); | 225 fclose(fp); |
| 229 } | 226 } |
| 230 | 227 |
| 231 | 228 |
| 232 static bool WriteToFile(const char* snapshot_file) { | 229 static bool WriteToFile(const char* snapshot_file) { |
| 233 FileByteSink file(snapshot_file); | 230 FileByteSink file(snapshot_file); |
| 234 StartupSerializer ser(&file); | 231 StartupSerializer ser(&file); |
| 235 ser.Serialize(); | 232 ser.Serialize(); |
| 233 |
| 234 file.WriteSpaceUsed( |
| 235 ser.CurrentAllocationAddress(NEW_SPACE), |
| 236 ser.CurrentAllocationAddress(OLD_POINTER_SPACE), |
| 237 ser.CurrentAllocationAddress(OLD_DATA_SPACE), |
| 238 ser.CurrentAllocationAddress(CODE_SPACE), |
| 239 ser.CurrentAllocationAddress(MAP_SPACE), |
| 240 ser.CurrentAllocationAddress(CELL_SPACE)); |
| 241 |
| 236 return true; | 242 return true; |
| 237 } | 243 } |
| 238 | 244 |
| 239 | 245 |
| 240 static void Serialize() { | 246 static void Serialize() { |
| 241 // We have to create one context. One reason for this is so that the builtins | 247 // We have to create one context. One reason for this is so that the builtins |
| 242 // can be loaded from v8natives.js and their addresses can be processed. This | 248 // can be loaded from v8natives.js and their addresses can be processed. This |
| 243 // will clear the pending fixups array, which would otherwise contain GC roots | 249 // will clear the pending fixups array, which would otherwise contain GC roots |
| 244 // that would confuse the serialization/deserialization process. | 250 // that would confuse the serialization/deserialization process. |
| 245 v8::Persistent<v8::Context> env = v8::Context::New(); | 251 v8::Persistent<v8::Context> env = v8::Context::New(); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 } | 383 } |
| 378 | 384 |
| 379 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; | 385 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; |
| 380 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); | 386 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); |
| 381 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); | 387 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
| 382 | 388 |
| 383 env->Exit(); | 389 env->Exit(); |
| 384 env.Dispose(); | 390 env.Dispose(); |
| 385 | 391 |
| 386 FileByteSink startup_sink(startup_name.start()); | 392 FileByteSink startup_sink(startup_name.start()); |
| 387 startup_name.Dispose(); | |
| 388 StartupSerializer startup_serializer(&startup_sink); | 393 StartupSerializer startup_serializer(&startup_sink); |
| 389 startup_serializer.SerializeStrongReferences(); | 394 startup_serializer.SerializeStrongReferences(); |
| 390 | 395 |
| 391 FileByteSink partial_sink(FLAG_testing_serialization_file); | 396 FileByteSink partial_sink(FLAG_testing_serialization_file); |
| 392 PartialSerializer p_ser(&startup_serializer, &partial_sink); | 397 PartialSerializer p_ser(&startup_serializer, &partial_sink); |
| 393 p_ser.Serialize(&raw_foo); | 398 p_ser.Serialize(&raw_foo); |
| 394 startup_serializer.SerializeWeakReferences(); | 399 startup_serializer.SerializeWeakReferences(); |
| 400 |
| 395 partial_sink.WriteSpaceUsed( | 401 partial_sink.WriteSpaceUsed( |
| 396 p_ser.CurrentAllocationAddress(NEW_SPACE), | 402 p_ser.CurrentAllocationAddress(NEW_SPACE), |
| 397 p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE), | 403 p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE), |
| 398 p_ser.CurrentAllocationAddress(OLD_DATA_SPACE), | 404 p_ser.CurrentAllocationAddress(OLD_DATA_SPACE), |
| 399 p_ser.CurrentAllocationAddress(CODE_SPACE), | 405 p_ser.CurrentAllocationAddress(CODE_SPACE), |
| 400 p_ser.CurrentAllocationAddress(MAP_SPACE), | 406 p_ser.CurrentAllocationAddress(MAP_SPACE), |
| 401 p_ser.CurrentAllocationAddress(CELL_SPACE), | 407 p_ser.CurrentAllocationAddress(CELL_SPACE)); |
| 402 p_ser.CurrentAllocationAddress(LO_SPACE)); | 408 |
| 409 startup_sink.WriteSpaceUsed( |
| 410 startup_serializer.CurrentAllocationAddress(NEW_SPACE), |
| 411 startup_serializer.CurrentAllocationAddress(OLD_POINTER_SPACE), |
| 412 startup_serializer.CurrentAllocationAddress(OLD_DATA_SPACE), |
| 413 startup_serializer.CurrentAllocationAddress(CODE_SPACE), |
| 414 startup_serializer.CurrentAllocationAddress(MAP_SPACE), |
| 415 startup_serializer.CurrentAllocationAddress(CELL_SPACE)); |
| 416 startup_name.Dispose(); |
| 403 } | 417 } |
| 404 } | 418 } |
| 405 | 419 |
| 406 | 420 |
| 407 static void ReserveSpaceForPartialSnapshot(const char* file_name) { | 421 static void ReserveSpaceForSnapshot(Deserializer* deserializer, |
| 422 const char* file_name) { |
| 408 int file_name_length = StrLength(file_name) + 10; | 423 int file_name_length = StrLength(file_name) + 10; |
| 409 Vector<char> name = Vector<char>::New(file_name_length + 1); | 424 Vector<char> name = Vector<char>::New(file_name_length + 1); |
| 410 OS::SNPrintF(name, "%s.size", file_name); | 425 OS::SNPrintF(name, "%s.size", file_name); |
| 411 FILE* fp = OS::FOpen(name.start(), "r"); | 426 FILE* fp = OS::FOpen(name.start(), "r"); |
| 412 name.Dispose(); | 427 name.Dispose(); |
| 413 int new_size, pointer_size, data_size, code_size, map_size, cell_size; | 428 int new_size, pointer_size, data_size, code_size, map_size, cell_size; |
| 414 int large_size; | |
| 415 #ifdef _MSC_VER | 429 #ifdef _MSC_VER |
| 416 // Avoid warning about unsafe fscanf from MSVC. | 430 // Avoid warning about unsafe fscanf from MSVC. |
| 417 // Please note that this is only fine if %c and %s are not being used. | 431 // Please note that this is only fine if %c and %s are not being used. |
| 418 #define fscanf fscanf_s | 432 #define fscanf fscanf_s |
| 419 #endif | 433 #endif |
| 420 CHECK_EQ(1, fscanf(fp, "new %d\n", &new_size)); | 434 CHECK_EQ(1, fscanf(fp, "new %d\n", &new_size)); |
| 421 CHECK_EQ(1, fscanf(fp, "pointer %d\n", &pointer_size)); | 435 CHECK_EQ(1, fscanf(fp, "pointer %d\n", &pointer_size)); |
| 422 CHECK_EQ(1, fscanf(fp, "data %d\n", &data_size)); | 436 CHECK_EQ(1, fscanf(fp, "data %d\n", &data_size)); |
| 423 CHECK_EQ(1, fscanf(fp, "code %d\n", &code_size)); | 437 CHECK_EQ(1, fscanf(fp, "code %d\n", &code_size)); |
| 424 CHECK_EQ(1, fscanf(fp, "map %d\n", &map_size)); | 438 CHECK_EQ(1, fscanf(fp, "map %d\n", &map_size)); |
| 425 CHECK_EQ(1, fscanf(fp, "cell %d\n", &cell_size)); | 439 CHECK_EQ(1, fscanf(fp, "cell %d\n", &cell_size)); |
| 426 CHECK_EQ(1, fscanf(fp, "large %d\n", &large_size)); | |
| 427 #ifdef _MSC_VER | 440 #ifdef _MSC_VER |
| 428 #undef fscanf | 441 #undef fscanf |
| 429 #endif | 442 #endif |
| 430 fclose(fp); | 443 fclose(fp); |
| 431 HEAP->ReserveSpace(new_size, | 444 deserializer->set_reservation(NEW_SPACE, new_size); |
| 432 pointer_size, | 445 deserializer->set_reservation(OLD_POINTER_SPACE, pointer_size); |
| 433 data_size, | 446 deserializer->set_reservation(OLD_DATA_SPACE, data_size); |
| 434 code_size, | 447 deserializer->set_reservation(CODE_SPACE, code_size); |
| 435 map_size, | 448 deserializer->set_reservation(MAP_SPACE, map_size); |
| 436 cell_size, | 449 deserializer->set_reservation(CELL_SPACE, cell_size); |
| 437 large_size); | |
| 438 } | 450 } |
| 439 | 451 |
| 440 | 452 |
| 441 DEPENDENT_TEST(PartialDeserialization, PartialSerialization) { | 453 DEPENDENT_TEST(PartialDeserialization, PartialSerialization) { |
| 442 if (!Snapshot::IsEnabled()) { | 454 if (!Snapshot::IsEnabled()) { |
| 443 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; | 455 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; |
| 444 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); | 456 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); |
| 445 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); | 457 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
| 446 | 458 |
| 447 CHECK(Snapshot::Initialize(startup_name.start())); | 459 CHECK(Snapshot::Initialize(startup_name.start())); |
| 448 startup_name.Dispose(); | 460 startup_name.Dispose(); |
| 449 | 461 |
| 450 const char* file_name = FLAG_testing_serialization_file; | 462 const char* file_name = FLAG_testing_serialization_file; |
| 451 ReserveSpaceForPartialSnapshot(file_name); | |
| 452 | 463 |
| 453 int snapshot_size = 0; | 464 int snapshot_size = 0; |
| 454 byte* snapshot = ReadBytes(file_name, &snapshot_size); | 465 byte* snapshot = ReadBytes(file_name, &snapshot_size); |
| 455 | 466 |
| 456 Object* root; | 467 Object* root; |
| 457 { | 468 { |
| 458 SnapshotByteSource source(snapshot, snapshot_size); | 469 SnapshotByteSource source(snapshot, snapshot_size); |
| 459 Deserializer deserializer(&source); | 470 Deserializer deserializer(&source); |
| 471 ReserveSpaceForSnapshot(&deserializer, file_name); |
| 460 deserializer.DeserializePartial(&root); | 472 deserializer.DeserializePartial(&root); |
| 461 CHECK(root->IsString()); | 473 CHECK(root->IsString()); |
| 462 } | 474 } |
| 463 v8::HandleScope handle_scope; | 475 v8::HandleScope handle_scope; |
| 464 Handle<Object> root_handle(root); | 476 Handle<Object> root_handle(root); |
| 465 | 477 |
| 466 ReserveSpaceForPartialSnapshot(file_name); | |
| 467 | 478 |
| 468 Object* root2; | 479 Object* root2; |
| 469 { | 480 { |
| 470 SnapshotByteSource source(snapshot, snapshot_size); | 481 SnapshotByteSource source(snapshot, snapshot_size); |
| 471 Deserializer deserializer(&source); | 482 Deserializer deserializer(&source); |
| 483 ReserveSpaceForSnapshot(&deserializer, file_name); |
| 472 deserializer.DeserializePartial(&root2); | 484 deserializer.DeserializePartial(&root2); |
| 473 CHECK(root2->IsString()); | 485 CHECK(root2->IsString()); |
| 474 CHECK(*root_handle == root2); | 486 CHECK(*root_handle == root2); |
| 475 } | 487 } |
| 476 } | 488 } |
| 477 } | 489 } |
| 478 | 490 |
| 479 | 491 |
| 480 TEST(ContextSerialization) { | 492 TEST(ContextSerialization) { |
| 481 if (!Snapshot::HaveASnapshotToStartFrom()) { | 493 if (!Snapshot::HaveASnapshotToStartFrom()) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 499 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); | 511 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); |
| 500 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); | 512 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
| 501 | 513 |
| 502 env->Exit(); | 514 env->Exit(); |
| 503 | 515 |
| 504 Object* raw_context = *(v8::Utils::OpenHandle(*env)); | 516 Object* raw_context = *(v8::Utils::OpenHandle(*env)); |
| 505 | 517 |
| 506 env.Dispose(); | 518 env.Dispose(); |
| 507 | 519 |
| 508 FileByteSink startup_sink(startup_name.start()); | 520 FileByteSink startup_sink(startup_name.start()); |
| 509 startup_name.Dispose(); | |
| 510 StartupSerializer startup_serializer(&startup_sink); | 521 StartupSerializer startup_serializer(&startup_sink); |
| 511 startup_serializer.SerializeStrongReferences(); | 522 startup_serializer.SerializeStrongReferences(); |
| 512 | 523 |
| 513 FileByteSink partial_sink(FLAG_testing_serialization_file); | 524 FileByteSink partial_sink(FLAG_testing_serialization_file); |
| 514 PartialSerializer p_ser(&startup_serializer, &partial_sink); | 525 PartialSerializer p_ser(&startup_serializer, &partial_sink); |
| 515 p_ser.Serialize(&raw_context); | 526 p_ser.Serialize(&raw_context); |
| 516 startup_serializer.SerializeWeakReferences(); | 527 startup_serializer.SerializeWeakReferences(); |
| 528 |
| 517 partial_sink.WriteSpaceUsed( | 529 partial_sink.WriteSpaceUsed( |
| 518 p_ser.CurrentAllocationAddress(NEW_SPACE), | 530 p_ser.CurrentAllocationAddress(NEW_SPACE), |
| 519 p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE), | 531 p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE), |
| 520 p_ser.CurrentAllocationAddress(OLD_DATA_SPACE), | 532 p_ser.CurrentAllocationAddress(OLD_DATA_SPACE), |
| 521 p_ser.CurrentAllocationAddress(CODE_SPACE), | 533 p_ser.CurrentAllocationAddress(CODE_SPACE), |
| 522 p_ser.CurrentAllocationAddress(MAP_SPACE), | 534 p_ser.CurrentAllocationAddress(MAP_SPACE), |
| 523 p_ser.CurrentAllocationAddress(CELL_SPACE), | 535 p_ser.CurrentAllocationAddress(CELL_SPACE)); |
| 524 p_ser.CurrentAllocationAddress(LO_SPACE)); | 536 |
| 537 startup_sink.WriteSpaceUsed( |
| 538 startup_serializer.CurrentAllocationAddress(NEW_SPACE), |
| 539 startup_serializer.CurrentAllocationAddress(OLD_POINTER_SPACE), |
| 540 startup_serializer.CurrentAllocationAddress(OLD_DATA_SPACE), |
| 541 startup_serializer.CurrentAllocationAddress(CODE_SPACE), |
| 542 startup_serializer.CurrentAllocationAddress(MAP_SPACE), |
| 543 startup_serializer.CurrentAllocationAddress(CELL_SPACE)); |
| 544 startup_name.Dispose(); |
| 525 } | 545 } |
| 526 } | 546 } |
| 527 | 547 |
| 528 | 548 |
| 529 DEPENDENT_TEST(ContextDeserialization, ContextSerialization) { | 549 DEPENDENT_TEST(ContextDeserialization, ContextSerialization) { |
| 530 if (!Snapshot::HaveASnapshotToStartFrom()) { | 550 if (!Snapshot::HaveASnapshotToStartFrom()) { |
| 531 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; | 551 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; |
| 532 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); | 552 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); |
| 533 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); | 553 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
| 534 | 554 |
| 535 CHECK(Snapshot::Initialize(startup_name.start())); | 555 CHECK(Snapshot::Initialize(startup_name.start())); |
| 536 startup_name.Dispose(); | 556 startup_name.Dispose(); |
| 537 | 557 |
| 538 const char* file_name = FLAG_testing_serialization_file; | 558 const char* file_name = FLAG_testing_serialization_file; |
| 539 ReserveSpaceForPartialSnapshot(file_name); | |
| 540 | 559 |
| 541 int snapshot_size = 0; | 560 int snapshot_size = 0; |
| 542 byte* snapshot = ReadBytes(file_name, &snapshot_size); | 561 byte* snapshot = ReadBytes(file_name, &snapshot_size); |
| 543 | 562 |
| 544 Object* root; | 563 Object* root; |
| 545 { | 564 { |
| 546 SnapshotByteSource source(snapshot, snapshot_size); | 565 SnapshotByteSource source(snapshot, snapshot_size); |
| 547 Deserializer deserializer(&source); | 566 Deserializer deserializer(&source); |
| 567 ReserveSpaceForSnapshot(&deserializer, file_name); |
| 548 deserializer.DeserializePartial(&root); | 568 deserializer.DeserializePartial(&root); |
| 549 CHECK(root->IsContext()); | 569 CHECK(root->IsContext()); |
| 550 } | 570 } |
| 551 v8::HandleScope handle_scope; | 571 v8::HandleScope handle_scope; |
| 552 Handle<Object> root_handle(root); | 572 Handle<Object> root_handle(root); |
| 553 | 573 |
| 554 ReserveSpaceForPartialSnapshot(file_name); | |
| 555 | 574 |
| 556 Object* root2; | 575 Object* root2; |
| 557 { | 576 { |
| 558 SnapshotByteSource source(snapshot, snapshot_size); | 577 SnapshotByteSource source(snapshot, snapshot_size); |
| 559 Deserializer deserializer(&source); | 578 Deserializer deserializer(&source); |
| 579 ReserveSpaceForSnapshot(&deserializer, file_name); |
| 560 deserializer.DeserializePartial(&root2); | 580 deserializer.DeserializePartial(&root2); |
| 561 CHECK(root2->IsContext()); | 581 CHECK(root2->IsContext()); |
| 562 CHECK(*root_handle != root2); | 582 CHECK(*root_handle != root2); |
| 563 } | 583 } |
| 564 } | 584 } |
| 565 } | 585 } |
| 566 | 586 |
| 567 | 587 |
| 568 TEST(LinearAllocation) { | |
| 569 v8::V8::Initialize(); | |
| 570 int new_space_max = 512 * KB; | |
| 571 int paged_space_max = Page::kMaxNonCodeHeapObjectSize; | |
| 572 int code_space_max = HEAP->code_space()->AreaSize(); | |
| 573 | |
| 574 for (int size = 1000; size < 5 * MB; size += size >> 1) { | |
| 575 size &= ~8; // Round. | |
| 576 int new_space_size = (size < new_space_max) ? size : new_space_max; | |
| 577 int paged_space_size = (size < paged_space_max) ? size : paged_space_max; | |
| 578 HEAP->ReserveSpace( | |
| 579 new_space_size, | |
| 580 paged_space_size, // Old pointer space. | |
| 581 paged_space_size, // Old data space. | |
| 582 HEAP->code_space()->RoundSizeDownToObjectAlignment(code_space_max), | |
| 583 HEAP->map_space()->RoundSizeDownToObjectAlignment(paged_space_size), | |
| 584 HEAP->cell_space()->RoundSizeDownToObjectAlignment(paged_space_size), | |
| 585 size); // Large object space. | |
| 586 LinearAllocationScope linear_allocation_scope; | |
| 587 DisallowAllocationFailure disallow_allocation_failure; | |
| 588 const int kSmallFixedArrayLength = 4; | |
| 589 const int kSmallFixedArraySize = | |
| 590 FixedArray::kHeaderSize + kSmallFixedArrayLength * kPointerSize; | |
| 591 const int kSmallStringLength = 16; | |
| 592 const int kSmallStringSize = | |
| 593 (SeqAsciiString::kHeaderSize + kSmallStringLength + | |
| 594 kObjectAlignmentMask) & ~kObjectAlignmentMask; | |
| 595 const int kMapSize = Map::kSize; | |
| 596 | |
| 597 Object* new_last = NULL; | |
| 598 for (int i = 0; | |
| 599 i + kSmallFixedArraySize <= new_space_size; | |
| 600 i += kSmallFixedArraySize) { | |
| 601 Object* obj = | |
| 602 HEAP->AllocateFixedArray(kSmallFixedArrayLength)->ToObjectChecked(); | |
| 603 if (new_last != NULL) { | |
| 604 CHECK(reinterpret_cast<char*>(obj) == | |
| 605 reinterpret_cast<char*>(new_last) + kSmallFixedArraySize); | |
| 606 } | |
| 607 new_last = obj; | |
| 608 } | |
| 609 | |
| 610 Object* pointer_last = NULL; | |
| 611 for (int i = 0; | |
| 612 i + kSmallFixedArraySize <= paged_space_size; | |
| 613 i += kSmallFixedArraySize) { | |
| 614 Object* obj = HEAP->AllocateFixedArray(kSmallFixedArrayLength, | |
| 615 TENURED)->ToObjectChecked(); | |
| 616 int old_page_fullness = i % Page::kPageSize; | |
| 617 int page_fullness = (i + kSmallFixedArraySize) % Page::kPageSize; | |
| 618 if (page_fullness < old_page_fullness || | |
| 619 page_fullness > HEAP->old_pointer_space()->AreaSize()) { | |
| 620 i = RoundUp(i, Page::kPageSize); | |
| 621 pointer_last = NULL; | |
| 622 } | |
| 623 if (pointer_last != NULL) { | |
| 624 CHECK(reinterpret_cast<char*>(obj) == | |
| 625 reinterpret_cast<char*>(pointer_last) + kSmallFixedArraySize); | |
| 626 } | |
| 627 pointer_last = obj; | |
| 628 } | |
| 629 | |
| 630 Object* data_last = NULL; | |
| 631 for (int i = 0; | |
| 632 i + kSmallStringSize <= paged_space_size; | |
| 633 i += kSmallStringSize) { | |
| 634 Object* obj = HEAP->AllocateRawAsciiString(kSmallStringLength, | |
| 635 TENURED)->ToObjectChecked(); | |
| 636 int old_page_fullness = i % Page::kPageSize; | |
| 637 int page_fullness = (i + kSmallStringSize) % Page::kPageSize; | |
| 638 if (page_fullness < old_page_fullness || | |
| 639 page_fullness > HEAP->old_data_space()->AreaSize()) { | |
| 640 i = RoundUp(i, Page::kPageSize); | |
| 641 data_last = NULL; | |
| 642 } | |
| 643 if (data_last != NULL) { | |
| 644 CHECK(reinterpret_cast<char*>(obj) == | |
| 645 reinterpret_cast<char*>(data_last) + kSmallStringSize); | |
| 646 } | |
| 647 data_last = obj; | |
| 648 } | |
| 649 | |
| 650 Object* map_last = NULL; | |
| 651 for (int i = 0; i + kMapSize <= paged_space_size; i += kMapSize) { | |
| 652 Object* obj = HEAP->AllocateMap(JS_OBJECT_TYPE, | |
| 653 42 * kPointerSize)->ToObjectChecked(); | |
| 654 int old_page_fullness = i % Page::kPageSize; | |
| 655 int page_fullness = (i + kMapSize) % Page::kPageSize; | |
| 656 if (page_fullness < old_page_fullness || | |
| 657 page_fullness > HEAP->map_space()->AreaSize()) { | |
| 658 i = RoundUp(i, Page::kPageSize); | |
| 659 map_last = NULL; | |
| 660 } | |
| 661 if (map_last != NULL) { | |
| 662 CHECK(reinterpret_cast<char*>(obj) == | |
| 663 reinterpret_cast<char*>(map_last) + kMapSize); | |
| 664 } | |
| 665 map_last = obj; | |
| 666 } | |
| 667 | |
| 668 if (size > Page::kMaxNonCodeHeapObjectSize) { | |
| 669 // Support for reserving space in large object space is not there yet, | |
| 670 // but using an always-allocate scope is fine for now. | |
| 671 AlwaysAllocateScope always; | |
| 672 int large_object_array_length = | |
| 673 (size - FixedArray::kHeaderSize) / kPointerSize; | |
| 674 Object* obj = HEAP->AllocateFixedArray(large_object_array_length, | |
| 675 TENURED)->ToObjectChecked(); | |
| 676 CHECK(!obj->IsFailure()); | |
| 677 } | |
| 678 } | |
| 679 } | |
| 680 | |
| 681 | |
| 682 TEST(TestThatAlwaysSucceeds) { | 588 TEST(TestThatAlwaysSucceeds) { |
| 683 } | 589 } |
| 684 | 590 |
| 685 | 591 |
| 686 TEST(TestThatAlwaysFails) { | 592 TEST(TestThatAlwaysFails) { |
| 687 bool ArtificialFailure = false; | 593 bool ArtificialFailure = false; |
| 688 CHECK(ArtificialFailure); | 594 CHECK(ArtificialFailure); |
| 689 } | 595 } |
| 690 | 596 |
| 691 | 597 |
| 692 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) { | 598 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) { |
| 693 bool ArtificialFailure2 = false; | 599 bool ArtificialFailure2 = false; |
| 694 CHECK(ArtificialFailure2); | 600 CHECK(ArtificialFailure2); |
| 695 } | 601 } |
| OLD | NEW |