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

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

Powered by Google App Engine
This is Rietveld 408576698