Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(808)

Side by Side Diff: runtime/vm/object.cc

Issue 16295022: Fix Issue 11047: use binary search instead of linear search to locate a pc-offset in the static cal… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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.
Florian Schneider 2013/06/04 08:36:49 Maybe I missed something, but where do we sort thi
srdjan 2013/06/04 15:45:27 Added comment // FlowGraphCompiler::AddStaticCal
7788 for (intptr_t i = kSCallTableEntryLength;
7789 i < value.Length();
7790 i += kSCallTableEntryLength) {
7791 ASSERT(value.At(i - kSCallTableEntryLength) < value.At(i));
7792 }
7793 #endif // DEBUG
7786 } 7794 }
7787 7795
7788 7796
7789 RawDeoptInfo* Code::GetDeoptInfoAtPc(uword pc, intptr_t* deopt_reason) const { 7797 RawDeoptInfo* Code::GetDeoptInfoAtPc(uword pc, intptr_t* deopt_reason) const {
7790 ASSERT(is_optimized()); 7798 ASSERT(is_optimized());
7791 const Instructions& instrs = Instructions::Handle(instructions()); 7799 const Instructions& instrs = Instructions::Handle(instructions());
7792 uword code_entry = instrs.EntryPoint(); 7800 uword code_entry = instrs.EntryPoint();
7793 const Array& table = Array::Handle(deopt_info_array()); 7801 const Array& table = Array::Handle(deopt_info_array());
7794 ASSERT(!table.IsNull()); 7802 ASSERT(!table.IsNull());
7795 // Linear search for the PC offset matching the target PC. 7803 // Linear search for the PC offset matching the target PC.
7796 intptr_t length = DeoptTable::GetLength(table); 7804 intptr_t length = DeoptTable::GetLength(table);
7797 Smi& offset = Smi::Handle(); 7805 Smi& offset = Smi::Handle();
7798 Smi& reason = Smi::Handle(); 7806 Smi& reason = Smi::Handle();
7799 DeoptInfo& info = DeoptInfo::Handle(); 7807 DeoptInfo& info = DeoptInfo::Handle();
7800 for (intptr_t i = 0; i < length; ++i) { 7808 for (intptr_t i = 0; i < length; ++i) {
7801 DeoptTable::GetEntry(table, i, &offset, &info, &reason); 7809 DeoptTable::GetEntry(table, i, &offset, &info, &reason);
7802 if (pc == (code_entry + offset.Value())) { 7810 if (pc == (code_entry + offset.Value())) {
7803 ASSERT(!info.IsNull()); 7811 ASSERT(!info.IsNull());
7804 *deopt_reason = reason.Value(); 7812 *deopt_reason = reason.Value();
7805 return info.raw(); 7813 return info.raw();
7806 } 7814 }
7807 } 7815 }
7808 *deopt_reason = kDeoptUnknown; 7816 *deopt_reason = kDeoptUnknown;
7809 return DeoptInfo::null(); 7817 return DeoptInfo::null();
7810 } 7818 }
7811 7819
7812 7820
7821 intptr_t Code::BinarySearchInSCallTable(RawObject* key) const {
siva 2013/06/03 23:35:35 Can we change the signature of this function to in
siva 2013/06/03 23:38:25 An even better option might be to pass the pc itse
srdjan 2013/06/04 15:45:27 Done.
srdjan 2013/06/04 15:45:27 Using other suggestion (passing pc).
7822 NoGCScope no_gc;
7823 const Array& table = Array::Handle(raw_ptr()->static_calls_target_table_);
7824 intptr_t imin = 0;
7825 intptr_t imax = table.Length() / kSCallTableEntryLength;
7826 while (imax >= imin) {
7827 const intptr_t imid = ((imax - imin) / 2) + imin;
7828 const intptr_t real_index = imid * kSCallTableEntryLength;
7829 RawObject* key_in_table = table.At(real_index);
siva 2013/06/03 23:35:35 This can be RawSmi* key_in_table = Smi::RawCast(ta
srdjan 2013/06/04 15:45:27 Using other suggestion (passing pc).
7830 if (key_in_table < key) {
7831 imin = imid + 1;
7832 } else if (key_in_table > key) {
7833 imax = imid - 1;
7834 } else {
7835 return real_index;
7836 }
7837 }
7838 return -1;
7839 }
7840
7841
7813 RawFunction* Code::GetStaticCallTargetFunctionAt(uword pc) const { 7842 RawFunction* Code::GetStaticCallTargetFunctionAt(uword pc) const {
7814 RawObject* raw_code_offset = 7843 RawObject* raw_code_offset =
7815 reinterpret_cast<RawObject*>(Smi::New(pc - EntryPoint())); 7844 reinterpret_cast<RawObject*>(Smi::New(pc - EntryPoint()));
7845 const intptr_t i = BinarySearchInSCallTable(raw_code_offset);
siva 2013/06/03 23:35:35 This would be just: const intptr_t i = BinarySear
siva 2013/06/03 23:38:25 And this would be: const intptr_t i = BinarySearc
srdjan 2013/06/04 15:45:27 Done.
srdjan 2013/06/04 15:45:27 Using other suggestion (passing pc).
7846 if (i < 0) {
7847 return Function::null();
7848 }
7816 const Array& array = 7849 const Array& array =
7817 Array::Handle(raw_ptr()->static_calls_target_table_); 7850 Array::Handle(raw_ptr()->static_calls_target_table_);
7818 for (intptr_t i = 0; i < array.Length(); i += kSCallTableEntryLength) { 7851 Function& function = Function::Handle();
7819 if (array.At(i) == raw_code_offset) { 7852 function ^= array.At(i + kSCallTableFunctionEntry);
7820 Function& function = Function::Handle(); 7853 return function.raw();
7821 function ^= array.At(i + kSCallTableFunctionEntry);
7822 return function.raw();
7823 }
7824 }
7825 return Function::null();
7826 } 7854 }
7827 7855
7828 7856
7829 void Code::SetStaticCallTargetCodeAt(uword pc, const Code& code) const { 7857 void Code::SetStaticCallTargetCodeAt(uword pc, const Code& code) const {
7830 RawObject* raw_code_offset = 7858 RawObject* raw_code_offset =
7831 reinterpret_cast<RawObject*>(Smi::New(pc - EntryPoint())); 7859 reinterpret_cast<RawObject*>(Smi::New(pc - EntryPoint()));
7832 const Array& array = 7860 const Array& array =
7833 Array::Handle(raw_ptr()->static_calls_target_table_); 7861 Array::Handle(raw_ptr()->static_calls_target_table_);
7834 for (intptr_t i = 0; i < array.Length(); i += kSCallTableEntryLength) { 7862 const intptr_t i = BinarySearchInSCallTable(raw_code_offset);
siva 2013/06/03 23:35:35 Ditto here.
srdjan 2013/06/04 15:45:27 Ditto
7835 if (array.At(i) == raw_code_offset) { 7863 ASSERT(i >= 0);
7836 ASSERT(code.IsNull() || 7864 ASSERT(code.IsNull() ||
7837 (code.function() == array.At(i + kSCallTableFunctionEntry))); 7865 (code.function() == array.At(i + kSCallTableFunctionEntry)));
7838 array.SetAt(i + kSCallTableCodeEntry, code); 7866 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
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
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698