| OLD | NEW |
| 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 29 matching lines...) Expand all Loading... |
| 40 #include "global-handles.h" | 40 #include "global-handles.h" |
| 41 #include "snapshot.h" | 41 #include "snapshot.h" |
| 42 #include "cctest.h" | 42 #include "cctest.h" |
| 43 | 43 |
| 44 using namespace v8::internal; | 44 using namespace v8::internal; |
| 45 | 45 |
| 46 static v8::Persistent<v8::Context> env; | 46 static v8::Persistent<v8::Context> env; |
| 47 | 47 |
| 48 static void InitializeVM() { | 48 static void InitializeVM() { |
| 49 if (env.IsEmpty()) env = v8::Context::New(); | 49 if (env.IsEmpty()) env = v8::Context::New(); |
| 50 v8::HandleScope scope; | |
| 51 env->Enter(); | 50 env->Enter(); |
| 52 } | 51 } |
| 53 | 52 |
| 54 | 53 |
| 55 TEST(MarkingDeque) { | 54 TEST(MarkingDeque) { |
| 56 InitializeVM(); | 55 InitializeVM(); |
| 57 int mem_size = 20 * kPointerSize; | 56 int mem_size = 20 * kPointerSize; |
| 58 byte* mem = NewArray<byte>(20*kPointerSize); | 57 byte* mem = NewArray<byte>(20*kPointerSize); |
| 59 Address low = reinterpret_cast<Address>(mem); | 58 Address low = reinterpret_cast<Address>(mem); |
| 60 Address high = low + mem_size; | 59 Address high = low + mem_size; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 85 if (FLAG_never_compact) return; | 84 if (FLAG_never_compact) return; |
| 86 | 85 |
| 87 // Ensure that we get a compacting collection so that objects are promoted | 86 // Ensure that we get a compacting collection so that objects are promoted |
| 88 // from new space. | 87 // from new space. |
| 89 FLAG_gc_global = true; | 88 FLAG_gc_global = true; |
| 90 FLAG_always_compact = true; | 89 FLAG_always_compact = true; |
| 91 HEAP->ConfigureHeap(2*256*KB, 8*MB, 8*MB); | 90 HEAP->ConfigureHeap(2*256*KB, 8*MB, 8*MB); |
| 92 | 91 |
| 93 InitializeVM(); | 92 InitializeVM(); |
| 94 | 93 |
| 95 v8::HandleScope sc; | 94 v8::HandleScope sc(env->GetIsolate()); |
| 96 | 95 |
| 97 // Allocate a fixed array in the new space. | 96 // Allocate a fixed array in the new space. |
| 98 int array_size = | 97 int array_size = |
| 99 (Page::kMaxNonCodeHeapObjectSize - FixedArray::kHeaderSize) / | 98 (Page::kMaxNonCodeHeapObjectSize - FixedArray::kHeaderSize) / |
| 100 (kPointerSize * 4); | 99 (kPointerSize * 4); |
| 101 Object* obj = HEAP->AllocateFixedArray(array_size)->ToObjectChecked(); | 100 Object* obj = HEAP->AllocateFixedArray(array_size)->ToObjectChecked(); |
| 102 | 101 |
| 103 Handle<FixedArray> array(FixedArray::cast(obj)); | 102 Handle<FixedArray> array(FixedArray::cast(obj)); |
| 104 | 103 |
| 105 // Array should be in the new space. | 104 // Array should be in the new space. |
| 106 CHECK(HEAP->InSpace(*array, NEW_SPACE)); | 105 CHECK(HEAP->InSpace(*array, NEW_SPACE)); |
| 107 | 106 |
| 108 // Call the m-c collector, so array becomes an old object. | 107 // Call the m-c collector, so array becomes an old object. |
| 109 HEAP->CollectGarbage(OLD_POINTER_SPACE); | 108 HEAP->CollectGarbage(OLD_POINTER_SPACE); |
| 110 | 109 |
| 111 // Array now sits in the old space | 110 // Array now sits in the old space |
| 112 CHECK(HEAP->InSpace(*array, OLD_POINTER_SPACE)); | 111 CHECK(HEAP->InSpace(*array, OLD_POINTER_SPACE)); |
| 113 } | 112 } |
| 114 | 113 |
| 115 | 114 |
| 116 TEST(NoPromotion) { | 115 TEST(NoPromotion) { |
| 117 HEAP->ConfigureHeap(2*256*KB, 8*MB, 8*MB); | 116 HEAP->ConfigureHeap(2*256*KB, 8*MB, 8*MB); |
| 118 | 117 |
| 119 // Test the situation that some objects in new space are promoted to | 118 // Test the situation that some objects in new space are promoted to |
| 120 // the old space | 119 // the old space |
| 121 InitializeVM(); | 120 InitializeVM(); |
| 122 | 121 |
| 123 v8::HandleScope sc; | 122 v8::HandleScope sc(env->GetIsolate()); |
| 124 | 123 |
| 125 // Do a mark compact GC to shrink the heap. | 124 // Do a mark compact GC to shrink the heap. |
| 126 HEAP->CollectGarbage(OLD_POINTER_SPACE); | 125 HEAP->CollectGarbage(OLD_POINTER_SPACE); |
| 127 | 126 |
| 128 // Allocate a big Fixed array in the new space. | 127 // Allocate a big Fixed array in the new space. |
| 129 int max_size = | 128 int max_size = |
| 130 Min(Page::kMaxNonCodeHeapObjectSize, HEAP->MaxObjectSizeInNewSpace()); | 129 Min(Page::kMaxNonCodeHeapObjectSize, HEAP->MaxObjectSizeInNewSpace()); |
| 131 | 130 |
| 132 int length = (max_size - FixedArray::kHeaderSize) / (2*kPointerSize); | 131 int length = (max_size - FixedArray::kHeaderSize) / (2*kPointerSize); |
| 133 Object* obj = i::Isolate::Current()->heap()->AllocateFixedArray(length)-> | 132 Object* obj = i::Isolate::Current()->heap()->AllocateFixedArray(length)-> |
| (...skipping 17 matching lines...) Expand all Loading... |
| 151 } | 150 } |
| 152 | 151 |
| 153 // Call mark compact GC, and it should pass. | 152 // Call mark compact GC, and it should pass. |
| 154 HEAP->CollectGarbage(OLD_POINTER_SPACE); | 153 HEAP->CollectGarbage(OLD_POINTER_SPACE); |
| 155 } | 154 } |
| 156 | 155 |
| 157 | 156 |
| 158 TEST(MarkCompactCollector) { | 157 TEST(MarkCompactCollector) { |
| 159 InitializeVM(); | 158 InitializeVM(); |
| 160 | 159 |
| 161 v8::HandleScope sc; | 160 v8::HandleScope sc(env->GetIsolate()); |
| 162 // call mark-compact when heap is empty | 161 // call mark-compact when heap is empty |
| 163 HEAP->CollectGarbage(OLD_POINTER_SPACE); | 162 HEAP->CollectGarbage(OLD_POINTER_SPACE); |
| 164 | 163 |
| 165 // keep allocating garbage in new space until it fails | 164 // keep allocating garbage in new space until it fails |
| 166 const int ARRAY_SIZE = 100; | 165 const int ARRAY_SIZE = 100; |
| 167 Object* array; | 166 Object* array; |
| 168 MaybeObject* maybe_array; | 167 MaybeObject* maybe_array; |
| 169 do { | 168 do { |
| 170 maybe_array = HEAP->AllocateFixedArray(ARRAY_SIZE); | 169 maybe_array = HEAP->AllocateFixedArray(ARRAY_SIZE); |
| 171 } while (maybe_array->ToObject(&array)); | 170 } while (maybe_array->ToObject(&array)); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 NumberOfWeakCalls++; | 312 NumberOfWeakCalls++; |
| 314 handle.Dispose(isolate); | 313 handle.Dispose(isolate); |
| 315 } | 314 } |
| 316 | 315 |
| 317 TEST(ObjectGroups) { | 316 TEST(ObjectGroups) { |
| 318 FLAG_incremental_marking = false; | 317 FLAG_incremental_marking = false; |
| 319 InitializeVM(); | 318 InitializeVM(); |
| 320 GlobalHandles* global_handles = Isolate::Current()->global_handles(); | 319 GlobalHandles* global_handles = Isolate::Current()->global_handles(); |
| 321 | 320 |
| 322 NumberOfWeakCalls = 0; | 321 NumberOfWeakCalls = 0; |
| 323 v8::HandleScope handle_scope; | 322 v8::HandleScope handle_scope(env->GetIsolate()); |
| 324 | 323 |
| 325 Handle<Object> g1s1 = | 324 Handle<Object> g1s1 = |
| 326 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 325 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
| 327 Handle<Object> g1s2 = | 326 Handle<Object> g1s2 = |
| 328 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 327 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
| 329 Handle<Object> g1c1 = | 328 Handle<Object> g1c1 = |
| 330 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 329 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
| 331 global_handles->MakeWeak(g1s1.location(), | 330 global_handles->MakeWeak(g1s1.location(), |
| 332 reinterpret_cast<void*>(1234), | 331 reinterpret_cast<void*>(1234), |
| 333 NULL, | 332 NULL, |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 | 448 |
| 450 private: | 449 private: |
| 451 bool has_been_disposed_; | 450 bool has_been_disposed_; |
| 452 }; | 451 }; |
| 453 | 452 |
| 454 | 453 |
| 455 TEST(EmptyObjectGroups) { | 454 TEST(EmptyObjectGroups) { |
| 456 InitializeVM(); | 455 InitializeVM(); |
| 457 GlobalHandles* global_handles = Isolate::Current()->global_handles(); | 456 GlobalHandles* global_handles = Isolate::Current()->global_handles(); |
| 458 | 457 |
| 459 v8::HandleScope handle_scope; | 458 v8::HandleScope handle_scope(env->GetIsolate()); |
| 460 | 459 |
| 461 Handle<Object> object = | 460 Handle<Object> object = |
| 462 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 461 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
| 463 | 462 |
| 464 TestRetainedObjectInfo info; | 463 TestRetainedObjectInfo info; |
| 465 global_handles->AddObjectGroup(NULL, 0, &info); | 464 global_handles->AddObjectGroup(NULL, 0, &info); |
| 466 ASSERT(info.has_been_disposed()); | 465 ASSERT(info.has_been_disposed()); |
| 467 | 466 |
| 468 global_handles->AddImplicitReferences( | 467 global_handles->AddImplicitReferences( |
| 469 Handle<HeapObject>::cast(object).location(), NULL, 0); | 468 Handle<HeapObject>::cast(object).location(), NULL, 0); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 if (v8::internal::Snapshot::IsEnabled()) { | 565 if (v8::internal::Snapshot::IsEnabled()) { |
| 567 CHECK_LE(delta, 2900 * 1024); | 566 CHECK_LE(delta, 2900 * 1024); |
| 568 } else { | 567 } else { |
| 569 CHECK_LE(delta, 3400 * 1024); | 568 CHECK_LE(delta, 3400 * 1024); |
| 570 } | 569 } |
| 571 } | 570 } |
| 572 } | 571 } |
| 573 } | 572 } |
| 574 | 573 |
| 575 #endif // __linux__ and !USE_SIMULATOR | 574 #endif // __linux__ and !USE_SIMULATOR |
| OLD | NEW |