| 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 #include "vm/raw_object.h" | 5 #include "vm/raw_object.h" |
| 6 | 6 |
| 7 #include "vm/class_table.h" |
| 7 #include "vm/freelist.h" | 8 #include "vm/freelist.h" |
| 8 #include "vm/isolate.h" | 9 #include "vm/isolate.h" |
| 9 #include "vm/object.h" | 10 #include "vm/object.h" |
| 10 #include "vm/visitor.h" | 11 #include "vm/visitor.h" |
| 11 | 12 |
| 12 | 13 |
| 13 namespace dart { | 14 namespace dart { |
| 14 | 15 |
| 15 void RawObject::Validate() const { | 16 void RawObject::Validate(Isolate* isolate) const { |
| 17 // Validation only happens in DEBUG builds. |
| 18 #if defined(DEBUG) |
| 16 if (Object::null_class_ == reinterpret_cast<RawClass*>(kHeapObjectTag)) { | 19 if (Object::null_class_ == reinterpret_cast<RawClass*>(kHeapObjectTag)) { |
| 17 // Validation relies on properly initialized class classes. Skip if the | 20 // Validation relies on properly initialized class classes. Skip if the |
| 18 // VM is still being initialized. | 21 // VM is still being initialized. |
| 19 return; | 22 return; |
| 20 } | 23 } |
| 21 // All Smi values are valid. | 24 // All Smi values are valid. |
| 22 if (!IsHeapObject()) { | 25 if (!IsHeapObject()) { |
| 23 return; | 26 return; |
| 24 } | 27 } |
| 25 // Validate that the class_ field is sensible. | 28 // Validate that the class_ field is sensible. |
| 26 RawClass* raw_class = ptr()->class_; | 29 RawClass* raw_class = ptr()->class_; |
| 27 ASSERT(raw_class->IsHeapObject()); | 30 ASSERT(raw_class->IsHeapObject()); |
| 28 RawClass* raw_class_class = raw_class->ptr()->class_; | 31 RawClass* raw_class_class = raw_class->ptr()->class_; |
| 29 ASSERT(raw_class_class->IsHeapObject()); | 32 ASSERT(raw_class_class->IsHeapObject()); |
| 30 ASSERT(raw_class_class->ptr()->instance_kind_ == kClass); | 33 ASSERT(raw_class_class->ptr()->instance_kind_ == kClass); |
| 31 | 34 |
| 32 // Validate that the tags_ field is sensible. | 35 // Validate that the tags_ field is sensible. |
| 33 intptr_t tags = ptr()->tags_; | 36 uword tags = ptr()->tags_; |
| 34 ASSERT((tags & 0x000000f0) == 0); | 37 ASSERT((tags & 0x000000f0) == 0); |
| 38 intptr_t cid = ClassTag::decode(tags); |
| 39 RawClass* tag_class = isolate->class_table()->At(cid); |
| 40 ASSERT(tag_class == raw_class); |
| 41 #endif |
| 35 } | 42 } |
| 36 | 43 |
| 37 | 44 |
| 38 intptr_t RawObject::SizeFromClass() const { | 45 intptr_t RawObject::SizeFromClass() const { |
| 39 NoHandleScope no_handles(Isolate::Current()); | 46 NoHandleScope no_handles(Isolate::Current()); |
| 40 | 47 |
| 41 // Only reasonable to be called on heap objects. | 48 // Only reasonable to be called on heap objects. |
| 42 ASSERT(IsHeapObject()); | 49 ASSERT(IsHeapObject()); |
| 43 | 50 |
| 44 RawClass* raw_class = ptr()->class_; | 51 RawClass* raw_class = ptr()->class_; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 FreeListElement* element = reinterpret_cast<FreeListElement*>(addr); | 177 FreeListElement* element = reinterpret_cast<FreeListElement*>(addr); |
| 171 instance_size = element->Size(); | 178 instance_size = element->Size(); |
| 172 break; | 179 break; |
| 173 } | 180 } |
| 174 default: | 181 default: |
| 175 UNREACHABLE(); | 182 UNREACHABLE(); |
| 176 break; | 183 break; |
| 177 } | 184 } |
| 178 } | 185 } |
| 179 ASSERT(instance_size != 0); | 186 ASSERT(instance_size != 0); |
| 180 intptr_t tags = ptr()->tags_; | 187 uword tags = ptr()->tags_; |
| 181 ASSERT((instance_size == SizeTag::decode(tags)) || | 188 ASSERT((instance_size == SizeTag::decode(tags)) || |
| 182 (SizeTag::decode(tags) == 0) || | 189 (SizeTag::decode(tags) == 0) || |
| 183 FreeBit::decode(tags)); | 190 FreeBit::decode(tags)); |
| 184 return instance_size; | 191 return instance_size; |
| 185 } | 192 } |
| 186 | 193 |
| 187 | 194 |
| 188 intptr_t RawObject::VisitPointers(ObjectPointerVisitor* visitor) { | 195 intptr_t RawObject::VisitPointers(ObjectPointerVisitor* visitor) { |
| 189 intptr_t size = 0; | 196 intptr_t size = 0; |
| 190 NoHandleScope no_handles(Isolate::Current()); | 197 NoHandleScope no_handles(Isolate::Current()); |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 intptr_t RawJSRegExp::VisitJSRegExpPointers(RawJSRegExp* raw_obj, | 700 intptr_t RawJSRegExp::VisitJSRegExpPointers(RawJSRegExp* raw_obj, |
| 694 ObjectPointerVisitor* visitor) { | 701 ObjectPointerVisitor* visitor) { |
| 695 // Make sure that we got here with the tagged pointer as this. | 702 // Make sure that we got here with the tagged pointer as this. |
| 696 ASSERT(raw_obj->IsHeapObject()); | 703 ASSERT(raw_obj->IsHeapObject()); |
| 697 intptr_t length = Smi::Value(raw_obj->ptr()->data_length_); | 704 intptr_t length = Smi::Value(raw_obj->ptr()->data_length_); |
| 698 visitor->VisitPointers(raw_obj->from(), raw_obj->to()); | 705 visitor->VisitPointers(raw_obj->from(), raw_obj->to()); |
| 699 return JSRegExp::InstanceSize(length); | 706 return JSRegExp::InstanceSize(length); |
| 700 } | 707 } |
| 701 | 708 |
| 702 } // namespace dart | 709 } // namespace dart |
| OLD | NEW |