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 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1010 // just enough room to allocate JSObject and thus fill the newspace. | 1005 // just enough room to allocate JSObject and thus fill the newspace. |
1011 | 1006 |
1012 int allocation_amount = Min(FixedArray::kMaxSize, | 1007 int allocation_amount = Min(FixedArray::kMaxSize, |
1013 Page::kMaxRegularHeapObjectSize + kPointerSize); | 1008 Page::kMaxRegularHeapObjectSize + kPointerSize); |
1014 int allocation_len = LenFromSize(allocation_amount); | 1009 int allocation_len = LenFromSize(allocation_amount); |
1015 NewSpace* new_space = heap->new_space(); | 1010 NewSpace* new_space = heap->new_space(); |
1016 Address* top_addr = new_space->allocation_top_address(); | 1011 Address* top_addr = new_space->allocation_top_address(); |
1017 Address* limit_addr = new_space->allocation_limit_address(); | 1012 Address* limit_addr = new_space->allocation_limit_address(); |
1018 while ((*limit_addr - *top_addr) > allocation_amount) { | 1013 while ((*limit_addr - *top_addr) > allocation_amount) { |
1019 CHECK(!heap->always_allocate()); | 1014 CHECK(!heap->always_allocate()); |
1020 Object* array = heap->AllocateFixedArray(allocation_len)->ToObjectChecked(); | 1015 Object* array = heap->AllocateFixedArray(allocation_len).ToObjectChecked(); |
1021 CHECK(!array->IsFailure()); | |
1022 CHECK(new_space->Contains(array)); | 1016 CHECK(new_space->Contains(array)); |
1023 } | 1017 } |
1024 | 1018 |
1025 // Step 3: now allocate fixed array and JSObject to fill the whole new space. | 1019 // Step 3: now allocate fixed array and JSObject to fill the whole new space. |
1026 int to_fill = static_cast<int>(*limit_addr - *top_addr - object_size); | 1020 int to_fill = static_cast<int>(*limit_addr - *top_addr - object_size); |
1027 int fixed_array_len = LenFromSize(to_fill); | 1021 int fixed_array_len = LenFromSize(to_fill); |
1028 CHECK(fixed_array_len < FixedArray::kMaxLength); | 1022 CHECK(fixed_array_len < FixedArray::kMaxLength); |
1029 | 1023 |
1030 CHECK(!heap->always_allocate()); | 1024 CHECK(!heap->always_allocate()); |
1031 Object* array = heap->AllocateFixedArray(fixed_array_len)->ToObjectChecked(); | 1025 Object* array = heap->AllocateFixedArray(fixed_array_len).ToObjectChecked(); |
1032 CHECK(!array->IsFailure()); | |
1033 CHECK(new_space->Contains(array)); | 1026 CHECK(new_space->Contains(array)); |
1034 | 1027 |
1035 Object* object = heap->AllocateJSObjectFromMap(*my_map)->ToObjectChecked(); | 1028 Object* object = heap->AllocateJSObjectFromMap(*my_map).ToObjectChecked(); |
1036 CHECK(new_space->Contains(object)); | 1029 CHECK(new_space->Contains(object)); |
1037 JSObject* jsobject = JSObject::cast(object); | 1030 JSObject* jsobject = JSObject::cast(object); |
1038 CHECK_EQ(0, FixedArray::cast(jsobject->elements())->length()); | 1031 CHECK_EQ(0, FixedArray::cast(jsobject->elements())->length()); |
1039 CHECK_EQ(0, jsobject->properties()->length()); | 1032 CHECK_EQ(0, jsobject->properties()->length()); |
1040 // Create a reference to object in new space in jsobject. | 1033 // Create a reference to object in new space in jsobject. |
1041 jsobject->FastPropertyAtPut(-1, array); | 1034 jsobject->FastPropertyAtPut(-1, array); |
1042 | 1035 |
1043 CHECK_EQ(0, static_cast<int>(*limit_addr - *top_addr)); | 1036 CHECK_EQ(0, static_cast<int>(*limit_addr - *top_addr)); |
1044 | 1037 |
1045 // Step 4: clone jsobject, but force always allocate first to create a clone | 1038 // Step 4: clone jsobject, but force always allocate first to create a clone |
1046 // in old pointer space. | 1039 // in old pointer space. |
1047 Address old_pointer_space_top = heap->old_pointer_space()->top(); | 1040 Address old_pointer_space_top = heap->old_pointer_space()->top(); |
1048 AlwaysAllocateScope aa_scope(isolate); | 1041 AlwaysAllocateScope aa_scope(isolate); |
1049 Object* clone_obj = heap->CopyJSObject(jsobject)->ToObjectChecked(); | 1042 Object* clone_obj = heap->CopyJSObject(jsobject).ToObjectChecked(); |
1050 JSObject* clone = JSObject::cast(clone_obj); | 1043 JSObject* clone = JSObject::cast(clone_obj); |
1051 if (clone->address() != old_pointer_space_top) { | 1044 if (clone->address() != old_pointer_space_top) { |
1052 // Alas, got allocated from free list, we cannot do checks. | 1045 // Alas, got allocated from free list, we cannot do checks. |
1053 return; | 1046 return; |
1054 } | 1047 } |
1055 CHECK(heap->old_pointer_space()->Contains(clone->address())); | 1048 CHECK(heap->old_pointer_space()->Contains(clone->address())); |
1056 } | 1049 } |
1057 | 1050 |
1058 | 1051 |
1059 TEST(TestCodeFlushing) { | 1052 TEST(TestCodeFlushing) { |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1617 } | 1610 } |
1618 int initial_size = static_cast<int>(CcTest::heap()->SizeOfObjects()); | 1611 int initial_size = static_cast<int>(CcTest::heap()->SizeOfObjects()); |
1619 | 1612 |
1620 { | 1613 { |
1621 // Allocate objects on several different old-space pages so that | 1614 // Allocate objects on several different old-space pages so that |
1622 // concurrent sweeper threads will be busy sweeping the old space on | 1615 // concurrent sweeper threads will be busy sweeping the old space on |
1623 // subsequent GC runs. | 1616 // subsequent GC runs. |
1624 AlwaysAllocateScope always_allocate(CcTest::i_isolate()); | 1617 AlwaysAllocateScope always_allocate(CcTest::i_isolate()); |
1625 int filler_size = static_cast<int>(FixedArray::SizeFor(8192)); | 1618 int filler_size = static_cast<int>(FixedArray::SizeFor(8192)); |
1626 for (int i = 1; i <= 100; i++) { | 1619 for (int i = 1; i <= 100; i++) { |
1627 CcTest::test_heap()->AllocateFixedArray(8192, TENURED)->ToObjectChecked(); | 1620 CcTest::test_heap()->AllocateFixedArray(8192, TENURED).ToObjectChecked(); |
1628 CHECK_EQ(initial_size + i * filler_size, | 1621 CHECK_EQ(initial_size + i * filler_size, |
1629 static_cast<int>(CcTest::heap()->SizeOfObjects())); | 1622 static_cast<int>(CcTest::heap()->SizeOfObjects())); |
1630 } | 1623 } |
1631 } | 1624 } |
1632 | 1625 |
1633 // The heap size should go back to initial size after a full GC, even | 1626 // The heap size should go back to initial size after a full GC, even |
1634 // though sweeping didn't finish yet. | 1627 // though sweeping didn't finish yet. |
1635 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 1628 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
1636 | 1629 |
1637 // Normally sweeping would not be complete here, but no guarantees. | 1630 // Normally sweeping would not be complete here, but no guarantees. |
(...skipping 1842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3480 } | 3473 } |
3481 | 3474 |
3482 | 3475 |
3483 // Helper function that simulates a fill new-space in the heap. | 3476 // Helper function that simulates a fill new-space in the heap. |
3484 static inline void AllocateAllButNBytes(v8::internal::NewSpace* space, | 3477 static inline void AllocateAllButNBytes(v8::internal::NewSpace* space, |
3485 int extra_bytes) { | 3478 int extra_bytes) { |
3486 int space_remaining = static_cast<int>( | 3479 int space_remaining = static_cast<int>( |
3487 *space->allocation_limit_address() - *space->allocation_top_address()); | 3480 *space->allocation_limit_address() - *space->allocation_top_address()); |
3488 CHECK(space_remaining >= extra_bytes); | 3481 CHECK(space_remaining >= extra_bytes); |
3489 int new_linear_size = space_remaining - extra_bytes; | 3482 int new_linear_size = space_remaining - extra_bytes; |
3490 v8::internal::MaybeObject* maybe = space->AllocateRaw(new_linear_size); | 3483 v8::internal::AllocationResult allocation = |
3491 v8::internal::FreeListNode* node = v8::internal::FreeListNode::cast(maybe); | 3484 space->AllocateRaw(new_linear_size); |
| 3485 v8::internal::FreeListNode* node = |
| 3486 v8::internal::FreeListNode::cast(allocation.ToObjectChecked()); |
3492 node->set_size(space->heap(), new_linear_size); | 3487 node->set_size(space->heap(), new_linear_size); |
3493 } | 3488 } |
3494 | 3489 |
3495 | 3490 |
3496 TEST(Regress169928) { | 3491 TEST(Regress169928) { |
3497 i::FLAG_allow_natives_syntax = true; | 3492 i::FLAG_allow_natives_syntax = true; |
3498 i::FLAG_crankshaft = false; | 3493 i::FLAG_crankshaft = false; |
3499 CcTest::InitializeVM(); | 3494 CcTest::InitializeVM(); |
3500 Isolate* isolate = CcTest::i_isolate(); | 3495 Isolate* isolate = CcTest::i_isolate(); |
3501 Factory* factory = isolate->factory(); | 3496 Factory* factory = isolate->factory(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3539 | 3534 |
3540 Handle<JSArray> array = factory->NewJSArrayWithElements(array_data, | 3535 Handle<JSArray> array = factory->NewJSArrayWithElements(array_data, |
3541 FAST_SMI_ELEMENTS, | 3536 FAST_SMI_ELEMENTS, |
3542 NOT_TENURED); | 3537 NOT_TENURED); |
3543 | 3538 |
3544 CHECK_EQ(Smi::FromInt(2), array->length()); | 3539 CHECK_EQ(Smi::FromInt(2), array->length()); |
3545 CHECK(array->HasFastSmiOrObjectElements()); | 3540 CHECK(array->HasFastSmiOrObjectElements()); |
3546 | 3541 |
3547 // We need filler the size of AllocationMemento object, plus an extra | 3542 // We need filler the size of AllocationMemento object, plus an extra |
3548 // fill pointer value. | 3543 // fill pointer value. |
3549 MaybeObject* maybe_object = CcTest::heap()->new_space()->AllocateRaw( | 3544 HeapObject* obj = NULL; |
| 3545 AllocationResult allocation = CcTest::heap()->new_space()->AllocateRaw( |
3550 AllocationMemento::kSize + kPointerSize); | 3546 AllocationMemento::kSize + kPointerSize); |
3551 Object* obj = NULL; | 3547 CHECK(allocation.To(&obj)); |
3552 CHECK(maybe_object->ToObject(&obj)); | 3548 Address addr_obj = obj->address(); |
3553 Address addr_obj = reinterpret_cast<Address>( | 3549 CcTest::heap()->CreateFillerObjectAt( |
3554 reinterpret_cast<byte*>(obj - kHeapObjectTag)); | 3550 addr_obj, AllocationMemento::kSize + kPointerSize); |
3555 CcTest::heap()->CreateFillerObjectAt(addr_obj, | |
3556 AllocationMemento::kSize + kPointerSize); | |
3557 | 3551 |
3558 // Give the array a name, making sure not to allocate strings. | 3552 // Give the array a name, making sure not to allocate strings. |
3559 v8::Handle<v8::Object> array_obj = v8::Utils::ToLocal(array); | 3553 v8::Handle<v8::Object> array_obj = v8::Utils::ToLocal(array); |
3560 CcTest::global()->Set(array_name, array_obj); | 3554 CcTest::global()->Set(array_name, array_obj); |
3561 | 3555 |
3562 // This should crash with a protection violation if we are running a build | 3556 // This should crash with a protection violation if we are running a build |
3563 // with the bug. | 3557 // with the bug. |
3564 AlwaysAllocateScope aa_scope(isolate); | 3558 AlwaysAllocateScope aa_scope(isolate); |
3565 v8::Script::Compile(mote_code_string)->Run(); | 3559 v8::Script::Compile(mote_code_string)->Run(); |
3566 } | 3560 } |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4221 "array;"); | 4215 "array;"); |
4222 | 4216 |
4223 Handle<JSObject> o = | 4217 Handle<JSObject> o = |
4224 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(result)); | 4218 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(result)); |
4225 CHECK(heap->InOldPointerSpace(o->elements())); | 4219 CHECK(heap->InOldPointerSpace(o->elements())); |
4226 CHECK(heap->InOldPointerSpace(*o)); | 4220 CHECK(heap->InOldPointerSpace(*o)); |
4227 Page* page = Page::FromAddress(o->elements()->address()); | 4221 Page* page = Page::FromAddress(o->elements()->address()); |
4228 CHECK(page->WasSwept() || | 4222 CHECK(page->WasSwept() || |
4229 Marking::IsBlack(Marking::MarkBitFrom(o->elements()))); | 4223 Marking::IsBlack(Marking::MarkBitFrom(o->elements()))); |
4230 } | 4224 } |
OLD | NEW |