| 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; |
| 616 static void DisposeExternalStringCount( |
| 617 String::ExternalStringResourceBase* resource) { |
| 618 dispose_count++; |
| 619 } |
| 620 |
| 621 |
| 622 static void DisposeExternalStringDeleteAndCount( |
| 623 String::ExternalStringResourceBase* resource) { |
| 624 delete resource; |
| 625 dispose_count++; |
| 626 } |
| 627 |
| 628 |
| 629 TEST(ExternalStringWithResourceDisposeCallback) { |
| 630 const char* c_source = "1 + 2 * 3"; |
| 631 |
| 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. |
| 636 dispose_count = 0; |
| 637 TestAsciiResource::dispose_count = 0; |
| 638 TestAsciiResource res_stack(i::StrDup(c_source)); |
| 639 { |
| 640 v8::HandleScope scope; |
| 641 LocalContext env; |
| 642 Local<String> source = String::NewExternal(&res_stack); |
| 643 Local<Script> script = Script::Compile(source); |
| 644 Local<Value> value = script->Run(); |
| 645 CHECK(value->IsNumber()); |
| 646 CHECK_EQ(7, value->Int32Value()); |
| 647 v8::internal::Heap::CollectAllGarbage(false); |
| 648 CHECK_EQ(0, TestAsciiResource::dispose_count); |
| 649 } |
| 650 v8::internal::CompilationCache::Clear(); |
| 651 v8::internal::Heap::CollectAllGarbage(false); |
| 652 CHECK_EQ(1, dispose_count); |
| 653 CHECK_EQ(0, TestAsciiResource::dispose_count); |
| 654 |
| 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. |
| 659 dispose_count = 0; |
| 660 TestAsciiResource::dispose_count = 0; |
| 661 TestAsciiResource* res_heap = new TestAsciiResource(i::StrDup(c_source)); |
| 662 { |
| 663 v8::HandleScope scope; |
| 664 LocalContext env; |
| 665 Local<String> source = String::NewExternal(res_heap); |
| 666 Local<Script> script = Script::Compile(source); |
| 667 Local<Value> value = script->Run(); |
| 668 CHECK(value->IsNumber()); |
| 669 CHECK_EQ(7, value->Int32Value()); |
| 670 v8::internal::Heap::CollectAllGarbage(false); |
| 671 CHECK_EQ(0, TestAsciiResource::dispose_count); |
| 672 } |
| 673 v8::internal::CompilationCache::Clear(); |
| 674 v8::internal::Heap::CollectAllGarbage(false); |
| 675 CHECK_EQ(1, dispose_count); |
| 676 CHECK_EQ(1, TestAsciiResource::dispose_count); |
| 677 } |
| 678 |
| 679 |
| 615 THREADED_TEST(StringConcat) { | 680 THREADED_TEST(StringConcat) { |
| 616 { | 681 { |
| 617 v8::HandleScope scope; | 682 v8::HandleScope scope; |
| 618 LocalContext env; | 683 LocalContext env; |
| 619 const char* one_byte_string_1 = "function a_times_t"; | 684 const char* one_byte_string_1 = "function a_times_t"; |
| 620 const char* two_byte_string_1 = "wo_plus_b(a, b) {return "; | 685 const char* two_byte_string_1 = "wo_plus_b(a, b) {return "; |
| 621 const char* one_byte_extern_1 = "a * 2 + b;} a_times_two_plus_b(4, 8) + "; | 686 const char* one_byte_extern_1 = "a * 2 + b;} a_times_two_plus_b(4, 8) + "; |
| 622 const char* two_byte_extern_1 = "a_times_two_plus_b(4, 8) + "; | 687 const char* two_byte_extern_1 = "a_times_two_plus_b(4, 8) + "; |
| 623 const char* one_byte_string_2 = "a_times_two_plus_b(4, 8) + "; | 688 const char* one_byte_string_2 = "a_times_two_plus_b(4, 8) + "; |
| 624 const char* two_byte_string_2 = "a_times_two_plus_b(4, 8) + "; | 689 const char* two_byte_string_2 = "a_times_two_plus_b(4, 8) + "; |
| (...skipping 9996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10621 const char* code = | 10686 const char* code = |
| 10622 "(function() {" | 10687 "(function() {" |
| 10623 " for (var i = 0; i < 2*16; i++) {" | 10688 " for (var i = 0; i < 2*16; i++) {" |
| 10624 " %_GetFromCache(0, 'a' + i);" | 10689 " %_GetFromCache(0, 'a' + i);" |
| 10625 " };" | 10690 " };" |
| 10626 " return 'PASSED';" | 10691 " return 'PASSED';" |
| 10627 "})()"; | 10692 "})()"; |
| 10628 v8::internal::Heap::ClearJSFunctionResultCaches(); | 10693 v8::internal::Heap::ClearJSFunctionResultCaches(); |
| 10629 ExpectString(code, "PASSED"); | 10694 ExpectString(code, "PASSED"); |
| 10630 } | 10695 } |
| OLD | NEW |