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 2184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2195 friend class Class; | 2195 friend class Class; |
2196 }; | 2196 }; |
2197 | 2197 |
2198 | 2198 |
2199 class PcDescriptors : public Object { | 2199 class PcDescriptors : public Object { |
2200 private: | 2200 private: |
2201 // Describes the layout of PC descriptor data. | 2201 // Describes the layout of PC descriptor data. |
2202 enum { | 2202 enum { |
2203 kPcEntry = 0, // PC value of the descriptor, unique. | 2203 kPcEntry = 0, // PC value of the descriptor, unique. |
2204 kKindEntry, | 2204 kKindEntry, |
2205 kNodeIdEntry, // AST node id. | 2205 kDeoptIdEntry, // Deopt id. |
2206 kTokenIndexEntry, // Token position in source of PC. | 2206 kTokenPosEntry, // Token position in source of PC. |
2207 kTryIndexEntry, // Try block index of PC. | 2207 kTryIndexEntry, // Try block index of PC. |
2208 // We would potentially be adding other objects here like | 2208 // We would potentially be adding other objects here like |
2209 // pointer maps for optimized functions, local variables information etc. | 2209 // pointer maps for optimized functions, local variables information etc. |
2210 kNumberOfEntries | 2210 kNumberOfEntries |
2211 }; | 2211 }; |
2212 | 2212 |
2213 public: | 2213 public: |
2214 enum Kind { | 2214 enum Kind { |
2215 kDeopt = 0, // Deoptimization cotinuation point. | 2215 kDeopt = 0, // Deoptimization continuation point. |
2216 kDeoptIndex, // Index into deopt info array. | 2216 kDeoptIndex, // Index into deopt info array. |
2217 kPatchCode, // Buffer for patching code entry. | 2217 kPatchCode, // Buffer for patching code entry. |
2218 kIcCall, // IC call. | 2218 kIcCall, // IC call. |
2219 kFuncCall, // Call to known target, e.g. static call, closure call. | 2219 kFuncCall, // Call to known target, e.g. static call, closure call. |
2220 kReturn, // Return from function. | 2220 kReturn, // Return from function. |
2221 kOther | 2221 kOther |
2222 }; | 2222 }; |
2223 | 2223 |
2224 intptr_t Length() const; | 2224 intptr_t Length() const; |
2225 | 2225 |
2226 uword PC(intptr_t index) const; | 2226 uword PC(intptr_t index) const; |
2227 PcDescriptors::Kind DescriptorKind(intptr_t index) const; | 2227 PcDescriptors::Kind DescriptorKind(intptr_t index) const; |
2228 const char* KindAsStr(intptr_t index) const; | 2228 const char* KindAsStr(intptr_t index) const; |
2229 intptr_t NodeId(intptr_t index) const; | 2229 intptr_t DeoptId(intptr_t index) const; |
2230 intptr_t TokenIndex(intptr_t index) const; | 2230 intptr_t TokenPos(intptr_t index) const; |
2231 intptr_t TryIndex(intptr_t index) const; | 2231 intptr_t TryIndex(intptr_t index) const; |
2232 // Index into the deopt-info array of Code object. | 2232 // Index into the deopt-info array of Code object. |
2233 intptr_t DeoptIndex(intptr_t index) const; | 2233 intptr_t DeoptIndex(intptr_t index) const; |
2234 | 2234 |
2235 void AddDescriptor(intptr_t index, | 2235 void AddDescriptor(intptr_t index, |
2236 uword pc, | 2236 uword pc, |
2237 PcDescriptors::Kind kind, | 2237 PcDescriptors::Kind kind, |
2238 intptr_t node_id, | 2238 intptr_t deopt_id, |
2239 intptr_t token_pos, | 2239 intptr_t token_pos, |
2240 intptr_t try_index) const { | 2240 intptr_t try_index) const { |
2241 SetPC(index, pc); | 2241 SetPC(index, pc); |
2242 SetKind(index, kind); | 2242 SetKind(index, kind); |
2243 SetNodeId(index, node_id); | 2243 SetDeoptId(index, deopt_id); |
2244 SetTokenIndex(index, token_pos); | 2244 SetTokenPos(index, token_pos); |
2245 SetTryIndex(index, try_index); | 2245 SetTryIndex(index, try_index); |
2246 } | 2246 } |
2247 | 2247 |
2248 static const intptr_t kBytesPerElement = (kNumberOfEntries * kWordSize); | 2248 static const intptr_t kBytesPerElement = (kNumberOfEntries * kWordSize); |
2249 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; | 2249 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
2250 | 2250 |
2251 static intptr_t InstanceSize() { | 2251 static intptr_t InstanceSize() { |
2252 ASSERT(sizeof(RawPcDescriptors) == OFFSET_OF(RawPcDescriptors, data_)); | 2252 ASSERT(sizeof(RawPcDescriptors) == OFFSET_OF(RawPcDescriptors, data_)); |
2253 return 0; | 2253 return 0; |
2254 } | 2254 } |
2255 static intptr_t InstanceSize(intptr_t len) { | 2255 static intptr_t InstanceSize(intptr_t len) { |
2256 ASSERT(0 <= len && len <= kMaxElements); | 2256 ASSERT(0 <= len && len <= kMaxElements); |
2257 return RoundedAllocationSize( | 2257 return RoundedAllocationSize( |
2258 sizeof(RawPcDescriptors) + (len * kBytesPerElement)); | 2258 sizeof(RawPcDescriptors) + (len * kBytesPerElement)); |
2259 } | 2259 } |
2260 | 2260 |
2261 static RawPcDescriptors* New(intptr_t num_descriptors); | 2261 static RawPcDescriptors* New(intptr_t num_descriptors); |
2262 | 2262 |
2263 // Verify (assert) assumptions about pc descriptors in debug mode. | 2263 // Verify (assert) assumptions about pc descriptors in debug mode. |
2264 void Verify(bool check_ids) const; | 2264 void Verify(bool check_ids) const; |
2265 | 2265 |
2266 // We would have a VisitPointers function here to traverse the | 2266 // We would have a VisitPointers function here to traverse the |
2267 // pc descriptors table to visit objects if any in the table. | 2267 // pc descriptors table to visit objects if any in the table. |
2268 | 2268 |
2269 private: | 2269 private: |
2270 void SetPC(intptr_t index, uword value) const; | 2270 void SetPC(intptr_t index, uword value) const; |
2271 void SetKind(intptr_t index, PcDescriptors::Kind kind) const; | 2271 void SetKind(intptr_t index, PcDescriptors::Kind kind) const; |
2272 void SetNodeId(intptr_t index, intptr_t value) const; | 2272 void SetDeoptId(intptr_t index, intptr_t value) const; |
2273 void SetTokenIndex(intptr_t index, intptr_t value) const; | 2273 void SetTokenPos(intptr_t index, intptr_t value) const; |
2274 void SetTryIndex(intptr_t index, intptr_t value) const; | 2274 void SetTryIndex(intptr_t index, intptr_t value) const; |
2275 | 2275 |
2276 void SetLength(intptr_t value) const; | 2276 void SetLength(intptr_t value) const; |
2277 | 2277 |
2278 intptr_t* EntryAddr(intptr_t index, intptr_t entry_offset) const { | 2278 intptr_t* EntryAddr(intptr_t index, intptr_t entry_offset) const { |
2279 ASSERT((index >=0) && (index < Length())); | 2279 ASSERT((index >=0) && (index < Length())); |
2280 intptr_t data_index = (index * kNumberOfEntries) + entry_offset; | 2280 intptr_t data_index = (index * kNumberOfEntries) + entry_offset; |
2281 return &raw_ptr()->data_[data_index]; | 2281 return &raw_ptr()->data_[data_index]; |
2282 } | 2282 } |
2283 RawSmi** SmiAddr(intptr_t index, intptr_t entry_offset) const { | 2283 RawSmi** SmiAddr(intptr_t index, intptr_t entry_offset) const { |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2583 static RawCode* LookupCode(uword pc); | 2583 static RawCode* LookupCode(uword pc); |
2584 | 2584 |
2585 int32_t GetPointerOffsetAt(int index) const { | 2585 int32_t GetPointerOffsetAt(int index) const { |
2586 return *PointerOffsetAddrAt(index); | 2586 return *PointerOffsetAddrAt(index); |
2587 } | 2587 } |
2588 intptr_t GetTokenIndexOfPC(uword pc) const; | 2588 intptr_t GetTokenIndexOfPC(uword pc) const; |
2589 | 2589 |
2590 // Find pc of patch code buffer. Return 0 if not found. | 2590 // Find pc of patch code buffer. Return 0 if not found. |
2591 uword GetPatchCodePc() const; | 2591 uword GetPatchCodePc() const; |
2592 | 2592 |
2593 uword GetDeoptPcAtNodeId(intptr_t node_id) const; | 2593 uword GetDeoptPcAtDeoptId(intptr_t deopt_id) const; |
2594 uword GetTypeTestAtNodeId(intptr_t node_id) const; | |
2595 | 2594 |
2596 // Returns true if there is an object in the code between 'start_offset' | 2595 // Returns true if there is an object in the code between 'start_offset' |
2597 // (inclusive) and 'end_offset' (exclusive). | 2596 // (inclusive) and 'end_offset' (exclusive). |
2598 bool ObjectExistsInArea(intptr_t start_offest, intptr_t end_offset) const; | 2597 bool ObjectExistsInArea(intptr_t start_offest, intptr_t end_offset) const; |
2599 | 2598 |
2600 // Each (*node_ids)[n] has a an extracted ic data array (*arrays)[n]. | 2599 // Each (*node_ids)[n] has a an extracted ic data array (*arrays)[n]. |
2601 // Returns the maximum id found. | 2600 // Returns the maximum id found. |
2602 intptr_t ExtractIcDataArraysAtCalls( | 2601 intptr_t ExtractIcDataArraysAtCalls( |
2603 GrowableArray<intptr_t>* node_ids, | 2602 GrowableArray<intptr_t>* node_ids, |
2604 const GrowableObjectArray& ic_data_objs) const; | 2603 const GrowableObjectArray& ic_data_objs) const; |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2786 } | 2785 } |
2787 | 2786 |
2788 RawString* target_name() const { | 2787 RawString* target_name() const { |
2789 return raw_ptr()->target_name_; | 2788 return raw_ptr()->target_name_; |
2790 } | 2789 } |
2791 | 2790 |
2792 intptr_t num_args_tested() const { | 2791 intptr_t num_args_tested() const { |
2793 return raw_ptr()->num_args_tested_; | 2792 return raw_ptr()->num_args_tested_; |
2794 } | 2793 } |
2795 | 2794 |
2796 intptr_t id() const { | 2795 intptr_t deopt_id() const { |
2797 return raw_ptr()->id_; | 2796 return raw_ptr()->deopt_id_; |
2798 } | 2797 } |
2799 | 2798 |
2800 intptr_t NumberOfChecks() const; | 2799 intptr_t NumberOfChecks() const; |
2801 | 2800 |
2802 static intptr_t InstanceSize() { | 2801 static intptr_t InstanceSize() { |
2803 return RoundedAllocationSize(sizeof(RawICData)); | 2802 return RoundedAllocationSize(sizeof(RawICData)); |
2804 } | 2803 } |
2805 | 2804 |
2806 static intptr_t target_name_offset() { | 2805 static intptr_t target_name_offset() { |
2807 return OFFSET_OF(RawICData, target_name_); | 2806 return OFFSET_OF(RawICData, target_name_); |
(...skipping 28 matching lines...) Expand all Loading... |
2836 intptr_t GetReceiverClassIdAt(intptr_t index) const; | 2835 intptr_t GetReceiverClassIdAt(intptr_t index) const; |
2837 RawFunction* GetTargetAt(intptr_t index) const; | 2836 RawFunction* GetTargetAt(intptr_t index) const; |
2838 RawFunction* GetTargetForReceiverClassId(intptr_t class_id) const; | 2837 RawFunction* GetTargetForReceiverClassId(intptr_t class_id) const; |
2839 | 2838 |
2840 // Returns this->raw() if num_args_tested == 1, otherwise returns a new | 2839 // Returns this->raw() if num_args_tested == 1, otherwise returns a new |
2841 // ICData object containing only unique arg0 checks. | 2840 // ICData object containing only unique arg0 checks. |
2842 RawICData* AsUnaryClassChecks() const; | 2841 RawICData* AsUnaryClassChecks() const; |
2843 | 2842 |
2844 static RawICData* New(const Function& caller_function, | 2843 static RawICData* New(const Function& caller_function, |
2845 const String& target_name, | 2844 const String& target_name, |
2846 intptr_t id, | 2845 intptr_t deopt_id, |
2847 intptr_t num_args_tested); | 2846 intptr_t num_args_tested); |
2848 | 2847 |
2849 private: | 2848 private: |
2850 RawArray* ic_data() const { | 2849 RawArray* ic_data() const { |
2851 return raw_ptr()->ic_data_; | 2850 return raw_ptr()->ic_data_; |
2852 } | 2851 } |
2853 | 2852 |
2854 void set_function(const Function& value) const; | 2853 void set_function(const Function& value) const; |
2855 void set_target_name(const String& value) const; | 2854 void set_target_name(const String& value) const; |
2856 void set_id(intptr_t value) const; | 2855 void set_deopt_id(intptr_t value) const; |
2857 void set_num_args_tested(intptr_t value) const; | 2856 void set_num_args_tested(intptr_t value) const; |
2858 void set_ic_data(const Array& value) const; | 2857 void set_ic_data(const Array& value) const; |
2859 | 2858 |
2860 intptr_t TestEntryLength() const; | 2859 intptr_t TestEntryLength() const; |
2861 void WriteSentinel() const; | 2860 void WriteSentinel() const; |
2862 | 2861 |
2863 HEAP_OBJECT_IMPLEMENTATION(ICData, Object); | 2862 HEAP_OBJECT_IMPLEMENTATION(ICData, Object); |
2864 friend class Class; | 2863 friend class Class; |
2865 }; | 2864 }; |
2866 | 2865 |
(...skipping 2582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5449 if (this->CharAt(i) != str.CharAt(begin_index + i)) { | 5448 if (this->CharAt(i) != str.CharAt(begin_index + i)) { |
5450 return false; | 5449 return false; |
5451 } | 5450 } |
5452 } | 5451 } |
5453 return true; | 5452 return true; |
5454 } | 5453 } |
5455 | 5454 |
5456 } // namespace dart | 5455 } // namespace dart |
5457 | 5456 |
5458 #endif // VM_OBJECT_H_ | 5457 #endif // VM_OBJECT_H_ |
OLD | NEW |