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

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

Issue 9395016: First part of new ICData infrastructure: use a wrapper object instead of an array. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 10 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/ic_data.h ('k') | runtime/vm/ic_data_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
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.
4
5 #include "vm/ic_data.h"
6 #include "vm/object.h"
7
8 namespace dart {
9
10 // ICData is a ValueObject, therefore 'data' need not be a ZoneObject.
11 ICData::ICData(const Array& data) : data_(&data) {
12 // Check consistency.
13 ASSERT(data_->IsNull() || !String::Handle(FunctionName()).IsNull());
14 ASSERT(data_->IsNull() || (NumberOfArgumentsChecked() > 0));
15 }
16
17
18 ICData::ICData(const String& function_name, intptr_t num_args_checked)
19 : data_(NULL) {
20 // Array contains: function-name, num_checked, NULL check sentinel (classes,
21 // target).
22 const intptr_t len = kChecksStartIndex + (num_args_checked + 1);
23 data_ = &Array::ZoneHandle(Array::New(len, Heap::kOld));
24 data_->SetAt(kNameIndex, function_name);
25 data_->SetAt(kNumArgsCheckedIndex, Smi::Handle(Smi::New(num_args_checked)));
26 }
27
28
29 RawArray* ICData::data() const {
30 return data_->raw();
31 }
32
33
34 void ICData::set_data(const Array& value) {
35 data_ = &value;
36 // Check consistency.
37 ASSERT(data_->IsNull() || !String::Handle(FunctionName()).IsNull());
38 ASSERT(data_->IsNull() || (NumberOfArgumentsChecked() > 0));
39 }
40
41
42 intptr_t ICData::ArrayElementsPerCheck() const {
43 // Number of checked classes + target.
44 return NumberOfArgumentsChecked() + 1;
45 }
46
47
48 intptr_t ICData::NumberOfArgumentsChecked() const {
49 if (data_->IsNull()) return 0;
50 Smi& result = Smi::Handle();
51 result ^= data_->At(kNumArgsCheckedIndex);
52 return result.Value();
53 }
54
55
56 intptr_t ICData::NumberOfChecks() const {
57 if (data_->IsNull()) return 0;
58 const intptr_t per_check = ArrayElementsPerCheck();
59 // Subtract function-name, num-checked and sentinel
60 intptr_t len = data_->Length() - kChecksStartIndex - per_check;
61 ASSERT(len % per_check == 0);
62 return len / per_check;
63 }
64
65
66 RawString* ICData::FunctionName() const {
67 if (data_->IsNull()) return String::null();
68 String& result = String::Handle();
69 result ^= data_->At(kNameIndex);
70 return result.raw();
71 }
72
73
74 void ICData::AddCheck(const GrowableArray<const Class*>& classes,
75 const Function& target) {
76 ASSERT(!data_->IsNull());
77 intptr_t old_number_of_checks = NumberOfChecks();
78 intptr_t new_len = data_->Length() + ArrayElementsPerCheck();
79 data_ = &Array::ZoneHandle(Array::Grow(*data_, new_len, Heap::kOld));
80 SetCheckAt(old_number_of_checks, classes, target);
81 }
82
83
84 void ICData::SetCheckAt(intptr_t index,
85 const GrowableArray<const Class*>& classes,
86 const Function& target) {
87 ASSERT(!data_->IsNull());
88 ASSERT((0 <= index) && (index < NumberOfChecks()));
89 intptr_t pos = kChecksStartIndex + ArrayElementsPerCheck() * index;
90 ASSERT(classes.length() == NumberOfArgumentsChecked());
91 for (intptr_t i = 0; i < classes.length(); i++) {
92 // Null is used as terminating object, do not add it.
93 ASSERT(!classes[i]->IsNull());
94 data_->SetAt(pos++, *(classes[i]));
95 }
96 ASSERT(!target.IsNull());
97 data_->SetAt(pos, target);
98 }
99
100
101 void ICData::GetOneClassCheckAt(intptr_t index,
102 Class* cls,
103 Function* target) const {
104 ASSERT(cls != NULL);
105 ASSERT(target != NULL);
106 ASSERT((0 <= index) && (index < NumberOfChecks()));
107 ASSERT(NumberOfArgumentsChecked() == 1);
108 intptr_t pos = 1 + 1 + ArrayElementsPerCheck() * index;
109 *cls ^= data_->At(pos);
110 (*target) ^= data_->At(pos + 1);
111 }
112
113
114 void ICData::GetCheckAt(intptr_t index,
115 GrowableArray<const Class*>* classes,
116 Function* target) const {
117 ASSERT(classes != NULL);
118 ASSERT(target != NULL);
119 ASSERT((0 <= index) && (index < NumberOfChecks()));
120 classes->Clear();
121 intptr_t pos = 1 + 1 + ArrayElementsPerCheck() * index;
122 for (intptr_t i = 0; i < NumberOfArgumentsChecked(); i++) {
123 Class& cls = Class::ZoneHandle();
124 cls ^= data_->At(pos++);
125 classes->Add(&cls);
126 }
127 (*target) ^= data_->At(pos);
128 }
129
130 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/ic_data.h ('k') | runtime/vm/ic_data_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698