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

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

Issue 12716010: Added a version of the v8::HandleScope constructor with an Isolate and use that consistently. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed rest Created 7 years, 9 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 25 matching lines...) Expand all
36 #include "global-handles.h" 36 #include "global-handles.h"
37 #include "stub-cache.h" 37 #include "stub-cache.h"
38 #include "cctest.h" 38 #include "cctest.h"
39 39
40 using namespace v8::internal; 40 using namespace v8::internal;
41 41
42 static v8::Persistent<v8::Context> env; 42 static v8::Persistent<v8::Context> env;
43 43
44 static void InitializeVM() { 44 static void InitializeVM() {
45 if (env.IsEmpty()) env = v8::Context::New(); 45 if (env.IsEmpty()) env = v8::Context::New();
46 v8::HandleScope scope;
47 env->Enter(); 46 env->Enter();
48 } 47 }
49 48
50 49
51 // Go through all incremental marking steps in one swoop. 50 // Go through all incremental marking steps in one swoop.
52 static void SimulateIncrementalMarking() { 51 static void SimulateIncrementalMarking() {
53 MarkCompactCollector* collector = HEAP->mark_compact_collector(); 52 MarkCompactCollector* collector = HEAP->mark_compact_collector();
54 IncrementalMarking* marking = HEAP->incremental_marking(); 53 IncrementalMarking* marking = HEAP->incremental_marking();
55 if (collector->IsConcurrentSweepingInProgress()) { 54 if (collector->IsConcurrentSweepingInProgress()) {
56 collector->WaitUntilSweepingCompleted(); 55 collector->WaitUntilSweepingCompleted();
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 obj_copy->Size() / 2); 148 obj_copy->Size() / 2);
150 CHECK(not_right != code); 149 CHECK(not_right != code);
151 } 150 }
152 151
153 152
154 TEST(HeapObjects) { 153 TEST(HeapObjects) {
155 InitializeVM(); 154 InitializeVM();
156 Isolate* isolate = Isolate::Current(); 155 Isolate* isolate = Isolate::Current();
157 Heap* heap = isolate->heap(); 156 Heap* heap = isolate->heap();
158 157
159 v8::HandleScope sc; 158 HandleScope sc(isolate);
160 Object* value = heap->NumberFromDouble(1.000123)->ToObjectChecked(); 159 Object* value = heap->NumberFromDouble(1.000123)->ToObjectChecked();
161 CHECK(value->IsHeapNumber()); 160 CHECK(value->IsHeapNumber());
162 CHECK(value->IsNumber()); 161 CHECK(value->IsNumber());
163 CHECK_EQ(1.000123, value->Number()); 162 CHECK_EQ(1.000123, value->Number());
164 163
165 value = heap->NumberFromDouble(1.0)->ToObjectChecked(); 164 value = heap->NumberFromDouble(1.0)->ToObjectChecked();
166 CHECK(value->IsSmi()); 165 CHECK(value->IsSmi());
167 CHECK(value->IsNumber()); 166 CHECK(value->IsNumber());
168 CHECK_EQ(1.0, value->Number()); 167 CHECK_EQ(1.0, value->Number());
169 168
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 CHECK(Smi::FromInt(Smi::kMaxValue)->IsSmi()); 250 CHECK(Smi::FromInt(Smi::kMaxValue)->IsSmi());
252 } 251 }
253 252
254 253
255 TEST(GarbageCollection) { 254 TEST(GarbageCollection) {
256 InitializeVM(); 255 InitializeVM();
257 Isolate* isolate = Isolate::Current(); 256 Isolate* isolate = Isolate::Current();
258 Heap* heap = isolate->heap(); 257 Heap* heap = isolate->heap();
259 Factory* factory = isolate->factory(); 258 Factory* factory = isolate->factory();
260 259
261 v8::HandleScope sc; 260 HandleScope sc(isolate);
262 // Check GC. 261 // Check GC.
263 heap->CollectGarbage(NEW_SPACE); 262 heap->CollectGarbage(NEW_SPACE);
264 263
265 Handle<String> name = factory->InternalizeUtf8String("theFunction"); 264 Handle<String> name = factory->InternalizeUtf8String("theFunction");
266 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot"); 265 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot");
267 Handle<String> prop_namex = factory->InternalizeUtf8String("theSlotx"); 266 Handle<String> prop_namex = factory->InternalizeUtf8String("theSlotx");
268 Handle<String> obj_name = factory->InternalizeUtf8String("theObject"); 267 Handle<String> obj_name = factory->InternalizeUtf8String("theObject");
269 268
270 { 269 {
271 HandleScope inner_scope(isolate); 270 HandleScope inner_scope(isolate);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 HasLocalProperty(*obj_name)); 315 HasLocalProperty(*obj_name));
317 CHECK(Isolate::Current()->context()->global_object()-> 316 CHECK(Isolate::Current()->context()->global_object()->
318 GetProperty(*obj_name)->ToObjectChecked()->IsJSObject()); 317 GetProperty(*obj_name)->ToObjectChecked()->IsJSObject());
319 Object* obj = Isolate::Current()->context()->global_object()-> 318 Object* obj = Isolate::Current()->context()->global_object()->
320 GetProperty(*obj_name)->ToObjectChecked(); 319 GetProperty(*obj_name)->ToObjectChecked();
321 JSObject* js_obj = JSObject::cast(obj); 320 JSObject* js_obj = JSObject::cast(obj);
322 CHECK_EQ(Smi::FromInt(23), js_obj->GetProperty(*prop_name)); 321 CHECK_EQ(Smi::FromInt(23), js_obj->GetProperty(*prop_name));
323 } 322 }
324 323
325 324
326 static void VerifyStringAllocation(const char* string) { 325 static void VerifyStringAllocation(Isolate* isolate, const char* string) {
327 v8::HandleScope scope; 326 HandleScope scope(isolate);
328 Handle<String> s = FACTORY->NewStringFromUtf8(CStrVector(string)); 327 Handle<String> s = isolate->factory()->NewStringFromUtf8(CStrVector(string));
329 CHECK_EQ(StrLength(string), s->length()); 328 CHECK_EQ(StrLength(string), s->length());
330 for (int index = 0; index < s->length(); index++) { 329 for (int index = 0; index < s->length(); index++) {
331 CHECK_EQ(static_cast<uint16_t>(string[index]), s->Get(index)); 330 CHECK_EQ(static_cast<uint16_t>(string[index]), s->Get(index));
332 } 331 }
333 } 332 }
334 333
335 334
336 TEST(String) { 335 TEST(String) {
337 InitializeVM(); 336 InitializeVM();
337 Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate());
338 338
339 VerifyStringAllocation("a"); 339 VerifyStringAllocation(isolate, "a");
340 VerifyStringAllocation("ab"); 340 VerifyStringAllocation(isolate, "ab");
341 VerifyStringAllocation("abc"); 341 VerifyStringAllocation(isolate, "abc");
342 VerifyStringAllocation("abcd"); 342 VerifyStringAllocation(isolate, "abcd");
343 VerifyStringAllocation("fiskerdrengen er paa havet"); 343 VerifyStringAllocation(isolate, "fiskerdrengen er paa havet");
344 } 344 }
345 345
346 346
347 TEST(LocalHandles) { 347 TEST(LocalHandles) {
348 InitializeVM(); 348 InitializeVM();
349 349
350 v8::HandleScope scope; 350 v8::HandleScope scope(env->GetIsolate());
351 const char* name = "Kasper the spunky"; 351 const char* name = "Kasper the spunky";
352 Handle<String> string = FACTORY->NewStringFromAscii(CStrVector(name)); 352 Handle<String> string = FACTORY->NewStringFromAscii(CStrVector(name));
353 CHECK_EQ(StrLength(name), string->length()); 353 CHECK_EQ(StrLength(name), string->length());
354 } 354 }
355 355
356 356
357 TEST(GlobalHandles) { 357 TEST(GlobalHandles) {
358 InitializeVM(); 358 InitializeVM();
359 Isolate* isolate = Isolate::Current(); 359 Isolate* isolate = Isolate::Current();
360 Heap* heap = isolate->heap(); 360 Heap* heap = isolate->heap();
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 InitializeVM(); 613 InitializeVM();
614 614
615 CheckInternalizedStrings(not_so_random_string_table); 615 CheckInternalizedStrings(not_so_random_string_table);
616 CheckInternalizedStrings(not_so_random_string_table); 616 CheckInternalizedStrings(not_so_random_string_table);
617 } 617 }
618 618
619 619
620 TEST(FunctionAllocation) { 620 TEST(FunctionAllocation) {
621 InitializeVM(); 621 InitializeVM();
622 622
623 v8::HandleScope sc; 623 v8::HandleScope sc(env->GetIsolate());
624 Handle<String> name = FACTORY->InternalizeUtf8String("theFunction"); 624 Handle<String> name = FACTORY->InternalizeUtf8String("theFunction");
625 Handle<JSFunction> function = 625 Handle<JSFunction> function =
626 FACTORY->NewFunction(name, FACTORY->undefined_value()); 626 FACTORY->NewFunction(name, FACTORY->undefined_value());
627 Handle<Map> initial_map = 627 Handle<Map> initial_map =
628 FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 628 FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
629 function->set_initial_map(*initial_map); 629 function->set_initial_map(*initial_map);
630 630
631 Handle<String> prop_name = FACTORY->InternalizeUtf8String("theSlot"); 631 Handle<String> prop_name = FACTORY->InternalizeUtf8String("theSlot");
632 Handle<JSObject> obj = FACTORY->NewJSObject(function); 632 Handle<JSObject> obj = FACTORY->NewJSObject(function);
633 obj->SetProperty( 633 obj->SetProperty(
634 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); 634 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked();
635 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); 635 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name));
636 // Check that we can add properties to function objects. 636 // Check that we can add properties to function objects.
637 function->SetProperty( 637 function->SetProperty(
638 *prop_name, Smi::FromInt(24), NONE, kNonStrictMode)->ToObjectChecked(); 638 *prop_name, Smi::FromInt(24), NONE, kNonStrictMode)->ToObjectChecked();
639 CHECK_EQ(Smi::FromInt(24), function->GetProperty(*prop_name)); 639 CHECK_EQ(Smi::FromInt(24), function->GetProperty(*prop_name));
640 } 640 }
641 641
642 642
643 TEST(ObjectProperties) { 643 TEST(ObjectProperties) {
644 InitializeVM(); 644 InitializeVM();
645 645
646 v8::HandleScope sc; 646 v8::HandleScope sc(env->GetIsolate());
647 String* object_string = String::cast(HEAP->Object_string()); 647 String* object_string = String::cast(HEAP->Object_string());
648 Object* raw_object = Isolate::Current()->context()->global_object()-> 648 Object* raw_object = Isolate::Current()->context()->global_object()->
649 GetProperty(object_string)->ToObjectChecked(); 649 GetProperty(object_string)->ToObjectChecked();
650 JSFunction* object_function = JSFunction::cast(raw_object); 650 JSFunction* object_function = JSFunction::cast(raw_object);
651 Handle<JSFunction> constructor(object_function); 651 Handle<JSFunction> constructor(object_function);
652 Handle<JSObject> obj = FACTORY->NewJSObject(constructor); 652 Handle<JSObject> obj = FACTORY->NewJSObject(constructor);
653 Handle<String> first = FACTORY->InternalizeUtf8String("first"); 653 Handle<String> first = FACTORY->InternalizeUtf8String("first");
654 Handle<String> second = FACTORY->InternalizeUtf8String("second"); 654 Handle<String> second = FACTORY->InternalizeUtf8String("second");
655 655
656 // check for empty 656 // check for empty
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 obj->SetProperty( 709 obj->SetProperty(
710 *s2_string, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); 710 *s2_string, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked();
711 Handle<String> s2 = FACTORY->NewStringFromAscii(CStrVector(string2)); 711 Handle<String> s2 = FACTORY->NewStringFromAscii(CStrVector(string2));
712 CHECK(obj->HasLocalProperty(*s2)); 712 CHECK(obj->HasLocalProperty(*s2));
713 } 713 }
714 714
715 715
716 TEST(JSObjectMaps) { 716 TEST(JSObjectMaps) {
717 InitializeVM(); 717 InitializeVM();
718 718
719 v8::HandleScope sc; 719 v8::HandleScope sc(env->GetIsolate());
720 Handle<String> name = FACTORY->InternalizeUtf8String("theFunction"); 720 Handle<String> name = FACTORY->InternalizeUtf8String("theFunction");
721 Handle<JSFunction> function = 721 Handle<JSFunction> function =
722 FACTORY->NewFunction(name, FACTORY->undefined_value()); 722 FACTORY->NewFunction(name, FACTORY->undefined_value());
723 Handle<Map> initial_map = 723 Handle<Map> initial_map =
724 FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 724 FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
725 function->set_initial_map(*initial_map); 725 function->set_initial_map(*initial_map);
726 726
727 Handle<String> prop_name = FACTORY->InternalizeUtf8String("theSlot"); 727 Handle<String> prop_name = FACTORY->InternalizeUtf8String("theSlot");
728 Handle<JSObject> obj = FACTORY->NewJSObject(function); 728 Handle<JSObject> obj = FACTORY->NewJSObject(function);
729 729
730 // Set a propery 730 // Set a propery
731 obj->SetProperty( 731 obj->SetProperty(
732 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked(); 732 *prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked();
733 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); 733 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name));
734 734
735 // Check the map has changed 735 // Check the map has changed
736 CHECK(*initial_map != obj->map()); 736 CHECK(*initial_map != obj->map());
737 } 737 }
738 738
739 739
740 TEST(JSArray) { 740 TEST(JSArray) {
741 InitializeVM(); 741 InitializeVM();
742 742
743 v8::HandleScope sc; 743 v8::HandleScope sc(env->GetIsolate());
744 Handle<String> name = FACTORY->InternalizeUtf8String("Array"); 744 Handle<String> name = FACTORY->InternalizeUtf8String("Array");
745 Object* raw_object = Isolate::Current()->context()->global_object()-> 745 Object* raw_object = Isolate::Current()->context()->global_object()->
746 GetProperty(*name)->ToObjectChecked(); 746 GetProperty(*name)->ToObjectChecked();
747 Handle<JSFunction> function = Handle<JSFunction>( 747 Handle<JSFunction> function = Handle<JSFunction>(
748 JSFunction::cast(raw_object)); 748 JSFunction::cast(raw_object));
749 749
750 // Allocate the object. 750 // Allocate the object.
751 Handle<JSObject> object = FACTORY->NewJSObject(function); 751 Handle<JSObject> object = FACTORY->NewJSObject(function);
752 Handle<JSArray> array = Handle<JSArray>::cast(object); 752 Handle<JSArray> array = Handle<JSArray>::cast(object);
753 // We just initialized the VM, no heap allocation failure yet. 753 // We just initialized the VM, no heap allocation failure yet.
(...skipping 26 matching lines...) Expand all
780 CHECK(array->length()->ToArrayIndex(&new_int_length)); 780 CHECK(array->length()->ToArrayIndex(&new_int_length));
781 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1); 781 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1);
782 CHECK_EQ(array->GetElement(int_length), *name); 782 CHECK_EQ(array->GetElement(int_length), *name);
783 CHECK_EQ(array->GetElement(0), *name); 783 CHECK_EQ(array->GetElement(0), *name);
784 } 784 }
785 785
786 786
787 TEST(JSObjectCopy) { 787 TEST(JSObjectCopy) {
788 InitializeVM(); 788 InitializeVM();
789 789
790 v8::HandleScope sc; 790 v8::HandleScope sc(env->GetIsolate());
791 String* object_string = String::cast(HEAP->Object_string()); 791 String* object_string = String::cast(HEAP->Object_string());
792 Object* raw_object = Isolate::Current()->context()->global_object()-> 792 Object* raw_object = Isolate::Current()->context()->global_object()->
793 GetProperty(object_string)->ToObjectChecked(); 793 GetProperty(object_string)->ToObjectChecked();
794 JSFunction* object_function = JSFunction::cast(raw_object); 794 JSFunction* object_function = JSFunction::cast(raw_object);
795 Handle<JSFunction> constructor(object_function); 795 Handle<JSFunction> constructor(object_function);
796 Handle<JSObject> obj = FACTORY->NewJSObject(constructor); 796 Handle<JSObject> obj = FACTORY->NewJSObject(constructor);
797 Handle<String> first = FACTORY->InternalizeUtf8String("first"); 797 Handle<String> first = FACTORY->InternalizeUtf8String("first");
798 Handle<String> second = FACTORY->InternalizeUtf8String("second"); 798 Handle<String> second = FACTORY->InternalizeUtf8String("second");
799 799
800 obj->SetProperty( 800 obj->SetProperty(
(...skipping 27 matching lines...) Expand all
828 CHECK_EQ(obj->GetElement(0), clone->GetElement(1)); 828 CHECK_EQ(obj->GetElement(0), clone->GetElement(1));
829 829
830 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first)); 830 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first));
831 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*second)); 831 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*second));
832 } 832 }
833 833
834 834
835 TEST(StringAllocation) { 835 TEST(StringAllocation) {
836 InitializeVM(); 836 InitializeVM();
837 837
838
839 const unsigned char chars[] = { 0xe5, 0xa4, 0xa7 }; 838 const unsigned char chars[] = { 0xe5, 0xa4, 0xa7 };
840 for (int length = 0; length < 100; length++) { 839 for (int length = 0; length < 100; length++) {
841 v8::HandleScope scope; 840 v8::HandleScope scope(env->GetIsolate());
842 char* non_ascii = NewArray<char>(3 * length + 1); 841 char* non_ascii = NewArray<char>(3 * length + 1);
843 char* ascii = NewArray<char>(length + 1); 842 char* ascii = NewArray<char>(length + 1);
844 non_ascii[3 * length] = 0; 843 non_ascii[3 * length] = 0;
845 ascii[length] = 0; 844 ascii[length] = 0;
846 for (int i = 0; i < length; i++) { 845 for (int i = 0; i < length; i++) {
847 ascii[i] = 'a'; 846 ascii[i] = 'a';
848 non_ascii[3 * i] = chars[0]; 847 non_ascii[3 * i] = chars[0];
849 non_ascii[3 * i + 1] = chars[1]; 848 non_ascii[3 * i + 1] = chars[1];
850 non_ascii[3 * i + 2] = chars[2]; 849 non_ascii[3 * i + 2] = chars[2];
851 } 850 }
(...skipping 28 matching lines...) Expand all
880 found_count++; 879 found_count++;
881 } 880 }
882 } 881 }
883 } 882 }
884 return found_count; 883 return found_count;
885 } 884 }
886 885
887 886
888 TEST(Iteration) { 887 TEST(Iteration) {
889 InitializeVM(); 888 InitializeVM();
890 v8::HandleScope scope; 889 v8::HandleScope scope(env->GetIsolate());
891 890
892 // Array of objects to scan haep for. 891 // Array of objects to scan haep for.
893 const int objs_count = 6; 892 const int objs_count = 6;
894 Handle<Object> objs[objs_count]; 893 Handle<Object> objs[objs_count];
895 int next_objs_index = 0; 894 int next_objs_index = 0;
896 895
897 // Allocate a JS array to OLD_POINTER_SPACE and NEW_SPACE 896 // Allocate a JS array to OLD_POINTER_SPACE and NEW_SPACE
898 objs[next_objs_index++] = FACTORY->NewJSArray(10); 897 objs[next_objs_index++] = FACTORY->NewJSArray(10);
899 objs[next_objs_index++] = FACTORY->NewJSArray(10, 898 objs[next_objs_index++] = FACTORY->NewJSArray(10,
900 FAST_HOLEY_ELEMENTS, 899 FAST_HOLEY_ELEMENTS,
(...skipping 18 matching lines...) Expand all
919 objs[next_objs_index++] = Handle<Map>(HeapObject::cast(*objs[0])->map()); 918 objs[next_objs_index++] = Handle<Map>(HeapObject::cast(*objs[0])->map());
920 919
921 CHECK_EQ(objs_count, next_objs_index); 920 CHECK_EQ(objs_count, next_objs_index);
922 CHECK_EQ(objs_count, ObjectsFoundInHeap(HEAP, objs, objs_count)); 921 CHECK_EQ(objs_count, ObjectsFoundInHeap(HEAP, objs, objs_count));
923 } 922 }
924 923
925 924
926 TEST(EmptyHandleEscapeFrom) { 925 TEST(EmptyHandleEscapeFrom) {
927 InitializeVM(); 926 InitializeVM();
928 927
929 v8::HandleScope scope; 928 v8::HandleScope scope(env->GetIsolate());
930 Handle<JSObject> runaway; 929 Handle<JSObject> runaway;
931 930
932 { 931 {
933 v8::HandleScope nested; 932 v8::HandleScope nested(env->GetIsolate());
934 Handle<JSObject> empty; 933 Handle<JSObject> empty;
935 runaway = empty.EscapeFrom(&nested); 934 runaway = empty.EscapeFrom(&nested);
936 } 935 }
937 936
938 CHECK(runaway.is_null()); 937 CHECK(runaway.is_null());
939 } 938 }
940 939
941 940
942 static int LenFromSize(int size) { 941 static int LenFromSize(int size) {
943 return (size - FixedArray::kHeaderSize) / kPointerSize; 942 return (size - FixedArray::kHeaderSize) / kPointerSize;
944 } 943 }
945 944
946 945
947 TEST(Regression39128) { 946 TEST(Regression39128) {
948 // Test case for crbug.com/39128. 947 // Test case for crbug.com/39128.
949 InitializeVM(); 948 InitializeVM();
950 949
951 // Increase the chance of 'bump-the-pointer' allocation in old space. 950 // Increase the chance of 'bump-the-pointer' allocation in old space.
952 HEAP->CollectAllGarbage(Heap::kNoGCFlags); 951 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
953 952
954 v8::HandleScope scope; 953 v8::HandleScope scope(env->GetIsolate());
955 954
956 // The plan: create JSObject which references objects in new space. 955 // The plan: create JSObject which references objects in new space.
957 // Then clone this object (forcing it to go into old space) and check 956 // Then clone this object (forcing it to go into old space) and check
958 // that region dirty marks are updated correctly. 957 // that region dirty marks are updated correctly.
959 958
960 // Step 1: prepare a map for the object. We add 1 inobject property to it. 959 // Step 1: prepare a map for the object. We add 1 inobject property to it.
961 Handle<JSFunction> object_ctor( 960 Handle<JSFunction> object_ctor(
962 Isolate::Current()->native_context()->object_function()); 961 Isolate::Current()->native_context()->object_function());
963 CHECK(object_ctor->has_initial_map()); 962 CHECK(object_ctor->has_initial_map());
964 Handle<Map> object_map(object_ctor->initial_map()); 963 Handle<Map> object_map(object_ctor->initial_map());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 } 1016 }
1018 CHECK(HEAP->old_pointer_space()->Contains(clone->address())); 1017 CHECK(HEAP->old_pointer_space()->Contains(clone->address()));
1019 } 1018 }
1020 1019
1021 1020
1022 TEST(TestCodeFlushing) { 1021 TEST(TestCodeFlushing) {
1023 // If we do not flush code this test is invalid. 1022 // If we do not flush code this test is invalid.
1024 if (!FLAG_flush_code) return; 1023 if (!FLAG_flush_code) return;
1025 i::FLAG_allow_natives_syntax = true; 1024 i::FLAG_allow_natives_syntax = true;
1026 InitializeVM(); 1025 InitializeVM();
1027 v8::HandleScope scope; 1026 v8::HandleScope scope(env->GetIsolate());
1028 const char* source = "function foo() {" 1027 const char* source = "function foo() {"
1029 " var x = 42;" 1028 " var x = 42;"
1030 " var y = 42;" 1029 " var y = 42;"
1031 " var z = x + y;" 1030 " var z = x + y;"
1032 "};" 1031 "};"
1033 "foo()"; 1032 "foo()";
1034 Handle<String> foo_name = FACTORY->InternalizeUtf8String("foo"); 1033 Handle<String> foo_name = FACTORY->InternalizeUtf8String("foo");
1035 1034
1036 // This compile will add the code to the compilation cache. 1035 // This compile will add the code to the compilation cache.
1037 { v8::HandleScope scope; 1036 { v8::HandleScope scope(env->GetIsolate());
1038 CompileRun(source); 1037 CompileRun(source);
1039 } 1038 }
1040 1039
1041 // Check function is compiled. 1040 // Check function is compiled.
1042 Object* func_value = Isolate::Current()->context()->global_object()-> 1041 Object* func_value = Isolate::Current()->context()->global_object()->
1043 GetProperty(*foo_name)->ToObjectChecked(); 1042 GetProperty(*foo_name)->ToObjectChecked();
1044 CHECK(func_value->IsJSFunction()); 1043 CHECK(func_value->IsJSFunction());
1045 Handle<JSFunction> function(JSFunction::cast(func_value)); 1044 Handle<JSFunction> function(JSFunction::cast(func_value));
1046 CHECK(function->shared()->is_compiled()); 1045 CHECK(function->shared()->is_compiled());
1047 1046
(...skipping 16 matching lines...) Expand all
1064 CHECK(function->shared()->is_compiled()); 1063 CHECK(function->shared()->is_compiled());
1065 CHECK(function->is_compiled()); 1064 CHECK(function->is_compiled());
1066 } 1065 }
1067 1066
1068 1067
1069 TEST(TestCodeFlushingIncremental) { 1068 TEST(TestCodeFlushingIncremental) {
1070 // If we do not flush code this test is invalid. 1069 // If we do not flush code this test is invalid.
1071 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return; 1070 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return;
1072 i::FLAG_allow_natives_syntax = true; 1071 i::FLAG_allow_natives_syntax = true;
1073 InitializeVM(); 1072 InitializeVM();
1074 v8::HandleScope scope; 1073 v8::HandleScope scope(env->GetIsolate());
1075 const char* source = "function foo() {" 1074 const char* source = "function foo() {"
1076 " var x = 42;" 1075 " var x = 42;"
1077 " var y = 42;" 1076 " var y = 42;"
1078 " var z = x + y;" 1077 " var z = x + y;"
1079 "};" 1078 "};"
1080 "foo()"; 1079 "foo()";
1081 Handle<String> foo_name = FACTORY->InternalizeUtf8String("foo"); 1080 Handle<String> foo_name = FACTORY->InternalizeUtf8String("foo");
1082 1081
1083 // This compile will add the code to the compilation cache. 1082 // This compile will add the code to the compilation cache.
1084 { v8::HandleScope scope; 1083 { v8::HandleScope scope(env->GetIsolate());
1085 CompileRun(source); 1084 CompileRun(source);
1086 } 1085 }
1087 1086
1088 // Check function is compiled. 1087 // Check function is compiled.
1089 Object* func_value = Isolate::Current()->context()->global_object()-> 1088 Object* func_value = Isolate::Current()->context()->global_object()->
1090 GetProperty(*foo_name)->ToObjectChecked(); 1089 GetProperty(*foo_name)->ToObjectChecked();
1091 CHECK(func_value->IsJSFunction()); 1090 CHECK(func_value->IsJSFunction());
1092 Handle<JSFunction> function(JSFunction::cast(func_value)); 1091 Handle<JSFunction> function(JSFunction::cast(func_value));
1093 CHECK(function->shared()->is_compiled()); 1092 CHECK(function->shared()->is_compiled());
1094 1093
1095 // The code will survive at least two GCs. 1094 // The code will survive at least two GCs.
1096 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 1095 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
1097 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 1096 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
1098 CHECK(function->shared()->is_compiled()); 1097 CHECK(function->shared()->is_compiled());
1099 1098
1100 // Simulate several GCs that use incremental marking. 1099 // Simulate several GCs that use incremental marking.
1101 const int kAgingThreshold = 6; 1100 const int kAgingThreshold = 6;
1102 for (int i = 0; i < kAgingThreshold; i++) { 1101 for (int i = 0; i < kAgingThreshold; i++) {
1103 SimulateIncrementalMarking(); 1102 SimulateIncrementalMarking();
1104 HEAP->CollectAllGarbage(Heap::kNoGCFlags); 1103 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
1105 } 1104 }
1106 CHECK(!function->shared()->is_compiled() || function->IsOptimized()); 1105 CHECK(!function->shared()->is_compiled() || function->IsOptimized());
1107 CHECK(!function->is_compiled() || function->IsOptimized()); 1106 CHECK(!function->is_compiled() || function->IsOptimized());
1108 1107
1109 // This compile will compile the function again. 1108 // This compile will compile the function again.
1110 { v8::HandleScope scope; 1109 { v8::HandleScope scope(env->GetIsolate());
1111 CompileRun("foo();"); 1110 CompileRun("foo();");
1112 } 1111 }
1113 1112
1114 // Simulate several GCs that use incremental marking but make sure 1113 // Simulate several GCs that use incremental marking but make sure
1115 // the loop breaks once the function is enqueued as a candidate. 1114 // the loop breaks once the function is enqueued as a candidate.
1116 for (int i = 0; i < kAgingThreshold; i++) { 1115 for (int i = 0; i < kAgingThreshold; i++) {
1117 SimulateIncrementalMarking(); 1116 SimulateIncrementalMarking();
1118 if (!function->next_function_link()->IsUndefined()) break; 1117 if (!function->next_function_link()->IsUndefined()) break;
1119 HEAP->CollectAllGarbage(Heap::kNoGCFlags); 1118 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
1120 } 1119 }
1121 1120
1122 // Force optimization while incremental marking is active and while 1121 // Force optimization while incremental marking is active and while
1123 // the function is enqueued as a candidate. 1122 // the function is enqueued as a candidate.
1124 { v8::HandleScope scope; 1123 { v8::HandleScope scope(env->GetIsolate());
1125 CompileRun("%OptimizeFunctionOnNextCall(foo); foo();"); 1124 CompileRun("%OptimizeFunctionOnNextCall(foo); foo();");
1126 } 1125 }
1127 1126
1128 // Simulate one final GC to make sure the candidate queue is sane. 1127 // Simulate one final GC to make sure the candidate queue is sane.
1129 HEAP->CollectAllGarbage(Heap::kNoGCFlags); 1128 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
1130 CHECK(function->shared()->is_compiled() || !function->IsOptimized()); 1129 CHECK(function->shared()->is_compiled() || !function->IsOptimized());
1131 CHECK(function->is_compiled() || !function->IsOptimized()); 1130 CHECK(function->is_compiled() || !function->IsOptimized());
1132 } 1131 }
1133 1132
1134 1133
1135 TEST(TestCodeFlushingIncrementalScavenge) { 1134 TEST(TestCodeFlushingIncrementalScavenge) {
1136 // If we do not flush code this test is invalid. 1135 // If we do not flush code this test is invalid.
1137 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return; 1136 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return;
1138 i::FLAG_allow_natives_syntax = true; 1137 i::FLAG_allow_natives_syntax = true;
1139 InitializeVM(); 1138 InitializeVM();
1140 v8::HandleScope scope; 1139 v8::HandleScope scope(env->GetIsolate());
1141 const char* source = "var foo = function() {" 1140 const char* source = "var foo = function() {"
1142 " var x = 42;" 1141 " var x = 42;"
1143 " var y = 42;" 1142 " var y = 42;"
1144 " var z = x + y;" 1143 " var z = x + y;"
1145 "};" 1144 "};"
1146 "foo();" 1145 "foo();"
1147 "var bar = function() {" 1146 "var bar = function() {"
1148 " var x = 23;" 1147 " var x = 23;"
1149 "};" 1148 "};"
1150 "bar();"; 1149 "bar();";
1151 Handle<String> foo_name = FACTORY->InternalizeUtf8String("foo"); 1150 Handle<String> foo_name = FACTORY->InternalizeUtf8String("foo");
1152 Handle<String> bar_name = FACTORY->InternalizeUtf8String("bar"); 1151 Handle<String> bar_name = FACTORY->InternalizeUtf8String("bar");
1153 1152
1154 // Perfrom one initial GC to enable code flushing. 1153 // Perfrom one initial GC to enable code flushing.
1155 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 1154 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
1156 1155
1157 // This compile will add the code to the compilation cache. 1156 // This compile will add the code to the compilation cache.
1158 { v8::HandleScope scope; 1157 { v8::HandleScope scope(env->GetIsolate());
1159 CompileRun(source); 1158 CompileRun(source);
1160 } 1159 }
1161 1160
1162 // Check functions are compiled. 1161 // Check functions are compiled.
1163 Object* func_value = Isolate::Current()->context()->global_object()-> 1162 Object* func_value = Isolate::Current()->context()->global_object()->
1164 GetProperty(*foo_name)->ToObjectChecked(); 1163 GetProperty(*foo_name)->ToObjectChecked();
1165 CHECK(func_value->IsJSFunction()); 1164 CHECK(func_value->IsJSFunction());
1166 Handle<JSFunction> function(JSFunction::cast(func_value)); 1165 Handle<JSFunction> function(JSFunction::cast(func_value));
1167 CHECK(function->shared()->is_compiled()); 1166 CHECK(function->shared()->is_compiled());
1168 Object* func_value2 = Isolate::Current()->context()->global_object()-> 1167 Object* func_value2 = Isolate::Current()->context()->global_object()->
1169 GetProperty(*bar_name)->ToObjectChecked(); 1168 GetProperty(*bar_name)->ToObjectChecked();
1170 CHECK(func_value2->IsJSFunction()); 1169 CHECK(func_value2->IsJSFunction());
1171 Handle<JSFunction> function2(JSFunction::cast(func_value2)); 1170 Handle<JSFunction> function2(JSFunction::cast(func_value2));
1172 CHECK(function2->shared()->is_compiled()); 1171 CHECK(function2->shared()->is_compiled());
1173 1172
1174 // Clear references to functions so that one of them can die. 1173 // Clear references to functions so that one of them can die.
1175 { v8::HandleScope scope; 1174 { v8::HandleScope scope(env->GetIsolate());
1176 CompileRun("foo = 0; bar = 0;"); 1175 CompileRun("foo = 0; bar = 0;");
1177 } 1176 }
1178 1177
1179 // Bump the code age so that flushing is triggered while the function 1178 // Bump the code age so that flushing is triggered while the function
1180 // object is still located in new-space. 1179 // object is still located in new-space.
1181 const int kAgingThreshold = 6; 1180 const int kAgingThreshold = 6;
1182 for (int i = 0; i < kAgingThreshold; i++) { 1181 for (int i = 0; i < kAgingThreshold; i++) {
1183 function->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2)); 1182 function->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2));
1184 function2->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2)); 1183 function2->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2));
1185 } 1184 }
(...skipping 12 matching lines...) Expand all
1198 } 1197 }
1199 1198
1200 1199
1201 TEST(TestCodeFlushingIncrementalAbort) { 1200 TEST(TestCodeFlushingIncrementalAbort) {
1202 // If we do not flush code this test is invalid. 1201 // If we do not flush code this test is invalid.
1203 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return; 1202 if (!FLAG_flush_code || !FLAG_flush_code_incrementally) return;
1204 i::FLAG_allow_natives_syntax = true; 1203 i::FLAG_allow_natives_syntax = true;
1205 InitializeVM(); 1204 InitializeVM();
1206 Isolate* isolate = Isolate::Current(); 1205 Isolate* isolate = Isolate::Current();
1207 Heap* heap = isolate->heap(); 1206 Heap* heap = isolate->heap();
1208 v8::HandleScope scope; 1207 v8::HandleScope scope(env->GetIsolate());
1209 const char* source = "function foo() {" 1208 const char* source = "function foo() {"
1210 " var x = 42;" 1209 " var x = 42;"
1211 " var y = 42;" 1210 " var y = 42;"
1212 " var z = x + y;" 1211 " var z = x + y;"
1213 "};" 1212 "};"
1214 "foo()"; 1213 "foo()";
1215 Handle<String> foo_name = FACTORY->InternalizeUtf8String("foo"); 1214 Handle<String> foo_name = FACTORY->InternalizeUtf8String("foo");
1216 1215
1217 // This compile will add the code to the compilation cache. 1216 // This compile will add the code to the compilation cache.
1218 { v8::HandleScope scope; 1217 { v8::HandleScope scope(env->GetIsolate());
1219 CompileRun(source); 1218 CompileRun(source);
1220 } 1219 }
1221 1220
1222 // Check function is compiled. 1221 // Check function is compiled.
1223 Object* func_value = Isolate::Current()->context()->global_object()-> 1222 Object* func_value = Isolate::Current()->context()->global_object()->
1224 GetProperty(*foo_name)->ToObjectChecked(); 1223 GetProperty(*foo_name)->ToObjectChecked();
1225 CHECK(func_value->IsJSFunction()); 1224 CHECK(func_value->IsJSFunction());
1226 Handle<JSFunction> function(JSFunction::cast(func_value)); 1225 Handle<JSFunction> function(JSFunction::cast(func_value));
1227 CHECK(function->shared()->is_compiled()); 1226 CHECK(function->shared()->is_compiled());
1228 1227
(...skipping 14 matching lines...) Expand all
1243 1242
1244 // Enable the debugger and add a breakpoint while incremental marking 1243 // Enable the debugger and add a breakpoint while incremental marking
1245 // is running so that incremental marking aborts and code flushing is 1244 // is running so that incremental marking aborts and code flushing is
1246 // disabled. 1245 // disabled.
1247 int position = 0; 1246 int position = 0;
1248 Handle<Object> breakpoint_object(Smi::FromInt(0), isolate); 1247 Handle<Object> breakpoint_object(Smi::FromInt(0), isolate);
1249 isolate->debug()->SetBreakPoint(function, breakpoint_object, &position); 1248 isolate->debug()->SetBreakPoint(function, breakpoint_object, &position);
1250 isolate->debug()->ClearAllBreakPoints(); 1249 isolate->debug()->ClearAllBreakPoints();
1251 1250
1252 // Force optimization now that code flushing is disabled. 1251 // Force optimization now that code flushing is disabled.
1253 { v8::HandleScope scope; 1252 { v8::HandleScope scope(env->GetIsolate());
1254 CompileRun("%OptimizeFunctionOnNextCall(foo); foo();"); 1253 CompileRun("%OptimizeFunctionOnNextCall(foo); foo();");
1255 } 1254 }
1256 1255
1257 // Simulate one final GC to make sure the candidate queue is sane. 1256 // Simulate one final GC to make sure the candidate queue is sane.
1258 heap->CollectAllGarbage(Heap::kNoGCFlags); 1257 heap->CollectAllGarbage(Heap::kNoGCFlags);
1259 CHECK(function->shared()->is_compiled() || !function->IsOptimized()); 1258 CHECK(function->shared()->is_compiled() || !function->IsOptimized());
1260 CHECK(function->is_compiled() || !function->IsOptimized()); 1259 CHECK(function->is_compiled() || !function->IsOptimized());
1261 } 1260 }
1262 1261
1263 1262
(...skipping 27 matching lines...) Expand all
1291 v8::V8::Initialize(); 1290 v8::V8::Initialize();
1292 1291
1293 // Some flags turn Scavenge collections into Mark-sweep collections 1292 // Some flags turn Scavenge collections into Mark-sweep collections
1294 // and hence are incompatible with this test case. 1293 // and hence are incompatible with this test case.
1295 if (FLAG_gc_global || FLAG_stress_compaction) return; 1294 if (FLAG_gc_global || FLAG_stress_compaction) return;
1296 1295
1297 static const int kNumTestContexts = 10; 1296 static const int kNumTestContexts = 10;
1298 1297
1299 Isolate* isolate = Isolate::Current(); 1298 Isolate* isolate = Isolate::Current();
1300 Heap* heap = isolate->heap(); 1299 Heap* heap = isolate->heap();
1301 v8::HandleScope scope; 1300 HandleScope scope(isolate);
1302 v8::Persistent<v8::Context> ctx[kNumTestContexts]; 1301 v8::Persistent<v8::Context> ctx[kNumTestContexts];
1303 1302
1304 CHECK_EQ(0, CountNativeContexts()); 1303 CHECK_EQ(0, CountNativeContexts());
1305 1304
1306 // Create a number of global contests which gets linked together. 1305 // Create a number of global contests which gets linked together.
1307 for (int i = 0; i < kNumTestContexts; i++) { 1306 for (int i = 0; i < kNumTestContexts; i++) {
1308 ctx[i] = v8::Context::New(); 1307 ctx[i] = v8::Context::New();
1309 1308
1310 bool opt = (FLAG_always_opt && i::V8::UseCrankshaft()); 1309 bool opt = (FLAG_always_opt && i::V8::UseCrankshaft());
1311 1310
1312 CHECK_EQ(i + 1, CountNativeContexts()); 1311 CHECK_EQ(i + 1, CountNativeContexts());
1313 1312
1314 ctx[i]->Enter(); 1313 ctx[i]->Enter();
1315 1314
1316 // Create a handle scope so no function objects get stuch in the outer 1315 // Create a handle scope so no function objects get stuch in the outer
1317 // handle scope 1316 // handle scope
1318 v8::HandleScope scope; 1317 HandleScope scope(isolate);
1319 const char* source = "function f1() { };" 1318 const char* source = "function f1() { };"
1320 "function f2() { };" 1319 "function f2() { };"
1321 "function f3() { };" 1320 "function f3() { };"
1322 "function f4() { };" 1321 "function f4() { };"
1323 "function f5() { };"; 1322 "function f5() { };";
1324 CompileRun(source); 1323 CompileRun(source);
1325 CHECK_EQ(0, CountOptimizedUserFunctions(ctx[i])); 1324 CHECK_EQ(0, CountOptimizedUserFunctions(ctx[i]));
1326 CompileRun("f1()"); 1325 CompileRun("f1()");
1327 CHECK_EQ(opt ? 1 : 0, CountOptimizedUserFunctions(ctx[i])); 1326 CHECK_EQ(opt ? 1 : 0, CountOptimizedUserFunctions(ctx[i]));
1328 CompileRun("f2()"); 1327 CompileRun("f2()");
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1428 return count; 1427 return count;
1429 } 1428 }
1430 1429
1431 1430
1432 TEST(TestInternalWeakListsTraverseWithGC) { 1431 TEST(TestInternalWeakListsTraverseWithGC) {
1433 v8::V8::Initialize(); 1432 v8::V8::Initialize();
1434 Isolate* isolate = Isolate::Current(); 1433 Isolate* isolate = Isolate::Current();
1435 1434
1436 static const int kNumTestContexts = 10; 1435 static const int kNumTestContexts = 10;
1437 1436
1438 v8::HandleScope scope; 1437 HandleScope scope(isolate);
1439 v8::Persistent<v8::Context> ctx[kNumTestContexts]; 1438 v8::Persistent<v8::Context> ctx[kNumTestContexts];
1440 1439
1441 CHECK_EQ(0, CountNativeContexts()); 1440 CHECK_EQ(0, CountNativeContexts());
1442 1441
1443 // Create an number of contexts and check the length of the weak list both 1442 // Create an number of contexts and check the length of the weak list both
1444 // with and without GCs while iterating the list. 1443 // with and without GCs while iterating the list.
1445 for (int i = 0; i < kNumTestContexts; i++) { 1444 for (int i = 0; i < kNumTestContexts; i++) {
1446 ctx[i] = v8::Context::New(); 1445 ctx[i] = v8::Context::New();
1447 CHECK_EQ(i + 1, CountNativeContexts()); 1446 CHECK_EQ(i + 1, CountNativeContexts());
1448 CHECK_EQ(i + 1, CountNativeContextsWithGC(isolate, i / 2 + 1)); 1447 CHECK_EQ(i + 1, CountNativeContextsWithGC(isolate, i / 2 + 1));
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1552 "delta: %" V8_PTR_PREFIX "d\n", 1551 "delta: %" V8_PTR_PREFIX "d\n",
1553 size_of_objects_1, size_of_objects_2, delta); 1552 size_of_objects_1, size_of_objects_2, delta);
1554 CHECK_GT(size_of_objects_2 / 20, delta); 1553 CHECK_GT(size_of_objects_2 / 20, delta);
1555 } 1554 }
1556 } 1555 }
1557 1556
1558 1557
1559 static void FillUpNewSpace(NewSpace* new_space) { 1558 static void FillUpNewSpace(NewSpace* new_space) {
1560 // Fill up new space to the point that it is completely full. Make sure 1559 // Fill up new space to the point that it is completely full. Make sure
1561 // that the scavenger does not undo the filling. 1560 // that the scavenger does not undo the filling.
1562 v8::HandleScope scope; 1561 Heap* heap = new_space->heap();
1562 Isolate* isolate = heap->isolate();
1563 Factory* factory = isolate->factory();
1564 HandleScope scope(isolate);
1563 AlwaysAllocateScope always_allocate; 1565 AlwaysAllocateScope always_allocate;
1564 intptr_t available = new_space->EffectiveCapacity() - new_space->Size(); 1566 intptr_t available = new_space->EffectiveCapacity() - new_space->Size();
1565 intptr_t number_of_fillers = (available / FixedArray::SizeFor(32)) - 1; 1567 intptr_t number_of_fillers = (available / FixedArray::SizeFor(32)) - 1;
1566 for (intptr_t i = 0; i < number_of_fillers; i++) { 1568 for (intptr_t i = 0; i < number_of_fillers; i++) {
1567 CHECK(HEAP->InNewSpace(*FACTORY->NewFixedArray(32, NOT_TENURED))); 1569 CHECK(heap->InNewSpace(*factory->NewFixedArray(32, NOT_TENURED)));
1568 } 1570 }
1569 } 1571 }
1570 1572
1571 1573
1572 TEST(GrowAndShrinkNewSpace) { 1574 TEST(GrowAndShrinkNewSpace) {
1573 InitializeVM(); 1575 InitializeVM();
1574 NewSpace* new_space = HEAP->new_space(); 1576 NewSpace* new_space = HEAP->new_space();
1575 1577
1576 if (HEAP->ReservedSemiSpaceSize() == HEAP->InitialSemiSpaceSize() || 1578 if (HEAP->ReservedSemiSpaceSize() == HEAP->InitialSemiSpaceSize() ||
1577 HEAP->MaxSemiSpaceSize() == HEAP->InitialSemiSpaceSize()) { 1579 HEAP->MaxSemiSpaceSize() == HEAP->InitialSemiSpaceSize()) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1623 InitializeVM(); 1625 InitializeVM();
1624 1626
1625 if (HEAP->ReservedSemiSpaceSize() == HEAP->InitialSemiSpaceSize() || 1627 if (HEAP->ReservedSemiSpaceSize() == HEAP->InitialSemiSpaceSize() ||
1626 HEAP->MaxSemiSpaceSize() == HEAP->InitialSemiSpaceSize()) { 1628 HEAP->MaxSemiSpaceSize() == HEAP->InitialSemiSpaceSize()) {
1627 // The max size cannot exceed the reserved size, since semispaces must be 1629 // The max size cannot exceed the reserved size, since semispaces must be
1628 // always within the reserved space. We can't test new space growing and 1630 // always within the reserved space. We can't test new space growing and
1629 // shrinking if the reserved size is the same as the minimum (initial) size. 1631 // shrinking if the reserved size is the same as the minimum (initial) size.
1630 return; 1632 return;
1631 } 1633 }
1632 1634
1633 v8::HandleScope scope; 1635 v8::HandleScope scope(env->GetIsolate());
1634 NewSpace* new_space = HEAP->new_space(); 1636 NewSpace* new_space = HEAP->new_space();
1635 intptr_t old_capacity, new_capacity; 1637 intptr_t old_capacity, new_capacity;
1636 old_capacity = new_space->Capacity(); 1638 old_capacity = new_space->Capacity();
1637 new_space->Grow(); 1639 new_space->Grow();
1638 new_capacity = new_space->Capacity(); 1640 new_capacity = new_space->Capacity();
1639 CHECK(2 * old_capacity == new_capacity); 1641 CHECK(2 * old_capacity == new_capacity);
1640 FillUpNewSpace(new_space); 1642 FillUpNewSpace(new_space);
1641 HEAP->CollectAllAvailableGarbage(); 1643 HEAP->CollectAllAvailableGarbage();
1642 new_capacity = new_space->Capacity(); 1644 new_capacity = new_space->Capacity();
1643 CHECK(old_capacity == new_capacity); 1645 CHECK(old_capacity == new_capacity);
1644 } 1646 }
1645 1647
1646 1648
1647 static int NumberOfGlobalObjects() { 1649 static int NumberOfGlobalObjects() {
1648 int count = 0; 1650 int count = 0;
1649 HeapIterator iterator(HEAP); 1651 HeapIterator iterator(HEAP);
1650 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { 1652 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) {
1651 if (obj->IsGlobalObject()) count++; 1653 if (obj->IsGlobalObject()) count++;
1652 } 1654 }
1653 return count; 1655 return count;
1654 } 1656 }
1655 1657
1656 1658
1657 // Test that we don't embed maps from foreign contexts into 1659 // Test that we don't embed maps from foreign contexts into
1658 // optimized code. 1660 // optimized code.
1659 TEST(LeakNativeContextViaMap) { 1661 TEST(LeakNativeContextViaMap) {
1660 i::FLAG_allow_natives_syntax = true; 1662 i::FLAG_allow_natives_syntax = true;
1661 v8::HandleScope outer_scope; 1663 v8::HandleScope outer_scope(v8::Isolate::GetCurrent());
1662 v8::Persistent<v8::Context> ctx1 = v8::Context::New(); 1664 v8::Persistent<v8::Context> ctx1 = v8::Context::New();
1663 v8::Persistent<v8::Context> ctx2 = v8::Context::New(); 1665 v8::Persistent<v8::Context> ctx2 = v8::Context::New();
1664 ctx1->Enter(); 1666 ctx1->Enter();
1665 1667
1666 HEAP->CollectAllAvailableGarbage(); 1668 HEAP->CollectAllAvailableGarbage();
1667 CHECK_EQ(4, NumberOfGlobalObjects()); 1669 CHECK_EQ(4, NumberOfGlobalObjects());
1668 1670
1669 { 1671 {
1670 v8::HandleScope inner_scope; 1672 v8::HandleScope inner_scope(v8::Isolate::GetCurrent());
1671 CompileRun("var v = {x: 42}"); 1673 CompileRun("var v = {x: 42}");
1672 v8::Local<v8::Value> v = ctx1->Global()->Get(v8_str("v")); 1674 v8::Local<v8::Value> v = ctx1->Global()->Get(v8_str("v"));
1673 ctx2->Enter(); 1675 ctx2->Enter();
1674 ctx2->Global()->Set(v8_str("o"), v); 1676 ctx2->Global()->Set(v8_str("o"), v);
1675 v8::Local<v8::Value> res = CompileRun( 1677 v8::Local<v8::Value> res = CompileRun(
1676 "function f() { return o.x; }" 1678 "function f() { return o.x; }"
1677 "for (var i = 0; i < 10; ++i) f();" 1679 "for (var i = 0; i < 10; ++i) f();"
1678 "%OptimizeFunctionOnNextCall(f);" 1680 "%OptimizeFunctionOnNextCall(f);"
1679 "f();"); 1681 "f();");
1680 CHECK_EQ(42, res->Int32Value()); 1682 CHECK_EQ(42, res->Int32Value());
1681 ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0)); 1683 ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0));
1682 ctx2->Exit(); 1684 ctx2->Exit();
1683 ctx1->Exit(); 1685 ctx1->Exit();
1684 ctx1.Dispose(ctx1->GetIsolate()); 1686 ctx1.Dispose(ctx1->GetIsolate());
1685 v8::V8::ContextDisposedNotification(); 1687 v8::V8::ContextDisposedNotification();
1686 } 1688 }
1687 HEAP->CollectAllAvailableGarbage(); 1689 HEAP->CollectAllAvailableGarbage();
1688 CHECK_EQ(2, NumberOfGlobalObjects()); 1690 CHECK_EQ(2, NumberOfGlobalObjects());
1689 ctx2.Dispose(ctx2->GetIsolate()); 1691 ctx2.Dispose(ctx2->GetIsolate());
1690 HEAP->CollectAllAvailableGarbage(); 1692 HEAP->CollectAllAvailableGarbage();
1691 CHECK_EQ(0, NumberOfGlobalObjects()); 1693 CHECK_EQ(0, NumberOfGlobalObjects());
1692 } 1694 }
1693 1695
1694 1696
1695 // Test that we don't embed functions from foreign contexts into 1697 // Test that we don't embed functions from foreign contexts into
1696 // optimized code. 1698 // optimized code.
1697 TEST(LeakNativeContextViaFunction) { 1699 TEST(LeakNativeContextViaFunction) {
1698 i::FLAG_allow_natives_syntax = true; 1700 i::FLAG_allow_natives_syntax = true;
1699 v8::HandleScope outer_scope; 1701 v8::HandleScope outer_scope(v8::Isolate::GetCurrent());
1700 v8::Persistent<v8::Context> ctx1 = v8::Context::New(); 1702 v8::Persistent<v8::Context> ctx1 = v8::Context::New();
1701 v8::Persistent<v8::Context> ctx2 = v8::Context::New(); 1703 v8::Persistent<v8::Context> ctx2 = v8::Context::New();
1702 ctx1->Enter(); 1704 ctx1->Enter();
1703 1705
1704 HEAP->CollectAllAvailableGarbage(); 1706 HEAP->CollectAllAvailableGarbage();
1705 CHECK_EQ(4, NumberOfGlobalObjects()); 1707 CHECK_EQ(4, NumberOfGlobalObjects());
1706 1708
1707 { 1709 {
1708 v8::HandleScope inner_scope; 1710 v8::HandleScope inner_scope(v8::Isolate::GetCurrent());
1709 CompileRun("var v = function() { return 42; }"); 1711 CompileRun("var v = function() { return 42; }");
1710 v8::Local<v8::Value> v = ctx1->Global()->Get(v8_str("v")); 1712 v8::Local<v8::Value> v = ctx1->Global()->Get(v8_str("v"));
1711 ctx2->Enter(); 1713 ctx2->Enter();
1712 ctx2->Global()->Set(v8_str("o"), v); 1714 ctx2->Global()->Set(v8_str("o"), v);
1713 v8::Local<v8::Value> res = CompileRun( 1715 v8::Local<v8::Value> res = CompileRun(
1714 "function f(x) { return x(); }" 1716 "function f(x) { return x(); }"
1715 "for (var i = 0; i < 10; ++i) f(o);" 1717 "for (var i = 0; i < 10; ++i) f(o);"
1716 "%OptimizeFunctionOnNextCall(f);" 1718 "%OptimizeFunctionOnNextCall(f);"
1717 "f(o);"); 1719 "f(o);");
1718 CHECK_EQ(42, res->Int32Value()); 1720 CHECK_EQ(42, res->Int32Value());
1719 ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0)); 1721 ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0));
1720 ctx2->Exit(); 1722 ctx2->Exit();
1721 ctx1->Exit(); 1723 ctx1->Exit();
1722 ctx1.Dispose(ctx1->GetIsolate()); 1724 ctx1.Dispose(ctx1->GetIsolate());
1723 v8::V8::ContextDisposedNotification(); 1725 v8::V8::ContextDisposedNotification();
1724 } 1726 }
1725 HEAP->CollectAllAvailableGarbage(); 1727 HEAP->CollectAllAvailableGarbage();
1726 CHECK_EQ(2, NumberOfGlobalObjects()); 1728 CHECK_EQ(2, NumberOfGlobalObjects());
1727 ctx2.Dispose(ctx2->GetIsolate()); 1729 ctx2.Dispose(ctx2->GetIsolate());
1728 HEAP->CollectAllAvailableGarbage(); 1730 HEAP->CollectAllAvailableGarbage();
1729 CHECK_EQ(0, NumberOfGlobalObjects()); 1731 CHECK_EQ(0, NumberOfGlobalObjects());
1730 } 1732 }
1731 1733
1732 1734
1733 TEST(LeakNativeContextViaMapKeyed) { 1735 TEST(LeakNativeContextViaMapKeyed) {
1734 i::FLAG_allow_natives_syntax = true; 1736 i::FLAG_allow_natives_syntax = true;
1735 v8::HandleScope outer_scope; 1737 v8::HandleScope outer_scope(v8::Isolate::GetCurrent());
1736 v8::Persistent<v8::Context> ctx1 = v8::Context::New(); 1738 v8::Persistent<v8::Context> ctx1 = v8::Context::New();
1737 v8::Persistent<v8::Context> ctx2 = v8::Context::New(); 1739 v8::Persistent<v8::Context> ctx2 = v8::Context::New();
1738 ctx1->Enter(); 1740 ctx1->Enter();
1739 1741
1740 HEAP->CollectAllAvailableGarbage(); 1742 HEAP->CollectAllAvailableGarbage();
1741 CHECK_EQ(4, NumberOfGlobalObjects()); 1743 CHECK_EQ(4, NumberOfGlobalObjects());
1742 1744
1743 { 1745 {
1744 v8::HandleScope inner_scope; 1746 v8::HandleScope inner_scope(v8::Isolate::GetCurrent());
1745 CompileRun("var v = [42, 43]"); 1747 CompileRun("var v = [42, 43]");
1746 v8::Local<v8::Value> v = ctx1->Global()->Get(v8_str("v")); 1748 v8::Local<v8::Value> v = ctx1->Global()->Get(v8_str("v"));
1747 ctx2->Enter(); 1749 ctx2->Enter();
1748 ctx2->Global()->Set(v8_str("o"), v); 1750 ctx2->Global()->Set(v8_str("o"), v);
1749 v8::Local<v8::Value> res = CompileRun( 1751 v8::Local<v8::Value> res = CompileRun(
1750 "function f() { return o[0]; }" 1752 "function f() { return o[0]; }"
1751 "for (var i = 0; i < 10; ++i) f();" 1753 "for (var i = 0; i < 10; ++i) f();"
1752 "%OptimizeFunctionOnNextCall(f);" 1754 "%OptimizeFunctionOnNextCall(f);"
1753 "f();"); 1755 "f();");
1754 CHECK_EQ(42, res->Int32Value()); 1756 CHECK_EQ(42, res->Int32Value());
1755 ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0)); 1757 ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0));
1756 ctx2->Exit(); 1758 ctx2->Exit();
1757 ctx1->Exit(); 1759 ctx1->Exit();
1758 ctx1.Dispose(ctx1->GetIsolate()); 1760 ctx1.Dispose(ctx1->GetIsolate());
1759 v8::V8::ContextDisposedNotification(); 1761 v8::V8::ContextDisposedNotification();
1760 } 1762 }
1761 HEAP->CollectAllAvailableGarbage(); 1763 HEAP->CollectAllAvailableGarbage();
1762 CHECK_EQ(2, NumberOfGlobalObjects()); 1764 CHECK_EQ(2, NumberOfGlobalObjects());
1763 ctx2.Dispose(ctx2->GetIsolate()); 1765 ctx2.Dispose(ctx2->GetIsolate());
1764 HEAP->CollectAllAvailableGarbage(); 1766 HEAP->CollectAllAvailableGarbage();
1765 CHECK_EQ(0, NumberOfGlobalObjects()); 1767 CHECK_EQ(0, NumberOfGlobalObjects());
1766 } 1768 }
1767 1769
1768 1770
1769 TEST(LeakNativeContextViaMapProto) { 1771 TEST(LeakNativeContextViaMapProto) {
1770 i::FLAG_allow_natives_syntax = true; 1772 i::FLAG_allow_natives_syntax = true;
1771 v8::HandleScope outer_scope; 1773 v8::HandleScope outer_scope(v8::Isolate::GetCurrent());
1772 v8::Persistent<v8::Context> ctx1 = v8::Context::New(); 1774 v8::Persistent<v8::Context> ctx1 = v8::Context::New();
1773 v8::Persistent<v8::Context> ctx2 = v8::Context::New(); 1775 v8::Persistent<v8::Context> ctx2 = v8::Context::New();
1774 ctx1->Enter(); 1776 ctx1->Enter();
1775 1777
1776 HEAP->CollectAllAvailableGarbage(); 1778 HEAP->CollectAllAvailableGarbage();
1777 CHECK_EQ(4, NumberOfGlobalObjects()); 1779 CHECK_EQ(4, NumberOfGlobalObjects());
1778 1780
1779 { 1781 {
1780 v8::HandleScope inner_scope; 1782 v8::HandleScope inner_scope(v8::Isolate::GetCurrent());
1781 CompileRun("var v = { y: 42}"); 1783 CompileRun("var v = { y: 42}");
1782 v8::Local<v8::Value> v = ctx1->Global()->Get(v8_str("v")); 1784 v8::Local<v8::Value> v = ctx1->Global()->Get(v8_str("v"));
1783 ctx2->Enter(); 1785 ctx2->Enter();
1784 ctx2->Global()->Set(v8_str("o"), v); 1786 ctx2->Global()->Set(v8_str("o"), v);
1785 v8::Local<v8::Value> res = CompileRun( 1787 v8::Local<v8::Value> res = CompileRun(
1786 "function f() {" 1788 "function f() {"
1787 " var p = {x: 42};" 1789 " var p = {x: 42};"
1788 " p.__proto__ = o;" 1790 " p.__proto__ = o;"
1789 " return p.x;" 1791 " return p.x;"
1790 "}" 1792 "}"
(...skipping 17 matching lines...) Expand all
1808 1810
1809 TEST(InstanceOfStubWriteBarrier) { 1811 TEST(InstanceOfStubWriteBarrier) {
1810 i::FLAG_allow_natives_syntax = true; 1812 i::FLAG_allow_natives_syntax = true;
1811 #ifdef VERIFY_HEAP 1813 #ifdef VERIFY_HEAP
1812 i::FLAG_verify_heap = true; 1814 i::FLAG_verify_heap = true;
1813 #endif 1815 #endif
1814 1816
1815 InitializeVM(); 1817 InitializeVM();
1816 if (!i::V8::UseCrankshaft()) return; 1818 if (!i::V8::UseCrankshaft()) return;
1817 if (i::FLAG_force_marking_deque_overflows) return; 1819 if (i::FLAG_force_marking_deque_overflows) return;
1818 v8::HandleScope outer_scope; 1820 v8::HandleScope outer_scope(v8::Isolate::GetCurrent());
1819 1821
1820 { 1822 {
1821 v8::HandleScope scope; 1823 v8::HandleScope scope(v8::Isolate::GetCurrent());
1822 CompileRun( 1824 CompileRun(
1823 "function foo () { }" 1825 "function foo () { }"
1824 "function mkbar () { return new (new Function(\"\")) (); }" 1826 "function mkbar () { return new (new Function(\"\")) (); }"
1825 "function f (x) { return (x instanceof foo); }" 1827 "function f (x) { return (x instanceof foo); }"
1826 "function g () { f(mkbar()); }" 1828 "function g () { f(mkbar()); }"
1827 "f(new foo()); f(new foo());" 1829 "f(new foo()); f(new foo());"
1828 "%OptimizeFunctionOnNextCall(f);" 1830 "%OptimizeFunctionOnNextCall(f);"
1829 "f(new foo()); g();"); 1831 "f(new foo()); g();");
1830 } 1832 }
1831 1833
(...skipping 11 matching lines...) Expand all
1843 while (!Marking::IsBlack(Marking::MarkBitFrom(f->code())) && 1845 while (!Marking::IsBlack(Marking::MarkBitFrom(f->code())) &&
1844 !marking->IsStopped()) { 1846 !marking->IsStopped()) {
1845 // Discard any pending GC requests otherwise we will get GC when we enter 1847 // Discard any pending GC requests otherwise we will get GC when we enter
1846 // code below. 1848 // code below.
1847 marking->Step(MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); 1849 marking->Step(MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD);
1848 } 1850 }
1849 1851
1850 CHECK(marking->IsMarking()); 1852 CHECK(marking->IsMarking());
1851 1853
1852 { 1854 {
1853 v8::HandleScope scope; 1855 v8::HandleScope scope(v8::Isolate::GetCurrent());
1854 v8::Handle<v8::Object> global = v8::Context::GetCurrent()->Global(); 1856 v8::Handle<v8::Object> global = v8::Context::GetCurrent()->Global();
1855 v8::Handle<v8::Function> g = 1857 v8::Handle<v8::Function> g =
1856 v8::Handle<v8::Function>::Cast(global->Get(v8_str("g"))); 1858 v8::Handle<v8::Function>::Cast(global->Get(v8_str("g")));
1857 g->Call(global, 0, NULL); 1859 g->Call(global, 0, NULL);
1858 } 1860 }
1859 1861
1860 HEAP->incremental_marking()->set_should_hurry(true); 1862 HEAP->incremental_marking()->set_should_hurry(true);
1861 HEAP->CollectGarbage(OLD_POINTER_SPACE); 1863 HEAP->CollectGarbage(OLD_POINTER_SPACE);
1862 } 1864 }
1863 1865
1864 1866
1865 TEST(PrototypeTransitionClearing) { 1867 TEST(PrototypeTransitionClearing) {
1866 InitializeVM(); 1868 InitializeVM();
1867 v8::HandleScope scope; 1869 v8::HandleScope scope(env->GetIsolate());
1868 1870
1869 CompileRun( 1871 CompileRun(
1870 "var base = {};" 1872 "var base = {};"
1871 "var live = [];" 1873 "var live = [];"
1872 "for (var i = 0; i < 10; i++) {" 1874 "for (var i = 0; i < 10; i++) {"
1873 " var object = {};" 1875 " var object = {};"
1874 " var prototype = {};" 1876 " var prototype = {};"
1875 " object.__proto__ = prototype;" 1877 " object.__proto__ = prototype;"
1876 " if (i >= 3) live.push(object, prototype);" 1878 " if (i >= 3) live.push(object, prototype);"
1877 "}"); 1879 "}");
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1921 1923
1922 1924
1923 TEST(ResetSharedFunctionInfoCountersDuringIncrementalMarking) { 1925 TEST(ResetSharedFunctionInfoCountersDuringIncrementalMarking) {
1924 i::FLAG_allow_natives_syntax = true; 1926 i::FLAG_allow_natives_syntax = true;
1925 #ifdef VERIFY_HEAP 1927 #ifdef VERIFY_HEAP
1926 i::FLAG_verify_heap = true; 1928 i::FLAG_verify_heap = true;
1927 #endif 1929 #endif
1928 1930
1929 InitializeVM(); 1931 InitializeVM();
1930 if (!i::V8::UseCrankshaft()) return; 1932 if (!i::V8::UseCrankshaft()) return;
1931 v8::HandleScope outer_scope; 1933 v8::HandleScope outer_scope(v8::Isolate::GetCurrent());
1932 1934
1933 { 1935 {
1934 v8::HandleScope scope; 1936 v8::HandleScope scope(v8::Isolate::GetCurrent());
1935 CompileRun( 1937 CompileRun(
1936 "function f () {" 1938 "function f () {"
1937 " var s = 0;" 1939 " var s = 0;"
1938 " for (var i = 0; i < 100; i++) s += i;" 1940 " for (var i = 0; i < 100; i++) s += i;"
1939 " return s;" 1941 " return s;"
1940 "}" 1942 "}"
1941 "f(); f();" 1943 "f(); f();"
1942 "%OptimizeFunctionOnNextCall(f);" 1944 "%OptimizeFunctionOnNextCall(f);"
1943 "f();"); 1945 "f();");
1944 } 1946 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1977 1979
1978 1980
1979 TEST(ResetSharedFunctionInfoCountersDuringMarkSweep) { 1981 TEST(ResetSharedFunctionInfoCountersDuringMarkSweep) {
1980 i::FLAG_allow_natives_syntax = true; 1982 i::FLAG_allow_natives_syntax = true;
1981 #ifdef VERIFY_HEAP 1983 #ifdef VERIFY_HEAP
1982 i::FLAG_verify_heap = true; 1984 i::FLAG_verify_heap = true;
1983 #endif 1985 #endif
1984 1986
1985 InitializeVM(); 1987 InitializeVM();
1986 if (!i::V8::UseCrankshaft()) return; 1988 if (!i::V8::UseCrankshaft()) return;
1987 v8::HandleScope outer_scope; 1989 v8::HandleScope outer_scope(env->GetIsolate());
1988 1990
1989 { 1991 {
1990 v8::HandleScope scope; 1992 v8::HandleScope scope(env->GetIsolate());
1991 CompileRun( 1993 CompileRun(
1992 "function f () {" 1994 "function f () {"
1993 " var s = 0;" 1995 " var s = 0;"
1994 " for (var i = 0; i < 100; i++) s += i;" 1996 " for (var i = 0; i < 100; i++) s += i;"
1995 " return s;" 1997 " return s;"
1996 "}" 1998 "}"
1997 "f(); f();" 1999 "f(); f();"
1998 "%OptimizeFunctionOnNextCall(f);" 2000 "%OptimizeFunctionOnNextCall(f);"
1999 "f();"); 2001 "f();");
2000 } 2002 }
(...skipping 16 matching lines...) Expand all
2017 CHECK_EQ(0, f->shared()->code()->profiler_ticks()); 2019 CHECK_EQ(0, f->shared()->code()->profiler_ticks());
2018 } 2020 }
2019 2021
2020 2022
2021 // Test that HAllocateObject will always return an object in new-space. 2023 // Test that HAllocateObject will always return an object in new-space.
2022 TEST(OptimizedAllocationAlwaysInNewSpace) { 2024 TEST(OptimizedAllocationAlwaysInNewSpace) {
2023 i::FLAG_allow_natives_syntax = true; 2025 i::FLAG_allow_natives_syntax = true;
2024 InitializeVM(); 2026 InitializeVM();
2025 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; 2027 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return;
2026 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; 2028 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
2027 v8::HandleScope scope; 2029 v8::HandleScope scope(env->GetIsolate());
2028 2030
2029 SimulateFullSpace(HEAP->new_space()); 2031 SimulateFullSpace(HEAP->new_space());
2030 AlwaysAllocateScope always_allocate; 2032 AlwaysAllocateScope always_allocate;
2031 v8::Local<v8::Value> res = CompileRun( 2033 v8::Local<v8::Value> res = CompileRun(
2032 "function c(x) {" 2034 "function c(x) {"
2033 " this.x = x;" 2035 " this.x = x;"
2034 " for (var i = 0; i < 32; i++) {" 2036 " for (var i = 0; i < 32; i++) {"
2035 " this['x' + i] = x;" 2037 " this['x' + i] = x;"
2036 " }" 2038 " }"
2037 "}" 2039 "}"
2038 "function f(x) { return new c(x); };" 2040 "function f(x) { return new c(x); };"
2039 "f(1); f(2); f(3);" 2041 "f(1); f(2); f(3);"
2040 "%OptimizeFunctionOnNextCall(f);" 2042 "%OptimizeFunctionOnNextCall(f);"
2041 "f(4);"); 2043 "f(4);");
2042 CHECK_EQ(4, res->ToObject()->GetRealNamedProperty(v8_str("x"))->Int32Value()); 2044 CHECK_EQ(4, res->ToObject()->GetRealNamedProperty(v8_str("x"))->Int32Value());
2043 2045
2044 Handle<JSObject> o = 2046 Handle<JSObject> o =
2045 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); 2047 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
2046 2048
2047 CHECK(HEAP->InNewSpace(*o)); 2049 CHECK(HEAP->InNewSpace(*o));
2048 } 2050 }
2049 2051
2050 2052
2051 // Test pretenuring of array literals allocated with HAllocate. 2053 // Test pretenuring of array literals allocated with HAllocate.
2052 TEST(OptimizedPretenuringArrayLiterals) { 2054 TEST(OptimizedPretenuringArrayLiterals) {
2053 i::FLAG_allow_natives_syntax = true; 2055 i::FLAG_allow_natives_syntax = true;
2054 InitializeVM(); 2056 InitializeVM();
2055 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; 2057 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return;
2056 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; 2058 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
2057 v8::HandleScope scope; 2059 v8::HandleScope scope(env->GetIsolate());
2058 2060
2059 AlwaysAllocateScope always_allocate; 2061 AlwaysAllocateScope always_allocate;
2060 v8::Local<v8::Value> res = CompileRun( 2062 v8::Local<v8::Value> res = CompileRun(
2061 "function f() {" 2063 "function f() {"
2062 " var numbers = new Array(1, 2, 3);" 2064 " var numbers = new Array(1, 2, 3);"
2063 " numbers[0] = 3.14;" 2065 " numbers[0] = 3.14;"
2064 " return numbers;" 2066 " return numbers;"
2065 "};" 2067 "};"
2066 "f(); f(); f();" 2068 "f(); f(); f();"
2067 "%OptimizeFunctionOnNextCall(f);" 2069 "%OptimizeFunctionOnNextCall(f);"
(...skipping 10 matching lines...) Expand all
2078 CHECK(HEAP->InNewSpace(*o)); 2080 CHECK(HEAP->InNewSpace(*o));
2079 } 2081 }
2080 2082
2081 2083
2082 // Test regular array literals allocation. 2084 // Test regular array literals allocation.
2083 TEST(OptimizedAllocationArrayLiterals) { 2085 TEST(OptimizedAllocationArrayLiterals) {
2084 i::FLAG_allow_natives_syntax = true; 2086 i::FLAG_allow_natives_syntax = true;
2085 InitializeVM(); 2087 InitializeVM();
2086 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; 2088 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return;
2087 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; 2089 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
2088 v8::HandleScope scope; 2090 v8::HandleScope scope(env->GetIsolate());
2089 2091
2090 AlwaysAllocateScope always_allocate; 2092 AlwaysAllocateScope always_allocate;
2091 v8::Local<v8::Value> res = CompileRun( 2093 v8::Local<v8::Value> res = CompileRun(
2092 "function f() {" 2094 "function f() {"
2093 " var numbers = new Array(1, 2, 3);" 2095 " var numbers = new Array(1, 2, 3);"
2094 " numbers[0] = 3.14;" 2096 " numbers[0] = 3.14;"
2095 " return numbers;" 2097 " return numbers;"
2096 "};" 2098 "};"
2097 "f(); f(); f();" 2099 "f(); f(); f();"
2098 "%OptimizeFunctionOnNextCall(f);" 2100 "%OptimizeFunctionOnNextCall(f);"
(...skipping 12 matching lines...) Expand all
2111 return map->transitions()->number_of_transitions(); 2113 return map->transitions()->number_of_transitions();
2112 } 2114 }
2113 2115
2114 2116
2115 // Test that map transitions are cleared and maps are collected with 2117 // Test that map transitions are cleared and maps are collected with
2116 // incremental marking as well. 2118 // incremental marking as well.
2117 TEST(Regress1465) { 2119 TEST(Regress1465) {
2118 i::FLAG_allow_natives_syntax = true; 2120 i::FLAG_allow_natives_syntax = true;
2119 i::FLAG_trace_incremental_marking = true; 2121 i::FLAG_trace_incremental_marking = true;
2120 InitializeVM(); 2122 InitializeVM();
2121 v8::HandleScope scope; 2123 v8::HandleScope scope(env->GetIsolate());
2122 static const int transitions_count = 256; 2124 static const int transitions_count = 256;
2123 2125
2124 { 2126 {
2125 AlwaysAllocateScope always_allocate; 2127 AlwaysAllocateScope always_allocate;
2126 for (int i = 0; i < transitions_count; i++) { 2128 for (int i = 0; i < transitions_count; i++) {
2127 EmbeddedVector<char, 64> buffer; 2129 EmbeddedVector<char, 64> buffer;
2128 OS::SNPrintF(buffer, "var o = new Object; o.prop%d = %d;", i, i); 2130 OS::SNPrintF(buffer, "var o = new Object; o.prop%d = %d;", i, i);
2129 CompileRun(buffer.start()); 2131 CompileRun(buffer.start());
2130 } 2132 }
2131 CompileRun("var root = new Object;"); 2133 CompileRun("var root = new Object;");
(...skipping 17 matching lines...) Expand all
2149 int transitions_after = CountMapTransitions(root->map()); 2151 int transitions_after = CountMapTransitions(root->map());
2150 CompileRun("%DebugPrint(root);"); 2152 CompileRun("%DebugPrint(root);");
2151 CHECK_EQ(1, transitions_after); 2153 CHECK_EQ(1, transitions_after);
2152 } 2154 }
2153 2155
2154 2156
2155 TEST(Regress2143a) { 2157 TEST(Regress2143a) {
2156 i::FLAG_collect_maps = true; 2158 i::FLAG_collect_maps = true;
2157 i::FLAG_incremental_marking = true; 2159 i::FLAG_incremental_marking = true;
2158 InitializeVM(); 2160 InitializeVM();
2159 v8::HandleScope scope; 2161 v8::HandleScope scope(env->GetIsolate());
2160 2162
2161 // Prepare a map transition from the root object together with a yet 2163 // Prepare a map transition from the root object together with a yet
2162 // untransitioned root object. 2164 // untransitioned root object.
2163 CompileRun("var root = new Object;" 2165 CompileRun("var root = new Object;"
2164 "root.foo = 0;" 2166 "root.foo = 0;"
2165 "root = new Object;"); 2167 "root = new Object;");
2166 2168
2167 SimulateIncrementalMarking(); 2169 SimulateIncrementalMarking();
2168 2170
2169 // Compile a StoreIC that performs the prepared map transition. This 2171 // Compile a StoreIC that performs the prepared map transition. This
(...skipping 20 matching lines...) Expand all
2190 CHECK(root->IsJSObject()); 2192 CHECK(root->IsJSObject());
2191 CHECK(root->map()->IsMap()); 2193 CHECK(root->map()->IsMap());
2192 } 2194 }
2193 2195
2194 2196
2195 TEST(Regress2143b) { 2197 TEST(Regress2143b) {
2196 i::FLAG_collect_maps = true; 2198 i::FLAG_collect_maps = true;
2197 i::FLAG_incremental_marking = true; 2199 i::FLAG_incremental_marking = true;
2198 i::FLAG_allow_natives_syntax = true; 2200 i::FLAG_allow_natives_syntax = true;
2199 InitializeVM(); 2201 InitializeVM();
2200 v8::HandleScope scope; 2202 v8::HandleScope scope(env->GetIsolate());
2201 2203
2202 // Prepare a map transition from the root object together with a yet 2204 // Prepare a map transition from the root object together with a yet
2203 // untransitioned root object. 2205 // untransitioned root object.
2204 CompileRun("var root = new Object;" 2206 CompileRun("var root = new Object;"
2205 "root.foo = 0;" 2207 "root.foo = 0;"
2206 "root = new Object;"); 2208 "root = new Object;");
2207 2209
2208 SimulateIncrementalMarking(); 2210 SimulateIncrementalMarking();
2209 2211
2210 // Compile an optimized LStoreNamedField that performs the prepared 2212 // Compile an optimized LStoreNamedField that performs the prepared
(...skipping 24 matching lines...) Expand all
2235 CHECK(root->map()->IsMap()); 2237 CHECK(root->map()->IsMap());
2236 } 2238 }
2237 2239
2238 2240
2239 TEST(ReleaseOverReservedPages) { 2241 TEST(ReleaseOverReservedPages) {
2240 i::FLAG_trace_gc = true; 2242 i::FLAG_trace_gc = true;
2241 // The optimizer can allocate stuff, messing up the test. 2243 // The optimizer can allocate stuff, messing up the test.
2242 i::FLAG_crankshaft = false; 2244 i::FLAG_crankshaft = false;
2243 i::FLAG_always_opt = false; 2245 i::FLAG_always_opt = false;
2244 InitializeVM(); 2246 InitializeVM();
2245 v8::HandleScope scope; 2247 v8::HandleScope scope(env->GetIsolate());
2246 static const int number_of_test_pages = 20; 2248 static const int number_of_test_pages = 20;
2247 2249
2248 // Prepare many pages with low live-bytes count. 2250 // Prepare many pages with low live-bytes count.
2249 PagedSpace* old_pointer_space = HEAP->old_pointer_space(); 2251 PagedSpace* old_pointer_space = HEAP->old_pointer_space();
2250 CHECK_EQ(1, old_pointer_space->CountTotalPages()); 2252 CHECK_EQ(1, old_pointer_space->CountTotalPages());
2251 for (int i = 0; i < number_of_test_pages; i++) { 2253 for (int i = 0; i < number_of_test_pages; i++) {
2252 AlwaysAllocateScope always_allocate; 2254 AlwaysAllocateScope always_allocate;
2253 SimulateFullSpace(old_pointer_space); 2255 SimulateFullSpace(old_pointer_space);
2254 FACTORY->NewFixedArray(1, TENURED); 2256 FACTORY->NewFixedArray(1, TENURED);
2255 } 2257 }
(...skipping 18 matching lines...) Expand all
2274 // first page should be small in order to reduce memory used when the VM 2276 // first page should be small in order to reduce memory used when the VM
2275 // boots, but if the 20 small arrays don't fit on the first page then that's 2277 // boots, but if the 20 small arrays don't fit on the first page then that's
2276 // an indication that it is too small. 2278 // an indication that it is too small.
2277 HEAP->CollectAllAvailableGarbage("triggered really hard"); 2279 HEAP->CollectAllAvailableGarbage("triggered really hard");
2278 CHECK_EQ(1, old_pointer_space->CountTotalPages()); 2280 CHECK_EQ(1, old_pointer_space->CountTotalPages());
2279 } 2281 }
2280 2282
2281 2283
2282 TEST(Regress2237) { 2284 TEST(Regress2237) {
2283 InitializeVM(); 2285 InitializeVM();
2284 v8::HandleScope scope; 2286 v8::HandleScope scope(env->GetIsolate());
2285 Handle<String> slice(HEAP->empty_string()); 2287 Handle<String> slice(HEAP->empty_string());
2286 2288
2287 { 2289 {
2288 // Generate a parent that lives in new-space. 2290 // Generate a parent that lives in new-space.
2289 v8::HandleScope inner_scope; 2291 v8::HandleScope inner_scope(env->GetIsolate());
2290 const char* c = "This text is long enough to trigger sliced strings."; 2292 const char* c = "This text is long enough to trigger sliced strings.";
2291 Handle<String> s = FACTORY->NewStringFromAscii(CStrVector(c)); 2293 Handle<String> s = FACTORY->NewStringFromAscii(CStrVector(c));
2292 CHECK(s->IsSeqOneByteString()); 2294 CHECK(s->IsSeqOneByteString());
2293 CHECK(HEAP->InNewSpace(*s)); 2295 CHECK(HEAP->InNewSpace(*s));
2294 2296
2295 // Generate a sliced string that is based on the above parent and 2297 // Generate a sliced string that is based on the above parent and
2296 // lives in old-space. 2298 // lives in old-space.
2297 SimulateFullSpace(HEAP->new_space()); 2299 SimulateFullSpace(HEAP->new_space());
2298 AlwaysAllocateScope always_allocate; 2300 AlwaysAllocateScope always_allocate;
2299 Handle<String> t = FACTORY->NewProperSubString(s, 5, 35); 2301 Handle<String> t = FACTORY->NewProperSubString(s, 5, 35);
2300 CHECK(t->IsSlicedString()); 2302 CHECK(t->IsSlicedString());
2301 CHECK(!HEAP->InNewSpace(*t)); 2303 CHECK(!HEAP->InNewSpace(*t));
2302 *slice.location() = *t.location(); 2304 *slice.location() = *t.location();
2303 } 2305 }
2304 2306
2305 CHECK(SlicedString::cast(*slice)->parent()->IsSeqOneByteString()); 2307 CHECK(SlicedString::cast(*slice)->parent()->IsSeqOneByteString());
2306 HEAP->CollectAllGarbage(Heap::kNoGCFlags); 2308 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
2307 CHECK(SlicedString::cast(*slice)->parent()->IsSeqOneByteString()); 2309 CHECK(SlicedString::cast(*slice)->parent()->IsSeqOneByteString());
2308 } 2310 }
2309 2311
2310 2312
2311 #ifdef OBJECT_PRINT 2313 #ifdef OBJECT_PRINT
2312 TEST(PrintSharedFunctionInfo) { 2314 TEST(PrintSharedFunctionInfo) {
2313 InitializeVM(); 2315 InitializeVM();
2314 v8::HandleScope scope; 2316 v8::HandleScope scope(env->GetIsolate());
2315 const char* source = "f = function() { return 987654321; }\n" 2317 const char* source = "f = function() { return 987654321; }\n"
2316 "g = function() { return 123456789; }\n"; 2318 "g = function() { return 123456789; }\n";
2317 CompileRun(source); 2319 CompileRun(source);
2318 Handle<JSFunction> g = 2320 Handle<JSFunction> g =
2319 v8::Utils::OpenHandle( 2321 v8::Utils::OpenHandle(
2320 *v8::Handle<v8::Function>::Cast( 2322 *v8::Handle<v8::Function>::Cast(
2321 v8::Context::GetCurrent()->Global()->Get(v8_str("g")))); 2323 v8::Context::GetCurrent()->Global()->Get(v8_str("g"))));
2322 2324
2323 AssertNoAllocation no_alloc; 2325 AssertNoAllocation no_alloc;
2324 g->shared()->PrintLn(); 2326 g->shared()->PrintLn();
2325 } 2327 }
2326 #endif // OBJECT_PRINT 2328 #endif // OBJECT_PRINT
2327 2329
2328 2330
2329 TEST(Regress2211) { 2331 TEST(Regress2211) {
2330 InitializeVM(); 2332 InitializeVM();
2331 v8::HandleScope scope; 2333 v8::HandleScope scope(env->GetIsolate());
2332 2334
2333 v8::Handle<v8::String> value = v8_str("val string"); 2335 v8::Handle<v8::String> value = v8_str("val string");
2334 Smi* hash = Smi::FromInt(321); 2336 Smi* hash = Smi::FromInt(321);
2335 Heap* heap = Isolate::Current()->heap(); 2337 Heap* heap = Isolate::Current()->heap();
2336 2338
2337 for (int i = 0; i < 2; i++) { 2339 for (int i = 0; i < 2; i++) {
2338 // Store identity hash first and common hidden property second. 2340 // Store identity hash first and common hidden property second.
2339 v8::Handle<v8::Object> obj = v8::Object::New(); 2341 v8::Handle<v8::Object> obj = v8::Object::New();
2340 Handle<JSObject> internal_obj = v8::Utils::OpenHandle(*obj); 2342 Handle<JSObject> internal_obj = v8::Utils::OpenHandle(*obj);
2341 CHECK(internal_obj->HasFastProperties()); 2343 CHECK(internal_obj->HasFastProperties());
(...skipping 17 matching lines...) Expand all
2359 internal_obj->FastPropertyAt(descriptors->GetFieldIndex(0))); 2361 internal_obj->FastPropertyAt(descriptors->GetFieldIndex(0)));
2360 // HashTable header (5) and 4 initial entries (8). 2362 // HashTable header (5) and 4 initial entries (8).
2361 CHECK_LE(hashtable->SizeFor(hashtable->length()), 13 * kPointerSize); 2363 CHECK_LE(hashtable->SizeFor(hashtable->length()), 13 * kPointerSize);
2362 } 2364 }
2363 } 2365 }
2364 2366
2365 2367
2366 TEST(IncrementalMarkingClearsTypeFeedbackCells) { 2368 TEST(IncrementalMarkingClearsTypeFeedbackCells) {
2367 if (i::FLAG_always_opt) return; 2369 if (i::FLAG_always_opt) return;
2368 InitializeVM(); 2370 InitializeVM();
2369 v8::HandleScope scope; 2371 v8::HandleScope scope(env->GetIsolate());
2370 v8::Local<v8::Value> fun1, fun2; 2372 v8::Local<v8::Value> fun1, fun2;
2371 2373
2372 { 2374 {
2373 LocalContext env; 2375 LocalContext env;
2374 CompileRun("function fun() {};"); 2376 CompileRun("function fun() {};");
2375 fun1 = env->Global()->Get(v8_str("fun")); 2377 fun1 = env->Global()->Get(v8_str("fun"));
2376 } 2378 }
2377 2379
2378 { 2380 {
2379 LocalContext env; 2381 LocalContext env;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2418 return target; 2420 return target;
2419 } 2421 }
2420 } 2422 }
2421 return NULL; 2423 return NULL;
2422 } 2424 }
2423 2425
2424 2426
2425 TEST(IncrementalMarkingPreservesMonomorhpicIC) { 2427 TEST(IncrementalMarkingPreservesMonomorhpicIC) {
2426 if (i::FLAG_always_opt) return; 2428 if (i::FLAG_always_opt) return;
2427 InitializeVM(); 2429 InitializeVM();
2428 v8::HandleScope scope; 2430 v8::HandleScope scope(env->GetIsolate());
2429 2431
2430 // Prepare function f that contains a monomorphic IC for object 2432 // Prepare function f that contains a monomorphic IC for object
2431 // originating from the same native context. 2433 // originating from the same native context.
2432 CompileRun("function fun() { this.x = 1; }; var obj = new fun();" 2434 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"
2433 "function f(o) { return o.x; } f(obj); f(obj);"); 2435 "function f(o) { return o.x; } f(obj); f(obj);");
2434 Handle<JSFunction> f = 2436 Handle<JSFunction> f =
2435 v8::Utils::OpenHandle( 2437 v8::Utils::OpenHandle(
2436 *v8::Handle<v8::Function>::Cast( 2438 *v8::Handle<v8::Function>::Cast(
2437 v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); 2439 v8::Context::GetCurrent()->Global()->Get(v8_str("f"))));
2438 2440
2439 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); 2441 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC);
2440 CHECK(ic_before->ic_state() == MONOMORPHIC); 2442 CHECK(ic_before->ic_state() == MONOMORPHIC);
2441 2443
2442 SimulateIncrementalMarking(); 2444 SimulateIncrementalMarking();
2443 HEAP->CollectAllGarbage(Heap::kNoGCFlags); 2445 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
2444 2446
2445 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); 2447 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC);
2446 CHECK(ic_after->ic_state() == MONOMORPHIC); 2448 CHECK(ic_after->ic_state() == MONOMORPHIC);
2447 } 2449 }
2448 2450
2449 2451
2450 TEST(IncrementalMarkingClearsMonomorhpicIC) { 2452 TEST(IncrementalMarkingClearsMonomorhpicIC) {
2451 if (i::FLAG_always_opt) return; 2453 if (i::FLAG_always_opt) return;
2452 InitializeVM(); 2454 InitializeVM();
2453 v8::HandleScope scope; 2455 v8::HandleScope scope(env->GetIsolate());
2454 v8::Local<v8::Value> obj1; 2456 v8::Local<v8::Value> obj1;
2455 2457
2456 { 2458 {
2457 LocalContext env; 2459 LocalContext env;
2458 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); 2460 CompileRun("function fun() { this.x = 1; }; var obj = new fun();");
2459 obj1 = env->Global()->Get(v8_str("obj")); 2461 obj1 = env->Global()->Get(v8_str("obj"));
2460 } 2462 }
2461 2463
2462 // Prepare function f that contains a monomorphic IC for object 2464 // Prepare function f that contains a monomorphic IC for object
2463 // originating from a different native context. 2465 // originating from a different native context.
(...skipping 13 matching lines...) Expand all
2477 HEAP->CollectAllGarbage(Heap::kNoGCFlags); 2479 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
2478 2480
2479 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); 2481 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC);
2480 CHECK(ic_after->ic_state() == UNINITIALIZED); 2482 CHECK(ic_after->ic_state() == UNINITIALIZED);
2481 } 2483 }
2482 2484
2483 2485
2484 TEST(IncrementalMarkingClearsPolymorhpicIC) { 2486 TEST(IncrementalMarkingClearsPolymorhpicIC) {
2485 if (i::FLAG_always_opt) return; 2487 if (i::FLAG_always_opt) return;
2486 InitializeVM(); 2488 InitializeVM();
2487 v8::HandleScope scope; 2489 v8::HandleScope scope(env->GetIsolate());
2488 v8::Local<v8::Value> obj1, obj2; 2490 v8::Local<v8::Value> obj1, obj2;
2489 2491
2490 { 2492 {
2491 LocalContext env; 2493 LocalContext env;
2492 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); 2494 CompileRun("function fun() { this.x = 1; }; var obj = new fun();");
2493 obj1 = env->Global()->Get(v8_str("obj")); 2495 obj1 = env->Global()->Get(v8_str("obj"));
2494 } 2496 }
2495 2497
2496 { 2498 {
2497 LocalContext env; 2499 LocalContext env;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2543 size_t length_; 2545 size_t length_;
2544 }; 2546 };
2545 2547
2546 2548
2547 void ReleaseStackTraceDataTest(const char* source) { 2549 void ReleaseStackTraceDataTest(const char* source) {
2548 // Test that the data retained by the Error.stack accessor is released 2550 // Test that the data retained by the Error.stack accessor is released
2549 // after the first time the accessor is fired. We use external string 2551 // after the first time the accessor is fired. We use external string
2550 // to check whether the data is being released since the external string 2552 // to check whether the data is being released since the external string
2551 // resource's callback is fired when the external string is GC'ed. 2553 // resource's callback is fired when the external string is GC'ed.
2552 InitializeVM(); 2554 InitializeVM();
2553 v8::HandleScope scope; 2555 v8::HandleScope scope(env->GetIsolate());
2554 SourceResource* resource = new SourceResource(i::StrDup(source)); 2556 SourceResource* resource = new SourceResource(i::StrDup(source));
2555 { 2557 {
2556 v8::HandleScope scope; 2558 v8::HandleScope scope(env->GetIsolate());
2557 v8::Handle<v8::String> source_string = v8::String::NewExternal(resource); 2559 v8::Handle<v8::String> source_string = v8::String::NewExternal(resource);
2558 v8::Script::Compile(source_string)->Run(); 2560 v8::Script::Compile(source_string)->Run();
2559 CHECK(!resource->IsDisposed()); 2561 CHECK(!resource->IsDisposed());
2560 } 2562 }
2561 HEAP->CollectAllAvailableGarbage(); 2563 HEAP->CollectAllAvailableGarbage();
2562 2564
2563 // External source has been released. 2565 // External source has been released.
2564 CHECK(resource->IsDisposed()); 2566 CHECK(resource->IsDisposed());
2565 delete resource; 2567 delete resource;
2566 } 2568 }
(...skipping 14 matching lines...) Expand all
2581 "} "; 2583 "} ";
2582 ReleaseStackTraceDataTest(source1); 2584 ReleaseStackTraceDataTest(source1);
2583 ReleaseStackTraceDataTest(source2); 2585 ReleaseStackTraceDataTest(source2);
2584 } 2586 }
2585 2587
2586 2588
2587 TEST(Regression144230) { 2589 TEST(Regression144230) {
2588 InitializeVM(); 2590 InitializeVM();
2589 Isolate* isolate = Isolate::Current(); 2591 Isolate* isolate = Isolate::Current();
2590 Heap* heap = isolate->heap(); 2592 Heap* heap = isolate->heap();
2591 v8::HandleScope scope; 2593 HandleScope scope(isolate);
2592 2594
2593 // First make sure that the uninitialized CallIC stub is on a single page 2595 // First make sure that the uninitialized CallIC stub is on a single page
2594 // that will later be selected as an evacuation candidate. 2596 // that will later be selected as an evacuation candidate.
2595 { 2597 {
2596 v8::HandleScope inner_scope; 2598 HandleScope inner_scope(isolate);
2597 AlwaysAllocateScope always_allocate; 2599 AlwaysAllocateScope always_allocate;
2598 SimulateFullSpace(heap->code_space()); 2600 SimulateFullSpace(heap->code_space());
2599 isolate->stub_cache()->ComputeCallInitialize(9, RelocInfo::CODE_TARGET); 2601 isolate->stub_cache()->ComputeCallInitialize(9, RelocInfo::CODE_TARGET);
2600 } 2602 }
2601 2603
2602 // Second compile a CallIC and execute it once so that it gets patched to 2604 // Second compile a CallIC and execute it once so that it gets patched to
2603 // the pre-monomorphic stub. These code objects are on yet another page. 2605 // the pre-monomorphic stub. These code objects are on yet another page.
2604 { 2606 {
2605 v8::HandleScope inner_scope; 2607 HandleScope inner_scope(isolate);
2606 AlwaysAllocateScope always_allocate; 2608 AlwaysAllocateScope always_allocate;
2607 SimulateFullSpace(heap->code_space()); 2609 SimulateFullSpace(heap->code_space());
2608 CompileRun("var o = { f:function(a,b,c,d,e,f,g,h,i) {}};" 2610 CompileRun("var o = { f:function(a,b,c,d,e,f,g,h,i) {}};"
2609 "function call() { o.f(1,2,3,4,5,6,7,8,9); };" 2611 "function call() { o.f(1,2,3,4,5,6,7,8,9); };"
2610 "call();"); 2612 "call();");
2611 } 2613 }
2612 2614
2613 // Third we fill up the last page of the code space so that it does not get 2615 // Third we fill up the last page of the code space so that it does not get
2614 // chosen as an evacuation candidate. 2616 // chosen as an evacuation candidate.
2615 { 2617 {
2616 v8::HandleScope inner_scope; 2618 HandleScope inner_scope(isolate);
2617 AlwaysAllocateScope always_allocate; 2619 AlwaysAllocateScope always_allocate;
2618 CompileRun("for (var i = 0; i < 2000; i++) {" 2620 CompileRun("for (var i = 0; i < 2000; i++) {"
2619 " eval('function f' + i + '() { return ' + i +'; };' +" 2621 " eval('function f' + i + '() { return ' + i +'; };' +"
2620 " 'f' + i + '();');" 2622 " 'f' + i + '();');"
2621 "}"); 2623 "}");
2622 } 2624 }
2623 heap->CollectAllGarbage(Heap::kNoGCFlags); 2625 heap->CollectAllGarbage(Heap::kNoGCFlags);
2624 2626
2625 // Fourth is the tricky part. Make sure the code containing the CallIC is 2627 // Fourth is the tricky part. Make sure the code containing the CallIC is
2626 // visited first without clearing the IC. The shared function info is then 2628 // visited first without clearing the IC. The shared function info is then
(...skipping 17 matching lines...) Expand all
2644 CompileRun("call();"); 2646 CompileRun("call();");
2645 } 2647 }
2646 2648
2647 2649
2648 TEST(Regress159140) { 2650 TEST(Regress159140) {
2649 i::FLAG_allow_natives_syntax = true; 2651 i::FLAG_allow_natives_syntax = true;
2650 i::FLAG_flush_code_incrementally = true; 2652 i::FLAG_flush_code_incrementally = true;
2651 InitializeVM(); 2653 InitializeVM();
2652 Isolate* isolate = Isolate::Current(); 2654 Isolate* isolate = Isolate::Current();
2653 Heap* heap = isolate->heap(); 2655 Heap* heap = isolate->heap();
2654 v8::HandleScope scope; 2656 HandleScope scope(isolate);
2655 2657
2656 // Perform one initial GC to enable code flushing. 2658 // Perform one initial GC to enable code flushing.
2657 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 2659 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
2658 2660
2659 // Prepare several closures that are all eligible for code flushing 2661 // Prepare several closures that are all eligible for code flushing
2660 // because all reachable ones are not optimized. Make sure that the 2662 // because all reachable ones are not optimized. Make sure that the
2661 // optimized code object is directly reachable through a handle so 2663 // optimized code object is directly reachable through a handle so
2662 // that it is marked black during incremental marking. 2664 // that it is marked black during incremental marking.
2663 Handle<Code> code; 2665 Handle<Code> code;
2664 { 2666 {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2706 CompileRun("g('bozo');"); 2708 CompileRun("g('bozo');");
2707 } 2709 }
2708 2710
2709 2711
2710 TEST(Regress165495) { 2712 TEST(Regress165495) {
2711 i::FLAG_allow_natives_syntax = true; 2713 i::FLAG_allow_natives_syntax = true;
2712 i::FLAG_flush_code_incrementally = true; 2714 i::FLAG_flush_code_incrementally = true;
2713 InitializeVM(); 2715 InitializeVM();
2714 Isolate* isolate = Isolate::Current(); 2716 Isolate* isolate = Isolate::Current();
2715 Heap* heap = isolate->heap(); 2717 Heap* heap = isolate->heap();
2716 v8::HandleScope scope; 2718 HandleScope scope(isolate);
2717 2719
2718 // Perform one initial GC to enable code flushing. 2720 // Perform one initial GC to enable code flushing.
2719 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 2721 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
2720 2722
2721 // Prepare an optimized closure that the optimized code map will get 2723 // Prepare an optimized closure that the optimized code map will get
2722 // populated. Then age the unoptimized code to trigger code flushing 2724 // populated. Then age the unoptimized code to trigger code flushing
2723 // but make sure the optimized code is unreachable. 2725 // but make sure the optimized code is unreachable.
2724 { 2726 {
2725 HandleScope inner_scope(isolate); 2727 HandleScope inner_scope(isolate);
2726 CompileRun("function mkClosure() {" 2728 CompileRun("function mkClosure() {"
(...skipping 27 matching lines...) Expand all
2754 } 2756 }
2755 2757
2756 2758
2757 TEST(Regress169209) { 2759 TEST(Regress169209) {
2758 i::FLAG_stress_compaction = false; 2760 i::FLAG_stress_compaction = false;
2759 i::FLAG_allow_natives_syntax = true; 2761 i::FLAG_allow_natives_syntax = true;
2760 i::FLAG_flush_code_incrementally = true; 2762 i::FLAG_flush_code_incrementally = true;
2761 InitializeVM(); 2763 InitializeVM();
2762 Isolate* isolate = Isolate::Current(); 2764 Isolate* isolate = Isolate::Current();
2763 Heap* heap = isolate->heap(); 2765 Heap* heap = isolate->heap();
2764 v8::HandleScope scope; 2766 HandleScope scope(isolate);
2765 2767
2766 // Perform one initial GC to enable code flushing. 2768 // Perform one initial GC to enable code flushing.
2767 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 2769 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
2768 2770
2769 // Prepare a shared function info eligible for code flushing for which 2771 // Prepare a shared function info eligible for code flushing for which
2770 // the unoptimized code will be replaced during optimization. 2772 // the unoptimized code will be replaced during optimization.
2771 Handle<SharedFunctionInfo> shared1; 2773 Handle<SharedFunctionInfo> shared1;
2772 { 2774 {
2773 HandleScope inner_scope(isolate); 2775 HandleScope inner_scope(isolate);
2774 CompileRun("function f() { return 'foobar'; }" 2776 CompileRun("function f() { return 'foobar'; }"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2838 v8::internal::MaybeObject* maybe = space->AllocateRaw(new_linear_size); 2840 v8::internal::MaybeObject* maybe = space->AllocateRaw(new_linear_size);
2839 v8::internal::FreeListNode* node = v8::internal::FreeListNode::cast(maybe); 2841 v8::internal::FreeListNode* node = v8::internal::FreeListNode::cast(maybe);
2840 node->set_size(space->heap(), new_linear_size); 2842 node->set_size(space->heap(), new_linear_size);
2841 } 2843 }
2842 2844
2843 2845
2844 TEST(Regress169928) { 2846 TEST(Regress169928) {
2845 i::FLAG_allow_natives_syntax = true; 2847 i::FLAG_allow_natives_syntax = true;
2846 i::FLAG_crankshaft = false; 2848 i::FLAG_crankshaft = false;
2847 InitializeVM(); 2849 InitializeVM();
2848 v8::HandleScope scope; 2850 v8::HandleScope scope(env->GetIsolate());
2849 2851
2850 // Some flags turn Scavenge collections into Mark-sweep collections 2852 // Some flags turn Scavenge collections into Mark-sweep collections
2851 // and hence are incompatible with this test case. 2853 // and hence are incompatible with this test case.
2852 if (FLAG_gc_global || FLAG_stress_compaction) return; 2854 if (FLAG_gc_global || FLAG_stress_compaction) return;
2853 2855
2854 // Prepare the environment 2856 // Prepare the environment
2855 CompileRun("function fastliteralcase(literal, value) {" 2857 CompileRun("function fastliteralcase(literal, value) {"
2856 " literal[0] = value;" 2858 " literal[0] = value;"
2857 " return literal;" 2859 " return literal;"
2858 "}" 2860 "}"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2913 2915
2914 2916
2915 TEST(Regress168801) { 2917 TEST(Regress168801) {
2916 i::FLAG_always_compact = true; 2918 i::FLAG_always_compact = true;
2917 i::FLAG_cache_optimized_code = false; 2919 i::FLAG_cache_optimized_code = false;
2918 i::FLAG_allow_natives_syntax = true; 2920 i::FLAG_allow_natives_syntax = true;
2919 i::FLAG_flush_code_incrementally = true; 2921 i::FLAG_flush_code_incrementally = true;
2920 InitializeVM(); 2922 InitializeVM();
2921 Isolate* isolate = Isolate::Current(); 2923 Isolate* isolate = Isolate::Current();
2922 Heap* heap = isolate->heap(); 2924 Heap* heap = isolate->heap();
2923 v8::HandleScope scope; 2925 HandleScope scope(isolate);
2924 2926
2925 // Perform one initial GC to enable code flushing. 2927 // Perform one initial GC to enable code flushing.
2926 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 2928 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
2927 2929
2928 // Ensure the code ends up on an evacuation candidate. 2930 // Ensure the code ends up on an evacuation candidate.
2929 SimulateFullSpace(heap->code_space()); 2931 SimulateFullSpace(heap->code_space());
2930 2932
2931 // Prepare an unoptimized function that is eligible for code flushing. 2933 // Prepare an unoptimized function that is eligible for code flushing.
2932 Handle<JSFunction> function; 2934 Handle<JSFunction> function;
2933 { 2935 {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2969 2971
2970 2972
2971 TEST(Regress173458) { 2973 TEST(Regress173458) {
2972 i::FLAG_always_compact = true; 2974 i::FLAG_always_compact = true;
2973 i::FLAG_cache_optimized_code = false; 2975 i::FLAG_cache_optimized_code = false;
2974 i::FLAG_allow_natives_syntax = true; 2976 i::FLAG_allow_natives_syntax = true;
2975 i::FLAG_flush_code_incrementally = true; 2977 i::FLAG_flush_code_incrementally = true;
2976 InitializeVM(); 2978 InitializeVM();
2977 Isolate* isolate = Isolate::Current(); 2979 Isolate* isolate = Isolate::Current();
2978 Heap* heap = isolate->heap(); 2980 Heap* heap = isolate->heap();
2979 v8::HandleScope scope; 2981 HandleScope scope(isolate);
2980 2982
2981 // Perform one initial GC to enable code flushing. 2983 // Perform one initial GC to enable code flushing.
2982 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 2984 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
2983 2985
2984 // Ensure the code ends up on an evacuation candidate. 2986 // Ensure the code ends up on an evacuation candidate.
2985 SimulateFullSpace(heap->code_space()); 2987 SimulateFullSpace(heap->code_space());
2986 2988
2987 // Prepare an unoptimized function that is eligible for code flushing. 2989 // Prepare an unoptimized function that is eligible for code flushing.
2988 Handle<JSFunction> function; 2990 Handle<JSFunction> function;
2989 { 2991 {
(...skipping 22 matching lines...) Expand all
3012 // explicitly enqueued. 3014 // explicitly enqueued.
3013 SimulateIncrementalMarking(); 3015 SimulateIncrementalMarking();
3014 3016
3015 // Now enable the debugger which in turn will disable code flushing. 3017 // Now enable the debugger which in turn will disable code flushing.
3016 CHECK(isolate->debug()->Load()); 3018 CHECK(isolate->debug()->Load());
3017 3019
3018 // This cycle will bust the heap and subsequent cycles will go ballistic. 3020 // This cycle will bust the heap and subsequent cycles will go ballistic.
3019 heap->CollectAllGarbage(Heap::kNoGCFlags); 3021 heap->CollectAllGarbage(Heap::kNoGCFlags);
3020 heap->CollectAllGarbage(Heap::kNoGCFlags); 3022 heap->CollectAllGarbage(Heap::kNoGCFlags);
3021 } 3023 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698