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; | |
24 class Isolate; | 23 class Isolate; |
25 | 24 |
26 // ----------------------------------------------------------------------------- | 25 // ----------------------------------------------------------------------------- |
27 // Heap structures: | 26 // Heap structures: |
28 // | 27 // |
29 // A JS heap consists of a young generation, an old generation, and a large | 28 // A JS heap consists of a young generation, an old generation, and a large |
30 // object space. The young generation is divided into two semispaces. A | 29 // object space. The young generation is divided into two semispaces. A |
31 // scavenger implements Cheney's copying algorithm. The old generation is | 30 // scavenger implements Cheney's copying algorithm. The old generation is |
32 // separated into a map space and an old object space. The map space contains | 31 // separated into a map space and an old object space. The map space contains |
33 // all (and only) map objects, the rest of old objects go into the old space. | 32 // 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... |
2561 | 2560 |
2562 private: | 2561 private: |
2563 NewSpacePage* prev_page_; // Previous page returned. | 2562 NewSpacePage* prev_page_; // Previous page returned. |
2564 // Next page that will be returned. Cached here so that we can use this | 2563 // Next page that will be returned. Cached here so that we can use this |
2565 // iterator for operations that deallocate pages. | 2564 // iterator for operations that deallocate pages. |
2566 NewSpacePage* next_page_; | 2565 NewSpacePage* next_page_; |
2567 // Last page returned. | 2566 // Last page returned. |
2568 NewSpacePage* last_page_; | 2567 NewSpacePage* last_page_; |
2569 }; | 2568 }; |
2570 | 2569 |
| 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 }; |
2571 | 2618 |
2572 // ----------------------------------------------------------------------------- | 2619 // ----------------------------------------------------------------------------- |
2573 // The young generation space. | 2620 // The young generation space. |
2574 // | 2621 // |
2575 // The new space consists of a contiguous pair of semispaces. It simply | 2622 // The new space consists of a contiguous pair of semispaces. It simply |
2576 // forwards most functions to the appropriate semispace. | 2623 // forwards most functions to the appropriate semispace. |
2577 | 2624 |
2578 class NewSpace : public Space { | 2625 class NewSpace : public Space { |
2579 public: | 2626 public: |
2580 // Constructor. | 2627 // Constructor. |
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3173 count = 0; | 3220 count = 0; |
3174 } | 3221 } |
3175 // Must be small, since an iteration is used for lookup. | 3222 // Must be small, since an iteration is used for lookup. |
3176 static const int kMaxComments = 64; | 3223 static const int kMaxComments = 64; |
3177 }; | 3224 }; |
3178 #endif | 3225 #endif |
3179 } // namespace internal | 3226 } // namespace internal |
3180 } // namespace v8 | 3227 } // namespace v8 |
3181 | 3228 |
3182 #endif // V8_HEAP_SPACES_H_ | 3229 #endif // V8_HEAP_SPACES_H_ |
OLD | NEW |