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

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

Issue 2866008: [Isolates] Move contents of Top into Isolate.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: ensure we're synced Created 10 years, 6 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-disasm-ia32.cc ('k') | test/cctest/test-log-stack-tracer.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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 2
3 #include <stdlib.h> 3 #include <stdlib.h>
4 4
5 #include "v8.h" 5 #include "v8.h"
6 6
7 #include "execution.h" 7 #include "execution.h"
8 #include "factory.h" 8 #include "factory.h"
9 #include "macro-assembler.h" 9 #include "macro-assembler.h"
10 #include "global-handles.h" 10 #include "global-handles.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 147
148 // nan oddball checks 148 // nan oddball checks
149 CHECK(HEAP->nan_value()->IsNumber()); 149 CHECK(HEAP->nan_value()->IsNumber());
150 CHECK(isnan(HEAP->nan_value()->Number())); 150 CHECK(isnan(HEAP->nan_value()->Number()));
151 151
152 Handle<String> s = Factory::NewStringFromAscii(CStrVector("fisk hest ")); 152 Handle<String> s = Factory::NewStringFromAscii(CStrVector("fisk hest "));
153 CHECK(s->IsString()); 153 CHECK(s->IsString());
154 CHECK_EQ(10, s->length()); 154 CHECK_EQ(10, s->length());
155 155
156 String* object_symbol = String::cast(HEAP->Object_symbol()); 156 String* object_symbol = String::cast(HEAP->Object_symbol());
157 CHECK(Top::context()->global()->HasLocalProperty(object_symbol)); 157 CHECK(
158 Isolate::Current()->context()->global()->HasLocalProperty(object_symbol));
158 159
159 // Check ToString for oddballs 160 // Check ToString for oddballs
160 CheckOddball(HEAP->true_value(), "true"); 161 CheckOddball(HEAP->true_value(), "true");
161 CheckOddball(HEAP->false_value(), "false"); 162 CheckOddball(HEAP->false_value(), "false");
162 CheckOddball(HEAP->null_value(), "null"); 163 CheckOddball(HEAP->null_value(), "null");
163 CheckOddball(HEAP->undefined_value(), "undefined"); 164 CheckOddball(HEAP->undefined_value(), "undefined");
164 165
165 // Check ToString for Smis 166 // Check ToString for Smis
166 CheckSmi(0, "0"); 167 CheckSmi(0, "0");
167 CheckSmi(42, "42"); 168 CheckSmi(42, "42");
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 Handle<String> obj_name = Factory::LookupAsciiSymbol("theObject"); 207 Handle<String> obj_name = Factory::LookupAsciiSymbol("theObject");
207 208
208 { 209 {
209 v8::HandleScope inner_scope; 210 v8::HandleScope inner_scope;
210 // Allocate a function and keep it in global object's property. 211 // Allocate a function and keep it in global object's property.
211 Handle<JSFunction> function = 212 Handle<JSFunction> function =
212 Factory::NewFunction(name, Factory::undefined_value()); 213 Factory::NewFunction(name, Factory::undefined_value());
213 Handle<Map> initial_map = 214 Handle<Map> initial_map =
214 Factory::NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 215 Factory::NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
215 function->set_initial_map(*initial_map); 216 function->set_initial_map(*initial_map);
216 Top::context()->global()->SetProperty(*name, *function, NONE); 217 Isolate::Current()->context()->global()->SetProperty(*name, *function,
218 NONE);
217 // Allocate an object. Unrooted after leaving the scope. 219 // Allocate an object. Unrooted after leaving the scope.
218 Handle<JSObject> obj = Factory::NewJSObject(function); 220 Handle<JSObject> obj = Factory::NewJSObject(function);
219 obj->SetProperty(*prop_name, Smi::FromInt(23), NONE); 221 obj->SetProperty(*prop_name, Smi::FromInt(23), NONE);
220 obj->SetProperty(*prop_namex, Smi::FromInt(24), NONE); 222 obj->SetProperty(*prop_namex, Smi::FromInt(24), NONE);
221 223
222 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); 224 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name));
223 CHECK_EQ(Smi::FromInt(24), obj->GetProperty(*prop_namex)); 225 CHECK_EQ(Smi::FromInt(24), obj->GetProperty(*prop_namex));
224 } 226 }
225 227
226 CHECK(HEAP->CollectGarbage(free_bytes, NEW_SPACE)); 228 CHECK(HEAP->CollectGarbage(free_bytes, NEW_SPACE));
227 229
228 // Function should be alive. 230 // Function should be alive.
229 CHECK(Top::context()->global()->HasLocalProperty(*name)); 231 CHECK(Isolate::Current()->context()->global()->HasLocalProperty(*name));
230 // Check function is retained. 232 // Check function is retained.
231 Object* func_value = Top::context()->global()->GetProperty(*name); 233 Object* func_value =
234 Isolate::Current()->context()->global()->GetProperty(*name);
232 CHECK(func_value->IsJSFunction()); 235 CHECK(func_value->IsJSFunction());
233 Handle<JSFunction> function(JSFunction::cast(func_value)); 236 Handle<JSFunction> function(JSFunction::cast(func_value));
234 237
235 { 238 {
236 HandleScope inner_scope; 239 HandleScope inner_scope;
237 // Allocate another object, make it reachable from global. 240 // Allocate another object, make it reachable from global.
238 Handle<JSObject> obj = Factory::NewJSObject(function); 241 Handle<JSObject> obj = Factory::NewJSObject(function);
239 Top::context()->global()->SetProperty(*obj_name, *obj, NONE); 242 Isolate::Current()->context()->global()->SetProperty(*obj_name, *obj, NONE);
240 obj->SetProperty(*prop_name, Smi::FromInt(23), NONE); 243 obj->SetProperty(*prop_name, Smi::FromInt(23), NONE);
241 } 244 }
242 245
243 // After gc, it should survive. 246 // After gc, it should survive.
244 CHECK(HEAP->CollectGarbage(free_bytes, NEW_SPACE)); 247 CHECK(HEAP->CollectGarbage(free_bytes, NEW_SPACE));
245 248
246 CHECK(Top::context()->global()->HasLocalProperty(*obj_name)); 249 CHECK(Isolate::Current()->context()->global()->HasLocalProperty(*obj_name));
247 CHECK(Top::context()->global()->GetProperty(*obj_name)->IsJSObject()); 250 CHECK(Isolate::Current()->context()->global()->GetProperty(*obj_name)->
251 IsJSObject());
248 JSObject* obj = 252 JSObject* obj =
249 JSObject::cast(Top::context()->global()->GetProperty(*obj_name)); 253 JSObject::cast(Isolate::Current()->context()->global()->
254 GetProperty(*obj_name));
250 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); 255 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name));
251 } 256 }
252 257
253 258
254 static void VerifyStringAllocation(const char* string) { 259 static void VerifyStringAllocation(const char* string) {
255 v8::HandleScope scope; 260 v8::HandleScope scope;
256 Handle<String> s = Factory::NewStringFromUtf8(CStrVector(string)); 261 Handle<String> s = Factory::NewStringFromUtf8(CStrVector(string));
257 CHECK_EQ(StrLength(string), s->length()); 262 CHECK_EQ(StrLength(string), s->length());
258 for (int index = 0; index < s->length(); index++) { 263 for (int index = 0; index < s->length(); index++) {
259 CHECK_EQ(static_cast<uint16_t>(string[index]), s->Get(index)); 264 CHECK_EQ(static_cast<uint16_t>(string[index]), s->Get(index));
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 CHECK_EQ(Smi::FromInt(24), function->GetProperty(*prop_name)); 553 CHECK_EQ(Smi::FromInt(24), function->GetProperty(*prop_name));
549 } 554 }
550 555
551 556
552 TEST(ObjectProperties) { 557 TEST(ObjectProperties) {
553 InitializeVM(); 558 InitializeVM();
554 559
555 v8::HandleScope sc; 560 v8::HandleScope sc;
556 String* object_symbol = String::cast(HEAP->Object_symbol()); 561 String* object_symbol = String::cast(HEAP->Object_symbol());
557 JSFunction* object_function = 562 JSFunction* object_function =
558 JSFunction::cast(Top::context()->global()->GetProperty(object_symbol)); 563 JSFunction::cast(Isolate::Current()->context()->global()->
564 GetProperty(object_symbol));
559 Handle<JSFunction> constructor(object_function); 565 Handle<JSFunction> constructor(object_function);
560 Handle<JSObject> obj = Factory::NewJSObject(constructor); 566 Handle<JSObject> obj = Factory::NewJSObject(constructor);
561 Handle<String> first = Factory::LookupAsciiSymbol("first"); 567 Handle<String> first = Factory::LookupAsciiSymbol("first");
562 Handle<String> second = Factory::LookupAsciiSymbol("second"); 568 Handle<String> second = Factory::LookupAsciiSymbol("second");
563 569
564 // check for empty 570 // check for empty
565 CHECK(!obj->HasLocalProperty(*first)); 571 CHECK(!obj->HasLocalProperty(*first));
566 572
567 // add first 573 // add first
568 obj->SetProperty(*first, Smi::FromInt(1), NONE); 574 obj->SetProperty(*first, Smi::FromInt(1), NONE);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 CHECK(*initial_map != obj->map()); 642 CHECK(*initial_map != obj->map());
637 } 643 }
638 644
639 645
640 TEST(JSArray) { 646 TEST(JSArray) {
641 InitializeVM(); 647 InitializeVM();
642 648
643 v8::HandleScope sc; 649 v8::HandleScope sc;
644 Handle<String> name = Factory::LookupAsciiSymbol("Array"); 650 Handle<String> name = Factory::LookupAsciiSymbol("Array");
645 Handle<JSFunction> function = Handle<JSFunction>( 651 Handle<JSFunction> function = Handle<JSFunction>(
646 JSFunction::cast(Top::context()->global()->GetProperty(*name))); 652 JSFunction::cast(Isolate::Current()->context()->global()->
653 GetProperty(*name)));
647 654
648 // Allocate the object. 655 // Allocate the object.
649 Handle<JSObject> object = Factory::NewJSObject(function); 656 Handle<JSObject> object = Factory::NewJSObject(function);
650 Handle<JSArray> array = Handle<JSArray>::cast(object); 657 Handle<JSArray> array = Handle<JSArray>::cast(object);
651 array->Initialize(0); 658 array->Initialize(0);
652 659
653 // Set array length to 0. 660 // Set array length to 0.
654 array->SetElementsLength(Smi::FromInt(0)); 661 array->SetElementsLength(Smi::FromInt(0));
655 CHECK_EQ(Smi::FromInt(0), array->length()); 662 CHECK_EQ(Smi::FromInt(0), array->length());
656 CHECK(array->HasFastElements()); // Must be in fast mode. 663 CHECK(array->HasFastElements()); // Must be in fast mode.
(...skipping 22 matching lines...) Expand all
679 CHECK_EQ(array->GetElement(0), *name); 686 CHECK_EQ(array->GetElement(0), *name);
680 } 687 }
681 688
682 689
683 TEST(JSObjectCopy) { 690 TEST(JSObjectCopy) {
684 InitializeVM(); 691 InitializeVM();
685 692
686 v8::HandleScope sc; 693 v8::HandleScope sc;
687 String* object_symbol = String::cast(HEAP->Object_symbol()); 694 String* object_symbol = String::cast(HEAP->Object_symbol());
688 JSFunction* object_function = 695 JSFunction* object_function =
689 JSFunction::cast(Top::context()->global()->GetProperty(object_symbol)); 696 JSFunction::cast(Isolate::Current()->context()->global()->
697 GetProperty(object_symbol));
690 Handle<JSFunction> constructor(object_function); 698 Handle<JSFunction> constructor(object_function);
691 Handle<JSObject> obj = Factory::NewJSObject(constructor); 699 Handle<JSObject> obj = Factory::NewJSObject(constructor);
692 Handle<String> first = Factory::LookupAsciiSymbol("first"); 700 Handle<String> first = Factory::LookupAsciiSymbol("first");
693 Handle<String> second = Factory::LookupAsciiSymbol("second"); 701 Handle<String> second = Factory::LookupAsciiSymbol("second");
694 702
695 obj->SetProperty(*first, Smi::FromInt(1), NONE); 703 obj->SetProperty(*first, Smi::FromInt(1), NONE);
696 obj->SetProperty(*second, Smi::FromInt(2), NONE); 704 obj->SetProperty(*second, Smi::FromInt(2), NONE);
697 705
698 obj->SetElement(0, *first); 706 obj->SetElement(0, *first);
699 obj->SetElement(1, *second); 707 obj->SetElement(1, *second);
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 bool force_compaction = true; 892 bool force_compaction = true;
885 HEAP->CollectAllGarbage(force_compaction); 893 HEAP->CollectAllGarbage(force_compaction);
886 894
887 v8::HandleScope scope; 895 v8::HandleScope scope;
888 896
889 // The plan: create JSObject which references objects in new space. 897 // The plan: create JSObject which references objects in new space.
890 // Then clone this object (forcing it to go into old space) and check 898 // Then clone this object (forcing it to go into old space) and check
891 // that region dirty marks are updated correctly. 899 // that region dirty marks are updated correctly.
892 900
893 // Step 1: prepare a map for the object. We add 1 inobject property to it. 901 // Step 1: prepare a map for the object. We add 1 inobject property to it.
894 Handle<JSFunction> object_ctor(Top::global_context()->object_function()); 902 Handle<JSFunction> object_ctor(
903 Isolate::Current()->global_context()->object_function());
895 CHECK(object_ctor->has_initial_map()); 904 CHECK(object_ctor->has_initial_map());
896 Handle<Map> object_map(object_ctor->initial_map()); 905 Handle<Map> object_map(object_ctor->initial_map());
897 // Create a map with single inobject property. 906 // Create a map with single inobject property.
898 Handle<Map> my_map = Factory::CopyMap(object_map, 1); 907 Handle<Map> my_map = Factory::CopyMap(object_map, 1);
899 int n_properties = my_map->inobject_properties(); 908 int n_properties = my_map->inobject_properties();
900 CHECK_GT(n_properties, 0); 909 CHECK_GT(n_properties, 0);
901 910
902 int object_size = my_map->instance_size(); 911 int object_size = my_map->instance_size();
903 912
904 // Step 2: allocate a lot of objects so to almost fill new space: we need 913 // Step 2: allocate a lot of objects so to almost fill new space: we need
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 " var y = 42;" 978 " var y = 42;"
970 " var z = x + y;" 979 " var z = x + y;"
971 "};" 980 "};"
972 "foo()"; 981 "foo()";
973 Handle<String> foo_name = Factory::LookupAsciiSymbol("foo"); 982 Handle<String> foo_name = Factory::LookupAsciiSymbol("foo");
974 983
975 // This compile will add the code to the compilation cache. 984 // This compile will add the code to the compilation cache.
976 CompileRun(source); 985 CompileRun(source);
977 986
978 // Check function is compiled. 987 // Check function is compiled.
979 Object* func_value = Top::context()->global()->GetProperty(*foo_name); 988 Object* func_value =
989 Isolate::Current()->context()->global()->GetProperty(*foo_name);
980 CHECK(func_value->IsJSFunction()); 990 CHECK(func_value->IsJSFunction());
981 Handle<JSFunction> function(JSFunction::cast(func_value)); 991 Handle<JSFunction> function(JSFunction::cast(func_value));
982 CHECK(function->shared()->is_compiled()); 992 CHECK(function->shared()->is_compiled());
983 993
984 HEAP->CollectAllGarbage(true); 994 HEAP->CollectAllGarbage(true);
985 HEAP->CollectAllGarbage(true); 995 HEAP->CollectAllGarbage(true);
986 996
987 // foo should still be in the compilation cache and therefore not 997 // foo should still be in the compilation cache and therefore not
988 // have been removed. 998 // have been removed.
989 CHECK(function->shared()->is_compiled()); 999 CHECK(function->shared()->is_compiled());
990 HEAP->CollectAllGarbage(true); 1000 HEAP->CollectAllGarbage(true);
991 HEAP->CollectAllGarbage(true); 1001 HEAP->CollectAllGarbage(true);
992 HEAP->CollectAllGarbage(true); 1002 HEAP->CollectAllGarbage(true);
993 HEAP->CollectAllGarbage(true); 1003 HEAP->CollectAllGarbage(true);
994 1004
995 // foo should no longer be in the compilation cache 1005 // foo should no longer be in the compilation cache
996 CHECK(!function->shared()->is_compiled()); 1006 CHECK(!function->shared()->is_compiled());
997 // Call foo to get it recompiled. 1007 // Call foo to get it recompiled.
998 CompileRun("foo()"); 1008 CompileRun("foo()");
999 CHECK(function->shared()->is_compiled()); 1009 CHECK(function->shared()->is_compiled());
1000 } 1010 }
OLDNEW
« no previous file with comments | « test/cctest/test-disasm-ia32.cc ('k') | test/cctest/test-log-stack-tracer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698