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/assembler.h" | 5 #include "vm/assembler.h" |
6 | 6 |
7 #include "platform/utils.h" | 7 #include "platform/utils.h" |
8 #include "vm/cpu.h" | 8 #include "vm/cpu.h" |
9 #include "vm/heap.h" | 9 #include "vm/heap.h" |
10 #include "vm/memory_region.h" | 10 #include "vm/memory_region.h" |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 | 235 |
236 for (intptr_t i = 0; i < comments_.length(); i++) { | 236 for (intptr_t i = 0; i < comments_.length(); i++) { |
237 comments.SetPCOffsetAt(i, comments_[i]->pc_offset()); | 237 comments.SetPCOffsetAt(i, comments_[i]->pc_offset()); |
238 comments.SetCommentAt(i, comments_[i]->comment()); | 238 comments.SetCommentAt(i, comments_[i]->comment()); |
239 } | 239 } |
240 | 240 |
241 return comments; | 241 return comments; |
242 } | 242 } |
243 | 243 |
244 | 244 |
245 intptr_t ObjectPool::AddObject(const Object& obj, Patchability patchable) { | 245 intptr_t ObjectPoolHelper::AddObject(const Object& obj) { |
| 246 return AddObject(ObjectPool::Entry(&obj), kNotPatchable); |
| 247 } |
| 248 |
| 249 |
| 250 intptr_t ObjectPoolHelper::AddImmediate(uword imm) { |
| 251 return AddObject(ObjectPool::Entry(imm, ObjectPool::kImmediate), |
| 252 kNotPatchable); |
| 253 } |
| 254 |
| 255 intptr_t ObjectPoolHelper::AddObject(ObjectPool::Entry entry, |
| 256 Patchability patchable) { |
246 // The object pool cannot be used in the vm isolate. | 257 // The object pool cannot be used in the vm isolate. |
247 ASSERT(Isolate::Current() != Dart::vm_isolate()); | 258 ASSERT(Isolate::Current() != Dart::vm_isolate()); |
248 if (object_pool_.IsNull()) { | 259 object_pool_.Add(entry); |
249 object_pool_ = GrowableObjectArray::New(Heap::kOld); | |
250 } | |
251 object_pool_.Add(obj, Heap::kOld); | |
252 patchable_pool_entries_.Add(patchable); | |
253 if (patchable == kNotPatchable) { | 260 if (patchable == kNotPatchable) { |
254 // The object isn't patchable. Record the index for fast lookup. | 261 // The object isn't patchable. Record the index for fast lookup. |
255 object_pool_index_table_.Insert( | 262 object_pool_index_table_.Insert( |
256 ObjIndexPair(&obj, object_pool_.Length() - 1)); | 263 ObjIndexPair(entry, object_pool_.length() - 1)); |
257 } | 264 } |
258 return object_pool_.Length() - 1; | 265 return object_pool_.length() - 1; |
259 } | 266 } |
260 | 267 |
261 | 268 |
262 intptr_t ObjectPool::AddExternalLabel(const ExternalLabel* label, | 269 intptr_t ObjectPoolHelper::AddExternalLabel(const ExternalLabel* label, |
263 Patchability patchable) { | 270 Patchability patchable) { |
264 ASSERT(Isolate::Current() != Dart::vm_isolate()); | 271 ASSERT(Isolate::Current() != Dart::vm_isolate()); |
265 const uword address = label->address(); | 272 return AddObject(ObjectPool::Entry(label->address(), |
266 ASSERT(Utils::IsAligned(address, 4)); | 273 ObjectPool::kImmediate), |
267 // The address is stored in the object array as a RawSmi. | 274 patchable); |
268 const Smi& smi = Smi::Handle(reinterpret_cast<RawSmi*>(address)); | |
269 return AddObject(smi, patchable); | |
270 } | 275 } |
271 | 276 |
272 | 277 |
273 intptr_t ObjectPool::FindObject(const Object& obj, Patchability patchable) { | 278 intptr_t ObjectPoolHelper::FindObject(ObjectPool::Entry entry, |
| 279 Patchability patchable) { |
274 // The object pool cannot be used in the vm isolate. | 280 // The object pool cannot be used in the vm isolate. |
275 ASSERT(Isolate::Current() != Dart::vm_isolate()); | 281 ASSERT(Isolate::Current() != Dart::vm_isolate()); |
276 | 282 |
277 // If the object is not patchable, check if we've already got it in the | 283 // If the object is not patchable, check if we've already got it in the |
278 // object pool. | 284 // object pool. |
279 if (patchable == kNotPatchable && !object_pool_.IsNull()) { | 285 if (patchable == kNotPatchable) { |
280 intptr_t idx = object_pool_index_table_.Lookup(&obj); | 286 intptr_t idx = object_pool_index_table_.Lookup(entry); |
281 if (idx != ObjIndexPair::kNoIndex) { | 287 if (idx != ObjIndexPair::kNoIndex) { |
282 ASSERT(patchable_pool_entries_[idx] == kNotPatchable); | |
283 return idx; | 288 return idx; |
284 } | 289 } |
285 } | 290 } |
286 | 291 |
287 return AddObject(obj, patchable); | 292 return AddObject(entry, patchable); |
288 } | 293 } |
289 | 294 |
290 | 295 |
291 intptr_t ObjectPool::FindExternalLabel(const ExternalLabel* label, | 296 intptr_t ObjectPoolHelper::FindObject(const Object& obj) { |
292 Patchability patchable) { | 297 return FindObject(ObjectPool::Entry(&obj), kNotPatchable); |
293 // The object pool cannot be used in the vm isolate. | |
294 ASSERT(Isolate::Current() != Dart::vm_isolate()); | |
295 const uword address = label->address(); | |
296 ASSERT(Utils::IsAligned(address, 4)); | |
297 // The address is stored in the object array as a RawSmi. | |
298 const Smi& smi = Smi::Handle(reinterpret_cast<RawSmi*>(address)); | |
299 return FindObject(smi, patchable); | |
300 } | 298 } |
301 | 299 |
302 | 300 |
| 301 intptr_t ObjectPoolHelper::FindImmediate(uword imm) { |
| 302 return FindObject(ObjectPool::Entry(imm, ObjectPool::kImmediate), |
| 303 kNotPatchable); |
| 304 } |
| 305 |
| 306 |
| 307 intptr_t ObjectPoolHelper::FindExternalLabel(const ExternalLabel* label, |
| 308 Patchability patchable) { |
| 309 // The object pool cannot be used in the vm isolate. |
| 310 ASSERT(Isolate::Current() != Dart::vm_isolate()); |
| 311 return FindObject(ObjectPool::Entry(label->address(), |
| 312 ObjectPool::kImmediate), |
| 313 patchable); |
| 314 } |
| 315 |
| 316 |
| 317 RawObjectPool* ObjectPoolHelper::MakeObjectPool() { |
| 318 intptr_t len = object_pool_.length(); |
| 319 if (len == 0) { |
| 320 return Object::empty_object_pool().raw(); |
| 321 } |
| 322 const ObjectPool& result = ObjectPool::Handle(ObjectPool::New(len)); |
| 323 for (intptr_t i = 0; i < len; ++i) { |
| 324 ObjectPool::EntryType info = object_pool_[i].type_; |
| 325 result.SetInfoAt(i, info); |
| 326 if (info == ObjectPool::kTaggedObject) { |
| 327 result.SetObjectAt(i, *object_pool_[i].obj_); |
| 328 } else { |
| 329 result.SetRawValueAt(i, object_pool_[i].raw_value_); |
| 330 } |
| 331 } |
| 332 return result.raw(); |
| 333 } |
| 334 |
| 335 |
303 } // namespace dart | 336 } // namespace dart |
OLD | NEW |