| 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> | 7 #include <map> |
| 8 | 8 |
| 9 #include "vm/bit_set.h" | 9 #include "vm/bit_set.h" |
| 10 #include "vm/lockers.h" | 10 #include "vm/lockers.h" |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 FreeListElement* result = free_lists_[index]; | 228 FreeListElement* result = free_lists_[index]; |
| 229 FreeListElement* next = result->next(); | 229 FreeListElement* next = result->next(); |
| 230 if (next == NULL && index != kNumLists) { | 230 if (next == NULL && index != kNumLists) { |
| 231 free_map_.Set(index, false); | 231 free_map_.Set(index, false); |
| 232 } | 232 } |
| 233 free_lists_[index] = next; | 233 free_lists_[index] = next; |
| 234 return result; | 234 return result; |
| 235 } | 235 } |
| 236 | 236 |
| 237 | 237 |
| 238 intptr_t FreeList::Length(int index) const { | 238 intptr_t FreeList::LengthLocked(int index) const { |
| 239 MutexLocker ml(mutex_); | 239 DEBUG_ASSERT(mutex_->Owner() == Isolate::Current()); |
| 240 ASSERT(index >= 0); | 240 ASSERT(index >= 0); |
| 241 ASSERT(index < kNumLists); | 241 ASSERT(index < kNumLists); |
| 242 intptr_t result = 0; | 242 intptr_t result = 0; |
| 243 FreeListElement* element = free_lists_[index]; | 243 FreeListElement* element = free_lists_[index]; |
| 244 while (element != NULL) { | 244 while (element != NULL) { |
| 245 ++result; | 245 ++result; |
| 246 element = element->next(); | 246 element = element->next(); |
| 247 } | 247 } |
| 248 return result; | 248 return result; |
| 249 } | 249 } |
| 250 | 250 |
| 251 | 251 |
| 252 void FreeList::PrintSmall() const { | 252 void FreeList::PrintSmall() const { |
| 253 int small_sizes = 0; | 253 int small_sizes = 0; |
| 254 int small_objects = 0; | 254 int small_objects = 0; |
| 255 intptr_t small_bytes = 0; | 255 intptr_t small_bytes = 0; |
| 256 for (int i = 0; i < kNumLists; ++i) { | 256 for (int i = 0; i < kNumLists; ++i) { |
| 257 if (free_lists_[i] == NULL) { | 257 if (free_lists_[i] == NULL) { |
| 258 continue; | 258 continue; |
| 259 } | 259 } |
| 260 small_sizes += 1; | 260 small_sizes += 1; |
| 261 intptr_t list_length = Length(i); | 261 intptr_t list_length = LengthLocked(i); |
| 262 small_objects += list_length; | 262 small_objects += list_length; |
| 263 intptr_t list_bytes = list_length * i * kObjectAlignment; | 263 intptr_t list_bytes = list_length * i * kObjectAlignment; |
| 264 small_bytes += list_bytes; | 264 small_bytes += list_bytes; |
| 265 OS::Print("small %3d [%8d bytes] : " | 265 OS::Print("small %3d [%8d bytes] : " |
| 266 "%8" Pd " objs; %8.1f KB; %8.1f cum KB\n", | 266 "%8" Pd " objs; %8.1f KB; %8.1f cum KB\n", |
| 267 i, | 267 i, |
| 268 i * kObjectAlignment, | 268 i * kObjectAlignment, |
| 269 list_length, | 269 list_length, |
| 270 list_bytes / static_cast<double>(KB), | 270 list_bytes / static_cast<double>(KB), |
| 271 small_bytes / static_cast<double>(KB)); | 271 small_bytes / static_cast<double>(KB)); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 if (is_protected && | 334 if (is_protected && |
| 335 !VirtualMemory::InSamePage(remainder_address - 1, remainder_address)) { | 335 !VirtualMemory::InSamePage(remainder_address - 1, remainder_address)) { |
| 336 bool status = | 336 bool status = |
| 337 VirtualMemory::Protect(reinterpret_cast<void*>(remainder_address), | 337 VirtualMemory::Protect(reinterpret_cast<void*>(remainder_address), |
| 338 remainder_size, | 338 remainder_size, |
| 339 VirtualMemory::kReadExecute); | 339 VirtualMemory::kReadExecute); |
| 340 ASSERT(status); | 340 ASSERT(status); |
| 341 } | 341 } |
| 342 } | 342 } |
| 343 | 343 |
| 344 |
| 345 FreeListElement* FreeList::TryAllocateLarge(intptr_t minimum_size) { |
| 346 MutexLocker ml(mutex_); |
| 347 FreeListElement* previous = NULL; |
| 348 FreeListElement* current = free_lists_[kNumLists]; |
| 349 // TODO(koda): Find largest. |
| 350 while (current != NULL) { |
| 351 FreeListElement* next = current->next(); |
| 352 if (current->Size() >= minimum_size) { |
| 353 if (previous == NULL) { |
| 354 free_lists_[kNumLists] = next; |
| 355 } else { |
| 356 previous->set_next(next); |
| 357 } |
| 358 return current; |
| 359 } |
| 360 previous = current; |
| 361 current = next; |
| 362 } |
| 363 return NULL; |
| 364 } |
| 365 |
| 344 } // namespace dart | 366 } // namespace dart |
| OLD | NEW |