blob: 515a2027693c7d46954733df88e552dd225ef0ea [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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
3// found in the LICENSE file.
4
5#ifndef V8_HEAP_SPACES_INL_H_
6#define V8_HEAP_SPACES_INL_H_
7
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008#include "src/heap/incremental-marking.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009#include "src/heap/spaces.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010#include "src/isolate.h"
11#include "src/msan.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000012#include "src/profiler/heap-profiler.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000013#include "src/v8memory.h"
14
15namespace v8 {
16namespace internal {
17
18
19// -----------------------------------------------------------------------------
20// Bitmap
21
22void Bitmap::Clear(MemoryChunk* chunk) {
23 Bitmap* bitmap = chunk->markbits();
24 for (int i = 0; i < bitmap->CellsCount(); i++) bitmap->cells()[i] = 0;
25 chunk->ResetLiveBytes();
26}
27
28
29// -----------------------------------------------------------------------------
30// PageIterator
31
Ben Murdochb8a8cc12014-11-26 15:28:44 +000032PageIterator::PageIterator(PagedSpace* space)
33 : space_(space),
34 prev_page_(&space->anchor_),
35 next_page_(prev_page_->next_page()) {}
36
37
38bool PageIterator::has_next() { return next_page_ != &space_->anchor_; }
39
40
41Page* PageIterator::next() {
42 DCHECK(has_next());
43 prev_page_ = next_page_;
44 next_page_ = next_page_->next_page();
45 return prev_page_;
46}
47
48
49// -----------------------------------------------------------------------------
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000050// SemiSpaceIterator
Ben Murdochb8a8cc12014-11-26 15:28:44 +000051
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000052HeapObject* SemiSpaceIterator::Next() {
53 while (current_ != limit_) {
54 if (NewSpacePage::IsAtEnd(current_)) {
55 NewSpacePage* page = NewSpacePage::FromLimit(current_);
56 page = page->next_page();
57 DCHECK(!page->is_anchor());
58 current_ = page->area_start();
59 if (current_ == limit_) return nullptr;
60 }
61 HeapObject* object = HeapObject::FromAddress(current_);
62 current_ += object->Size();
63 if (!object->IsFiller()) {
64 return object;
65 }
66 }
67 return nullptr;
68}
69
70
71HeapObject* SemiSpaceIterator::next_object() { return Next(); }
72
73
74// -----------------------------------------------------------------------------
75// NewSpacePageIterator
Ben Murdochb8a8cc12014-11-26 15:28:44 +000076
77NewSpacePageIterator::NewSpacePageIterator(NewSpace* space)
78 : prev_page_(NewSpacePage::FromAddress(space->ToSpaceStart())->prev_page()),
79 next_page_(NewSpacePage::FromAddress(space->ToSpaceStart())),
80 last_page_(NewSpacePage::FromLimit(space->ToSpaceEnd())) {}
81
82NewSpacePageIterator::NewSpacePageIterator(SemiSpace* space)
83 : prev_page_(space->anchor()),
84 next_page_(prev_page_->next_page()),
85 last_page_(prev_page_->prev_page()) {}
86
87NewSpacePageIterator::NewSpacePageIterator(Address start, Address limit)
88 : prev_page_(NewSpacePage::FromAddress(start)->prev_page()),
89 next_page_(NewSpacePage::FromAddress(start)),
90 last_page_(NewSpacePage::FromLimit(limit)) {
91 SemiSpace::AssertValidRange(start, limit);
92}
93
94
95bool NewSpacePageIterator::has_next() { return prev_page_ != last_page_; }
96
97
98NewSpacePage* NewSpacePageIterator::next() {
99 DCHECK(has_next());
100 prev_page_ = next_page_;
101 next_page_ = next_page_->next_page();
102 return prev_page_;
103}
104
105
106// -----------------------------------------------------------------------------
107// HeapObjectIterator
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000108
109HeapObject* HeapObjectIterator::Next() {
110 do {
111 HeapObject* next_obj = FromCurrentPage();
112 if (next_obj != NULL) return next_obj;
113 } while (AdvanceToNextPage());
114 return NULL;
115}
116
117
118HeapObject* HeapObjectIterator::next_object() { return Next(); }
119
120
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000121HeapObject* HeapObjectIterator::FromCurrentPage() {
122 while (cur_addr_ != cur_end_) {
123 if (cur_addr_ == space_->top() && cur_addr_ != space_->limit()) {
124 cur_addr_ = space_->limit();
125 continue;
126 }
127 HeapObject* obj = HeapObject::FromAddress(cur_addr_);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000128 int obj_size = obj->Size();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000129 cur_addr_ += obj_size;
130 DCHECK(cur_addr_ <= cur_end_);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000131 // TODO(hpayer): Remove the debugging code.
132 if (cur_addr_ > cur_end_) {
133 space_->heap()->isolate()->PushStackTraceAndDie(0xaaaaaaaa, obj, NULL,
134 obj_size);
135 }
136
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000137 if (!obj->IsFiller()) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000138 if (obj->IsCode()) {
139 DCHECK_EQ(space_, space_->heap()->code_space());
140 DCHECK_CODEOBJECT_SIZE(obj_size, space_);
141 } else {
142 DCHECK_OBJECT_SIZE(obj_size);
143 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000144 return obj;
145 }
146 }
147 return NULL;
148}
149
150
151// -----------------------------------------------------------------------------
152// MemoryAllocator
153
154#ifdef ENABLE_HEAP_PROTECTION
155
156void MemoryAllocator::Protect(Address start, size_t size) {
157 base::OS::Protect(start, size);
158}
159
160
161void MemoryAllocator::Unprotect(Address start, size_t size,
162 Executability executable) {
163 base::OS::Unprotect(start, size, executable);
164}
165
166
167void MemoryAllocator::ProtectChunkFromPage(Page* page) {
168 int id = GetChunkId(page);
169 base::OS::Protect(chunks_[id].address(), chunks_[id].size());
170}
171
172
173void MemoryAllocator::UnprotectChunkFromPage(Page* page) {
174 int id = GetChunkId(page);
175 base::OS::Unprotect(chunks_[id].address(), chunks_[id].size(),
176 chunks_[id].owner()->executable() == EXECUTABLE);
177}
178
179#endif
180
Ben Murdoch097c5b22016-05-18 11:27:45 +0100181// -----------------------------------------------------------------------------
182// SemiSpace
183
184bool SemiSpace::Contains(HeapObject* o) {
185 return id_ == kToSpace
186 ? MemoryChunk::FromAddress(o->address())->InToSpace()
187 : MemoryChunk::FromAddress(o->address())->InFromSpace();
188}
189
190bool SemiSpace::Contains(Object* o) {
191 return o->IsHeapObject() && Contains(HeapObject::cast(o));
192}
193
194bool SemiSpace::ContainsSlow(Address a) {
195 NewSpacePageIterator it(this);
196 while (it.has_next()) {
197 if (it.next() == MemoryChunk::FromAddress(a)) return true;
198 }
199 return false;
200}
201
202// --------------------------------------------------------------------------
203// NewSpace
204
205bool NewSpace::Contains(HeapObject* o) {
206 return MemoryChunk::FromAddress(o->address())->InNewSpace();
207}
208
209bool NewSpace::Contains(Object* o) {
210 return o->IsHeapObject() && Contains(HeapObject::cast(o));
211}
212
213bool NewSpace::ContainsSlow(Address a) {
214 return from_space_.ContainsSlow(a) || to_space_.ContainsSlow(a);
215}
216
217bool NewSpace::ToSpaceContainsSlow(Address a) {
218 return to_space_.ContainsSlow(a);
219}
220
221bool NewSpace::FromSpaceContainsSlow(Address a) {
222 return from_space_.ContainsSlow(a);
223}
224
225bool NewSpace::ToSpaceContains(Object* o) { return to_space_.Contains(o); }
226bool NewSpace::FromSpaceContains(Object* o) { return from_space_.Contains(o); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000227
228// --------------------------------------------------------------------------
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000229// AllocationResult
230
231AllocationSpace AllocationResult::RetrySpace() {
232 DCHECK(IsRetry());
233 return static_cast<AllocationSpace>(Smi::cast(object_)->value());
234}
235
236
237// --------------------------------------------------------------------------
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000238// PagedSpace
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000239
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000240Page* Page::Initialize(Heap* heap, MemoryChunk* chunk, Executability executable,
241 PagedSpace* owner) {
242 Page* page = reinterpret_cast<Page*>(chunk);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000243 page->mutex_ = new base::Mutex();
244 DCHECK(page->area_size() <= kAllocatableMemory);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000245 DCHECK(chunk->owner() == owner);
246 owner->IncreaseCapacity(page->area_size());
247 owner->Free(page->area_start(), page->area_size());
248
249 heap->incremental_marking()->SetOldSpacePageFlags(chunk);
250
251 return page;
252}
253
Ben Murdoch097c5b22016-05-18 11:27:45 +0100254void MemoryChunk::IncrementLiveBytesFromGC(HeapObject* object, int by) {
255 MemoryChunk::FromAddress(object->address())->IncrementLiveBytes(by);
256}
257
258void MemoryChunk::ResetLiveBytes() {
259 if (FLAG_trace_live_bytes) {
260 PrintIsolate(heap()->isolate(), "live-bytes: reset page=%p %d->0\n", this,
261 live_byte_count_);
262 }
263 live_byte_count_ = 0;
264}
265
266void MemoryChunk::IncrementLiveBytes(int by) {
267 if (FLAG_trace_live_bytes) {
268 PrintIsolate(heap()->isolate(),
269 "live-bytes: update page=%p delta=%d %d->%d\n", this, by,
270 live_byte_count_, live_byte_count_ + by);
271 }
272 live_byte_count_ += by;
273 DCHECK_GE(live_byte_count_, 0);
274 DCHECK_LE(static_cast<size_t>(live_byte_count_), size_);
275}
276
277void MemoryChunk::IncrementLiveBytesFromMutator(HeapObject* object, int by) {
278 MemoryChunk* chunk = MemoryChunk::FromAddress(object->address());
279 if (!chunk->InNewSpace() && !static_cast<Page*>(chunk)->SweepingDone()) {
280 static_cast<PagedSpace*>(chunk->owner())->Allocate(by);
281 }
282 chunk->IncrementLiveBytes(by);
283}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000284
285bool PagedSpace::Contains(Address addr) {
286 Page* p = Page::FromAddress(addr);
287 if (!p->is_valid()) return false;
288 return p->owner() == this;
289}
290
Ben Murdoch097c5b22016-05-18 11:27:45 +0100291bool PagedSpace::Contains(Object* o) {
292 if (!o->IsHeapObject()) return false;
293 Page* p = Page::FromAddress(HeapObject::cast(o)->address());
294 if (!p->is_valid()) return false;
295 return p->owner() == this;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000296}
297
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000298MemoryChunk* MemoryChunk::FromAnyPointerAddress(Heap* heap, Address addr) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100299 MemoryChunk* chunk = MemoryChunk::FromAddress(addr);
300 uintptr_t offset = addr - chunk->address();
301 if (offset < MemoryChunk::kHeaderSize || !chunk->HasPageHeader()) {
302 chunk = heap->lo_space()->FindPage(addr);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000303 }
Ben Murdoch097c5b22016-05-18 11:27:45 +0100304 return chunk;
305}
306
307Page* Page::FromAnyPointerAddress(Heap* heap, Address addr) {
308 return static_cast<Page*>(MemoryChunk::FromAnyPointerAddress(heap, addr));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000309}
310
311
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000312PointerChunkIterator::PointerChunkIterator(Heap* heap)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000313 : state_(kOldSpaceState),
314 old_iterator_(heap->old_space()),
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000315 map_iterator_(heap->map_space()),
316 lo_iterator_(heap->lo_space()) {}
317
318
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000319MemoryChunk* PointerChunkIterator::next() {
320 switch (state_) {
321 case kOldSpaceState: {
322 if (old_iterator_.has_next()) {
323 return old_iterator_.next();
324 }
325 state_ = kMapState;
326 // Fall through.
327 }
328 case kMapState: {
329 if (map_iterator_.has_next()) {
330 return map_iterator_.next();
331 }
332 state_ = kLargeObjectState;
333 // Fall through.
334 }
335 case kLargeObjectState: {
336 HeapObject* heap_object;
337 do {
338 heap_object = lo_iterator_.Next();
339 if (heap_object == NULL) {
340 state_ = kFinishedState;
341 return NULL;
342 }
343 // Fixed arrays are the only pointer-containing objects in large
344 // object space.
345 } while (!heap_object->IsFixedArray());
346 MemoryChunk* answer = MemoryChunk::FromAddress(heap_object->address());
347 return answer;
348 }
349 case kFinishedState:
350 return NULL;
351 default:
352 break;
353 }
354 UNREACHABLE();
355 return NULL;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000356}
357
358
359void Page::set_next_page(Page* page) {
360 DCHECK(page->owner() == owner());
361 set_next_chunk(page);
362}
363
364
365void Page::set_prev_page(Page* page) {
366 DCHECK(page->owner() == owner());
367 set_prev_chunk(page);
368}
369
370
371// Try linear allocation in the page of alloc_info's allocation top. Does
372// not contain slow case logic (e.g. move to the next page or try free list
373// allocation) so it can be used by all the allocation functions and for all
374// the paged spaces.
375HeapObject* PagedSpace::AllocateLinearly(int size_in_bytes) {
376 Address current_top = allocation_info_.top();
377 Address new_top = current_top + size_in_bytes;
378 if (new_top > allocation_info_.limit()) return NULL;
379
380 allocation_info_.set_top(new_top);
381 return HeapObject::FromAddress(current_top);
382}
383
384
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000385AllocationResult LocalAllocationBuffer::AllocateRawAligned(
386 int size_in_bytes, AllocationAlignment alignment) {
387 Address current_top = allocation_info_.top();
388 int filler_size = Heap::GetFillToAlign(current_top, alignment);
389
390 Address new_top = current_top + filler_size + size_in_bytes;
391 if (new_top > allocation_info_.limit()) return AllocationResult::Retry();
392
393 allocation_info_.set_top(new_top);
394 if (filler_size > 0) {
395 return heap_->PrecedeWithFiller(HeapObject::FromAddress(current_top),
396 filler_size);
397 }
398
399 return AllocationResult(HeapObject::FromAddress(current_top));
400}
401
402
403HeapObject* PagedSpace::AllocateLinearlyAligned(int* size_in_bytes,
404 AllocationAlignment alignment) {
405 Address current_top = allocation_info_.top();
406 int filler_size = Heap::GetFillToAlign(current_top, alignment);
407
408 Address new_top = current_top + filler_size + *size_in_bytes;
409 if (new_top > allocation_info_.limit()) return NULL;
410
411 allocation_info_.set_top(new_top);
412 if (filler_size > 0) {
413 *size_in_bytes += filler_size;
414 return heap()->PrecedeWithFiller(HeapObject::FromAddress(current_top),
415 filler_size);
416 }
417
418 return HeapObject::FromAddress(current_top);
419}
420
421
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000422// Raw allocation.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000423AllocationResult PagedSpace::AllocateRawUnaligned(int size_in_bytes) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000424 HeapObject* object = AllocateLinearly(size_in_bytes);
425
426 if (object == NULL) {
427 object = free_list_.Allocate(size_in_bytes);
428 if (object == NULL) {
429 object = SlowAllocateRaw(size_in_bytes);
430 }
431 }
432
433 if (object != NULL) {
434 if (identity() == CODE_SPACE) {
435 SkipList::Update(object->address(), size_in_bytes);
436 }
437 MSAN_ALLOCATED_UNINITIALIZED_MEMORY(object->address(), size_in_bytes);
438 return object;
439 }
440
441 return AllocationResult::Retry(identity());
442}
443
444
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000445AllocationResult PagedSpace::AllocateRawUnalignedSynchronized(
446 int size_in_bytes) {
447 base::LockGuard<base::Mutex> lock_guard(&space_mutex_);
448 return AllocateRawUnaligned(size_in_bytes);
449}
450
451
452// Raw allocation.
453AllocationResult PagedSpace::AllocateRawAligned(int size_in_bytes,
454 AllocationAlignment alignment) {
455 DCHECK(identity() == OLD_SPACE);
456 int allocation_size = size_in_bytes;
457 HeapObject* object = AllocateLinearlyAligned(&allocation_size, alignment);
458
459 if (object == NULL) {
460 // We don't know exactly how much filler we need to align until space is
461 // allocated, so assume the worst case.
462 int filler_size = Heap::GetMaximumFillToAlign(alignment);
463 allocation_size += filler_size;
464 object = free_list_.Allocate(allocation_size);
465 if (object == NULL) {
466 object = SlowAllocateRaw(allocation_size);
467 }
468 if (object != NULL && filler_size != 0) {
469 object = heap()->AlignWithFiller(object, size_in_bytes, allocation_size,
470 alignment);
471 // Filler objects are initialized, so mark only the aligned object memory
472 // as uninitialized.
473 allocation_size = size_in_bytes;
474 }
475 }
476
477 if (object != NULL) {
478 MSAN_ALLOCATED_UNINITIALIZED_MEMORY(object->address(), allocation_size);
479 return object;
480 }
481
482 return AllocationResult::Retry(identity());
483}
484
485
486AllocationResult PagedSpace::AllocateRaw(int size_in_bytes,
487 AllocationAlignment alignment) {
488#ifdef V8_HOST_ARCH_32_BIT
Ben Murdoch097c5b22016-05-18 11:27:45 +0100489 AllocationResult result =
490 alignment == kDoubleAligned
491 ? AllocateRawAligned(size_in_bytes, kDoubleAligned)
492 : AllocateRawUnaligned(size_in_bytes);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000493#else
Ben Murdoch097c5b22016-05-18 11:27:45 +0100494 AllocationResult result = AllocateRawUnaligned(size_in_bytes);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000495#endif
Ben Murdoch097c5b22016-05-18 11:27:45 +0100496 HeapObject* heap_obj = nullptr;
497 if (!result.IsRetry() && result.To(&heap_obj)) {
498 AllocationStep(heap_obj->address(), size_in_bytes);
499 }
500 return result;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000501}
502
503
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000504// -----------------------------------------------------------------------------
505// NewSpace
506
507
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000508AllocationResult NewSpace::AllocateRawAligned(int size_in_bytes,
509 AllocationAlignment alignment) {
510 Address top = allocation_info_.top();
511 int filler_size = Heap::GetFillToAlign(top, alignment);
512 int aligned_size_in_bytes = size_in_bytes + filler_size;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000513
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000514 if (allocation_info_.limit() - top < aligned_size_in_bytes) {
515 // See if we can create room.
516 if (!EnsureAllocation(size_in_bytes, alignment)) {
517 return AllocationResult::Retry();
518 }
519
520 top = allocation_info_.top();
521 filler_size = Heap::GetFillToAlign(top, alignment);
522 aligned_size_in_bytes = size_in_bytes + filler_size;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000523 }
524
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000525 HeapObject* obj = HeapObject::FromAddress(top);
526 allocation_info_.set_top(top + aligned_size_in_bytes);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000527 DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_);
528
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000529 if (filler_size > 0) {
530 obj = heap()->PrecedeWithFiller(obj, filler_size);
531 }
532
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000533 MSAN_ALLOCATED_UNINITIALIZED_MEMORY(obj->address(), size_in_bytes);
534
535 return obj;
536}
537
538
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000539AllocationResult NewSpace::AllocateRawUnaligned(int size_in_bytes) {
540 Address top = allocation_info_.top();
541 if (allocation_info_.limit() < top + size_in_bytes) {
542 // See if we can create room.
543 if (!EnsureAllocation(size_in_bytes, kWordAligned)) {
544 return AllocationResult::Retry();
545 }
546
547 top = allocation_info_.top();
548 }
549
550 HeapObject* obj = HeapObject::FromAddress(top);
551 allocation_info_.set_top(top + size_in_bytes);
552 DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_);
553
554 MSAN_ALLOCATED_UNINITIALIZED_MEMORY(obj->address(), size_in_bytes);
555
556 return obj;
557}
558
559
560AllocationResult NewSpace::AllocateRaw(int size_in_bytes,
561 AllocationAlignment alignment) {
562#ifdef V8_HOST_ARCH_32_BIT
563 return alignment == kDoubleAligned
564 ? AllocateRawAligned(size_in_bytes, kDoubleAligned)
565 : AllocateRawUnaligned(size_in_bytes);
566#else
567 return AllocateRawUnaligned(size_in_bytes);
568#endif
569}
570
571
572MUST_USE_RESULT inline AllocationResult NewSpace::AllocateRawSynchronized(
573 int size_in_bytes, AllocationAlignment alignment) {
574 base::LockGuard<base::Mutex> guard(&mutex_);
575 return AllocateRaw(size_in_bytes, alignment);
576}
577
578
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000579LargePage* LargePage::Initialize(Heap* heap, MemoryChunk* chunk) {
580 heap->incremental_marking()->SetOldSpacePageFlags(chunk);
581 return static_cast<LargePage*>(chunk);
582}
583
584
585intptr_t LargeObjectSpace::Available() {
586 return ObjectSizeFor(heap()->isolate()->memory_allocator()->Available());
587}
588
589
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000590LocalAllocationBuffer LocalAllocationBuffer::InvalidBuffer() {
591 return LocalAllocationBuffer(nullptr, AllocationInfo(nullptr, nullptr));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000592}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000593
594
595LocalAllocationBuffer LocalAllocationBuffer::FromResult(Heap* heap,
596 AllocationResult result,
597 intptr_t size) {
598 if (result.IsRetry()) return InvalidBuffer();
599 HeapObject* obj = nullptr;
600 bool ok = result.To(&obj);
601 USE(ok);
602 DCHECK(ok);
603 Address top = HeapObject::cast(obj)->address();
604 return LocalAllocationBuffer(heap, AllocationInfo(top, top + size));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000605}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000606
607
608bool LocalAllocationBuffer::TryMerge(LocalAllocationBuffer* other) {
609 if (allocation_info_.top() == other->allocation_info_.limit()) {
610 allocation_info_.set_top(other->allocation_info_.top());
611 other->allocation_info_.Reset(nullptr, nullptr);
612 return true;
613 }
614 return false;
615}
616
617} // namespace internal
618} // namespace v8
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000619
620#endif // V8_HEAP_SPACES_INL_H_