| 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 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 } | 676 } |
| 677 | 677 |
| 678 // Allocate and initialize the empty_descriptors instance. | 678 // Allocate and initialize the empty_descriptors instance. |
| 679 { | 679 { |
| 680 uword address = heap->Allocate(PcDescriptors::InstanceSize(0), Heap::kOld); | 680 uword address = heap->Allocate(PcDescriptors::InstanceSize(0), Heap::kOld); |
| 681 InitializeObject(address, kPcDescriptorsCid, | 681 InitializeObject(address, kPcDescriptorsCid, |
| 682 PcDescriptors::InstanceSize(0)); | 682 PcDescriptors::InstanceSize(0)); |
| 683 PcDescriptors::initializeHandle( | 683 PcDescriptors::initializeHandle( |
| 684 empty_descriptors_, | 684 empty_descriptors_, |
| 685 reinterpret_cast<RawPcDescriptors*>(address + kHeapObjectTag)); | 685 reinterpret_cast<RawPcDescriptors*>(address + kHeapObjectTag)); |
| 686 empty_descriptors_->raw_ptr()->length_ = Smi::New(0); | 686 empty_descriptors_->raw_ptr()->length_ = 0; |
| 687 } | 687 } |
| 688 | 688 |
| 689 | 689 |
| 690 cls = Class::New<Instance>(kDynamicCid); | 690 cls = Class::New<Instance>(kDynamicCid); |
| 691 cls.set_is_abstract(); | 691 cls.set_is_abstract(); |
| 692 cls.set_num_type_arguments(0); | 692 cls.set_num_type_arguments(0); |
| 693 cls.set_num_own_type_arguments(0); | 693 cls.set_num_own_type_arguments(0); |
| 694 cls.set_is_type_finalized(); | 694 cls.set_is_type_finalized(); |
| 695 cls.set_is_finalized(); | 695 cls.set_is_finalized(); |
| 696 dynamic_class_ = cls.raw(); | 696 dynamic_class_ = cls.raw(); |
| (...skipping 3897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4594 void PatchClass::set_source_class(const Class& value) const { | 4594 void PatchClass::set_source_class(const Class& value) const { |
| 4595 StorePointer(&raw_ptr()->source_class_, value.raw()); | 4595 StorePointer(&raw_ptr()->source_class_, value.raw()); |
| 4596 } | 4596 } |
| 4597 | 4597 |
| 4598 | 4598 |
| 4599 bool Function::HasBreakpoint() const { | 4599 bool Function::HasBreakpoint() const { |
| 4600 return Isolate::Current()->debugger()->HasBreakpoint(*this); | 4600 return Isolate::Current()->debugger()->HasBreakpoint(*this); |
| 4601 } | 4601 } |
| 4602 | 4602 |
| 4603 | 4603 |
| 4604 void Function::SetCode(const Code& value) const { | 4604 void Function::set_code(const Code& value) const { |
| 4605 StorePointer(&raw_ptr()->code_, value.raw()); | 4605 StorePointer(&raw_ptr()->code_, value.raw()); |
| 4606 } |
| 4607 |
| 4608 void Function::AttachCode(const Code& value) const { |
| 4609 set_code(value); |
| 4606 ASSERT(Function::Handle(value.function()).IsNull() || | 4610 ASSERT(Function::Handle(value.function()).IsNull() || |
| 4607 (value.function() == this->raw())); | 4611 (value.function() == this->raw())); |
| 4608 value.set_owner(*this); | 4612 value.set_owner(*this); |
| 4609 } | 4613 } |
| 4610 | 4614 |
| 4611 | 4615 |
| 4616 bool Function::HasCode() const { |
| 4617 return raw_ptr()->code_ != Code::null() |
| 4618 && raw_ptr()->code_ != StubCode::LazyCompileClosure_entry()->code(); |
| 4619 } |
| 4620 |
| 4621 |
| 4612 void Function::ClearCode() const { | 4622 void Function::ClearCode() const { |
| 4613 StorePointer(&raw_ptr()->code_, Code::null()); | 4623 StorePointer(&raw_ptr()->code_, |
| 4624 IsClosureFunction() |
| 4625 ? StubCode::LazyCompileClosure_entry()->code() |
| 4626 : Code::null()); |
| 4614 StorePointer(&raw_ptr()->unoptimized_code_, Code::null()); | 4627 StorePointer(&raw_ptr()->unoptimized_code_, Code::null()); |
| 4615 } | 4628 } |
| 4616 | 4629 |
| 4617 | 4630 |
| 4618 void Function::SwitchToUnoptimizedCode() const { | 4631 void Function::SwitchToUnoptimizedCode() const { |
| 4619 ASSERT(HasOptimizedCode()); | 4632 ASSERT(HasOptimizedCode()); |
| 4620 | 4633 |
| 4621 const Code& current_code = Code::Handle(CurrentCode()); | 4634 const Code& current_code = Code::Handle(CurrentCode()); |
| 4622 | 4635 |
| 4623 // Optimized code object might have been actually fully produced by the | 4636 // Optimized code object might have been actually fully produced by the |
| 4624 // intrinsifier in this case nothing has to be done. In fact an attempt to | 4637 // intrinsifier in this case nothing has to be done. In fact an attempt to |
| 4625 // patch such code will cause crash. | 4638 // patch such code will cause crash. |
| 4626 // TODO(vegorov): if intrisifier can fully intrinsify the function then we | 4639 // TODO(vegorov): if intrisifier can fully intrinsify the function then we |
| 4627 // should not later try to optimize it. | 4640 // should not later try to optimize it. |
| 4628 if (PcDescriptors::Handle(current_code.pc_descriptors()).Length() == 0) { | 4641 if (PcDescriptors::Handle(current_code.pc_descriptors()).Length() == 0) { |
| 4629 return; | 4642 return; |
| 4630 } | 4643 } |
| 4631 | 4644 |
| 4632 if (FLAG_trace_disabling_optimized_code) { | 4645 if (FLAG_trace_disabling_optimized_code) { |
| 4633 OS::Print("Disabling optimized code: '%s' entry: %#" Px "\n", | 4646 OS::Print("Disabling optimized code: '%s' entry: %#" Px "\n", |
| 4634 ToFullyQualifiedCString(), | 4647 ToFullyQualifiedCString(), |
| 4635 current_code.EntryPoint()); | 4648 current_code.EntryPoint()); |
| 4636 } | 4649 } |
| 4637 // Patch entry of the optimized code. | 4650 // Patch entry of the optimized code. |
| 4638 CodePatcher::PatchEntry(current_code); | 4651 CodePatcher::PatchEntry(current_code); |
| 4639 // Use previously compiled unoptimized code. | 4652 // Use previously compiled unoptimized code. |
| 4640 SetCode(Code::Handle(unoptimized_code())); | 4653 AttachCode(Code::Handle(unoptimized_code())); |
| 4641 CodePatcher::RestoreEntry(Code::Handle(unoptimized_code())); | 4654 CodePatcher::RestoreEntry(Code::Handle(unoptimized_code())); |
| 4642 } | 4655 } |
| 4643 | 4656 |
| 4644 | 4657 |
| 4645 void Function::set_unoptimized_code(const Code& value) const { | 4658 void Function::set_unoptimized_code(const Code& value) const { |
| 4646 ASSERT(!value.is_optimized()); | 4659 ASSERT(!value.is_optimized()); |
| 4647 StorePointer(&raw_ptr()->unoptimized_code_, value.raw()); | 4660 StorePointer(&raw_ptr()->unoptimized_code_, value.raw()); |
| 4648 } | 4661 } |
| 4649 | 4662 |
| 4650 | 4663 |
| (...skipping 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5672 Function::New(name, | 5685 Function::New(name, |
| 5673 RawFunction::kClosureFunction, | 5686 RawFunction::kClosureFunction, |
| 5674 /* is_static = */ parent.is_static(), | 5687 /* is_static = */ parent.is_static(), |
| 5675 /* is_const = */ false, | 5688 /* is_const = */ false, |
| 5676 /* is_abstract = */ false, | 5689 /* is_abstract = */ false, |
| 5677 /* is_external = */ false, | 5690 /* is_external = */ false, |
| 5678 parent.is_native(), | 5691 parent.is_native(), |
| 5679 parent_owner, | 5692 parent_owner, |
| 5680 token_pos)); | 5693 token_pos)); |
| 5681 result.set_parent_function(parent); | 5694 result.set_parent_function(parent); |
| 5695 result.set_code(Code::Handle(StubCode::LazyCompileClosure_entry()->code())); |
| 5696 |
| 5682 return result.raw(); | 5697 return result.raw(); |
| 5683 } | 5698 } |
| 5684 | 5699 |
| 5685 | 5700 |
| 5686 RawFunction* Function::ImplicitClosureFunction() const { | 5701 RawFunction* Function::ImplicitClosureFunction() const { |
| 5687 // Return the existing implicit closure function if any. | 5702 // Return the existing implicit closure function if any. |
| 5688 if (implicit_closure_function() != Function::null()) { | 5703 if (implicit_closure_function() != Function::null()) { |
| 5689 return implicit_closure_function(); | 5704 return implicit_closure_function(); |
| 5690 } | 5705 } |
| 5691 ASSERT(!IsSignatureFunction() && !IsClosureFunction()); | 5706 ASSERT(!IsSignatureFunction() && !IsClosureFunction()); |
| (...skipping 3665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9357 return "Instructions"; | 9372 return "Instructions"; |
| 9358 } | 9373 } |
| 9359 | 9374 |
| 9360 | 9375 |
| 9361 void Instructions::PrintToJSONStream(JSONStream* stream, bool ref) const { | 9376 void Instructions::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 9362 JSONObject jsobj(stream); | 9377 JSONObject jsobj(stream); |
| 9363 } | 9378 } |
| 9364 | 9379 |
| 9365 | 9380 |
| 9366 intptr_t PcDescriptors::Length() const { | 9381 intptr_t PcDescriptors::Length() const { |
| 9367 return Smi::Value(raw_ptr()->length_); | 9382 return raw_ptr()->length_; |
| 9368 } | 9383 } |
| 9369 | 9384 |
| 9370 | 9385 |
| 9371 void PcDescriptors::SetLength(intptr_t value) const { | 9386 void PcDescriptors::SetLength(intptr_t value) const { |
| 9372 // This is only safe because we create a new Smi, which does not cause | 9387 raw_ptr()->length_ = value; |
| 9373 // heap allocation. | |
| 9374 raw_ptr()->length_ = Smi::New(value); | |
| 9375 } | 9388 } |
| 9376 | 9389 |
| 9377 | 9390 |
| 9378 uword PcDescriptors::PC(intptr_t index) const { | 9391 uword PcDescriptors::PC(intptr_t index) const { |
| 9379 return static_cast<uword>(*(EntryAddr(index, kPcEntry))); | 9392 return static_cast<uword>(*(EntryAddr(index, kPcEntry))); |
| 9380 } | 9393 } |
| 9381 | 9394 |
| 9382 | 9395 |
| 9383 void PcDescriptors::SetPC(intptr_t index, uword value) const { | 9396 void PcDescriptors::SetPC(intptr_t index, uword value) const { |
| 9384 *(EntryAddr(index, kPcEntry)) = static_cast<intptr_t>(value); | 9397 *(EntryAddr(index, kPcEntry)) = static_cast<intptr_t>(value); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9566 uword PcDescriptors::GetPcForKind(Kind kind) const { | 9579 uword PcDescriptors::GetPcForKind(Kind kind) const { |
| 9567 for (intptr_t i = 0; i < Length(); i++) { | 9580 for (intptr_t i = 0; i < Length(); i++) { |
| 9568 if (DescriptorKind(i) == kind) { | 9581 if (DescriptorKind(i) == kind) { |
| 9569 return PC(i); | 9582 return PC(i); |
| 9570 } | 9583 } |
| 9571 } | 9584 } |
| 9572 return 0; | 9585 return 0; |
| 9573 } | 9586 } |
| 9574 | 9587 |
| 9575 | 9588 |
| 9576 void Stackmap::SetCode(const dart::Code& code) const { | |
| 9577 StorePointer(&raw_ptr()->code_, code.raw()); | |
| 9578 } | |
| 9579 | |
| 9580 | |
| 9581 bool Stackmap::GetBit(intptr_t bit_index) const { | 9589 bool Stackmap::GetBit(intptr_t bit_index) const { |
| 9582 ASSERT(InRange(bit_index)); | 9590 ASSERT(InRange(bit_index)); |
| 9583 int byte_index = bit_index >> kBitsPerByteLog2; | 9591 int byte_index = bit_index >> kBitsPerByteLog2; |
| 9584 int bit_remainder = bit_index & (kBitsPerByte - 1); | 9592 int bit_remainder = bit_index & (kBitsPerByte - 1); |
| 9585 uint8_t byte_mask = 1U << bit_remainder; | 9593 uint8_t byte_mask = 1U << bit_remainder; |
| 9586 uint8_t byte = raw_ptr()->data_[byte_index]; | 9594 uint8_t byte = raw_ptr()->data_[byte_index]; |
| 9587 return (byte & byte_mask); | 9595 return (byte & byte_mask); |
| 9588 } | 9596 } |
| 9589 | 9597 |
| 9590 | 9598 |
| (...skipping 8117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17708 return "_MirrorReference"; | 17716 return "_MirrorReference"; |
| 17709 } | 17717 } |
| 17710 | 17718 |
| 17711 | 17719 |
| 17712 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 17720 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 17713 Instance::PrintToJSONStream(stream, ref); | 17721 Instance::PrintToJSONStream(stream, ref); |
| 17714 } | 17722 } |
| 17715 | 17723 |
| 17716 | 17724 |
| 17717 } // namespace dart | 17725 } // namespace dart |
| OLD | NEW |