Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: src/heap/heap-inl.h

Issue 1051233002: Reland "Merge old data and pointer space." (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/heap/heap.cc ('k') | src/heap/incremental-marking.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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, OLD_DATA_SPACE, TENURED); 84 AllocationSpace space = SelectSpace(size, TENURED);
85 85
86 // Allocate string. 86 // Allocate string.
87 HeapObject* result; 87 HeapObject* result;
88 { 88 {
89 AllocationResult allocation = AllocateRaw(size, space, OLD_DATA_SPACE); 89 AllocationResult allocation = AllocateRaw(size, space, OLD_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, OLD_DATA_SPACE, TENURED); 116 AllocationSpace space = SelectSpace(size, TENURED);
117 117
118 // Allocate string. 118 // Allocate string.
119 HeapObject* result; 119 HeapObject* result;
120 { 120 {
121 AllocationResult allocation = AllocateRaw(size, space, OLD_DATA_SPACE); 121 AllocationResult allocation = AllocateRaw(size, space, OLD_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
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_POINTER_SPACE == space) { 186 if (OLD_SPACE == space) {
187 allocation = old_pointer_space_->AllocateRaw(size_in_bytes); 187 allocation = old_space_->AllocateRaw(size_in_bytes);
188 } else if (OLD_DATA_SPACE == space) {
189 allocation = old_data_space_->AllocateRaw(size_in_bytes);
190 } else if (CODE_SPACE == space) { 188 } else if (CODE_SPACE == space) {
191 if (size_in_bytes <= code_space()->AreaSize()) { 189 if (size_in_bytes <= code_space()->AreaSize()) {
192 allocation = code_space_->AllocateRaw(size_in_bytes); 190 allocation = code_space_->AllocateRaw(size_in_bytes);
193 } else { 191 } else {
194 // Large code objects are allocated in large object space. 192 // Large code objects are allocated in large object space.
195 allocation = lo_space_->AllocateRaw(size_in_bytes, EXECUTABLE); 193 allocation = lo_space_->AllocateRaw(size_in_bytes, EXECUTABLE);
196 } 194 }
197 } else if (LO_SPACE == space) { 195 } else if (LO_SPACE == space) {
198 allocation = lo_space_->AllocateRaw(size_in_bytes, NOT_EXECUTABLE); 196 allocation = lo_space_->AllocateRaw(size_in_bytes, NOT_EXECUTABLE);
199 } else if (CELL_SPACE == space) { 197 } else if (CELL_SPACE == space) {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 bool Heap::InFromSpace(Object* object) { 318 bool Heap::InFromSpace(Object* object) {
321 return new_space_.FromSpaceContains(object); 319 return new_space_.FromSpaceContains(object);
322 } 320 }
323 321
324 322
325 bool Heap::InToSpace(Object* object) { 323 bool Heap::InToSpace(Object* object) {
326 return new_space_.ToSpaceContains(object); 324 return new_space_.ToSpaceContains(object);
327 } 325 }
328 326
329 327
330 bool Heap::InOldPointerSpace(Address address) { 328 bool Heap::InOldSpace(Address address) { return old_space_->Contains(address); }
331 return old_pointer_space_->Contains(address); 329
330
331 bool Heap::InOldSpace(Object* object) {
332 return InOldSpace(reinterpret_cast<Address>(object));
332 } 333 }
333 334
334 335
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
350 bool Heap::OldGenerationAllocationLimitReached() { 336 bool Heap::OldGenerationAllocationLimitReached() {
351 if (!incremental_marking()->IsStopped()) return false; 337 if (!incremental_marking()->IsStopped()) return false;
352 return OldGenerationSpaceAvailable() < 0; 338 return OldGenerationSpaceAvailable() < 0;
353 } 339 }
354 340
355 341
356 bool Heap::ShouldBePromoted(Address old_address, int object_size) { 342 bool Heap::ShouldBePromoted(Address old_address, int object_size) {
357 NewSpacePage* page = NewSpacePage::FromAddress(old_address); 343 NewSpacePage* page = NewSpacePage::FromAddress(old_address);
358 Address age_mark = new_space_.age_mark(); 344 Address age_mark = new_space_.age_mark();
359 return page->IsFlagSet(MemoryChunk::NEW_SPACE_BELOW_AGE_MARK) && 345 return page->IsFlagSet(MemoryChunk::NEW_SPACE_BELOW_AGE_MARK) &&
360 (!page->ContainsLimit(age_mark) || old_address < age_mark); 346 (!page->ContainsLimit(age_mark) || old_address < age_mark);
361 } 347 }
362 348
363 349
364 void Heap::RecordWrite(Address address, int offset) { 350 void Heap::RecordWrite(Address address, int offset) {
365 if (!InNewSpace(address)) store_buffer_.Mark(address + offset); 351 if (!InNewSpace(address)) store_buffer_.Mark(address + offset);
366 } 352 }
367 353
368 354
369 void Heap::RecordWrites(Address address, int start, int len) { 355 void Heap::RecordWrites(Address address, int start, int len) {
370 if (!InNewSpace(address)) { 356 if (!InNewSpace(address)) {
371 for (int i = 0; i < len; i++) { 357 for (int i = 0; i < len; i++) {
372 store_buffer_.Mark(address + start + i * kPointerSize); 358 store_buffer_.Mark(address + start + i * kPointerSize);
373 } 359 }
374 } 360 }
375 } 361 }
376 362
377 363
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
412 bool Heap::AllowedToBeMigrated(HeapObject* obj, AllocationSpace dst) { 364 bool Heap::AllowedToBeMigrated(HeapObject* obj, AllocationSpace dst) {
413 // Object migration is governed by the following rules: 365 // Object migration is governed by the following rules:
414 // 366 //
415 // 1) Objects in new-space can be migrated to one of the old spaces 367 // 1) Objects in new-space can be migrated to the old space
416 // that matches their target space or they stay in new-space. 368 // that matches their target space or they stay in new-space.
417 // 2) Objects in old-space stay in the same space when migrating. 369 // 2) Objects in old-space stay in the same space when migrating.
418 // 3) Fillers (two or more words) can migrate due to left-trimming of 370 // 3) Fillers (two or more words) can migrate due to left-trimming of
419 // fixed arrays in new-space, old-data-space and old-pointer-space. 371 // fixed arrays in new-space or old space.
420 // 4) Fillers (one word) can never migrate, they are skipped by 372 // 4) Fillers (one word) can never migrate, they are skipped by
421 // incremental marking explicitly to prevent invalid pattern. 373 // 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).
424 // 374 //
425 // Since this function is used for debugging only, we do not place 375 // Since this function is used for debugging only, we do not place
426 // asserts here, but check everything explicitly. 376 // asserts here, but check everything explicitly.
427 if (obj->map() == one_pointer_filler_map()) return false; 377 if (obj->map() == one_pointer_filler_map()) return false;
428 InstanceType type = obj->map()->instance_type(); 378 InstanceType type = obj->map()->instance_type();
429 MemoryChunk* chunk = MemoryChunk::FromAddress(obj->address()); 379 MemoryChunk* chunk = MemoryChunk::FromAddress(obj->address());
430 AllocationSpace src = chunk->owner()->identity(); 380 AllocationSpace src = chunk->owner()->identity();
431 switch (src) { 381 switch (src) {
432 case NEW_SPACE: 382 case NEW_SPACE:
433 return dst == src || dst == TargetSpaceId(type); 383 return dst == src || dst == OLD_SPACE;
434 case OLD_POINTER_SPACE: 384 case OLD_SPACE:
435 return dst == src && (dst == TargetSpaceId(type) || obj->IsFiller() || 385 return dst == src &&
436 obj->IsExternalString()); 386 (dst == OLD_SPACE || obj->IsFiller() || obj->IsExternalString());
437 case OLD_DATA_SPACE:
438 return dst == src && dst == TargetSpaceId(type);
439 case CODE_SPACE: 387 case CODE_SPACE:
440 return dst == src && type == CODE_TYPE; 388 return dst == src && type == CODE_TYPE;
441 case MAP_SPACE: 389 case MAP_SPACE:
442 case CELL_SPACE: 390 case CELL_SPACE:
443 case LO_SPACE: 391 case LO_SPACE:
444 return false; 392 return false;
445 } 393 }
446 UNREACHABLE(); 394 UNREACHABLE();
447 return false; 395 return false;
448 } 396 }
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 681
734 void VerifySmisVisitor::VisitPointers(Object** start, Object** end) { 682 void VerifySmisVisitor::VisitPointers(Object** start, Object** end) {
735 for (Object** current = start; current < end; current++) { 683 for (Object** current = start; current < end; current++) {
736 CHECK((*current)->IsSmi()); 684 CHECK((*current)->IsSmi());
737 } 685 }
738 } 686 }
739 } 687 }
740 } // namespace v8::internal 688 } // namespace v8::internal
741 689
742 #endif // V8_HEAP_HEAP_INL_H_ 690 #endif // V8_HEAP_HEAP_INL_H_
OLDNEW
« no previous file with comments | « src/heap/heap.cc ('k') | src/heap/incremental-marking.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698