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 | 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 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 objs[next_objs_index++] = | 802 objs[next_objs_index++] = |
803 Factory::NewStringFromAscii(CStrVector(str), TENURED); | 803 Factory::NewStringFromAscii(CStrVector(str), TENURED); |
804 delete[] str; | 804 delete[] str; |
805 | 805 |
806 // Add a Map object to look for. | 806 // Add a Map object to look for. |
807 objs[next_objs_index++] = Handle<Map>(HeapObject::cast(*objs[0])->map()); | 807 objs[next_objs_index++] = Handle<Map>(HeapObject::cast(*objs[0])->map()); |
808 | 808 |
809 CHECK_EQ(objs_count, next_objs_index); | 809 CHECK_EQ(objs_count, next_objs_index); |
810 CHECK_EQ(objs_count, ObjectsFoundInHeap(objs, objs_count)); | 810 CHECK_EQ(objs_count, ObjectsFoundInHeap(objs, objs_count)); |
811 } | 811 } |
| 812 |
| 813 |
| 814 TEST(LargeObjectSpaceContains) { |
| 815 InitializeVM(); |
| 816 |
| 817 int free_bytes = Heap::MaxObjectSizeInPagedSpace(); |
| 818 CHECK(Heap::CollectGarbage(free_bytes, NEW_SPACE)); |
| 819 |
| 820 Address current_top = Heap::new_space()->top(); |
| 821 Page* page = Page::FromAddress(current_top); |
| 822 Address current_page = page->address(); |
| 823 Address next_page = current_page + Page::kPageSize; |
| 824 int bytes_to_page = next_page - current_top; |
| 825 if (bytes_to_page <= FixedArray::kHeaderSize) { |
| 826 // Alas, need to cross another page to be able to |
| 827 // put desired value. |
| 828 next_page += Page::kPageSize; |
| 829 bytes_to_page = next_page - current_top; |
| 830 } |
| 831 CHECK(bytes_to_page > FixedArray::kHeaderSize); |
| 832 |
| 833 int* is_normal_page_ptr = &Page::FromAddress(next_page)->is_normal_page; |
| 834 Address is_normal_page_addr = reinterpret_cast<Address>(is_normal_page_ptr); |
| 835 |
| 836 int bytes_to_allocate = (is_normal_page_addr - current_top) + kPointerSize; |
| 837 |
| 838 int n_elements = (bytes_to_allocate - FixedArray::kHeaderSize) / |
| 839 kPointerSize; |
| 840 CHECK_EQ(bytes_to_allocate, FixedArray::SizeFor(n_elements)); |
| 841 FixedArray* array = FixedArray::cast( |
| 842 Heap::AllocateFixedArray(n_elements)); |
| 843 |
| 844 int index = n_elements - 1; |
| 845 CHECK_EQ(is_normal_page_ptr, |
| 846 HeapObject::RawField(array, FixedArray::OffsetOfElementAt(index))); |
| 847 array->set(index, Smi::FromInt(0)); |
| 848 // This chould have turned next page into LargeObjectPage: |
| 849 // CHECK(Page::FromAddress(next_page)->IsLargeObjectPage()); |
| 850 |
| 851 HeapObject* addr = HeapObject::FromAddress(next_page + 2 * kPointerSize); |
| 852 CHECK(Heap::new_space()->Contains(addr)); |
| 853 CHECK(!Heap::lo_space()->Contains(addr)); |
| 854 } |
OLD | NEW |