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/object.h" | 5 #include "vm/object.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 Array::initializeHandle( | 618 Array::initializeHandle( |
619 zero_array_, | 619 zero_array_, |
620 reinterpret_cast<RawArray*>(address + kHeapObjectTag)); | 620 reinterpret_cast<RawArray*>(address + kHeapObjectTag)); |
621 zero_array_->StoreSmi(&zero_array_->raw_ptr()->length_, Smi::New(1)); | 621 zero_array_->StoreSmi(&zero_array_->raw_ptr()->length_, Smi::New(1)); |
622 smi = Smi::New(0); | 622 smi = Smi::New(0); |
623 zero_array_->SetAt(0, smi); | 623 zero_array_->SetAt(0, smi); |
624 } | 624 } |
625 | 625 |
626 // Allocate and initialize the empty_descriptors instance. | 626 // Allocate and initialize the empty_descriptors instance. |
627 { | 627 { |
628 uword address = heap->Allocate( | 628 uword address = heap->Allocate(PcDescriptors::InstanceSize(0), Heap::kOld); |
629 PcDescriptors::InstanceSize(0, RawPcDescriptors::kCompressedRecSize), | |
630 Heap::kOld); | |
631 InitializeObject(address, kPcDescriptorsCid, | 629 InitializeObject(address, kPcDescriptorsCid, |
632 PcDescriptors::InstanceSize(0, RawPcDescriptors::kCompressedRecSize)); | 630 PcDescriptors::InstanceSize(0)); |
633 PcDescriptors::initializeHandle( | 631 PcDescriptors::initializeHandle( |
634 empty_descriptors_, | 632 empty_descriptors_, |
635 reinterpret_cast<RawPcDescriptors*>(address + kHeapObjectTag)); | 633 reinterpret_cast<RawPcDescriptors*>(address + kHeapObjectTag)); |
636 empty_descriptors_->StoreNonPointer(&empty_descriptors_->raw_ptr()->length_, | 634 empty_descriptors_->StoreNonPointer(&empty_descriptors_->raw_ptr()->length_, |
637 0); | 635 0); |
638 } | 636 } |
639 | 637 |
640 // Allocate and initialize the canonical empty variable descriptor object. | 638 // Allocate and initialize the canonical empty variable descriptor object. |
641 { | 639 { |
642 uword address = | 640 uword address = |
(...skipping 9898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10541 const char* Instructions::ToCString() const { | 10539 const char* Instructions::ToCString() const { |
10542 return "Instructions"; | 10540 return "Instructions"; |
10543 } | 10541 } |
10544 | 10542 |
10545 | 10543 |
10546 void Instructions::PrintJSONImpl(JSONStream* stream, bool ref) const { | 10544 void Instructions::PrintJSONImpl(JSONStream* stream, bool ref) const { |
10547 Object::PrintJSONImpl(stream, ref); | 10545 Object::PrintJSONImpl(stream, ref); |
10548 } | 10546 } |
10549 | 10547 |
10550 | 10548 |
| 10549 // Encode integer in SLEB128 format. |
| 10550 void PcDescriptors::EncodeInteger(GrowableArray<uint8_t>* data, |
| 10551 intptr_t value) { |
| 10552 bool is_last_part = false; |
| 10553 while (!is_last_part) { |
| 10554 intptr_t part = value & 0x7f; |
| 10555 value >>= 7; |
| 10556 if ((value == 0 && (part & 0x40) == 0) || |
| 10557 (value == -1 && (part & 0x40) != 0)) { |
| 10558 is_last_part = true; |
| 10559 } else { |
| 10560 part |= 0x80; |
| 10561 } |
| 10562 data->Add(part); |
| 10563 } |
| 10564 } |
| 10565 |
| 10566 |
| 10567 // Decode SLEB128 encoded integer. Update byte_index to the next integer. |
| 10568 intptr_t PcDescriptors::DecodeInteger(intptr_t* byte_index) const { |
| 10569 NoSafepointScope no_safepoint; |
| 10570 const uint8_t* data = raw_ptr()->data(); |
| 10571 ASSERT(*byte_index < Length()); |
| 10572 uword shift = 0; |
| 10573 intptr_t value = 0; |
| 10574 intptr_t part = 0; |
| 10575 do { |
| 10576 part = data[(*byte_index)++]; |
| 10577 value |= (part & 0x7f) << shift; |
| 10578 shift += 7; |
| 10579 } while ((part & 0x80) != 0); |
| 10580 |
| 10581 if (shift < sizeof(value) * 8 && (part & 0x40) != 0) { |
| 10582 value |= -(1 << shift); |
| 10583 } |
| 10584 return value; |
| 10585 } |
| 10586 |
| 10587 |
10551 intptr_t PcDescriptors::Length() const { | 10588 intptr_t PcDescriptors::Length() const { |
10552 return raw_ptr()->length_; | 10589 return raw_ptr()->length_; |
10553 } | 10590 } |
10554 | 10591 |
10555 | 10592 |
10556 void PcDescriptors::SetLength(intptr_t value) const { | 10593 void PcDescriptors::SetLength(intptr_t value) const { |
10557 StoreNonPointer(&raw_ptr()->length_, value); | 10594 StoreNonPointer(&raw_ptr()->length_, value); |
10558 } | 10595 } |
10559 | 10596 |
10560 | 10597 |
10561 intptr_t PcDescriptors::RecordSizeInBytes() const { | 10598 void PcDescriptors::CopyData(GrowableArray<uint8_t>* delta_encoded_data) { |
10562 return raw_ptr()->record_size_in_bytes_; | 10599 NoSafepointScope no_safepoint; |
| 10600 uint8_t* data = UnsafeMutableNonPointer(&raw_ptr()->data()[0]); |
| 10601 for (intptr_t i = 0; i < delta_encoded_data->length(); ++i) { |
| 10602 data[i] = (*delta_encoded_data)[i]; |
| 10603 } |
10563 } | 10604 } |
10564 | 10605 |
10565 | 10606 |
10566 void PcDescriptors::SetRecordSizeInBytes(intptr_t value) const { | 10607 RawPcDescriptors* PcDescriptors::New(GrowableArray<uint8_t>* data) { |
10567 StoreNonPointer(&raw_ptr()->record_size_in_bytes_, value); | |
10568 } | |
10569 | |
10570 | |
10571 RawPcDescriptors* PcDescriptors::New(intptr_t num_descriptors, | |
10572 bool has_try_index) { | |
10573 ASSERT(Object::pc_descriptors_class() != Class::null()); | 10608 ASSERT(Object::pc_descriptors_class() != Class::null()); |
10574 if (num_descriptors < 0 || num_descriptors > kMaxElements) { | |
10575 // This should be caught before we reach here. | |
10576 FATAL1("Fatal error in PcDescriptors::New: " | |
10577 "invalid num_descriptors %" Pd "\n", num_descriptors); | |
10578 } | |
10579 Isolate* isolate = Isolate::Current(); | 10609 Isolate* isolate = Isolate::Current(); |
10580 PcDescriptors& result = PcDescriptors::Handle(isolate); | 10610 PcDescriptors& result = PcDescriptors::Handle(isolate); |
10581 { | 10611 { |
10582 const intptr_t rec_size = RawPcDescriptors::RecordSize(has_try_index); | 10612 uword size = PcDescriptors::InstanceSize(data->length()); |
10583 uword size = PcDescriptors::InstanceSize(num_descriptors, rec_size); | |
10584 RawObject* raw = Object::Allocate(PcDescriptors::kClassId, | 10613 RawObject* raw = Object::Allocate(PcDescriptors::kClassId, |
10585 size, | 10614 size, |
10586 Heap::kOld); | 10615 Heap::kOld); |
10587 INC_STAT(isolate, total_code_size, size); | 10616 INC_STAT(isolate, total_code_size, size); |
10588 INC_STAT(isolate, pc_desc_size, size); | 10617 INC_STAT(isolate, pc_desc_size, size); |
10589 NoSafepointScope no_safepoint; | 10618 NoSafepointScope no_safepoint; |
10590 result ^= raw; | 10619 result ^= raw; |
10591 result.SetLength(num_descriptors); | 10620 result.SetLength(data->length()); |
10592 result.SetRecordSizeInBytes(rec_size); | 10621 result.CopyData(data); |
10593 } | 10622 } |
10594 return result.raw(); | 10623 return result.raw(); |
10595 } | 10624 } |
10596 | 10625 |
10597 | 10626 |
10598 const char* PcDescriptors::KindAsStr(RawPcDescriptors::Kind kind) { | 10627 const char* PcDescriptors::KindAsStr(RawPcDescriptors::Kind kind) { |
10599 switch (kind) { | 10628 switch (kind) { |
10600 case RawPcDescriptors::kDeopt: return "deopt "; | 10629 case RawPcDescriptors::kDeopt: return "deopt "; |
10601 case RawPcDescriptors::kIcCall: return "ic-call "; | 10630 case RawPcDescriptors::kIcCall: return "ic-call "; |
10602 case RawPcDescriptors::kOptStaticCall: return "opt-call "; | 10631 case RawPcDescriptors::kOptStaticCall: return "opt-call "; |
(...skipping 10102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20705 return tag_label.ToCString(); | 20734 return tag_label.ToCString(); |
20706 } | 20735 } |
20707 | 20736 |
20708 | 20737 |
20709 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 20738 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
20710 Instance::PrintJSONImpl(stream, ref); | 20739 Instance::PrintJSONImpl(stream, ref); |
20711 } | 20740 } |
20712 | 20741 |
20713 | 20742 |
20714 } // namespace dart | 20743 } // namespace dart |
OLD | NEW |