Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(498)

Side by Side Diff: runtime/vm/freelist.cc

Issue 2083103002: Remove some uses of STL map. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/flow_graph_range_analysis.cc ('k') | runtime/vm/hash_map.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
9 #include "vm/bit_set.h" 7 #include "vm/bit_set.h"
8 #include "vm/hash_map.h"
10 #include "vm/lockers.h" 9 #include "vm/lockers.h"
11 #include "vm/object.h" 10 #include "vm/object.h"
11 #include "vm/os_thread.h"
12 #include "vm/raw_object.h" 12 #include "vm/raw_object.h"
13 #include "vm/os_thread.h"
14 13
15 namespace dart { 14 namespace dart {
16 15
17 16
18 FreeListElement* FreeListElement::AsElement(uword addr, intptr_t size) { 17 FreeListElement* FreeListElement::AsElement(uword addr, intptr_t size) {
19 // Precondition: the (page containing the) header of the element is 18 // Precondition: the (page containing the) header of the element is
20 // writable. 19 // writable.
21 ASSERT(size >= kObjectAlignment); 20 ASSERT(size >= kObjectAlignment);
22 ASSERT(Utils::IsAligned(size, kObjectAlignment)); 21 ASSERT(Utils::IsAligned(size, kObjectAlignment));
23 22
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 "%8" Pd " objs; %8.1f KB; %8.1f cum KB\n", 278 "%8" Pd " objs; %8.1f KB; %8.1f cum KB\n",
280 i, 279 i,
281 i * kObjectAlignment, 280 i * kObjectAlignment,
282 list_length, 281 list_length,
283 list_bytes / static_cast<double>(KB), 282 list_bytes / static_cast<double>(KB),
284 small_bytes / static_cast<double>(KB)); 283 small_bytes / static_cast<double>(KB));
285 } 284 }
286 } 285 }
287 286
288 287
288 class IntptrPair {
289 public:
290 IntptrPair() : first_(-1), second_(-1) {}
291 IntptrPair(intptr_t first, intptr_t second)
292 : first_(first), second_(second) {}
293
294 intptr_t first() const { return first_; }
295 intptr_t second() const { return second_; }
296 void set_second(intptr_t s) { second_ = s; }
297
298 bool operator==(const IntptrPair& other) {
299 return (first_ == other.first_) && (second_ == other.second_);
300 }
301
302 bool operator!=(const IntptrPair& other) {
303 return (first_ != other.first_) || (second_ != other.second_);
304 }
305
306 private:
307 intptr_t first_;
308 intptr_t second_;
309 };
310
311
289 void FreeList::PrintLarge() const { 312 void FreeList::PrintLarge() const {
290 int large_sizes = 0; 313 int large_sizes = 0;
291 int large_objects = 0; 314 int large_objects = 0;
292 intptr_t large_bytes = 0; 315 intptr_t large_bytes = 0;
293 std::map<intptr_t, intptr_t> sorted; 316 MallocDirectChainedHashMap<NumbersKeyValueTrait<IntptrPair> > map;
294 std::map<intptr_t, intptr_t>::iterator it;
295 FreeListElement* node; 317 FreeListElement* node;
296 for (node = free_lists_[kNumLists]; node != NULL; node = node->next()) { 318 for (node = free_lists_[kNumLists]; node != NULL; node = node->next()) {
297 it = sorted.find(node->Size()); 319 IntptrPair* pair = map.Lookup(node->Size());
298 if (it != sorted.end()) { 320 if (pair == NULL) {
299 it->second += 1; 321 large_sizes += 1;
322 map.Insert(IntptrPair(node->Size(), 1));
300 } else { 323 } else {
301 large_sizes += 1; 324 pair->set_second(pair->second() + 1);
302 sorted.insert(std::make_pair(node->Size(), 1));
303 } 325 }
304 large_objects += 1; 326 large_objects += 1;
305 } 327 }
306 for (it = sorted.begin(); it != sorted.end(); ++it) { 328
307 intptr_t size = it->first; 329 MallocDirectChainedHashMap<NumbersKeyValueTrait<IntptrPair> >::Iterator it =
308 intptr_t list_length = it->second; 330 map.GetIterator();
331 IntptrPair* pair;
332 while ((pair = it.Next()) != NULL) {
333 intptr_t size = pair->first();
334 intptr_t list_length = pair->second();
309 intptr_t list_bytes = list_length * size; 335 intptr_t list_bytes = list_length * size;
310 large_bytes += list_bytes; 336 large_bytes += list_bytes;
311 OS::Print("large %3" Pd " [%8" Pd " bytes] : " 337 OS::Print("large %3" Pd " [%8" Pd " bytes] : "
312 "%8" Pd " objs; %8.1f KB; %8.1f cum KB\n", 338 "%8" Pd " objs; %8.1f KB; %8.1f cum KB\n",
313 size / kObjectAlignment, 339 size / kObjectAlignment,
314 size, 340 size,
315 list_length, 341 list_length,
316 list_bytes / static_cast<double>(KB), 342 list_bytes / static_cast<double>(KB),
317 large_bytes / static_cast<double>(KB)); 343 large_bytes / static_cast<double>(KB));
318 } 344 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 if (next_index != -1) { 423 if (next_index != -1) {
398 FreeListElement* element = DequeueElement(next_index); 424 FreeListElement* element = DequeueElement(next_index);
399 SplitElementAfterAndEnqueue(element, size, false); 425 SplitElementAfterAndEnqueue(element, size, false);
400 return reinterpret_cast<uword>(element); 426 return reinterpret_cast<uword>(element);
401 } 427 }
402 } 428 }
403 return 0; 429 return 0;
404 } 430 }
405 431
406 } // namespace dart 432 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_range_analysis.cc ('k') | runtime/vm/hash_map.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698