OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 CompileRun("function cons(a, b) { return a + b; }" | 600 CompileRun("function cons(a, b) { return a + b; }" |
601 "function slice(a) { return a.substring(1); }"); | 601 "function slice(a) { return a.substring(1); }"); |
602 // Create a cons string that will land in old pointer space. | 602 // Create a cons string that will land in old pointer space. |
603 Local<String> cons = Local<String>::Cast(CompileRun( | 603 Local<String> cons = Local<String>::Cast(CompileRun( |
604 "cons('abcdefghijklm', 'nopqrstuvwxyz');")); | 604 "cons('abcdefghijklm', 'nopqrstuvwxyz');")); |
605 // Create a sliced string that will land in old pointer space. | 605 // Create a sliced string that will land in old pointer space. |
606 Local<String> slice = Local<String>::Cast(CompileRun( | 606 Local<String> slice = Local<String>::Cast(CompileRun( |
607 "slice('abcdefghijklmnopqrstuvwxyz');")); | 607 "slice('abcdefghijklmnopqrstuvwxyz');")); |
608 | 608 |
609 // Trigger GCs so that the newly allocated string moves to old gen. | 609 // Trigger GCs so that the newly allocated string moves to old gen. |
610 SimulateFullSpace(CcTest::heap()->old_pointer_space()); | 610 SimulateFullSpace(CcTest::heap()->old_space()); |
611 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now | 611 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now |
612 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now | 612 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now |
613 | 613 |
614 // Turn into external string with unaligned resource data. | 614 // Turn into external string with unaligned resource data. |
615 const char* c_cons = "_abcdefghijklmnopqrstuvwxyz"; | 615 const char* c_cons = "_abcdefghijklmnopqrstuvwxyz"; |
616 bool success = | 616 bool success = |
617 cons->MakeExternal(new TestOneByteResource(i::StrDup(c_cons), NULL, 1)); | 617 cons->MakeExternal(new TestOneByteResource(i::StrDup(c_cons), NULL, 1)); |
618 CHECK(success); | 618 CHECK(success); |
619 const char* c_slice = "_bcdefghijklmnopqrstuvwxyz"; | 619 const char* c_slice = "_bcdefghijklmnopqrstuvwxyz"; |
620 success = | 620 success = |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 int dispose_count = 0; | 720 int dispose_count = 0; |
721 bool in_new_space = false; | 721 bool in_new_space = false; |
722 { | 722 { |
723 v8::HandleScope scope(CcTest::isolate()); | 723 v8::HandleScope scope(CcTest::isolate()); |
724 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); | 724 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); |
725 Local<String> string = String::NewExternal( | 725 Local<String> string = String::NewExternal( |
726 CcTest::isolate(), new TestResource(two_byte_string, &dispose_count)); | 726 CcTest::isolate(), new TestResource(two_byte_string, &dispose_count)); |
727 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); | 727 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); |
728 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 728 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
729 in_new_space = CcTest::heap()->InNewSpace(*istring); | 729 in_new_space = CcTest::heap()->InNewSpace(*istring); |
730 CHECK(in_new_space || CcTest::heap()->old_data_space()->Contains(*istring)); | 730 CHECK(in_new_space || CcTest::heap()->old_space()->Contains(*istring)); |
731 CHECK_EQ(0, dispose_count); | 731 CHECK_EQ(0, dispose_count); |
732 } | 732 } |
733 CcTest::heap()->CollectGarbage(in_new_space ? i::NEW_SPACE | 733 CcTest::heap()->CollectGarbage(in_new_space ? i::NEW_SPACE : i::OLD_SPACE); |
734 : i::OLD_DATA_SPACE); | |
735 CHECK_EQ(1, dispose_count); | 734 CHECK_EQ(1, dispose_count); |
736 } | 735 } |
737 | 736 |
738 | 737 |
739 THREADED_TEST(ScavengeExternalOneByteString) { | 738 THREADED_TEST(ScavengeExternalOneByteString) { |
740 i::FLAG_stress_compaction = false; | 739 i::FLAG_stress_compaction = false; |
741 i::FLAG_gc_global = false; | 740 i::FLAG_gc_global = false; |
742 int dispose_count = 0; | 741 int dispose_count = 0; |
743 bool in_new_space = false; | 742 bool in_new_space = false; |
744 { | 743 { |
745 v8::HandleScope scope(CcTest::isolate()); | 744 v8::HandleScope scope(CcTest::isolate()); |
746 const char* one_byte_string = "test string"; | 745 const char* one_byte_string = "test string"; |
747 Local<String> string = String::NewExternal( | 746 Local<String> string = String::NewExternal( |
748 CcTest::isolate(), | 747 CcTest::isolate(), |
749 new TestOneByteResource(i::StrDup(one_byte_string), &dispose_count)); | 748 new TestOneByteResource(i::StrDup(one_byte_string), &dispose_count)); |
750 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); | 749 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); |
751 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 750 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
752 in_new_space = CcTest::heap()->InNewSpace(*istring); | 751 in_new_space = CcTest::heap()->InNewSpace(*istring); |
753 CHECK(in_new_space || CcTest::heap()->old_data_space()->Contains(*istring)); | 752 CHECK(in_new_space || CcTest::heap()->old_space()->Contains(*istring)); |
754 CHECK_EQ(0, dispose_count); | 753 CHECK_EQ(0, dispose_count); |
755 } | 754 } |
756 CcTest::heap()->CollectGarbage(in_new_space ? i::NEW_SPACE | 755 CcTest::heap()->CollectGarbage(in_new_space ? i::NEW_SPACE : i::OLD_SPACE); |
757 : i::OLD_DATA_SPACE); | |
758 CHECK_EQ(1, dispose_count); | 756 CHECK_EQ(1, dispose_count); |
759 } | 757 } |
760 | 758 |
761 | 759 |
762 class TestOneByteResourceWithDisposeControl : public TestOneByteResource { | 760 class TestOneByteResourceWithDisposeControl : public TestOneByteResource { |
763 public: | 761 public: |
764 // Only used by non-threaded tests, so it can use static fields. | 762 // Only used by non-threaded tests, so it can use static fields. |
765 static int dispose_calls; | 763 static int dispose_calls; |
766 static int dispose_count; | 764 static int dispose_count; |
767 | 765 |
(...skipping 15369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16137 | 16135 |
16138 | 16136 |
16139 TEST(ExternalizeOldSpaceTwoByteCons) { | 16137 TEST(ExternalizeOldSpaceTwoByteCons) { |
16140 v8::Isolate* isolate = CcTest::isolate(); | 16138 v8::Isolate* isolate = CcTest::isolate(); |
16141 LocalContext env; | 16139 LocalContext env; |
16142 v8::HandleScope scope(isolate); | 16140 v8::HandleScope scope(isolate); |
16143 v8::Local<v8::String> cons = | 16141 v8::Local<v8::String> cons = |
16144 CompileRun("'Romeo Montague ' + 'Juliet Capulet'")->ToString(isolate); | 16142 CompileRun("'Romeo Montague ' + 'Juliet Capulet'")->ToString(isolate); |
16145 CHECK(v8::Utils::OpenHandle(*cons)->IsConsString()); | 16143 CHECK(v8::Utils::OpenHandle(*cons)->IsConsString()); |
16146 CcTest::heap()->CollectAllAvailableGarbage(); | 16144 CcTest::heap()->CollectAllAvailableGarbage(); |
16147 CHECK(CcTest::heap()->old_pointer_space()->Contains( | 16145 CHECK(CcTest::heap()->old_space()->Contains(*v8::Utils::OpenHandle(*cons))); |
16148 *v8::Utils::OpenHandle(*cons))); | |
16149 | 16146 |
16150 TestResource* resource = new TestResource( | 16147 TestResource* resource = new TestResource( |
16151 AsciiToTwoByteString("Romeo Montague Juliet Capulet")); | 16148 AsciiToTwoByteString("Romeo Montague Juliet Capulet")); |
16152 cons->MakeExternal(resource); | 16149 cons->MakeExternal(resource); |
16153 | 16150 |
16154 CHECK(cons->IsExternal()); | 16151 CHECK(cons->IsExternal()); |
16155 CHECK_EQ(resource, cons->GetExternalStringResource()); | 16152 CHECK_EQ(resource, cons->GetExternalStringResource()); |
16156 String::Encoding encoding; | 16153 String::Encoding encoding; |
16157 CHECK_EQ(resource, cons->GetExternalStringResourceBase(&encoding)); | 16154 CHECK_EQ(resource, cons->GetExternalStringResourceBase(&encoding)); |
16158 CHECK_EQ(String::TWO_BYTE_ENCODING, encoding); | 16155 CHECK_EQ(String::TWO_BYTE_ENCODING, encoding); |
16159 } | 16156 } |
16160 | 16157 |
16161 | 16158 |
16162 TEST(ExternalizeOldSpaceOneByteCons) { | 16159 TEST(ExternalizeOldSpaceOneByteCons) { |
16163 v8::Isolate* isolate = CcTest::isolate(); | 16160 v8::Isolate* isolate = CcTest::isolate(); |
16164 LocalContext env; | 16161 LocalContext env; |
16165 v8::HandleScope scope(isolate); | 16162 v8::HandleScope scope(isolate); |
16166 v8::Local<v8::String> cons = | 16163 v8::Local<v8::String> cons = |
16167 CompileRun("'Romeo Montague ' + 'Juliet Capulet'")->ToString(isolate); | 16164 CompileRun("'Romeo Montague ' + 'Juliet Capulet'")->ToString(isolate); |
16168 CHECK(v8::Utils::OpenHandle(*cons)->IsConsString()); | 16165 CHECK(v8::Utils::OpenHandle(*cons)->IsConsString()); |
16169 CcTest::heap()->CollectAllAvailableGarbage(); | 16166 CcTest::heap()->CollectAllAvailableGarbage(); |
16170 CHECK(CcTest::heap()->old_pointer_space()->Contains( | 16167 CHECK(CcTest::heap()->old_space()->Contains(*v8::Utils::OpenHandle(*cons))); |
16171 *v8::Utils::OpenHandle(*cons))); | |
16172 | 16168 |
16173 TestOneByteResource* resource = | 16169 TestOneByteResource* resource = |
16174 new TestOneByteResource(i::StrDup("Romeo Montague Juliet Capulet")); | 16170 new TestOneByteResource(i::StrDup("Romeo Montague Juliet Capulet")); |
16175 cons->MakeExternal(resource); | 16171 cons->MakeExternal(resource); |
16176 | 16172 |
16177 CHECK(cons->IsExternalOneByte()); | 16173 CHECK(cons->IsExternalOneByte()); |
16178 CHECK_EQ(resource, cons->GetExternalOneByteStringResource()); | 16174 CHECK_EQ(resource, cons->GetExternalOneByteStringResource()); |
16179 String::Encoding encoding; | 16175 String::Encoding encoding; |
16180 CHECK_EQ(resource, cons->GetExternalStringResourceBase(&encoding)); | 16176 CHECK_EQ(resource, cons->GetExternalStringResourceBase(&encoding)); |
16181 CHECK_EQ(String::ONE_BYTE_ENCODING, encoding); | 16177 CHECK_EQ(String::ONE_BYTE_ENCODING, encoding); |
(...skipping 5687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21869 } | 21865 } |
21870 { | 21866 { |
21871 v8::TryCatch try_catch; | 21867 v8::TryCatch try_catch; |
21872 uint16_t* data = reinterpret_cast<uint16_t*>(buffer); | 21868 uint16_t* data = reinterpret_cast<uint16_t*>(buffer); |
21873 CHECK(v8::String::NewFromTwoByte(isolate, data, v8::String::kNormalString, | 21869 CHECK(v8::String::NewFromTwoByte(isolate, data, v8::String::kNormalString, |
21874 length).IsEmpty()); | 21870 length).IsEmpty()); |
21875 CHECK(!try_catch.HasCaught()); | 21871 CHECK(!try_catch.HasCaught()); |
21876 } | 21872 } |
21877 free(buffer); | 21873 free(buffer); |
21878 } | 21874 } |
OLD | NEW |