| 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 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 TEST(LargeObjectSpaceContains) { | 814 TEST(LargeObjectSpaceContains) { |
| 815 InitializeVM(); | 815 InitializeVM(); |
| 816 | 816 |
| 817 int free_bytes = Heap::MaxObjectSizeInPagedSpace(); | 817 int free_bytes = Heap::MaxObjectSizeInPagedSpace(); |
| 818 CHECK(Heap::CollectGarbage(free_bytes, NEW_SPACE)); | 818 CHECK(Heap::CollectGarbage(free_bytes, NEW_SPACE)); |
| 819 | 819 |
| 820 Address current_top = Heap::new_space()->top(); | 820 Address current_top = Heap::new_space()->top(); |
| 821 Page* page = Page::FromAddress(current_top); | 821 Page* page = Page::FromAddress(current_top); |
| 822 Address current_page = page->address(); | 822 Address current_page = page->address(); |
| 823 Address next_page = current_page + Page::kPageSize; | 823 Address next_page = current_page + Page::kPageSize; |
| 824 int bytes_to_page = next_page - current_top; | 824 int bytes_to_page = static_cast<int>(next_page - current_top); |
| 825 if (bytes_to_page <= FixedArray::kHeaderSize) { | 825 if (bytes_to_page <= FixedArray::kHeaderSize) { |
| 826 // Alas, need to cross another page to be able to | 826 // Alas, need to cross another page to be able to |
| 827 // put desired value. | 827 // put desired value. |
| 828 next_page += Page::kPageSize; | 828 next_page += Page::kPageSize; |
| 829 bytes_to_page = next_page - current_top; | 829 bytes_to_page = static_cast<int>(next_page - current_top); |
| 830 } | 830 } |
| 831 CHECK(bytes_to_page > FixedArray::kHeaderSize); | 831 CHECK(bytes_to_page > FixedArray::kHeaderSize); |
| 832 | 832 |
| 833 int* is_normal_page_ptr = &Page::FromAddress(next_page)->is_normal_page; | 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); | 834 Address is_normal_page_addr = reinterpret_cast<Address>(is_normal_page_ptr); |
| 835 | 835 |
| 836 int bytes_to_allocate = (is_normal_page_addr - current_top) + kPointerSize; | 836 int bytes_to_allocate = |
| 837 static_cast<int>(is_normal_page_addr - current_top) + kPointerSize; |
| 837 | 838 |
| 838 int n_elements = (bytes_to_allocate - FixedArray::kHeaderSize) / | 839 int n_elements = (bytes_to_allocate - FixedArray::kHeaderSize) / |
| 839 kPointerSize; | 840 kPointerSize; |
| 840 CHECK_EQ(bytes_to_allocate, FixedArray::SizeFor(n_elements)); | 841 CHECK_EQ(bytes_to_allocate, FixedArray::SizeFor(n_elements)); |
| 841 FixedArray* array = FixedArray::cast( | 842 FixedArray* array = FixedArray::cast( |
| 842 Heap::AllocateFixedArray(n_elements)); | 843 Heap::AllocateFixedArray(n_elements)); |
| 843 | 844 |
| 844 int index = n_elements - 1; | 845 int index = n_elements - 1; |
| 845 CHECK_EQ(is_normal_page_ptr, | 846 CHECK_EQ(is_normal_page_ptr, |
| 846 HeapObject::RawField(array, FixedArray::OffsetOfElementAt(index))); | 847 HeapObject::RawField(array, FixedArray::OffsetOfElementAt(index))); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 Address* top_addr = new_space->allocation_top_address(); | 911 Address* top_addr = new_space->allocation_top_address(); |
| 911 Address* limit_addr = new_space->allocation_limit_address(); | 912 Address* limit_addr = new_space->allocation_limit_address(); |
| 912 while ((*limit_addr - *top_addr) > allocation_amount) { | 913 while ((*limit_addr - *top_addr) > allocation_amount) { |
| 913 CHECK(!Heap::always_allocate()); | 914 CHECK(!Heap::always_allocate()); |
| 914 Object* array = Heap::AllocateFixedArray(allocation_len); | 915 Object* array = Heap::AllocateFixedArray(allocation_len); |
| 915 CHECK(!array->IsFailure()); | 916 CHECK(!array->IsFailure()); |
| 916 CHECK(new_space->Contains(array)); | 917 CHECK(new_space->Contains(array)); |
| 917 } | 918 } |
| 918 | 919 |
| 919 // Step 3: now allocate fixed array and JSObject to fill the whole new space. | 920 // Step 3: now allocate fixed array and JSObject to fill the whole new space. |
| 920 int to_fill = *limit_addr - *top_addr - object_size; | 921 int to_fill = static_cast<int>(*limit_addr - *top_addr - object_size); |
| 921 int fixed_array_len = LenFromSize(to_fill); | 922 int fixed_array_len = LenFromSize(to_fill); |
| 922 CHECK(fixed_array_len < FixedArray::kMaxLength); | 923 CHECK(fixed_array_len < FixedArray::kMaxLength); |
| 923 | 924 |
| 924 CHECK(!Heap::always_allocate()); | 925 CHECK(!Heap::always_allocate()); |
| 925 Object* array = Heap::AllocateFixedArray(fixed_array_len); | 926 Object* array = Heap::AllocateFixedArray(fixed_array_len); |
| 926 CHECK(!array->IsFailure()); | 927 CHECK(!array->IsFailure()); |
| 927 CHECK(new_space->Contains(array)); | 928 CHECK(new_space->Contains(array)); |
| 928 | 929 |
| 929 Object* object = Heap::AllocateJSObjectFromMap(*my_map); | 930 Object* object = Heap::AllocateJSObjectFromMap(*my_map); |
| 930 CHECK(!object->IsFailure()); | 931 CHECK(!object->IsFailure()); |
| 931 CHECK(new_space->Contains(object)); | 932 CHECK(new_space->Contains(object)); |
| 932 JSObject* jsobject = JSObject::cast(object); | 933 JSObject* jsobject = JSObject::cast(object); |
| 933 CHECK_EQ(0, jsobject->elements()->length()); | 934 CHECK_EQ(0, jsobject->elements()->length()); |
| 934 CHECK_EQ(0, jsobject->properties()->length()); | 935 CHECK_EQ(0, jsobject->properties()->length()); |
| 935 // Create a reference to object in new space in jsobject. | 936 // Create a reference to object in new space in jsobject. |
| 936 jsobject->FastPropertyAtPut(-1, array); | 937 jsobject->FastPropertyAtPut(-1, array); |
| 937 | 938 |
| 938 CHECK_EQ(0L, (*limit_addr - *top_addr)); | 939 CHECK_EQ(0, static_cast<int>(*limit_addr - *top_addr)); |
| 939 | 940 |
| 940 // Step 4: clone jsobject, but force always allocate first to create a clone | 941 // Step 4: clone jsobject, but force always allocate first to create a clone |
| 941 // in old pointer space. | 942 // in old pointer space. |
| 942 Address old_pointer_space_top = Heap::old_pointer_space()->top(); | 943 Address old_pointer_space_top = Heap::old_pointer_space()->top(); |
| 943 AlwaysAllocateScope aa_scope; | 944 AlwaysAllocateScope aa_scope; |
| 944 Object* clone_obj = Heap::CopyJSObject(jsobject); | 945 Object* clone_obj = Heap::CopyJSObject(jsobject); |
| 945 CHECK(!object->IsFailure()); | 946 CHECK(!object->IsFailure()); |
| 946 JSObject* clone = JSObject::cast(clone_obj); | 947 JSObject* clone = JSObject::cast(clone_obj); |
| 947 if (clone->address() != old_pointer_space_top) { | 948 if (clone->address() != old_pointer_space_top) { |
| 948 // Alas, got allocated from free list, we cannot do checks. | 949 // Alas, got allocated from free list, we cannot do checks. |
| 949 return; | 950 return; |
| 950 } | 951 } |
| 951 CHECK(Heap::old_pointer_space()->Contains(clone->address())); | 952 CHECK(Heap::old_pointer_space()->Contains(clone->address())); |
| 952 | 953 |
| 953 // Step 5: verify validity of remembered set. | 954 // Step 5: verify validity of remembered set. |
| 954 Address clone_addr = clone->address(); | 955 Address clone_addr = clone->address(); |
| 955 Page* page = Page::FromAddress(clone_addr); | 956 Page* page = Page::FromAddress(clone_addr); |
| 956 // Check that remembered set tracks a reference from inobject property 1. | 957 // Check that remembered set tracks a reference from inobject property 1. |
| 957 CHECK(page->IsRSetSet(clone_addr, object_size - kPointerSize)); | 958 CHECK(page->IsRSetSet(clone_addr, object_size - kPointerSize)); |
| 958 // Probe several addresses after the object. | 959 // Probe several addresses after the object. |
| 959 for (int i = 0; i < 7; i++) { | 960 for (int i = 0; i < 7; i++) { |
| 960 int offset = object_size + i * kPointerSize; | 961 int offset = object_size + i * kPointerSize; |
| 961 if (clone_addr + offset >= page->ObjectAreaEnd()) { | 962 if (clone_addr + offset >= page->ObjectAreaEnd()) { |
| 962 break; | 963 break; |
| 963 } | 964 } |
| 964 CHECK(!page->IsRSetSet(clone_addr, offset)); | 965 CHECK(!page->IsRSetSet(clone_addr, offset)); |
| 965 } | 966 } |
| 966 } | 967 } |
| OLD | NEW |