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

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

Issue 3836001: Get rid of requested size in RetryAfterGC. (Closed)
Patch Set: Created 10 years, 2 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
« no previous file with comments | « test/cctest/test-alloc.cc ('k') | test/cctest/test-debug.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-2009 the V8 project authors. All rights reserved. 1 // Copyright 2007-2009 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 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 424
425 425
426 THREADED_TEST(ScriptMakingExternalString) { 426 THREADED_TEST(ScriptMakingExternalString) {
427 TestResource::dispose_count = 0; 427 TestResource::dispose_count = 0;
428 uint16_t* two_byte_source = AsciiToTwoByteString("1 + 2 * 3"); 428 uint16_t* two_byte_source = AsciiToTwoByteString("1 + 2 * 3");
429 { 429 {
430 v8::HandleScope scope; 430 v8::HandleScope scope;
431 LocalContext env; 431 LocalContext env;
432 Local<String> source = String::New(two_byte_source); 432 Local<String> source = String::New(two_byte_source);
433 // Trigger GCs so that the newly allocated string moves to old gen. 433 // Trigger GCs so that the newly allocated string moves to old gen.
434 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in survivor space now 434 i::Heap::CollectGarbage(i::NEW_SPACE); // in survivor space now
435 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in old gen now 435 i::Heap::CollectGarbage(i::NEW_SPACE); // in old gen now
436 bool success = source->MakeExternal(new TestResource(two_byte_source)); 436 bool success = source->MakeExternal(new TestResource(two_byte_source));
437 CHECK(success); 437 CHECK(success);
438 Local<Script> script = Script::Compile(source); 438 Local<Script> script = Script::Compile(source);
439 Local<Value> value = script->Run(); 439 Local<Value> value = script->Run();
440 CHECK(value->IsNumber()); 440 CHECK(value->IsNumber());
441 CHECK_EQ(7, value->Int32Value()); 441 CHECK_EQ(7, value->Int32Value());
442 i::Heap::CollectAllGarbage(false); 442 i::Heap::CollectAllGarbage(false);
443 CHECK_EQ(0, TestResource::dispose_count); 443 CHECK_EQ(0, TestResource::dispose_count);
444 } 444 }
445 i::CompilationCache::Clear(); 445 i::CompilationCache::Clear();
446 i::Heap::CollectAllGarbage(false); 446 i::Heap::CollectAllGarbage(false);
447 CHECK_EQ(1, TestResource::dispose_count); 447 CHECK_EQ(1, TestResource::dispose_count);
448 } 448 }
449 449
450 450
451 THREADED_TEST(ScriptMakingExternalAsciiString) { 451 THREADED_TEST(ScriptMakingExternalAsciiString) {
452 TestAsciiResource::dispose_count = 0; 452 TestAsciiResource::dispose_count = 0;
453 const char* c_source = "1 + 2 * 3"; 453 const char* c_source = "1 + 2 * 3";
454 { 454 {
455 v8::HandleScope scope; 455 v8::HandleScope scope;
456 LocalContext env; 456 LocalContext env;
457 Local<String> source = v8_str(c_source); 457 Local<String> source = v8_str(c_source);
458 // Trigger GCs so that the newly allocated string moves to old gen. 458 // Trigger GCs so that the newly allocated string moves to old gen.
459 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in survivor space now 459 i::Heap::CollectGarbage(i::NEW_SPACE); // in survivor space now
460 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in old gen now 460 i::Heap::CollectGarbage(i::NEW_SPACE); // in old gen now
461 bool success = source->MakeExternal( 461 bool success = source->MakeExternal(
462 new TestAsciiResource(i::StrDup(c_source))); 462 new TestAsciiResource(i::StrDup(c_source)));
463 CHECK(success); 463 CHECK(success);
464 Local<Script> script = Script::Compile(source); 464 Local<Script> script = Script::Compile(source);
465 Local<Value> value = script->Run(); 465 Local<Value> value = script->Run();
466 CHECK(value->IsNumber()); 466 CHECK(value->IsNumber());
467 CHECK_EQ(7, value->Int32Value()); 467 CHECK_EQ(7, value->Int32Value());
468 i::Heap::CollectAllGarbage(false); 468 i::Heap::CollectAllGarbage(false);
469 CHECK_EQ(0, TestAsciiResource::dispose_count); 469 CHECK_EQ(0, TestAsciiResource::dispose_count);
470 } 470 }
471 i::CompilationCache::Clear(); 471 i::CompilationCache::Clear();
472 i::Heap::CollectAllGarbage(false); 472 i::Heap::CollectAllGarbage(false);
473 CHECK_EQ(1, TestAsciiResource::dispose_count); 473 CHECK_EQ(1, TestAsciiResource::dispose_count);
474 } 474 }
475 475
476 476
477 TEST(MakingExternalStringConditions) { 477 TEST(MakingExternalStringConditions) {
478 v8::HandleScope scope; 478 v8::HandleScope scope;
479 LocalContext env; 479 LocalContext env;
480 480
481 // Free some space in the new space so that we can check freshness. 481 // Free some space in the new space so that we can check freshness.
482 i::Heap::CollectGarbage(0, i::NEW_SPACE); 482 i::Heap::CollectGarbage(i::NEW_SPACE);
483 i::Heap::CollectGarbage(0, i::NEW_SPACE); 483 i::Heap::CollectGarbage(i::NEW_SPACE);
484 484
485 uint16_t* two_byte_string = AsciiToTwoByteString("small"); 485 uint16_t* two_byte_string = AsciiToTwoByteString("small");
486 Local<String> small_string = String::New(two_byte_string); 486 Local<String> small_string = String::New(two_byte_string);
487 i::DeleteArray(two_byte_string); 487 i::DeleteArray(two_byte_string);
488 488
489 // We should refuse to externalize newly created small string. 489 // We should refuse to externalize newly created small string.
490 CHECK(!small_string->CanMakeExternal()); 490 CHECK(!small_string->CanMakeExternal());
491 // Trigger GCs so that the newly allocated string moves to old gen. 491 // Trigger GCs so that the newly allocated string moves to old gen.
492 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in survivor space now 492 i::Heap::CollectGarbage(i::NEW_SPACE); // in survivor space now
493 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in old gen now 493 i::Heap::CollectGarbage(i::NEW_SPACE); // in old gen now
494 // Old space strings should be accepted. 494 // Old space strings should be accepted.
495 CHECK(small_string->CanMakeExternal()); 495 CHECK(small_string->CanMakeExternal());
496 496
497 two_byte_string = AsciiToTwoByteString("small 2"); 497 two_byte_string = AsciiToTwoByteString("small 2");
498 small_string = String::New(two_byte_string); 498 small_string = String::New(two_byte_string);
499 i::DeleteArray(two_byte_string); 499 i::DeleteArray(two_byte_string);
500 500
501 // We should refuse externalizing newly created small string. 501 // We should refuse externalizing newly created small string.
502 CHECK(!small_string->CanMakeExternal()); 502 CHECK(!small_string->CanMakeExternal());
503 for (int i = 0; i < 100; i++) { 503 for (int i = 0; i < 100; i++) {
(...skipping 14 matching lines...) Expand all
518 // Large strings should be immediately accepted. 518 // Large strings should be immediately accepted.
519 CHECK(large_string->CanMakeExternal()); 519 CHECK(large_string->CanMakeExternal());
520 } 520 }
521 521
522 522
523 TEST(MakingExternalAsciiStringConditions) { 523 TEST(MakingExternalAsciiStringConditions) {
524 v8::HandleScope scope; 524 v8::HandleScope scope;
525 LocalContext env; 525 LocalContext env;
526 526
527 // Free some space in the new space so that we can check freshness. 527 // Free some space in the new space so that we can check freshness.
528 i::Heap::CollectGarbage(0, i::NEW_SPACE); 528 i::Heap::CollectGarbage(i::NEW_SPACE);
529 i::Heap::CollectGarbage(0, i::NEW_SPACE); 529 i::Heap::CollectGarbage(i::NEW_SPACE);
530 530
531 Local<String> small_string = String::New("small"); 531 Local<String> small_string = String::New("small");
532 // We should refuse to externalize newly created small string. 532 // We should refuse to externalize newly created small string.
533 CHECK(!small_string->CanMakeExternal()); 533 CHECK(!small_string->CanMakeExternal());
534 // Trigger GCs so that the newly allocated string moves to old gen. 534 // Trigger GCs so that the newly allocated string moves to old gen.
535 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in survivor space now 535 i::Heap::CollectGarbage(i::NEW_SPACE); // in survivor space now
536 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in old gen now 536 i::Heap::CollectGarbage(i::NEW_SPACE); // in old gen now
537 // Old space strings should be accepted. 537 // Old space strings should be accepted.
538 CHECK(small_string->CanMakeExternal()); 538 CHECK(small_string->CanMakeExternal());
539 539
540 small_string = String::New("small 2"); 540 small_string = String::New("small 2");
541 // We should refuse externalizing newly created small string. 541 // We should refuse externalizing newly created small string.
542 CHECK(!small_string->CanMakeExternal()); 542 CHECK(!small_string->CanMakeExternal());
543 for (int i = 0; i < 100; i++) { 543 for (int i = 0; i < 100; i++) {
544 String::Value value(small_string); 544 String::Value value(small_string);
545 } 545 }
546 // Frequently used strings should be accepted. 546 // Frequently used strings should be accepted.
(...skipping 11 matching lines...) Expand all
558 558
559 559
560 THREADED_TEST(UsingExternalString) { 560 THREADED_TEST(UsingExternalString) {
561 { 561 {
562 v8::HandleScope scope; 562 v8::HandleScope scope;
563 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); 563 uint16_t* two_byte_string = AsciiToTwoByteString("test string");
564 Local<String> string = 564 Local<String> string =
565 String::NewExternal(new TestResource(two_byte_string)); 565 String::NewExternal(new TestResource(two_byte_string));
566 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); 566 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string);
567 // Trigger GCs so that the newly allocated string moves to old gen. 567 // Trigger GCs so that the newly allocated string moves to old gen.
568 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in survivor space now 568 i::Heap::CollectGarbage(i::NEW_SPACE); // in survivor space now
569 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in old gen now 569 i::Heap::CollectGarbage(i::NEW_SPACE); // in old gen now
570 i::Handle<i::String> isymbol = i::Factory::SymbolFromString(istring); 570 i::Handle<i::String> isymbol = i::Factory::SymbolFromString(istring);
571 CHECK(isymbol->IsSymbol()); 571 CHECK(isymbol->IsSymbol());
572 } 572 }
573 i::Heap::CollectAllGarbage(false); 573 i::Heap::CollectAllGarbage(false);
574 i::Heap::CollectAllGarbage(false); 574 i::Heap::CollectAllGarbage(false);
575 } 575 }
576 576
577 577
578 THREADED_TEST(UsingExternalAsciiString) { 578 THREADED_TEST(UsingExternalAsciiString) {
579 { 579 {
580 v8::HandleScope scope; 580 v8::HandleScope scope;
581 const char* one_byte_string = "test string"; 581 const char* one_byte_string = "test string";
582 Local<String> string = String::NewExternal( 582 Local<String> string = String::NewExternal(
583 new TestAsciiResource(i::StrDup(one_byte_string))); 583 new TestAsciiResource(i::StrDup(one_byte_string)));
584 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); 584 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string);
585 // Trigger GCs so that the newly allocated string moves to old gen. 585 // Trigger GCs so that the newly allocated string moves to old gen.
586 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in survivor space now 586 i::Heap::CollectGarbage(i::NEW_SPACE); // in survivor space now
587 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in old gen now 587 i::Heap::CollectGarbage(i::NEW_SPACE); // in old gen now
588 i::Handle<i::String> isymbol = i::Factory::SymbolFromString(istring); 588 i::Handle<i::String> isymbol = i::Factory::SymbolFromString(istring);
589 CHECK(isymbol->IsSymbol()); 589 CHECK(isymbol->IsSymbol());
590 } 590 }
591 i::Heap::CollectAllGarbage(false); 591 i::Heap::CollectAllGarbage(false);
592 i::Heap::CollectAllGarbage(false); 592 i::Heap::CollectAllGarbage(false);
593 } 593 }
594 594
595 595
596 THREADED_TEST(ScavengeExternalString) { 596 THREADED_TEST(ScavengeExternalString) {
597 TestResource::dispose_count = 0; 597 TestResource::dispose_count = 0;
598 bool in_new_space = false; 598 bool in_new_space = false;
599 { 599 {
600 v8::HandleScope scope; 600 v8::HandleScope scope;
601 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); 601 uint16_t* two_byte_string = AsciiToTwoByteString("test string");
602 Local<String> string = 602 Local<String> string =
603 String::NewExternal(new TestResource(two_byte_string)); 603 String::NewExternal(new TestResource(two_byte_string));
604 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); 604 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string);
605 i::Heap::CollectGarbage(0, i::NEW_SPACE); 605 i::Heap::CollectGarbage(i::NEW_SPACE);
606 in_new_space = i::Heap::InNewSpace(*istring); 606 in_new_space = i::Heap::InNewSpace(*istring);
607 CHECK(in_new_space || i::Heap::old_data_space()->Contains(*istring)); 607 CHECK(in_new_space || i::Heap::old_data_space()->Contains(*istring));
608 CHECK_EQ(0, TestResource::dispose_count); 608 CHECK_EQ(0, TestResource::dispose_count);
609 } 609 }
610 i::Heap::CollectGarbage(0, in_new_space ? i::NEW_SPACE : i::OLD_DATA_SPACE); 610 i::Heap::CollectGarbage(in_new_space ? i::NEW_SPACE : i::OLD_DATA_SPACE);
611 CHECK_EQ(1, TestResource::dispose_count); 611 CHECK_EQ(1, TestResource::dispose_count);
612 } 612 }
613 613
614 614
615 THREADED_TEST(ScavengeExternalAsciiString) { 615 THREADED_TEST(ScavengeExternalAsciiString) {
616 TestAsciiResource::dispose_count = 0; 616 TestAsciiResource::dispose_count = 0;
617 bool in_new_space = false; 617 bool in_new_space = false;
618 { 618 {
619 v8::HandleScope scope; 619 v8::HandleScope scope;
620 const char* one_byte_string = "test string"; 620 const char* one_byte_string = "test string";
621 Local<String> string = String::NewExternal( 621 Local<String> string = String::NewExternal(
622 new TestAsciiResource(i::StrDup(one_byte_string))); 622 new TestAsciiResource(i::StrDup(one_byte_string)));
623 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); 623 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string);
624 i::Heap::CollectGarbage(0, i::NEW_SPACE); 624 i::Heap::CollectGarbage(i::NEW_SPACE);
625 in_new_space = i::Heap::InNewSpace(*istring); 625 in_new_space = i::Heap::InNewSpace(*istring);
626 CHECK(in_new_space || i::Heap::old_data_space()->Contains(*istring)); 626 CHECK(in_new_space || i::Heap::old_data_space()->Contains(*istring));
627 CHECK_EQ(0, TestAsciiResource::dispose_count); 627 CHECK_EQ(0, TestAsciiResource::dispose_count);
628 } 628 }
629 i::Heap::CollectGarbage(0, in_new_space ? i::NEW_SPACE : i::OLD_DATA_SPACE); 629 i::Heap::CollectGarbage(in_new_space ? i::NEW_SPACE : i::OLD_DATA_SPACE);
630 CHECK_EQ(1, TestAsciiResource::dispose_count); 630 CHECK_EQ(1, TestAsciiResource::dispose_count);
631 } 631 }
632 632
633 633
634 class TestAsciiResourceWithDisposeControl: public TestAsciiResource { 634 class TestAsciiResourceWithDisposeControl: public TestAsciiResource {
635 public: 635 public:
636 static int dispose_calls; 636 static int dispose_calls;
637 637
638 TestAsciiResourceWithDisposeControl(const char* data, bool dispose) 638 TestAsciiResourceWithDisposeControl(const char* data, bool dispose)
639 : TestAsciiResource(data), 639 : TestAsciiResource(data),
(...skipping 11108 matching lines...) Expand 10 before | Expand all | Expand 10 after
11748 v8::Context::Scope context_scope(context.local()); 11748 v8::Context::Scope context_scope(context.local());
11749 11749
11750 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(); 11750 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New();
11751 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); 11751 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator);
11752 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); 11752 context->Global()->Set(v8_str("o"), tmpl->NewInstance());
11753 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( 11753 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun(
11754 "var result = []; for (var k in o) result.push(k); result")); 11754 "var result = []; for (var k in o) result.push(k); result"));
11755 CHECK_EQ(1, result->Length()); 11755 CHECK_EQ(1, result->Length());
11756 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); 11756 CHECK_EQ(v8_str("universalAnswer"), result->Get(0));
11757 } 11757 }
OLDNEW
« no previous file with comments | « test/cctest/test-alloc.cc ('k') | test/cctest/test-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698