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 <limits> | 8 #include <limits> |
9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
(...skipping 3029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3040 | 3040 |
3041 void PrintToJSONObject(JSONObject* jsobj) const; | 3041 void PrintToJSONObject(JSONObject* jsobj) const; |
3042 | 3042 |
3043 // We would have a VisitPointers function here to traverse the | 3043 // We would have a VisitPointers function here to traverse the |
3044 // pc descriptors table to visit objects if any in the table. | 3044 // pc descriptors table to visit objects if any in the table. |
3045 // Note: never return a reference to a RawPcDescriptors::PcDescriptorRec | 3045 // Note: never return a reference to a RawPcDescriptors::PcDescriptorRec |
3046 // as the object can move. | 3046 // as the object can move. |
3047 class Iterator : ValueObject { | 3047 class Iterator : ValueObject { |
3048 public: | 3048 public: |
3049 Iterator(const PcDescriptors& descriptors, intptr_t kind_mask) | 3049 Iterator(const PcDescriptors& descriptors, intptr_t kind_mask) |
3050 : descriptors_(descriptors), kind_mask_(kind_mask), current_ix_(0) { | 3050 : descriptors_(descriptors), |
| 3051 kind_mask_(kind_mask), |
| 3052 next_ix_(0), |
| 3053 current_ix_(-1) { |
3051 MoveToMatching(); | 3054 MoveToMatching(); |
3052 } | 3055 } |
3053 | 3056 |
3054 bool HasNext() const { return current_ix_ < descriptors_.Length(); } | 3057 bool MoveNext() { |
3055 | 3058 if (HasNext()) { |
3056 intptr_t NextDeoptId() { | 3059 current_ix_ = next_ix_++; |
3057 ASSERT(HasNext()); | 3060 MoveToMatching(); |
3058 const intptr_t res = descriptors_.recAt(current_ix_++)->deopt_id(); | 3061 return true; |
3059 MoveToMatching(); | 3062 } else { |
3060 return res; | 3063 return false; |
| 3064 } |
3061 } | 3065 } |
3062 | 3066 |
3063 uword NextPc() { | 3067 uword Pc() const { return descriptors_.recAt(current_ix_)->pc(); } |
3064 ASSERT(HasNext()); | 3068 intptr_t DeoptId() const { |
3065 const uword res = descriptors_.recAt(current_ix_++)->pc(); | 3069 return descriptors_.recAt(current_ix_)->deopt_id(); |
3066 MoveToMatching(); | |
3067 return res; | |
3068 } | 3070 } |
3069 | 3071 intptr_t TokenPos() const { |
3070 void NextRec(RawPcDescriptors::PcDescriptorRec* result) { | 3072 return descriptors_.recAt(current_ix_)->token_pos(); |
3071 ASSERT(HasNext()); | 3073 } |
3072 const RawPcDescriptors::PcDescriptorRec* r = | 3074 intptr_t TryIndex() const { |
3073 descriptors_.recAt(current_ix_++); | 3075 return descriptors_.recAt(current_ix_)->try_index(); |
3074 r->CopyTo(result); | 3076 } |
3075 MoveToMatching(); | 3077 RawPcDescriptors::Kind Kind() const { |
| 3078 return descriptors_.recAt(current_ix_)->kind(); |
3076 } | 3079 } |
3077 | 3080 |
3078 private: | 3081 private: |
3079 friend class PcDescriptors; | 3082 friend class PcDescriptors; |
3080 | 3083 |
| 3084 bool HasNext() const { return next_ix_ < descriptors_.Length(); } |
| 3085 |
3081 // For nested iterations, starting at element after. | 3086 // For nested iterations, starting at element after. |
3082 explicit Iterator(const Iterator& iter) | 3087 explicit Iterator(const Iterator& iter) |
3083 : ValueObject(), | 3088 : ValueObject(), |
3084 descriptors_(iter.descriptors_), | 3089 descriptors_(iter.descriptors_), |
3085 kind_mask_(iter.kind_mask_), | 3090 kind_mask_(iter.kind_mask_), |
| 3091 next_ix_(iter.next_ix_), |
3086 current_ix_(iter.current_ix_) {} | 3092 current_ix_(iter.current_ix_) {} |
3087 | 3093 |
3088 // Moves to record that matches kind_mask_. | 3094 // Moves to record that matches kind_mask_. |
3089 void MoveToMatching() { | 3095 void MoveToMatching() { |
3090 while (current_ix_ < descriptors_.Length()) { | 3096 while (next_ix_ < descriptors_.Length()) { |
3091 const RawPcDescriptors::PcDescriptorRec& rec = | 3097 const RawPcDescriptors::PcDescriptorRec& rec = |
3092 *descriptors_.recAt(current_ix_); | 3098 *descriptors_.recAt(next_ix_); |
3093 if ((rec.kind() & kind_mask_) != 0) { | 3099 if ((rec.kind() & kind_mask_) != 0) { |
3094 return; // Current is valid. | 3100 return; // Current is valid. |
3095 } else { | 3101 } else { |
3096 ++current_ix_; | 3102 ++next_ix_; |
3097 } | 3103 } |
3098 } | 3104 } |
3099 } | 3105 } |
3100 | 3106 |
3101 const PcDescriptors& descriptors_; | 3107 const PcDescriptors& descriptors_; |
3102 const intptr_t kind_mask_; | 3108 const intptr_t kind_mask_; |
| 3109 intptr_t next_ix_; |
3103 intptr_t current_ix_; | 3110 intptr_t current_ix_; |
3104 }; | 3111 }; |
3105 | 3112 |
3106 private: | 3113 private: |
3107 static const char* KindAsStr(RawPcDescriptors::Kind kind); | 3114 static const char* KindAsStr(RawPcDescriptors::Kind kind); |
3108 | 3115 |
3109 intptr_t Length() const; | 3116 intptr_t Length() const; |
3110 void SetLength(intptr_t value) const; | 3117 void SetLength(intptr_t value) const; |
3111 | 3118 |
3112 void SetRecordSizeInBytes(intptr_t value) const; | 3119 void SetRecordSizeInBytes(intptr_t value) const; |
3113 intptr_t RecordSizeInBytes() const; | 3120 intptr_t RecordSizeInBytes() const; |
3114 | 3121 |
3115 RawPcDescriptors::PcDescriptorRec* recAt(intptr_t ix) const { | 3122 RawPcDescriptors::PcDescriptorRec* recAt(intptr_t ix) const { |
3116 ASSERT(ix < Length()); | 3123 ASSERT((0 <= ix) && (ix < Length())); |
3117 uint8_t* d = raw_ptr()->data() + (ix * RecordSizeInBytes()); | 3124 uint8_t* d = raw_ptr()->data() + (ix * RecordSizeInBytes()); |
3118 return reinterpret_cast<RawPcDescriptors::PcDescriptorRec*>(d); | 3125 return reinterpret_cast<RawPcDescriptors::PcDescriptorRec*>(d); |
3119 } | 3126 } |
3120 | 3127 |
3121 FINAL_HEAP_OBJECT_IMPLEMENTATION(PcDescriptors, Object); | 3128 FINAL_HEAP_OBJECT_IMPLEMENTATION(PcDescriptors, Object); |
3122 friend class Class; | 3129 friend class Class; |
3123 friend class Object; | 3130 friend class Object; |
3124 }; | 3131 }; |
3125 | 3132 |
3126 | 3133 |
(...skipping 4113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7240 | 7247 |
7241 | 7248 |
7242 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, | 7249 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, |
7243 intptr_t index) { | 7250 intptr_t index) { |
7244 return array.At((index * kEntryLength) + kTargetFunctionIndex); | 7251 return array.At((index * kEntryLength) + kTargetFunctionIndex); |
7245 } | 7252 } |
7246 | 7253 |
7247 } // namespace dart | 7254 } // namespace dart |
7248 | 7255 |
7249 #endif // VM_OBJECT_H_ | 7256 #endif // VM_OBJECT_H_ |
OLD | NEW |