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 #ifndef VM_OBJECT_H_ | 5 #ifndef VM_OBJECT_H_ |
6 #define VM_OBJECT_H_ | 6 #define VM_OBJECT_H_ |
7 | 7 |
8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "platform/utils.h" | 10 #include "platform/utils.h" |
(...skipping 3257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3268 | 3268 |
3269 private: | 3269 private: |
3270 FINAL_HEAP_OBJECT_IMPLEMENTATION(LocalVarDescriptors, Object); | 3270 FINAL_HEAP_OBJECT_IMPLEMENTATION(LocalVarDescriptors, Object); |
3271 friend class Class; | 3271 friend class Class; |
3272 friend class Object; | 3272 friend class Object; |
3273 }; | 3273 }; |
3274 | 3274 |
3275 | 3275 |
3276 class PcDescriptors : public Object { | 3276 class PcDescriptors : public Object { |
3277 public: | 3277 public: |
3278 void AddDescriptor(intptr_t index, | 3278 static const intptr_t kBytesPerElement = 1; |
3279 uword pc_offset, | 3279 static const intptr_t kMaxElements = kMaxInt32 / kBytesPerElement; |
3280 RawPcDescriptors::Kind kind, | |
3281 int64_t deopt_id, | |
3282 int64_t token_pos, // Or deopt reason. | |
3283 intptr_t try_index) const { // Or deopt index. | |
3284 NoSafepointScope no_safepoint; | |
3285 RawPcDescriptors::PcDescriptorRec* rec = recAt(index); | |
3286 rec->set_pc_offset(pc_offset); | |
3287 rec->set_kind(kind); | |
3288 ASSERT(Utils::IsInt(32, deopt_id)); | |
3289 rec->set_deopt_id(static_cast<int32_t>(deopt_id)); | |
3290 ASSERT(Utils::IsInt(32, token_pos)); | |
3291 rec->set_token_pos(static_cast<int32_t>(token_pos), | |
3292 RecordSizeInBytes() == RawPcDescriptors::kCompressedRecSize); | |
3293 ASSERT(Utils::IsInt(16, try_index)); | |
3294 rec->set_try_index(try_index); | |
3295 ASSERT(rec->try_index() == try_index); | |
3296 ASSERT(rec->token_pos() == token_pos); | |
3297 } | |
3298 | |
3299 static const intptr_t kMaxBytesPerElement = | |
3300 sizeof(RawPcDescriptors::PcDescriptorRec); | |
3301 static const intptr_t kMaxElements = kMaxInt32 / kMaxBytesPerElement; | |
3302 | 3280 |
3303 static intptr_t InstanceSize() { | 3281 static intptr_t InstanceSize() { |
3304 ASSERT(sizeof(RawPcDescriptors) == | 3282 ASSERT(sizeof(RawPcDescriptors) == |
3305 OFFSET_OF_RETURNED_VALUE(RawPcDescriptors, data)); | 3283 OFFSET_OF_RETURNED_VALUE(RawPcDescriptors, data)); |
3306 return 0; | 3284 return 0; |
3307 } | 3285 } |
3308 static intptr_t InstanceSize(intptr_t len, intptr_t record_size_in_bytes) { | 3286 static intptr_t InstanceSize(intptr_t len) { |
3309 ASSERT(0 <= len && len <= kMaxElements); | 3287 ASSERT(0 <= len && len <= kMaxElements); |
3310 return RoundedAllocationSize( | 3288 return RoundedAllocationSize(sizeof(RawPcDescriptors) + len); |
3311 sizeof(RawPcDescriptors) + (len * record_size_in_bytes)); | |
3312 } | 3289 } |
3313 | 3290 |
3314 static RawPcDescriptors* New(intptr_t num_descriptors, bool has_try_index); | 3291 static RawPcDescriptors* New(GrowableArray<uint8_t>* delta_encoded_data); |
3315 | 3292 |
3316 // Verify (assert) assumptions about pc descriptors in debug mode. | 3293 // Verify (assert) assumptions about pc descriptors in debug mode. |
3317 void Verify(const Function& function) const; | 3294 void Verify(const Function& function) const; |
3318 | 3295 |
3319 static void PrintHeaderString(); | 3296 static void PrintHeaderString(); |
3320 | 3297 |
3321 void PrintToJSONObject(JSONObject* jsobj, bool ref) const; | 3298 void PrintToJSONObject(JSONObject* jsobj, bool ref) const; |
3322 | 3299 |
| 3300 // Encode integer in SLEB128 format. |
| 3301 static void EncodeInteger(GrowableArray<uint8_t>* data, intptr_t value); |
| 3302 |
| 3303 // Decode SLEB128 encoded integer. Update byte_index to the next integer. |
| 3304 intptr_t DecodeInteger(intptr_t* byte_index) const; |
| 3305 |
3323 // We would have a VisitPointers function here to traverse the | 3306 // We would have a VisitPointers function here to traverse the |
3324 // pc descriptors table to visit objects if any in the table. | 3307 // pc descriptors table to visit objects if any in the table. |
3325 // Note: never return a reference to a RawPcDescriptors::PcDescriptorRec | 3308 // Note: never return a reference to a RawPcDescriptors::PcDescriptorRec |
3326 // as the object can move. | 3309 // as the object can move. |
3327 class Iterator : ValueObject { | 3310 class Iterator : ValueObject { |
3328 public: | 3311 public: |
3329 Iterator(const PcDescriptors& descriptors, intptr_t kind_mask) | 3312 Iterator(const PcDescriptors& descriptors, intptr_t kind_mask) |
3330 : descriptors_(descriptors), | 3313 : descriptors_(descriptors), |
3331 kind_mask_(kind_mask), | 3314 kind_mask_(kind_mask), |
3332 next_ix_(0), | 3315 byte_index_(0), |
3333 current_ix_(-1) { | 3316 cur_pc_offset_(0), |
3334 MoveToMatching(); | 3317 cur_kind_(0), |
| 3318 cur_deopt_id_(0), |
| 3319 cur_token_pos_(0), |
| 3320 cur_try_index_(0) { |
3335 } | 3321 } |
3336 | 3322 |
3337 bool MoveNext() { | 3323 bool MoveNext() { |
3338 if (HasNext()) { | 3324 // Moves to record that matches kind_mask_. |
3339 current_ix_ = next_ix_++; | 3325 while (byte_index_ < descriptors_.Length()) { |
3340 MoveToMatching(); | 3326 cur_kind_ = descriptors_.DecodeInteger(&byte_index_); |
3341 return true; | 3327 cur_try_index_ = descriptors_.DecodeInteger(&byte_index_); |
3342 } else { | 3328 cur_pc_offset_ += descriptors_.DecodeInteger(&byte_index_); |
3343 return false; | 3329 cur_deopt_id_ += descriptors_.DecodeInteger(&byte_index_); |
| 3330 cur_token_pos_ += descriptors_.DecodeInteger(&byte_index_); |
| 3331 |
| 3332 if ((cur_kind_ & kind_mask_) != 0) { |
| 3333 return true; // Current is valid. |
| 3334 } |
3344 } | 3335 } |
| 3336 return false; |
3345 } | 3337 } |
3346 | 3338 |
3347 uword PcOffset() const { | 3339 uword PcOffset() const { return cur_pc_offset_; } |
3348 NoSafepointScope no_safepoint; | 3340 intptr_t DeoptId() const { return cur_deopt_id_; } |
3349 return descriptors_.recAt(current_ix_)->pc_offset(); | 3341 intptr_t TokenPos() const { return cur_token_pos_; } |
3350 } | 3342 intptr_t TryIndex() const { return cur_try_index_; } |
3351 intptr_t DeoptId() const { | |
3352 NoSafepointScope no_safepoint; | |
3353 return descriptors_.recAt(current_ix_)->deopt_id(); | |
3354 } | |
3355 intptr_t TokenPos() const { | |
3356 NoSafepointScope no_safepoint; | |
3357 return descriptors_.recAt(current_ix_)->token_pos(); | |
3358 } | |
3359 intptr_t TryIndex() const { | |
3360 NoSafepointScope no_safepoint; | |
3361 return descriptors_.recAt(current_ix_)->try_index(); | |
3362 } | |
3363 RawPcDescriptors::Kind Kind() const { | 3343 RawPcDescriptors::Kind Kind() const { |
3364 NoSafepointScope no_safepoint; | 3344 return static_cast<RawPcDescriptors::Kind>(cur_kind_); |
3365 return descriptors_.recAt(current_ix_)->kind(); | |
3366 } | 3345 } |
3367 | 3346 |
3368 private: | 3347 private: |
3369 friend class PcDescriptors; | 3348 friend class PcDescriptors; |
3370 | 3349 |
3371 bool HasNext() const { return next_ix_ < descriptors_.Length(); } | |
3372 | |
3373 // For nested iterations, starting at element after. | 3350 // For nested iterations, starting at element after. |
3374 explicit Iterator(const Iterator& iter) | 3351 explicit Iterator(const Iterator& iter) |
3375 : ValueObject(), | 3352 : ValueObject(), |
3376 descriptors_(iter.descriptors_), | 3353 descriptors_(iter.descriptors_), |
3377 kind_mask_(iter.kind_mask_), | 3354 kind_mask_(iter.kind_mask_), |
3378 next_ix_(iter.next_ix_), | 3355 byte_index_(iter.byte_index_), |
3379 current_ix_(iter.current_ix_) {} | 3356 cur_pc_offset_(iter.cur_pc_offset_), |
3380 | 3357 cur_kind_(iter.cur_kind_), |
3381 // Moves to record that matches kind_mask_. | 3358 cur_deopt_id_(iter.cur_deopt_id_), |
3382 void MoveToMatching() { | 3359 cur_token_pos_(iter.cur_token_pos_), |
3383 NoSafepointScope no_safepoint; | 3360 cur_try_index_(iter.cur_try_index_) {} |
3384 while (next_ix_ < descriptors_.Length()) { | |
3385 const RawPcDescriptors::PcDescriptorRec& rec = | |
3386 *descriptors_.recAt(next_ix_); | |
3387 if ((rec.kind() & kind_mask_) != 0) { | |
3388 return; // Current is valid. | |
3389 } else { | |
3390 ++next_ix_; | |
3391 } | |
3392 } | |
3393 } | |
3394 | 3361 |
3395 const PcDescriptors& descriptors_; | 3362 const PcDescriptors& descriptors_; |
3396 const intptr_t kind_mask_; | 3363 const intptr_t kind_mask_; |
3397 intptr_t next_ix_; | 3364 intptr_t byte_index_; |
3398 intptr_t current_ix_; | 3365 |
| 3366 intptr_t cur_pc_offset_; |
| 3367 intptr_t cur_kind_; |
| 3368 intptr_t cur_deopt_id_; |
| 3369 intptr_t cur_token_pos_; |
| 3370 intptr_t cur_try_index_; |
3399 }; | 3371 }; |
3400 | 3372 |
3401 private: | 3373 private: |
3402 static const char* KindAsStr(RawPcDescriptors::Kind kind); | 3374 static const char* KindAsStr(RawPcDescriptors::Kind kind); |
3403 | 3375 |
3404 intptr_t Length() const; | 3376 intptr_t Length() const; |
3405 void SetLength(intptr_t value) const; | 3377 void SetLength(intptr_t value) const; |
3406 | 3378 void CopyData(GrowableArray<uint8_t>* data); |
3407 void SetRecordSizeInBytes(intptr_t value) const; | |
3408 intptr_t RecordSizeInBytes() const; | |
3409 | |
3410 RawPcDescriptors::PcDescriptorRec* recAt(intptr_t ix) const { | |
3411 ASSERT((0 <= ix) && (ix < Length())); | |
3412 uint8_t* d = UnsafeMutableNonPointer(raw_ptr()->data()) + | |
3413 (ix * RecordSizeInBytes()); | |
3414 return reinterpret_cast<RawPcDescriptors::PcDescriptorRec*>(d); | |
3415 } | |
3416 | 3379 |
3417 FINAL_HEAP_OBJECT_IMPLEMENTATION(PcDescriptors, Object); | 3380 FINAL_HEAP_OBJECT_IMPLEMENTATION(PcDescriptors, Object); |
3418 friend class Class; | 3381 friend class Class; |
3419 friend class Object; | 3382 friend class Object; |
3420 }; | 3383 }; |
3421 | 3384 |
3422 | 3385 |
3423 class Stackmap : public Object { | 3386 class Stackmap : public Object { |
3424 public: | 3387 public: |
3425 static const intptr_t kNoMaximum = -1; | 3388 static const intptr_t kNoMaximum = -1; |
(...skipping 4346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7772 | 7735 |
7773 | 7736 |
7774 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, | 7737 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, |
7775 intptr_t index) { | 7738 intptr_t index) { |
7776 return array.At((index * kEntryLength) + kTargetFunctionIndex); | 7739 return array.At((index * kEntryLength) + kTargetFunctionIndex); |
7777 } | 7740 } |
7778 | 7741 |
7779 } // namespace dart | 7742 } // namespace dart |
7780 | 7743 |
7781 #endif // VM_OBJECT_H_ | 7744 #endif // VM_OBJECT_H_ |
OLD | NEW |