| OLD | NEW |
| 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 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 i::Heap::CollectGarbage(0, i::NEW_SPACE); | 605 i::Heap::CollectGarbage(0, 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, TestAsciiResource::dispose_count); | 608 CHECK_EQ(0, TestAsciiResource::dispose_count); |
| 609 } | 609 } |
| 610 i::Heap::CollectGarbage(0, in_new_space ? i::NEW_SPACE : i::OLD_DATA_SPACE); | 610 i::Heap::CollectGarbage(0, in_new_space ? i::NEW_SPACE : i::OLD_DATA_SPACE); |
| 611 CHECK_EQ(1, TestAsciiResource::dispose_count); | 611 CHECK_EQ(1, TestAsciiResource::dispose_count); |
| 612 } | 612 } |
| 613 | 613 |
| 614 | 614 |
| 615 static int dispose_count = 0; | 615 class TestAsciiResourceWithDisposeControl: public TestAsciiResource { |
| 616 static void DisposeExternalStringCount( | 616 public: |
| 617 String::ExternalStringResourceBase* resource) { | 617 static int dispose_calls; |
| 618 dispose_count++; | 618 |
| 619 } | 619 TestAsciiResourceWithDisposeControl(const char* data, bool dispose) |
| 620 : TestAsciiResource(data), |
| 621 dispose_(dispose) { } |
| 622 |
| 623 void Dispose() { |
| 624 ++dispose_calls; |
| 625 if (dispose_) delete this; |
| 626 } |
| 627 private: |
| 628 bool dispose_; |
| 629 }; |
| 620 | 630 |
| 621 | 631 |
| 622 static void DisposeExternalStringDeleteAndCount( | 632 int TestAsciiResourceWithDisposeControl::dispose_calls = 0; |
| 623 String::ExternalStringResourceBase* resource) { | |
| 624 delete resource; | |
| 625 dispose_count++; | |
| 626 } | |
| 627 | 633 |
| 628 | 634 |
| 629 TEST(ExternalStringWithResourceDisposeCallback) { | 635 TEST(ExternalStringWithDisposeHandling) { |
| 630 const char* c_source = "1 + 2 * 3"; | 636 const char* c_source = "1 + 2 * 3"; |
| 631 | 637 |
| 632 // Set an external string collected callback which does not delete the object. | |
| 633 v8::V8::SetExternalStringDiposeCallback(DisposeExternalStringCount); | |
| 634 | |
| 635 // Use a stack allocated external string resource allocated object. | 638 // Use a stack allocated external string resource allocated object. |
| 636 dispose_count = 0; | |
| 637 TestAsciiResource::dispose_count = 0; | 639 TestAsciiResource::dispose_count = 0; |
| 638 TestAsciiResource res_stack(i::StrDup(c_source)); | 640 TestAsciiResourceWithDisposeControl::dispose_calls = 0; |
| 641 TestAsciiResourceWithDisposeControl res_stack(i::StrDup(c_source), false); |
| 639 { | 642 { |
| 640 v8::HandleScope scope; | 643 v8::HandleScope scope; |
| 641 LocalContext env; | 644 LocalContext env; |
| 642 Local<String> source = String::NewExternal(&res_stack); | 645 Local<String> source = String::NewExternal(&res_stack); |
| 643 Local<Script> script = Script::Compile(source); | 646 Local<Script> script = Script::Compile(source); |
| 644 Local<Value> value = script->Run(); | 647 Local<Value> value = script->Run(); |
| 645 CHECK(value->IsNumber()); | 648 CHECK(value->IsNumber()); |
| 646 CHECK_EQ(7, value->Int32Value()); | 649 CHECK_EQ(7, value->Int32Value()); |
| 647 v8::internal::Heap::CollectAllGarbage(false); | 650 v8::internal::Heap::CollectAllGarbage(false); |
| 648 CHECK_EQ(0, TestAsciiResource::dispose_count); | 651 CHECK_EQ(0, TestAsciiResource::dispose_count); |
| 649 } | 652 } |
| 650 v8::internal::CompilationCache::Clear(); | 653 v8::internal::CompilationCache::Clear(); |
| 651 v8::internal::Heap::CollectAllGarbage(false); | 654 v8::internal::Heap::CollectAllGarbage(false); |
| 652 CHECK_EQ(1, dispose_count); | 655 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_calls); |
| 653 CHECK_EQ(0, TestAsciiResource::dispose_count); | 656 CHECK_EQ(0, TestAsciiResource::dispose_count); |
| 654 | 657 |
| 655 // Set an external string collected callback which does delete the object. | |
| 656 v8::V8::SetExternalStringDiposeCallback(DisposeExternalStringDeleteAndCount); | |
| 657 | |
| 658 // Use a heap allocated external string resource allocated object. | 658 // Use a heap allocated external string resource allocated object. |
| 659 dispose_count = 0; | |
| 660 TestAsciiResource::dispose_count = 0; | 659 TestAsciiResource::dispose_count = 0; |
| 661 TestAsciiResource* res_heap = new TestAsciiResource(i::StrDup(c_source)); | 660 TestAsciiResourceWithDisposeControl::dispose_calls = 0; |
| 661 TestAsciiResource* res_heap = |
| 662 new TestAsciiResourceWithDisposeControl(i::StrDup(c_source), true); |
| 662 { | 663 { |
| 663 v8::HandleScope scope; | 664 v8::HandleScope scope; |
| 664 LocalContext env; | 665 LocalContext env; |
| 665 Local<String> source = String::NewExternal(res_heap); | 666 Local<String> source = String::NewExternal(res_heap); |
| 666 Local<Script> script = Script::Compile(source); | 667 Local<Script> script = Script::Compile(source); |
| 667 Local<Value> value = script->Run(); | 668 Local<Value> value = script->Run(); |
| 668 CHECK(value->IsNumber()); | 669 CHECK(value->IsNumber()); |
| 669 CHECK_EQ(7, value->Int32Value()); | 670 CHECK_EQ(7, value->Int32Value()); |
| 670 v8::internal::Heap::CollectAllGarbage(false); | 671 v8::internal::Heap::CollectAllGarbage(false); |
| 671 CHECK_EQ(0, TestAsciiResource::dispose_count); | 672 CHECK_EQ(0, TestAsciiResource::dispose_count); |
| 672 } | 673 } |
| 673 v8::internal::CompilationCache::Clear(); | 674 v8::internal::CompilationCache::Clear(); |
| 674 v8::internal::Heap::CollectAllGarbage(false); | 675 v8::internal::Heap::CollectAllGarbage(false); |
| 675 CHECK_EQ(1, dispose_count); | 676 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_calls); |
| 676 CHECK_EQ(1, TestAsciiResource::dispose_count); | 677 CHECK_EQ(1, TestAsciiResource::dispose_count); |
| 677 } | 678 } |
| 678 | 679 |
| 679 | 680 |
| 680 THREADED_TEST(StringConcat) { | 681 THREADED_TEST(StringConcat) { |
| 681 { | 682 { |
| 682 v8::HandleScope scope; | 683 v8::HandleScope scope; |
| 683 LocalContext env; | 684 LocalContext env; |
| 684 const char* one_byte_string_1 = "function a_times_t"; | 685 const char* one_byte_string_1 = "function a_times_t"; |
| 685 const char* two_byte_string_1 = "wo_plus_b(a, b) {return "; | 686 const char* two_byte_string_1 = "wo_plus_b(a, b) {return "; |
| (...skipping 10157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10843 const char* code = | 10844 const char* code = |
| 10844 "(function() {" | 10845 "(function() {" |
| 10845 " for (var i = 0; i < 2*16; i++) {" | 10846 " for (var i = 0; i < 2*16; i++) {" |
| 10846 " %_GetFromCache(0, 'a' + i);" | 10847 " %_GetFromCache(0, 'a' + i);" |
| 10847 " };" | 10848 " };" |
| 10848 " return 'PASSED';" | 10849 " return 'PASSED';" |
| 10849 "})()"; | 10850 "})()"; |
| 10850 v8::internal::Heap::ClearJSFunctionResultCaches(); | 10851 v8::internal::Heap::ClearJSFunctionResultCaches(); |
| 10851 ExpectString(code, "PASSED"); | 10852 ExpectString(code, "PASSED"); |
| 10852 } | 10853 } |
| OLD | NEW |