| 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" |
| (...skipping 2559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2570 // ----------------------------------------------------------------------------- | 2570 // ----------------------------------------------------------------------------- |
| 2571 // Allows observation of inline allocation in the new space. | 2571 // Allows observation of inline allocation in the new space. |
| 2572 class InlineAllocationObserver { | 2572 class InlineAllocationObserver { |
| 2573 public: | 2573 public: |
| 2574 explicit InlineAllocationObserver(intptr_t step_size) | 2574 explicit InlineAllocationObserver(intptr_t step_size) |
| 2575 : step_size_(step_size), bytes_to_next_step_(step_size) { | 2575 : step_size_(step_size), bytes_to_next_step_(step_size) { |
| 2576 DCHECK(step_size >= kPointerSize); | 2576 DCHECK(step_size >= kPointerSize); |
| 2577 } | 2577 } |
| 2578 virtual ~InlineAllocationObserver() {} | 2578 virtual ~InlineAllocationObserver() {} |
| 2579 | 2579 |
| 2580 private: | 2580 // Called each time the new space does an inline allocation step. This may be |
| 2581 // more frequently than the step_size we are monitoring (e.g. when there are |
| 2582 // multiple observers, or when page or space boundary is encountered.) |
| 2583 void InlineAllocationStep(int bytes_allocated, Address soon_object, |
| 2584 size_t size) { |
| 2585 bytes_to_next_step_ -= bytes_allocated; |
| 2586 if (bytes_to_next_step_ <= 0) { |
| 2587 Step(static_cast<int>(step_size_ - bytes_to_next_step_), soon_object, |
| 2588 size); |
| 2589 step_size_ = GetNextStepSize(); |
| 2590 bytes_to_next_step_ = step_size_; |
| 2591 } |
| 2592 } |
| 2593 |
| 2594 protected: |
| 2581 intptr_t step_size() const { return step_size_; } | 2595 intptr_t step_size() const { return step_size_; } |
| 2582 intptr_t bytes_to_next_step() const { return bytes_to_next_step_; } | 2596 intptr_t bytes_to_next_step() const { return bytes_to_next_step_; } |
| 2583 | 2597 |
| 2584 // Pure virtual method provided by the subclasses that gets called when at | 2598 // 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 | 2599 // 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 | 2600 // 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 | 2601 // requested (i.e. w/o the alignment fillers). Some complexities to be aware |
| 2588 // of: | 2602 // of: |
| 2589 // 1) soon_object will be nullptr in cases where we end up observing an | 2603 // 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.) | 2604 // 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 | 2605 // 2) size is the requested size at the time of allocation. Right-trimming |
| 2592 // may change the object size dynamically. | 2606 // may change the object size dynamically. |
| 2593 // 3) soon_object may actually be the first object in an allocation-folding | 2607 // 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 | 2608 // group. In such a case size is the size of the group rather than the |
| 2595 // first object. | 2609 // first object. |
| 2596 virtual void Step(int bytes_allocated, Address soon_object, size_t size) = 0; | 2610 virtual void Step(int bytes_allocated, Address soon_object, size_t size) = 0; |
| 2597 | 2611 |
| 2598 // Called each time the new space does an inline allocation step. This may be | 2612 // Subclasses can override this method to make step size dynamic. |
| 2599 // more frequently than the step_size we are monitoring (e.g. when there are | 2613 virtual intptr_t GetNextStepSize() { return step_size_; } |
| 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 | 2614 |
| 2611 intptr_t step_size_; | 2615 intptr_t step_size_; |
| 2612 intptr_t bytes_to_next_step_; | 2616 intptr_t bytes_to_next_step_; |
| 2613 | 2617 |
| 2618 private: |
| 2614 friend class NewSpace; | 2619 friend class NewSpace; |
| 2615 | |
| 2616 DISALLOW_COPY_AND_ASSIGN(InlineAllocationObserver); | 2620 DISALLOW_COPY_AND_ASSIGN(InlineAllocationObserver); |
| 2617 }; | 2621 }; |
| 2618 | 2622 |
| 2619 // ----------------------------------------------------------------------------- | 2623 // ----------------------------------------------------------------------------- |
| 2620 // The young generation space. | 2624 // The young generation space. |
| 2621 // | 2625 // |
| 2622 // The new space consists of a contiguous pair of semispaces. It simply | 2626 // The new space consists of a contiguous pair of semispaces. It simply |
| 2623 // forwards most functions to the appropriate semispace. | 2627 // forwards most functions to the appropriate semispace. |
| 2624 | 2628 |
| 2625 class NewSpace : public Space { | 2629 class NewSpace : public Space { |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3220 count = 0; | 3224 count = 0; |
| 3221 } | 3225 } |
| 3222 // Must be small, since an iteration is used for lookup. | 3226 // Must be small, since an iteration is used for lookup. |
| 3223 static const int kMaxComments = 64; | 3227 static const int kMaxComments = 64; |
| 3224 }; | 3228 }; |
| 3225 #endif | 3229 #endif |
| 3226 } // namespace internal | 3230 } // namespace internal |
| 3227 } // namespace v8 | 3231 } // namespace v8 |
| 3228 | 3232 |
| 3229 #endif // V8_HEAP_SPACES_H_ | 3233 #endif // V8_HEAP_SPACES_H_ |
| OLD | NEW |