| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // TODO(gc) you can no longer allocate pages like this. Details are hidden. | 64 // TODO(gc) you can no longer allocate pages like this. Details are hidden. |
| 65 #if 0 | 65 #if 0 |
| 66 TEST(Page) { | 66 TEST(Page) { |
| 67 byte* mem = NewArray<byte>(2*Page::kPageSize); | 67 byte* mem = NewArray<byte>(2*Page::kPageSize); |
| 68 CHECK(mem != NULL); | 68 CHECK(mem != NULL); |
| 69 | 69 |
| 70 Address start = reinterpret_cast<Address>(mem); | 70 Address start = reinterpret_cast<Address>(mem); |
| 71 Address page_start = RoundUp(start, Page::kPageSize); | 71 Address page_start = RoundUp(start, Page::kPageSize); |
| 72 | 72 |
| 73 Page* p = Page::FromAddress(page_start); | 73 Page* p = Page::FromAddress(page_start); |
| 74 // Initialized Page has heap pointer, normally set by memory_allocator. |
| 75 p->heap_ = HEAP; |
| 74 CHECK(p->address() == page_start); | 76 CHECK(p->address() == page_start); |
| 75 CHECK(p->is_valid()); | 77 CHECK(p->is_valid()); |
| 76 | 78 |
| 77 p->opaque_header = 0; | 79 p->opaque_header = 0; |
| 78 p->SetIsLargeObjectPage(false); | 80 p->SetIsLargeObjectPage(false); |
| 79 CHECK(!p->next_page()->is_valid()); | 81 CHECK(!p->next_page()->is_valid()); |
| 80 | 82 |
| 81 CHECK(p->ObjectAreaStart() == page_start + Page::kObjectStartOffset); | 83 CHECK(p->ObjectAreaStart() == page_start + Page::kObjectStartOffset); |
| 82 CHECK(p->ObjectAreaEnd() == page_start + Page::kPageSize); | 84 CHECK(p->ObjectAreaEnd() == page_start + Page::kPageSize); |
| 83 | 85 |
| 84 CHECK(p->Offset(page_start + Page::kObjectStartOffset) == | 86 CHECK(p->Offset(page_start + Page::kObjectStartOffset) == |
| 85 Page::kObjectStartOffset); | 87 Page::kObjectStartOffset); |
| 86 CHECK(p->Offset(page_start + Page::kPageSize) == Page::kPageSize); | 88 CHECK(p->Offset(page_start + Page::kPageSize) == Page::kPageSize); |
| 87 | 89 |
| 88 CHECK(p->OffsetToAddress(Page::kObjectStartOffset) == p->ObjectAreaStart()); | 90 CHECK(p->OffsetToAddress(Page::kObjectStartOffset) == p->ObjectAreaStart()); |
| 89 CHECK(p->OffsetToAddress(Page::kPageSize) == p->ObjectAreaEnd()); | 91 CHECK(p->OffsetToAddress(Page::kPageSize) == p->ObjectAreaEnd()); |
| 90 | 92 |
| 91 // test region marking | 93 // test region marking |
| 92 VerifyRegionMarking(page_start); | 94 VerifyRegionMarking(page_start); |
| 93 | 95 |
| 94 DeleteArray(mem); | 96 DeleteArray(mem); |
| 95 } | 97 } |
| 96 #endif | 98 #endif |
| 97 | 99 |
| 98 | 100 |
| 99 TEST(MemoryAllocator) { | 101 TEST(MemoryAllocator) { |
| 100 CHECK(Heap::ConfigureHeapDefault()); | 102 OS::Setup(); |
| 101 CHECK(MemoryAllocator::Setup(Heap::MaxReserved(), Heap::MaxExecutableSize())); | 103 Isolate* isolate = Isolate::Current(); |
| 104 CHECK(HEAP->ConfigureHeapDefault()); |
| 105 CHECK(isolate->memory_allocator()->Setup(HEAP->MaxReserved(), |
| 106 HEAP->MaxExecutableSize())); |
| 102 | 107 |
| 103 int total_pages = 0; | 108 int total_pages = 0; |
| 104 OldSpace faked_space(Heap::MaxReserved(), OLD_POINTER_SPACE, NOT_EXECUTABLE); | 109 OldSpace faked_space(HEAP, |
| 110 HEAP->MaxReserved(), |
| 111 OLD_POINTER_SPACE, |
| 112 NOT_EXECUTABLE); |
| 105 Page* first_page = | 113 Page* first_page = |
| 106 MemoryAllocator::AllocatePage(&faked_space, NOT_EXECUTABLE); | 114 isolate->memory_allocator()->AllocatePage(&faked_space, NOT_EXECUTABLE); |
| 107 first_page->InsertAfter(faked_space.anchor()->prev_page()); | 115 first_page->InsertAfter(faked_space.anchor()->prev_page()); |
| 108 CHECK(first_page->is_valid()); | 116 CHECK(first_page->is_valid()); |
| 109 CHECK(first_page->next_page() == faked_space.anchor()); | 117 CHECK(first_page->next_page() == faked_space.anchor()); |
| 110 total_pages++; | 118 total_pages++; |
| 111 | 119 |
| 112 for (Page* p = first_page; p != faked_space.anchor(); p = p->next_page()) { | 120 for (Page* p = first_page; p != faked_space.anchor(); p = p->next_page()) { |
| 113 CHECK(p->owner() == &faked_space); | 121 CHECK(p->owner() == &faked_space); |
| 114 } | 122 } |
| 115 | 123 |
| 116 // Again, we should get n or n - 1 pages. | 124 // Again, we should get n or n - 1 pages. |
| 117 Page* other = | 125 Page* other = |
| 118 MemoryAllocator::AllocatePage(&faked_space, NOT_EXECUTABLE); | 126 isolate->memory_allocator()->AllocatePage(&faked_space, NOT_EXECUTABLE); |
| 119 CHECK(other->is_valid()); | 127 CHECK(other->is_valid()); |
| 120 total_pages++; | 128 total_pages++; |
| 121 other->InsertAfter(first_page); | 129 other->InsertAfter(first_page); |
| 122 int page_count = 0; | 130 int page_count = 0; |
| 123 for (Page* p = first_page; p != faked_space.anchor(); p = p->next_page()) { | 131 for (Page* p = first_page; p != faked_space.anchor(); p = p->next_page()) { |
| 124 CHECK(p->owner() == &faked_space); | 132 CHECK(p->owner() == &faked_space); |
| 125 page_count++; | 133 page_count++; |
| 126 } | 134 } |
| 127 CHECK(total_pages == page_count); | 135 CHECK(total_pages == page_count); |
| 128 | 136 |
| 129 Page* second_page = first_page->next_page(); | 137 Page* second_page = first_page->next_page(); |
| 130 CHECK(second_page->is_valid()); | 138 CHECK(second_page->is_valid()); |
| 131 MemoryAllocator::Free(first_page); | 139 isolate->memory_allocator()->Free(first_page); |
| 132 MemoryAllocator::Free(second_page); | 140 isolate->memory_allocator()->Free(second_page); |
| 133 MemoryAllocator::TearDown(); | 141 isolate->memory_allocator()->TearDown(); |
| 134 } | 142 } |
| 135 | 143 |
| 136 | 144 |
| 137 TEST(NewSpace) { | 145 TEST(NewSpace) { |
| 138 CHECK(Heap::ConfigureHeapDefault()); | 146 OS::Setup(); |
| 139 CHECK(MemoryAllocator::Setup(Heap::MaxReserved(), Heap::MaxExecutableSize())); | 147 CHECK(HEAP->ConfigureHeapDefault()); |
| 148 CHECK(Isolate::Current()->memory_allocator()->Setup( |
| 149 HEAP->MaxReserved(), HEAP->MaxExecutableSize())); |
| 140 | 150 |
| 141 NewSpace new_space; | 151 NewSpace new_space(HEAP); |
| 142 | 152 |
| 143 CHECK(new_space.Setup(Heap::ReservedSemiSpaceSize())); | 153 CHECK(new_space.Setup(HEAP->ReservedSemiSpaceSize())); |
| 144 CHECK(new_space.HasBeenSetup()); | 154 CHECK(new_space.HasBeenSetup()); |
| 145 | 155 |
| 146 while (new_space.Available() >= Page::kMaxHeapObjectSize) { | 156 while (new_space.Available() >= Page::kMaxHeapObjectSize) { |
| 147 Object* obj = | 157 Object* obj = |
| 148 new_space.AllocateRaw(Page::kMaxHeapObjectSize)->ToObjectUnchecked(); | 158 new_space.AllocateRaw(Page::kMaxHeapObjectSize)->ToObjectUnchecked(); |
| 149 CHECK(new_space.Contains(HeapObject::cast(obj))); | 159 CHECK(new_space.Contains(HeapObject::cast(obj))); |
| 150 } | 160 } |
| 151 | 161 |
| 152 new_space.TearDown(); | 162 new_space.TearDown(); |
| 153 MemoryAllocator::TearDown(); | 163 Isolate::Current()->memory_allocator()->TearDown(); |
| 154 } | 164 } |
| 155 | 165 |
| 156 | 166 |
| 157 TEST(OldSpace) { | 167 TEST(OldSpace) { |
| 158 CHECK(Heap::ConfigureHeapDefault()); | 168 OS::Setup(); |
| 159 CHECK(MemoryAllocator::Setup(Heap::MaxReserved(), Heap::MaxExecutableSize())); | 169 CHECK(HEAP->ConfigureHeapDefault()); |
| 170 CHECK(Isolate::Current()->memory_allocator()->Setup( |
| 171 HEAP->MaxReserved(), HEAP->MaxExecutableSize())); |
| 160 | 172 |
| 161 OldSpace* s = new OldSpace(Heap::MaxOldGenerationSize(), | 173 OldSpace* s = new OldSpace(HEAP, |
| 174 HEAP->MaxOldGenerationSize(), |
| 162 OLD_POINTER_SPACE, | 175 OLD_POINTER_SPACE, |
| 163 NOT_EXECUTABLE); | 176 NOT_EXECUTABLE); |
| 164 CHECK(s != NULL); | 177 CHECK(s != NULL); |
| 165 | 178 |
| 166 CHECK(s->Setup()); | 179 CHECK(s->Setup()); |
| 167 | 180 |
| 168 while (s->Available() > 0) { | 181 while (s->Available() > 0) { |
| 169 s->AllocateRaw(Page::kMaxHeapObjectSize)->ToObjectUnchecked(); | 182 s->AllocateRaw(Page::kMaxHeapObjectSize)->ToObjectUnchecked(); |
| 170 } | 183 } |
| 171 | 184 |
| 172 s->TearDown(); | 185 s->TearDown(); |
| 173 delete s; | 186 delete s; |
| 174 MemoryAllocator::TearDown(); | 187 Isolate::Current()->memory_allocator()->TearDown(); |
| 175 } | 188 } |
| 176 | 189 |
| 177 | 190 |
| 178 TEST(LargeObjectSpace) { | 191 TEST(LargeObjectSpace) { |
| 179 CHECK(Heap::Setup(false)); | 192 OS::Setup(); |
| 193 CHECK(HEAP->Setup(false)); |
| 180 | 194 |
| 181 LargeObjectSpace* lo = Heap::lo_space(); | 195 LargeObjectSpace* lo = HEAP->lo_space(); |
| 182 CHECK(lo != NULL); | 196 CHECK(lo != NULL); |
| 183 | 197 |
| 184 Map* faked_map = reinterpret_cast<Map*>(HeapObject::FromAddress(0)); | |
| 185 int lo_size = Page::kPageSize; | 198 int lo_size = Page::kPageSize; |
| 186 | 199 |
| 187 Object* obj = lo->AllocateRaw(lo_size)->ToObjectUnchecked(); | 200 Object* obj = lo->AllocateRaw(lo_size)->ToObjectUnchecked(); |
| 188 CHECK(obj->IsHeapObject()); | 201 CHECK(obj->IsHeapObject()); |
| 189 | 202 |
| 190 HeapObject* ho = HeapObject::cast(obj); | 203 HeapObject* ho = HeapObject::cast(obj); |
| 191 ho->set_map(faked_map); | |
| 192 | 204 |
| 193 CHECK(lo->Contains(HeapObject::cast(obj))); | 205 CHECK(lo->Contains(HeapObject::cast(obj))); |
| 194 | 206 |
| 195 CHECK(lo->FindObject(ho->address()) == obj); | 207 CHECK(lo->FindObject(ho->address()) == obj); |
| 196 | 208 |
| 197 CHECK(lo->Contains(ho)); | 209 CHECK(lo->Contains(ho)); |
| 198 | 210 |
| 199 while (true) { | 211 while (true) { |
| 200 intptr_t available = lo->Available(); | 212 intptr_t available = lo->Available(); |
| 201 { MaybeObject* maybe_obj = lo->AllocateRaw(lo_size); | 213 { MaybeObject* maybe_obj = lo->AllocateRaw(lo_size); |
| 202 if (!maybe_obj->ToObject(&obj)) break; | 214 if (!maybe_obj->ToObject(&obj)) break; |
| 203 } | 215 } |
| 204 HeapObject::cast(obj)->set_map(faked_map); | |
| 205 CHECK(lo->Available() < available); | 216 CHECK(lo->Available() < available); |
| 206 }; | 217 }; |
| 207 | 218 |
| 208 CHECK(!lo->IsEmpty()); | 219 CHECK(!lo->IsEmpty()); |
| 209 | 220 |
| 210 CHECK(lo->AllocateRaw(lo_size)->IsFailure()); | 221 CHECK(lo->AllocateRaw(lo_size)->IsFailure()); |
| 211 | 222 |
| 212 Heap::TearDown(); | 223 HEAP->TearDown(); |
| 213 } | 224 } |
| OLD | NEW |