| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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/class_table.h" | 5 #include "vm/class_table.h" |
| 6 | 6 |
| 7 #include "vm/atomic.h" | 7 #include "vm/atomic.h" |
| 8 #include "vm/flags.h" | 8 #include "vm/flags.h" |
| 9 #include "vm/freelist.h" | 9 #include "vm/freelist.h" |
| 10 #include "vm/growable_array.h" | 10 #include "vm/growable_array.h" |
| 11 #include "vm/heap.h" | 11 #include "vm/heap.h" |
| 12 #include "vm/object.h" | 12 #include "vm/object.h" |
| 13 #include "vm/raw_object.h" | 13 #include "vm/raw_object.h" |
| 14 #include "vm/visitor.h" | 14 #include "vm/visitor.h" |
| 15 | 15 |
| 16 namespace dart { | 16 namespace dart { |
| 17 | 17 |
| 18 DEFINE_FLAG(bool, print_class_table, false, "Print initial class table."); | 18 DEFINE_FLAG(bool, print_class_table, false, "Print initial class table."); |
| 19 | 19 |
| 20 ClassTable::ClassTable() | 20 ClassTable::ClassTable() |
| 21 : top_(kNumPredefinedCids), capacity_(0), table_(NULL), | 21 : top_(kNumPredefinedCids), |
| 22 capacity_(0), |
| 23 table_(NULL), |
| 22 old_tables_(new MallocGrowableArray<RawClass**>()) { | 24 old_tables_(new MallocGrowableArray<RawClass**>()) { |
| 23 NOT_IN_PRODUCT(class_heap_stats_table_ = NULL); | 25 NOT_IN_PRODUCT(class_heap_stats_table_ = NULL); |
| 24 NOT_IN_PRODUCT(predefined_class_heap_stats_table_ = NULL); | 26 NOT_IN_PRODUCT(predefined_class_heap_stats_table_ = NULL); |
| 25 if (Dart::vm_isolate() == NULL) { | 27 if (Dart::vm_isolate() == NULL) { |
| 26 capacity_ = initial_capacity_; | 28 capacity_ = initial_capacity_; |
| 27 table_ = reinterpret_cast<RawClass**>( | 29 table_ = reinterpret_cast<RawClass**>( |
| 28 calloc(capacity_, sizeof(RawClass*))); // NOLINT | 30 calloc(capacity_, sizeof(RawClass*))); // NOLINT |
| 29 } else { | 31 } else { |
| 30 // Duplicate the class table from the VM isolate. | 32 // Duplicate the class table from the VM isolate. |
| 31 ClassTable* vm_class_table = Dart::vm_isolate()->class_table(); | 33 ClassTable* vm_class_table = Dart::vm_isolate()->class_table(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 43 #ifndef PRODUCT | 45 #ifndef PRODUCT |
| 44 class_heap_stats_table_ = reinterpret_cast<ClassHeapStats*>( | 46 class_heap_stats_table_ = reinterpret_cast<ClassHeapStats*>( |
| 45 calloc(capacity_, sizeof(ClassHeapStats))); // NOLINT | 47 calloc(capacity_, sizeof(ClassHeapStats))); // NOLINT |
| 46 for (intptr_t i = 0; i < capacity_; i++) { | 48 for (intptr_t i = 0; i < capacity_; i++) { |
| 47 class_heap_stats_table_[i].Initialize(); | 49 class_heap_stats_table_[i].Initialize(); |
| 48 } | 50 } |
| 49 #endif // !PRODUCT | 51 #endif // !PRODUCT |
| 50 } | 52 } |
| 51 #ifndef PRODUCT | 53 #ifndef PRODUCT |
| 52 predefined_class_heap_stats_table_ = reinterpret_cast<ClassHeapStats*>( | 54 predefined_class_heap_stats_table_ = reinterpret_cast<ClassHeapStats*>( |
| 53 calloc(kNumPredefinedCids, sizeof(ClassHeapStats))); // NOLINT | 55 calloc(kNumPredefinedCids, sizeof(ClassHeapStats))); // NOLINT |
| 54 for (intptr_t i = 0; i < kNumPredefinedCids; i++) { | 56 for (intptr_t i = 0; i < kNumPredefinedCids; i++) { |
| 55 predefined_class_heap_stats_table_[i].Initialize(); | 57 predefined_class_heap_stats_table_[i].Initialize(); |
| 56 } | 58 } |
| 57 #endif // !PRODUCT | 59 #endif // !PRODUCT |
| 58 } | 60 } |
| 59 | 61 |
| 60 | 62 |
| 61 ClassTable::ClassTable(ClassTable* original) | 63 ClassTable::ClassTable(ClassTable* original) |
| 62 : top_(original->top_), | 64 : top_(original->top_), |
| 63 capacity_(original->top_), | 65 capacity_(original->top_), |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 intptr_t index = cls.id(); | 117 intptr_t index = cls.id(); |
| 116 if (index != kIllegalCid) { | 118 if (index != kIllegalCid) { |
| 117 ASSERT(index > 0); | 119 ASSERT(index > 0); |
| 118 ASSERT(index < kNumPredefinedCids); | 120 ASSERT(index < kNumPredefinedCids); |
| 119 ASSERT(table_[index] == 0); | 121 ASSERT(table_[index] == 0); |
| 120 ASSERT(index < capacity_); | 122 ASSERT(index < capacity_); |
| 121 table_[index] = cls.raw(); | 123 table_[index] = cls.raw(); |
| 122 // Add the vtable for this predefined class into the static vtable registry | 124 // Add the vtable for this predefined class into the static vtable registry |
| 123 // if it has not been setup yet. | 125 // if it has not been setup yet. |
| 124 cpp_vtable cls_vtable = cls.handle_vtable(); | 126 cpp_vtable cls_vtable = cls.handle_vtable(); |
| 125 AtomicOperations::CompareAndSwapWord( | 127 AtomicOperations::CompareAndSwapWord(&(Object::builtin_vtables_[index]), 0, |
| 126 &(Object::builtin_vtables_[index]), 0, cls_vtable); | 128 cls_vtable); |
| 127 ASSERT(Object::builtin_vtables_[index] == cls_vtable); | 129 ASSERT(Object::builtin_vtables_[index] == cls_vtable); |
| 128 } else { | 130 } else { |
| 129 if (top_ == capacity_) { | 131 if (top_ == capacity_) { |
| 130 // Grow the capacity of the class table. | 132 // Grow the capacity of the class table. |
| 131 // TODO(koda): Add ClassTable::Grow to share code. | 133 // TODO(koda): Add ClassTable::Grow to share code. |
| 132 intptr_t new_capacity = capacity_ + capacity_increment_; | 134 intptr_t new_capacity = capacity_ + capacity_increment_; |
| 133 RawClass** new_table = reinterpret_cast<RawClass**>( | 135 RawClass** new_table = reinterpret_cast<RawClass**>( |
| 134 malloc(new_capacity * sizeof(RawClass*))); // NOLINT | 136 malloc(new_capacity * sizeof(RawClass*))); // NOLINT |
| 135 memmove(new_table, table_, capacity_ * sizeof(RawClass*)); | 137 memmove(new_table, table_, capacity_ * sizeof(RawClass*)); |
| 136 #ifndef PRODUCT | 138 #ifndef PRODUCT |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 ASSERT(cid > 0); | 431 ASSERT(cid > 0); |
| 430 if (cid < kNumPredefinedCids) { | 432 if (cid < kNumPredefinedCids) { |
| 431 return &predefined_class_heap_stats_table_[cid]; | 433 return &predefined_class_heap_stats_table_[cid]; |
| 432 } | 434 } |
| 433 ASSERT(cid < top_); | 435 ASSERT(cid < top_); |
| 434 return &class_heap_stats_table_[cid]; | 436 return &class_heap_stats_table_[cid]; |
| 435 } | 437 } |
| 436 | 438 |
| 437 | 439 |
| 438 ClassHeapStats* ClassTable::StatsWithUpdatedSize(intptr_t cid) { | 440 ClassHeapStats* ClassTable::StatsWithUpdatedSize(intptr_t cid) { |
| 439 if (!HasValidClassAt(cid) || | 441 if (!HasValidClassAt(cid) || (cid == kFreeListElement) || |
| 440 (cid == kFreeListElement) || | 442 (cid == kForwardingCorpse) || (cid == kSmiCid)) { |
| 441 (cid == kForwardingCorpse) || | |
| 442 (cid == kSmiCid)) { | |
| 443 return NULL; | 443 return NULL; |
| 444 } | 444 } |
| 445 Class& cls = Class::Handle(At(cid)); | 445 Class& cls = Class::Handle(At(cid)); |
| 446 if (!(cls.is_finalized() || cls.is_prefinalized())) { | 446 if (!(cls.is_finalized() || cls.is_prefinalized())) { |
| 447 // Not finalized. | 447 // Not finalized. |
| 448 return NULL; | 448 return NULL; |
| 449 } | 449 } |
| 450 ClassHeapStats* stats = PreliminaryStatsAt(cid); | 450 ClassHeapStats* stats = PreliminaryStatsAt(cid); |
| 451 if (ShouldUpdateSizeForClassId(cid)) { | 451 if (ShouldUpdateSizeForClassId(cid)) { |
| 452 stats->UpdateSize(cls.instance_size()); | 452 stats->UpdateSize(cls.instance_size()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 480 for (intptr_t i = 0; i < kNumPredefinedCids; i++) { | 480 for (intptr_t i = 0; i < kNumPredefinedCids; i++) { |
| 481 predefined_class_heap_stats_table_[i].UpdatePromotedAfterNewGC(); | 481 predefined_class_heap_stats_table_[i].UpdatePromotedAfterNewGC(); |
| 482 } | 482 } |
| 483 for (intptr_t i = kNumPredefinedCids; i < top_; i++) { | 483 for (intptr_t i = kNumPredefinedCids; i < top_; i++) { |
| 484 class_heap_stats_table_[i].UpdatePromotedAfterNewGC(); | 484 class_heap_stats_table_[i].UpdatePromotedAfterNewGC(); |
| 485 } | 485 } |
| 486 } | 486 } |
| 487 | 487 |
| 488 | 488 |
| 489 ClassHeapStats** ClassTable::TableAddressFor(intptr_t cid) { | 489 ClassHeapStats** ClassTable::TableAddressFor(intptr_t cid) { |
| 490 return (cid < kNumPredefinedCids) | 490 return (cid < kNumPredefinedCids) ? &predefined_class_heap_stats_table_ |
| 491 ? &predefined_class_heap_stats_table_ | 491 : &class_heap_stats_table_; |
| 492 : &class_heap_stats_table_; | |
| 493 } | 492 } |
| 494 | 493 |
| 495 | 494 |
| 496 intptr_t ClassTable::TableOffsetFor(intptr_t cid) { | 495 intptr_t ClassTable::TableOffsetFor(intptr_t cid) { |
| 497 return (cid < kNumPredefinedCids) | 496 return (cid < kNumPredefinedCids) |
| 498 ? OFFSET_OF(ClassTable, predefined_class_heap_stats_table_) | 497 ? OFFSET_OF(ClassTable, predefined_class_heap_stats_table_) |
| 499 : OFFSET_OF(ClassTable, class_heap_stats_table_); | 498 : OFFSET_OF(ClassTable, class_heap_stats_table_); |
| 500 } | 499 } |
| 501 | 500 |
| 502 | 501 |
| 503 intptr_t ClassTable::ClassOffsetFor(intptr_t cid) { | 502 intptr_t ClassTable::ClassOffsetFor(intptr_t cid) { |
| 504 return cid * sizeof(ClassHeapStats); // NOLINT | 503 return cid * sizeof(ClassHeapStats); // NOLINT |
| 505 } | 504 } |
| 506 | 505 |
| 507 | 506 |
| 508 intptr_t ClassTable::CounterOffsetFor(intptr_t cid, bool is_new_space) { | 507 intptr_t ClassTable::CounterOffsetFor(intptr_t cid, bool is_new_space) { |
| 509 const intptr_t class_offset = ClassOffsetFor(cid); | 508 const intptr_t class_offset = ClassOffsetFor(cid); |
| 510 const intptr_t count_field_offset = is_new_space | 509 const intptr_t count_field_offset = |
| 511 ? ClassHeapStats::allocated_since_gc_new_space_offset() | 510 is_new_space ? ClassHeapStats::allocated_since_gc_new_space_offset() |
| 512 : ClassHeapStats::allocated_since_gc_old_space_offset(); | 511 : ClassHeapStats::allocated_since_gc_old_space_offset(); |
| 513 return class_offset + count_field_offset; | 512 return class_offset + count_field_offset; |
| 514 } | 513 } |
| 515 | 514 |
| 516 | 515 |
| 517 intptr_t ClassTable::StateOffsetFor(intptr_t cid) { | 516 intptr_t ClassTable::StateOffsetFor(intptr_t cid) { |
| 518 return ClassOffsetFor(cid) + ClassHeapStats::state_offset(); | 517 return ClassOffsetFor(cid) + ClassHeapStats::state_offset(); |
| 519 } | 518 } |
| 520 | 519 |
| 521 | 520 |
| 522 intptr_t ClassTable::SizeOffsetFor(intptr_t cid, bool is_new_space) { | 521 intptr_t ClassTable::SizeOffsetFor(intptr_t cid, bool is_new_space) { |
| 523 const uword class_offset = ClassOffsetFor(cid); | 522 const uword class_offset = ClassOffsetFor(cid); |
| 524 const uword size_field_offset = is_new_space | 523 const uword size_field_offset = |
| 525 ? ClassHeapStats::allocated_size_since_gc_new_space_offset() | 524 is_new_space ? ClassHeapStats::allocated_size_since_gc_new_space_offset() |
| 526 : ClassHeapStats::allocated_size_since_gc_old_space_offset(); | 525 : ClassHeapStats::allocated_size_since_gc_old_space_offset(); |
| 527 return class_offset + size_field_offset; | 526 return class_offset + size_field_offset; |
| 528 } | 527 } |
| 529 | 528 |
| 530 | 529 |
| 531 void ClassTable::AllocationProfilePrintJSON(JSONStream* stream) { | 530 void ClassTable::AllocationProfilePrintJSON(JSONStream* stream) { |
| 532 if (!FLAG_support_service) { | 531 if (!FLAG_support_service) { |
| 533 return; | 532 return; |
| 534 } | 533 } |
| 535 Isolate* isolate = Isolate::Current(); | 534 Isolate* isolate = Isolate::Current(); |
| 536 ASSERT(isolate != NULL); | 535 ASSERT(isolate != NULL); |
| 537 Heap* heap = isolate->heap(); | 536 Heap* heap = isolate->heap(); |
| 538 ASSERT(heap != NULL); | 537 ASSERT(heap != NULL); |
| 539 JSONObject obj(stream); | 538 JSONObject obj(stream); |
| 540 obj.AddProperty("type", "AllocationProfile"); | 539 obj.AddProperty("type", "AllocationProfile"); |
| 541 if (isolate->last_allocationprofile_accumulator_reset_timestamp() != 0) { | 540 if (isolate->last_allocationprofile_accumulator_reset_timestamp() != 0) { |
| 542 obj.AddPropertyF( | 541 obj.AddPropertyF( |
| 543 "dateLastAccumulatorReset", | 542 "dateLastAccumulatorReset", "%" Pd64 "", |
| 544 "%" Pd64 "", | |
| 545 isolate->last_allocationprofile_accumulator_reset_timestamp()); | 543 isolate->last_allocationprofile_accumulator_reset_timestamp()); |
| 546 } | 544 } |
| 547 if (isolate->last_allocationprofile_gc_timestamp() != 0) { | 545 if (isolate->last_allocationprofile_gc_timestamp() != 0) { |
| 548 obj.AddPropertyF( | 546 obj.AddPropertyF("dateLastServiceGC", "%" Pd64 "", |
| 549 "dateLastServiceGC", | 547 isolate->last_allocationprofile_gc_timestamp()); |
| 550 "%" Pd64 "", | |
| 551 isolate->last_allocationprofile_gc_timestamp()); | |
| 552 } | 548 } |
| 553 | 549 |
| 554 { | 550 { |
| 555 JSONObject heaps(&obj, "heaps"); | 551 JSONObject heaps(&obj, "heaps"); |
| 556 { | 552 { heap->PrintToJSONObject(Heap::kNew, &heaps); } |
| 557 heap->PrintToJSONObject(Heap::kNew, &heaps); | 553 { heap->PrintToJSONObject(Heap::kOld, &heaps); } |
| 558 } | |
| 559 { | |
| 560 heap->PrintToJSONObject(Heap::kOld, &heaps); | |
| 561 } | |
| 562 } | 554 } |
| 563 { | 555 { |
| 564 JSONArray arr(&obj, "members"); | 556 JSONArray arr(&obj, "members"); |
| 565 Class& cls = Class::Handle(); | 557 Class& cls = Class::Handle(); |
| 566 for (intptr_t i = 1; i < top_; i++) { | 558 for (intptr_t i = 1; i < top_; i++) { |
| 567 const ClassHeapStats* stats = StatsWithUpdatedSize(i); | 559 const ClassHeapStats* stats = StatsWithUpdatedSize(i); |
| 568 if (stats != NULL) { | 560 if (stats != NULL) { |
| 569 JSONObject obj(&arr); | 561 JSONObject obj(&arr); |
| 570 cls = At(i); | 562 cls = At(i); |
| 571 stats->PrintToJSONObject(cls, &obj); | 563 stats->PrintToJSONObject(cls, &obj); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 597 void ClassTable::UpdateLiveNew(intptr_t cid, intptr_t size) { | 589 void ClassTable::UpdateLiveNew(intptr_t cid, intptr_t size) { |
| 598 ClassHeapStats* stats = PreliminaryStatsAt(cid); | 590 ClassHeapStats* stats = PreliminaryStatsAt(cid); |
| 599 ASSERT(stats != NULL); | 591 ASSERT(stats != NULL); |
| 600 ASSERT(size >= 0); | 592 ASSERT(size >= 0); |
| 601 stats->post_gc.AddNew(size); | 593 stats->post_gc.AddNew(size); |
| 602 } | 594 } |
| 603 #endif // !PRODUCT | 595 #endif // !PRODUCT |
| 604 | 596 |
| 605 | 597 |
| 606 } // namespace dart | 598 } // namespace dart |
| OLD | NEW |