| 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 // 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 97 |
| 98 | 98 |
| 99 TEST(MemoryAllocator) { | 99 TEST(MemoryAllocator) { |
| 100 CHECK(Heap::ConfigureHeapDefault()); | 100 CHECK(Heap::ConfigureHeapDefault()); |
| 101 CHECK(MemoryAllocator::Setup(Heap::MaxReserved(), Heap::MaxExecutableSize())); | 101 CHECK(MemoryAllocator::Setup(Heap::MaxReserved(), Heap::MaxExecutableSize())); |
| 102 | 102 |
| 103 int total_pages = 0; | 103 int total_pages = 0; |
| 104 OldSpace faked_space(Heap::MaxReserved(), OLD_POINTER_SPACE, NOT_EXECUTABLE); | 104 OldSpace faked_space(Heap::MaxReserved(), OLD_POINTER_SPACE, NOT_EXECUTABLE); |
| 105 Page* first_page = | 105 Page* first_page = |
| 106 MemoryAllocator::AllocatePage(&faked_space, NOT_EXECUTABLE); | 106 MemoryAllocator::AllocatePage(&faked_space, NOT_EXECUTABLE); |
| 107 first_page->InsertAfter(faked_space.anchor()->prev_page()); |
| 107 CHECK(first_page->is_valid()); | 108 CHECK(first_page->is_valid()); |
| 108 CHECK(!first_page->next_page()->is_valid()); | 109 CHECK(first_page->next_page() == faked_space.anchor()); |
| 109 total_pages++; | 110 total_pages++; |
| 110 | 111 |
| 111 Page* last_page = first_page; | 112 for (Page* p = first_page; p != faked_space.anchor(); p = p->next_page()) { |
| 112 for (Page* p = first_page; p->is_valid(); p = p->next_page()) { | |
| 113 CHECK(p->owner() == &faked_space); | 113 CHECK(p->owner() == &faked_space); |
| 114 last_page = p; | |
| 115 } | 114 } |
| 116 | 115 |
| 117 CHECK(last_page == first_page); | |
| 118 | |
| 119 // Again, we should get n or n - 1 pages. | 116 // Again, we should get n or n - 1 pages. |
| 120 Page* other = | 117 Page* other = |
| 121 MemoryAllocator::AllocatePage(&faked_space, NOT_EXECUTABLE); | 118 MemoryAllocator::AllocatePage(&faked_space, NOT_EXECUTABLE); |
| 122 CHECK(other->is_valid()); | 119 CHECK(other->is_valid()); |
| 123 total_pages++; | 120 total_pages++; |
| 124 last_page->set_next_page(other); | 121 other->InsertAfter(first_page); |
| 125 int page_count = 0; | 122 int page_count = 0; |
| 126 for (Page* p = first_page; p->is_valid(); p = p->next_page()) { | 123 for (Page* p = first_page; p != faked_space.anchor(); p = p->next_page()) { |
| 127 CHECK(p->owner() == &faked_space); | 124 CHECK(p->owner() == &faked_space); |
| 128 page_count++; | 125 page_count++; |
| 129 } | 126 } |
| 130 CHECK(total_pages == page_count); | 127 CHECK(total_pages == page_count); |
| 131 | 128 |
| 132 Page* second_page = first_page->next_page(); | 129 Page* second_page = first_page->next_page(); |
| 133 CHECK(second_page->is_valid()); | 130 CHECK(second_page->is_valid()); |
| 134 MemoryAllocator::Free(first_page); | 131 MemoryAllocator::Free(first_page); |
| 135 MemoryAllocator::Free(second_page); | 132 MemoryAllocator::Free(second_page); |
| 136 MemoryAllocator::TearDown(); | 133 MemoryAllocator::TearDown(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 HeapObject::cast(obj)->set_map(faked_map); | 204 HeapObject::cast(obj)->set_map(faked_map); |
| 208 CHECK(lo->Available() < available); | 205 CHECK(lo->Available() < available); |
| 209 }; | 206 }; |
| 210 | 207 |
| 211 CHECK(!lo->IsEmpty()); | 208 CHECK(!lo->IsEmpty()); |
| 212 | 209 |
| 213 CHECK(lo->AllocateRaw(lo_size)->IsFailure()); | 210 CHECK(lo->AllocateRaw(lo_size)->IsFailure()); |
| 214 | 211 |
| 215 Heap::TearDown(); | 212 Heap::TearDown(); |
| 216 } | 213 } |
| OLD | NEW |