Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: runtime/vm/object.h

Issue 11364134: Merge libv1. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Reupload due to error Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/message_handler.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 return raw()->ptr(); \ 143 return raw()->ptr(); \
144 } \ 144 } \
145 SNAPSHOT_READER_SUPPORT(object) \ 145 SNAPSHOT_READER_SUPPORT(object) \
146 friend class StackFrame; \ 146 friend class StackFrame; \
147 147
148 class Object { 148 class Object {
149 public: 149 public:
150 virtual ~Object() { } 150 virtual ~Object() { }
151 151
152 RawObject* raw() const { return raw_; } 152 RawObject* raw() const { return raw_; }
153 void operator=(RawObject* value) { SetRaw(value); } 153 void operator=(RawObject* value) {
154 initializeHandle(this, value);
155 }
154 156
155 void set_tags(intptr_t value) const { 157 void set_tags(intptr_t value) const {
156 // TODO(asiva): Remove the capability of setting tags in general. The mask 158 // TODO(asiva): Remove the capability of setting tags in general. The mask
157 // here only allows for canonical and from_snapshot flags to be set. 159 // here only allows for canonical and from_snapshot flags to be set.
158 ASSERT(!IsNull()); 160 ASSERT(!IsNull());
159 uword tags = raw()->ptr()->tags_ & ~0x0000000c; 161 uword tags = raw()->ptr()->tags_ & ~0x0000000c;
160 raw()->ptr()->tags_ = tags | (value & 0x0000000c); 162 raw()->ptr()->tags_ = tags | (value & 0x0000000c);
161 } 163 }
162 void SetCreatedFromSnapshot() const { 164 void SetCreatedFromSnapshot() const {
163 ASSERT(!IsNull()); 165 ASSERT(!IsNull());
164 raw()->SetCreatedFromSnapshot(); 166 raw()->SetCreatedFromSnapshot();
165 } 167 }
166 bool IsCanonical() const { 168 bool IsCanonical() const {
167 ASSERT(!IsNull()); 169 ASSERT(!IsNull());
168 return raw()->IsCanonical(); 170 return raw()->IsCanonical();
169 } 171 }
170 void SetCanonical() const { 172 void SetCanonical() const {
171 ASSERT(!IsNull()); 173 ASSERT(!IsNull());
172 raw()->SetCanonical(); 174 raw()->SetCanonical();
173 } 175 }
174 176
175 inline RawClass* clazz() const; 177 inline RawClass* clazz() const;
176 static intptr_t tags_offset() { return OFFSET_OF(RawObject, tags_); } 178 static intptr_t tags_offset() { return OFFSET_OF(RawObject, tags_); }
177 179
178 // Class testers. 180 // Class testers.
179 #define DEFINE_CLASS_TESTER(clazz) \ 181 #define DEFINE_CLASS_TESTER(clazz) \
180 virtual bool Is##clazz() const { return false; } 182 virtual bool Is##clazz() const { return false; }
181 CLASS_LIST_NO_OBJECT(DEFINE_CLASS_TESTER); 183 CLASS_LIST_FOR_HANDLES(DEFINE_CLASS_TESTER);
182 #undef DEFINE_CLASS_TESTER 184 #undef DEFINE_CLASS_TESTER
183 185
184 bool IsNull() const { return raw_ == null_; } 186 bool IsNull() const { return raw_ == null_; }
185 187
186 virtual const char* ToCString() const { 188 virtual const char* ToCString() const {
187 if (IsNull()) { 189 if (IsNull()) {
188 return "null"; 190 return "null";
189 } else { 191 } else {
190 return "Object"; 192 return "Object";
191 } 193 }
(...skipping 13 matching lines...) Expand all
205 void Print() const; 207 void Print() const;
206 208
207 bool IsZoneHandle() const { 209 bool IsZoneHandle() const {
208 return VMHandles::IsZoneHandle(reinterpret_cast<uword>(this)); 210 return VMHandles::IsZoneHandle(reinterpret_cast<uword>(this));
209 } 211 }
210 212
211 static RawObject* Clone(const Object& src, Heap::Space space = Heap::kNew); 213 static RawObject* Clone(const Object& src, Heap::Space space = Heap::kNew);
212 214
213 static Object& Handle(Isolate* isolate, RawObject* raw_ptr) { 215 static Object& Handle(Isolate* isolate, RawObject* raw_ptr) {
214 Object* obj = reinterpret_cast<Object*>(VMHandles::AllocateHandle(isolate)); 216 Object* obj = reinterpret_cast<Object*>(VMHandles::AllocateHandle(isolate));
215 obj->SetRaw(raw_ptr); 217 initializeHandle(obj, raw_ptr);
216 return *obj; 218 return *obj;
217 } 219 }
218 220
219 static Object& Handle() { 221 static Object& Handle() {
220 return Handle(Isolate::Current(), null_); 222 return Handle(Isolate::Current(), null_);
221 } 223 }
222 224
223 static Object& Handle(Isolate* isolate) { 225 static Object& Handle(Isolate* isolate) {
224 return Handle(isolate, null_); 226 return Handle(isolate, null_);
225 } 227 }
226 228
227 static Object& Handle(RawObject* raw_ptr) { 229 static Object& Handle(RawObject* raw_ptr) {
228 return Handle(Isolate::Current(), raw_ptr); 230 return Handle(Isolate::Current(), raw_ptr);
229 } 231 }
230 232
231 static Object& ZoneHandle(Isolate* isolate, RawObject* raw_ptr) { 233 static Object& ZoneHandle(Isolate* isolate, RawObject* raw_ptr) {
232 Object* obj = reinterpret_cast<Object*>( 234 Object* obj = reinterpret_cast<Object*>(
233 VMHandles::AllocateZoneHandle(isolate)); 235 VMHandles::AllocateZoneHandle(isolate));
234 obj->SetRaw(raw_ptr); 236 initializeHandle(obj, raw_ptr);
235 return *obj; 237 return *obj;
236 } 238 }
237 239
238 static Object& ZoneHandle() { 240 static Object& ZoneHandle() {
239 return ZoneHandle(Isolate::Current(), null_); 241 return ZoneHandle(Isolate::Current(), null_);
240 } 242 }
241 243
242 static Object& ZoneHandle(RawObject* raw_ptr) { 244 static Object& ZoneHandle(RawObject* raw_ptr) {
243 return ZoneHandle(Isolate::Current(), raw_ptr); 245 return ZoneHandle(Isolate::Current(), raw_ptr);
244 } 246 }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 static RawClass* CreateAndRegisterInterface(const char* cname, 366 static RawClass* CreateAndRegisterInterface(const char* cname,
365 const Script& script, 367 const Script& script,
366 const Library& lib); 368 const Library& lib);
367 static void RegisterClass(const Class& cls, 369 static void RegisterClass(const Class& cls,
368 const String& name, 370 const String& name,
369 const Library& lib); 371 const Library& lib);
370 static void RegisterPrivateClass(const Class& cls, 372 static void RegisterPrivateClass(const Class& cls,
371 const String& name, 373 const String& name,
372 const Library& lib); 374 const Library& lib);
373 375
376 /* Initialize the handle based on the raw_ptr in the presence of null. */
377 static void initializeHandle(Object* obj, RawObject* raw_ptr) {
378 if (raw_ptr != Object::null()) {
379 obj->SetRaw(raw_ptr);
380 } else {
381 obj->raw_ = Object::null();
382 Object fake_object;
383 obj->set_vtable(fake_object.vtable());
384 }
385 }
386
374 cpp_vtable* vtable_address() const { 387 cpp_vtable* vtable_address() const {
375 uword vtable_addr = reinterpret_cast<uword>(this); 388 uword vtable_addr = reinterpret_cast<uword>(this);
376 return reinterpret_cast<cpp_vtable*>(vtable_addr); 389 return reinterpret_cast<cpp_vtable*>(vtable_addr);
377 } 390 }
378 391
379 static cpp_vtable handle_vtable_; 392 static cpp_vtable handle_vtable_;
380 static cpp_vtable builtin_vtables_[kNumPredefinedCids]; 393 static cpp_vtable builtin_vtables_[kNumPredefinedCids];
381 394
382 // The static values below are singletons shared between the different 395 // The static values below are singletons shared between the different
383 // isolates. They are all allocated in the non-GC'd Dart::vm_isolate_. 396 // isolates. They are all allocated in the non-GC'd Dart::vm_isolate_.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 static RawClass* subtypetestcache_class_; // Class of SubtypeTestCache. 431 static RawClass* subtypetestcache_class_; // Class of SubtypeTestCache.
419 static RawClass* api_error_class_; // Class of ApiError. 432 static RawClass* api_error_class_; // Class of ApiError.
420 static RawClass* language_error_class_; // Class of LanguageError. 433 static RawClass* language_error_class_; // Class of LanguageError.
421 static RawClass* unhandled_exception_class_; // Class of UnhandledException. 434 static RawClass* unhandled_exception_class_; // Class of UnhandledException.
422 static RawClass* unwind_error_class_; // Class of UnwindError. 435 static RawClass* unwind_error_class_; // Class of UnwindError.
423 436
424 friend void ClassTable::Register(const Class& cls); 437 friend void ClassTable::Register(const Class& cls);
425 friend void RawObject::Validate(Isolate* isolate) const; 438 friend void RawObject::Validate(Isolate* isolate) const;
426 friend class Closure; 439 friend class Closure;
427 friend class SnapshotReader; 440 friend class SnapshotReader;
441 friend class OneByteString;
442 friend class TwoByteString;
443 friend class ExternalOneByteString;
444 friend class ExternalTwoByteString;
428 445
429 // Disallow allocation. 446 // Disallow allocation.
430 void* operator new(size_t size); 447 void* operator new(size_t size);
431 // Disallow copy constructor. 448 // Disallow copy constructor.
432 DISALLOW_COPY_AND_ASSIGN(Object); 449 DISALLOW_COPY_AND_ASSIGN(Object);
433 }; 450 };
434 451
435 452
436 class Class : public Object { 453 class Class : public Object {
437 public: 454 public:
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 static RawClass* New(const String& name, 725 static RawClass* New(const String& name,
709 const Script& script, 726 const Script& script,
710 intptr_t token_pos); 727 intptr_t token_pos);
711 static RawClass* NewInterface(const String& name, 728 static RawClass* NewInterface(const String& name,
712 const Script& script, 729 const Script& script,
713 intptr_t token_pos); 730 intptr_t token_pos);
714 static RawClass* NewNativeWrapper(const Library& library, 731 static RawClass* NewNativeWrapper(const Library& library,
715 const String& name, 732 const String& name,
716 int num_fields); 733 int num_fields);
717 734
735 // Allocate the raw string classes.
736 static RawClass* NewStringClass(intptr_t class_id);
737
718 // Allocate a class representing a function signature described by 738 // Allocate a class representing a function signature described by
719 // signature_function, which must be a closure function or a signature 739 // signature_function, which must be a closure function or a signature
720 // function. 740 // function.
721 // The class may be type parameterized unless the signature_function is in a 741 // The class may be type parameterized unless the signature_function is in a
722 // static scope. In that case, the type parameters are copied from the owner 742 // static scope. In that case, the type parameters are copied from the owner
723 // class of signature_function. 743 // class of signature_function.
724 static RawClass* NewSignatureClass(const String& name, 744 static RawClass* NewSignatureClass(const String& name,
725 const Function& signature_function, 745 const Function& signature_function,
726 const Script& script); 746 const Script& script);
727 747
(...skipping 1828 matching lines...) Expand 10 before | Expand all | Expand 10 after
2556 2576
2557 // Each (*node_ids)[n] has a an extracted ic data array (*arrays)[n]. 2577 // Each (*node_ids)[n] has a an extracted ic data array (*arrays)[n].
2558 // Returns the maximum id found. 2578 // Returns the maximum id found.
2559 intptr_t ExtractIcDataArraysAtCalls( 2579 intptr_t ExtractIcDataArraysAtCalls(
2560 GrowableArray<intptr_t>* node_ids, 2580 GrowableArray<intptr_t>* node_ids,
2561 const GrowableObjectArray& ic_data_objs) const; 2581 const GrowableObjectArray& ic_data_objs) const;
2562 2582
2563 // Returns an array indexed by deopt id, containing the extracted ICData. 2583 // Returns an array indexed by deopt id, containing the extracted ICData.
2564 RawArray* ExtractTypeFeedbackArray() const; 2584 RawArray* ExtractTypeFeedbackArray() const;
2565 2585
2586 // Returns deopt-ids of all static calls that were never resolved, i.e.,
2587 // never executed.
2588 void ExtractUncalledStaticCallDeoptIds(
2589 GrowableArray<intptr_t>* deopt_ids) const;
2590
2566 private: 2591 private:
2567 // An object finder visitor interface. 2592 // An object finder visitor interface.
2568 class FindRawCodeVisitor : public FindObjectVisitor { 2593 class FindRawCodeVisitor : public FindObjectVisitor {
2569 public: 2594 public:
2570 explicit FindRawCodeVisitor(uword pc) 2595 explicit FindRawCodeVisitor(uword pc)
2571 : FindObjectVisitor(Isolate::Current()), pc_(pc) { } 2596 : FindObjectVisitor(Isolate::Current()), pc_(pc) { }
2572 virtual ~FindRawCodeVisitor() { } 2597 virtual ~FindRawCodeVisitor() { }
2573 2598
2574 // Check if object matches find condition. 2599 // Check if object matches find condition.
2575 virtual bool FindObject(RawObject* obj); 2600 virtual bool FindObject(RawObject* obj);
(...skipping 1076 matching lines...) Expand 10 before | Expand all | Expand 10 after
3652 intptr_t Length() const { return Smi::Value(raw_ptr()->length_); } 3677 intptr_t Length() const { return Smi::Value(raw_ptr()->length_); }
3653 static intptr_t length_offset() { return OFFSET_OF(RawString, length_); } 3678 static intptr_t length_offset() { return OFFSET_OF(RawString, length_); }
3654 3679
3655 virtual intptr_t Hash() const; 3680 virtual intptr_t Hash() const;
3656 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); } 3681 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); }
3657 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len); 3682 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len);
3658 static intptr_t Hash(const uint8_t* characters, intptr_t len); 3683 static intptr_t Hash(const uint8_t* characters, intptr_t len);
3659 static intptr_t Hash(const uint16_t* characters, intptr_t len); 3684 static intptr_t Hash(const uint16_t* characters, intptr_t len);
3660 static intptr_t Hash(const uint32_t* characters, intptr_t len); 3685 static intptr_t Hash(const uint32_t* characters, intptr_t len);
3661 3686
3662 virtual int32_t CharAt(intptr_t index) const; 3687 int32_t CharAt(intptr_t index) const;
3663 3688
3664 virtual intptr_t CharSize() const; 3689 intptr_t CharSize() const;
3665 3690
3666 inline bool Equals(const String& str) const; 3691 inline bool Equals(const String& str) const;
3667 inline bool Equals(const String& str, 3692 inline bool Equals(const String& str,
3668 intptr_t begin_index, // begin index on 'str'. 3693 intptr_t begin_index, // begin index on 'str'.
3669 intptr_t len) const; // len on 'str'. 3694 intptr_t len) const; // len on 'str'.
3670 bool Equals(const char* str) const; 3695 bool Equals(const char* str) const;
3671 bool Equals(const uint8_t* characters, intptr_t len) const; 3696 bool Equals(const uint8_t* characters, intptr_t len) const;
3672 bool Equals(const uint16_t* characters, intptr_t len) const; 3697 bool Equals(const uint16_t* characters, intptr_t len) const;
3673 bool Equals(const uint32_t* characters, intptr_t len) const; 3698 bool Equals(const uint32_t* characters, intptr_t len) const;
3674 3699
3675 virtual bool Equals(const Instance& other) const; 3700 virtual bool Equals(const Instance& other) const;
3676 3701
3677 intptr_t CompareTo(const String& other) const; 3702 intptr_t CompareTo(const String& other) const;
3678 3703
3679 bool StartsWith(const String& other) const; 3704 bool StartsWith(const String& other) const;
3680 3705
3681 virtual RawInstance* Canonicalize() const; 3706 virtual RawInstance* Canonicalize() const;
3682 3707
3683 bool IsSymbol() const { return raw()->IsCanonical(); } 3708 bool IsSymbol() const { return raw()->IsCanonical(); }
3684 3709
3685 virtual bool IsExternal() const { return false; } 3710 bool IsOneByteString() const {
3686 virtual void* GetPeer() const { 3711 return raw()->GetClassId() == kOneByteStringCid;
3687 UNREACHABLE();
3688 return NULL;
3689 } 3712 }
3690 3713
3714 bool IsTwoByteString() const {
3715 return raw()->GetClassId() == kTwoByteStringCid;
3716 }
3717
3718 bool IsExternalOneByteString() const {
3719 return raw()->GetClassId() == kExternalOneByteStringCid;
3720 }
3721
3722 bool IsExternalTwoByteString() const {
3723 return raw()->GetClassId() == kExternalTwoByteStringCid;
3724 }
3725
3726 bool IsExternal() const {
3727 return RawObject::IsExternalStringClassId(raw()->GetClassId());
3728 }
3729
3730 void* GetPeer() const;
3731
3691 void ToUTF8(uint8_t* utf8_array, intptr_t array_len) const; 3732 void ToUTF8(uint8_t* utf8_array, intptr_t array_len) const;
3692 3733
3693 // Creates a new String object from a C string that is assumed to contain 3734 // Creates a new String object from a C string that is assumed to contain
3694 // UTF-8 encoded characters and '\0' is considered a termination character. 3735 // UTF-8 encoded characters and '\0' is considered a termination character.
3695 static RawString* New(const char* cstr, Heap::Space space = Heap::kNew); 3736 static RawString* New(const char* cstr, Heap::Space space = Heap::kNew);
3696 3737
3697 // Creates a new String object from an array of UTF-8 encoded characters. 3738 // Creates a new String object from an array of UTF-8 encoded characters.
3698 static RawString* New(const uint8_t* utf8_array, 3739 static RawString* New(const uint8_t* utf8_array,
3699 intptr_t array_len, 3740 intptr_t array_len,
3700 Heap::Space space = Heap::kNew); 3741 Heap::Space space = Heap::kNew);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
3784 } 3825 }
3785 3826
3786 void SetHash(intptr_t value) const { 3827 void SetHash(intptr_t value) const {
3787 // This is only safe because we create a new Smi, which does not cause 3828 // This is only safe because we create a new Smi, which does not cause
3788 // heap allocation. 3829 // heap allocation.
3789 raw_ptr()->hash_ = Smi::New(value); 3830 raw_ptr()->hash_ = Smi::New(value);
3790 } 3831 }
3791 3832
3792 template<typename HandleType, typename ElementType> 3833 template<typename HandleType, typename ElementType>
3793 static void ReadFromImpl(SnapshotReader* reader, 3834 static void ReadFromImpl(SnapshotReader* reader,
3794 HandleType* str_obj, 3835 String* str_obj,
3795 intptr_t len, 3836 intptr_t len,
3796 intptr_t tags, 3837 intptr_t tags,
3797 Snapshot::Kind kind); 3838 Snapshot::Kind kind);
3798 3839
3799 HEAP_OBJECT_IMPLEMENTATION(String, Instance); 3840 HEAP_OBJECT_IMPLEMENTATION(String, Instance);
3800 3841
3842 friend class Class;
3801 friend class Symbols; 3843 friend class Symbols;
3844 friend class OneByteString;
3845 friend class TwoByteString;
3846 friend class ExternalOneByteString;
3847 friend class ExternalTwoByteString;
3802 }; 3848 };
3803 3849
3804 3850
3805 class OneByteString : public String { 3851 class OneByteString : public AllStatic {
3806 public: 3852 public:
3807 virtual int32_t CharAt(intptr_t index) const { 3853 static int32_t CharAt(const String& str, intptr_t index) {
3808 return *CharAddr(index); 3854 return *CharAddr(str, index);
3809 } 3855 }
3810 3856
3811 virtual intptr_t CharSize() const { 3857 static RawOneByteString* EscapeSpecialCharacters(const String& str,
3812 return kOneByteChar; 3858 bool raw_str);
3813 }
3814 3859
3815 RawOneByteString* EscapeSpecialCharacters(bool raw_str) const; 3860 static bool EqualsIgnoringPrivateKey(const String& str1,
3816 3861 const String& str2);
3817 bool EqualsIgnoringPrivateKey(const OneByteString& str) const;
3818 3862
3819 // We use the same maximum elements for all strings. 3863 // We use the same maximum elements for all strings.
3820 static const intptr_t kBytesPerElement = 1; 3864 static const intptr_t kBytesPerElement = 1;
3821 static const intptr_t kMaxElements = String::kMaxElements; 3865 static const intptr_t kMaxElements = String::kMaxElements;
3822 3866
3823 static intptr_t data_offset() { return OFFSET_OF(RawOneByteString, data_); } 3867 static intptr_t data_offset() { return OFFSET_OF(RawOneByteString, data_); }
3824 3868
3825 static intptr_t InstanceSize() { 3869 static intptr_t InstanceSize() {
3826 ASSERT(sizeof(RawOneByteString) == OFFSET_OF(RawOneByteString, data_)); 3870 ASSERT(sizeof(RawOneByteString) == OFFSET_OF(RawOneByteString, data_));
3827 return 0; 3871 return 0;
3828 } 3872 }
3829 3873
3830 static intptr_t InstanceSize(intptr_t len) { 3874 static intptr_t InstanceSize(intptr_t len) {
3831 ASSERT(sizeof(RawOneByteString) == kSizeofRawString); 3875 ASSERT(sizeof(RawOneByteString) == String::kSizeofRawString);
3832 ASSERT(0 <= len && len <= kMaxElements); 3876 ASSERT(0 <= len && len <= kMaxElements);
3833 return RoundedAllocationSize( 3877 return String::RoundedAllocationSize(
3834 sizeof(RawOneByteString) + (len * kBytesPerElement)); 3878 sizeof(RawOneByteString) + (len * kBytesPerElement));
3835 } 3879 }
3836 3880
3837 static RawOneByteString* New(intptr_t len, 3881 static RawOneByteString* New(intptr_t len,
3838 Heap::Space space); 3882 Heap::Space space);
3839 static RawOneByteString* New(const char* c_string, 3883 static RawOneByteString* New(const char* c_string,
3840 Heap::Space space = Heap::kNew) { 3884 Heap::Space space = Heap::kNew) {
3841 return New(reinterpret_cast<const uint8_t*>(c_string), 3885 return New(reinterpret_cast<const uint8_t*>(c_string),
3842 strlen(c_string), 3886 strlen(c_string),
3843 space); 3887 space);
3844 } 3888 }
3845 static RawOneByteString* New(const uint8_t* characters, 3889 static RawOneByteString* New(const uint8_t* characters,
3846 intptr_t len, 3890 intptr_t len,
3847 Heap::Space space); 3891 Heap::Space space);
3848 static RawOneByteString* New(const uint16_t* characters, 3892 static RawOneByteString* New(const uint16_t* characters,
3849 intptr_t len, 3893 intptr_t len,
3850 Heap::Space space); 3894 Heap::Space space);
3851 static RawOneByteString* New(const uint32_t* characters, 3895 static RawOneByteString* New(const uint32_t* characters,
3852 intptr_t len, 3896 intptr_t len,
3853 Heap::Space space); 3897 Heap::Space space);
3854 static RawOneByteString* New(const OneByteString& str, 3898 static RawOneByteString* New(const String& str,
3855 Heap::Space space); 3899 Heap::Space space);
3856 3900
3857 static RawOneByteString* Concat(const String& str1, 3901 static RawOneByteString* Concat(const String& str1,
3858 const String& str2, 3902 const String& str2,
3859 Heap::Space space); 3903 Heap::Space space);
3860 static RawOneByteString* ConcatAll(const Array& strings, 3904 static RawOneByteString* ConcatAll(const Array& strings,
3861 intptr_t len, 3905 intptr_t len,
3862 Heap::Space space); 3906 Heap::Space space);
3863 3907
3864 static RawOneByteString* Transform(int32_t (*mapping)(int32_t ch), 3908 static RawOneByteString* Transform(int32_t (*mapping)(int32_t ch),
3865 const String& str, 3909 const String& str,
3866 Heap::Space space); 3910 Heap::Space space);
3867 3911
3868 private: 3912 static const ClassId kClassId = kOneByteStringCid;
3869 uint8_t* CharAddr(intptr_t index) const { 3913
3870 // TODO(iposva): Determine if we should throw an exception here. 3914 static RawOneByteString* null() {
3871 ASSERT((index >= 0) && (index < Length())); 3915 return reinterpret_cast<RawOneByteString*>(Object::null());
3872 return &raw_ptr()->data_[index];
3873 } 3916 }
3874 3917
3875 HEAP_OBJECT_IMPLEMENTATION(OneByteString, String); 3918 private:
3919 static RawOneByteString* raw(const String& str) {
3920 return reinterpret_cast<RawOneByteString*>(str.raw());
3921 }
3922
3923 static RawOneByteString* raw_ptr(const String& str) {
3924 return reinterpret_cast<RawOneByteString*>(str.raw_ptr());
3925 }
3926
3927 static uint8_t* CharAddr(const String& str, intptr_t index) {
3928 ASSERT((index >= 0) && (index < str.Length()));
3929 ASSERT(str.IsOneByteString());
3930 NoGCScope no_gc;
3931 return &raw_ptr(str)->data_[index];
3932 }
3933
3934 static RawOneByteString* ReadFrom(SnapshotReader* reader,
3935 intptr_t object_id,
3936 intptr_t tags,
3937 Snapshot::Kind kind);
3938
3876 friend class Class; 3939 friend class Class;
3877 friend class String; 3940 friend class String;
3941 friend class SnapshotReader;
3878 }; 3942 };
3879 3943
3880 3944
3881 class TwoByteString : public String { 3945 class TwoByteString : public AllStatic {
3882 public: 3946 public:
3883 virtual int32_t CharAt(intptr_t index) const { 3947 static int32_t CharAt(const String& str, intptr_t index) {
3884 return *CharAddr(index); 3948 return *CharAddr(str, index);
3885 } 3949 }
3886 3950
3887 virtual intptr_t CharSize() const { 3951 static RawTwoByteString* EscapeSpecialCharacters(const String& str,
3888 return kTwoByteChar; 3952 bool raw_str);
3889 }
3890
3891 RawTwoByteString* EscapeSpecialCharacters(bool raw_str) const;
3892 3953
3893 // We use the same maximum elements for all strings. 3954 // We use the same maximum elements for all strings.
3894 static const intptr_t kBytesPerElement = 2; 3955 static const intptr_t kBytesPerElement = 2;
3895 static const intptr_t kMaxElements = String::kMaxElements; 3956 static const intptr_t kMaxElements = String::kMaxElements;
3896 3957
3897 static intptr_t data_offset() { return OFFSET_OF(RawTwoByteString, data_); } 3958 static intptr_t data_offset() { return OFFSET_OF(RawTwoByteString, data_); }
3898 3959
3899 static intptr_t InstanceSize() { 3960 static intptr_t InstanceSize() {
3900 ASSERT(sizeof(RawTwoByteString) == OFFSET_OF(RawTwoByteString, data_)); 3961 ASSERT(sizeof(RawTwoByteString) == OFFSET_OF(RawTwoByteString, data_));
3901 return 0; 3962 return 0;
3902 } 3963 }
3903 3964
3904 static intptr_t InstanceSize(intptr_t len) { 3965 static intptr_t InstanceSize(intptr_t len) {
3905 ASSERT(sizeof(RawTwoByteString) == kSizeofRawString); 3966 ASSERT(sizeof(RawTwoByteString) == String::kSizeofRawString);
3906 ASSERT(0 <= len && len <= kMaxElements); 3967 ASSERT(0 <= len && len <= kMaxElements);
3907 return RoundedAllocationSize( 3968 return String::RoundedAllocationSize(
3908 sizeof(RawTwoByteString) + (len * kBytesPerElement)); 3969 sizeof(RawTwoByteString) + (len * kBytesPerElement));
3909 } 3970 }
3910 3971
3911 static RawTwoByteString* New(intptr_t len, 3972 static RawTwoByteString* New(intptr_t len,
3912 Heap::Space space); 3973 Heap::Space space);
3913 static RawTwoByteString* New(const uint16_t* characters, 3974 static RawTwoByteString* New(const uint16_t* characters,
3914 intptr_t len, 3975 intptr_t len,
3915 Heap::Space space); 3976 Heap::Space space);
3916 static RawTwoByteString* New(intptr_t utf16_len, 3977 static RawTwoByteString* New(intptr_t utf16_len,
3917 const uint32_t* characters, 3978 const uint32_t* characters,
3918 intptr_t len, 3979 intptr_t len,
3919 Heap::Space space); 3980 Heap::Space space);
3920 static RawTwoByteString* New(const TwoByteString& str, 3981 static RawTwoByteString* New(const String& str,
3921 Heap::Space space); 3982 Heap::Space space);
3922 3983
3923 static RawTwoByteString* Concat(const String& str1, 3984 static RawTwoByteString* Concat(const String& str1,
3924 const String& str2, 3985 const String& str2,
3925 Heap::Space space); 3986 Heap::Space space);
3926 static RawTwoByteString* ConcatAll(const Array& strings, 3987 static RawTwoByteString* ConcatAll(const Array& strings,
3927 intptr_t len, 3988 intptr_t len,
3928 Heap::Space space); 3989 Heap::Space space);
3929 3990
3930 static RawTwoByteString* Transform(int32_t (*mapping)(int32_t ch), 3991 static RawTwoByteString* Transform(int32_t (*mapping)(int32_t ch),
3931 const String& str, 3992 const String& str,
3932 Heap::Space space); 3993 Heap::Space space);
3933 3994
3934 private: 3995 static RawTwoByteString* null() {
3935 uint16_t* CharAddr(intptr_t index) const { 3996 return reinterpret_cast<RawTwoByteString*>(Object::null());
3936 ASSERT((index >= 0) && (index < Length()));
3937 return &raw_ptr()->data_[index];
3938 } 3997 }
3939 3998
3940 HEAP_OBJECT_IMPLEMENTATION(TwoByteString, String); 3999
4000 static const ClassId kClassId = kTwoByteStringCid;
4001
4002 private:
4003 static RawTwoByteString* raw(const String& str) {
4004 return reinterpret_cast<RawTwoByteString*>(str.raw());
4005 }
4006
4007 static RawTwoByteString* raw_ptr(const String& str) {
4008 return reinterpret_cast<RawTwoByteString*>(str.raw_ptr());
4009 }
4010
4011 static uint16_t* CharAddr(const String& str, intptr_t index) {
4012 ASSERT((index >= 0) && (index < str.Length()));
4013 ASSERT(str.IsTwoByteString());
4014 NoGCScope no_gc;
4015 return &raw_ptr(str)->data_[index];
4016 }
4017
4018 static RawTwoByteString* ReadFrom(SnapshotReader* reader,
4019 intptr_t object_id,
4020 intptr_t tags,
4021 Snapshot::Kind kind);
4022
3941 friend class Class; 4023 friend class Class;
3942 friend class String; 4024 friend class String;
4025 friend class SnapshotReader;
3943 }; 4026 };
3944 4027
3945 4028
3946 class ExternalOneByteString : public String { 4029 class ExternalOneByteString : public AllStatic {
3947 public: 4030 public:
3948 virtual int32_t CharAt(intptr_t index) const { 4031 static int32_t CharAt(const String& str, intptr_t index) {
3949 return *CharAddr(index); 4032 return *CharAddr(str, index);
3950 } 4033 }
3951 4034
3952 virtual intptr_t CharSize() const { 4035 static void* GetPeer(const String& str) {
3953 return kOneByteChar; 4036 return raw_ptr(str)->external_data_->peer();
3954 }
3955
3956 virtual bool IsExternal() const { return true; }
3957 virtual void* GetPeer() const {
3958 return raw_ptr()->external_data_->peer();
3959 } 4037 }
3960 4038
3961 // We use the same maximum elements for all strings. 4039 // We use the same maximum elements for all strings.
3962 static const intptr_t kBytesPerElement = 1; 4040 static const intptr_t kBytesPerElement = 1;
3963 static const intptr_t kMaxElements = String::kMaxElements; 4041 static const intptr_t kMaxElements = String::kMaxElements;
3964 4042
3965 static intptr_t InstanceSize() { 4043 static intptr_t InstanceSize() {
3966 return RoundedAllocationSize(sizeof(RawExternalOneByteString)); 4044 return String::RoundedAllocationSize(sizeof(RawExternalOneByteString));
3967 } 4045 }
3968 4046
3969 static RawExternalOneByteString* New(const uint8_t* characters, 4047 static RawExternalOneByteString* New(const uint8_t* characters,
3970 intptr_t len, 4048 intptr_t len,
3971 void* peer, 4049 void* peer,
3972 Dart_PeerFinalizer callback, 4050 Dart_PeerFinalizer callback,
3973 Heap::Space space); 4051 Heap::Space space);
3974 4052
3975 private: 4053 static RawExternalOneByteString* null() {
3976 const uint8_t* CharAddr(intptr_t index) const { 4054 return reinterpret_cast<RawExternalOneByteString*>(Object::null());
3977 // TODO(iposva): Determine if we should throw an exception here.
3978 ASSERT((index >= 0) && (index < Length()));
3979 return &(raw_ptr()->external_data_->data()[index]);
3980 } 4055 }
3981 4056
3982 void SetExternalData(ExternalStringData<uint8_t>* data) { 4057 static const ClassId kClassId = kExternalOneByteStringCid;
3983 raw_ptr()->external_data_ = data; 4058
4059 private:
4060 static RawExternalOneByteString* raw(const String& str) {
4061 return reinterpret_cast<RawExternalOneByteString*>(str.raw());
4062 }
4063
4064 static RawExternalOneByteString* raw_ptr(const String& str) {
4065 return reinterpret_cast<RawExternalOneByteString*>(str.raw_ptr());
4066 }
4067
4068 static const uint8_t* CharAddr(const String& str, intptr_t index) {
4069 ASSERT((index >= 0) && (index < str.Length()));
4070 ASSERT(str.IsExternalOneByteString());
4071 NoGCScope no_gc;
4072 return &(raw_ptr(str)->external_data_->data()[index]);
4073 }
4074
4075 static void SetExternalData(const String& str,
4076 ExternalStringData<uint8_t>* data) {
4077 ASSERT(str.IsExternalOneByteString());
4078 NoGCScope no_gc;
4079 raw_ptr(str)->external_data_ = data;
3984 } 4080 }
3985 4081
3986 static void Finalize(Dart_Handle handle, void* peer); 4082 static void Finalize(Dart_Handle handle, void* peer);
3987 4083
3988 HEAP_OBJECT_IMPLEMENTATION(ExternalOneByteString, String); 4084 static RawExternalOneByteString* ReadFrom(SnapshotReader* reader,
4085 intptr_t object_id,
4086 intptr_t tags,
4087 Snapshot::Kind kind);
4088
3989 friend class Class; 4089 friend class Class;
3990 friend class String; 4090 friend class String;
4091 friend class SnapshotReader;
3991 }; 4092 };
3992 4093
3993 4094
3994 class ExternalTwoByteString : public String { 4095 class ExternalTwoByteString : public AllStatic {
3995 public: 4096 public:
3996 virtual int32_t CharAt(intptr_t index) const { 4097 static int32_t CharAt(const String& str, intptr_t index) {
3997 return *CharAddr(index); 4098 return *CharAddr(str, index);
3998 } 4099 }
3999 4100
4000 virtual intptr_t CharSize() const { 4101 static void* GetPeer(const String& str) {
4001 return kTwoByteChar; 4102 return raw_ptr(str)->external_data_->peer();
4002 }
4003
4004 virtual bool IsExternal() const { return true; }
4005 virtual void* GetPeer() const {
4006 return raw_ptr()->external_data_->peer();
4007 } 4103 }
4008 4104
4009 // We use the same maximum elements for all strings. 4105 // We use the same maximum elements for all strings.
4010 static const intptr_t kBytesPerElement = 2; 4106 static const intptr_t kBytesPerElement = 2;
4011 static const intptr_t kMaxElements = String::kMaxElements; 4107 static const intptr_t kMaxElements = String::kMaxElements;
4012 4108
4013 static intptr_t InstanceSize() { 4109 static intptr_t InstanceSize() {
4014 return RoundedAllocationSize(sizeof(RawExternalTwoByteString)); 4110 return String::RoundedAllocationSize(sizeof(RawExternalTwoByteString));
4015 } 4111 }
4016 4112
4017 static RawExternalTwoByteString* New(const uint16_t* characters, 4113 static RawExternalTwoByteString* New(const uint16_t* characters,
4018 intptr_t len, 4114 intptr_t len,
4019 void* peer, 4115 void* peer,
4020 Dart_PeerFinalizer callback, 4116 Dart_PeerFinalizer callback,
4021 Heap::Space space = Heap::kNew); 4117 Heap::Space space = Heap::kNew);
4022 4118
4023 private: 4119 static RawExternalTwoByteString* null() {
4024 const uint16_t* CharAddr(intptr_t index) const { 4120 return reinterpret_cast<RawExternalTwoByteString*>(Object::null());
4025 // TODO(iposva): Determine if we should throw an exception here.
4026 ASSERT((index >= 0) && (index < Length()));
4027 return &(raw_ptr()->external_data_->data()[index]);
4028 } 4121 }
4029 4122
4030 void SetExternalData(ExternalStringData<uint16_t>* data) { 4123 static const ClassId kClassId = kExternalTwoByteStringCid;
4031 raw_ptr()->external_data_ = data; 4124
4125 private:
4126 static RawExternalTwoByteString* raw(const String& str) {
4127 return reinterpret_cast<RawExternalTwoByteString*>(str.raw());
4128 }
4129
4130 static RawExternalTwoByteString* raw_ptr(const String& str) {
4131 return reinterpret_cast<RawExternalTwoByteString*>(str.raw_ptr());
4132 }
4133
4134 static const uint16_t* CharAddr(const String& str, intptr_t index) {
4135 ASSERT((index >= 0) && (index < str.Length()));
4136 ASSERT(str.IsExternalTwoByteString());
4137 NoGCScope no_gc;
4138 return &(raw_ptr(str)->external_data_->data()[index]);
4139 }
4140
4141 static void SetExternalData(const String& str,
4142 ExternalStringData<uint16_t>* data) {
4143 ASSERT(str.IsExternalTwoByteString());
4144 NoGCScope no_gc;
4145 raw_ptr(str)->external_data_ = data;
4032 } 4146 }
4033 4147
4034 static void Finalize(Dart_Handle handle, void* peer); 4148 static void Finalize(Dart_Handle handle, void* peer);
4035 4149
4036 HEAP_OBJECT_IMPLEMENTATION(ExternalTwoByteString, String); 4150 static RawExternalTwoByteString* ReadFrom(SnapshotReader* reader,
4151 intptr_t object_id,
4152 intptr_t tags,
4153 Snapshot::Kind kind);
4154
4037 friend class Class; 4155 friend class Class;
4038 friend class String; 4156 friend class String;
4157 friend class SnapshotReader;
4039 }; 4158 };
4040 4159
4041 4160
4042 // Class Bool implements Dart core class bool. 4161 // Class Bool implements Dart core class bool.
4043 class Bool : public Instance { 4162 class Bool : public Instance {
4044 public: 4163 public:
4045 bool value() const { 4164 bool value() const {
4046 return raw_ptr()->value_; 4165 return raw_ptr()->value_;
4047 } 4166 }
4048 4167
(...skipping 1619 matching lines...) Expand 10 before | Expand all | Expand 10 after
5668 5787
5669 5788
5670 void Object::SetRaw(RawObject* value) { 5789 void Object::SetRaw(RawObject* value) {
5671 // NOTE: The assignment "raw_ = value" should be the first statement in 5790 // NOTE: The assignment "raw_ = value" should be the first statement in
5672 // this function. Also do not use 'value' in this function after the 5791 // this function. Also do not use 'value' in this function after the
5673 // assignment (use 'raw_' instead). 5792 // assignment (use 'raw_' instead).
5674 raw_ = value; 5793 raw_ = value;
5675 if ((reinterpret_cast<uword>(raw_) & kSmiTagMask) == kSmiTag) { 5794 if ((reinterpret_cast<uword>(raw_) & kSmiTagMask) == kSmiTag) {
5676 set_vtable(Smi::handle_vtable_); 5795 set_vtable(Smi::handle_vtable_);
5677 return; 5796 return;
5678 } else if (raw_ == null_) {
5679 set_vtable(handle_vtable_);
5680 return;
5681 } 5797 }
5682 5798 intptr_t cid = raw_->GetClassId();
5799 if (cid >= kNumPredefinedCids) {
5800 cid = kInstanceCid;
5801 }
5802 set_vtable(builtin_vtables_[cid]);
5683 #if defined(DEBUG) 5803 #if defined(DEBUG)
5684 Isolate* isolate = Isolate::Current(); 5804 Isolate* isolate = Isolate::Current();
5685 if (FLAG_verify_handles) { 5805 if (FLAG_verify_handles) {
5686 Heap* isolate_heap = isolate->heap(); 5806 Heap* isolate_heap = isolate->heap();
5687 Heap* vm_isolate_heap = Dart::vm_isolate()->heap(); 5807 Heap* vm_isolate_heap = Dart::vm_isolate()->heap();
5688 ASSERT(isolate_heap->Contains(reinterpret_cast<uword>(raw_->ptr())) || 5808 ASSERT(isolate_heap->Contains(reinterpret_cast<uword>(raw_->ptr())) ||
5689 vm_isolate_heap->Contains(reinterpret_cast<uword>(raw_->ptr()))); 5809 vm_isolate_heap->Contains(reinterpret_cast<uword>(raw_->ptr())));
5690 } 5810 }
5811 ASSERT(builtin_vtables_[cid] ==
5812 isolate->class_table()->At(cid)->ptr()->handle_vtable_);
5691 #endif 5813 #endif
5692 intptr_t cid = raw_->GetClassId();
5693 if (cid < kNumPredefinedCids) {
5694 #if defined(DEBUG)
5695 ASSERT(builtin_vtables_[cid] ==
5696 isolate->class_table()->At(cid)->ptr()->handle_vtable_);
5697 #endif
5698 set_vtable(builtin_vtables_[cid]);
5699 } else {
5700 set_vtable(builtin_vtables_[kInstanceCid]);
5701 }
5702 } 5814 }
5703 5815
5704 5816
5705 bool Function::HasCode() const { 5817 bool Function::HasCode() const {
5706 return raw_ptr()->code_ != Code::null(); 5818 return raw_ptr()->code_ != Code::null();
5707 } 5819 }
5708 5820
5709 5821
5710 intptr_t Field::Offset() const { 5822 intptr_t Field::Offset() const {
5711 ASSERT(!is_static()); // Offset is valid only for instance fields. 5823 ASSERT(!is_static()); // Offset is valid only for instance fields.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
5749 if (this->CharAt(i) != str.CharAt(begin_index + i)) { 5861 if (this->CharAt(i) != str.CharAt(begin_index + i)) {
5750 return false; 5862 return false;
5751 } 5863 }
5752 } 5864 }
5753 return true; 5865 return true;
5754 } 5866 }
5755 5867
5756 } // namespace dart 5868 } // namespace dart
5757 5869
5758 #endif // VM_OBJECT_H_ 5870 #endif // VM_OBJECT_H_
OLDNEW
« no previous file with comments | « runtime/vm/message_handler.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698