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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 | 228 |
229 CheckFindCodeObject(isolate); | 229 CheckFindCodeObject(isolate); |
230 } | 230 } |
231 | 231 |
232 | 232 |
233 TEST(Tagging) { | 233 TEST(Tagging) { |
234 CcTest::InitializeVM(); | 234 CcTest::InitializeVM(); |
235 int request = 24; | 235 int request = 24; |
236 CHECK_EQ(request, static_cast<int>(OBJECT_POINTER_ALIGN(request))); | 236 CHECK_EQ(request, static_cast<int>(OBJECT_POINTER_ALIGN(request))); |
237 CHECK(Smi::FromInt(42)->IsSmi()); | 237 CHECK(Smi::FromInt(42)->IsSmi()); |
238 CHECK(Failure::RetryAfterGC(NEW_SPACE)->IsFailure()); | |
239 CHECK_EQ(NEW_SPACE, | |
240 Failure::RetryAfterGC(NEW_SPACE)->allocation_space()); | |
241 CHECK_EQ(OLD_POINTER_SPACE, | |
242 Failure::RetryAfterGC(OLD_POINTER_SPACE)->allocation_space()); | |
243 CHECK(Smi::FromInt(Smi::kMinValue)->IsSmi()); | 238 CHECK(Smi::FromInt(Smi::kMinValue)->IsSmi()); |
244 CHECK(Smi::FromInt(Smi::kMaxValue)->IsSmi()); | 239 CHECK(Smi::FromInt(Smi::kMaxValue)->IsSmi()); |
245 } | 240 } |
246 | 241 |
247 | 242 |
248 TEST(GarbageCollection) { | 243 TEST(GarbageCollection) { |
249 CcTest::InitializeVM(); | 244 CcTest::InitializeVM(); |
250 Isolate* isolate = CcTest::i_isolate(); | 245 Isolate* isolate = CcTest::i_isolate(); |
251 Heap* heap = isolate->heap(); | 246 Heap* heap = isolate->heap(); |
252 Factory* factory = isolate->factory(); | 247 Factory* factory = isolate->factory(); |
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 // just enough room to allocate JSObject and thus fill the newspace. | 998 // just enough room to allocate JSObject and thus fill the newspace. |
1004 | 999 |
1005 int allocation_amount = Min(FixedArray::kMaxSize, | 1000 int allocation_amount = Min(FixedArray::kMaxSize, |
1006 Page::kMaxRegularHeapObjectSize + kPointerSize); | 1001 Page::kMaxRegularHeapObjectSize + kPointerSize); |
1007 int allocation_len = LenFromSize(allocation_amount); | 1002 int allocation_len = LenFromSize(allocation_amount); |
1008 NewSpace* new_space = heap->new_space(); | 1003 NewSpace* new_space = heap->new_space(); |
1009 Address* top_addr = new_space->allocation_top_address(); | 1004 Address* top_addr = new_space->allocation_top_address(); |
1010 Address* limit_addr = new_space->allocation_limit_address(); | 1005 Address* limit_addr = new_space->allocation_limit_address(); |
1011 while ((*limit_addr - *top_addr) > allocation_amount) { | 1006 while ((*limit_addr - *top_addr) > allocation_amount) { |
1012 CHECK(!heap->always_allocate()); | 1007 CHECK(!heap->always_allocate()); |
1013 Object* array = heap->AllocateFixedArray(allocation_len)->ToObjectChecked(); | 1008 Object* array = heap->AllocateFixedArray(allocation_len).ToObjectChecked(); |
1014 CHECK(!array->IsFailure()); | |
1015 CHECK(new_space->Contains(array)); | 1009 CHECK(new_space->Contains(array)); |
1016 } | 1010 } |
1017 | 1011 |
1018 // Step 3: now allocate fixed array and JSObject to fill the whole new space. | 1012 // Step 3: now allocate fixed array and JSObject to fill the whole new space. |
1019 int to_fill = static_cast<int>(*limit_addr - *top_addr - object_size); | 1013 int to_fill = static_cast<int>(*limit_addr - *top_addr - object_size); |
1020 int fixed_array_len = LenFromSize(to_fill); | 1014 int fixed_array_len = LenFromSize(to_fill); |
1021 CHECK(fixed_array_len < FixedArray::kMaxLength); | 1015 CHECK(fixed_array_len < FixedArray::kMaxLength); |
1022 | 1016 |
1023 CHECK(!heap->always_allocate()); | 1017 CHECK(!heap->always_allocate()); |
1024 Object* array = heap->AllocateFixedArray(fixed_array_len)->ToObjectChecked(); | 1018 Object* array = heap->AllocateFixedArray(fixed_array_len).ToObjectChecked(); |
1025 CHECK(!array->IsFailure()); | |
1026 CHECK(new_space->Contains(array)); | 1019 CHECK(new_space->Contains(array)); |
1027 | 1020 |
1028 Object* object = heap->AllocateJSObjectFromMap(*my_map)->ToObjectChecked(); | 1021 Object* object = heap->AllocateJSObjectFromMap(*my_map).ToObjectChecked(); |
1029 CHECK(new_space->Contains(object)); | 1022 CHECK(new_space->Contains(object)); |
1030 JSObject* jsobject = JSObject::cast(object); | 1023 JSObject* jsobject = JSObject::cast(object); |
1031 CHECK_EQ(0, FixedArray::cast(jsobject->elements())->length()); | 1024 CHECK_EQ(0, FixedArray::cast(jsobject->elements())->length()); |
1032 CHECK_EQ(0, jsobject->properties()->length()); | 1025 CHECK_EQ(0, jsobject->properties()->length()); |
1033 // Create a reference to object in new space in jsobject. | 1026 // Create a reference to object in new space in jsobject. |
1034 jsobject->FastPropertyAtPut(-1, array); | 1027 jsobject->FastPropertyAtPut(-1, array); |
1035 | 1028 |
1036 CHECK_EQ(0, static_cast<int>(*limit_addr - *top_addr)); | 1029 CHECK_EQ(0, static_cast<int>(*limit_addr - *top_addr)); |
1037 | 1030 |
1038 // Step 4: clone jsobject, but force always allocate first to create a clone | 1031 // Step 4: clone jsobject, but force always allocate first to create a clone |
1039 // in old pointer space. | 1032 // in old pointer space. |
1040 Address old_pointer_space_top = heap->old_pointer_space()->top(); | 1033 Address old_pointer_space_top = heap->old_pointer_space()->top(); |
1041 AlwaysAllocateScope aa_scope(isolate); | 1034 AlwaysAllocateScope aa_scope(isolate); |
1042 Object* clone_obj = heap->CopyJSObject(jsobject)->ToObjectChecked(); | 1035 Object* clone_obj = heap->CopyJSObject(jsobject).ToObjectChecked(); |
1043 JSObject* clone = JSObject::cast(clone_obj); | 1036 JSObject* clone = JSObject::cast(clone_obj); |
1044 if (clone->address() != old_pointer_space_top) { | 1037 if (clone->address() != old_pointer_space_top) { |
1045 // Alas, got allocated from free list, we cannot do checks. | 1038 // Alas, got allocated from free list, we cannot do checks. |
1046 return; | 1039 return; |
1047 } | 1040 } |
1048 CHECK(heap->old_pointer_space()->Contains(clone->address())); | 1041 CHECK(heap->old_pointer_space()->Contains(clone->address())); |
1049 } | 1042 } |
1050 | 1043 |
1051 | 1044 |
1052 TEST(TestCodeFlushing) { | 1045 TEST(TestCodeFlushing) { |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1610 } | 1603 } |
1611 int initial_size = static_cast<int>(CcTest::heap()->SizeOfObjects()); | 1604 int initial_size = static_cast<int>(CcTest::heap()->SizeOfObjects()); |
1612 | 1605 |
1613 { | 1606 { |
1614 // Allocate objects on several different old-space pages so that | 1607 // Allocate objects on several different old-space pages so that |
1615 // concurrent sweeper threads will be busy sweeping the old space on | 1608 // concurrent sweeper threads will be busy sweeping the old space on |
1616 // subsequent GC runs. | 1609 // subsequent GC runs. |
1617 AlwaysAllocateScope always_allocate(CcTest::i_isolate()); | 1610 AlwaysAllocateScope always_allocate(CcTest::i_isolate()); |
1618 int filler_size = static_cast<int>(FixedArray::SizeFor(8192)); | 1611 int filler_size = static_cast<int>(FixedArray::SizeFor(8192)); |
1619 for (int i = 1; i <= 100; i++) { | 1612 for (int i = 1; i <= 100; i++) { |
1620 CcTest::heap()->AllocateFixedArray(8192, TENURED)->ToObjectChecked(); | 1613 CcTest::heap()->AllocateFixedArray(8192, TENURED).ToObjectChecked(); |
1621 CHECK_EQ(initial_size + i * filler_size, | 1614 CHECK_EQ(initial_size + i * filler_size, |
1622 static_cast<int>(CcTest::heap()->SizeOfObjects())); | 1615 static_cast<int>(CcTest::heap()->SizeOfObjects())); |
1623 } | 1616 } |
1624 } | 1617 } |
1625 | 1618 |
1626 // The heap size should go back to initial size after a full GC, even | 1619 // The heap size should go back to initial size after a full GC, even |
1627 // though sweeping didn't finish yet. | 1620 // though sweeping didn't finish yet. |
1628 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 1621 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
1629 | 1622 |
1630 // Normally sweeping would not be complete here, but no guarantees. | 1623 // Normally sweeping would not be complete here, but no guarantees. |
(...skipping 1843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3474 } | 3467 } |
3475 | 3468 |
3476 | 3469 |
3477 // Helper function that simulates a fill new-space in the heap. | 3470 // Helper function that simulates a fill new-space in the heap. |
3478 static inline void AllocateAllButNBytes(v8::internal::NewSpace* space, | 3471 static inline void AllocateAllButNBytes(v8::internal::NewSpace* space, |
3479 int extra_bytes) { | 3472 int extra_bytes) { |
3480 int space_remaining = static_cast<int>( | 3473 int space_remaining = static_cast<int>( |
3481 *space->allocation_limit_address() - *space->allocation_top_address()); | 3474 *space->allocation_limit_address() - *space->allocation_top_address()); |
3482 CHECK(space_remaining >= extra_bytes); | 3475 CHECK(space_remaining >= extra_bytes); |
3483 int new_linear_size = space_remaining - extra_bytes; | 3476 int new_linear_size = space_remaining - extra_bytes; |
3484 v8::internal::MaybeObject* maybe = space->AllocateRaw(new_linear_size); | 3477 v8::internal::AllocationResult allocation = |
3485 v8::internal::FreeListNode* node = v8::internal::FreeListNode::cast(maybe); | 3478 space->AllocateRaw(new_linear_size); |
| 3479 v8::internal::FreeListNode* node = |
| 3480 v8::internal::FreeListNode::cast(allocation.ToObjectChecked()); |
3486 node->set_size(space->heap(), new_linear_size); | 3481 node->set_size(space->heap(), new_linear_size); |
3487 } | 3482 } |
3488 | 3483 |
3489 | 3484 |
3490 TEST(Regress169928) { | 3485 TEST(Regress169928) { |
3491 i::FLAG_allow_natives_syntax = true; | 3486 i::FLAG_allow_natives_syntax = true; |
3492 i::FLAG_crankshaft = false; | 3487 i::FLAG_crankshaft = false; |
3493 CcTest::InitializeVM(); | 3488 CcTest::InitializeVM(); |
3494 Isolate* isolate = CcTest::i_isolate(); | 3489 Isolate* isolate = CcTest::i_isolate(); |
3495 Factory* factory = isolate->factory(); | 3490 Factory* factory = isolate->factory(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3533 | 3528 |
3534 Handle<JSArray> array = factory->NewJSArrayWithElements(array_data, | 3529 Handle<JSArray> array = factory->NewJSArrayWithElements(array_data, |
3535 FAST_SMI_ELEMENTS, | 3530 FAST_SMI_ELEMENTS, |
3536 NOT_TENURED); | 3531 NOT_TENURED); |
3537 | 3532 |
3538 CHECK_EQ(Smi::FromInt(2), array->length()); | 3533 CHECK_EQ(Smi::FromInt(2), array->length()); |
3539 CHECK(array->HasFastSmiOrObjectElements()); | 3534 CHECK(array->HasFastSmiOrObjectElements()); |
3540 | 3535 |
3541 // We need filler the size of AllocationMemento object, plus an extra | 3536 // We need filler the size of AllocationMemento object, plus an extra |
3542 // fill pointer value. | 3537 // fill pointer value. |
3543 MaybeObject* maybe_object = CcTest::heap()->new_space()->AllocateRaw( | 3538 HeapObject* obj = NULL; |
| 3539 AllocationResult allocation = CcTest::heap()->new_space()->AllocateRaw( |
3544 AllocationMemento::kSize + kPointerSize); | 3540 AllocationMemento::kSize + kPointerSize); |
3545 Object* obj = NULL; | 3541 CHECK(allocation.To(&obj)); |
3546 CHECK(maybe_object->ToObject(&obj)); | 3542 Address addr_obj = obj->address(); |
3547 Address addr_obj = reinterpret_cast<Address>( | 3543 CcTest::heap()->CreateFillerObjectAt( |
3548 reinterpret_cast<byte*>(obj - kHeapObjectTag)); | 3544 addr_obj, AllocationMemento::kSize + kPointerSize); |
3549 CcTest::heap()->CreateFillerObjectAt(addr_obj, | |
3550 AllocationMemento::kSize + kPointerSize); | |
3551 | 3545 |
3552 // Give the array a name, making sure not to allocate strings. | 3546 // Give the array a name, making sure not to allocate strings. |
3553 v8::Handle<v8::Object> array_obj = v8::Utils::ToLocal(array); | 3547 v8::Handle<v8::Object> array_obj = v8::Utils::ToLocal(array); |
3554 CcTest::global()->Set(array_name, array_obj); | 3548 CcTest::global()->Set(array_name, array_obj); |
3555 | 3549 |
3556 // This should crash with a protection violation if we are running a build | 3550 // This should crash with a protection violation if we are running a build |
3557 // with the bug. | 3551 // with the bug. |
3558 AlwaysAllocateScope aa_scope(isolate); | 3552 AlwaysAllocateScope aa_scope(isolate); |
3559 v8::Script::Compile(mote_code_string)->Run(); | 3553 v8::Script::Compile(mote_code_string)->Run(); |
3560 } | 3554 } |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4215 "array;"); | 4209 "array;"); |
4216 | 4210 |
4217 Handle<JSObject> o = | 4211 Handle<JSObject> o = |
4218 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(result)); | 4212 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(result)); |
4219 CHECK(heap->InOldPointerSpace(o->elements())); | 4213 CHECK(heap->InOldPointerSpace(o->elements())); |
4220 CHECK(heap->InOldPointerSpace(*o)); | 4214 CHECK(heap->InOldPointerSpace(*o)); |
4221 Page* page = Page::FromAddress(o->elements()->address()); | 4215 Page* page = Page::FromAddress(o->elements()->address()); |
4222 CHECK(page->WasSwept() || | 4216 CHECK(page->WasSwept() || |
4223 Marking::IsBlack(Marking::MarkBitFrom(o->elements()))); | 4217 Marking::IsBlack(Marking::MarkBitFrom(o->elements()))); |
4224 } | 4218 } |
OLD | NEW |