| 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 7765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7776 } | 7776 } |
| 7777 | 7777 |
| 7778 | 7778 |
| 7779 void Code::set_object_table(const Array& array) const { | 7779 void Code::set_object_table(const Array& array) const { |
| 7780 StorePointer(&raw_ptr()->object_table_, array.raw()); | 7780 StorePointer(&raw_ptr()->object_table_, array.raw()); |
| 7781 } | 7781 } |
| 7782 | 7782 |
| 7783 | 7783 |
| 7784 void Code::set_static_calls_target_table(const Array& value) const { | 7784 void Code::set_static_calls_target_table(const Array& value) const { |
| 7785 StorePointer(&raw_ptr()->static_calls_target_table_, value.raw()); | 7785 StorePointer(&raw_ptr()->static_calls_target_table_, value.raw()); |
| 7786 #if defined(DEBUG) |
| 7787 // Check that the table is sorted by pc offsets. |
| 7788 // FlowGraphCompiler::AddStaticCallTarget adds pc-offsets to the table while |
| 7789 // emitting assembly. This guarantees that every succeeding pc-offset is |
| 7790 // larger than the previously added one. |
| 7791 for (intptr_t i = kSCallTableEntryLength; |
| 7792 i < value.Length(); |
| 7793 i += kSCallTableEntryLength) { |
| 7794 ASSERT(value.At(i - kSCallTableEntryLength) < value.At(i)); |
| 7795 } |
| 7796 #endif // DEBUG |
| 7786 } | 7797 } |
| 7787 | 7798 |
| 7788 | 7799 |
| 7789 RawDeoptInfo* Code::GetDeoptInfoAtPc(uword pc, intptr_t* deopt_reason) const { | 7800 RawDeoptInfo* Code::GetDeoptInfoAtPc(uword pc, intptr_t* deopt_reason) const { |
| 7790 ASSERT(is_optimized()); | 7801 ASSERT(is_optimized()); |
| 7791 const Instructions& instrs = Instructions::Handle(instructions()); | 7802 const Instructions& instrs = Instructions::Handle(instructions()); |
| 7792 uword code_entry = instrs.EntryPoint(); | 7803 uword code_entry = instrs.EntryPoint(); |
| 7793 const Array& table = Array::Handle(deopt_info_array()); | 7804 const Array& table = Array::Handle(deopt_info_array()); |
| 7794 ASSERT(!table.IsNull()); | 7805 ASSERT(!table.IsNull()); |
| 7795 // Linear search for the PC offset matching the target PC. | 7806 // Linear search for the PC offset matching the target PC. |
| 7796 intptr_t length = DeoptTable::GetLength(table); | 7807 intptr_t length = DeoptTable::GetLength(table); |
| 7797 Smi& offset = Smi::Handle(); | 7808 Smi& offset = Smi::Handle(); |
| 7798 Smi& reason = Smi::Handle(); | 7809 Smi& reason = Smi::Handle(); |
| 7799 DeoptInfo& info = DeoptInfo::Handle(); | 7810 DeoptInfo& info = DeoptInfo::Handle(); |
| 7800 for (intptr_t i = 0; i < length; ++i) { | 7811 for (intptr_t i = 0; i < length; ++i) { |
| 7801 DeoptTable::GetEntry(table, i, &offset, &info, &reason); | 7812 DeoptTable::GetEntry(table, i, &offset, &info, &reason); |
| 7802 if (pc == (code_entry + offset.Value())) { | 7813 if (pc == (code_entry + offset.Value())) { |
| 7803 ASSERT(!info.IsNull()); | 7814 ASSERT(!info.IsNull()); |
| 7804 *deopt_reason = reason.Value(); | 7815 *deopt_reason = reason.Value(); |
| 7805 return info.raw(); | 7816 return info.raw(); |
| 7806 } | 7817 } |
| 7807 } | 7818 } |
| 7808 *deopt_reason = kDeoptUnknown; | 7819 *deopt_reason = kDeoptUnknown; |
| 7809 return DeoptInfo::null(); | 7820 return DeoptInfo::null(); |
| 7810 } | 7821 } |
| 7811 | 7822 |
| 7812 | 7823 |
| 7824 intptr_t Code::BinarySearchInSCallTable(uword pc) const { |
| 7825 NoGCScope no_gc; |
| 7826 const Array& table = Array::Handle(raw_ptr()->static_calls_target_table_); |
| 7827 RawObject* key = reinterpret_cast<RawObject*>(Smi::New(pc - EntryPoint())); |
| 7828 intptr_t imin = 0; |
| 7829 intptr_t imax = table.Length() / kSCallTableEntryLength; |
| 7830 while (imax >= imin) { |
| 7831 const intptr_t imid = ((imax - imin) / 2) + imin; |
| 7832 const intptr_t real_index = imid * kSCallTableEntryLength; |
| 7833 RawObject* key_in_table = table.At(real_index); |
| 7834 if (key_in_table < key) { |
| 7835 imin = imid + 1; |
| 7836 } else if (key_in_table > key) { |
| 7837 imax = imid - 1; |
| 7838 } else { |
| 7839 return real_index; |
| 7840 } |
| 7841 } |
| 7842 return -1; |
| 7843 } |
| 7844 |
| 7845 |
| 7813 RawFunction* Code::GetStaticCallTargetFunctionAt(uword pc) const { | 7846 RawFunction* Code::GetStaticCallTargetFunctionAt(uword pc) const { |
| 7814 RawObject* raw_code_offset = | 7847 const intptr_t i = BinarySearchInSCallTable(pc); |
| 7815 reinterpret_cast<RawObject*>(Smi::New(pc - EntryPoint())); | 7848 if (i < 0) { |
| 7849 return Function::null(); |
| 7850 } |
| 7816 const Array& array = | 7851 const Array& array = |
| 7817 Array::Handle(raw_ptr()->static_calls_target_table_); | 7852 Array::Handle(raw_ptr()->static_calls_target_table_); |
| 7818 for (intptr_t i = 0; i < array.Length(); i += kSCallTableEntryLength) { | 7853 Function& function = Function::Handle(); |
| 7819 if (array.At(i) == raw_code_offset) { | 7854 function ^= array.At(i + kSCallTableFunctionEntry); |
| 7820 Function& function = Function::Handle(); | 7855 return function.raw(); |
| 7821 function ^= array.At(i + kSCallTableFunctionEntry); | |
| 7822 return function.raw(); | |
| 7823 } | |
| 7824 } | |
| 7825 return Function::null(); | |
| 7826 } | 7856 } |
| 7827 | 7857 |
| 7828 | 7858 |
| 7829 void Code::SetStaticCallTargetCodeAt(uword pc, const Code& code) const { | 7859 void Code::SetStaticCallTargetCodeAt(uword pc, const Code& code) const { |
| 7830 RawObject* raw_code_offset = | 7860 const intptr_t i = BinarySearchInSCallTable(pc); |
| 7831 reinterpret_cast<RawObject*>(Smi::New(pc - EntryPoint())); | 7861 ASSERT(i >= 0); |
| 7832 const Array& array = | 7862 const Array& array = |
| 7833 Array::Handle(raw_ptr()->static_calls_target_table_); | 7863 Array::Handle(raw_ptr()->static_calls_target_table_); |
| 7834 for (intptr_t i = 0; i < array.Length(); i += kSCallTableEntryLength) { | 7864 ASSERT(code.IsNull() || |
| 7835 if (array.At(i) == raw_code_offset) { | 7865 (code.function() == array.At(i + kSCallTableFunctionEntry))); |
| 7836 ASSERT(code.IsNull() || | 7866 array.SetAt(i + kSCallTableCodeEntry, code); |
| 7837 (code.function() == array.At(i + kSCallTableFunctionEntry))); | |
| 7838 array.SetAt(i + kSCallTableCodeEntry, code); | |
| 7839 return; | |
| 7840 } | |
| 7841 } | |
| 7842 UNREACHABLE(); | |
| 7843 } | 7867 } |
| 7844 | 7868 |
| 7845 | 7869 |
| 7846 const Code::Comments& Code::comments() const { | 7870 const Code::Comments& Code::comments() const { |
| 7847 Comments* comments = new Code::Comments(Array::Handle(raw_ptr()->comments_)); | 7871 Comments* comments = new Code::Comments(Array::Handle(raw_ptr()->comments_)); |
| 7848 return *comments; | 7872 return *comments; |
| 7849 } | 7873 } |
| 7850 | 7874 |
| 7851 | 7875 |
| 7852 void Code::set_comments(const Code::Comments& comments) const { | 7876 void Code::set_comments(const Code::Comments& comments) const { |
| (...skipping 5452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13305 space); | 13329 space); |
| 13306 return reinterpret_cast<RawWeakProperty*>(raw); | 13330 return reinterpret_cast<RawWeakProperty*>(raw); |
| 13307 } | 13331 } |
| 13308 | 13332 |
| 13309 | 13333 |
| 13310 const char* WeakProperty::ToCString() const { | 13334 const char* WeakProperty::ToCString() const { |
| 13311 return "_WeakProperty"; | 13335 return "_WeakProperty"; |
| 13312 } | 13336 } |
| 13313 | 13337 |
| 13314 } // namespace dart | 13338 } // namespace dart |
| OLD | NEW |