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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 } | 211 } |
212 | 212 |
213 | 213 |
214 TEST(GarbageCollection) { | 214 TEST(GarbageCollection) { |
215 InitializeVM(); | 215 InitializeVM(); |
216 | 216 |
217 v8::HandleScope sc; | 217 v8::HandleScope sc; |
218 // Check GC. | 218 // Check GC. |
219 HEAP->CollectGarbage(NEW_SPACE); | 219 HEAP->CollectGarbage(NEW_SPACE); |
220 | 220 |
221 Handle<String> name = FACTORY->LookupAsciiSymbol("theFunction"); | 221 Handle<String> name = FACTORY->LookupUtf8Symbol("theFunction"); |
222 Handle<String> prop_name = FACTORY->LookupAsciiSymbol("theSlot"); | 222 Handle<String> prop_name = FACTORY->LookupUtf8Symbol("theSlot"); |
223 Handle<String> prop_namex = FACTORY->LookupAsciiSymbol("theSlotx"); | 223 Handle<String> prop_namex = FACTORY->LookupUtf8Symbol("theSlotx"); |
224 Handle<String> obj_name = FACTORY->LookupAsciiSymbol("theObject"); | 224 Handle<String> obj_name = FACTORY->LookupUtf8Symbol("theObject"); |
225 | 225 |
226 { | 226 { |
227 v8::HandleScope inner_scope; | 227 v8::HandleScope inner_scope; |
228 // Allocate a function and keep it in global object's property. | 228 // Allocate a function and keep it in global object's property. |
229 Handle<JSFunction> function = | 229 Handle<JSFunction> function = |
230 FACTORY->NewFunction(name, FACTORY->undefined_value()); | 230 FACTORY->NewFunction(name, FACTORY->undefined_value()); |
231 Handle<Map> initial_map = | 231 Handle<Map> initial_map = |
232 FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 232 FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
233 function->set_initial_map(*initial_map); | 233 function->set_initial_map(*initial_map); |
234 Isolate::Current()->context()->global_object()->SetProperty( | 234 Isolate::Current()->context()->global_object()->SetProperty( |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 "volatile", | 529 "volatile", |
530 "while", | 530 "while", |
531 "with", | 531 "with", |
532 0 | 532 0 |
533 }; | 533 }; |
534 | 534 |
535 | 535 |
536 static void CheckSymbols(const char** strings) { | 536 static void CheckSymbols(const char** strings) { |
537 for (const char* string = *strings; *strings != 0; string = *strings++) { | 537 for (const char* string = *strings; *strings != 0; string = *strings++) { |
538 Object* a; | 538 Object* a; |
539 MaybeObject* maybe_a = HEAP->LookupAsciiSymbol(string); | 539 MaybeObject* maybe_a = HEAP->LookupUtf8Symbol(string); |
540 // LookupAsciiSymbol may return a failure if a GC is needed. | 540 // LookupUtf8Symbol may return a failure if a GC is needed. |
541 if (!maybe_a->ToObject(&a)) continue; | 541 if (!maybe_a->ToObject(&a)) continue; |
542 CHECK(a->IsSymbol()); | 542 CHECK(a->IsSymbol()); |
543 Object* b; | 543 Object* b; |
544 MaybeObject* maybe_b = HEAP->LookupAsciiSymbol(string); | 544 MaybeObject* maybe_b = HEAP->LookupUtf8Symbol(string); |
545 if (!maybe_b->ToObject(&b)) continue; | 545 if (!maybe_b->ToObject(&b)) continue; |
546 CHECK_EQ(b, a); | 546 CHECK_EQ(b, a); |
547 CHECK(String::cast(b)->IsEqualTo(CStrVector(string))); | 547 CHECK(String::cast(b)->IsEqualTo(CStrVector(string))); |
548 } | 548 } |
549 } | 549 } |
550 | 550 |
551 | 551 |
552 TEST(SymbolTable) { | 552 TEST(SymbolTable) { |
553 InitializeVM(); | 553 InitializeVM(); |
554 | 554 |
555 CheckSymbols(not_so_random_string_table); | 555 CheckSymbols(not_so_random_string_table); |
556 CheckSymbols(not_so_random_string_table); | 556 CheckSymbols(not_so_random_string_table); |
557 } | 557 } |
558 | 558 |
559 | 559 |
560 TEST(FunctionAllocation) { | 560 TEST(FunctionAllocation) { |
561 InitializeVM(); | 561 InitializeVM(); |
562 | 562 |
563 v8::HandleScope sc; | 563 v8::HandleScope sc; |
564 Handle<String> name = FACTORY->LookupAsciiSymbol("theFunction"); | 564 Handle<String> name = FACTORY->LookupUtf8Symbol("theFunction"); |
565 Handle<JSFunction> function = | 565 Handle<JSFunction> function = |
566 FACTORY->NewFunction(name, FACTORY->undefined_value()); | 566 FACTORY->NewFunction(name, FACTORY->undefined_value()); |
567 Handle<Map> initial_map = | 567 Handle<Map> initial_map = |
568 FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 568 FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
569 function->set_initial_map(*initial_map); | 569 function->set_initial_map(*initial_map); |
570 | 570 |
571 Handle<String> prop_name = FACTORY->LookupAsciiSymbol("theSlot"); | 571 Handle<String> prop_name = FACTORY->LookupUtf8Symbol("theSlot"); |
572 Handle<JSObject> obj = FACTORY->NewJSObject(function); | 572 Handle<JSObject> obj = FACTORY->NewJSObject(function); |
573 obj->SetProperty( | 573 obj->SetProperty( |
574 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); | 574 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); |
575 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); | 575 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); |
576 // Check that we can add properties to function objects. | 576 // Check that we can add properties to function objects. |
577 function->SetProperty( | 577 function->SetProperty( |
578 *prop_name, Smi::FromInt(24), NONE, kNonStrictMode)->ToObjectChecked(); | 578 *prop_name, Smi::FromInt(24), NONE, kNonStrictMode)->ToObjectChecked(); |
579 CHECK_EQ(Smi::FromInt(24), function->GetProperty(*prop_name)); | 579 CHECK_EQ(Smi::FromInt(24), function->GetProperty(*prop_name)); |
580 } | 580 } |
581 | 581 |
582 | 582 |
583 TEST(ObjectProperties) { | 583 TEST(ObjectProperties) { |
584 InitializeVM(); | 584 InitializeVM(); |
585 | 585 |
586 v8::HandleScope sc; | 586 v8::HandleScope sc; |
587 String* object_symbol = String::cast(HEAP->Object_symbol()); | 587 String* object_symbol = String::cast(HEAP->Object_symbol()); |
588 Object* raw_object = Isolate::Current()->context()->global_object()-> | 588 Object* raw_object = Isolate::Current()->context()->global_object()-> |
589 GetProperty(object_symbol)->ToObjectChecked(); | 589 GetProperty(object_symbol)->ToObjectChecked(); |
590 JSFunction* object_function = JSFunction::cast(raw_object); | 590 JSFunction* object_function = JSFunction::cast(raw_object); |
591 Handle<JSFunction> constructor(object_function); | 591 Handle<JSFunction> constructor(object_function); |
592 Handle<JSObject> obj = FACTORY->NewJSObject(constructor); | 592 Handle<JSObject> obj = FACTORY->NewJSObject(constructor); |
593 Handle<String> first = FACTORY->LookupAsciiSymbol("first"); | 593 Handle<String> first = FACTORY->LookupUtf8Symbol("first"); |
594 Handle<String> second = FACTORY->LookupAsciiSymbol("second"); | 594 Handle<String> second = FACTORY->LookupUtf8Symbol("second"); |
595 | 595 |
596 // check for empty | 596 // check for empty |
597 CHECK(!obj->HasLocalProperty(*first)); | 597 CHECK(!obj->HasLocalProperty(*first)); |
598 | 598 |
599 // add first | 599 // add first |
600 obj->SetProperty( | 600 obj->SetProperty( |
601 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); | 601 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); |
602 CHECK(obj->HasLocalProperty(*first)); | 602 CHECK(obj->HasLocalProperty(*first)); |
603 | 603 |
604 // delete first | 604 // delete first |
(...skipping 28 matching lines...) Expand all Loading... |
633 CHECK(obj->HasLocalProperty(*first)); | 633 CHECK(obj->HasLocalProperty(*first)); |
634 CHECK(obj->DeleteProperty(*first, JSObject::NORMAL_DELETION)); | 634 CHECK(obj->DeleteProperty(*first, JSObject::NORMAL_DELETION)); |
635 CHECK(!obj->HasLocalProperty(*first)); | 635 CHECK(!obj->HasLocalProperty(*first)); |
636 CHECK(!obj->HasLocalProperty(*second)); | 636 CHECK(!obj->HasLocalProperty(*second)); |
637 | 637 |
638 // check string and symbol match | 638 // check string and symbol match |
639 const char* string1 = "fisk"; | 639 const char* string1 = "fisk"; |
640 Handle<String> s1 = FACTORY->NewStringFromAscii(CStrVector(string1)); | 640 Handle<String> s1 = FACTORY->NewStringFromAscii(CStrVector(string1)); |
641 obj->SetProperty( | 641 obj->SetProperty( |
642 *s1, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); | 642 *s1, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); |
643 Handle<String> s1_symbol = FACTORY->LookupAsciiSymbol(string1); | 643 Handle<String> s1_symbol = FACTORY->LookupUtf8Symbol(string1); |
644 CHECK(obj->HasLocalProperty(*s1_symbol)); | 644 CHECK(obj->HasLocalProperty(*s1_symbol)); |
645 | 645 |
646 // check symbol and string match | 646 // check symbol and string match |
647 const char* string2 = "fugl"; | 647 const char* string2 = "fugl"; |
648 Handle<String> s2_symbol = FACTORY->LookupAsciiSymbol(string2); | 648 Handle<String> s2_symbol = FACTORY->LookupUtf8Symbol(string2); |
649 obj->SetProperty( | 649 obj->SetProperty( |
650 *s2_symbol, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); | 650 *s2_symbol, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); |
651 Handle<String> s2 = FACTORY->NewStringFromAscii(CStrVector(string2)); | 651 Handle<String> s2 = FACTORY->NewStringFromAscii(CStrVector(string2)); |
652 CHECK(obj->HasLocalProperty(*s2)); | 652 CHECK(obj->HasLocalProperty(*s2)); |
653 } | 653 } |
654 | 654 |
655 | 655 |
656 TEST(JSObjectMaps) { | 656 TEST(JSObjectMaps) { |
657 InitializeVM(); | 657 InitializeVM(); |
658 | 658 |
659 v8::HandleScope sc; | 659 v8::HandleScope sc; |
660 Handle<String> name = FACTORY->LookupAsciiSymbol("theFunction"); | 660 Handle<String> name = FACTORY->LookupUtf8Symbol("theFunction"); |
661 Handle<JSFunction> function = | 661 Handle<JSFunction> function = |
662 FACTORY->NewFunction(name, FACTORY->undefined_value()); | 662 FACTORY->NewFunction(name, FACTORY->undefined_value()); |
663 Handle<Map> initial_map = | 663 Handle<Map> initial_map = |
664 FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 664 FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
665 function->set_initial_map(*initial_map); | 665 function->set_initial_map(*initial_map); |
666 | 666 |
667 Handle<String> prop_name = FACTORY->LookupAsciiSymbol("theSlot"); | 667 Handle<String> prop_name = FACTORY->LookupUtf8Symbol("theSlot"); |
668 Handle<JSObject> obj = FACTORY->NewJSObject(function); | 668 Handle<JSObject> obj = FACTORY->NewJSObject(function); |
669 | 669 |
670 // Set a propery | 670 // Set a propery |
671 obj->SetProperty( | 671 obj->SetProperty( |
672 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); | 672 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); |
673 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); | 673 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); |
674 | 674 |
675 // Check the map has changed | 675 // Check the map has changed |
676 CHECK(*initial_map != obj->map()); | 676 CHECK(*initial_map != obj->map()); |
677 } | 677 } |
678 | 678 |
679 | 679 |
680 TEST(JSArray) { | 680 TEST(JSArray) { |
681 InitializeVM(); | 681 InitializeVM(); |
682 | 682 |
683 v8::HandleScope sc; | 683 v8::HandleScope sc; |
684 Handle<String> name = FACTORY->LookupAsciiSymbol("Array"); | 684 Handle<String> name = FACTORY->LookupUtf8Symbol("Array"); |
685 Object* raw_object = Isolate::Current()->context()->global_object()-> | 685 Object* raw_object = Isolate::Current()->context()->global_object()-> |
686 GetProperty(*name)->ToObjectChecked(); | 686 GetProperty(*name)->ToObjectChecked(); |
687 Handle<JSFunction> function = Handle<JSFunction>( | 687 Handle<JSFunction> function = Handle<JSFunction>( |
688 JSFunction::cast(raw_object)); | 688 JSFunction::cast(raw_object)); |
689 | 689 |
690 // Allocate the object. | 690 // Allocate the object. |
691 Handle<JSObject> object = FACTORY->NewJSObject(function); | 691 Handle<JSObject> object = FACTORY->NewJSObject(function); |
692 Handle<JSArray> array = Handle<JSArray>::cast(object); | 692 Handle<JSArray> array = Handle<JSArray>::cast(object); |
693 // We just initialized the VM, no heap allocation failure yet. | 693 // We just initialized the VM, no heap allocation failure yet. |
694 array->Initialize(0)->ToObjectChecked(); | 694 array->Initialize(0)->ToObjectChecked(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 TEST(JSObjectCopy) { | 727 TEST(JSObjectCopy) { |
728 InitializeVM(); | 728 InitializeVM(); |
729 | 729 |
730 v8::HandleScope sc; | 730 v8::HandleScope sc; |
731 String* object_symbol = String::cast(HEAP->Object_symbol()); | 731 String* object_symbol = String::cast(HEAP->Object_symbol()); |
732 Object* raw_object = Isolate::Current()->context()->global_object()-> | 732 Object* raw_object = Isolate::Current()->context()->global_object()-> |
733 GetProperty(object_symbol)->ToObjectChecked(); | 733 GetProperty(object_symbol)->ToObjectChecked(); |
734 JSFunction* object_function = JSFunction::cast(raw_object); | 734 JSFunction* object_function = JSFunction::cast(raw_object); |
735 Handle<JSFunction> constructor(object_function); | 735 Handle<JSFunction> constructor(object_function); |
736 Handle<JSObject> obj = FACTORY->NewJSObject(constructor); | 736 Handle<JSObject> obj = FACTORY->NewJSObject(constructor); |
737 Handle<String> first = FACTORY->LookupAsciiSymbol("first"); | 737 Handle<String> first = FACTORY->LookupUtf8Symbol("first"); |
738 Handle<String> second = FACTORY->LookupAsciiSymbol("second"); | 738 Handle<String> second = FACTORY->LookupUtf8Symbol("second"); |
739 | 739 |
740 obj->SetProperty( | 740 obj->SetProperty( |
741 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); | 741 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); |
742 obj->SetProperty( | 742 obj->SetProperty( |
743 *second, Smi::FromInt(2), NONE, kNonStrictMode)->ToObjectChecked(); | 743 *second, Smi::FromInt(2), NONE, kNonStrictMode)->ToObjectChecked(); |
744 | 744 |
745 obj->SetElement(0, *first, NONE, kNonStrictMode)->ToObjectChecked(); | 745 obj->SetElement(0, *first, NONE, kNonStrictMode)->ToObjectChecked(); |
746 obj->SetElement(1, *second, NONE, kNonStrictMode)->ToObjectChecked(); | 746 obj->SetElement(1, *second, NONE, kNonStrictMode)->ToObjectChecked(); |
747 | 747 |
748 // Make the clone. | 748 // Make the clone. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 char* ascii = NewArray<char>(length + 1); | 783 char* ascii = NewArray<char>(length + 1); |
784 non_ascii[3 * length] = 0; | 784 non_ascii[3 * length] = 0; |
785 ascii[length] = 0; | 785 ascii[length] = 0; |
786 for (int i = 0; i < length; i++) { | 786 for (int i = 0; i < length; i++) { |
787 ascii[i] = 'a'; | 787 ascii[i] = 'a'; |
788 non_ascii[3 * i] = chars[0]; | 788 non_ascii[3 * i] = chars[0]; |
789 non_ascii[3 * i + 1] = chars[1]; | 789 non_ascii[3 * i + 1] = chars[1]; |
790 non_ascii[3 * i + 2] = chars[2]; | 790 non_ascii[3 * i + 2] = chars[2]; |
791 } | 791 } |
792 Handle<String> non_ascii_sym = | 792 Handle<String> non_ascii_sym = |
793 FACTORY->LookupSymbol(Vector<const char>(non_ascii, 3 * length)); | 793 FACTORY->LookupUtf8Symbol(Vector<const char>(non_ascii, 3 * length)); |
794 CHECK_EQ(length, non_ascii_sym->length()); | 794 CHECK_EQ(length, non_ascii_sym->length()); |
795 Handle<String> ascii_sym = | 795 Handle<String> ascii_sym = |
796 FACTORY->LookupSymbol(Vector<const char>(ascii, length)); | 796 FACTORY->LookupOneByteSymbol(Vector<const char>(ascii, length)); |
797 CHECK_EQ(length, ascii_sym->length()); | 797 CHECK_EQ(length, ascii_sym->length()); |
798 Handle<String> non_ascii_str = | 798 Handle<String> non_ascii_str = |
799 FACTORY->NewStringFromUtf8(Vector<const char>(non_ascii, 3 * length)); | 799 FACTORY->NewStringFromUtf8(Vector<const char>(non_ascii, 3 * length)); |
800 non_ascii_str->Hash(); | 800 non_ascii_str->Hash(); |
801 CHECK_EQ(length, non_ascii_str->length()); | 801 CHECK_EQ(length, non_ascii_str->length()); |
802 Handle<String> ascii_str = | 802 Handle<String> ascii_str = |
803 FACTORY->NewStringFromUtf8(Vector<const char>(ascii, length)); | 803 FACTORY->NewStringFromUtf8(Vector<const char>(ascii, length)); |
804 ascii_str->Hash(); | 804 ascii_str->Hash(); |
805 CHECK_EQ(length, ascii_str->length()); | 805 CHECK_EQ(length, ascii_str->length()); |
806 DeleteArray(non_ascii); | 806 DeleteArray(non_ascii); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 if (!FLAG_flush_code) return; | 963 if (!FLAG_flush_code) return; |
964 i::FLAG_allow_natives_syntax = true; | 964 i::FLAG_allow_natives_syntax = true; |
965 InitializeVM(); | 965 InitializeVM(); |
966 v8::HandleScope scope; | 966 v8::HandleScope scope; |
967 const char* source = "function foo() {" | 967 const char* source = "function foo() {" |
968 " var x = 42;" | 968 " var x = 42;" |
969 " var y = 42;" | 969 " var y = 42;" |
970 " var z = x + y;" | 970 " var z = x + y;" |
971 "};" | 971 "};" |
972 "foo()"; | 972 "foo()"; |
973 Handle<String> foo_name = FACTORY->LookupAsciiSymbol("foo"); | 973 Handle<String> foo_name = FACTORY->LookupUtf8Symbol("foo"); |
974 | 974 |
975 // This compile will add the code to the compilation cache. | 975 // This compile will add the code to the compilation cache. |
976 { v8::HandleScope scope; | 976 { v8::HandleScope scope; |
977 CompileRun(source); | 977 CompileRun(source); |
978 } | 978 } |
979 | 979 |
980 // Check function is compiled. | 980 // Check function is compiled. |
981 Object* func_value = Isolate::Current()->context()->global_object()-> | 981 Object* func_value = Isolate::Current()->context()->global_object()-> |
982 GetProperty(*foo_name)->ToObjectChecked(); | 982 GetProperty(*foo_name)->ToObjectChecked(); |
983 CHECK(func_value->IsJSFunction()); | 983 CHECK(func_value->IsJSFunction()); |
(...skipping 26 matching lines...) Expand all Loading... |
1010 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return; | 1010 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return; |
1011 i::FLAG_allow_natives_syntax = true; | 1011 i::FLAG_allow_natives_syntax = true; |
1012 InitializeVM(); | 1012 InitializeVM(); |
1013 v8::HandleScope scope; | 1013 v8::HandleScope scope; |
1014 const char* source = "function foo() {" | 1014 const char* source = "function foo() {" |
1015 " var x = 42;" | 1015 " var x = 42;" |
1016 " var y = 42;" | 1016 " var y = 42;" |
1017 " var z = x + y;" | 1017 " var z = x + y;" |
1018 "};" | 1018 "};" |
1019 "foo()"; | 1019 "foo()"; |
1020 Handle<String> foo_name = FACTORY->LookupAsciiSymbol("foo"); | 1020 Handle<String> foo_name = FACTORY->LookupUtf8Symbol("foo"); |
1021 | 1021 |
1022 // This compile will add the code to the compilation cache. | 1022 // This compile will add the code to the compilation cache. |
1023 { v8::HandleScope scope; | 1023 { v8::HandleScope scope; |
1024 CompileRun(source); | 1024 CompileRun(source); |
1025 } | 1025 } |
1026 | 1026 |
1027 // Check function is compiled. | 1027 // Check function is compiled. |
1028 Object* func_value = Isolate::Current()->context()->global_object()-> | 1028 Object* func_value = Isolate::Current()->context()->global_object()-> |
1029 GetProperty(*foo_name)->ToObjectChecked(); | 1029 GetProperty(*foo_name)->ToObjectChecked(); |
1030 CHECK(func_value->IsJSFunction()); | 1030 CHECK(func_value->IsJSFunction()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1080 const char* source = "var foo = function() {" | 1080 const char* source = "var foo = function() {" |
1081 " var x = 42;" | 1081 " var x = 42;" |
1082 " var y = 42;" | 1082 " var y = 42;" |
1083 " var z = x + y;" | 1083 " var z = x + y;" |
1084 "};" | 1084 "};" |
1085 "foo();" | 1085 "foo();" |
1086 "var bar = function() {" | 1086 "var bar = function() {" |
1087 " var x = 23;" | 1087 " var x = 23;" |
1088 "};" | 1088 "};" |
1089 "bar();"; | 1089 "bar();"; |
1090 Handle<String> foo_name = FACTORY->LookupAsciiSymbol("foo"); | 1090 Handle<String> foo_name = FACTORY->LookupUtf8Symbol("foo"); |
1091 Handle<String> bar_name = FACTORY->LookupAsciiSymbol("bar"); | 1091 Handle<String> bar_name = FACTORY->LookupUtf8Symbol("bar"); |
1092 | 1092 |
1093 // Perfrom one initial GC to enable code flushing. | 1093 // Perfrom one initial GC to enable code flushing. |
1094 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 1094 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
1095 | 1095 |
1096 // This compile will add the code to the compilation cache. | 1096 // This compile will add the code to the compilation cache. |
1097 { v8::HandleScope scope; | 1097 { v8::HandleScope scope; |
1098 CompileRun(source); | 1098 CompileRun(source); |
1099 } | 1099 } |
1100 | 1100 |
1101 // Check functions are compiled. | 1101 // Check functions are compiled. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1142 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return; | 1142 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return; |
1143 i::FLAG_allow_natives_syntax = true; | 1143 i::FLAG_allow_natives_syntax = true; |
1144 InitializeVM(); | 1144 InitializeVM(); |
1145 v8::HandleScope scope; | 1145 v8::HandleScope scope; |
1146 const char* source = "function foo() {" | 1146 const char* source = "function foo() {" |
1147 " var x = 42;" | 1147 " var x = 42;" |
1148 " var y = 42;" | 1148 " var y = 42;" |
1149 " var z = x + y;" | 1149 " var z = x + y;" |
1150 "};" | 1150 "};" |
1151 "foo()"; | 1151 "foo()"; |
1152 Handle<String> foo_name = FACTORY->LookupAsciiSymbol("foo"); | 1152 Handle<String> foo_name = FACTORY->LookupUtf8Symbol("foo"); |
1153 | 1153 |
1154 // This compile will add the code to the compilation cache. | 1154 // This compile will add the code to the compilation cache. |
1155 { v8::HandleScope scope; | 1155 { v8::HandleScope scope; |
1156 CompileRun(source); | 1156 CompileRun(source); |
1157 } | 1157 } |
1158 | 1158 |
1159 // Check function is compiled. | 1159 // Check function is compiled. |
1160 Object* func_value = Isolate::Current()->context()->global_object()-> | 1160 Object* func_value = Isolate::Current()->context()->global_object()-> |
1161 GetProperty(*foo_name)->ToObjectChecked(); | 1161 GetProperty(*foo_name)->ToObjectChecked(); |
1162 CHECK(func_value->IsJSFunction()); | 1162 CHECK(func_value->IsJSFunction()); |
(...skipping 1323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2486 CompileRun("for (var i = 0; i < 2000; i++) {" | 2486 CompileRun("for (var i = 0; i < 2000; i++) {" |
2487 " eval('function f' + i + '() { return ' + i +'; };' +" | 2487 " eval('function f' + i + '() { return ' + i +'; };' +" |
2488 " 'f' + i + '();');" | 2488 " 'f' + i + '();');" |
2489 "}"); | 2489 "}"); |
2490 } | 2490 } |
2491 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 2491 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
2492 | 2492 |
2493 // Fourth is the tricky part. Make sure the code containing the CallIC is | 2493 // Fourth is the tricky part. Make sure the code containing the CallIC is |
2494 // visited first without clearing the IC. The shared function info is then | 2494 // visited first without clearing the IC. The shared function info is then |
2495 // visited later, causing the CallIC to be cleared. | 2495 // visited later, causing the CallIC to be cleared. |
2496 Handle<String> name = FACTORY->LookupAsciiSymbol("call"); | 2496 Handle<String> name = FACTORY->LookupUtf8Symbol("call"); |
2497 Handle<GlobalObject> global(ISOLATE->context()->global_object()); | 2497 Handle<GlobalObject> global(ISOLATE->context()->global_object()); |
2498 MaybeObject* maybe_call = global->GetProperty(*name); | 2498 MaybeObject* maybe_call = global->GetProperty(*name); |
2499 JSFunction* call = JSFunction::cast(maybe_call->ToObjectChecked()); | 2499 JSFunction* call = JSFunction::cast(maybe_call->ToObjectChecked()); |
2500 USE(global->SetProperty(*name, Smi::FromInt(0), NONE, kNonStrictMode)); | 2500 USE(global->SetProperty(*name, Smi::FromInt(0), NONE, kNonStrictMode)); |
2501 ISOLATE->compilation_cache()->Clear(); | 2501 ISOLATE->compilation_cache()->Clear(); |
2502 call->shared()->set_ic_age(HEAP->global_ic_age() + 1); | 2502 call->shared()->set_ic_age(HEAP->global_ic_age() + 1); |
2503 Handle<Object> call_code(call->code()); | 2503 Handle<Object> call_code(call->code()); |
2504 Handle<Object> call_function(call); | 2504 Handle<Object> call_function(call); |
2505 | 2505 |
2506 // Now we are ready to mess up the heap. | 2506 // Now we are ready to mess up the heap. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2609 | 2609 |
2610 // Simulate incremental marking so that unoptimized code is flushed | 2610 // Simulate incremental marking so that unoptimized code is flushed |
2611 // even though it still is cached in the optimized code map. | 2611 // even though it still is cached in the optimized code map. |
2612 SimulateIncrementalMarking(); | 2612 SimulateIncrementalMarking(); |
2613 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 2613 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
2614 | 2614 |
2615 // Make a new closure that will get code installed from the code map. | 2615 // Make a new closure that will get code installed from the code map. |
2616 // Unoptimized code is missing and the deoptimizer will go ballistic. | 2616 // Unoptimized code is missing and the deoptimizer will go ballistic. |
2617 CompileRun("var g = mkClosure(); g('bozo');"); | 2617 CompileRun("var g = mkClosure(); g('bozo');"); |
2618 } | 2618 } |
OLD | NEW |