| 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/freelist.h" | 5 #include "vm/freelist.h" |
| 6 | 6 |
| 7 #include <map> |
| 8 #include <utility> |
| 9 |
| 7 #include "vm/bit_set.h" | 10 #include "vm/bit_set.h" |
| 8 #include "vm/object.h" | 11 #include "vm/object.h" |
| 9 #include "vm/raw_object.h" | 12 #include "vm/raw_object.h" |
| 10 | 13 |
| 11 namespace dart { | 14 namespace dart { |
| 12 | 15 |
| 13 | 16 |
| 14 FreeListElement* FreeListElement::AsElement(uword addr, intptr_t size) { | 17 FreeListElement* FreeListElement::AsElement(uword addr, intptr_t size) { |
| 15 ASSERT(size >= kObjectAlignment); | 18 ASSERT(size >= kObjectAlignment); |
| 16 ASSERT(Utils::IsAligned(size, kObjectAlignment)); | 19 ASSERT(Utils::IsAligned(size, kObjectAlignment)); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 intptr_t result = 0; | 143 intptr_t result = 0; |
| 141 FreeListElement* element = free_lists_[index]; | 144 FreeListElement* element = free_lists_[index]; |
| 142 while (element != NULL) { | 145 while (element != NULL) { |
| 143 ++result; | 146 ++result; |
| 144 element = element->next(); | 147 element = element->next(); |
| 145 } | 148 } |
| 146 return result; | 149 return result; |
| 147 } | 150 } |
| 148 | 151 |
| 149 | 152 |
| 153 void FreeList::PrintSmall() const { |
| 154 int small_sizes = 0; |
| 155 int small_objects = 0; |
| 156 intptr_t small_bytes = 0; |
| 157 for (int i = 0; i < kNumLists; ++i) { |
| 158 if (free_lists_[i] == NULL) { |
| 159 continue; |
| 160 } |
| 161 small_sizes += 1; |
| 162 intptr_t list_length = Length(i); |
| 163 small_objects += list_length; |
| 164 intptr_t list_bytes = list_length * i * kObjectAlignment; |
| 165 small_bytes += list_bytes; |
| 166 OS::Print("small %3d [%8d bytes] : " |
| 167 "%8"Pd" objs; %8.1f KB; %8.1f cum KB\n", |
| 168 i, |
| 169 i * kObjectAlignment, |
| 170 list_length, |
| 171 list_bytes / static_cast<double>(KB), |
| 172 small_bytes / static_cast<double>(KB)); |
| 173 } |
| 174 } |
| 175 |
| 176 |
| 177 void FreeList::PrintLarge() const { |
| 178 int large_sizes = 0; |
| 179 int large_objects = 0; |
| 180 intptr_t large_bytes = 0; |
| 181 std::map<intptr_t, intptr_t> sorted; |
| 182 std::map<intptr_t, intptr_t>::iterator it; |
| 183 FreeListElement* node; |
| 184 for (node = free_lists_[kNumLists]; node != NULL; node = node->next()) { |
| 185 it = sorted.find(node->Size()); |
| 186 if (it != sorted.end()) { |
| 187 it->second += 1; |
| 188 } else { |
| 189 large_sizes += 1; |
| 190 sorted.insert(std::make_pair(node->Size(), 1)); |
| 191 } |
| 192 large_objects += 1; |
| 193 } |
| 194 for (it = sorted.begin(); it != sorted.end(); ++it) { |
| 195 intptr_t size = it->first; |
| 196 int list_length = it->second; |
| 197 intptr_t list_bytes = list_length * size; |
| 198 large_bytes += list_bytes; |
| 199 OS::Print("large %3d [%8d bytes] : " |
| 200 "%8"Pd" objs; %8.1f KB; %8.1f cum KB\n", |
| 201 size / kObjectAlignment, |
| 202 size, |
| 203 list_length, |
| 204 list_bytes / static_cast<double>(KB), |
| 205 large_bytes / static_cast<double>(KB)); |
| 206 } |
| 207 } |
| 208 |
| 209 |
| 150 void FreeList::Print() const { | 210 void FreeList::Print() const { |
| 151 OS::Print("%*s %*s %*s\n", 10, "Class", 10, "Length", 10, "Size"); | 211 PrintSmall(); |
| 152 OS::Print("--------------------------------\n"); | 212 PrintLarge(); |
| 153 int total_index = 0; | |
| 154 int total_length = 0; | |
| 155 int total_size = 0; | |
| 156 for (int i = 0; i < kNumLists; ++i) { | |
| 157 if (free_lists_[i] == NULL) { | |
| 158 continue; | |
| 159 } | |
| 160 total_index += 1; | |
| 161 intptr_t length = Length(i); | |
| 162 total_length += length; | |
| 163 intptr_t size = length * i * kObjectAlignment; | |
| 164 total_size += size; | |
| 165 OS::Print("%*d %*"Pd" %*"Pd"\n", | |
| 166 10, i * kObjectAlignment, 10, length, 10, size); | |
| 167 } | |
| 168 OS::Print("--------------------------------\n"); | |
| 169 OS::Print("%*d %*d %*d\n", 10, total_index, 10, total_length, 10, total_size); | |
| 170 } | 213 } |
| 171 | 214 |
| 172 | 215 |
| 173 void FreeList::SplitElementAfterAndEnqueue(FreeListElement* element, | 216 void FreeList::SplitElementAfterAndEnqueue(FreeListElement* element, |
| 174 intptr_t size) { | 217 intptr_t size) { |
| 175 intptr_t remainder_size = element->Size() - size; | 218 intptr_t remainder_size = element->Size() - size; |
| 176 if (remainder_size == 0) return; | 219 if (remainder_size == 0) return; |
| 177 | 220 |
| 178 element = FreeListElement::AsElement(reinterpret_cast<uword>(element) + size, | 221 element = FreeListElement::AsElement(reinterpret_cast<uword>(element) + size, |
| 179 remainder_size); | 222 remainder_size); |
| 180 intptr_t remainder_index = IndexForSize(remainder_size); | 223 intptr_t remainder_index = IndexForSize(remainder_size); |
| 181 EnqueueElement(element, remainder_index); | 224 EnqueueElement(element, remainder_index); |
| 182 } | 225 } |
| 183 | 226 |
| 184 } // namespace dart | 227 } // namespace dart |
| OLD | NEW |