| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 static v8::Persistent<v8::Context> env; | 38 static v8::Persistent<v8::Context> env; |
| 39 | 39 |
| 40 static void InitializeVM() { | 40 static void InitializeVM() { |
| 41 if (env.IsEmpty()) env = v8::Context::New(); | 41 if (env.IsEmpty()) env = v8::Context::New(); |
| 42 v8::HandleScope scope; | 42 v8::HandleScope scope; |
| 43 env->Enter(); | 43 env->Enter(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 | 46 |
| 47 TEST(MarkingStack) { | 47 TEST(MarkingDeque) { |
| 48 int mem_size = 20 * kPointerSize; | 48 int mem_size = 20 * kPointerSize; |
| 49 byte* mem = NewArray<byte>(20*kPointerSize); | 49 byte* mem = NewArray<byte>(20*kPointerSize); |
| 50 Address low = reinterpret_cast<Address>(mem); | 50 Address low = reinterpret_cast<Address>(mem); |
| 51 Address high = low + mem_size; | 51 Address high = low + mem_size; |
| 52 MarkingStack s; | 52 MarkingDeque s; |
| 53 s.Initialize(low, high); | 53 s.Initialize(low, high); |
| 54 | 54 |
| 55 Address address = NULL; | 55 Address address = NULL; |
| 56 while (!s.is_full()) { | 56 while (!s.IsFull()) { |
| 57 s.Push(HeapObject::FromAddress(address)); | 57 s.PushBlack(HeapObject::FromAddress(address)); |
| 58 address += kPointerSize; | 58 address += kPointerSize; |
| 59 } | 59 } |
| 60 | 60 |
| 61 while (!s.is_empty()) { | 61 while (!s.IsEmpty()) { |
| 62 Address value = s.Pop()->address(); | 62 Address value = s.Pop()->address(); |
| 63 address -= kPointerSize; | 63 address -= kPointerSize; |
| 64 CHECK_EQ(address, value); | 64 CHECK_EQ(address, value); |
| 65 } | 65 } |
| 66 | 66 |
| 67 CHECK_EQ(NULL, address); | 67 CHECK_EQ(NULL, address); |
| 68 DeleteArray(mem); | 68 DeleteArray(mem); |
| 69 } | 69 } |
| 70 | 70 |
| 71 | 71 |
| 72 TEST(Promotion) { | 72 TEST(Promotion) { |
| 73 // This test requires compaction. If compaction is turned off, we | 73 // This test requires compaction. If compaction is turned off, we |
| 74 // skip the entire test. | 74 // skip the entire test. |
| 75 if (FLAG_never_compact) return; | 75 if (FLAG_never_compact) return; |
| 76 | 76 |
| 77 // Ensure that we get a compacting collection so that objects are promoted | 77 // Ensure that we get a compacting collection so that objects are promoted |
| 78 // from new space. | 78 // from new space. |
| 79 FLAG_gc_global = true; | 79 FLAG_gc_global = true; |
| 80 FLAG_always_compact = true; | 80 FLAG_always_compact = true; |
| 81 HEAP->ConfigureHeap(2*256*KB, 4*MB, 4*MB); | 81 HEAP->ConfigureHeap(2*256*KB, 8*MB, 8*MB); |
| 82 | 82 |
| 83 InitializeVM(); | 83 InitializeVM(); |
| 84 | 84 |
| 85 v8::HandleScope sc; | 85 v8::HandleScope sc; |
| 86 | 86 |
| 87 // Allocate a fixed array in the new space. | 87 // Allocate a fixed array in the new space. |
| 88 int array_size = | 88 int array_size = |
| 89 (HEAP->MaxObjectSizeInPagedSpace() - FixedArray::kHeaderSize) / | 89 (HEAP->MaxObjectSizeInPagedSpace() - FixedArray::kHeaderSize) / |
| 90 (kPointerSize * 4); | 90 (kPointerSize * 4); |
| 91 Object* obj = HEAP->AllocateFixedArray(array_size)->ToObjectChecked(); | 91 Object* obj = HEAP->AllocateFixedArray(array_size)->ToObjectChecked(); |
| 92 | 92 |
| 93 Handle<FixedArray> array(FixedArray::cast(obj)); | 93 Handle<FixedArray> array(FixedArray::cast(obj)); |
| 94 | 94 |
| 95 // Array should be in the new space. | 95 // Array should be in the new space. |
| 96 CHECK(HEAP->InSpace(*array, NEW_SPACE)); | 96 CHECK(HEAP->InSpace(*array, NEW_SPACE)); |
| 97 | 97 |
| 98 // Call the m-c collector, so array becomes an old object. | 98 // Call the m-c collector, so array becomes an old object. |
| 99 HEAP->CollectGarbage(OLD_POINTER_SPACE); | 99 HEAP->CollectGarbage(OLD_POINTER_SPACE); |
| 100 | 100 |
| 101 // Array now sits in the old space | 101 // Array now sits in the old space |
| 102 CHECK(HEAP->InSpace(*array, OLD_POINTER_SPACE)); | 102 CHECK(HEAP->InSpace(*array, OLD_POINTER_SPACE)); |
| 103 } | 103 } |
| 104 | 104 |
| 105 | 105 |
| 106 TEST(NoPromotion) { | 106 TEST(NoPromotion) { |
| 107 HEAP->ConfigureHeap(2*256*KB, 4*MB, 4*MB); | 107 HEAP->ConfigureHeap(2*256*KB, 8*MB, 8*MB); |
| 108 | 108 |
| 109 // Test the situation that some objects in new space are promoted to | 109 // Test the situation that some objects in new space are promoted to |
| 110 // the old space | 110 // the old space |
| 111 InitializeVM(); | 111 InitializeVM(); |
| 112 | 112 |
| 113 v8::HandleScope sc; | 113 v8::HandleScope sc; |
| 114 | 114 |
| 115 // Do a mark compact GC to shrink the heap. | 115 // Do a mark compact GC to shrink the heap. |
| 116 HEAP->CollectGarbage(OLD_POINTER_SPACE); | 116 HEAP->CollectGarbage(OLD_POINTER_SPACE); |
| 117 | 117 |
| 118 // Allocate a big Fixed array in the new space. | 118 // Allocate a big Fixed array in the new space. |
| 119 int size = (HEAP->MaxObjectSizeInPagedSpace() - FixedArray::kHeaderSize) / | 119 int max_size = |
| 120 kPointerSize; | 120 Min(HEAP->MaxObjectSizeInPagedSpace(), HEAP->MaxObjectSizeInNewSpace()); |
| 121 Object* obj = HEAP->AllocateFixedArray(size)->ToObjectChecked(); | 121 |
| 122 int length = (max_size - FixedArray::kHeaderSize) / (2*kPointerSize); |
| 123 Object* obj = i::Isolate::Current()->heap()->AllocateFixedArray(length)-> |
| 124 ToObjectChecked(); |
| 122 | 125 |
| 123 Handle<FixedArray> array(FixedArray::cast(obj)); | 126 Handle<FixedArray> array(FixedArray::cast(obj)); |
| 124 | 127 |
| 125 // Array still stays in the new space. | 128 // Array still stays in the new space. |
| 126 CHECK(HEAP->InSpace(*array, NEW_SPACE)); | 129 CHECK(HEAP->InSpace(*array, NEW_SPACE)); |
| 127 | 130 |
| 128 // Allocate objects in the old space until out of memory. | 131 // Allocate objects in the old space until out of memory. |
| 129 FixedArray* host = *array; | 132 FixedArray* host = *array; |
| 130 while (true) { | 133 while (true) { |
| 131 Object* obj; | 134 Object* obj; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 CHECK(Isolate::Current()->context()->global()-> | 224 CHECK(Isolate::Current()->context()->global()-> |
| 222 GetProperty(obj_name)->ToObjectChecked()->IsJSObject()); | 225 GetProperty(obj_name)->ToObjectChecked()->IsJSObject()); |
| 223 obj = JSObject::cast(Isolate::Current()->context()->global()-> | 226 obj = JSObject::cast(Isolate::Current()->context()->global()-> |
| 224 GetProperty(obj_name)->ToObjectChecked()); | 227 GetProperty(obj_name)->ToObjectChecked()); |
| 225 prop_name = | 228 prop_name = |
| 226 String::cast(HEAP->LookupAsciiSymbol("theSlot")->ToObjectChecked()); | 229 String::cast(HEAP->LookupAsciiSymbol("theSlot")->ToObjectChecked()); |
| 227 CHECK(obj->GetProperty(prop_name) == Smi::FromInt(23)); | 230 CHECK(obj->GetProperty(prop_name) == Smi::FromInt(23)); |
| 228 } | 231 } |
| 229 | 232 |
| 230 | 233 |
| 234 // TODO(1600): compaction of map space is temporary removed from GC. |
| 235 #if 0 |
| 231 static Handle<Map> CreateMap() { | 236 static Handle<Map> CreateMap() { |
| 232 return FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 237 return FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
| 233 } | 238 } |
| 234 | 239 |
| 235 | 240 |
| 236 TEST(MapCompact) { | 241 TEST(MapCompact) { |
| 237 FLAG_max_map_space_pages = 16; | 242 FLAG_max_map_space_pages = 16; |
| 238 InitializeVM(); | 243 InitializeVM(); |
| 239 | 244 |
| 240 { | 245 { |
| 241 v8::HandleScope sc; | 246 v8::HandleScope sc; |
| 242 // keep allocating maps while pointers are still encodable and thus | 247 // keep allocating maps while pointers are still encodable and thus |
| 243 // mark compact is permitted. | 248 // mark compact is permitted. |
| 244 Handle<JSObject> root = FACTORY->NewJSObjectFromMap(CreateMap()); | 249 Handle<JSObject> root = FACTORY->NewJSObjectFromMap(CreateMap()); |
| 245 do { | 250 do { |
| 246 Handle<Map> map = CreateMap(); | 251 Handle<Map> map = CreateMap(); |
| 247 map->set_prototype(*root); | 252 map->set_prototype(*root); |
| 248 root = FACTORY->NewJSObjectFromMap(map); | 253 root = FACTORY->NewJSObjectFromMap(map); |
| 249 } while (HEAP->map_space()->MapPointersEncodable()); | 254 } while (HEAP->map_space()->MapPointersEncodable()); |
| 250 } | 255 } |
| 251 // Now, as we don't have any handles to just allocated maps, we should | 256 // Now, as we don't have any handles to just allocated maps, we should |
| 252 // be able to trigger map compaction. | 257 // be able to trigger map compaction. |
| 253 // To give an additional chance to fail, try to force compaction which | 258 // To give an additional chance to fail, try to force compaction which |
| 254 // should be impossible right now. | 259 // should be impossible right now. |
| 255 HEAP->CollectAllGarbage(true); | 260 HEAP->CollectAllGarbage(Heap::kForceCompactionMask); |
| 256 // And now map pointers should be encodable again. | 261 // And now map pointers should be encodable again. |
| 257 CHECK(HEAP->map_space()->MapPointersEncodable()); | 262 CHECK(HEAP->map_space()->MapPointersEncodable()); |
| 258 } | 263 } |
| 259 | 264 #endif |
| 260 | 265 |
| 261 static int gc_starts = 0; | 266 static int gc_starts = 0; |
| 262 static int gc_ends = 0; | 267 static int gc_ends = 0; |
| 263 | 268 |
| 264 static void GCPrologueCallbackFunc() { | 269 static void GCPrologueCallbackFunc() { |
| 265 CHECK(gc_starts == gc_ends); | 270 CHECK(gc_starts == gc_ends); |
| 266 gc_starts++; | 271 gc_starts++; |
| 267 } | 272 } |
| 268 | 273 |
| 269 | 274 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 Handle<Object> object = | 440 Handle<Object> object = |
| 436 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 441 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
| 437 | 442 |
| 438 TestRetainedObjectInfo info; | 443 TestRetainedObjectInfo info; |
| 439 global_handles->AddObjectGroup(NULL, 0, &info); | 444 global_handles->AddObjectGroup(NULL, 0, &info); |
| 440 ASSERT(info.has_been_disposed()); | 445 ASSERT(info.has_been_disposed()); |
| 441 | 446 |
| 442 global_handles->AddImplicitReferences( | 447 global_handles->AddImplicitReferences( |
| 443 Handle<HeapObject>::cast(object).location(), NULL, 0); | 448 Handle<HeapObject>::cast(object).location(), NULL, 0); |
| 444 } | 449 } |
| OLD | NEW |