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 2518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2551 | 2552 |
2552 private: | 2553 private: |
2553 NewSpacePage* prev_page_; // Previous page returned. | 2554 NewSpacePage* prev_page_; // Previous page returned. |
2554 // Next page that will be returned. Cached here so that we can use this | 2555 // Next page that will be returned. Cached here so that we can use this |
2555 // iterator for operations that deallocate pages. | 2556 // iterator for operations that deallocate pages. |
2556 NewSpacePage* next_page_; | 2557 NewSpacePage* next_page_; |
2557 // Last page returned. | 2558 // Last page returned. |
2558 NewSpacePage* last_page_; | 2559 NewSpacePage* last_page_; |
2559 }; | 2560 }; |
2560 | 2561 |
2561 // ----------------------------------------------------------------------------- | |
2562 // Allows observation of inline allocation in the new space. | |
2563 class InlineAllocationObserver { | |
2564 public: | |
2565 explicit InlineAllocationObserver(intptr_t step_size) | |
2566 : step_size_(step_size), bytes_to_next_step_(step_size) { | |
2567 DCHECK(step_size >= kPointerSize); | |
2568 } | |
2569 virtual ~InlineAllocationObserver() {} | |
2570 | |
2571 private: | |
2572 intptr_t step_size() const { return step_size_; } | |
2573 intptr_t bytes_to_next_step() const { return bytes_to_next_step_; } | |
2574 | |
2575 // Pure virtual method provided by the subclasses that gets called when at | |
2576 // least step_size bytes have been allocated. soon_object is the address just | |
2577 // allocated (but not yet initialized.) size is the size of the object as | |
2578 // requested (i.e. w/o the alignment fillers). Some complexities to be aware | |
2579 // of: | |
2580 // 1) soon_object will be nullptr in cases where we end up observing an | |
2581 // allocation that happens to be a filler space (e.g. page boundaries.) | |
2582 // 2) size is the requested size at the time of allocation. Right-trimming | |
2583 // may change the object size dynamically. | |
2584 // 3) soon_object may actually be the first object in an allocation-folding | |
2585 // group. In such a case size is the size of the group rather than the | |
2586 // first object. | |
2587 virtual void Step(int bytes_allocated, Address soon_object, size_t size) = 0; | |
2588 | |
2589 // Called each time the new space does an inline allocation step. This may be | |
2590 // more frequently than the step_size we are monitoring (e.g. when there are | |
2591 // multiple observers, or when page or space boundary is encountered.) | |
2592 void InlineAllocationStep(int bytes_allocated, Address soon_object, | |
2593 size_t size) { | |
2594 bytes_to_next_step_ -= bytes_allocated; | |
2595 if (bytes_to_next_step_ <= 0) { | |
2596 Step(static_cast<int>(step_size_ - bytes_to_next_step_), soon_object, | |
2597 size); | |
2598 bytes_to_next_step_ = step_size_; | |
2599 } | |
2600 } | |
2601 | |
2602 intptr_t step_size_; | |
2603 intptr_t bytes_to_next_step_; | |
2604 | |
2605 friend class NewSpace; | |
2606 | |
2607 DISALLOW_COPY_AND_ASSIGN(InlineAllocationObserver); | |
2608 }; | |
2609 | 2562 |
2610 // ----------------------------------------------------------------------------- | 2563 // ----------------------------------------------------------------------------- |
2611 // The young generation space. | 2564 // The young generation space. |
2612 // | 2565 // |
2613 // The new space consists of a contiguous pair of semispaces. It simply | 2566 // The new space consists of a contiguous pair of semispaces. It simply |
2614 // forwards most functions to the appropriate semispace. | 2567 // forwards most functions to the appropriate semispace. |
2615 | 2568 |
2616 class NewSpace : public Space { | 2569 class NewSpace : public Space { |
2617 public: | 2570 public: |
2618 // Constructor. | 2571 // Constructor. |
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3211 count = 0; | 3164 count = 0; |
3212 } | 3165 } |
3213 // Must be small, since an iteration is used for lookup. | 3166 // Must be small, since an iteration is used for lookup. |
3214 static const int kMaxComments = 64; | 3167 static const int kMaxComments = 64; |
3215 }; | 3168 }; |
3216 #endif | 3169 #endif |
3217 } // namespace internal | 3170 } // namespace internal |
3218 } // namespace v8 | 3171 } // namespace v8 |
3219 | 3172 |
3220 #endif // V8_HEAP_SPACES_H_ | 3173 #endif // V8_HEAP_SPACES_H_ |
OLD | NEW |