OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef VM_SCAVENGER_H_ | 5 #ifndef VM_SCAVENGER_H_ |
6 #define VM_SCAVENGER_H_ | 6 #define VM_SCAVENGER_H_ |
7 | 7 |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "platform/utils.h" | 9 #include "platform/utils.h" |
10 #include "vm/flags.h" | 10 #include "vm/flags.h" |
11 #include "vm/globals.h" | 11 #include "vm/globals.h" |
12 #include "vm/raw_object.h" | 12 #include "vm/raw_object.h" |
13 #include "vm/virtual_memory.h" | 13 #include "vm/virtual_memory.h" |
14 #include "vm/visitor.h" | 14 #include "vm/visitor.h" |
15 | 15 |
16 namespace dart { | 16 namespace dart { |
17 | 17 |
18 // Forward declarations. | 18 // Forward declarations. |
19 class Heap; | 19 class Heap; |
20 class Isolate; | 20 class Isolate; |
21 class ScavengerVisitor; | 21 class ScavengerVisitor; |
22 | 22 |
23 DECLARE_FLAG(bool, gc_at_alloc); | 23 DECLARE_FLAG(bool, gc_at_alloc); |
24 | 24 |
25 class Scavenger { | 25 class Scavenger { |
26 public: | 26 public: |
27 Scavenger(Heap* heap, intptr_t max_capacity, uword object_alignment); | 27 Scavenger(Heap* heap, intptr_t max_capacity_in_words, uword object_alignment); |
28 ~Scavenger(); | 28 ~Scavenger(); |
29 | 29 |
30 // Check whether this Scavenger contains this address. | 30 // Check whether this Scavenger contains this address. |
31 // During scavenging both the to and from spaces contain "legal" objects. | 31 // During scavenging both the to and from spaces contain "legal" objects. |
32 // During a scavenge this function only returns true for addresses that will | 32 // During a scavenge this function only returns true for addresses that will |
33 // be part of the surviving objects. | 33 // be part of the surviving objects. |
34 bool Contains(uword addr) const { | 34 bool Contains(uword addr) const { |
35 // No reasonable algorithm should be checking for objects in from space. At | 35 // No reasonable algorithm should be checking for objects in from space. At |
36 // least unless it is debugging code. This might need to be relaxed later, | 36 // least unless it is debugging code. This might need to be relaxed later, |
37 // but currently it helps prevent dumb bugs. | 37 // but currently it helps prevent dumb bugs. |
(...skipping 24 matching lines...) Expand all Loading... |
62 // Collect the garbage in this scavenger. | 62 // Collect the garbage in this scavenger. |
63 void Scavenge(); | 63 void Scavenge(); |
64 void Scavenge(bool invoke_api_callbacks); | 64 void Scavenge(bool invoke_api_callbacks); |
65 | 65 |
66 // Accessors to generate code for inlined allocation. | 66 // Accessors to generate code for inlined allocation. |
67 uword* TopAddress() { return &top_; } | 67 uword* TopAddress() { return &top_; } |
68 uword* EndAddress() { return &end_; } | 68 uword* EndAddress() { return &end_; } |
69 static intptr_t top_offset() { return OFFSET_OF(Scavenger, top_); } | 69 static intptr_t top_offset() { return OFFSET_OF(Scavenger, top_); } |
70 static intptr_t end_offset() { return OFFSET_OF(Scavenger, end_); } | 70 static intptr_t end_offset() { return OFFSET_OF(Scavenger, end_); } |
71 | 71 |
72 intptr_t in_use() const { return (top_ - FirstObjectStart()); } | 72 intptr_t UsedInWords() const { |
73 intptr_t capacity() const { return space_->size(); } | 73 return (top_ - FirstObjectStart()) >> kWordSizeLog2; |
| 74 } |
| 75 intptr_t CapacityInWords() const { return space_->size() >> kWordSizeLog2; } |
74 | 76 |
75 void VisitObjects(ObjectVisitor* visitor) const; | 77 void VisitObjects(ObjectVisitor* visitor) const; |
76 void VisitObjectPointers(ObjectPointerVisitor* visitor) const; | 78 void VisitObjectPointers(ObjectPointerVisitor* visitor) const; |
77 | 79 |
78 void StartEndAddress(uword* start, uword* end) const { | 80 void StartEndAddress(uword* start, uword* end) const { |
79 *start = to_->start(); | 81 *start = to_->start(); |
80 *end = to_->end(); | 82 *end = to_->end(); |
81 } | 83 } |
82 | 84 |
83 // Returns true if the last scavenge had a promotion failure. | 85 // Returns true if the last scavenge had a promotion failure. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 | 172 |
171 friend class ScavengerVisitor; | 173 friend class ScavengerVisitor; |
172 friend class ScavengerWeakVisitor; | 174 friend class ScavengerWeakVisitor; |
173 | 175 |
174 DISALLOW_COPY_AND_ASSIGN(Scavenger); | 176 DISALLOW_COPY_AND_ASSIGN(Scavenger); |
175 }; | 177 }; |
176 | 178 |
177 } // namespace dart | 179 } // namespace dart |
178 | 180 |
179 #endif // VM_SCAVENGER_H_ | 181 #endif // VM_SCAVENGER_H_ |
OLD | NEW |