1 // Copyright 2020 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_NEW_SPACES_INL_H_ 6 #define V8_HEAP_NEW_SPACES_INL_H_ 7 8 #include "src/base/sanitizer/msan.h" 9 #include "src/common/globals.h" 10 #include "src/heap/heap.h" 11 #include "src/heap/new-spaces.h" 12 #include "src/heap/spaces-inl.h" 13 #include "src/objects/objects-inl.h" 14 #include "src/objects/tagged-impl.h" 15 16 namespace v8 { 17 namespace internal { 18 19 // ----------------------------------------------------------------------------- 20 // SemiSpace 21 Contains(HeapObject o)22bool SemiSpace::Contains(HeapObject o) const { 23 BasicMemoryChunk* memory_chunk = BasicMemoryChunk::FromHeapObject(o); 24 if (memory_chunk->IsLargePage()) return false; 25 return id_ == kToSpace ? memory_chunk->IsToPage() 26 : memory_chunk->IsFromPage(); 27 } 28 Contains(Object o)29bool SemiSpace::Contains(Object o) const { 30 return o.IsHeapObject() && Contains(HeapObject::cast(o)); 31 } 32 ContainsSlow(Address a)33bool SemiSpace::ContainsSlow(Address a) const { 34 for (const Page* p : *this) { 35 if (p == BasicMemoryChunk::FromAddress(a)) return true; 36 } 37 return false; 38 } 39 40 // -------------------------------------------------------------------------- 41 // NewSpace 42 Contains(Object o)43bool NewSpace::Contains(Object o) const { 44 return o.IsHeapObject() && Contains(HeapObject::cast(o)); 45 } 46 Contains(HeapObject o)47bool NewSpace::Contains(HeapObject o) const { 48 return BasicMemoryChunk::FromHeapObject(o)->InNewSpace(); 49 } 50 ContainsSlow(Address a)51bool NewSpace::ContainsSlow(Address a) const { 52 return from_space_.ContainsSlow(a) || to_space_.ContainsSlow(a); 53 } 54 ToSpaceContainsSlow(Address a)55bool NewSpace::ToSpaceContainsSlow(Address a) const { 56 return to_space_.ContainsSlow(a); 57 } 58 ToSpaceContains(Object o)59bool NewSpace::ToSpaceContains(Object o) const { return to_space_.Contains(o); } FromSpaceContains(Object o)60bool NewSpace::FromSpaceContains(Object o) const { 61 return from_space_.Contains(o); 62 } 63 64 // ----------------------------------------------------------------------------- 65 // SemiSpaceObjectIterator 66 Next()67HeapObject SemiSpaceObjectIterator::Next() { 68 while (current_ != limit_) { 69 if (Page::IsAlignedToPageSize(current_)) { 70 Page* page = Page::FromAllocationAreaAddress(current_); 71 page = page->next_page(); 72 DCHECK(page); 73 current_ = page->area_start(); 74 if (current_ == limit_) return HeapObject(); 75 } 76 HeapObject object = HeapObject::FromAddress(current_); 77 current_ += object.Size(); 78 if (!object.IsFreeSpaceOrFiller()) { 79 return object; 80 } 81 } 82 return HeapObject(); 83 } 84 85 // ----------------------------------------------------------------------------- 86 // NewSpace 87 AllocateRawSynchronized(int size_in_bytes,AllocationAlignment alignment,AllocationOrigin origin)88V8_WARN_UNUSED_RESULT inline AllocationResult NewSpace::AllocateRawSynchronized( 89 int size_in_bytes, AllocationAlignment alignment, AllocationOrigin origin) { 90 base::MutexGuard guard(&mutex_); 91 return AllocateRaw(size_in_bytes, alignment, origin); 92 } 93 94 } // namespace internal 95 } // namespace v8 96 97 #endif // V8_HEAP_NEW_SPACES_INL_H_ 98