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/class_table.h" |
8 #include "vm/dart.h" | 8 #include "vm/dart.h" |
9 #include "vm/freelist.h" | 9 #include "vm/freelist.h" |
10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 case kFreeListElement: { | 174 case kFreeListElement: { |
175 uword addr = RawObject::ToAddr(this); | 175 uword addr = RawObject::ToAddr(this); |
176 FreeListElement* element = reinterpret_cast<FreeListElement*>(addr); | 176 FreeListElement* element = reinterpret_cast<FreeListElement*>(addr); |
177 instance_size = element->Size(); | 177 instance_size = element->Size(); |
178 break; | 178 break; |
179 } | 179 } |
180 default: { | 180 default: { |
181 // Get the (constant) instance size out of the class object. | 181 // Get the (constant) instance size out of the class object. |
182 // TODO(koda): Add Size(ClassTable*) interface to allow caching in loops. | 182 // TODO(koda): Add Size(ClassTable*) interface to allow caching in loops. |
183 Isolate* isolate = Isolate::Current(); | 183 Isolate* isolate = Isolate::Current(); |
| 184 #if defined(DEBUG) |
184 ClassTable* class_table = isolate->class_table(); | 185 ClassTable* class_table = isolate->class_table(); |
185 #if defined(DEBUG) | |
186 if (!class_table->IsValidIndex(class_id) || | 186 if (!class_table->IsValidIndex(class_id) || |
187 !class_table->HasValidClassAt(class_id)) { | 187 !class_table->HasValidClassAt(class_id)) { |
188 FATAL2("Invalid class id: %" Pd " from tags %" Px "\n", | 188 FATAL2("Invalid class id: %" Pd " from tags %" Px "\n", |
189 class_id, ptr()->tags_); | 189 class_id, ptr()->tags_); |
190 } | 190 } |
191 #endif // DEBUG | 191 #endif // DEBUG |
192 RawClass* raw_class = class_table->At(class_id); | 192 RawClass* raw_class = isolate->GetClassForHeapWalkAt(class_id); |
193 ASSERT(raw_class->ptr()->id_ == class_id); | |
194 instance_size = | 193 instance_size = |
195 raw_class->ptr()->instance_size_in_words_ << kWordSizeLog2; | 194 raw_class->ptr()->instance_size_in_words_ << kWordSizeLog2; |
196 } | 195 } |
197 } | 196 } |
198 ASSERT(instance_size != 0); | 197 ASSERT(instance_size != 0); |
199 #if defined(DEBUG) | 198 #if defined(DEBUG) |
200 uword tags = ptr()->tags_; | 199 uword tags = ptr()->tags_; |
201 intptr_t tags_size = SizeTag::decode(tags); | 200 intptr_t tags_size = SizeTag::decode(tags); |
202 if ((class_id == kArrayCid) && (instance_size > tags_size && tags_size > 0)) { | 201 if ((class_id == kArrayCid) && (instance_size > tags_size && tags_size > 0)) { |
203 // TODO(22501): Array::MakeArray could be in the process of shrinking | 202 // TODO(22501): Array::MakeArray could be in the process of shrinking |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 | 705 |
707 | 706 |
708 intptr_t RawInstance::VisitInstancePointers(RawInstance* raw_obj, | 707 intptr_t RawInstance::VisitInstancePointers(RawInstance* raw_obj, |
709 ObjectPointerVisitor* visitor) { | 708 ObjectPointerVisitor* visitor) { |
710 // Make sure that we got here with the tagged pointer as this. | 709 // Make sure that we got here with the tagged pointer as this. |
711 ASSERT(raw_obj->IsHeapObject()); | 710 ASSERT(raw_obj->IsHeapObject()); |
712 uword tags = raw_obj->ptr()->tags_; | 711 uword tags = raw_obj->ptr()->tags_; |
713 intptr_t instance_size = SizeTag::decode(tags); | 712 intptr_t instance_size = SizeTag::decode(tags); |
714 if (instance_size == 0) { | 713 if (instance_size == 0) { |
715 RawClass* cls = | 714 RawClass* cls = |
716 visitor->isolate()->class_table()->At(raw_obj->GetClassId()); | 715 visitor->isolate()->GetClassForHeapWalkAt(raw_obj->GetClassId()); |
717 instance_size = cls->ptr()->instance_size_in_words_ << kWordSizeLog2; | 716 instance_size = cls->ptr()->instance_size_in_words_ << kWordSizeLog2; |
718 } | 717 } |
719 | 718 |
720 // Calculate the first and last raw object pointer fields. | 719 // Calculate the first and last raw object pointer fields. |
721 uword obj_addr = RawObject::ToAddr(raw_obj); | 720 uword obj_addr = RawObject::ToAddr(raw_obj); |
722 uword from = obj_addr + sizeof(RawObject); | 721 uword from = obj_addr + sizeof(RawObject); |
723 uword to = obj_addr + instance_size - kWordSize; | 722 uword to = obj_addr + instance_size - kWordSize; |
724 visitor->VisitPointers(reinterpret_cast<RawObject**>(from), | 723 visitor->VisitPointers(reinterpret_cast<RawObject**>(from), |
725 reinterpret_cast<RawObject**>(to)); | 724 reinterpret_cast<RawObject**>(to)); |
726 return instance_size; | 725 return instance_size; |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 intptr_t RawUserTag::VisitUserTagPointers( | 962 intptr_t RawUserTag::VisitUserTagPointers( |
964 RawUserTag* raw_obj, ObjectPointerVisitor* visitor) { | 963 RawUserTag* raw_obj, ObjectPointerVisitor* visitor) { |
965 // Make sure that we got here with the tagged pointer as this. | 964 // Make sure that we got here with the tagged pointer as this. |
966 ASSERT(raw_obj->IsHeapObject()); | 965 ASSERT(raw_obj->IsHeapObject()); |
967 visitor->VisitPointers(raw_obj->from(), raw_obj->to()); | 966 visitor->VisitPointers(raw_obj->from(), raw_obj->to()); |
968 return UserTag::InstanceSize(); | 967 return UserTag::InstanceSize(); |
969 } | 968 } |
970 | 969 |
971 | 970 |
972 } // namespace dart | 971 } // namespace dart |
OLD | NEW |