OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/base/platform/platform.h" | 7 #include "src/base/platform/platform.h" |
8 #include "src/full-codegen.h" | 8 #include "src/full-codegen.h" |
9 #include "src/heap/mark-compact.h" | 9 #include "src/heap/mark-compact.h" |
10 #include "src/macro-assembler.h" | 10 #include "src/macro-assembler.h" |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 current_allocation_block_index_ = 0; | 186 current_allocation_block_index_ = 0; |
187 // Code range is full or too fragmented. | 187 // Code range is full or too fragmented. |
188 return false; | 188 return false; |
189 } | 189 } |
190 | 190 |
191 | 191 |
192 Address CodeRange::AllocateRawMemory(const size_t requested_size, | 192 Address CodeRange::AllocateRawMemory(const size_t requested_size, |
193 const size_t commit_size, | 193 const size_t commit_size, |
194 size_t* allocated) { | 194 size_t* allocated) { |
195 DCHECK(commit_size <= requested_size); | 195 DCHECK(commit_size <= requested_size); |
196 DCHECK(current_allocation_block_index_ < allocation_list_.length()); | 196 DCHECK(allocation_list_.length() == 0 || |
197 if (requested_size > allocation_list_[current_allocation_block_index_].size) { | 197 current_allocation_block_index_ < allocation_list_.length()); |
| 198 if (allocation_list_.length() == 0 || |
| 199 requested_size > allocation_list_[current_allocation_block_index_].size) { |
198 // Find an allocation block large enough. | 200 // Find an allocation block large enough. |
199 if (!GetNextAllocationBlock(requested_size)) return NULL; | 201 if (!GetNextAllocationBlock(requested_size)) return NULL; |
200 } | 202 } |
201 // Commit the requested memory at the start of the current allocation block. | 203 // Commit the requested memory at the start of the current allocation block. |
202 size_t aligned_requested = RoundUp(requested_size, MemoryChunk::kAlignment); | 204 size_t aligned_requested = RoundUp(requested_size, MemoryChunk::kAlignment); |
203 FreeBlock current = allocation_list_[current_allocation_block_index_]; | 205 FreeBlock current = allocation_list_[current_allocation_block_index_]; |
204 if (aligned_requested >= (current.size - Page::kPageSize)) { | 206 if (aligned_requested >= (current.size - Page::kPageSize)) { |
205 // Don't leave a small free block, useless for a large object or chunk. | 207 // Don't leave a small free block, useless for a large object or chunk. |
206 *allocated = current.size; | 208 *allocated = current.size; |
207 } else { | 209 } else { |
208 *allocated = aligned_requested; | 210 *allocated = aligned_requested; |
209 } | 211 } |
210 DCHECK(*allocated <= current.size); | 212 DCHECK(*allocated <= current.size); |
211 DCHECK(IsAddressAligned(current.start, MemoryChunk::kAlignment)); | 213 DCHECK(IsAddressAligned(current.start, MemoryChunk::kAlignment)); |
212 if (!isolate_->memory_allocator()->CommitExecutableMemory( | 214 if (!isolate_->memory_allocator()->CommitExecutableMemory( |
213 code_range_, current.start, commit_size, *allocated)) { | 215 code_range_, current.start, commit_size, *allocated)) { |
214 *allocated = 0; | 216 *allocated = 0; |
215 return NULL; | 217 return NULL; |
216 } | 218 } |
217 allocation_list_[current_allocation_block_index_].start += *allocated; | 219 allocation_list_[current_allocation_block_index_].start += *allocated; |
218 allocation_list_[current_allocation_block_index_].size -= *allocated; | 220 allocation_list_[current_allocation_block_index_].size -= *allocated; |
219 if (*allocated == current.size) { | 221 if (*allocated == current.size) { |
220 // This block is used up, get the next one. | 222 // This block is used up, get the next one. |
221 if (!GetNextAllocationBlock(0)) return NULL; | 223 GetNextAllocationBlock(0); |
222 } | 224 } |
223 return current.start; | 225 return current.start; |
224 } | 226 } |
225 | 227 |
226 | 228 |
227 bool CodeRange::CommitRawMemory(Address start, size_t length) { | 229 bool CodeRange::CommitRawMemory(Address start, size_t length) { |
228 return isolate_->memory_allocator()->CommitMemory(start, length, EXECUTABLE); | 230 return isolate_->memory_allocator()->CommitMemory(start, length, EXECUTABLE); |
229 } | 231 } |
230 | 232 |
231 | 233 |
(...skipping 2867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3099 object->ShortPrint(); | 3101 object->ShortPrint(); |
3100 PrintF("\n"); | 3102 PrintF("\n"); |
3101 } | 3103 } |
3102 printf(" --------------------------------------\n"); | 3104 printf(" --------------------------------------\n"); |
3103 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3105 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
3104 } | 3106 } |
3105 | 3107 |
3106 #endif // DEBUG | 3108 #endif // DEBUG |
3107 } | 3109 } |
3108 } // namespace v8::internal | 3110 } // namespace v8::internal |
OLD | NEW |