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

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

Issue 8357034: Transitioning to new IC structure: change IC data to include function name; pass IC data instead ... (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 2 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
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 }
13
14
15 ICData::ICData(const String& function_name, intptr_t num_args_checked)
16 : data_(NULL) {
17 // Array contains: function-name, num_checked, NULL check sentinel (classes,
18 // target).
19 const intptr_t len = kChecksStartIndex + (num_args_checked + 1);
20 data_ = &Array::ZoneHandle(Array::New(len, Heap::kOld));
21 data_->SetAt(kNameIndex, function_name);
22 data_->SetAt(kNumArgsCheckedIndex, Smi::Handle(Smi::New(num_args_checked)));
23 }
24
25
26 RawArray* ICData::data() const {
27 return data_->raw();
28 }
29
30
31 intptr_t ICData::ArrayElementsPerCheck() const {
32 // Number of checked classes + target.
33 return NumberOfArgumentsChecked() + 1;
34 }
35
36
37 intptr_t ICData::NumberOfArgumentsChecked() const {
38 Smi& result = Smi::Handle();
39 result ^= data_->At(kNumArgsCheckedIndex);
40 return result.Value();
41 }
42
43
44 intptr_t ICData::NumberOfChecks() const {
45 const intptr_t per_check = ArrayElementsPerCheck();
46 // Subtract function-name, num-checked and sentinel
47 intptr_t len = data_->Length() - kChecksStartIndex - per_check;
48 ASSERT(len % per_check == 0);
49 return len / per_check;
50 }
51
52
53 RawString* ICData::FunctionName() const {
54 String& result = String::Handle();
55 result ^= data_->At(kNameIndex);
56 return result.raw();
57 }
58
59
60 void ICData::AddCheck(const GrowableArray<const Class*>& classes,
61 const Function& target) {
62 intptr_t old_number_of_checks = NumberOfChecks();
63 intptr_t new_len = data_->Length() + ArrayElementsPerCheck();
64 data_ =
65 &Array::ZoneHandle(Array::Grow(*data_, new_len, Heap::kOld));
regis 2011/10/21 03:03:52 Should fit on one line.
srdjan 2011/10/22 07:48:53 Done.
66 SetCheckAt(old_number_of_checks, classes, target);
67 }
68
69
70 void ICData::SetCheckAt(intptr_t index,
71 const GrowableArray<const Class*>& classes,
72 const Function& target) {
73 ASSERT((0 <= index) && (index < NumberOfChecks()));
74 intptr_t pos = kChecksStartIndex + ArrayElementsPerCheck() * index;
75 ASSERT(classes.length() == NumberOfArgumentsChecked());
76 for (intptr_t i = 0; i < classes.length(); i++) {
77 // Null is used as terminating object, do not add it.
78 ASSERT(!classes[i]->IsNull());
79 // Contract says that no null classes may be added.
regis 2011/10/21 03:03:52 There is only one Null class. How about // Contrac
srdjan 2011/10/22 07:48:53 Done.
80 ASSERT(!classes[i]->IsNullClass());
81 data_->SetAt(pos++, *(classes[i]));
82 }
83 ASSERT(!target.IsNull());
84 data_->SetAt(pos, target);
85 }
86
87
88 void ICData::GetCheckAt(intptr_t index,
89 GrowableArray<const Class*>* classes,
90 Function* target) const {
91 ASSERT(classes != NULL);
92 ASSERT(target != NULL);
93 ASSERT((0 <= index) && (index < NumberOfChecks()));
94 classes->Clear();
95 intptr_t pos = 1 + 1 + ArrayElementsPerCheck() * index;
96 for (intptr_t i = 0; i < NumberOfArgumentsChecked(); i++) {
97 Class& cls = Class::ZoneHandle();
98 cls ^= data_->At(pos++);
99 classes->Add(&cls);
100 }
101 (*target) ^= data_->At(pos);
102 }
103
104 } // namespace dart
OLDNEW
« runtime/vm/ic_data.h ('K') | « 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