| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 #include "vm/scavenger.h" | 5 #include "vm/scavenger.h" |
| 6 | 6 |
| 7 #include "vm/dart.h" | 7 #include "vm/dart.h" |
| 8 #include "vm/dart_api_state.h" | 8 #include "vm/dart_api_state.h" |
| 9 #include "vm/isolate.h" | 9 #include "vm/isolate.h" |
| 10 #include "vm/lockers.h" | 10 #include "vm/lockers.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 ASSERT(from_->Contains(raw_addr)); | 117 ASSERT(from_->Contains(raw_addr)); |
| 118 // Read the header word of the object and determine if the object has | 118 // Read the header word of the object and determine if the object has |
| 119 // already been copied. | 119 // already been copied. |
| 120 uword header = *reinterpret_cast<uword*>(raw_addr); | 120 uword header = *reinterpret_cast<uword*>(raw_addr); |
| 121 uword new_addr = 0; | 121 uword new_addr = 0; |
| 122 if (IsForwarding(header)) { | 122 if (IsForwarding(header)) { |
| 123 // Get the new location of the object. | 123 // Get the new location of the object. |
| 124 new_addr = ForwardedAddr(header); | 124 new_addr = ForwardedAddr(header); |
| 125 } else { | 125 } else { |
| 126 intptr_t size = raw_obj->Size(); | 126 intptr_t size = raw_obj->Size(); |
| 127 intptr_t cid = raw_obj->GetClassId(); | 127 NOT_IN_PRODUCT(intptr_t cid = raw_obj->GetClassId()); |
| 128 ClassTable* class_table = isolate()->class_table(); | 128 NOT_IN_PRODUCT(ClassTable* class_table = isolate()->class_table()); |
| 129 // Check whether object should be promoted. | 129 // Check whether object should be promoted. |
| 130 if (scavenger_->survivor_end_ <= raw_addr) { | 130 if (scavenger_->survivor_end_ <= raw_addr) { |
| 131 // Not a survivor of a previous scavenge. Just copy the object into the | 131 // Not a survivor of a previous scavenge. Just copy the object into the |
| 132 // to space. | 132 // to space. |
| 133 new_addr = scavenger_->TryAllocate(size); | 133 new_addr = scavenger_->TryAllocate(size); |
| 134 class_table->UpdateLiveNew(cid, size); | 134 NOT_IN_PRODUCT(class_table->UpdateLiveNew(cid, size)); |
| 135 } else { | 135 } else { |
| 136 // TODO(iposva): Experiment with less aggressive promotion. For example | 136 // TODO(iposva): Experiment with less aggressive promotion. For example |
| 137 // a coin toss determines if an object is promoted or whether it should | 137 // a coin toss determines if an object is promoted or whether it should |
| 138 // survive in this generation. | 138 // survive in this generation. |
| 139 // | 139 // |
| 140 // This object is a survivor of a previous scavenge. Attempt to promote | 140 // This object is a survivor of a previous scavenge. Attempt to promote |
| 141 // the object. | 141 // the object. |
| 142 new_addr = | 142 new_addr = |
| 143 page_space_->TryAllocatePromoLocked(size, PageSpace::kForceGrowth); | 143 page_space_->TryAllocatePromoLocked(size, PageSpace::kForceGrowth); |
| 144 if (new_addr != 0) { | 144 if (new_addr != 0) { |
| 145 // If promotion succeeded then we need to remember it so that it can | 145 // If promotion succeeded then we need to remember it so that it can |
| 146 // be traversed later. | 146 // be traversed later. |
| 147 scavenger_->PushToPromotedStack(new_addr); | 147 scavenger_->PushToPromotedStack(new_addr); |
| 148 bytes_promoted_ += size; | 148 bytes_promoted_ += size; |
| 149 class_table->UpdateAllocatedOld(cid, size); | 149 NOT_IN_PRODUCT(class_table->UpdateAllocatedOld(cid, size)); |
| 150 } else { | 150 } else { |
| 151 // Promotion did not succeed. Copy into the to space instead. | 151 // Promotion did not succeed. Copy into the to space instead. |
| 152 new_addr = scavenger_->TryAllocate(size); | 152 new_addr = scavenger_->TryAllocate(size); |
| 153 class_table->UpdateLiveNew(cid, size); | 153 NOT_IN_PRODUCT(class_table->UpdateLiveNew(cid, size)); |
| 154 } | 154 } |
| 155 } | 155 } |
| 156 // During a scavenge we always succeed to at least copy all of the | 156 // During a scavenge we always succeed to at least copy all of the |
| 157 // current objects to the to space. | 157 // current objects to the to space. |
| 158 ASSERT(new_addr != 0); | 158 ASSERT(new_addr != 0); |
| 159 // Copy the object to the new location. | 159 // Copy the object to the new location. |
| 160 memmove(reinterpret_cast<void*>(new_addr), | 160 memmove(reinterpret_cast<void*>(new_addr), |
| 161 reinterpret_cast<void*>(raw_addr), | 161 reinterpret_cast<void*>(raw_addr), |
| 162 size); | 162 size); |
| 163 // Remember forwarding address. | 163 // Remember forwarding address. |
| (...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 } | 893 } |
| 894 | 894 |
| 895 | 895 |
| 896 void Scavenger::FreeExternal(intptr_t size) { | 896 void Scavenger::FreeExternal(intptr_t size) { |
| 897 ASSERT(size >= 0); | 897 ASSERT(size >= 0); |
| 898 external_size_ -= size; | 898 external_size_ -= size; |
| 899 ASSERT(external_size_ >= 0); | 899 ASSERT(external_size_ >= 0); |
| 900 } | 900 } |
| 901 | 901 |
| 902 } // namespace dart | 902 } // namespace dart |
| OLD | NEW |