Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1751)

Side by Side Diff: test/cctest/test-heap.cc

Issue 229973004: Remove calls to non-handlified version of GetProperty(name). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: update Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-compiler.cc ('k') | test/cctest/test-mark-compact.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 286 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
287 function->set_initial_map(*initial_map); 287 function->set_initial_map(*initial_map);
288 JSReceiver::SetProperty(global, name, function, NONE, SLOPPY).Check(); 288 JSReceiver::SetProperty(global, name, function, NONE, SLOPPY).Check();
289 // Allocate an object. Unrooted after leaving the scope. 289 // Allocate an object. Unrooted after leaving the scope.
290 Handle<JSObject> obj = factory->NewJSObject(function); 290 Handle<JSObject> obj = factory->NewJSObject(function);
291 JSReceiver::SetProperty( 291 JSReceiver::SetProperty(
292 obj, prop_name, twenty_three, NONE, SLOPPY).Check(); 292 obj, prop_name, twenty_three, NONE, SLOPPY).Check();
293 JSReceiver::SetProperty( 293 JSReceiver::SetProperty(
294 obj, prop_namex, twenty_four, NONE, SLOPPY).Check(); 294 obj, prop_namex, twenty_four, NONE, SLOPPY).Check();
295 295
296 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); 296 CHECK_EQ(Smi::FromInt(23), *Object::GetProperty(obj, prop_name));
297 CHECK_EQ(Smi::FromInt(24), obj->GetProperty(*prop_namex)); 297 CHECK_EQ(Smi::FromInt(24), *Object::GetProperty(obj, prop_namex));
298 } 298 }
299 299
300 heap->CollectGarbage(NEW_SPACE); 300 heap->CollectGarbage(NEW_SPACE);
301 301
302 // Function should be alive. 302 // Function should be alive.
303 CHECK(JSReceiver::HasLocalProperty(global, name)); 303 CHECK(JSReceiver::HasLocalProperty(global, name));
304 // Check function is retained. 304 // Check function is retained.
305 Object* func_value = CcTest::i_isolate()->context()->global_object()-> 305 Handle<Object> func_value = Object::GetProperty(global, name);
306 GetProperty(*name)->ToObjectChecked();
307 CHECK(func_value->IsJSFunction()); 306 CHECK(func_value->IsJSFunction());
308 Handle<JSFunction> function(JSFunction::cast(func_value)); 307 Handle<JSFunction> function = Handle<JSFunction>::cast(func_value);
309 308
310 { 309 {
311 HandleScope inner_scope(isolate); 310 HandleScope inner_scope(isolate);
312 // Allocate another object, make it reachable from global. 311 // Allocate another object, make it reachable from global.
313 Handle<JSObject> obj = factory->NewJSObject(function); 312 Handle<JSObject> obj = factory->NewJSObject(function);
314 JSReceiver::SetProperty(global, obj_name, obj, NONE, SLOPPY).Check(); 313 JSReceiver::SetProperty(global, obj_name, obj, NONE, SLOPPY).Check();
315 JSReceiver::SetProperty( 314 JSReceiver::SetProperty(
316 obj, prop_name, twenty_three, NONE, SLOPPY).Check(); 315 obj, prop_name, twenty_three, NONE, SLOPPY).Check();
317 } 316 }
318 317
319 // After gc, it should survive. 318 // After gc, it should survive.
320 heap->CollectGarbage(NEW_SPACE); 319 heap->CollectGarbage(NEW_SPACE);
321 320
322 CHECK(JSReceiver::HasLocalProperty(global, obj_name)); 321 CHECK(JSReceiver::HasLocalProperty(global, obj_name));
323 CHECK(CcTest::i_isolate()->context()->global_object()-> 322 Handle<Object> obj = Object::GetProperty(global, obj_name);
324 GetProperty(*obj_name)->ToObjectChecked()->IsJSObject()); 323 CHECK(obj->IsJSObject());
325 Object* obj = CcTest::i_isolate()->context()->global_object()-> 324 CHECK_EQ(Smi::FromInt(23), *Object::GetProperty(obj, prop_name));
326 GetProperty(*obj_name)->ToObjectChecked();
327 JSObject* js_obj = JSObject::cast(obj);
328 CHECK_EQ(Smi::FromInt(23), js_obj->GetProperty(*prop_name));
329 } 325 }
330 326
331 327
332 static void VerifyStringAllocation(Isolate* isolate, const char* string) { 328 static void VerifyStringAllocation(Isolate* isolate, const char* string) {
333 HandleScope scope(isolate); 329 HandleScope scope(isolate);
334 Handle<String> s = isolate->factory()->NewStringFromUtf8(CStrVector(string)); 330 Handle<String> s = isolate->factory()->NewStringFromUtf8(CStrVector(string));
335 CHECK_EQ(StrLength(string), s->length()); 331 CHECK_EQ(StrLength(string), s->length());
336 for (int index = 0; index < s->length(); index++) { 332 for (int index = 0; index < s->length(); index++) {
337 CHECK_EQ(static_cast<uint16_t>(string[index]), s->Get(index)); 333 CHECK_EQ(static_cast<uint16_t>(string[index]), s->Get(index));
338 } 334 }
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 Handle<Map> initial_map = 638 Handle<Map> initial_map =
643 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 639 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
644 function->set_initial_map(*initial_map); 640 function->set_initial_map(*initial_map);
645 641
646 Handle<Smi> twenty_three(Smi::FromInt(23), isolate); 642 Handle<Smi> twenty_three(Smi::FromInt(23), isolate);
647 Handle<Smi> twenty_four(Smi::FromInt(24), isolate); 643 Handle<Smi> twenty_four(Smi::FromInt(24), isolate);
648 644
649 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot"); 645 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot");
650 Handle<JSObject> obj = factory->NewJSObject(function); 646 Handle<JSObject> obj = factory->NewJSObject(function);
651 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, SLOPPY).Check(); 647 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, SLOPPY).Check();
652 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); 648 CHECK_EQ(Smi::FromInt(23), *Object::GetProperty(obj, prop_name));
653 // Check that we can add properties to function objects. 649 // Check that we can add properties to function objects.
654 JSReceiver::SetProperty( 650 JSReceiver::SetProperty(
655 function, prop_name, twenty_four, NONE, SLOPPY).Check(); 651 function, prop_name, twenty_four, NONE, SLOPPY).Check();
656 CHECK_EQ(Smi::FromInt(24), function->GetProperty(*prop_name)); 652 CHECK_EQ(Smi::FromInt(24), *Object::GetProperty(function, prop_name));
657 } 653 }
658 654
659 655
660 TEST(ObjectProperties) { 656 TEST(ObjectProperties) {
661 CcTest::InitializeVM(); 657 CcTest::InitializeVM();
662 Isolate* isolate = CcTest::i_isolate(); 658 Isolate* isolate = CcTest::i_isolate();
663 Factory* factory = isolate->factory(); 659 Factory* factory = isolate->factory();
664 660
665 v8::HandleScope sc(CcTest::isolate()); 661 v8::HandleScope sc(CcTest::isolate());
666 String* object_string = String::cast(CcTest::heap()->Object_string()); 662 Handle<String> object_string(String::cast(CcTest::heap()->Object_string()));
667 Object* raw_object = CcTest::i_isolate()->context()->global_object()-> 663 Handle<Object> object =
668 GetProperty(object_string)->ToObjectChecked(); 664 Object::GetProperty(CcTest::i_isolate()->global_object(), object_string);
669 JSFunction* object_function = JSFunction::cast(raw_object); 665 Handle<JSFunction> constructor = Handle<JSFunction>::cast(object);
670 Handle<JSFunction> constructor(object_function);
671 Handle<JSObject> obj = factory->NewJSObject(constructor); 666 Handle<JSObject> obj = factory->NewJSObject(constructor);
672 Handle<String> first = factory->InternalizeUtf8String("first"); 667 Handle<String> first = factory->InternalizeUtf8String("first");
673 Handle<String> second = factory->InternalizeUtf8String("second"); 668 Handle<String> second = factory->InternalizeUtf8String("second");
674 669
675 Handle<Smi> one(Smi::FromInt(1), isolate); 670 Handle<Smi> one(Smi::FromInt(1), isolate);
676 Handle<Smi> two(Smi::FromInt(2), isolate); 671 Handle<Smi> two(Smi::FromInt(2), isolate);
677 672
678 // check for empty 673 // check for empty
679 CHECK(!JSReceiver::HasLocalProperty(obj, first)); 674 CHECK(!JSReceiver::HasLocalProperty(obj, first));
680 675
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 Handle<Map> initial_map = 735 Handle<Map> initial_map =
741 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 736 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
742 function->set_initial_map(*initial_map); 737 function->set_initial_map(*initial_map);
743 738
744 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot"); 739 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot");
745 Handle<JSObject> obj = factory->NewJSObject(function); 740 Handle<JSObject> obj = factory->NewJSObject(function);
746 741
747 // Set a propery 742 // Set a propery
748 Handle<Smi> twenty_three(Smi::FromInt(23), isolate); 743 Handle<Smi> twenty_three(Smi::FromInt(23), isolate);
749 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, SLOPPY).Check(); 744 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, SLOPPY).Check();
750 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); 745 CHECK_EQ(Smi::FromInt(23), *Object::GetProperty(obj, prop_name));
751 746
752 // Check the map has changed 747 // Check the map has changed
753 CHECK(*initial_map != obj->map()); 748 CHECK(*initial_map != obj->map());
754 } 749 }
755 750
756 751
757 TEST(JSArray) { 752 TEST(JSArray) {
758 CcTest::InitializeVM(); 753 CcTest::InitializeVM();
759 Isolate* isolate = CcTest::i_isolate(); 754 Isolate* isolate = CcTest::i_isolate();
760 Factory* factory = isolate->factory(); 755 Factory* factory = isolate->factory();
761 756
762 v8::HandleScope sc(CcTest::isolate()); 757 v8::HandleScope sc(CcTest::isolate());
763 Handle<String> name = factory->InternalizeUtf8String("Array"); 758 Handle<String> name = factory->InternalizeUtf8String("Array");
764 Object* raw_object = CcTest::i_isolate()->context()->global_object()-> 759 Handle<Object> fun_obj =
765 GetProperty(*name)->ToObjectChecked(); 760 Object::GetProperty(CcTest::i_isolate()->global_object(), name);
766 Handle<JSFunction> function = Handle<JSFunction>( 761 Handle<JSFunction> function = Handle<JSFunction>::cast(fun_obj);
767 JSFunction::cast(raw_object));
768 762
769 // Allocate the object. 763 // Allocate the object.
770 Handle<JSObject> object = factory->NewJSObject(function); 764 Handle<JSObject> object = factory->NewJSObject(function);
771 Handle<JSArray> array = Handle<JSArray>::cast(object); 765 Handle<JSArray> array = Handle<JSArray>::cast(object);
772 // We just initialized the VM, no heap allocation failure yet. 766 // We just initialized the VM, no heap allocation failure yet.
773 JSArray::Initialize(array, 0); 767 JSArray::Initialize(array, 0);
774 768
775 // Set array length to 0. 769 // Set array length to 0.
776 *JSArray::SetElementsLength(array, handle(Smi::FromInt(0), isolate)); 770 *JSArray::SetElementsLength(array, handle(Smi::FromInt(0), isolate));
777 CHECK_EQ(Smi::FromInt(0), array->length()); 771 CHECK_EQ(Smi::FromInt(0), array->length());
(...skipping 24 matching lines...) Expand all
802 CHECK_EQ(*i::Object::GetElement(isolate, array, 0), *name); 796 CHECK_EQ(*i::Object::GetElement(isolate, array, 0), *name);
803 } 797 }
804 798
805 799
806 TEST(JSObjectCopy) { 800 TEST(JSObjectCopy) {
807 CcTest::InitializeVM(); 801 CcTest::InitializeVM();
808 Isolate* isolate = CcTest::i_isolate(); 802 Isolate* isolate = CcTest::i_isolate();
809 Factory* factory = isolate->factory(); 803 Factory* factory = isolate->factory();
810 804
811 v8::HandleScope sc(CcTest::isolate()); 805 v8::HandleScope sc(CcTest::isolate());
812 String* object_string = String::cast(CcTest::heap()->Object_string()); 806 Handle<String> object_string(String::cast(CcTest::heap()->Object_string()));
813 Object* raw_object = CcTest::i_isolate()->context()->global_object()-> 807 Handle<Object> object =
814 GetProperty(object_string)->ToObjectChecked(); 808 Object::GetProperty(CcTest::i_isolate()->global_object(), object_string);
815 JSFunction* object_function = JSFunction::cast(raw_object); 809 Handle<JSFunction> constructor = Handle<JSFunction>::cast(object);
816 Handle<JSFunction> constructor(object_function);
817 Handle<JSObject> obj = factory->NewJSObject(constructor); 810 Handle<JSObject> obj = factory->NewJSObject(constructor);
818 Handle<String> first = factory->InternalizeUtf8String("first"); 811 Handle<String> first = factory->InternalizeUtf8String("first");
819 Handle<String> second = factory->InternalizeUtf8String("second"); 812 Handle<String> second = factory->InternalizeUtf8String("second");
820 813
821 Handle<Smi> one(Smi::FromInt(1), isolate); 814 Handle<Smi> one(Smi::FromInt(1), isolate);
822 Handle<Smi> two(Smi::FromInt(2), isolate); 815 Handle<Smi> two(Smi::FromInt(2), isolate);
823 816
824 JSReceiver::SetProperty(obj, first, one, NONE, SLOPPY).Check(); 817 JSReceiver::SetProperty(obj, first, one, NONE, SLOPPY).Check();
825 JSReceiver::SetProperty(obj, second, two, NONE, SLOPPY).Check(); 818 JSReceiver::SetProperty(obj, second, two, NONE, SLOPPY).Check();
826 819
827 JSReceiver::SetElement(obj, 0, first, NONE, SLOPPY).Check(); 820 JSReceiver::SetElement(obj, 0, first, NONE, SLOPPY).Check();
828 JSReceiver::SetElement(obj, 1, second, NONE, SLOPPY).Check(); 821 JSReceiver::SetElement(obj, 1, second, NONE, SLOPPY).Check();
829 822
830 // Make the clone. 823 // Make the clone.
831 Handle<JSObject> clone = JSObject::Copy(obj); 824 Handle<JSObject> clone = JSObject::Copy(obj);
832 CHECK(!clone.is_identical_to(obj)); 825 CHECK(!clone.is_identical_to(obj));
833 826
834 CHECK_EQ(*i::Object::GetElement(isolate, obj, 0), 827 CHECK_EQ(*i::Object::GetElement(isolate, obj, 0),
835 *i::Object::GetElement(isolate, clone, 0)); 828 *i::Object::GetElement(isolate, clone, 0));
836 CHECK_EQ(*i::Object::GetElement(isolate, obj, 1), 829 CHECK_EQ(*i::Object::GetElement(isolate, obj, 1),
837 *i::Object::GetElement(isolate, clone, 1)); 830 *i::Object::GetElement(isolate, clone, 1));
838 831
839 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*first)); 832 CHECK_EQ(*Object::GetProperty(obj, first),
840 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*second)); 833 *Object::GetProperty(clone, first));
834 CHECK_EQ(*Object::GetProperty(obj, second),
835 *Object::GetProperty(clone, second));
841 836
842 // Flip the values. 837 // Flip the values.
843 JSReceiver::SetProperty(clone, first, two, NONE, SLOPPY).Check(); 838 JSReceiver::SetProperty(clone, first, two, NONE, SLOPPY).Check();
844 JSReceiver::SetProperty(clone, second, one, NONE, SLOPPY).Check(); 839 JSReceiver::SetProperty(clone, second, one, NONE, SLOPPY).Check();
845 840
846 JSReceiver::SetElement(clone, 0, second, NONE, SLOPPY).Check(); 841 JSReceiver::SetElement(clone, 0, second, NONE, SLOPPY).Check();
847 JSReceiver::SetElement(clone, 1, first, NONE, SLOPPY).Check(); 842 JSReceiver::SetElement(clone, 1, first, NONE, SLOPPY).Check();
848 843
849 CHECK_EQ(*i::Object::GetElement(isolate, obj, 1), 844 CHECK_EQ(*i::Object::GetElement(isolate, obj, 1),
850 *i::Object::GetElement(isolate, clone, 0)); 845 *i::Object::GetElement(isolate, clone, 0));
851 CHECK_EQ(*i::Object::GetElement(isolate, obj, 0), 846 CHECK_EQ(*i::Object::GetElement(isolate, obj, 0),
852 *i::Object::GetElement(isolate, clone, 1)); 847 *i::Object::GetElement(isolate, clone, 1));
853 848
854 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first)); 849 CHECK_EQ(*Object::GetProperty(obj, second),
855 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*second)); 850 *Object::GetProperty(clone, first));
851 CHECK_EQ(*Object::GetProperty(obj, first),
852 *Object::GetProperty(clone, second));
856 } 853 }
857 854
858 855
859 TEST(StringAllocation) { 856 TEST(StringAllocation) {
860 CcTest::InitializeVM(); 857 CcTest::InitializeVM();
861 Isolate* isolate = CcTest::i_isolate(); 858 Isolate* isolate = CcTest::i_isolate();
862 Factory* factory = isolate->factory(); 859 Factory* factory = isolate->factory();
863 860
864 const unsigned char chars[] = { 0xe5, 0xa4, 0xa7 }; 861 const unsigned char chars[] = { 0xe5, 0xa4, 0xa7 };
865 for (int length = 0; length < 100; length++) { 862 for (int length = 0; length < 100; length++) {
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 "};" 1061 "};"
1065 "foo()"; 1062 "foo()";
1066 Handle<String> foo_name = factory->InternalizeUtf8String("foo"); 1063 Handle<String> foo_name = factory->InternalizeUtf8String("foo");
1067 1064
1068 // This compile will add the code to the compilation cache. 1065 // This compile will add the code to the compilation cache.
1069 { v8::HandleScope scope(CcTest::isolate()); 1066 { v8::HandleScope scope(CcTest::isolate());
1070 CompileRun(source); 1067 CompileRun(source);
1071 } 1068 }
1072 1069
1073 // Check function is compiled. 1070 // Check function is compiled.
1074 Object* func_value = CcTest::i_isolate()->context()->global_object()-> 1071 Handle<Object> func_value =
1075 GetProperty(*foo_name)->ToObjectChecked(); 1072 Object::GetProperty(CcTest::i_isolate()->global_object(), foo_name);
1076 CHECK(func_value->IsJSFunction()); 1073 CHECK(func_value->IsJSFunction());
1077 Handle<JSFunction> function(JSFunction::cast(func_value)); 1074 Handle<JSFunction> function = Handle<JSFunction>::cast(func_value);
1078 CHECK(function->shared()->is_compiled()); 1075 CHECK(function->shared()->is_compiled());
1079 1076
1080 // The code will survive at least two GCs. 1077 // The code will survive at least two GCs.
1081 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 1078 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
1082 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 1079 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
1083 CHECK(function->shared()->is_compiled()); 1080 CHECK(function->shared()->is_compiled());
1084 1081
1085 // Simulate several GCs that use full marking. 1082 // Simulate several GCs that use full marking.
1086 const int kAgingThreshold = 6; 1083 const int kAgingThreshold = 6;
1087 for (int i = 0; i < kAgingThreshold; i++) { 1084 for (int i = 0; i < kAgingThreshold; i++) {
1088 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 1085 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
1089 } 1086 }
1090 1087
1091 // foo should no longer be in the compilation cache 1088 // foo should no longer be in the compilation cache
1092 CHECK(!function->shared()->is_compiled() || function->IsOptimized()); 1089 CHECK(!function->shared()->is_compiled() || function->IsOptimized());
1093 CHECK(!function->is_compiled() || function->IsOptimized()); 1090 CHECK(!function->is_compiled() || function->IsOptimized());
1094 // Call foo to get it recompiled. 1091 // Call foo to get it recompiled.
1095 CompileRun("foo()"); 1092 CompileRun("foo()");
1096 CHECK(function->shared()->is_compiled()); 1093 CHECK(function->shared()->is_compiled());
1097 CHECK(function->is_compiled()); 1094 CHECK(function->is_compiled());
1098 } 1095 }
1099 1096
1100 1097
1101 TEST(TestCodeFlushingPreAged) { 1098 TEST(TestCodeFlushingPreAged) {
1102 // If we do not flush code this test is invalid. 1099 // If we do not flush code this test is invalid.
1103 if (!FLAG_flush_code) return; 1100 if (!FLAG_flush_code) return;
1104 i::FLAG_allow_natives_syntax = true; 1101 i::FLAG_allow_natives_syntax = true;
1105 i::FLAG_optimize_for_size = true; 1102 i::FLAG_optimize_for_size = true;
1106 CcTest::InitializeVM(); 1103 CcTest::InitializeVM();
1107 Isolate* isolate = Isolate::Current(); 1104 Isolate* isolate = CcTest::i_isolate();
1108 Factory* factory = isolate->factory(); 1105 Factory* factory = isolate->factory();
1109 v8::HandleScope scope(CcTest::isolate()); 1106 v8::HandleScope scope(CcTest::isolate());
1110 const char* source = "function foo() {" 1107 const char* source = "function foo() {"
1111 " var x = 42;" 1108 " var x = 42;"
1112 " var y = 42;" 1109 " var y = 42;"
1113 " var z = x + y;" 1110 " var z = x + y;"
1114 "};" 1111 "};"
1115 "foo()"; 1112 "foo()";
1116 Handle<String> foo_name = factory->InternalizeUtf8String("foo"); 1113 Handle<String> foo_name = factory->InternalizeUtf8String("foo");
1117 1114
1118 // Compile foo, but don't run it. 1115 // Compile foo, but don't run it.
1119 { v8::HandleScope scope(CcTest::isolate()); 1116 { v8::HandleScope scope(CcTest::isolate());
1120 CompileRun(source); 1117 CompileRun(source);
1121 } 1118 }
1122 1119
1123 // Check function is compiled. 1120 // Check function is compiled.
1124 Object* func_value = Isolate::Current()->context()->global_object()-> 1121 Handle<Object> func_value =
1125 GetProperty(*foo_name)->ToObjectChecked(); 1122 Object::GetProperty(isolate->global_object(), foo_name);
1126 CHECK(func_value->IsJSFunction()); 1123 CHECK(func_value->IsJSFunction());
1127 Handle<JSFunction> function(JSFunction::cast(func_value)); 1124 Handle<JSFunction> function = Handle<JSFunction>::cast(func_value);
1128 CHECK(function->shared()->is_compiled()); 1125 CHECK(function->shared()->is_compiled());
1129 1126
1130 // The code has been run so will survive at least one GC. 1127 // The code has been run so will survive at least one GC.
1131 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 1128 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
1132 CHECK(function->shared()->is_compiled()); 1129 CHECK(function->shared()->is_compiled());
1133 1130
1134 // The code was only run once, so it should be pre-aged and collected on the 1131 // The code was only run once, so it should be pre-aged and collected on the
1135 // next GC. 1132 // next GC.
1136 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 1133 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
1137 CHECK(!function->shared()->is_compiled() || function->IsOptimized()); 1134 CHECK(!function->shared()->is_compiled() || function->IsOptimized());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 "};" 1176 "};"
1180 "foo()"; 1177 "foo()";
1181 Handle<String> foo_name = factory->InternalizeUtf8String("foo"); 1178 Handle<String> foo_name = factory->InternalizeUtf8String("foo");
1182 1179
1183 // This compile will add the code to the compilation cache. 1180 // This compile will add the code to the compilation cache.
1184 { v8::HandleScope scope(CcTest::isolate()); 1181 { v8::HandleScope scope(CcTest::isolate());
1185 CompileRun(source); 1182 CompileRun(source);
1186 } 1183 }
1187 1184
1188 // Check function is compiled. 1185 // Check function is compiled.
1189 Object* func_value = CcTest::i_isolate()->context()->global_object()-> 1186 Handle<Object> func_value =
1190 GetProperty(*foo_name)->ToObjectChecked(); 1187 Object::GetProperty(isolate->global_object(), foo_name);
1191 CHECK(func_value->IsJSFunction()); 1188 CHECK(func_value->IsJSFunction());
1192 Handle<JSFunction> function(JSFunction::cast(func_value)); 1189 Handle<JSFunction> function = Handle<JSFunction>::cast(func_value);
1193 CHECK(function->shared()->is_compiled()); 1190 CHECK(function->shared()->is_compiled());
1194 1191
1195 // The code will survive at least two GCs. 1192 // The code will survive at least two GCs.
1196 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 1193 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
1197 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 1194 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
1198 CHECK(function->shared()->is_compiled()); 1195 CHECK(function->shared()->is_compiled());
1199 1196
1200 // Simulate several GCs that use incremental marking. 1197 // Simulate several GCs that use incremental marking.
1201 const int kAgingThreshold = 6; 1198 const int kAgingThreshold = 6;
1202 for (int i = 0; i < kAgingThreshold; i++) { 1199 for (int i = 0; i < kAgingThreshold; i++) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 1253
1257 // Perfrom one initial GC to enable code flushing. 1254 // Perfrom one initial GC to enable code flushing.
1258 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 1255 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
1259 1256
1260 // This compile will add the code to the compilation cache. 1257 // This compile will add the code to the compilation cache.
1261 { v8::HandleScope scope(CcTest::isolate()); 1258 { v8::HandleScope scope(CcTest::isolate());
1262 CompileRun(source); 1259 CompileRun(source);
1263 } 1260 }
1264 1261
1265 // Check functions are compiled. 1262 // Check functions are compiled.
1266 Object* func_value = CcTest::i_isolate()->context()->global_object()-> 1263 Handle<Object> func_value =
1267 GetProperty(*foo_name)->ToObjectChecked(); 1264 Object::GetProperty(isolate->global_object(), foo_name);
1268 CHECK(func_value->IsJSFunction()); 1265 CHECK(func_value->IsJSFunction());
1269 Handle<JSFunction> function(JSFunction::cast(func_value)); 1266 Handle<JSFunction> function = Handle<JSFunction>::cast(func_value);
1270 CHECK(function->shared()->is_compiled()); 1267 CHECK(function->shared()->is_compiled());
1271 Object* func_value2 = CcTest::i_isolate()->context()->global_object()-> 1268 Handle<Object> func_value2 =
1272 GetProperty(*bar_name)->ToObjectChecked(); 1269 Object::GetProperty(isolate->global_object(), bar_name);
1273 CHECK(func_value2->IsJSFunction()); 1270 CHECK(func_value2->IsJSFunction());
1274 Handle<JSFunction> function2(JSFunction::cast(func_value2)); 1271 Handle<JSFunction> function2 = Handle<JSFunction>::cast(func_value2);
1275 CHECK(function2->shared()->is_compiled()); 1272 CHECK(function2->shared()->is_compiled());
1276 1273
1277 // Clear references to functions so that one of them can die. 1274 // Clear references to functions so that one of them can die.
1278 { v8::HandleScope scope(CcTest::isolate()); 1275 { v8::HandleScope scope(CcTest::isolate());
1279 CompileRun("foo = 0; bar = 0;"); 1276 CompileRun("foo = 0; bar = 0;");
1280 } 1277 }
1281 1278
1282 // Bump the code age so that flushing is triggered while the function 1279 // Bump the code age so that flushing is triggered while the function
1283 // object is still located in new-space. 1280 // object is still located in new-space.
1284 const int kAgingThreshold = 6; 1281 const int kAgingThreshold = 6;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1318 "};" 1315 "};"
1319 "foo()"; 1316 "foo()";
1320 Handle<String> foo_name = factory->InternalizeUtf8String("foo"); 1317 Handle<String> foo_name = factory->InternalizeUtf8String("foo");
1321 1318
1322 // This compile will add the code to the compilation cache. 1319 // This compile will add the code to the compilation cache.
1323 { v8::HandleScope scope(CcTest::isolate()); 1320 { v8::HandleScope scope(CcTest::isolate());
1324 CompileRun(source); 1321 CompileRun(source);
1325 } 1322 }
1326 1323
1327 // Check function is compiled. 1324 // Check function is compiled.
1328 Object* func_value = CcTest::i_isolate()->context()->global_object()-> 1325 Handle<Object> func_value =
1329 GetProperty(*foo_name)->ToObjectChecked(); 1326 Object::GetProperty(isolate->global_object(), foo_name);
1330 CHECK(func_value->IsJSFunction()); 1327 CHECK(func_value->IsJSFunction());
1331 Handle<JSFunction> function(JSFunction::cast(func_value)); 1328 Handle<JSFunction> function = Handle<JSFunction>::cast(func_value);
1332 CHECK(function->shared()->is_compiled()); 1329 CHECK(function->shared()->is_compiled());
1333 1330
1334 // The code will survive at least two GCs. 1331 // The code will survive at least two GCs.
1335 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 1332 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
1336 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 1333 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
1337 CHECK(function->shared()->is_compiled()); 1334 CHECK(function->shared()->is_compiled());
1338 1335
1339 // Bump the code age so that flushing is triggered. 1336 // Bump the code age so that flushing is triggered.
1340 const int kAgingThreshold = 6; 1337 const int kAgingThreshold = 6;
1341 for (int i = 0; i < kAgingThreshold; i++) { 1338 for (int i = 0; i < kAgingThreshold; i++) {
(...skipping 2595 matching lines...) Expand 10 before | Expand all | Expand 10 after
3937 v8::Context::Scope cscope(context); 3934 v8::Context::Scope cscope(context);
3938 3935
3939 v8::Local<v8::Value> result = CompileRun( 3936 v8::Local<v8::Value> result = CompileRun(
3940 "var locals = '';" 3937 "var locals = '';"
3941 "for (var i = 0; i < 512; i++) locals += 'var v' + i + '= 42;';" 3938 "for (var i = 0; i < 512; i++) locals += 'var v' + i + '= 42;';"
3942 "eval('function f() {' + locals + 'return function() { return v0; }; }');" 3939 "eval('function f() {' + locals + 'return function() { return v0; }; }');"
3943 "interrupt();" // This triggers a fake stack overflow in f. 3940 "interrupt();" // This triggers a fake stack overflow in f.
3944 "f()()"); 3941 "f()()");
3945 CHECK_EQ(42.0, result->ToNumber()->Value()); 3942 CHECK_EQ(42.0, result->ToNumber()->Value());
3946 } 3943 }
OLDNEW
« no previous file with comments | « test/cctest/test-compiler.cc ('k') | test/cctest/test-mark-compact.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698