| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 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 | 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 #ifndef V8_HEAP_HEAP_INL_H_ | 5 #ifndef V8_HEAP_HEAP_INL_H_ |
| 6 #define V8_HEAP_HEAP_INL_H_ | 6 #define V8_HEAP_HEAP_INL_H_ |
| 7 | 7 |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 return AllocateInternalizedStringImpl<false>(t, chars, hash_field); | 74 return AllocateInternalizedStringImpl<false>(t, chars, hash_field); |
| 75 } | 75 } |
| 76 | 76 |
| 77 | 77 |
| 78 AllocationResult Heap::AllocateOneByteInternalizedString( | 78 AllocationResult Heap::AllocateOneByteInternalizedString( |
| 79 Vector<const uint8_t> str, uint32_t hash_field) { | 79 Vector<const uint8_t> str, uint32_t hash_field) { |
| 80 CHECK_GE(String::kMaxLength, str.length()); | 80 CHECK_GE(String::kMaxLength, str.length()); |
| 81 // Compute map and object size. | 81 // Compute map and object size. |
| 82 Map* map = one_byte_internalized_string_map(); | 82 Map* map = one_byte_internalized_string_map(); |
| 83 int size = SeqOneByteString::SizeFor(str.length()); | 83 int size = SeqOneByteString::SizeFor(str.length()); |
| 84 AllocationSpace space = SelectSpace(size, TENURED); | 84 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, TENURED); |
| 85 | 85 |
| 86 // Allocate string. | 86 // Allocate string. |
| 87 HeapObject* result; | 87 HeapObject* result; |
| 88 { | 88 { |
| 89 AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE); | 89 AllocationResult allocation = AllocateRaw(size, space, OLD_DATA_SPACE); |
| 90 if (!allocation.To(&result)) return allocation; | 90 if (!allocation.To(&result)) return allocation; |
| 91 } | 91 } |
| 92 | 92 |
| 93 // String maps are all immortal immovable objects. | 93 // String maps are all immortal immovable objects. |
| 94 result->set_map_no_write_barrier(map); | 94 result->set_map_no_write_barrier(map); |
| 95 // Set length and hash fields of the allocated string. | 95 // Set length and hash fields of the allocated string. |
| 96 String* answer = String::cast(result); | 96 String* answer = String::cast(result); |
| 97 answer->set_length(str.length()); | 97 answer->set_length(str.length()); |
| 98 answer->set_hash_field(hash_field); | 98 answer->set_hash_field(hash_field); |
| 99 | 99 |
| 100 DCHECK_EQ(size, answer->Size()); | 100 DCHECK_EQ(size, answer->Size()); |
| 101 | 101 |
| 102 // Fill in the characters. | 102 // Fill in the characters. |
| 103 MemCopy(answer->address() + SeqOneByteString::kHeaderSize, str.start(), | 103 MemCopy(answer->address() + SeqOneByteString::kHeaderSize, str.start(), |
| 104 str.length()); | 104 str.length()); |
| 105 | 105 |
| 106 return answer; | 106 return answer; |
| 107 } | 107 } |
| 108 | 108 |
| 109 | 109 |
| 110 AllocationResult Heap::AllocateTwoByteInternalizedString(Vector<const uc16> str, | 110 AllocationResult Heap::AllocateTwoByteInternalizedString(Vector<const uc16> str, |
| 111 uint32_t hash_field) { | 111 uint32_t hash_field) { |
| 112 CHECK_GE(String::kMaxLength, str.length()); | 112 CHECK_GE(String::kMaxLength, str.length()); |
| 113 // Compute map and object size. | 113 // Compute map and object size. |
| 114 Map* map = internalized_string_map(); | 114 Map* map = internalized_string_map(); |
| 115 int size = SeqTwoByteString::SizeFor(str.length()); | 115 int size = SeqTwoByteString::SizeFor(str.length()); |
| 116 AllocationSpace space = SelectSpace(size, TENURED); | 116 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, TENURED); |
| 117 | 117 |
| 118 // Allocate string. | 118 // Allocate string. |
| 119 HeapObject* result; | 119 HeapObject* result; |
| 120 { | 120 { |
| 121 AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE); | 121 AllocationResult allocation = AllocateRaw(size, space, OLD_DATA_SPACE); |
| 122 if (!allocation.To(&result)) return allocation; | 122 if (!allocation.To(&result)) return allocation; |
| 123 } | 123 } |
| 124 | 124 |
| 125 result->set_map(map); | 125 result->set_map(map); |
| 126 // Set length and hash fields of the allocated string. | 126 // Set length and hash fields of the allocated string. |
| 127 String* answer = String::cast(result); | 127 String* answer = String::cast(result); |
| 128 answer->set_length(str.length()); | 128 answer->set_length(str.length()); |
| 129 answer->set_hash_field(hash_field); | 129 answer->set_hash_field(hash_field); |
| 130 | 130 |
| 131 DCHECK_EQ(size, answer->Size()); | 131 DCHECK_EQ(size, answer->Size()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 if (always_allocate() && allocation.IsRetry() && retry_space != NEW_SPACE) { | 176 if (always_allocate() && allocation.IsRetry() && retry_space != NEW_SPACE) { |
| 177 space = retry_space; | 177 space = retry_space; |
| 178 } else { | 178 } else { |
| 179 if (allocation.To(&object)) { | 179 if (allocation.To(&object)) { |
| 180 OnAllocationEvent(object, size_in_bytes); | 180 OnAllocationEvent(object, size_in_bytes); |
| 181 } | 181 } |
| 182 return allocation; | 182 return allocation; |
| 183 } | 183 } |
| 184 } | 184 } |
| 185 | 185 |
| 186 if (OLD_SPACE == space) { | 186 if (OLD_POINTER_SPACE == space) { |
| 187 allocation = old_space_->AllocateRaw(size_in_bytes); | 187 allocation = old_pointer_space_->AllocateRaw(size_in_bytes); |
| 188 } else if (OLD_DATA_SPACE == space) { |
| 189 allocation = old_data_space_->AllocateRaw(size_in_bytes); |
| 188 } else if (CODE_SPACE == space) { | 190 } else if (CODE_SPACE == space) { |
| 189 if (size_in_bytes <= code_space()->AreaSize()) { | 191 if (size_in_bytes <= code_space()->AreaSize()) { |
| 190 allocation = code_space_->AllocateRaw(size_in_bytes); | 192 allocation = code_space_->AllocateRaw(size_in_bytes); |
| 191 } else { | 193 } else { |
| 192 // Large code objects are allocated in large object space. | 194 // Large code objects are allocated in large object space. |
| 193 allocation = lo_space_->AllocateRaw(size_in_bytes, EXECUTABLE); | 195 allocation = lo_space_->AllocateRaw(size_in_bytes, EXECUTABLE); |
| 194 } | 196 } |
| 195 } else if (LO_SPACE == space) { | 197 } else if (LO_SPACE == space) { |
| 196 allocation = lo_space_->AllocateRaw(size_in_bytes, NOT_EXECUTABLE); | 198 allocation = lo_space_->AllocateRaw(size_in_bytes, NOT_EXECUTABLE); |
| 197 } else if (CELL_SPACE == space) { | 199 } else if (CELL_SPACE == space) { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 bool Heap::InFromSpace(Object* object) { | 320 bool Heap::InFromSpace(Object* object) { |
| 319 return new_space_.FromSpaceContains(object); | 321 return new_space_.FromSpaceContains(object); |
| 320 } | 322 } |
| 321 | 323 |
| 322 | 324 |
| 323 bool Heap::InToSpace(Object* object) { | 325 bool Heap::InToSpace(Object* object) { |
| 324 return new_space_.ToSpaceContains(object); | 326 return new_space_.ToSpaceContains(object); |
| 325 } | 327 } |
| 326 | 328 |
| 327 | 329 |
| 328 bool Heap::InOldSpace(Address address) { return old_space_->Contains(address); } | 330 bool Heap::InOldPointerSpace(Address address) { |
| 329 | 331 return old_pointer_space_->Contains(address); |
| 330 | |
| 331 bool Heap::InOldSpace(Object* object) { | |
| 332 return InOldSpace(reinterpret_cast<Address>(object)); | |
| 333 } | 332 } |
| 334 | 333 |
| 335 | 334 |
| 335 bool Heap::InOldPointerSpace(Object* object) { |
| 336 return InOldPointerSpace(reinterpret_cast<Address>(object)); |
| 337 } |
| 338 |
| 339 |
| 340 bool Heap::InOldDataSpace(Address address) { |
| 341 return old_data_space_->Contains(address); |
| 342 } |
| 343 |
| 344 |
| 345 bool Heap::InOldDataSpace(Object* object) { |
| 346 return InOldDataSpace(reinterpret_cast<Address>(object)); |
| 347 } |
| 348 |
| 349 |
| 336 bool Heap::OldGenerationAllocationLimitReached() { | 350 bool Heap::OldGenerationAllocationLimitReached() { |
| 337 if (!incremental_marking()->IsStopped()) return false; | 351 if (!incremental_marking()->IsStopped()) return false; |
| 338 return OldGenerationSpaceAvailable() < 0; | 352 return OldGenerationSpaceAvailable() < 0; |
| 339 } | 353 } |
| 340 | 354 |
| 341 | 355 |
| 342 bool Heap::ShouldBePromoted(Address old_address, int object_size) { | 356 bool Heap::ShouldBePromoted(Address old_address, int object_size) { |
| 343 NewSpacePage* page = NewSpacePage::FromAddress(old_address); | 357 NewSpacePage* page = NewSpacePage::FromAddress(old_address); |
| 344 Address age_mark = new_space_.age_mark(); | 358 Address age_mark = new_space_.age_mark(); |
| 345 return page->IsFlagSet(MemoryChunk::NEW_SPACE_BELOW_AGE_MARK) && | 359 return page->IsFlagSet(MemoryChunk::NEW_SPACE_BELOW_AGE_MARK) && |
| 346 (!page->ContainsLimit(age_mark) || old_address < age_mark); | 360 (!page->ContainsLimit(age_mark) || old_address < age_mark); |
| 347 } | 361 } |
| 348 | 362 |
| 349 | 363 |
| 350 void Heap::RecordWrite(Address address, int offset) { | 364 void Heap::RecordWrite(Address address, int offset) { |
| 351 if (!InNewSpace(address)) store_buffer_.Mark(address + offset); | 365 if (!InNewSpace(address)) store_buffer_.Mark(address + offset); |
| 352 } | 366 } |
| 353 | 367 |
| 354 | 368 |
| 355 void Heap::RecordWrites(Address address, int start, int len) { | 369 void Heap::RecordWrites(Address address, int start, int len) { |
| 356 if (!InNewSpace(address)) { | 370 if (!InNewSpace(address)) { |
| 357 for (int i = 0; i < len; i++) { | 371 for (int i = 0; i < len; i++) { |
| 358 store_buffer_.Mark(address + start + i * kPointerSize); | 372 store_buffer_.Mark(address + start + i * kPointerSize); |
| 359 } | 373 } |
| 360 } | 374 } |
| 361 } | 375 } |
| 362 | 376 |
| 363 | 377 |
| 378 OldSpace* Heap::TargetSpace(HeapObject* object) { |
| 379 InstanceType type = object->map()->instance_type(); |
| 380 AllocationSpace space = TargetSpaceId(type); |
| 381 return (space == OLD_POINTER_SPACE) ? old_pointer_space_ : old_data_space_; |
| 382 } |
| 383 |
| 384 |
| 385 AllocationSpace Heap::TargetSpaceId(InstanceType type) { |
| 386 // Heap numbers and sequential strings are promoted to old data space, all |
| 387 // other object types are promoted to old pointer space. We do not use |
| 388 // object->IsHeapNumber() and object->IsSeqString() because we already |
| 389 // know that object has the heap object tag. |
| 390 |
| 391 // These objects are never allocated in new space. |
| 392 DCHECK(type != MAP_TYPE); |
| 393 DCHECK(type != CODE_TYPE); |
| 394 DCHECK(type != ODDBALL_TYPE); |
| 395 DCHECK(type != CELL_TYPE); |
| 396 |
| 397 if (type <= LAST_NAME_TYPE) { |
| 398 if (type == SYMBOL_TYPE) return OLD_POINTER_SPACE; |
| 399 DCHECK(type < FIRST_NONSTRING_TYPE); |
| 400 // There are four string representations: sequential strings, external |
| 401 // strings, cons strings, and sliced strings. |
| 402 // Only the latter two contain non-map-word pointers to heap objects. |
| 403 return ((type & kIsIndirectStringMask) == kIsIndirectStringTag) |
| 404 ? OLD_POINTER_SPACE |
| 405 : OLD_DATA_SPACE; |
| 406 } else { |
| 407 return (type <= LAST_DATA_TYPE) ? OLD_DATA_SPACE : OLD_POINTER_SPACE; |
| 408 } |
| 409 } |
| 410 |
| 411 |
| 364 bool Heap::AllowedToBeMigrated(HeapObject* obj, AllocationSpace dst) { | 412 bool Heap::AllowedToBeMigrated(HeapObject* obj, AllocationSpace dst) { |
| 365 // Object migration is governed by the following rules: | 413 // Object migration is governed by the following rules: |
| 366 // | 414 // |
| 367 // 1) Objects in new-space can be migrated to the old space | 415 // 1) Objects in new-space can be migrated to one of the old spaces |
| 368 // that matches their target space or they stay in new-space. | 416 // that matches their target space or they stay in new-space. |
| 369 // 2) Objects in old-space stay in the same space when migrating. | 417 // 2) Objects in old-space stay in the same space when migrating. |
| 370 // 3) Fillers (two or more words) can migrate due to left-trimming of | 418 // 3) Fillers (two or more words) can migrate due to left-trimming of |
| 371 // fixed arrays in new-space or old space. | 419 // fixed arrays in new-space, old-data-space and old-pointer-space. |
| 372 // 4) Fillers (one word) can never migrate, they are skipped by | 420 // 4) Fillers (one word) can never migrate, they are skipped by |
| 373 // incremental marking explicitly to prevent invalid pattern. | 421 // incremental marking explicitly to prevent invalid pattern. |
| 422 // 5) Short external strings can end up in old pointer space when a cons |
| 423 // string in old pointer space is made external (String::MakeExternal). |
| 374 // | 424 // |
| 375 // Since this function is used for debugging only, we do not place | 425 // Since this function is used for debugging only, we do not place |
| 376 // asserts here, but check everything explicitly. | 426 // asserts here, but check everything explicitly. |
| 377 if (obj->map() == one_pointer_filler_map()) return false; | 427 if (obj->map() == one_pointer_filler_map()) return false; |
| 378 InstanceType type = obj->map()->instance_type(); | 428 InstanceType type = obj->map()->instance_type(); |
| 379 MemoryChunk* chunk = MemoryChunk::FromAddress(obj->address()); | 429 MemoryChunk* chunk = MemoryChunk::FromAddress(obj->address()); |
| 380 AllocationSpace src = chunk->owner()->identity(); | 430 AllocationSpace src = chunk->owner()->identity(); |
| 381 switch (src) { | 431 switch (src) { |
| 382 case NEW_SPACE: | 432 case NEW_SPACE: |
| 383 return dst == src || dst == OLD_SPACE; | 433 return dst == src || dst == TargetSpaceId(type); |
| 384 case OLD_SPACE: | 434 case OLD_POINTER_SPACE: |
| 385 return dst == src && | 435 return dst == src && (dst == TargetSpaceId(type) || obj->IsFiller() || |
| 386 (dst == OLD_SPACE || obj->IsFiller() || obj->IsExternalString()); | 436 obj->IsExternalString()); |
| 437 case OLD_DATA_SPACE: |
| 438 return dst == src && dst == TargetSpaceId(type); |
| 387 case CODE_SPACE: | 439 case CODE_SPACE: |
| 388 return dst == src && type == CODE_TYPE; | 440 return dst == src && type == CODE_TYPE; |
| 389 case MAP_SPACE: | 441 case MAP_SPACE: |
| 390 case CELL_SPACE: | 442 case CELL_SPACE: |
| 391 case LO_SPACE: | 443 case LO_SPACE: |
| 392 return false; | 444 return false; |
| 393 } | 445 } |
| 394 UNREACHABLE(); | 446 UNREACHABLE(); |
| 395 return false; | 447 return false; |
| 396 } | 448 } |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 | 739 |
| 688 void VerifySmisVisitor::VisitPointers(Object** start, Object** end) { | 740 void VerifySmisVisitor::VisitPointers(Object** start, Object** end) { |
| 689 for (Object** current = start; current < end; current++) { | 741 for (Object** current = start; current < end; current++) { |
| 690 CHECK((*current)->IsSmi()); | 742 CHECK((*current)->IsSmi()); |
| 691 } | 743 } |
| 692 } | 744 } |
| 693 } | 745 } |
| 694 } // namespace v8::internal | 746 } // namespace v8::internal |
| 695 | 747 |
| 696 #endif // V8_HEAP_HEAP_INL_H_ | 748 #endif // V8_HEAP_HEAP_INL_H_ |
| OLD | NEW |