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