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