Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1 | // Copyright 2012 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_HEAP_INL_H_ |
| 6 | #define V8_HEAP_HEAP_INL_H_ |
| 7 | |
| 8 | #include <cmath> |
| 9 | |
| 10 | #include "src/base/platform/platform.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 11 | #include "src/counters.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 12 | #include "src/heap/heap.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 13 | #include "src/heap/incremental-marking-inl.h" |
| 14 | #include "src/heap/mark-compact.h" |
| 15 | #include "src/heap/spaces-inl.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 16 | #include "src/heap/store-buffer.h" |
| 17 | #include "src/heap/store-buffer-inl.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 18 | #include "src/isolate.h" |
| 19 | #include "src/list-inl.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 20 | #include "src/log.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 21 | #include "src/msan.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 22 | #include "src/objects-inl.h" |
| 23 | #include "src/type-feedback-vector-inl.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 24 | |
| 25 | namespace v8 { |
| 26 | namespace internal { |
| 27 | |
| 28 | void PromotionQueue::insert(HeapObject* target, int size) { |
| 29 | if (emergency_stack_ != NULL) { |
| 30 | emergency_stack_->Add(Entry(target, size)); |
| 31 | return; |
| 32 | } |
| 33 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 34 | if ((rear_ - 2) < limit_) { |
| 35 | RelocateQueueHead(); |
| 36 | emergency_stack_->Add(Entry(target, size)); |
| 37 | return; |
| 38 | } |
| 39 | |
| 40 | *(--rear_) = reinterpret_cast<intptr_t>(target); |
| 41 | *(--rear_) = size; |
| 42 | // Assert no overflow into live objects. |
| 43 | #ifdef DEBUG |
| 44 | SemiSpace::AssertValidRange(target->GetIsolate()->heap()->new_space()->top(), |
| 45 | reinterpret_cast<Address>(rear_)); |
| 46 | #endif |
| 47 | } |
| 48 | |
| 49 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 50 | #define ROOT_ACCESSOR(type, name, camel_name) \ |
| 51 | type* Heap::name() { return type::cast(roots_[k##camel_name##RootIndex]); } |
| 52 | ROOT_LIST(ROOT_ACCESSOR) |
| 53 | #undef ROOT_ACCESSOR |
| 54 | |
| 55 | #define STRUCT_MAP_ACCESSOR(NAME, Name, name) \ |
| 56 | Map* Heap::name##_map() { return Map::cast(roots_[k##Name##MapRootIndex]); } |
| 57 | STRUCT_LIST(STRUCT_MAP_ACCESSOR) |
| 58 | #undef STRUCT_MAP_ACCESSOR |
| 59 | |
| 60 | #define STRING_ACCESSOR(name, str) \ |
| 61 | String* Heap::name() { return String::cast(roots_[k##name##RootIndex]); } |
| 62 | INTERNALIZED_STRING_LIST(STRING_ACCESSOR) |
| 63 | #undef STRING_ACCESSOR |
| 64 | |
| 65 | #define SYMBOL_ACCESSOR(name) \ |
| 66 | Symbol* Heap::name() { return Symbol::cast(roots_[k##name##RootIndex]); } |
| 67 | PRIVATE_SYMBOL_LIST(SYMBOL_ACCESSOR) |
| 68 | #undef SYMBOL_ACCESSOR |
| 69 | |
| 70 | #define SYMBOL_ACCESSOR(name, description) \ |
| 71 | Symbol* Heap::name() { return Symbol::cast(roots_[k##name##RootIndex]); } |
| 72 | PUBLIC_SYMBOL_LIST(SYMBOL_ACCESSOR) |
| 73 | WELL_KNOWN_SYMBOL_LIST(SYMBOL_ACCESSOR) |
| 74 | #undef SYMBOL_ACCESSOR |
| 75 | |
| 76 | #define ROOT_ACCESSOR(type, name, camel_name) \ |
| 77 | void Heap::set_##name(type* value) { \ |
| 78 | /* The deserializer makes use of the fact that these common roots are */ \ |
| 79 | /* never in new space and never on a page that is being compacted. */ \ |
| 80 | DCHECK(!deserialization_complete() || \ |
| 81 | RootCanBeWrittenAfterInitialization(k##camel_name##RootIndex)); \ |
| 82 | DCHECK(k##camel_name##RootIndex >= kOldSpaceRoots || !InNewSpace(value)); \ |
| 83 | roots_[k##camel_name##RootIndex] = value; \ |
| 84 | } |
| 85 | ROOT_LIST(ROOT_ACCESSOR) |
| 86 | #undef ROOT_ACCESSOR |
| 87 | |
| 88 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 89 | template <> |
| 90 | bool inline Heap::IsOneByte(Vector<const char> str, int chars) { |
| 91 | // TODO(dcarney): incorporate Latin-1 check when Latin-1 is supported? |
| 92 | return chars == str.length(); |
| 93 | } |
| 94 | |
| 95 | |
| 96 | template <> |
| 97 | bool inline Heap::IsOneByte(String* str, int chars) { |
| 98 | return str->IsOneByteRepresentation(); |
| 99 | } |
| 100 | |
| 101 | |
| 102 | AllocationResult Heap::AllocateInternalizedStringFromUtf8( |
| 103 | Vector<const char> str, int chars, uint32_t hash_field) { |
| 104 | if (IsOneByte(str, chars)) { |
| 105 | return AllocateOneByteInternalizedString(Vector<const uint8_t>::cast(str), |
| 106 | hash_field); |
| 107 | } |
| 108 | return AllocateInternalizedStringImpl<false>(str, chars, hash_field); |
| 109 | } |
| 110 | |
| 111 | |
| 112 | template <typename T> |
| 113 | AllocationResult Heap::AllocateInternalizedStringImpl(T t, int chars, |
| 114 | uint32_t hash_field) { |
| 115 | if (IsOneByte(t, chars)) { |
| 116 | return AllocateInternalizedStringImpl<true>(t, chars, hash_field); |
| 117 | } |
| 118 | return AllocateInternalizedStringImpl<false>(t, chars, hash_field); |
| 119 | } |
| 120 | |
| 121 | |
| 122 | AllocationResult Heap::AllocateOneByteInternalizedString( |
| 123 | Vector<const uint8_t> str, uint32_t hash_field) { |
| 124 | CHECK_GE(String::kMaxLength, str.length()); |
| 125 | // Compute map and object size. |
| 126 | Map* map = one_byte_internalized_string_map(); |
| 127 | int size = SeqOneByteString::SizeFor(str.length()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 128 | |
| 129 | // Allocate string. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 130 | HeapObject* result = nullptr; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 131 | { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 132 | AllocationResult allocation = AllocateRaw(size, OLD_SPACE); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 133 | if (!allocation.To(&result)) return allocation; |
| 134 | } |
| 135 | |
| 136 | // String maps are all immortal immovable objects. |
| 137 | result->set_map_no_write_barrier(map); |
| 138 | // Set length and hash fields of the allocated string. |
| 139 | String* answer = String::cast(result); |
| 140 | answer->set_length(str.length()); |
| 141 | answer->set_hash_field(hash_field); |
| 142 | |
| 143 | DCHECK_EQ(size, answer->Size()); |
| 144 | |
| 145 | // Fill in the characters. |
| 146 | MemCopy(answer->address() + SeqOneByteString::kHeaderSize, str.start(), |
| 147 | str.length()); |
| 148 | |
| 149 | return answer; |
| 150 | } |
| 151 | |
| 152 | |
| 153 | AllocationResult Heap::AllocateTwoByteInternalizedString(Vector<const uc16> str, |
| 154 | uint32_t hash_field) { |
| 155 | CHECK_GE(String::kMaxLength, str.length()); |
| 156 | // Compute map and object size. |
| 157 | Map* map = internalized_string_map(); |
| 158 | int size = SeqTwoByteString::SizeFor(str.length()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 159 | |
| 160 | // Allocate string. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 161 | HeapObject* result = nullptr; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 162 | { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 163 | AllocationResult allocation = AllocateRaw(size, OLD_SPACE); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 164 | if (!allocation.To(&result)) return allocation; |
| 165 | } |
| 166 | |
| 167 | result->set_map(map); |
| 168 | // Set length and hash fields of the allocated string. |
| 169 | String* answer = String::cast(result); |
| 170 | answer->set_length(str.length()); |
| 171 | answer->set_hash_field(hash_field); |
| 172 | |
| 173 | DCHECK_EQ(size, answer->Size()); |
| 174 | |
| 175 | // Fill in the characters. |
| 176 | MemCopy(answer->address() + SeqTwoByteString::kHeaderSize, str.start(), |
| 177 | str.length() * kUC16Size); |
| 178 | |
| 179 | return answer; |
| 180 | } |
| 181 | |
| 182 | AllocationResult Heap::CopyFixedArray(FixedArray* src) { |
| 183 | if (src->length() == 0) return src; |
| 184 | return CopyFixedArrayWithMap(src, src->map()); |
| 185 | } |
| 186 | |
| 187 | |
| 188 | AllocationResult Heap::CopyFixedDoubleArray(FixedDoubleArray* src) { |
| 189 | if (src->length() == 0) return src; |
| 190 | return CopyFixedDoubleArrayWithMap(src, src->map()); |
| 191 | } |
| 192 | |
| 193 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 194 | AllocationResult Heap::AllocateRaw(int size_in_bytes, AllocationSpace space, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 195 | AllocationAlignment alignment) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 196 | DCHECK(AllowHandleAllocation::IsAllowed()); |
| 197 | DCHECK(AllowHeapAllocation::IsAllowed()); |
| 198 | DCHECK(gc_state_ == NOT_IN_GC); |
| 199 | #ifdef DEBUG |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 200 | if (FLAG_gc_interval >= 0 && !always_allocate() && |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 201 | Heap::allocation_timeout_-- <= 0) { |
| 202 | return AllocationResult::Retry(space); |
| 203 | } |
| 204 | isolate_->counters()->objs_since_last_full()->Increment(); |
| 205 | isolate_->counters()->objs_since_last_young()->Increment(); |
| 206 | #endif |
| 207 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 208 | bool large_object = size_in_bytes > Page::kMaxRegularHeapObjectSize; |
| 209 | HeapObject* object = nullptr; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 210 | AllocationResult allocation; |
| 211 | if (NEW_SPACE == space) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 212 | if (large_object) { |
| 213 | space = LO_SPACE; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 214 | } else { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 215 | allocation = new_space_.AllocateRaw(size_in_bytes, alignment); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 216 | if (allocation.To(&object)) { |
| 217 | OnAllocationEvent(object, size_in_bytes); |
| 218 | } |
| 219 | return allocation; |
| 220 | } |
| 221 | } |
| 222 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 223 | // Here we only allocate in the old generation. |
| 224 | if (OLD_SPACE == space) { |
| 225 | if (large_object) { |
| 226 | allocation = lo_space_->AllocateRaw(size_in_bytes, NOT_EXECUTABLE); |
| 227 | } else { |
| 228 | allocation = old_space_->AllocateRaw(size_in_bytes, alignment); |
| 229 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 230 | } else if (CODE_SPACE == space) { |
| 231 | if (size_in_bytes <= code_space()->AreaSize()) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 232 | allocation = code_space_->AllocateRawUnaligned(size_in_bytes); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 233 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 234 | allocation = lo_space_->AllocateRaw(size_in_bytes, EXECUTABLE); |
| 235 | } |
| 236 | } else if (LO_SPACE == space) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 237 | DCHECK(large_object); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 238 | allocation = lo_space_->AllocateRaw(size_in_bytes, NOT_EXECUTABLE); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 239 | } else if (MAP_SPACE == space) { |
| 240 | allocation = map_space_->AllocateRawUnaligned(size_in_bytes); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 241 | } else { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 242 | // NEW_SPACE is not allowed here. |
| 243 | UNREACHABLE(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 244 | } |
| 245 | if (allocation.To(&object)) { |
| 246 | OnAllocationEvent(object, size_in_bytes); |
| 247 | } else { |
| 248 | old_gen_exhausted_ = true; |
| 249 | } |
| 250 | return allocation; |
| 251 | } |
| 252 | |
| 253 | |
| 254 | void Heap::OnAllocationEvent(HeapObject* object, int size_in_bytes) { |
| 255 | HeapProfiler* profiler = isolate_->heap_profiler(); |
| 256 | if (profiler->is_tracking_allocations()) { |
| 257 | profiler->AllocationEvent(object->address(), size_in_bytes); |
| 258 | } |
| 259 | |
| 260 | if (FLAG_verify_predictable) { |
| 261 | ++allocations_count_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 262 | // Advance synthetic time by making a time request. |
| 263 | MonotonicallyIncreasingTimeInMs(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 264 | |
| 265 | UpdateAllocationsHash(object); |
| 266 | UpdateAllocationsHash(size_in_bytes); |
| 267 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 268 | if (allocations_count_ % FLAG_dump_allocations_digest_at_alloc == 0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 269 | PrintAlloctionsHash(); |
| 270 | } |
| 271 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 272 | |
| 273 | if (FLAG_trace_allocation_stack_interval > 0) { |
| 274 | if (!FLAG_verify_predictable) ++allocations_count_; |
| 275 | if (allocations_count_ % FLAG_trace_allocation_stack_interval == 0) { |
| 276 | isolate()->PrintStack(stdout, Isolate::kPrintStackConcise); |
| 277 | } |
| 278 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | |
| 282 | void Heap::OnMoveEvent(HeapObject* target, HeapObject* source, |
| 283 | int size_in_bytes) { |
| 284 | HeapProfiler* heap_profiler = isolate_->heap_profiler(); |
| 285 | if (heap_profiler->is_tracking_object_moves()) { |
| 286 | heap_profiler->ObjectMoveEvent(source->address(), target->address(), |
| 287 | size_in_bytes); |
| 288 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 289 | if (target->IsSharedFunctionInfo()) { |
| 290 | LOG_CODE_EVENT(isolate_, SharedFunctionInfoMoveEvent(source->address(), |
| 291 | target->address())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | if (FLAG_verify_predictable) { |
| 295 | ++allocations_count_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 296 | // Advance synthetic time by making a time request. |
| 297 | MonotonicallyIncreasingTimeInMs(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 298 | |
| 299 | UpdateAllocationsHash(source); |
| 300 | UpdateAllocationsHash(target); |
| 301 | UpdateAllocationsHash(size_in_bytes); |
| 302 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 303 | if (allocations_count_ % FLAG_dump_allocations_digest_at_alloc == 0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 304 | PrintAlloctionsHash(); |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | |
| 310 | void Heap::UpdateAllocationsHash(HeapObject* object) { |
| 311 | Address object_address = object->address(); |
| 312 | MemoryChunk* memory_chunk = MemoryChunk::FromAddress(object_address); |
| 313 | AllocationSpace allocation_space = memory_chunk->owner()->identity(); |
| 314 | |
| 315 | STATIC_ASSERT(kSpaceTagSize + kPageSizeBits <= 32); |
| 316 | uint32_t value = |
| 317 | static_cast<uint32_t>(object_address - memory_chunk->address()) | |
| 318 | (static_cast<uint32_t>(allocation_space) << kPageSizeBits); |
| 319 | |
| 320 | UpdateAllocationsHash(value); |
| 321 | } |
| 322 | |
| 323 | |
| 324 | void Heap::UpdateAllocationsHash(uint32_t value) { |
| 325 | uint16_t c1 = static_cast<uint16_t>(value); |
| 326 | uint16_t c2 = static_cast<uint16_t>(value >> 16); |
| 327 | raw_allocations_hash_ = |
| 328 | StringHasher::AddCharacterCore(raw_allocations_hash_, c1); |
| 329 | raw_allocations_hash_ = |
| 330 | StringHasher::AddCharacterCore(raw_allocations_hash_, c2); |
| 331 | } |
| 332 | |
| 333 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 334 | void Heap::RegisterExternalString(String* string) { |
| 335 | external_string_table_.AddString(string); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | |
| 339 | void Heap::FinalizeExternalString(String* string) { |
| 340 | DCHECK(string->IsExternalString()); |
| 341 | v8::String::ExternalStringResourceBase** resource_addr = |
| 342 | reinterpret_cast<v8::String::ExternalStringResourceBase**>( |
| 343 | reinterpret_cast<byte*>(string) + ExternalString::kResourceOffset - |
| 344 | kHeapObjectTag); |
| 345 | |
| 346 | // Dispose of the C++ object if it has not already been disposed. |
| 347 | if (*resource_addr != NULL) { |
| 348 | (*resource_addr)->Dispose(); |
| 349 | *resource_addr = NULL; |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | |
| 354 | bool Heap::InNewSpace(Object* object) { |
| 355 | bool result = new_space_.Contains(object); |
| 356 | DCHECK(!result || // Either not in new space |
| 357 | gc_state_ != NOT_IN_GC || // ... or in the middle of GC |
| 358 | InToSpace(object)); // ... or in to-space (where we allocate). |
| 359 | return result; |
| 360 | } |
| 361 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 362 | bool Heap::InFromSpace(Object* object) { |
| 363 | return new_space_.FromSpaceContains(object); |
| 364 | } |
| 365 | |
| 366 | |
| 367 | bool Heap::InToSpace(Object* object) { |
| 368 | return new_space_.ToSpaceContains(object); |
| 369 | } |
| 370 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 371 | bool Heap::InOldSpace(Object* object) { return old_space_->Contains(object); } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 372 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 373 | bool Heap::InNewSpaceSlow(Address address) { |
| 374 | return new_space_.ContainsSlow(address); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 375 | } |
| 376 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 377 | bool Heap::InOldSpaceSlow(Address address) { |
| 378 | return old_space_->ContainsSlow(address); |
| 379 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 380 | |
| 381 | bool Heap::OldGenerationAllocationLimitReached() { |
| 382 | if (!incremental_marking()->IsStopped()) return false; |
| 383 | return OldGenerationSpaceAvailable() < 0; |
| 384 | } |
| 385 | |
| 386 | |
| 387 | bool Heap::ShouldBePromoted(Address old_address, int object_size) { |
| 388 | NewSpacePage* page = NewSpacePage::FromAddress(old_address); |
| 389 | Address age_mark = new_space_.age_mark(); |
| 390 | return page->IsFlagSet(MemoryChunk::NEW_SPACE_BELOW_AGE_MARK) && |
| 391 | (!page->ContainsLimit(age_mark) || old_address < age_mark); |
| 392 | } |
| 393 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 394 | void Heap::RecordWrite(Object* object, int offset, Object* o) { |
| 395 | if (!InNewSpace(o) || !object->IsHeapObject() || InNewSpace(object)) { |
| 396 | return; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 397 | } |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 398 | Page* page = Page::FromAddress(reinterpret_cast<Address>(object)); |
| 399 | Address slot = HeapObject::cast(object)->address() + offset; |
| 400 | RememberedSet<OLD_TO_NEW>::Insert(page, slot); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 404 | bool Heap::AllowedToBeMigrated(HeapObject* obj, AllocationSpace dst) { |
| 405 | // Object migration is governed by the following rules: |
| 406 | // |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 407 | // 1) Objects in new-space can be migrated to the old space |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 408 | // that matches their target space or they stay in new-space. |
| 409 | // 2) Objects in old-space stay in the same space when migrating. |
| 410 | // 3) Fillers (two or more words) can migrate due to left-trimming of |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 411 | // fixed arrays in new-space or old space. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 412 | // 4) Fillers (one word) can never migrate, they are skipped by |
| 413 | // incremental marking explicitly to prevent invalid pattern. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 414 | // |
| 415 | // Since this function is used for debugging only, we do not place |
| 416 | // asserts here, but check everything explicitly. |
| 417 | if (obj->map() == one_pointer_filler_map()) return false; |
| 418 | InstanceType type = obj->map()->instance_type(); |
| 419 | MemoryChunk* chunk = MemoryChunk::FromAddress(obj->address()); |
| 420 | AllocationSpace src = chunk->owner()->identity(); |
| 421 | switch (src) { |
| 422 | case NEW_SPACE: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 423 | return dst == src || dst == OLD_SPACE; |
| 424 | case OLD_SPACE: |
| 425 | return dst == src && |
| 426 | (dst == OLD_SPACE || obj->IsFiller() || obj->IsExternalString()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 427 | case CODE_SPACE: |
| 428 | return dst == src && type == CODE_TYPE; |
| 429 | case MAP_SPACE: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 430 | case LO_SPACE: |
| 431 | return false; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 432 | } |
| 433 | UNREACHABLE(); |
| 434 | return false; |
| 435 | } |
| 436 | |
| 437 | |
| 438 | void Heap::CopyBlock(Address dst, Address src, int byte_size) { |
| 439 | CopyWords(reinterpret_cast<Object**>(dst), reinterpret_cast<Object**>(src), |
| 440 | static_cast<size_t>(byte_size / kPointerSize)); |
| 441 | } |
| 442 | |
| 443 | |
| 444 | void Heap::MoveBlock(Address dst, Address src, int byte_size) { |
| 445 | DCHECK(IsAligned(byte_size, kPointerSize)); |
| 446 | |
| 447 | int size_in_words = byte_size / kPointerSize; |
| 448 | |
| 449 | if ((dst < src) || (dst >= (src + byte_size))) { |
| 450 | Object** src_slot = reinterpret_cast<Object**>(src); |
| 451 | Object** dst_slot = reinterpret_cast<Object**>(dst); |
| 452 | Object** end_slot = src_slot + size_in_words; |
| 453 | |
| 454 | while (src_slot != end_slot) { |
| 455 | *dst_slot++ = *src_slot++; |
| 456 | } |
| 457 | } else { |
| 458 | MemMove(dst, src, static_cast<size_t>(byte_size)); |
| 459 | } |
| 460 | } |
| 461 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 462 | template <Heap::FindMementoMode mode> |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 463 | AllocationMemento* Heap::FindAllocationMemento(HeapObject* object) { |
| 464 | // Check if there is potentially a memento behind the object. If |
| 465 | // the last word of the memento is on another page we return |
| 466 | // immediately. |
| 467 | Address object_address = object->address(); |
| 468 | Address memento_address = object_address + object->Size(); |
| 469 | Address last_memento_word_address = memento_address + kPointerSize; |
| 470 | if (!NewSpacePage::OnSamePage(object_address, last_memento_word_address)) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 471 | return nullptr; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 472 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 473 | HeapObject* candidate = HeapObject::FromAddress(memento_address); |
| 474 | Map* candidate_map = candidate->map(); |
| 475 | // This fast check may peek at an uninitialized word. However, the slow check |
| 476 | // below (memento_address == top) ensures that this is safe. Mark the word as |
| 477 | // initialized to silence MemorySanitizer warnings. |
| 478 | MSAN_MEMORY_IS_INITIALIZED(&candidate_map, sizeof(candidate_map)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 479 | if (candidate_map != allocation_memento_map()) { |
| 480 | return nullptr; |
| 481 | } |
| 482 | AllocationMemento* memento_candidate = AllocationMemento::cast(candidate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 483 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 484 | // Depending on what the memento is used for, we might need to perform |
| 485 | // additional checks. |
| 486 | Address top; |
| 487 | switch (mode) { |
| 488 | case Heap::kForGC: |
| 489 | return memento_candidate; |
| 490 | case Heap::kForRuntime: |
| 491 | if (memento_candidate == nullptr) return nullptr; |
| 492 | // Either the object is the last object in the new space, or there is |
| 493 | // another object of at least word size (the header map word) following |
| 494 | // it, so suffices to compare ptr and top here. |
| 495 | top = NewSpaceTop(); |
| 496 | DCHECK(memento_address == top || |
| 497 | memento_address + HeapObject::kHeaderSize <= top || |
| 498 | !NewSpacePage::OnSamePage(memento_address, top - 1)); |
| 499 | if ((memento_address != top) && memento_candidate->IsValid()) { |
| 500 | return memento_candidate; |
| 501 | } |
| 502 | return nullptr; |
| 503 | default: |
| 504 | UNREACHABLE(); |
| 505 | } |
| 506 | UNREACHABLE(); |
| 507 | return nullptr; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 508 | } |
| 509 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 510 | template <Heap::UpdateAllocationSiteMode mode> |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 511 | void Heap::UpdateAllocationSite(HeapObject* object, |
| 512 | HashMap* pretenuring_feedback) { |
| 513 | DCHECK(InFromSpace(object)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 514 | if (!FLAG_allocation_site_pretenuring || |
| 515 | !AllocationSite::CanTrack(object->map()->instance_type())) |
| 516 | return; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 517 | AllocationMemento* memento_candidate = FindAllocationMemento<kForGC>(object); |
| 518 | if (memento_candidate == nullptr) return; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 519 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 520 | if (mode == kGlobal) { |
| 521 | DCHECK_EQ(pretenuring_feedback, global_pretenuring_feedback_); |
| 522 | // Entering global pretenuring feedback is only used in the scavenger, where |
| 523 | // we are allowed to actually touch the allocation site. |
| 524 | if (!memento_candidate->IsValid()) return; |
| 525 | AllocationSite* site = memento_candidate->GetAllocationSite(); |
| 526 | DCHECK(!site->IsZombie()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 527 | // For inserting in the global pretenuring storage we need to first |
| 528 | // increment the memento found count on the allocation site. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 529 | if (site->IncrementMementoFoundCount()) { |
| 530 | global_pretenuring_feedback_->LookupOrInsert(site, |
| 531 | ObjectHash(site->address())); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 532 | } |
| 533 | } else { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 534 | DCHECK_EQ(mode, kCached); |
| 535 | DCHECK_NE(pretenuring_feedback, global_pretenuring_feedback_); |
| 536 | // Entering cached feedback is used in the parallel case. We are not allowed |
| 537 | // to dereference the allocation site and rather have to postpone all checks |
| 538 | // till actually merging the data. |
| 539 | Address key = memento_candidate->GetAllocationSiteUnchecked(); |
| 540 | HashMap::Entry* e = |
| 541 | pretenuring_feedback->LookupOrInsert(key, ObjectHash(key)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 542 | DCHECK(e != nullptr); |
| 543 | (*bit_cast<intptr_t*>(&e->value))++; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 544 | } |
| 545 | } |
| 546 | |
| 547 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 548 | void Heap::RemoveAllocationSitePretenuringFeedback(AllocationSite* site) { |
| 549 | global_pretenuring_feedback_->Remove( |
| 550 | site, static_cast<uint32_t>(bit_cast<uintptr_t>(site))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | |
| 554 | bool Heap::CollectGarbage(AllocationSpace space, const char* gc_reason, |
| 555 | const v8::GCCallbackFlags callbackFlags) { |
| 556 | const char* collector_reason = NULL; |
| 557 | GarbageCollector collector = SelectGarbageCollector(space, &collector_reason); |
| 558 | return CollectGarbage(collector, gc_reason, collector_reason, callbackFlags); |
| 559 | } |
| 560 | |
| 561 | |
| 562 | Isolate* Heap::isolate() { |
| 563 | return reinterpret_cast<Isolate*>( |
| 564 | reinterpret_cast<intptr_t>(this) - |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 565 | reinterpret_cast<size_t>(reinterpret_cast<Isolate*>(16)->heap()) + 16); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 569 | void Heap::ExternalStringTable::AddString(String* string) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 570 | DCHECK(string->IsExternalString()); |
| 571 | if (heap_->InNewSpace(string)) { |
| 572 | new_space_strings_.Add(string); |
| 573 | } else { |
| 574 | old_space_strings_.Add(string); |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 579 | void Heap::ExternalStringTable::Iterate(ObjectVisitor* v) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 580 | if (!new_space_strings_.is_empty()) { |
| 581 | Object** start = &new_space_strings_[0]; |
| 582 | v->VisitPointers(start, start + new_space_strings_.length()); |
| 583 | } |
| 584 | if (!old_space_strings_.is_empty()) { |
| 585 | Object** start = &old_space_strings_[0]; |
| 586 | v->VisitPointers(start, start + old_space_strings_.length()); |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | |
| 591 | // Verify() is inline to avoid ifdef-s around its calls in release |
| 592 | // mode. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 593 | void Heap::ExternalStringTable::Verify() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 594 | #ifdef DEBUG |
| 595 | for (int i = 0; i < new_space_strings_.length(); ++i) { |
| 596 | Object* obj = Object::cast(new_space_strings_[i]); |
| 597 | DCHECK(heap_->InNewSpace(obj)); |
| 598 | DCHECK(obj != heap_->the_hole_value()); |
| 599 | } |
| 600 | for (int i = 0; i < old_space_strings_.length(); ++i) { |
| 601 | Object* obj = Object::cast(old_space_strings_[i]); |
| 602 | DCHECK(!heap_->InNewSpace(obj)); |
| 603 | DCHECK(obj != heap_->the_hole_value()); |
| 604 | } |
| 605 | #endif |
| 606 | } |
| 607 | |
| 608 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 609 | void Heap::ExternalStringTable::AddOldString(String* string) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 610 | DCHECK(string->IsExternalString()); |
| 611 | DCHECK(!heap_->InNewSpace(string)); |
| 612 | old_space_strings_.Add(string); |
| 613 | } |
| 614 | |
| 615 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 616 | void Heap::ExternalStringTable::ShrinkNewStrings(int position) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 617 | new_space_strings_.Rewind(position); |
| 618 | #ifdef VERIFY_HEAP |
| 619 | if (FLAG_verify_heap) { |
| 620 | Verify(); |
| 621 | } |
| 622 | #endif |
| 623 | } |
| 624 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 625 | // static |
| 626 | int DescriptorLookupCache::Hash(Object* source, Name* name) { |
| 627 | DCHECK(name->IsUniqueName()); |
| 628 | // Uses only lower 32 bits if pointers are larger. |
| 629 | uint32_t source_hash = |
| 630 | static_cast<uint32_t>(reinterpret_cast<uintptr_t>(source)) >> |
| 631 | kPointerSizeLog2; |
| 632 | uint32_t name_hash = name->hash_field(); |
| 633 | return (source_hash ^ name_hash) % kLength; |
| 634 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 635 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 636 | int DescriptorLookupCache::Lookup(Map* source, Name* name) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 637 | int index = Hash(source, name); |
| 638 | Key& key = keys_[index]; |
| 639 | if ((key.source == source) && (key.name == name)) return results_[index]; |
| 640 | return kAbsent; |
| 641 | } |
| 642 | |
| 643 | |
| 644 | void DescriptorLookupCache::Update(Map* source, Name* name, int result) { |
| 645 | DCHECK(result != kAbsent); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 646 | int index = Hash(source, name); |
| 647 | Key& key = keys_[index]; |
| 648 | key.source = source; |
| 649 | key.name = name; |
| 650 | results_[index] = result; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 654 | void Heap::ClearInstanceofCache() { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 655 | set_instanceof_cache_function(Smi::FromInt(0)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | |
| 659 | Object* Heap::ToBoolean(bool condition) { |
| 660 | return condition ? true_value() : false_value(); |
| 661 | } |
| 662 | |
| 663 | |
| 664 | void Heap::CompletelyClearInstanceofCache() { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 665 | set_instanceof_cache_map(Smi::FromInt(0)); |
| 666 | set_instanceof_cache_function(Smi::FromInt(0)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 670 | uint32_t Heap::HashSeed() { |
| 671 | uint32_t seed = static_cast<uint32_t>(hash_seed()->value()); |
| 672 | DCHECK(FLAG_randomize_hashes || seed == 0); |
| 673 | return seed; |
| 674 | } |
| 675 | |
| 676 | |
| 677 | int Heap::NextScriptId() { |
| 678 | int last_id = last_script_id()->value(); |
| 679 | if (last_id == Smi::kMaxValue) { |
| 680 | last_id = 1; |
| 681 | } else { |
| 682 | last_id++; |
| 683 | } |
| 684 | set_last_script_id(Smi::FromInt(last_id)); |
| 685 | return last_id; |
| 686 | } |
| 687 | |
| 688 | |
| 689 | void Heap::SetArgumentsAdaptorDeoptPCOffset(int pc_offset) { |
| 690 | DCHECK(arguments_adaptor_deopt_pc_offset() == Smi::FromInt(0)); |
| 691 | set_arguments_adaptor_deopt_pc_offset(Smi::FromInt(pc_offset)); |
| 692 | } |
| 693 | |
| 694 | |
| 695 | void Heap::SetConstructStubDeoptPCOffset(int pc_offset) { |
| 696 | DCHECK(construct_stub_deopt_pc_offset() == Smi::FromInt(0)); |
| 697 | set_construct_stub_deopt_pc_offset(Smi::FromInt(pc_offset)); |
| 698 | } |
| 699 | |
| 700 | |
| 701 | void Heap::SetGetterStubDeoptPCOffset(int pc_offset) { |
| 702 | DCHECK(getter_stub_deopt_pc_offset() == Smi::FromInt(0)); |
| 703 | set_getter_stub_deopt_pc_offset(Smi::FromInt(pc_offset)); |
| 704 | } |
| 705 | |
| 706 | |
| 707 | void Heap::SetSetterStubDeoptPCOffset(int pc_offset) { |
| 708 | DCHECK(setter_stub_deopt_pc_offset() == Smi::FromInt(0)); |
| 709 | set_setter_stub_deopt_pc_offset(Smi::FromInt(pc_offset)); |
| 710 | } |
| 711 | |
| 712 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 713 | AlwaysAllocateScope::AlwaysAllocateScope(Isolate* isolate) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 714 | : heap_(isolate->heap()) { |
| 715 | heap_->always_allocate_scope_count_.Increment(1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | |
| 719 | AlwaysAllocateScope::~AlwaysAllocateScope() { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 720 | heap_->always_allocate_scope_count_.Increment(-1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | |
| 724 | void VerifyPointersVisitor::VisitPointers(Object** start, Object** end) { |
| 725 | for (Object** current = start; current < end; current++) { |
| 726 | if ((*current)->IsHeapObject()) { |
| 727 | HeapObject* object = HeapObject::cast(*current); |
| 728 | CHECK(object->GetIsolate()->heap()->Contains(object)); |
| 729 | CHECK(object->map()->IsMap()); |
| 730 | } |
| 731 | } |
| 732 | } |
| 733 | |
| 734 | |
| 735 | void VerifySmisVisitor::VisitPointers(Object** start, Object** end) { |
| 736 | for (Object** current = start; current < end; current++) { |
| 737 | CHECK((*current)->IsSmi()); |
| 738 | } |
| 739 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 740 | } // namespace internal |
| 741 | } // namespace v8 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 742 | |
| 743 | #endif // V8_HEAP_HEAP_INL_H_ |