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 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 Array::initializeHandle( | 620 Array::initializeHandle( |
621 zero_array_, | 621 zero_array_, |
622 reinterpret_cast<RawArray*>(address + kHeapObjectTag)); | 622 reinterpret_cast<RawArray*>(address + kHeapObjectTag)); |
623 zero_array_->StoreSmi(&zero_array_->raw_ptr()->length_, Smi::New(1)); | 623 zero_array_->StoreSmi(&zero_array_->raw_ptr()->length_, Smi::New(1)); |
624 smi = Smi::New(0); | 624 smi = Smi::New(0); |
625 zero_array_->SetAt(0, smi); | 625 zero_array_->SetAt(0, smi); |
626 } | 626 } |
627 | 627 |
628 // Allocate and initialize the empty_descriptors instance. | 628 // Allocate and initialize the empty_descriptors instance. |
629 { | 629 { |
630 uword address = heap->Allocate( | 630 uword address = heap->Allocate(PcDescriptors::InstanceSize(0), Heap::kOld); |
631 PcDescriptors::InstanceSize(0, RawPcDescriptors::kCompressedRecSize), | |
632 Heap::kOld); | |
633 InitializeObject(address, kPcDescriptorsCid, | 631 InitializeObject(address, kPcDescriptorsCid, |
634 PcDescriptors::InstanceSize(0, RawPcDescriptors::kCompressedRecSize)); | 632 PcDescriptors::InstanceSize(0)); |
635 PcDescriptors::initializeHandle( | 633 PcDescriptors::initializeHandle( |
636 empty_descriptors_, | 634 empty_descriptors_, |
637 reinterpret_cast<RawPcDescriptors*>(address + kHeapObjectTag)); | 635 reinterpret_cast<RawPcDescriptors*>(address + kHeapObjectTag)); |
638 empty_descriptors_->StoreNonPointer(&empty_descriptors_->raw_ptr()->length_, | 636 empty_descriptors_->StoreNonPointer(&empty_descriptors_->raw_ptr()->length_, |
639 0); | 637 0); |
640 } | 638 } |
641 | 639 |
642 // Allocate and initialize the canonical empty variable descriptor object. | 640 // Allocate and initialize the canonical empty variable descriptor object. |
643 { | 641 { |
644 uword address = | 642 uword address = |
(...skipping 9899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10544 const char* Instructions::ToCString() const { | 10542 const char* Instructions::ToCString() const { |
10545 return "Instructions"; | 10543 return "Instructions"; |
10546 } | 10544 } |
10547 | 10545 |
10548 | 10546 |
10549 void Instructions::PrintJSONImpl(JSONStream* stream, bool ref) const { | 10547 void Instructions::PrintJSONImpl(JSONStream* stream, bool ref) const { |
10550 Object::PrintJSONImpl(stream, ref); | 10548 Object::PrintJSONImpl(stream, ref); |
10551 } | 10549 } |
10552 | 10550 |
10553 | 10551 |
| 10552 // Encode integer in SLEB128 format. |
| 10553 void PcDescriptors::EncodeInteger(GrowableArray<uint8_t>* data, |
| 10554 intptr_t value) { |
| 10555 bool is_last_part = false; |
| 10556 while (!is_last_part) { |
| 10557 intptr_t part = value & 0x7f; |
| 10558 value >>= 7; |
| 10559 if ((value == 0 && (part & 0x40) == 0) || |
| 10560 (value == -1 && (part & 0x40) != 0)) { |
| 10561 is_last_part = true; |
| 10562 } else { |
| 10563 part |= 0x80; |
| 10564 } |
| 10565 data->Add(part); |
| 10566 } |
| 10567 } |
| 10568 |
| 10569 |
| 10570 // Decode SLEB128 encoded integer. Update byte_index to the next integer. |
| 10571 intptr_t PcDescriptors::DecodeInteger(intptr_t* byte_index) const { |
| 10572 NoSafepointScope no_safepoint; |
| 10573 const uint8_t* data = raw_ptr()->data(); |
| 10574 ASSERT(*byte_index < Length()); |
| 10575 uword shift = 0; |
| 10576 intptr_t value = 0; |
| 10577 intptr_t part = 0; |
| 10578 do { |
| 10579 part = data[(*byte_index)++]; |
| 10580 value |= (part & 0x7f) << shift; |
| 10581 shift += 7; |
| 10582 } while ((part & 0x80) != 0); |
| 10583 |
| 10584 if (shift < sizeof(value) * 8 && (part & 0x40) != 0) { |
| 10585 value |= -(1 << shift); |
| 10586 } |
| 10587 return value; |
| 10588 } |
| 10589 |
| 10590 |
10554 intptr_t PcDescriptors::Length() const { | 10591 intptr_t PcDescriptors::Length() const { |
10555 return raw_ptr()->length_; | 10592 return raw_ptr()->length_; |
10556 } | 10593 } |
10557 | 10594 |
10558 | 10595 |
10559 void PcDescriptors::SetLength(intptr_t value) const { | 10596 void PcDescriptors::SetLength(intptr_t value) const { |
10560 StoreNonPointer(&raw_ptr()->length_, value); | 10597 StoreNonPointer(&raw_ptr()->length_, value); |
10561 } | 10598 } |
10562 | 10599 |
10563 | 10600 |
10564 intptr_t PcDescriptors::RecordSizeInBytes() const { | 10601 void PcDescriptors::CopyData(GrowableArray<uint8_t>* delta_encoded_data) { |
10565 return raw_ptr()->record_size_in_bytes_; | 10602 NoSafepointScope no_safepoint; |
| 10603 uint8_t* data = UnsafeMutableNonPointer(&raw_ptr()->data()[0]); |
| 10604 for (intptr_t i = 0; i < delta_encoded_data->length(); ++i) { |
| 10605 data[i] = (*delta_encoded_data)[i]; |
| 10606 } |
10566 } | 10607 } |
10567 | 10608 |
10568 | 10609 |
10569 void PcDescriptors::SetRecordSizeInBytes(intptr_t value) const { | 10610 RawPcDescriptors* PcDescriptors::New(GrowableArray<uint8_t>* data) { |
10570 StoreNonPointer(&raw_ptr()->record_size_in_bytes_, value); | |
10571 } | |
10572 | |
10573 | |
10574 RawPcDescriptors* PcDescriptors::New(intptr_t num_descriptors, | |
10575 bool has_try_index) { | |
10576 ASSERT(Object::pc_descriptors_class() != Class::null()); | 10611 ASSERT(Object::pc_descriptors_class() != Class::null()); |
10577 if (num_descriptors < 0 || num_descriptors > kMaxElements) { | |
10578 // This should be caught before we reach here. | |
10579 FATAL1("Fatal error in PcDescriptors::New: " | |
10580 "invalid num_descriptors %" Pd "\n", num_descriptors); | |
10581 } | |
10582 PcDescriptors& result = PcDescriptors::Handle(); | 10612 PcDescriptors& result = PcDescriptors::Handle(); |
10583 { | 10613 { |
10584 const intptr_t rec_size = RawPcDescriptors::RecordSize(has_try_index); | 10614 uword size = PcDescriptors::InstanceSize(data->length()); |
10585 uword size = PcDescriptors::InstanceSize(num_descriptors, rec_size); | |
10586 RawObject* raw = Object::Allocate(PcDescriptors::kClassId, | 10615 RawObject* raw = Object::Allocate(PcDescriptors::kClassId, |
10587 size, | 10616 size, |
10588 Heap::kOld); | 10617 Heap::kOld); |
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 10121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20724 return tag_label.ToCString(); | 20753 return tag_label.ToCString(); |
20725 } | 20754 } |
20726 | 20755 |
20727 | 20756 |
20728 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 20757 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
20729 Instance::PrintJSONImpl(stream, ref); | 20758 Instance::PrintJSONImpl(stream, ref); |
20730 } | 20759 } |
20731 | 20760 |
20732 | 20761 |
20733 } // namespace dart | 20762 } // namespace dart |
OLD | NEW |