| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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/isolate.h" |
| 7 #include "vm/object.h" | 8 #include "vm/object.h" |
| 8 #include "vm/visitor.h" | 9 #include "vm/visitor.h" |
| 9 | 10 |
| 10 | 11 |
| 11 namespace dart { | 12 namespace dart { |
| 12 | 13 |
| 13 void RawObject::Validate() const { | 14 void RawObject::Validate() const { |
| 14 // All Smi values are valid. | 15 // All Smi values are valid. |
| 15 if (!IsHeapObject()) { | 16 if (!IsHeapObject()) { |
| 16 return; | 17 return; |
| 17 } | 18 } |
| 18 // Validate that the class_ field is sensible. | 19 // Validate that the class_ field is sensible. |
| 19 RawClass* raw_class = ptr()->class_; | 20 RawClass* raw_class = ptr()->class_; |
| 20 ASSERT(raw_class->IsHeapObject()); | 21 ASSERT(raw_class->IsHeapObject()); |
| 21 RawClass* raw_class_class = raw_class->ptr()->class_; | 22 RawClass* raw_class_class = raw_class->ptr()->class_; |
| 22 ASSERT(raw_class_class->IsHeapObject()); | 23 ASSERT(raw_class_class->IsHeapObject()); |
| 23 ASSERT(raw_class_class->ptr()->instance_kind_ == kClass); | 24 ASSERT(raw_class_class->ptr()->instance_kind_ == kClass); |
| 24 } | 25 } |
| 25 | 26 |
| 26 | 27 |
| 27 intptr_t RawObject::Size() const { | 28 intptr_t RawObject::Size() const { |
| 28 NoHandleScope no_handles; | 29 NoHandleScope no_handles(Isolate::Current()); |
| 29 | 30 |
| 30 // Only reasonable to be called on heap objects. | 31 // Only reasonable to be called on heap objects. |
| 31 ASSERT(IsHeapObject()); | 32 ASSERT(IsHeapObject()); |
| 32 | 33 |
| 33 RawClass* raw_class = ptr()->class_; | 34 RawClass* raw_class = ptr()->class_; |
| 34 intptr_t instance_size = raw_class->ptr()->instance_size_; | 35 intptr_t instance_size = raw_class->ptr()->instance_size_; |
| 35 if (instance_size == 0) { | 36 if (instance_size == 0) { |
| 36 switch (raw_class->ptr()->instance_kind_) { | 37 switch (raw_class->ptr()->instance_kind_) { |
| 37 case kTokenStream: { | 38 case kTokenStream: { |
| 38 const RawTokenStream* raw_tokens = | 39 const RawTokenStream* raw_tokens = |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 break; | 137 break; |
| 137 } | 138 } |
| 138 } | 139 } |
| 139 ASSERT(instance_size != 0); | 140 ASSERT(instance_size != 0); |
| 140 return instance_size; | 141 return instance_size; |
| 141 } | 142 } |
| 142 | 143 |
| 143 | 144 |
| 144 intptr_t RawObject::VisitPointers(ObjectPointerVisitor* visitor) { | 145 intptr_t RawObject::VisitPointers(ObjectPointerVisitor* visitor) { |
| 145 intptr_t size = 0; | 146 intptr_t size = 0; |
| 146 NoHandleScope no_handles; | 147 NoHandleScope no_handles(Isolate::Current()); |
| 147 | 148 |
| 148 // Only reasonable to be called on heap objects. | 149 // Only reasonable to be called on heap objects. |
| 149 ASSERT(IsHeapObject()); | 150 ASSERT(IsHeapObject()); |
| 150 | 151 |
| 151 // Read the necessary data out of the class before visting the class itself. | 152 // Read the necessary data out of the class before visting the class itself. |
| 152 ObjectKind kind = ptr()->class_->ptr()->instance_kind_; | 153 ObjectKind kind = ptr()->class_->ptr()->instance_kind_; |
| 153 | 154 |
| 154 // Visit the class before visting the fields. | 155 // Visit the class before visting the fields. |
| 155 visitor->VisitPointer(reinterpret_cast<RawObject**>(&ptr()->class_)); | 156 visitor->VisitPointer(reinterpret_cast<RawObject**>(&ptr()->class_)); |
| 156 | 157 |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 intptr_t RawJSRegExp::VisitJSRegExpPointers(RawJSRegExp* raw_obj, | 498 intptr_t RawJSRegExp::VisitJSRegExpPointers(RawJSRegExp* raw_obj, |
| 498 ObjectPointerVisitor* visitor) { | 499 ObjectPointerVisitor* visitor) { |
| 499 // Make sure that we got here with the tagged pointer as this. | 500 // Make sure that we got here with the tagged pointer as this. |
| 500 ASSERT(raw_obj->IsHeapObject()); | 501 ASSERT(raw_obj->IsHeapObject()); |
| 501 intptr_t length = Smi::Value(raw_obj->ptr()->data_length_); | 502 intptr_t length = Smi::Value(raw_obj->ptr()->data_length_); |
| 502 visitor->VisitPointers(raw_obj->from(), raw_obj->to()); | 503 visitor->VisitPointers(raw_obj->from(), raw_obj->to()); |
| 503 return JSRegExp::InstanceSize(length); | 504 return JSRegExp::InstanceSize(length); |
| 504 } | 505 } |
| 505 | 506 |
| 506 } // namespace dart | 507 } // namespace dart |
| OLD | NEW |