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

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

Issue 9475031: Cleaned up usage of Function::code, since it may be misunderstood that it points to the only Code o… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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/code_index_table.h ('k') | runtime/vm/code_index_table_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
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 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 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/code_index_table.h" 5 #include "vm/code_index_table.h"
6 6
7 #include "vm/isolate.h" 7 #include "vm/isolate.h"
8 #include "vm/object.h" 8 #include "vm/object.h"
9 #include "vm/pages.h" 9 #include "vm/pages.h"
10 #include "vm/raw_object.h" 10 #include "vm/raw_object.h"
(...skipping 16 matching lines...) Expand all
27 IndexArray<PcRange>* pc_ranges = code_pages_->At(i).pc_ranges; 27 IndexArray<PcRange>* pc_ranges = code_pages_->At(i).pc_ranges;
28 delete pc_ranges; 28 delete pc_ranges;
29 } 29 }
30 delete code_pages_; 30 delete code_pages_;
31 code_lists_ = Array::null(); 31 code_lists_ = Array::null();
32 delete largecode_pc_ranges_; 32 delete largecode_pc_ranges_;
33 largecode_list_ = Array::null(); 33 largecode_list_ = Array::null();
34 } 34 }
35 35
36 36
37 void CodeIndexTable::AddFunction(const Function& func) { 37 void CodeIndexTable::AddCode(const Code& code) {
38 const Code& code = Code::Handle(func.code());
39 ASSERT(!code.IsNull()); 38 ASSERT(!code.IsNull());
40 uword entrypoint = code.EntryPoint(); // Entry point for a function. 39 uword entrypoint = code.EntryPoint(); // Entry point for a function.
41 intptr_t instr_size = code.Size(); // Instructions size for the function. 40 intptr_t instr_size = code.Size(); // Instructions size for the function.
42 if (PageSpace::IsPageAllocatableSize(instr_size)) { 41 if (PageSpace::IsPageAllocatableSize(instr_size)) {
43 uword page_start = (entrypoint & ~(PageSpace::kPageSize - 1)); 42 uword page_start = (entrypoint & ~(PageSpace::kPageSize - 1));
44 int page_index = FindPageIndex(page_start); 43 int page_index = FindPageIndex(page_start);
45 if (page_index == -1) { 44 if (page_index == -1) {
46 // We do not have an entry for this code page, add one. 45 // We do not have an entry for this code page, add one.
47 page_index = AddPageIndex(page_start); 46 page_index = AddPageIndex(page_start);
48 } 47 }
49 ASSERT(page_index != -1); 48 ASSERT(page_index != -1);
50 // Add the entrypoint, size and function object at the specified index. 49 // Add the entrypoint, size and function object at the specified index.
51 AddFunctionToList(page_index, entrypoint, instr_size, func); 50 AddCodeToList(page_index, entrypoint, instr_size, code);
52 } else { 51 } else {
53 AddLargeFunction(entrypoint, instr_size, func); 52 AddLargeCode(entrypoint, instr_size, code);
54 } 53 }
55 } 54 }
56 55
57 56
58 RawFunction* CodeIndexTable::LookupFunction(uword pc) const {
59 const Code& code = Code::Handle(LookupCode(pc));
60 if (code.IsNull()) {
61 return Function::null();
62 }
63 return code.function();
64 }
65
66
67 RawCode* CodeIndexTable::LookupCode(uword pc) const { 57 RawCode* CodeIndexTable::LookupCode(uword pc) const {
68 uword page_start = (pc & ~(PageSpace::kPageSize - 1)); 58 uword page_start = (pc & ~(PageSpace::kPageSize - 1));
69 int page_index = FindPageIndex(page_start); 59 int page_index = FindPageIndex(page_start);
70 if (page_index == -1) { 60 if (page_index == -1) {
71 // Check if the pc exists in the large pc ranges as this might be 61 // Check if the pc exists in the large pc ranges as this might be
72 // the pc of a large code object. This would return the large code 62 // the pc of a large code object. This would return the large code
73 // or a null object if it doesn't exist in that list too. 63 // or a null object if it doesn't exist in that list too.
74 return LookupLargeCode(pc); 64 return LookupLargeCode(pc);
75 } 65 }
76 IndexArray<PcRange>* pc_ranges = code_pages_->At(page_index).pc_ranges; 66 IndexArray<PcRange>* pc_ranges = code_pages_->At(page_index).pc_ranges;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 // table. 114 // table.
125 for (int i = 0; i < code_pages_->length(); i++) { 115 for (int i = 0; i < code_pages_->length(); i++) {
126 if (code_pages_->At(i).page_start == page_start) { 116 if (code_pages_->At(i).page_start == page_start) {
127 return i; 117 return i;
128 } 118 }
129 } 119 }
130 return -1; 120 return -1;
131 } 121 }
132 122
133 123
134 void CodeIndexTable::AddFunctionToList(int page_index, 124 void CodeIndexTable::AddCodeToList(int page_index,
135 uword entrypoint, 125 uword entrypoint,
136 intptr_t size, 126 intptr_t size,
137 const Function& func) { 127 const Code& code) {
138 // Get PC ranges index array at specified index. 128 // Get PC ranges index array at specified index.
139 IndexArray<PcRange>* pc_ranges = code_pages_->At(page_index).pc_ranges; 129 IndexArray<PcRange>* pc_ranges = code_pages_->At(page_index).pc_ranges;
140 ASSERT(pc_ranges != NULL); 130 ASSERT(pc_ranges != NULL);
141 const Array& codes_list = Array::Handle(code_lists_); 131 const Array& codes_list = Array::Handle(code_lists_);
142 ASSERT(!codes_list.IsNull()); 132 ASSERT(!codes_list.IsNull());
143 // Get functions array present at specified index. 133 // Get functions array present at specified index.
144 Array& codes = Array::Handle(); 134 Array& codes = Array::Handle();
145 codes ^= codes_list.At(page_index); 135 codes ^= codes_list.At(page_index);
146 ASSERT(!codes.IsNull()); 136 ASSERT(!codes.IsNull());
147 // Asserting with an unsorted search, to ensure addition of pc was done right. 137 // Asserting with an unsorted search, to ensure addition of pc was done right.
148 ASSERT(FindPcIndex(*pc_ranges, entrypoint, kIsNotSorted) == -1); 138 ASSERT(FindPcIndex(*pc_ranges, entrypoint, kIsNotSorted) == -1);
149 AddFuncHelper(pc_ranges, codes, entrypoint, size, func); 139 AddCodeHelper(pc_ranges, codes, entrypoint, size, code);
150 if (pc_ranges->IsFull()) { 140 if (pc_ranges->IsFull()) {
151 // Grow the pc ranges table and the associated functions table. 141 // Grow the pc ranges table and the associated functions table.
152 int new_size = pc_ranges->length() + kInitialSize; 142 int new_size = pc_ranges->length() + kInitialSize;
153 pc_ranges->Resize(new_size); 143 pc_ranges->Resize(new_size);
154 codes = Array::Grow(codes, new_size); 144 codes = Array::Grow(codes, new_size);
155 codes_list.SetAt(page_index, codes); 145 codes_list.SetAt(page_index, codes);
156 } 146 }
157 } 147 }
158 148
159 149
160 void CodeIndexTable::AddLargeFunction(uword entrypoint, 150 void CodeIndexTable::AddLargeCode(uword entrypoint,
161 intptr_t size, 151 intptr_t size,
162 const Function& func) { 152 const Code& code) {
163 if (largecode_pc_ranges_ == NULL) { 153 if (largecode_pc_ranges_ == NULL) {
164 // No large functions seen so far. 154 // No large functions seen so far.
165 largecode_pc_ranges_ = new IndexArray<PcRange>(kInitialSize); 155 largecode_pc_ranges_ = new IndexArray<PcRange>(kInitialSize);
166 ASSERT(largecode_pc_ranges_ != NULL); 156 ASSERT(largecode_pc_ranges_ != NULL);
167 largecode_list_ = Array::New(kInitialSize); 157 largecode_list_ = Array::New(kInitialSize);
168 } 158 }
169 ASSERT(FindPcIndex(*largecode_pc_ranges_, entrypoint, kIsNotSorted) == -1); 159 ASSERT(FindPcIndex(*largecode_pc_ranges_, entrypoint, kIsNotSorted) == -1);
170 const Array& largecode_list = Array::Handle(largecode_list_); 160 const Array& largecode_list = Array::Handle(largecode_list_);
171 ASSERT(!largecode_list.IsNull()); 161 ASSERT(!largecode_list.IsNull());
172 AddFuncHelper(largecode_pc_ranges_, largecode_list, entrypoint, size, func); 162 AddCodeHelper(largecode_pc_ranges_, largecode_list, entrypoint, size, code);
173 if (largecode_pc_ranges_->IsFull()) { 163 if (largecode_pc_ranges_->IsFull()) {
174 // Grow largecode_pc_ranges_ and largecode_list_. 164 // Grow largecode_pc_ranges_ and largecode_list_.
175 int new_size = largecode_pc_ranges_->length() + kInitialSize; 165 int new_size = largecode_pc_ranges_->length() + kInitialSize;
176 largecode_pc_ranges_->Resize(new_size); 166 largecode_pc_ranges_->Resize(new_size);
177 largecode_list_ = Array::Grow(largecode_list, new_size); 167 largecode_list_ = Array::Grow(largecode_list, new_size);
178 } 168 }
179 } 169 }
180 170
181 171
182 void CodeIndexTable::AddFuncHelper(IndexArray<PcRange>* pc_ranges, 172 void CodeIndexTable::AddCodeHelper(IndexArray<PcRange>* pc_ranges,
183 const Array& codes, 173 const Array& codes,
184 uword entrypoint, 174 uword entrypoint,
185 intptr_t size, 175 intptr_t size,
186 const Function& func) { 176 const Code& code) {
187 PcRange pc_range; 177 PcRange pc_range;
188 pc_range.entrypoint = entrypoint; 178 pc_range.entrypoint = entrypoint;
189 pc_range.size = size; 179 pc_range.size = size;
190 intptr_t next_slot = pc_ranges->length(); 180 intptr_t next_slot = pc_ranges->length();
191 pc_ranges->Add(pc_range); // pc_range gets added at 'next_slot'. 181 pc_ranges->Add(pc_range); // pc_range gets added at 'next_slot'.
192 codes.SetAt(next_slot, Code::Handle(func.code())); 182 codes.SetAt(next_slot, code);
193 } 183 }
194 184
195 185
196 RawCode* CodeIndexTable::LookupLargeCode(uword pc) const { 186 RawCode* CodeIndexTable::LookupLargeCode(uword pc) const {
197 const Array& large_codes = Array::Handle(largecode_list_); 187 const Array& large_codes = Array::Handle(largecode_list_);
198 return LookupCodeFromList(largecode_pc_ranges_, 188 return LookupCodeFromList(largecode_pc_ranges_,
199 large_codes, 189 large_codes,
200 pc, 190 pc,
201 kIsNotSorted); 191 kIsNotSorted);
202 } 192 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 return -1; // Entry not found. 248 return -1; // Entry not found.
259 } 249 }
260 250
261 251
262 void CodeIndexTable::GrowCodeIndexTable(int new_size) { 252 void CodeIndexTable::GrowCodeIndexTable(int new_size) {
263 code_pages_->Resize(new_size); 253 code_pages_->Resize(new_size);
264 code_lists_ = Array::Grow(Array::Handle(code_lists_), new_size); 254 code_lists_ = Array::Grow(Array::Handle(code_lists_), new_size);
265 } 255 }
266 256
267 } // namespace dart 257 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/code_index_table.h ('k') | runtime/vm/code_index_table_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698