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