Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 } | 332 } |
| 333 } | 333 } |
| 334 | 334 |
| 335 void set_owner(Space* space) { | 335 void set_owner(Space* space) { |
| 336 ASSERT((reinterpret_cast<intptr_t>(space) & kFailureTagMask) == 0); | 336 ASSERT((reinterpret_cast<intptr_t>(space) & kFailureTagMask) == 0); |
| 337 owner_ = reinterpret_cast<Address>(space) + kFailureTag; | 337 owner_ = reinterpret_cast<Address>(space) + kFailureTag; |
| 338 ASSERT((reinterpret_cast<intptr_t>(owner_) & kFailureTagMask) == | 338 ASSERT((reinterpret_cast<intptr_t>(owner_) & kFailureTagMask) == |
| 339 kFailureTag); | 339 kFailureTag); |
| 340 } | 340 } |
| 341 | 341 |
| 342 bool scan_on_scavenge() { return scan_on_scavenge_; } | 342 bool scan_on_scavenge() { return IsFlagSet(SCAN_ON_SCAVENGE); } |
| 343 void initialize_scan_on_scavenge(bool scan) { scan_on_scavenge_ = scan; } | 343 void initialize_scan_on_scavenge(bool scan) { |
| 344 if (scan) { | |
| 345 SetFlag(SCAN_ON_SCAVENGE); | |
| 346 } else { | |
| 347 ClearFlag(SCAN_ON_SCAVENGE); | |
| 348 } | |
| 349 } | |
| 344 inline void set_scan_on_scavenge(bool scan); | 350 inline void set_scan_on_scavenge(bool scan); |
| 345 | 351 |
| 346 int store_buffer_counter() { return store_buffer_counter_; } | 352 int store_buffer_counter() { return store_buffer_counter_; } |
| 347 void set_store_buffer_counter(int counter) { | 353 void set_store_buffer_counter(int counter) { |
| 348 store_buffer_counter_ = counter; | 354 store_buffer_counter_ = counter; |
| 349 } | 355 } |
| 350 | 356 |
| 351 Address body() { return address() + kObjectStartOffset; } | 357 Address body() { return address() + kObjectStartOffset; } |
| 352 | 358 |
| 353 int body_size() { return size() - kObjectStartOffset; } | 359 int body_size() { return size() - kObjectStartOffset; } |
| 354 | 360 |
| 355 bool Contains(Address addr) { | 361 bool Contains(Address addr) { |
| 356 return addr >= body() && addr < address() + size(); | 362 return addr >= body() && addr < address() + size(); |
| 357 } | 363 } |
| 358 | 364 |
| 359 enum MemoryChunkFlags { | 365 enum MemoryChunkFlags { |
| 360 IS_EXECUTABLE, | 366 IS_EXECUTABLE, |
| 361 WAS_SWEPT_CONSERVATIVELY, | 367 WAS_SWEPT_CONSERVATIVELY, |
| 362 CONTAINS_ONLY_DATA, | 368 CONTAINS_ONLY_DATA, |
| 369 CONTAINS_INTERESTING_VALUES, | |
| 370 CONTAINS_INTERESTING_DESTINATIONS, | |
|
Erik Corry
2011/05/11 18:53:57
I don't like these names. If a pointer points fro
Vyacheslav Egorov (Chromium)
2011/05/13 11:06:52
Done.
| |
| 371 SCAN_ON_SCAVENGE, | |
| 363 NUM_MEMORY_CHUNK_FLAGS | 372 NUM_MEMORY_CHUNK_FLAGS |
| 364 }; | 373 }; |
| 365 | 374 |
| 366 void SetFlag(int flag) { | 375 void SetFlag(int flag) { |
| 367 flags_ |= 1 << flag; | 376 flags_ |= 1 << flag; |
| 368 } | 377 } |
| 369 | 378 |
| 370 void ClearFlag(int flag) { | 379 void ClearFlag(int flag) { |
| 371 flags_ &= ~(1 << flag); | 380 flags_ &= ~(1 << flag); |
| 372 } | 381 } |
| 373 | 382 |
| 374 bool IsFlagSet(int flag) { | 383 bool IsFlagSet(int flag) { |
| 375 return (flags_ & (1 << flag)) != 0; | 384 return (flags_ & (1 << flag)) != 0; |
| 376 } | 385 } |
| 377 | 386 |
| 387 void CopyFlagsFrom(MemoryChunk* chunk) { | |
| 388 flags_ = chunk->flags_; | |
| 389 } | |
| 390 | |
| 378 static const intptr_t kAlignment = (1 << kPageSizeBits); | 391 static const intptr_t kAlignment = (1 << kPageSizeBits); |
| 379 | 392 |
| 380 static const intptr_t kAlignmentMask = kAlignment - 1; | 393 static const intptr_t kAlignmentMask = kAlignment - 1; |
| 381 | 394 |
| 382 static const size_t kHeaderSize = kPointerSize + kPointerSize + kPointerSize + | 395 static const size_t kHeaderSize = kPointerSize + kPointerSize + kPointerSize + |
| 383 kPointerSize + kPointerSize + kPointerSize + kPointerSize + kPointerSize; | 396 kPointerSize + kPointerSize + kPointerSize + kPointerSize + kPointerSize; |
| 384 | 397 |
| 385 static const size_t kMarksBitmapLength = | 398 static const size_t kMarksBitmapLength = |
| 386 (1 << kPageSizeBits) >> (kPointerSizeLog2); | 399 (1 << kPageSizeBits) >> (kPointerSizeLog2); |
| 387 | 400 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 441 inline Address MarkbitIndexToAddress(uint32_t index) { | 454 inline Address MarkbitIndexToAddress(uint32_t index) { |
| 442 return this->address() + (index << kPointerSizeLog2); | 455 return this->address() + (index << kPointerSizeLog2); |
| 443 } | 456 } |
| 444 | 457 |
| 445 void InsertAfter(MemoryChunk* other); | 458 void InsertAfter(MemoryChunk* other); |
| 446 void Unlink(); | 459 void Unlink(); |
| 447 | 460 |
| 448 inline Heap* heap() { return heap_; } | 461 inline Heap* heap() { return heap_; } |
| 449 | 462 |
| 450 static const int kFlagsOffset = kPointerSize * 3; | 463 static const int kFlagsOffset = kPointerSize * 3; |
| 451 static const int kScanOnScavengeOffset = kPointerSize * 6; | |
| 452 | 464 |
| 453 protected: | 465 protected: |
| 454 MemoryChunk* next_chunk_; | 466 MemoryChunk* next_chunk_; |
| 455 MemoryChunk* prev_chunk_; | 467 MemoryChunk* prev_chunk_; |
| 456 size_t size_; | 468 size_t size_; |
| 457 intptr_t flags_; | 469 intptr_t flags_; |
| 458 // The identity of the owning space. This is tagged as a failure pointer, but | 470 // The identity of the owning space. This is tagged as a failure pointer, but |
| 459 // no failure can be in an object, so this can be distinguished from any entry | 471 // no failure can be in an object, so this can be distinguished from any entry |
| 460 // in a fixed array. | 472 // in a fixed array. |
| 461 Address owner_; | 473 Address owner_; |
| 462 Heap* heap_; | 474 Heap* heap_; |
| 463 // This flag indicates that the page is not being tracked by the store buffer. | |
| 464 // At any point where we have to iterate over pointers to new space, we must | |
| 465 // search this page for pointers to new space. | |
| 466 bool scan_on_scavenge_; | |
| 467 // Used by the store buffer to keep track of which pages to mark scan-on- | 475 // Used by the store buffer to keep track of which pages to mark scan-on- |
| 468 // scavenge. | 476 // scavenge. |
| 469 int store_buffer_counter_; | 477 int store_buffer_counter_; |
| 470 | 478 |
| 471 static MemoryChunk* Initialize(Heap* heap, | 479 static MemoryChunk* Initialize(Heap* heap, |
| 472 Address base, | 480 Address base, |
| 473 size_t size, | 481 size_t size, |
| 474 Executability executable, | 482 Executability executable, |
| 475 Space* owner); | 483 Space* owner); |
| 476 | 484 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 579 } | 587 } |
| 580 | 588 |
| 581 inline LargePage* next_page() const { | 589 inline LargePage* next_page() const { |
| 582 return static_cast<LargePage*>(next_chunk()); | 590 return static_cast<LargePage*>(next_chunk()); |
| 583 } | 591 } |
| 584 | 592 |
| 585 inline void set_next_page(LargePage* page) { | 593 inline void set_next_page(LargePage* page) { |
| 586 set_next_chunk(page); | 594 set_next_chunk(page); |
| 587 } | 595 } |
| 588 private: | 596 private: |
| 589 static LargePage* Initialize(Heap* heap, | 597 static inline LargePage* Initialize(Heap* heap, MemoryChunk* chunk); |
| 590 MemoryChunk* chunk) { | |
| 591 // TODO(gc) ISOLATESMERGE initialize chunk to point to heap? | |
| 592 return static_cast<LargePage*>(chunk); | |
| 593 } | |
| 594 | 598 |
| 595 friend class MemoryAllocator; | 599 friend class MemoryAllocator; |
| 596 }; | 600 }; |
| 597 | 601 |
| 598 STATIC_CHECK(sizeof(LargePage) <= MemoryChunk::kHeaderSize); | 602 STATIC_CHECK(sizeof(LargePage) <= MemoryChunk::kHeaderSize); |
| 599 | 603 |
| 600 // ---------------------------------------------------------------------------- | 604 // ---------------------------------------------------------------------------- |
| 601 // Space is the abstract superclass for all allocation spaces. | 605 // Space is the abstract superclass for all allocation spaces. |
| 602 class Space : public Malloced { | 606 class Space : public Malloced { |
| 603 public: | 607 public: |
| (...skipping 1251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1855 | 1859 |
| 1856 bool UncommitFromSpace() { | 1860 bool UncommitFromSpace() { |
| 1857 if (!from_space_.is_committed()) return true; | 1861 if (!from_space_.is_committed()) return true; |
| 1858 return from_space_.Uncommit(); | 1862 return from_space_.Uncommit(); |
| 1859 } | 1863 } |
| 1860 | 1864 |
| 1861 inline intptr_t inline_alloction_limit_step() { | 1865 inline intptr_t inline_alloction_limit_step() { |
| 1862 return inline_alloction_limit_step_; | 1866 return inline_alloction_limit_step_; |
| 1863 } | 1867 } |
| 1864 | 1868 |
| 1869 NewSpacePage* ActivePage() { | |
| 1870 return to_space_.current_page(); | |
| 1871 } | |
| 1872 | |
| 1865 private: | 1873 private: |
| 1866 Address chunk_base_; | 1874 Address chunk_base_; |
| 1867 uintptr_t chunk_size_; | 1875 uintptr_t chunk_size_; |
| 1868 | 1876 |
| 1869 // The semispaces. | 1877 // The semispaces. |
| 1870 SemiSpace to_space_; | 1878 SemiSpace to_space_; |
| 1871 SemiSpace from_space_; | 1879 SemiSpace from_space_; |
| 1872 | 1880 |
| 1873 // Start address and bit mask for containment testing. | 1881 // Start address and bit mask for containment testing. |
| 1874 Address start_; | 1882 Address start_; |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2124 // called after ReserveSpace has been called on the paged spaces, since they | 2132 // called after ReserveSpace has been called on the paged spaces, since they |
| 2125 // may use some memory, leaving less for large objects. | 2133 // may use some memory, leaving less for large objects. |
| 2126 virtual bool ReserveSpace(int bytes); | 2134 virtual bool ReserveSpace(int bytes); |
| 2127 | 2135 |
| 2128 #ifdef ENABLE_HEAP_PROTECTION | 2136 #ifdef ENABLE_HEAP_PROTECTION |
| 2129 // Protect/unprotect the space by marking it read-only/writable. | 2137 // Protect/unprotect the space by marking it read-only/writable. |
| 2130 void Protect(); | 2138 void Protect(); |
| 2131 void Unprotect(); | 2139 void Unprotect(); |
| 2132 #endif | 2140 #endif |
| 2133 | 2141 |
| 2142 LargePage* first_page() { return first_page_; } | |
| 2143 | |
| 2134 #ifdef DEBUG | 2144 #ifdef DEBUG |
| 2135 virtual void Verify(); | 2145 virtual void Verify(); |
| 2136 virtual void Print(); | 2146 virtual void Print(); |
| 2137 void ReportStatistics(); | 2147 void ReportStatistics(); |
| 2138 void CollectCodeStatistics(); | 2148 void CollectCodeStatistics(); |
| 2139 #endif | 2149 #endif |
| 2140 // Checks whether an address is in the object area in this space. It | 2150 // Checks whether an address is in the object area in this space. It |
| 2141 // iterates all objects in the space. May be slow. | 2151 // iterates all objects in the space. May be slow. |
| 2142 bool SlowContains(Address addr) { return !FindObject(addr)->IsFailure(); } | 2152 bool SlowContains(Address addr) { return !FindObject(addr)->IsFailure(); } |
| 2143 | 2153 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2249 } | 2259 } |
| 2250 // Must be small, since an iteration is used for lookup. | 2260 // Must be small, since an iteration is used for lookup. |
| 2251 static const int kMaxComments = 64; | 2261 static const int kMaxComments = 64; |
| 2252 }; | 2262 }; |
| 2253 #endif | 2263 #endif |
| 2254 | 2264 |
| 2255 | 2265 |
| 2256 } } // namespace v8::internal | 2266 } } // namespace v8::internal |
| 2257 | 2267 |
| 2258 #endif // V8_SPACES_H_ | 2268 #endif // V8_SPACES_H_ |
| OLD | NEW |