| 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" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 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. |
| 38 ASSERT(!from_->Contains(addr)); | 38 ASSERT(!from_->Contains(addr)); |
| 39 return to_->Contains(addr); | 39 return to_->Contains(addr); |
| 40 } | 40 } |
| 41 | 41 |
| 42 uword TryAllocate(intptr_t size) { | 42 uword TryAllocate(intptr_t size) { |
| 43 ASSERT(Utils::IsAligned(size, kObjectAlignment)); | 43 ASSERT(Utils::IsAligned(size, kObjectAlignment)); |
| 44 #if defined(DEBUG) | 44 #if defined(DEBUG) |
| 45 if (FLAG_gc_at_alloc && !scavenging_) { | 45 if (FLAG_gc_at_alloc && !scavenging_) { |
| 46 Scavenge(); | 46 Scavenge("debugging"); |
| 47 } | 47 } |
| 48 #endif | 48 #endif |
| 49 uword result = top_; | 49 uword result = top_; |
| 50 intptr_t remaining = end_ - top_; | 50 intptr_t remaining = end_ - top_; |
| 51 if (remaining < size) { | 51 if (remaining < size) { |
| 52 return 0; | 52 return 0; |
| 53 } | 53 } |
| 54 ASSERT(to_->Contains(result)); | 54 ASSERT(to_->Contains(result)); |
| 55 ASSERT((result & kObjectAlignmentMask) == object_alignment_); | 55 ASSERT((result & kObjectAlignmentMask) == object_alignment_); |
| 56 | 56 |
| 57 top_ += size; | 57 top_ += size; |
| 58 ASSERT(to_->Contains(top_) || (top_ == to_->end())); | 58 ASSERT(to_->Contains(top_) || (top_ == to_->end())); |
| 59 return result; | 59 return result; |
| 60 } | 60 } |
| 61 | 61 |
| 62 // Collect the garbage in this scavenger. | 62 // Collect the garbage in this scavenger. |
| 63 void Scavenge(); | 63 void Scavenge(const char* gc_reason); |
| 64 void Scavenge(bool invoke_api_callbacks); | 64 void Scavenge(bool invoke_api_callbacks, const char* gc_reason); |
| 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 in_use() const { return (top_ - FirstObjectStart()); } |
| 73 intptr_t capacity() const { return space_->size(); } | 73 intptr_t capacity() const { return space_->size(); } |
| 74 | 74 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 155 |
| 156 friend class ScavengerVisitor; | 156 friend class ScavengerVisitor; |
| 157 friend class ScavengerWeakVisitor; | 157 friend class ScavengerWeakVisitor; |
| 158 | 158 |
| 159 DISALLOW_COPY_AND_ASSIGN(Scavenger); | 159 DISALLOW_COPY_AND_ASSIGN(Scavenger); |
| 160 }; | 160 }; |
| 161 | 161 |
| 162 } // namespace dart | 162 } // namespace dart |
| 163 | 163 |
| 164 #endif // VM_SCAVENGER_H_ | 164 #endif // VM_SCAVENGER_H_ |
| OLD | NEW |