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

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: Feedback. Rebased 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
« no previous file with comments | « test/cctest/test-global-object.cc ('k') | test/cctest/test-heap-profiler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 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 "}"
(...skipping 10 matching lines...) Expand all
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 i::FLAG_pretenure_literals = true; 2056 i::FLAG_pretenure_literals = true;
2055 InitializeVM(); 2057 InitializeVM();
2056 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; 2058 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return;
2057 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; 2059 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
2058 v8::HandleScope scope; 2060 v8::HandleScope scope(env->GetIsolate());
2059 2061
2060 AlwaysAllocateScope always_allocate; 2062 AlwaysAllocateScope always_allocate;
2061 v8::Local<v8::Value> res = CompileRun( 2063 v8::Local<v8::Value> res = CompileRun(
2062 "function f() {" 2064 "function f() {"
2063 " var numbers = [1, 2, 3];" 2065 " var numbers = [1, 2, 3];"
2064 " numbers[0] = {};" 2066 " numbers[0] = {};"
2065 " return numbers;" 2067 " return numbers;"
2066 "};" 2068 "};"
2067 "f(); f(); f();" 2069 "f(); f(); f();"
2068 "%OptimizeFunctionOnNextCall(f);" 2070 "%OptimizeFunctionOnNextCall(f);"
2069 "f();"); 2071 "f();");
2070 2072
2071 Handle<JSObject> o = 2073 Handle<JSObject> o =
2072 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); 2074 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
2073 2075
2074 CHECK(HEAP->InOldPointerSpace(o->elements())); 2076 CHECK(HEAP->InOldPointerSpace(o->elements()));
2075 } 2077 }
2076 2078
2077 2079
2078 // Test regular array literals allocation. 2080 // Test regular array literals allocation.
2079 TEST(OptimizedAllocationArrayLiterals) { 2081 TEST(OptimizedAllocationArrayLiterals) {
2080 i::FLAG_allow_natives_syntax = true; 2082 i::FLAG_allow_natives_syntax = true;
2081 InitializeVM(); 2083 InitializeVM();
2082 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; 2084 if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return;
2083 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; 2085 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
2084 v8::HandleScope scope; 2086 v8::HandleScope scope(env->GetIsolate());
2085 2087
2086 AlwaysAllocateScope always_allocate; 2088 AlwaysAllocateScope always_allocate;
2087 v8::Local<v8::Value> res = CompileRun( 2089 v8::Local<v8::Value> res = CompileRun(
2088 "function f() {" 2090 "function f() {"
2089 " var numbers = new Array(1, 2, 3);" 2091 " var numbers = new Array(1, 2, 3);"
2090 " numbers[0] = 3.14;" 2092 " numbers[0] = 3.14;"
2091 " return numbers;" 2093 " return numbers;"
2092 "};" 2094 "};"
2093 "f(); f(); f();" 2095 "f(); f(); f();"
2094 "%OptimizeFunctionOnNextCall(f);" 2096 "%OptimizeFunctionOnNextCall(f);"
(...skipping 12 matching lines...) Expand all
2107 return map->transitions()->number_of_transitions(); 2109 return map->transitions()->number_of_transitions();
2108 } 2110 }
2109 2111
2110 2112
2111 // Test that map transitions are cleared and maps are collected with 2113 // Test that map transitions are cleared and maps are collected with
2112 // incremental marking as well. 2114 // incremental marking as well.
2113 TEST(Regress1465) { 2115 TEST(Regress1465) {
2114 i::FLAG_allow_natives_syntax = true; 2116 i::FLAG_allow_natives_syntax = true;
2115 i::FLAG_trace_incremental_marking = true; 2117 i::FLAG_trace_incremental_marking = true;
2116 InitializeVM(); 2118 InitializeVM();
2117 v8::HandleScope scope; 2119 v8::HandleScope scope(env->GetIsolate());
2118 static const int transitions_count = 256; 2120 static const int transitions_count = 256;
2119 2121
2120 { 2122 {
2121 AlwaysAllocateScope always_allocate; 2123 AlwaysAllocateScope always_allocate;
2122 for (int i = 0; i < transitions_count; i++) { 2124 for (int i = 0; i < transitions_count; i++) {
2123 EmbeddedVector<char, 64> buffer; 2125 EmbeddedVector<char, 64> buffer;
2124 OS::SNPrintF(buffer, "var o = new Object; o.prop%d = %d;", i, i); 2126 OS::SNPrintF(buffer, "var o = new Object; o.prop%d = %d;", i, i);
2125 CompileRun(buffer.start()); 2127 CompileRun(buffer.start());
2126 } 2128 }
2127 CompileRun("var root = new Object;"); 2129 CompileRun("var root = new Object;");
(...skipping 17 matching lines...) Expand all
2145 int transitions_after = CountMapTransitions(root->map()); 2147 int transitions_after = CountMapTransitions(root->map());
2146 CompileRun("%DebugPrint(root);"); 2148 CompileRun("%DebugPrint(root);");
2147 CHECK_EQ(1, transitions_after); 2149 CHECK_EQ(1, transitions_after);
2148 } 2150 }
2149 2151
2150 2152
2151 TEST(Regress2143a) { 2153 TEST(Regress2143a) {
2152 i::FLAG_collect_maps = true; 2154 i::FLAG_collect_maps = true;
2153 i::FLAG_incremental_marking = true; 2155 i::FLAG_incremental_marking = true;
2154 InitializeVM(); 2156 InitializeVM();
2155 v8::HandleScope scope; 2157 v8::HandleScope scope(env->GetIsolate());
2156 2158
2157 // Prepare a map transition from the root object together with a yet 2159 // Prepare a map transition from the root object together with a yet
2158 // untransitioned root object. 2160 // untransitioned root object.
2159 CompileRun("var root = new Object;" 2161 CompileRun("var root = new Object;"
2160 "root.foo = 0;" 2162 "root.foo = 0;"
2161 "root = new Object;"); 2163 "root = new Object;");
2162 2164
2163 SimulateIncrementalMarking(); 2165 SimulateIncrementalMarking();
2164 2166
2165 // Compile a StoreIC that performs the prepared map transition. This 2167 // Compile a StoreIC that performs the prepared map transition. This
(...skipping 20 matching lines...) Expand all
2186 CHECK(root->IsJSObject()); 2188 CHECK(root->IsJSObject());
2187 CHECK(root->map()->IsMap()); 2189 CHECK(root->map()->IsMap());
2188 } 2190 }
2189 2191
2190 2192
2191 TEST(Regress2143b) { 2193 TEST(Regress2143b) {
2192 i::FLAG_collect_maps = true; 2194 i::FLAG_collect_maps = true;
2193 i::FLAG_incremental_marking = true; 2195 i::FLAG_incremental_marking = true;
2194 i::FLAG_allow_natives_syntax = true; 2196 i::FLAG_allow_natives_syntax = true;
2195 InitializeVM(); 2197 InitializeVM();
2196 v8::HandleScope scope; 2198 v8::HandleScope scope(env->GetIsolate());
2197 2199
2198 // Prepare a map transition from the root object together with a yet 2200 // Prepare a map transition from the root object together with a yet
2199 // untransitioned root object. 2201 // untransitioned root object.
2200 CompileRun("var root = new Object;" 2202 CompileRun("var root = new Object;"
2201 "root.foo = 0;" 2203 "root.foo = 0;"
2202 "root = new Object;"); 2204 "root = new Object;");
2203 2205
2204 SimulateIncrementalMarking(); 2206 SimulateIncrementalMarking();
2205 2207
2206 // Compile an optimized LStoreNamedField that performs the prepared 2208 // Compile an optimized LStoreNamedField that performs the prepared
(...skipping 24 matching lines...) Expand all
2231 CHECK(root->map()->IsMap()); 2233 CHECK(root->map()->IsMap());
2232 } 2234 }
2233 2235
2234 2236
2235 TEST(ReleaseOverReservedPages) { 2237 TEST(ReleaseOverReservedPages) {
2236 i::FLAG_trace_gc = true; 2238 i::FLAG_trace_gc = true;
2237 // The optimizer can allocate stuff, messing up the test. 2239 // The optimizer can allocate stuff, messing up the test.
2238 i::FLAG_crankshaft = false; 2240 i::FLAG_crankshaft = false;
2239 i::FLAG_always_opt = false; 2241 i::FLAG_always_opt = false;
2240 InitializeVM(); 2242 InitializeVM();
2241 v8::HandleScope scope; 2243 v8::HandleScope scope(env->GetIsolate());
2242 static const int number_of_test_pages = 20; 2244 static const int number_of_test_pages = 20;
2243 2245
2244 // Prepare many pages with low live-bytes count. 2246 // Prepare many pages with low live-bytes count.
2245 PagedSpace* old_pointer_space = HEAP->old_pointer_space(); 2247 PagedSpace* old_pointer_space = HEAP->old_pointer_space();
2246 CHECK_EQ(1, old_pointer_space->CountTotalPages()); 2248 CHECK_EQ(1, old_pointer_space->CountTotalPages());
2247 for (int i = 0; i < number_of_test_pages; i++) { 2249 for (int i = 0; i < number_of_test_pages; i++) {
2248 AlwaysAllocateScope always_allocate; 2250 AlwaysAllocateScope always_allocate;
2249 SimulateFullSpace(old_pointer_space); 2251 SimulateFullSpace(old_pointer_space);
2250 FACTORY->NewFixedArray(1, TENURED); 2252 FACTORY->NewFixedArray(1, TENURED);
2251 } 2253 }
(...skipping 18 matching lines...) Expand all
2270 // first page should be small in order to reduce memory used when the VM 2272 // first page should be small in order to reduce memory used when the VM
2271 // boots, but if the 20 small arrays don't fit on the first page then that's 2273 // boots, but if the 20 small arrays don't fit on the first page then that's
2272 // an indication that it is too small. 2274 // an indication that it is too small.
2273 HEAP->CollectAllAvailableGarbage("triggered really hard"); 2275 HEAP->CollectAllAvailableGarbage("triggered really hard");
2274 CHECK_EQ(1, old_pointer_space->CountTotalPages()); 2276 CHECK_EQ(1, old_pointer_space->CountTotalPages());
2275 } 2277 }
2276 2278
2277 2279
2278 TEST(Regress2237) { 2280 TEST(Regress2237) {
2279 InitializeVM(); 2281 InitializeVM();
2280 v8::HandleScope scope; 2282 v8::HandleScope scope(env->GetIsolate());
2281 Handle<String> slice(HEAP->empty_string()); 2283 Handle<String> slice(HEAP->empty_string());
2282 2284
2283 { 2285 {
2284 // Generate a parent that lives in new-space. 2286 // Generate a parent that lives in new-space.
2285 v8::HandleScope inner_scope; 2287 v8::HandleScope inner_scope(env->GetIsolate());
2286 const char* c = "This text is long enough to trigger sliced strings."; 2288 const char* c = "This text is long enough to trigger sliced strings.";
2287 Handle<String> s = FACTORY->NewStringFromAscii(CStrVector(c)); 2289 Handle<String> s = FACTORY->NewStringFromAscii(CStrVector(c));
2288 CHECK(s->IsSeqOneByteString()); 2290 CHECK(s->IsSeqOneByteString());
2289 CHECK(HEAP->InNewSpace(*s)); 2291 CHECK(HEAP->InNewSpace(*s));
2290 2292
2291 // Generate a sliced string that is based on the above parent and 2293 // Generate a sliced string that is based on the above parent and
2292 // lives in old-space. 2294 // lives in old-space.
2293 SimulateFullSpace(HEAP->new_space()); 2295 SimulateFullSpace(HEAP->new_space());
2294 AlwaysAllocateScope always_allocate; 2296 AlwaysAllocateScope always_allocate;
2295 Handle<String> t = FACTORY->NewProperSubString(s, 5, 35); 2297 Handle<String> t = FACTORY->NewProperSubString(s, 5, 35);
2296 CHECK(t->IsSlicedString()); 2298 CHECK(t->IsSlicedString());
2297 CHECK(!HEAP->InNewSpace(*t)); 2299 CHECK(!HEAP->InNewSpace(*t));
2298 *slice.location() = *t.location(); 2300 *slice.location() = *t.location();
2299 } 2301 }
2300 2302
2301 CHECK(SlicedString::cast(*slice)->parent()->IsSeqOneByteString()); 2303 CHECK(SlicedString::cast(*slice)->parent()->IsSeqOneByteString());
2302 HEAP->CollectAllGarbage(Heap::kNoGCFlags); 2304 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
2303 CHECK(SlicedString::cast(*slice)->parent()->IsSeqOneByteString()); 2305 CHECK(SlicedString::cast(*slice)->parent()->IsSeqOneByteString());
2304 } 2306 }
2305 2307
2306 2308
2307 #ifdef OBJECT_PRINT 2309 #ifdef OBJECT_PRINT
2308 TEST(PrintSharedFunctionInfo) { 2310 TEST(PrintSharedFunctionInfo) {
2309 InitializeVM(); 2311 InitializeVM();
2310 v8::HandleScope scope; 2312 v8::HandleScope scope(env->GetIsolate());
2311 const char* source = "f = function() { return 987654321; }\n" 2313 const char* source = "f = function() { return 987654321; }\n"
2312 "g = function() { return 123456789; }\n"; 2314 "g = function() { return 123456789; }\n";
2313 CompileRun(source); 2315 CompileRun(source);
2314 Handle<JSFunction> g = 2316 Handle<JSFunction> g =
2315 v8::Utils::OpenHandle( 2317 v8::Utils::OpenHandle(
2316 *v8::Handle<v8::Function>::Cast( 2318 *v8::Handle<v8::Function>::Cast(
2317 v8::Context::GetCurrent()->Global()->Get(v8_str("g")))); 2319 v8::Context::GetCurrent()->Global()->Get(v8_str("g"))));
2318 2320
2319 AssertNoAllocation no_alloc; 2321 AssertNoAllocation no_alloc;
2320 g->shared()->PrintLn(); 2322 g->shared()->PrintLn();
2321 } 2323 }
2322 #endif // OBJECT_PRINT 2324 #endif // OBJECT_PRINT
2323 2325
2324 2326
2325 TEST(Regress2211) { 2327 TEST(Regress2211) {
2326 InitializeVM(); 2328 InitializeVM();
2327 v8::HandleScope scope; 2329 v8::HandleScope scope(env->GetIsolate());
2328 2330
2329 v8::Handle<v8::String> value = v8_str("val string"); 2331 v8::Handle<v8::String> value = v8_str("val string");
2330 Smi* hash = Smi::FromInt(321); 2332 Smi* hash = Smi::FromInt(321);
2331 Heap* heap = Isolate::Current()->heap(); 2333 Heap* heap = Isolate::Current()->heap();
2332 2334
2333 for (int i = 0; i < 2; i++) { 2335 for (int i = 0; i < 2; i++) {
2334 // Store identity hash first and common hidden property second. 2336 // Store identity hash first and common hidden property second.
2335 v8::Handle<v8::Object> obj = v8::Object::New(); 2337 v8::Handle<v8::Object> obj = v8::Object::New();
2336 Handle<JSObject> internal_obj = v8::Utils::OpenHandle(*obj); 2338 Handle<JSObject> internal_obj = v8::Utils::OpenHandle(*obj);
2337 CHECK(internal_obj->HasFastProperties()); 2339 CHECK(internal_obj->HasFastProperties());
(...skipping 17 matching lines...) Expand all
2355 internal_obj->FastPropertyAt(descriptors->GetFieldIndex(0))); 2357 internal_obj->FastPropertyAt(descriptors->GetFieldIndex(0)));
2356 // HashTable header (5) and 4 initial entries (8). 2358 // HashTable header (5) and 4 initial entries (8).
2357 CHECK_LE(hashtable->SizeFor(hashtable->length()), 13 * kPointerSize); 2359 CHECK_LE(hashtable->SizeFor(hashtable->length()), 13 * kPointerSize);
2358 } 2360 }
2359 } 2361 }
2360 2362
2361 2363
2362 TEST(IncrementalMarkingClearsTypeFeedbackCells) { 2364 TEST(IncrementalMarkingClearsTypeFeedbackCells) {
2363 if (i::FLAG_always_opt) return; 2365 if (i::FLAG_always_opt) return;
2364 InitializeVM(); 2366 InitializeVM();
2365 v8::HandleScope scope; 2367 v8::HandleScope scope(env->GetIsolate());
2366 v8::Local<v8::Value> fun1, fun2; 2368 v8::Local<v8::Value> fun1, fun2;
2367 2369
2368 { 2370 {
2369 LocalContext env; 2371 LocalContext env;
2370 CompileRun("function fun() {};"); 2372 CompileRun("function fun() {};");
2371 fun1 = env->Global()->Get(v8_str("fun")); 2373 fun1 = env->Global()->Get(v8_str("fun"));
2372 } 2374 }
2373 2375
2374 { 2376 {
2375 LocalContext env; 2377 LocalContext env;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2414 return target; 2416 return target;
2415 } 2417 }
2416 } 2418 }
2417 return NULL; 2419 return NULL;
2418 } 2420 }
2419 2421
2420 2422
2421 TEST(IncrementalMarkingPreservesMonomorhpicIC) { 2423 TEST(IncrementalMarkingPreservesMonomorhpicIC) {
2422 if (i::FLAG_always_opt) return; 2424 if (i::FLAG_always_opt) return;
2423 InitializeVM(); 2425 InitializeVM();
2424 v8::HandleScope scope; 2426 v8::HandleScope scope(env->GetIsolate());
2425 2427
2426 // Prepare function f that contains a monomorphic IC for object 2428 // Prepare function f that contains a monomorphic IC for object
2427 // originating from the same native context. 2429 // originating from the same native context.
2428 CompileRun("function fun() { this.x = 1; }; var obj = new fun();" 2430 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"
2429 "function f(o) { return o.x; } f(obj); f(obj);"); 2431 "function f(o) { return o.x; } f(obj); f(obj);");
2430 Handle<JSFunction> f = 2432 Handle<JSFunction> f =
2431 v8::Utils::OpenHandle( 2433 v8::Utils::OpenHandle(
2432 *v8::Handle<v8::Function>::Cast( 2434 *v8::Handle<v8::Function>::Cast(
2433 v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); 2435 v8::Context::GetCurrent()->Global()->Get(v8_str("f"))));
2434 2436
2435 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); 2437 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC);
2436 CHECK(ic_before->ic_state() == MONOMORPHIC); 2438 CHECK(ic_before->ic_state() == MONOMORPHIC);
2437 2439
2438 SimulateIncrementalMarking(); 2440 SimulateIncrementalMarking();
2439 HEAP->CollectAllGarbage(Heap::kNoGCFlags); 2441 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
2440 2442
2441 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); 2443 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC);
2442 CHECK(ic_after->ic_state() == MONOMORPHIC); 2444 CHECK(ic_after->ic_state() == MONOMORPHIC);
2443 } 2445 }
2444 2446
2445 2447
2446 TEST(IncrementalMarkingClearsMonomorhpicIC) { 2448 TEST(IncrementalMarkingClearsMonomorhpicIC) {
2447 if (i::FLAG_always_opt) return; 2449 if (i::FLAG_always_opt) return;
2448 InitializeVM(); 2450 InitializeVM();
2449 v8::HandleScope scope; 2451 v8::HandleScope scope(env->GetIsolate());
2450 v8::Local<v8::Value> obj1; 2452 v8::Local<v8::Value> obj1;
2451 2453
2452 { 2454 {
2453 LocalContext env; 2455 LocalContext env;
2454 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); 2456 CompileRun("function fun() { this.x = 1; }; var obj = new fun();");
2455 obj1 = env->Global()->Get(v8_str("obj")); 2457 obj1 = env->Global()->Get(v8_str("obj"));
2456 } 2458 }
2457 2459
2458 // Prepare function f that contains a monomorphic IC for object 2460 // Prepare function f that contains a monomorphic IC for object
2459 // originating from a different native context. 2461 // originating from a different native context.
(...skipping 13 matching lines...) Expand all
2473 HEAP->CollectAllGarbage(Heap::kNoGCFlags); 2475 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
2474 2476
2475 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); 2477 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC);
2476 CHECK(ic_after->ic_state() == UNINITIALIZED); 2478 CHECK(ic_after->ic_state() == UNINITIALIZED);
2477 } 2479 }
2478 2480
2479 2481
2480 TEST(IncrementalMarkingClearsPolymorhpicIC) { 2482 TEST(IncrementalMarkingClearsPolymorhpicIC) {
2481 if (i::FLAG_always_opt) return; 2483 if (i::FLAG_always_opt) return;
2482 InitializeVM(); 2484 InitializeVM();
2483 v8::HandleScope scope; 2485 v8::HandleScope scope(env->GetIsolate());
2484 v8::Local<v8::Value> obj1, obj2; 2486 v8::Local<v8::Value> obj1, obj2;
2485 2487
2486 { 2488 {
2487 LocalContext env; 2489 LocalContext env;
2488 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); 2490 CompileRun("function fun() { this.x = 1; }; var obj = new fun();");
2489 obj1 = env->Global()->Get(v8_str("obj")); 2491 obj1 = env->Global()->Get(v8_str("obj"));
2490 } 2492 }
2491 2493
2492 { 2494 {
2493 LocalContext env; 2495 LocalContext env;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2539 size_t length_; 2541 size_t length_;
2540 }; 2542 };
2541 2543
2542 2544
2543 void ReleaseStackTraceDataTest(const char* source) { 2545 void ReleaseStackTraceDataTest(const char* source) {
2544 // Test that the data retained by the Error.stack accessor is released 2546 // Test that the data retained by the Error.stack accessor is released
2545 // after the first time the accessor is fired. We use external string 2547 // after the first time the accessor is fired. We use external string
2546 // to check whether the data is being released since the external string 2548 // to check whether the data is being released since the external string
2547 // resource's callback is fired when the external string is GC'ed. 2549 // resource's callback is fired when the external string is GC'ed.
2548 InitializeVM(); 2550 InitializeVM();
2549 v8::HandleScope scope; 2551 v8::HandleScope scope(env->GetIsolate());
2550 SourceResource* resource = new SourceResource(i::StrDup(source)); 2552 SourceResource* resource = new SourceResource(i::StrDup(source));
2551 { 2553 {
2552 v8::HandleScope scope; 2554 v8::HandleScope scope(env->GetIsolate());
2553 v8::Handle<v8::String> source_string = v8::String::NewExternal(resource); 2555 v8::Handle<v8::String> source_string = v8::String::NewExternal(resource);
2554 v8::Script::Compile(source_string)->Run(); 2556 v8::Script::Compile(source_string)->Run();
2555 CHECK(!resource->IsDisposed()); 2557 CHECK(!resource->IsDisposed());
2556 } 2558 }
2557 HEAP->CollectAllAvailableGarbage(); 2559 HEAP->CollectAllAvailableGarbage();
2558 2560
2559 // External source has been released. 2561 // External source has been released.
2560 CHECK(resource->IsDisposed()); 2562 CHECK(resource->IsDisposed());
2561 delete resource; 2563 delete resource;
2562 } 2564 }
(...skipping 14 matching lines...) Expand all
2577 "} "; 2579 "} ";
2578 ReleaseStackTraceDataTest(source1); 2580 ReleaseStackTraceDataTest(source1);
2579 ReleaseStackTraceDataTest(source2); 2581 ReleaseStackTraceDataTest(source2);
2580 } 2582 }
2581 2583
2582 2584
2583 TEST(Regression144230) { 2585 TEST(Regression144230) {
2584 InitializeVM(); 2586 InitializeVM();
2585 Isolate* isolate = Isolate::Current(); 2587 Isolate* isolate = Isolate::Current();
2586 Heap* heap = isolate->heap(); 2588 Heap* heap = isolate->heap();
2587 v8::HandleScope scope; 2589 HandleScope scope(isolate);
2588 2590
2589 // First make sure that the uninitialized CallIC stub is on a single page 2591 // First make sure that the uninitialized CallIC stub is on a single page
2590 // that will later be selected as an evacuation candidate. 2592 // that will later be selected as an evacuation candidate.
2591 { 2593 {
2592 v8::HandleScope inner_scope; 2594 HandleScope inner_scope(isolate);
2593 AlwaysAllocateScope always_allocate; 2595 AlwaysAllocateScope always_allocate;
2594 SimulateFullSpace(heap->code_space()); 2596 SimulateFullSpace(heap->code_space());
2595 isolate->stub_cache()->ComputeCallInitialize(9, RelocInfo::CODE_TARGET); 2597 isolate->stub_cache()->ComputeCallInitialize(9, RelocInfo::CODE_TARGET);
2596 } 2598 }
2597 2599
2598 // Second compile a CallIC and execute it once so that it gets patched to 2600 // Second compile a CallIC and execute it once so that it gets patched to
2599 // the pre-monomorphic stub. These code objects are on yet another page. 2601 // the pre-monomorphic stub. These code objects are on yet another page.
2600 { 2602 {
2601 v8::HandleScope inner_scope; 2603 HandleScope inner_scope(isolate);
2602 AlwaysAllocateScope always_allocate; 2604 AlwaysAllocateScope always_allocate;
2603 SimulateFullSpace(heap->code_space()); 2605 SimulateFullSpace(heap->code_space());
2604 CompileRun("var o = { f:function(a,b,c,d,e,f,g,h,i) {}};" 2606 CompileRun("var o = { f:function(a,b,c,d,e,f,g,h,i) {}};"
2605 "function call() { o.f(1,2,3,4,5,6,7,8,9); };" 2607 "function call() { o.f(1,2,3,4,5,6,7,8,9); };"
2606 "call();"); 2608 "call();");
2607 } 2609 }
2608 2610
2609 // Third we fill up the last page of the code space so that it does not get 2611 // Third we fill up the last page of the code space so that it does not get
2610 // chosen as an evacuation candidate. 2612 // chosen as an evacuation candidate.
2611 { 2613 {
2612 v8::HandleScope inner_scope; 2614 HandleScope inner_scope(isolate);
2613 AlwaysAllocateScope always_allocate; 2615 AlwaysAllocateScope always_allocate;
2614 CompileRun("for (var i = 0; i < 2000; i++) {" 2616 CompileRun("for (var i = 0; i < 2000; i++) {"
2615 " eval('function f' + i + '() { return ' + i +'; };' +" 2617 " eval('function f' + i + '() { return ' + i +'; };' +"
2616 " 'f' + i + '();');" 2618 " 'f' + i + '();');"
2617 "}"); 2619 "}");
2618 } 2620 }
2619 heap->CollectAllGarbage(Heap::kNoGCFlags); 2621 heap->CollectAllGarbage(Heap::kNoGCFlags);
2620 2622
2621 // Fourth is the tricky part. Make sure the code containing the CallIC is 2623 // Fourth is the tricky part. Make sure the code containing the CallIC is
2622 // visited first without clearing the IC. The shared function info is then 2624 // visited first without clearing the IC. The shared function info is then
(...skipping 17 matching lines...) Expand all
2640 CompileRun("call();"); 2642 CompileRun("call();");
2641 } 2643 }
2642 2644
2643 2645
2644 TEST(Regress159140) { 2646 TEST(Regress159140) {
2645 i::FLAG_allow_natives_syntax = true; 2647 i::FLAG_allow_natives_syntax = true;
2646 i::FLAG_flush_code_incrementally = true; 2648 i::FLAG_flush_code_incrementally = true;
2647 InitializeVM(); 2649 InitializeVM();
2648 Isolate* isolate = Isolate::Current(); 2650 Isolate* isolate = Isolate::Current();
2649 Heap* heap = isolate->heap(); 2651 Heap* heap = isolate->heap();
2650 v8::HandleScope scope; 2652 HandleScope scope(isolate);
2651 2653
2652 // Perform one initial GC to enable code flushing. 2654 // Perform one initial GC to enable code flushing.
2653 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 2655 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
2654 2656
2655 // Prepare several closures that are all eligible for code flushing 2657 // Prepare several closures that are all eligible for code flushing
2656 // because all reachable ones are not optimized. Make sure that the 2658 // because all reachable ones are not optimized. Make sure that the
2657 // optimized code object is directly reachable through a handle so 2659 // optimized code object is directly reachable through a handle so
2658 // that it is marked black during incremental marking. 2660 // that it is marked black during incremental marking.
2659 Handle<Code> code; 2661 Handle<Code> code;
2660 { 2662 {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2702 CompileRun("g('bozo');"); 2704 CompileRun("g('bozo');");
2703 } 2705 }
2704 2706
2705 2707
2706 TEST(Regress165495) { 2708 TEST(Regress165495) {
2707 i::FLAG_allow_natives_syntax = true; 2709 i::FLAG_allow_natives_syntax = true;
2708 i::FLAG_flush_code_incrementally = true; 2710 i::FLAG_flush_code_incrementally = true;
2709 InitializeVM(); 2711 InitializeVM();
2710 Isolate* isolate = Isolate::Current(); 2712 Isolate* isolate = Isolate::Current();
2711 Heap* heap = isolate->heap(); 2713 Heap* heap = isolate->heap();
2712 v8::HandleScope scope; 2714 HandleScope scope(isolate);
2713 2715
2714 // Perform one initial GC to enable code flushing. 2716 // Perform one initial GC to enable code flushing.
2715 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 2717 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
2716 2718
2717 // Prepare an optimized closure that the optimized code map will get 2719 // Prepare an optimized closure that the optimized code map will get
2718 // populated. Then age the unoptimized code to trigger code flushing 2720 // populated. Then age the unoptimized code to trigger code flushing
2719 // but make sure the optimized code is unreachable. 2721 // but make sure the optimized code is unreachable.
2720 { 2722 {
2721 HandleScope inner_scope(isolate); 2723 HandleScope inner_scope(isolate);
2722 CompileRun("function mkClosure() {" 2724 CompileRun("function mkClosure() {"
(...skipping 27 matching lines...) Expand all
2750 } 2752 }
2751 2753
2752 2754
2753 TEST(Regress169209) { 2755 TEST(Regress169209) {
2754 i::FLAG_stress_compaction = false; 2756 i::FLAG_stress_compaction = false;
2755 i::FLAG_allow_natives_syntax = true; 2757 i::FLAG_allow_natives_syntax = true;
2756 i::FLAG_flush_code_incrementally = true; 2758 i::FLAG_flush_code_incrementally = true;
2757 InitializeVM(); 2759 InitializeVM();
2758 Isolate* isolate = Isolate::Current(); 2760 Isolate* isolate = Isolate::Current();
2759 Heap* heap = isolate->heap(); 2761 Heap* heap = isolate->heap();
2760 v8::HandleScope scope; 2762 HandleScope scope(isolate);
2761 2763
2762 // Perform one initial GC to enable code flushing. 2764 // Perform one initial GC to enable code flushing.
2763 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 2765 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
2764 2766
2765 // Prepare a shared function info eligible for code flushing for which 2767 // Prepare a shared function info eligible for code flushing for which
2766 // the unoptimized code will be replaced during optimization. 2768 // the unoptimized code will be replaced during optimization.
2767 Handle<SharedFunctionInfo> shared1; 2769 Handle<SharedFunctionInfo> shared1;
2768 { 2770 {
2769 HandleScope inner_scope(isolate); 2771 HandleScope inner_scope(isolate);
2770 CompileRun("function f() { return 'foobar'; }" 2772 CompileRun("function f() { return 'foobar'; }"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2834 v8::internal::MaybeObject* maybe = space->AllocateRaw(new_linear_size); 2836 v8::internal::MaybeObject* maybe = space->AllocateRaw(new_linear_size);
2835 v8::internal::FreeListNode* node = v8::internal::FreeListNode::cast(maybe); 2837 v8::internal::FreeListNode* node = v8::internal::FreeListNode::cast(maybe);
2836 node->set_size(space->heap(), new_linear_size); 2838 node->set_size(space->heap(), new_linear_size);
2837 } 2839 }
2838 2840
2839 2841
2840 TEST(Regress169928) { 2842 TEST(Regress169928) {
2841 i::FLAG_allow_natives_syntax = true; 2843 i::FLAG_allow_natives_syntax = true;
2842 i::FLAG_crankshaft = false; 2844 i::FLAG_crankshaft = false;
2843 InitializeVM(); 2845 InitializeVM();
2844 v8::HandleScope scope; 2846 v8::HandleScope scope(env->GetIsolate());
2845 2847
2846 // Some flags turn Scavenge collections into Mark-sweep collections 2848 // Some flags turn Scavenge collections into Mark-sweep collections
2847 // and hence are incompatible with this test case. 2849 // and hence are incompatible with this test case.
2848 if (FLAG_gc_global || FLAG_stress_compaction) return; 2850 if (FLAG_gc_global || FLAG_stress_compaction) return;
2849 2851
2850 // Prepare the environment 2852 // Prepare the environment
2851 CompileRun("function fastliteralcase(literal, value) {" 2853 CompileRun("function fastliteralcase(literal, value) {"
2852 " literal[0] = value;" 2854 " literal[0] = value;"
2853 " return literal;" 2855 " return literal;"
2854 "}" 2856 "}"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2909 2911
2910 2912
2911 TEST(Regress168801) { 2913 TEST(Regress168801) {
2912 i::FLAG_always_compact = true; 2914 i::FLAG_always_compact = true;
2913 i::FLAG_cache_optimized_code = false; 2915 i::FLAG_cache_optimized_code = false;
2914 i::FLAG_allow_natives_syntax = true; 2916 i::FLAG_allow_natives_syntax = true;
2915 i::FLAG_flush_code_incrementally = true; 2917 i::FLAG_flush_code_incrementally = true;
2916 InitializeVM(); 2918 InitializeVM();
2917 Isolate* isolate = Isolate::Current(); 2919 Isolate* isolate = Isolate::Current();
2918 Heap* heap = isolate->heap(); 2920 Heap* heap = isolate->heap();
2919 v8::HandleScope scope; 2921 HandleScope scope(isolate);
2920 2922
2921 // Perform one initial GC to enable code flushing. 2923 // Perform one initial GC to enable code flushing.
2922 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 2924 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
2923 2925
2924 // Ensure the code ends up on an evacuation candidate. 2926 // Ensure the code ends up on an evacuation candidate.
2925 SimulateFullSpace(heap->code_space()); 2927 SimulateFullSpace(heap->code_space());
2926 2928
2927 // Prepare an unoptimized function that is eligible for code flushing. 2929 // Prepare an unoptimized function that is eligible for code flushing.
2928 Handle<JSFunction> function; 2930 Handle<JSFunction> function;
2929 { 2931 {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2965 2967
2966 2968
2967 TEST(Regress173458) { 2969 TEST(Regress173458) {
2968 i::FLAG_always_compact = true; 2970 i::FLAG_always_compact = true;
2969 i::FLAG_cache_optimized_code = false; 2971 i::FLAG_cache_optimized_code = false;
2970 i::FLAG_allow_natives_syntax = true; 2972 i::FLAG_allow_natives_syntax = true;
2971 i::FLAG_flush_code_incrementally = true; 2973 i::FLAG_flush_code_incrementally = true;
2972 InitializeVM(); 2974 InitializeVM();
2973 Isolate* isolate = Isolate::Current(); 2975 Isolate* isolate = Isolate::Current();
2974 Heap* heap = isolate->heap(); 2976 Heap* heap = isolate->heap();
2975 v8::HandleScope scope; 2977 HandleScope scope(isolate);
2976 2978
2977 // Perform one initial GC to enable code flushing. 2979 // Perform one initial GC to enable code flushing.
2978 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 2980 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
2979 2981
2980 // Ensure the code ends up on an evacuation candidate. 2982 // Ensure the code ends up on an evacuation candidate.
2981 SimulateFullSpace(heap->code_space()); 2983 SimulateFullSpace(heap->code_space());
2982 2984
2983 // Prepare an unoptimized function that is eligible for code flushing. 2985 // Prepare an unoptimized function that is eligible for code flushing.
2984 Handle<JSFunction> function; 2986 Handle<JSFunction> function;
2985 { 2987 {
(...skipping 22 matching lines...) Expand all
3008 // explicitly enqueued. 3010 // explicitly enqueued.
3009 SimulateIncrementalMarking(); 3011 SimulateIncrementalMarking();
3010 3012
3011 // Now enable the debugger which in turn will disable code flushing. 3013 // Now enable the debugger which in turn will disable code flushing.
3012 CHECK(isolate->debug()->Load()); 3014 CHECK(isolate->debug()->Load());
3013 3015
3014 // This cycle will bust the heap and subsequent cycles will go ballistic. 3016 // This cycle will bust the heap and subsequent cycles will go ballistic.
3015 heap->CollectAllGarbage(Heap::kNoGCFlags); 3017 heap->CollectAllGarbage(Heap::kNoGCFlags);
3016 heap->CollectAllGarbage(Heap::kNoGCFlags); 3018 heap->CollectAllGarbage(Heap::kNoGCFlags);
3017 } 3019 }
OLDNEW
« no previous file with comments | « test/cctest/test-global-object.cc ('k') | test/cctest/test-heap-profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698