OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 | 2 |
3 #include <stdlib.h> | 3 #include <stdlib.h> |
4 | 4 |
5 #include "v8.h" | 5 #include "v8.h" |
6 | 6 |
7 #include "compilation-cache.h" | 7 #include "compilation-cache.h" |
8 #include "execution.h" | 8 #include "execution.h" |
9 #include "factory.h" | 9 #include "factory.h" |
10 #include "macro-assembler.h" | 10 #include "macro-assembler.h" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 value->Number()); | 172 value->Number()); |
173 | 173 |
174 // nan oddball checks | 174 // nan oddball checks |
175 CHECK(HEAP->nan_value()->IsNumber()); | 175 CHECK(HEAP->nan_value()->IsNumber()); |
176 CHECK(isnan(HEAP->nan_value()->Number())); | 176 CHECK(isnan(HEAP->nan_value()->Number())); |
177 | 177 |
178 Handle<String> s = FACTORY->NewStringFromAscii(CStrVector("fisk hest ")); | 178 Handle<String> s = FACTORY->NewStringFromAscii(CStrVector("fisk hest ")); |
179 CHECK(s->IsString()); | 179 CHECK(s->IsString()); |
180 CHECK_EQ(10, s->length()); | 180 CHECK_EQ(10, s->length()); |
181 | 181 |
182 String* object_symbol = String::cast(HEAP->Object_symbol()); | 182 String* object_string = String::cast(HEAP->Object_string()); |
183 CHECK( | 183 CHECK( |
184 Isolate::Current()->context()->global_object()->HasLocalProperty( | 184 Isolate::Current()->context()->global_object()->HasLocalProperty( |
185 object_symbol)); | 185 object_string)); |
186 | 186 |
187 // Check ToString for oddballs | 187 // Check ToString for oddballs |
188 CheckOddball(HEAP->true_value(), "true"); | 188 CheckOddball(HEAP->true_value(), "true"); |
189 CheckOddball(HEAP->false_value(), "false"); | 189 CheckOddball(HEAP->false_value(), "false"); |
190 CheckOddball(HEAP->null_value(), "null"); | 190 CheckOddball(HEAP->null_value(), "null"); |
191 CheckOddball(HEAP->undefined_value(), "undefined"); | 191 CheckOddball(HEAP->undefined_value(), "undefined"); |
192 | 192 |
193 // Check ToString for Smis | 193 // Check ToString for Smis |
194 CheckSmi(0, "0"); | 194 CheckSmi(0, "0"); |
195 CheckSmi(42, "42"); | 195 CheckSmi(42, "42"); |
(...skipping 22 matching lines...) Expand all Loading... |
218 } | 218 } |
219 | 219 |
220 | 220 |
221 TEST(GarbageCollection) { | 221 TEST(GarbageCollection) { |
222 InitializeVM(); | 222 InitializeVM(); |
223 | 223 |
224 v8::HandleScope sc; | 224 v8::HandleScope sc; |
225 // Check GC. | 225 // Check GC. |
226 HEAP->CollectGarbage(NEW_SPACE); | 226 HEAP->CollectGarbage(NEW_SPACE); |
227 | 227 |
228 Handle<String> name = FACTORY->LookupUtf8Symbol("theFunction"); | 228 Handle<String> name = FACTORY->InternalizeUtf8String("theFunction"); |
229 Handle<String> prop_name = FACTORY->LookupUtf8Symbol("theSlot"); | 229 Handle<String> prop_name = FACTORY->InternalizeUtf8String("theSlot"); |
230 Handle<String> prop_namex = FACTORY->LookupUtf8Symbol("theSlotx"); | 230 Handle<String> prop_namex = FACTORY->InternalizeUtf8String("theSlotx"); |
231 Handle<String> obj_name = FACTORY->LookupUtf8Symbol("theObject"); | 231 Handle<String> obj_name = FACTORY->InternalizeUtf8String("theObject"); |
232 | 232 |
233 { | 233 { |
234 v8::HandleScope inner_scope; | 234 v8::HandleScope inner_scope; |
235 // Allocate a function and keep it in global object's property. | 235 // Allocate a function and keep it in global object's property. |
236 Handle<JSFunction> function = | 236 Handle<JSFunction> function = |
237 FACTORY->NewFunction(name, FACTORY->undefined_value()); | 237 FACTORY->NewFunction(name, FACTORY->undefined_value()); |
238 Handle<Map> initial_map = | 238 Handle<Map> initial_map = |
239 FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 239 FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
240 function->set_initial_map(*initial_map); | 240 function->set_initial_map(*initial_map); |
241 Isolate::Current()->context()->global_object()->SetProperty( | 241 Isolate::Current()->context()->global_object()->SetProperty( |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 "typeof", | 537 "typeof", |
538 "var", | 538 "var", |
539 "void", | 539 "void", |
540 "volatile", | 540 "volatile", |
541 "while", | 541 "while", |
542 "with", | 542 "with", |
543 0 | 543 0 |
544 }; | 544 }; |
545 | 545 |
546 | 546 |
547 static void CheckSymbols(const char** strings) { | 547 static void CheckInternalizedStrings(const char** strings) { |
548 for (const char* string = *strings; *strings != 0; string = *strings++) { | 548 for (const char* string = *strings; *strings != 0; string = *strings++) { |
549 Object* a; | 549 Object* a; |
550 MaybeObject* maybe_a = HEAP->LookupUtf8Symbol(string); | 550 MaybeObject* maybe_a = HEAP->InternalizeUtf8String(string); |
551 // LookupUtf8Symbol may return a failure if a GC is needed. | 551 // InternalizeUtf8String may return a failure if a GC is needed. |
552 if (!maybe_a->ToObject(&a)) continue; | 552 if (!maybe_a->ToObject(&a)) continue; |
553 CHECK(a->IsSymbol()); | 553 CHECK(a->IsInternalizedString()); |
554 Object* b; | 554 Object* b; |
555 MaybeObject* maybe_b = HEAP->LookupUtf8Symbol(string); | 555 MaybeObject* maybe_b = HEAP->InternalizeUtf8String(string); |
556 if (!maybe_b->ToObject(&b)) continue; | 556 if (!maybe_b->ToObject(&b)) continue; |
557 CHECK_EQ(b, a); | 557 CHECK_EQ(b, a); |
558 CHECK(String::cast(b)->IsUtf8EqualTo(CStrVector(string))); | 558 CHECK(String::cast(b)->IsUtf8EqualTo(CStrVector(string))); |
559 } | 559 } |
560 } | 560 } |
561 | 561 |
562 | 562 |
563 TEST(SymbolTable) { | 563 TEST(StringTable) { |
564 InitializeVM(); | 564 InitializeVM(); |
565 | 565 |
566 CheckSymbols(not_so_random_string_table); | 566 CheckInternalizedStrings(not_so_random_string_table); |
567 CheckSymbols(not_so_random_string_table); | 567 CheckInternalizedStrings(not_so_random_string_table); |
568 } | 568 } |
569 | 569 |
570 | 570 |
571 TEST(FunctionAllocation) { | 571 TEST(FunctionAllocation) { |
572 InitializeVM(); | 572 InitializeVM(); |
573 | 573 |
574 v8::HandleScope sc; | 574 v8::HandleScope sc; |
575 Handle<String> name = FACTORY->LookupUtf8Symbol("theFunction"); | 575 Handle<String> name = FACTORY->InternalizeUtf8String("theFunction"); |
576 Handle<JSFunction> function = | 576 Handle<JSFunction> function = |
577 FACTORY->NewFunction(name, FACTORY->undefined_value()); | 577 FACTORY->NewFunction(name, FACTORY->undefined_value()); |
578 Handle<Map> initial_map = | 578 Handle<Map> initial_map = |
579 FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 579 FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
580 function->set_initial_map(*initial_map); | 580 function->set_initial_map(*initial_map); |
581 | 581 |
582 Handle<String> prop_name = FACTORY->LookupUtf8Symbol("theSlot"); | 582 Handle<String> prop_name = FACTORY->InternalizeUtf8String("theSlot"); |
583 Handle<JSObject> obj = FACTORY->NewJSObject(function); | 583 Handle<JSObject> obj = FACTORY->NewJSObject(function); |
584 obj->SetProperty( | 584 obj->SetProperty( |
585 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); | 585 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); |
586 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); | 586 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); |
587 // Check that we can add properties to function objects. | 587 // Check that we can add properties to function objects. |
588 function->SetProperty( | 588 function->SetProperty( |
589 *prop_name, Smi::FromInt(24), NONE, kNonStrictMode)->ToObjectChecked(); | 589 *prop_name, Smi::FromInt(24), NONE, kNonStrictMode)->ToObjectChecked(); |
590 CHECK_EQ(Smi::FromInt(24), function->GetProperty(*prop_name)); | 590 CHECK_EQ(Smi::FromInt(24), function->GetProperty(*prop_name)); |
591 } | 591 } |
592 | 592 |
593 | 593 |
594 TEST(ObjectProperties) { | 594 TEST(ObjectProperties) { |
595 InitializeVM(); | 595 InitializeVM(); |
596 | 596 |
597 v8::HandleScope sc; | 597 v8::HandleScope sc; |
598 String* object_symbol = String::cast(HEAP->Object_symbol()); | 598 String* object_string = String::cast(HEAP->Object_string()); |
599 Object* raw_object = Isolate::Current()->context()->global_object()-> | 599 Object* raw_object = Isolate::Current()->context()->global_object()-> |
600 GetProperty(object_symbol)->ToObjectChecked(); | 600 GetProperty(object_string)->ToObjectChecked(); |
601 JSFunction* object_function = JSFunction::cast(raw_object); | 601 JSFunction* object_function = JSFunction::cast(raw_object); |
602 Handle<JSFunction> constructor(object_function); | 602 Handle<JSFunction> constructor(object_function); |
603 Handle<JSObject> obj = FACTORY->NewJSObject(constructor); | 603 Handle<JSObject> obj = FACTORY->NewJSObject(constructor); |
604 Handle<String> first = FACTORY->LookupUtf8Symbol("first"); | 604 Handle<String> first = FACTORY->InternalizeUtf8String("first"); |
605 Handle<String> second = FACTORY->LookupUtf8Symbol("second"); | 605 Handle<String> second = FACTORY->InternalizeUtf8String("second"); |
606 | 606 |
607 // check for empty | 607 // check for empty |
608 CHECK(!obj->HasLocalProperty(*first)); | 608 CHECK(!obj->HasLocalProperty(*first)); |
609 | 609 |
610 // add first | 610 // add first |
611 obj->SetProperty( | 611 obj->SetProperty( |
612 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); | 612 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); |
613 CHECK(obj->HasLocalProperty(*first)); | 613 CHECK(obj->HasLocalProperty(*first)); |
614 | 614 |
615 // delete first | 615 // delete first |
(...skipping 23 matching lines...) Expand all Loading... |
639 CHECK(obj->HasLocalProperty(*first)); | 639 CHECK(obj->HasLocalProperty(*first)); |
640 CHECK(obj->HasLocalProperty(*second)); | 640 CHECK(obj->HasLocalProperty(*second)); |
641 | 641 |
642 // delete second and then first | 642 // delete second and then first |
643 CHECK(obj->DeleteProperty(*second, JSObject::NORMAL_DELETION)); | 643 CHECK(obj->DeleteProperty(*second, JSObject::NORMAL_DELETION)); |
644 CHECK(obj->HasLocalProperty(*first)); | 644 CHECK(obj->HasLocalProperty(*first)); |
645 CHECK(obj->DeleteProperty(*first, JSObject::NORMAL_DELETION)); | 645 CHECK(obj->DeleteProperty(*first, JSObject::NORMAL_DELETION)); |
646 CHECK(!obj->HasLocalProperty(*first)); | 646 CHECK(!obj->HasLocalProperty(*first)); |
647 CHECK(!obj->HasLocalProperty(*second)); | 647 CHECK(!obj->HasLocalProperty(*second)); |
648 | 648 |
649 // check string and symbol match | 649 // check string and internalized string match |
650 const char* string1 = "fisk"; | 650 const char* string1 = "fisk"; |
651 Handle<String> s1 = FACTORY->NewStringFromAscii(CStrVector(string1)); | 651 Handle<String> s1 = FACTORY->NewStringFromAscii(CStrVector(string1)); |
652 obj->SetProperty( | 652 obj->SetProperty( |
653 *s1, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); | 653 *s1, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); |
654 Handle<String> s1_symbol = FACTORY->LookupUtf8Symbol(string1); | 654 Handle<String> s1_string = FACTORY->InternalizeUtf8String(string1); |
655 CHECK(obj->HasLocalProperty(*s1_symbol)); | 655 CHECK(obj->HasLocalProperty(*s1_string)); |
656 | 656 |
657 // check symbol and string match | 657 // check internalized string and string match |
658 const char* string2 = "fugl"; | 658 const char* string2 = "fugl"; |
659 Handle<String> s2_symbol = FACTORY->LookupUtf8Symbol(string2); | 659 Handle<String> s2_string = FACTORY->InternalizeUtf8String(string2); |
660 obj->SetProperty( | 660 obj->SetProperty( |
661 *s2_symbol, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); | 661 *s2_string, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); |
662 Handle<String> s2 = FACTORY->NewStringFromAscii(CStrVector(string2)); | 662 Handle<String> s2 = FACTORY->NewStringFromAscii(CStrVector(string2)); |
663 CHECK(obj->HasLocalProperty(*s2)); | 663 CHECK(obj->HasLocalProperty(*s2)); |
664 } | 664 } |
665 | 665 |
666 | 666 |
667 TEST(JSObjectMaps) { | 667 TEST(JSObjectMaps) { |
668 InitializeVM(); | 668 InitializeVM(); |
669 | 669 |
670 v8::HandleScope sc; | 670 v8::HandleScope sc; |
671 Handle<String> name = FACTORY->LookupUtf8Symbol("theFunction"); | 671 Handle<String> name = FACTORY->InternalizeUtf8String("theFunction"); |
672 Handle<JSFunction> function = | 672 Handle<JSFunction> function = |
673 FACTORY->NewFunction(name, FACTORY->undefined_value()); | 673 FACTORY->NewFunction(name, FACTORY->undefined_value()); |
674 Handle<Map> initial_map = | 674 Handle<Map> initial_map = |
675 FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 675 FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
676 function->set_initial_map(*initial_map); | 676 function->set_initial_map(*initial_map); |
677 | 677 |
678 Handle<String> prop_name = FACTORY->LookupUtf8Symbol("theSlot"); | 678 Handle<String> prop_name = FACTORY->InternalizeUtf8String("theSlot"); |
679 Handle<JSObject> obj = FACTORY->NewJSObject(function); | 679 Handle<JSObject> obj = FACTORY->NewJSObject(function); |
680 | 680 |
681 // Set a propery | 681 // Set a propery |
682 obj->SetProperty( | 682 obj->SetProperty( |
683 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); | 683 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); |
684 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); | 684 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); |
685 | 685 |
686 // Check the map has changed | 686 // Check the map has changed |
687 CHECK(*initial_map != obj->map()); | 687 CHECK(*initial_map != obj->map()); |
688 } | 688 } |
689 | 689 |
690 | 690 |
691 TEST(JSArray) { | 691 TEST(JSArray) { |
692 InitializeVM(); | 692 InitializeVM(); |
693 | 693 |
694 v8::HandleScope sc; | 694 v8::HandleScope sc; |
695 Handle<String> name = FACTORY->LookupUtf8Symbol("Array"); | 695 Handle<String> name = FACTORY->InternalizeUtf8String("Array"); |
696 Object* raw_object = Isolate::Current()->context()->global_object()-> | 696 Object* raw_object = Isolate::Current()->context()->global_object()-> |
697 GetProperty(*name)->ToObjectChecked(); | 697 GetProperty(*name)->ToObjectChecked(); |
698 Handle<JSFunction> function = Handle<JSFunction>( | 698 Handle<JSFunction> function = Handle<JSFunction>( |
699 JSFunction::cast(raw_object)); | 699 JSFunction::cast(raw_object)); |
700 | 700 |
701 // Allocate the object. | 701 // Allocate the object. |
702 Handle<JSObject> object = FACTORY->NewJSObject(function); | 702 Handle<JSObject> object = FACTORY->NewJSObject(function); |
703 Handle<JSArray> array = Handle<JSArray>::cast(object); | 703 Handle<JSArray> array = Handle<JSArray>::cast(object); |
704 // We just initialized the VM, no heap allocation failure yet. | 704 // We just initialized the VM, no heap allocation failure yet. |
705 array->Initialize(0)->ToObjectChecked(); | 705 array->Initialize(0)->ToObjectChecked(); |
(...skipping 26 matching lines...) Expand all Loading... |
732 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1); | 732 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1); |
733 CHECK_EQ(array->GetElement(int_length), *name); | 733 CHECK_EQ(array->GetElement(int_length), *name); |
734 CHECK_EQ(array->GetElement(0), *name); | 734 CHECK_EQ(array->GetElement(0), *name); |
735 } | 735 } |
736 | 736 |
737 | 737 |
738 TEST(JSObjectCopy) { | 738 TEST(JSObjectCopy) { |
739 InitializeVM(); | 739 InitializeVM(); |
740 | 740 |
741 v8::HandleScope sc; | 741 v8::HandleScope sc; |
742 String* object_symbol = String::cast(HEAP->Object_symbol()); | 742 String* object_string = String::cast(HEAP->Object_string()); |
743 Object* raw_object = Isolate::Current()->context()->global_object()-> | 743 Object* raw_object = Isolate::Current()->context()->global_object()-> |
744 GetProperty(object_symbol)->ToObjectChecked(); | 744 GetProperty(object_string)->ToObjectChecked(); |
745 JSFunction* object_function = JSFunction::cast(raw_object); | 745 JSFunction* object_function = JSFunction::cast(raw_object); |
746 Handle<JSFunction> constructor(object_function); | 746 Handle<JSFunction> constructor(object_function); |
747 Handle<JSObject> obj = FACTORY->NewJSObject(constructor); | 747 Handle<JSObject> obj = FACTORY->NewJSObject(constructor); |
748 Handle<String> first = FACTORY->LookupUtf8Symbol("first"); | 748 Handle<String> first = FACTORY->InternalizeUtf8String("first"); |
749 Handle<String> second = FACTORY->LookupUtf8Symbol("second"); | 749 Handle<String> second = FACTORY->InternalizeUtf8String("second"); |
750 | 750 |
751 obj->SetProperty( | 751 obj->SetProperty( |
752 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); | 752 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); |
753 obj->SetProperty( | 753 obj->SetProperty( |
754 *second, Smi::FromInt(2), NONE, kNonStrictMode)->ToObjectChecked(); | 754 *second, Smi::FromInt(2), NONE, kNonStrictMode)->ToObjectChecked(); |
755 | 755 |
756 obj->SetElement(0, *first, NONE, kNonStrictMode)->ToObjectChecked(); | 756 obj->SetElement(0, *first, NONE, kNonStrictMode)->ToObjectChecked(); |
757 obj->SetElement(1, *second, NONE, kNonStrictMode)->ToObjectChecked(); | 757 obj->SetElement(1, *second, NONE, kNonStrictMode)->ToObjectChecked(); |
758 | 758 |
759 // Make the clone. | 759 // Make the clone. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 char* ascii = NewArray<char>(length + 1); | 794 char* ascii = NewArray<char>(length + 1); |
795 non_ascii[3 * length] = 0; | 795 non_ascii[3 * length] = 0; |
796 ascii[length] = 0; | 796 ascii[length] = 0; |
797 for (int i = 0; i < length; i++) { | 797 for (int i = 0; i < length; i++) { |
798 ascii[i] = 'a'; | 798 ascii[i] = 'a'; |
799 non_ascii[3 * i] = chars[0]; | 799 non_ascii[3 * i] = chars[0]; |
800 non_ascii[3 * i + 1] = chars[1]; | 800 non_ascii[3 * i + 1] = chars[1]; |
801 non_ascii[3 * i + 2] = chars[2]; | 801 non_ascii[3 * i + 2] = chars[2]; |
802 } | 802 } |
803 Handle<String> non_ascii_sym = | 803 Handle<String> non_ascii_sym = |
804 FACTORY->LookupUtf8Symbol(Vector<const char>(non_ascii, 3 * length)); | 804 FACTORY->InternalizeUtf8String( |
| 805 Vector<const char>(non_ascii, 3 * length)); |
805 CHECK_EQ(length, non_ascii_sym->length()); | 806 CHECK_EQ(length, non_ascii_sym->length()); |
806 Handle<String> ascii_sym = | 807 Handle<String> ascii_sym = |
807 FACTORY->LookupOneByteSymbol(OneByteVector(ascii, length)); | 808 FACTORY->InternalizeOneByteString(OneByteVector(ascii, length)); |
808 CHECK_EQ(length, ascii_sym->length()); | 809 CHECK_EQ(length, ascii_sym->length()); |
809 Handle<String> non_ascii_str = | 810 Handle<String> non_ascii_str = |
810 FACTORY->NewStringFromUtf8(Vector<const char>(non_ascii, 3 * length)); | 811 FACTORY->NewStringFromUtf8(Vector<const char>(non_ascii, 3 * length)); |
811 non_ascii_str->Hash(); | 812 non_ascii_str->Hash(); |
812 CHECK_EQ(length, non_ascii_str->length()); | 813 CHECK_EQ(length, non_ascii_str->length()); |
813 Handle<String> ascii_str = | 814 Handle<String> ascii_str = |
814 FACTORY->NewStringFromUtf8(Vector<const char>(ascii, length)); | 815 FACTORY->NewStringFromUtf8(Vector<const char>(ascii, length)); |
815 ascii_str->Hash(); | 816 ascii_str->Hash(); |
816 CHECK_EQ(length, ascii_str->length()); | 817 CHECK_EQ(length, ascii_str->length()); |
817 DeleteArray(non_ascii); | 818 DeleteArray(non_ascii); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 if (!FLAG_flush_code) return; | 975 if (!FLAG_flush_code) return; |
975 i::FLAG_allow_natives_syntax = true; | 976 i::FLAG_allow_natives_syntax = true; |
976 InitializeVM(); | 977 InitializeVM(); |
977 v8::HandleScope scope; | 978 v8::HandleScope scope; |
978 const char* source = "function foo() {" | 979 const char* source = "function foo() {" |
979 " var x = 42;" | 980 " var x = 42;" |
980 " var y = 42;" | 981 " var y = 42;" |
981 " var z = x + y;" | 982 " var z = x + y;" |
982 "};" | 983 "};" |
983 "foo()"; | 984 "foo()"; |
984 Handle<String> foo_name = FACTORY->LookupUtf8Symbol("foo"); | 985 Handle<String> foo_name = FACTORY->InternalizeUtf8String("foo"); |
985 | 986 |
986 // This compile will add the code to the compilation cache. | 987 // This compile will add the code to the compilation cache. |
987 { v8::HandleScope scope; | 988 { v8::HandleScope scope; |
988 CompileRun(source); | 989 CompileRun(source); |
989 } | 990 } |
990 | 991 |
991 // Check function is compiled. | 992 // Check function is compiled. |
992 Object* func_value = Isolate::Current()->context()->global_object()-> | 993 Object* func_value = Isolate::Current()->context()->global_object()-> |
993 GetProperty(*foo_name)->ToObjectChecked(); | 994 GetProperty(*foo_name)->ToObjectChecked(); |
994 CHECK(func_value->IsJSFunction()); | 995 CHECK(func_value->IsJSFunction()); |
(...skipping 26 matching lines...) Expand all Loading... |
1021 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return; | 1022 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return; |
1022 i::FLAG_allow_natives_syntax = true; | 1023 i::FLAG_allow_natives_syntax = true; |
1023 InitializeVM(); | 1024 InitializeVM(); |
1024 v8::HandleScope scope; | 1025 v8::HandleScope scope; |
1025 const char* source = "function foo() {" | 1026 const char* source = "function foo() {" |
1026 " var x = 42;" | 1027 " var x = 42;" |
1027 " var y = 42;" | 1028 " var y = 42;" |
1028 " var z = x + y;" | 1029 " var z = x + y;" |
1029 "};" | 1030 "};" |
1030 "foo()"; | 1031 "foo()"; |
1031 Handle<String> foo_name = FACTORY->LookupUtf8Symbol("foo"); | 1032 Handle<String> foo_name = FACTORY->InternalizeUtf8String("foo"); |
1032 | 1033 |
1033 // This compile will add the code to the compilation cache. | 1034 // This compile will add the code to the compilation cache. |
1034 { v8::HandleScope scope; | 1035 { v8::HandleScope scope; |
1035 CompileRun(source); | 1036 CompileRun(source); |
1036 } | 1037 } |
1037 | 1038 |
1038 // Check function is compiled. | 1039 // Check function is compiled. |
1039 Object* func_value = Isolate::Current()->context()->global_object()-> | 1040 Object* func_value = Isolate::Current()->context()->global_object()-> |
1040 GetProperty(*foo_name)->ToObjectChecked(); | 1041 GetProperty(*foo_name)->ToObjectChecked(); |
1041 CHECK(func_value->IsJSFunction()); | 1042 CHECK(func_value->IsJSFunction()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1091 const char* source = "var foo = function() {" | 1092 const char* source = "var foo = function() {" |
1092 " var x = 42;" | 1093 " var x = 42;" |
1093 " var y = 42;" | 1094 " var y = 42;" |
1094 " var z = x + y;" | 1095 " var z = x + y;" |
1095 "};" | 1096 "};" |
1096 "foo();" | 1097 "foo();" |
1097 "var bar = function() {" | 1098 "var bar = function() {" |
1098 " var x = 23;" | 1099 " var x = 23;" |
1099 "};" | 1100 "};" |
1100 "bar();"; | 1101 "bar();"; |
1101 Handle<String> foo_name = FACTORY->LookupUtf8Symbol("foo"); | 1102 Handle<String> foo_name = FACTORY->InternalizeUtf8String("foo"); |
1102 Handle<String> bar_name = FACTORY->LookupUtf8Symbol("bar"); | 1103 Handle<String> bar_name = FACTORY->InternalizeUtf8String("bar"); |
1103 | 1104 |
1104 // Perfrom one initial GC to enable code flushing. | 1105 // Perfrom one initial GC to enable code flushing. |
1105 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 1106 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
1106 | 1107 |
1107 // This compile will add the code to the compilation cache. | 1108 // This compile will add the code to the compilation cache. |
1108 { v8::HandleScope scope; | 1109 { v8::HandleScope scope; |
1109 CompileRun(source); | 1110 CompileRun(source); |
1110 } | 1111 } |
1111 | 1112 |
1112 // Check functions are compiled. | 1113 // Check functions are compiled. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1153 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return; | 1154 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return; |
1154 i::FLAG_allow_natives_syntax = true; | 1155 i::FLAG_allow_natives_syntax = true; |
1155 InitializeVM(); | 1156 InitializeVM(); |
1156 v8::HandleScope scope; | 1157 v8::HandleScope scope; |
1157 const char* source = "function foo() {" | 1158 const char* source = "function foo() {" |
1158 " var x = 42;" | 1159 " var x = 42;" |
1159 " var y = 42;" | 1160 " var y = 42;" |
1160 " var z = x + y;" | 1161 " var z = x + y;" |
1161 "};" | 1162 "};" |
1162 "foo()"; | 1163 "foo()"; |
1163 Handle<String> foo_name = FACTORY->LookupUtf8Symbol("foo"); | 1164 Handle<String> foo_name = FACTORY->InternalizeUtf8String("foo"); |
1164 | 1165 |
1165 // This compile will add the code to the compilation cache. | 1166 // This compile will add the code to the compilation cache. |
1166 { v8::HandleScope scope; | 1167 { v8::HandleScope scope; |
1167 CompileRun(source); | 1168 CompileRun(source); |
1168 } | 1169 } |
1169 | 1170 |
1170 // Check function is compiled. | 1171 // Check function is compiled. |
1171 Object* func_value = Isolate::Current()->context()->global_object()-> | 1172 Object* func_value = Isolate::Current()->context()->global_object()-> |
1172 GetProperty(*foo_name)->ToObjectChecked(); | 1173 GetProperty(*foo_name)->ToObjectChecked(); |
1173 CHECK(func_value->IsJSFunction()); | 1174 CHECK(func_value->IsJSFunction()); |
(...skipping 1050 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2224 // In the first iteration, set hidden value first and identity hash second. | 2225 // In the first iteration, set hidden value first and identity hash second. |
2225 // In the second iteration, reverse the order. | 2226 // In the second iteration, reverse the order. |
2226 if (i == 0) obj->SetHiddenValue(v8_str("key string"), value); | 2227 if (i == 0) obj->SetHiddenValue(v8_str("key string"), value); |
2227 MaybeObject* maybe_obj = internal_obj->SetIdentityHash(hash, | 2228 MaybeObject* maybe_obj = internal_obj->SetIdentityHash(hash, |
2228 ALLOW_CREATION); | 2229 ALLOW_CREATION); |
2229 CHECK(!maybe_obj->IsFailure()); | 2230 CHECK(!maybe_obj->IsFailure()); |
2230 if (i == 1) obj->SetHiddenValue(v8_str("key string"), value); | 2231 if (i == 1) obj->SetHiddenValue(v8_str("key string"), value); |
2231 | 2232 |
2232 // Check values. | 2233 // Check values. |
2233 CHECK_EQ(hash, | 2234 CHECK_EQ(hash, |
2234 internal_obj->GetHiddenProperty(heap->identity_hash_symbol())); | 2235 internal_obj->GetHiddenProperty(heap->identity_hash_string())); |
2235 CHECK(value->Equals(obj->GetHiddenValue(v8_str("key string")))); | 2236 CHECK(value->Equals(obj->GetHiddenValue(v8_str("key string")))); |
2236 | 2237 |
2237 // Check size. | 2238 // Check size. |
2238 DescriptorArray* descriptors = internal_obj->map()->instance_descriptors(); | 2239 DescriptorArray* descriptors = internal_obj->map()->instance_descriptors(); |
2239 ObjectHashTable* hashtable = ObjectHashTable::cast( | 2240 ObjectHashTable* hashtable = ObjectHashTable::cast( |
2240 internal_obj->FastPropertyAt(descriptors->GetFieldIndex(0))); | 2241 internal_obj->FastPropertyAt(descriptors->GetFieldIndex(0))); |
2241 // HashTable header (5) and 4 initial entries (8). | 2242 // HashTable header (5) and 4 initial entries (8). |
2242 CHECK_LE(hashtable->SizeFor(hashtable->length()), 13 * kPointerSize); | 2243 CHECK_LE(hashtable->SizeFor(hashtable->length()), 13 * kPointerSize); |
2243 } | 2244 } |
2244 } | 2245 } |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2497 CompileRun("for (var i = 0; i < 2000; i++) {" | 2498 CompileRun("for (var i = 0; i < 2000; i++) {" |
2498 " eval('function f' + i + '() { return ' + i +'; };' +" | 2499 " eval('function f' + i + '() { return ' + i +'; };' +" |
2499 " 'f' + i + '();');" | 2500 " 'f' + i + '();');" |
2500 "}"); | 2501 "}"); |
2501 } | 2502 } |
2502 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 2503 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
2503 | 2504 |
2504 // Fourth is the tricky part. Make sure the code containing the CallIC is | 2505 // Fourth is the tricky part. Make sure the code containing the CallIC is |
2505 // visited first without clearing the IC. The shared function info is then | 2506 // visited first without clearing the IC. The shared function info is then |
2506 // visited later, causing the CallIC to be cleared. | 2507 // visited later, causing the CallIC to be cleared. |
2507 Handle<String> name = FACTORY->LookupUtf8Symbol("call"); | 2508 Handle<String> name = FACTORY->InternalizeUtf8String("call"); |
2508 Handle<GlobalObject> global(ISOLATE->context()->global_object()); | 2509 Handle<GlobalObject> global(ISOLATE->context()->global_object()); |
2509 MaybeObject* maybe_call = global->GetProperty(*name); | 2510 MaybeObject* maybe_call = global->GetProperty(*name); |
2510 JSFunction* call = JSFunction::cast(maybe_call->ToObjectChecked()); | 2511 JSFunction* call = JSFunction::cast(maybe_call->ToObjectChecked()); |
2511 USE(global->SetProperty(*name, Smi::FromInt(0), NONE, kNonStrictMode)); | 2512 USE(global->SetProperty(*name, Smi::FromInt(0), NONE, kNonStrictMode)); |
2512 ISOLATE->compilation_cache()->Clear(); | 2513 ISOLATE->compilation_cache()->Clear(); |
2513 call->shared()->set_ic_age(HEAP->global_ic_age() + 1); | 2514 call->shared()->set_ic_age(HEAP->global_ic_age() + 1); |
2514 Handle<Object> call_code(call->code()); | 2515 Handle<Object> call_code(call->code()); |
2515 Handle<Object> call_function(call); | 2516 Handle<Object> call_function(call); |
2516 | 2517 |
2517 // Now we are ready to mess up the heap. | 2518 // Now we are ready to mess up the heap. |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2829 // Now optimize the function so that it is taken off the candidate list. | 2830 // Now optimize the function so that it is taken off the candidate list. |
2830 { | 2831 { |
2831 HandleScope inner_scope; | 2832 HandleScope inner_scope; |
2832 CompileRun("%OptimizeFunctionOnNextCall(f); f(3);"); | 2833 CompileRun("%OptimizeFunctionOnNextCall(f); f(3);"); |
2833 } | 2834 } |
2834 | 2835 |
2835 // This cycle will bust the heap and subsequent cycles will go ballistic. | 2836 // This cycle will bust the heap and subsequent cycles will go ballistic. |
2836 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 2837 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
2837 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 2838 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
2838 } | 2839 } |
OLD | NEW |