| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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_SPACES_H_ | 5 #ifndef V8_HEAP_SPACES_H_ |
| 6 #define V8_HEAP_SPACES_H_ | 6 #define V8_HEAP_SPACES_H_ |
| 7 | 7 |
| 8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
| 9 #include "src/atomic-utils.h" | 9 #include "src/atomic-utils.h" |
| 10 #include "src/base/atomicops.h" | 10 #include "src/base/atomicops.h" |
| 11 #include "src/base/bits.h" | 11 #include "src/base/bits.h" |
| 12 #include "src/base/platform/mutex.h" | 12 #include "src/base/platform/mutex.h" |
| 13 #include "src/flags.h" | 13 #include "src/flags.h" |
| 14 #include "src/hashmap.h" | 14 #include "src/hashmap.h" |
| 15 #include "src/list.h" | 15 #include "src/list.h" |
| 16 #include "src/objects.h" | 16 #include "src/objects.h" |
| 17 #include "src/utils.h" | 17 #include "src/utils.h" |
| 18 | 18 |
| 19 namespace v8 { | 19 namespace v8 { |
| 20 namespace internal { | 20 namespace internal { |
| 21 | 21 |
| 22 class CompactionSpaceCollection; | 22 class CompactionSpaceCollection; |
| 23 class InlineAllocationObserver; |
| 23 class Isolate; | 24 class Isolate; |
| 24 | 25 |
| 25 // ----------------------------------------------------------------------------- | 26 // ----------------------------------------------------------------------------- |
| 26 // Heap structures: | 27 // Heap structures: |
| 27 // | 28 // |
| 28 // A JS heap consists of a young generation, an old generation, and a large | 29 // A JS heap consists of a young generation, an old generation, and a large |
| 29 // object space. The young generation is divided into two semispaces. A | 30 // object space. The young generation is divided into two semispaces. A |
| 30 // scavenger implements Cheney's copying algorithm. The old generation is | 31 // scavenger implements Cheney's copying algorithm. The old generation is |
| 31 // separated into a map space and an old object space. The map space contains | 32 // separated into a map space and an old object space. The map space contains |
| 32 // all (and only) map objects, the rest of old objects go into the old space. | 33 // all (and only) map objects, the rest of old objects go into the old space. |
| (...skipping 2527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2560 | 2561 |
| 2561 private: | 2562 private: |
| 2562 NewSpacePage* prev_page_; // Previous page returned. | 2563 NewSpacePage* prev_page_; // Previous page returned. |
| 2563 // Next page that will be returned. Cached here so that we can use this | 2564 // Next page that will be returned. Cached here so that we can use this |
| 2564 // iterator for operations that deallocate pages. | 2565 // iterator for operations that deallocate pages. |
| 2565 NewSpacePage* next_page_; | 2566 NewSpacePage* next_page_; |
| 2566 // Last page returned. | 2567 // Last page returned. |
| 2567 NewSpacePage* last_page_; | 2568 NewSpacePage* last_page_; |
| 2568 }; | 2569 }; |
| 2569 | 2570 |
| 2570 // ----------------------------------------------------------------------------- | |
| 2571 // Allows observation of inline allocation in the new space. | |
| 2572 class InlineAllocationObserver { | |
| 2573 public: | |
| 2574 explicit InlineAllocationObserver(intptr_t step_size) | |
| 2575 : step_size_(step_size), bytes_to_next_step_(step_size) { | |
| 2576 DCHECK(step_size >= kPointerSize); | |
| 2577 } | |
| 2578 virtual ~InlineAllocationObserver() {} | |
| 2579 | |
| 2580 private: | |
| 2581 intptr_t step_size() const { return step_size_; } | |
| 2582 intptr_t bytes_to_next_step() const { return bytes_to_next_step_; } | |
| 2583 | |
| 2584 // Pure virtual method provided by the subclasses that gets called when at | |
| 2585 // least step_size bytes have been allocated. soon_object is the address just | |
| 2586 // allocated (but not yet initialized.) size is the size of the object as | |
| 2587 // requested (i.e. w/o the alignment fillers). Some complexities to be aware | |
| 2588 // of: | |
| 2589 // 1) soon_object will be nullptr in cases where we end up observing an | |
| 2590 // allocation that happens to be a filler space (e.g. page boundaries.) | |
| 2591 // 2) size is the requested size at the time of allocation. Right-trimming | |
| 2592 // may change the object size dynamically. | |
| 2593 // 3) soon_object may actually be the first object in an allocation-folding | |
| 2594 // group. In such a case size is the size of the group rather than the | |
| 2595 // first object. | |
| 2596 virtual void Step(int bytes_allocated, Address soon_object, size_t size) = 0; | |
| 2597 | |
| 2598 // Called each time the new space does an inline allocation step. This may be | |
| 2599 // more frequently than the step_size we are monitoring (e.g. when there are | |
| 2600 // multiple observers, or when page or space boundary is encountered.) | |
| 2601 void InlineAllocationStep(int bytes_allocated, Address soon_object, | |
| 2602 size_t size) { | |
| 2603 bytes_to_next_step_ -= bytes_allocated; | |
| 2604 if (bytes_to_next_step_ <= 0) { | |
| 2605 Step(static_cast<int>(step_size_ - bytes_to_next_step_), soon_object, | |
| 2606 size); | |
| 2607 bytes_to_next_step_ = step_size_; | |
| 2608 } | |
| 2609 } | |
| 2610 | |
| 2611 intptr_t step_size_; | |
| 2612 intptr_t bytes_to_next_step_; | |
| 2613 | |
| 2614 friend class NewSpace; | |
| 2615 | |
| 2616 DISALLOW_COPY_AND_ASSIGN(InlineAllocationObserver); | |
| 2617 }; | |
| 2618 | 2571 |
| 2619 // ----------------------------------------------------------------------------- | 2572 // ----------------------------------------------------------------------------- |
| 2620 // The young generation space. | 2573 // The young generation space. |
| 2621 // | 2574 // |
| 2622 // The new space consists of a contiguous pair of semispaces. It simply | 2575 // The new space consists of a contiguous pair of semispaces. It simply |
| 2623 // forwards most functions to the appropriate semispace. | 2576 // forwards most functions to the appropriate semispace. |
| 2624 | 2577 |
| 2625 class NewSpace : public Space { | 2578 class NewSpace : public Space { |
| 2626 public: | 2579 public: |
| 2627 // Constructor. | 2580 // Constructor. |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3220 count = 0; | 3173 count = 0; |
| 3221 } | 3174 } |
| 3222 // Must be small, since an iteration is used for lookup. | 3175 // Must be small, since an iteration is used for lookup. |
| 3223 static const int kMaxComments = 64; | 3176 static const int kMaxComments = 64; |
| 3224 }; | 3177 }; |
| 3225 #endif | 3178 #endif |
| 3226 } // namespace internal | 3179 } // namespace internal |
| 3227 } // namespace v8 | 3180 } // namespace v8 |
| 3228 | 3181 |
| 3229 #endif // V8_HEAP_SPACES_H_ | 3182 #endif // V8_HEAP_SPACES_H_ |
| OLD | NEW |