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/become.h" | 7 #include "vm/become.h" |
8 #include "vm/class_table.h" | 8 #include "vm/class_table.h" |
9 #include "vm/dart.h" | 9 #include "vm/dart.h" |
10 #include "vm/freelist.h" | 10 #include "vm/freelist.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 } | 23 } |
24 // All Smi values are valid. | 24 // All Smi values are valid. |
25 if (!IsHeapObject()) { | 25 if (!IsHeapObject()) { |
26 return; | 26 return; |
27 } | 27 } |
28 // Slightly more readable than a segfault. | 28 // Slightly more readable than a segfault. |
29 if (this == reinterpret_cast<RawObject*>(kHeapObjectTag)) { | 29 if (this == reinterpret_cast<RawObject*>(kHeapObjectTag)) { |
30 FATAL("RAW_NULL encountered"); | 30 FATAL("RAW_NULL encountered"); |
31 } | 31 } |
32 // Validate that the tags_ field is sensible. | 32 // Validate that the tags_ field is sensible. |
33 uint32_t tags = ptr()->tags_; | 33 uword tags = ptr()->tags_; |
34 intptr_t reserved = ReservedBits::decode(tags); | 34 intptr_t reserved = ReservedBits::decode(tags); |
35 if (reserved != 0) { | 35 if (reserved != 0) { |
36 FATAL1("Invalid tags field encountered %x\n", tags); | 36 FATAL1("Invalid tags field encountered %#" Px "\n", tags); |
37 } | 37 } |
38 intptr_t class_id = ClassIdTag::decode(tags); | 38 intptr_t class_id = ClassIdTag::decode(tags); |
39 if (!isolate->class_table()->IsValidIndex(class_id)) { | 39 if (!isolate->class_table()->IsValidIndex(class_id)) { |
40 FATAL1("Invalid class id encountered %" Pd "\n", class_id); | 40 FATAL1("Invalid class id encountered %" Pd "\n", class_id); |
41 } | 41 } |
42 if ((class_id == kNullCid) && | 42 if ((class_id == kNullCid) && |
43 (isolate->class_table()->At(class_id) == NULL)) { | 43 (isolate->class_table()->At(class_id) == NULL)) { |
44 // Null class not yet initialized; skip. | 44 // Null class not yet initialized; skip. |
45 return; | 45 return; |
46 } | 46 } |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 #if defined(DEBUG) |
185 ClassTable* class_table = isolate->class_table(); | 185 ClassTable* class_table = isolate->class_table(); |
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 %x\n", class_id, | 188 FATAL2("Invalid class id: %" Pd " from tags %" Px "\n", class_id, |
189 ptr()->tags_); | 189 ptr()->tags_); |
190 } | 190 } |
191 #endif // DEBUG | 191 #endif // DEBUG |
192 RawClass* raw_class = isolate->GetClassForHeapWalkAt(class_id); | 192 RawClass* raw_class = isolate->GetClassForHeapWalkAt(class_id); |
193 instance_size = raw_class->ptr()->instance_size_in_words_ | 193 instance_size = raw_class->ptr()->instance_size_in_words_ |
194 << kWordSizeLog2; | 194 << kWordSizeLog2; |
195 } | 195 } |
196 } | 196 } |
197 ASSERT(instance_size != 0); | 197 ASSERT(instance_size != 0); |
198 #if defined(DEBUG) | 198 #if defined(DEBUG) |
199 uint32_t tags = ptr()->tags_; | 199 uword tags = ptr()->tags_; |
200 intptr_t tags_size = SizeTag::decode(tags); | 200 intptr_t tags_size = SizeTag::decode(tags); |
201 if ((class_id == kArrayCid) && (instance_size > tags_size && tags_size > 0)) { | 201 if ((class_id == kArrayCid) && (instance_size > tags_size && tags_size > 0)) { |
202 // TODO(22501): Array::MakeFixedLength could be in the process of shrinking | 202 // TODO(22501): Array::MakeFixedLength could be in the process of shrinking |
203 // the array (see comment therein), having already updated the tags but not | 203 // the array (see comment therein), having already updated the tags but not |
204 // yet set the new length. Wait a millisecond and try again. | 204 // yet set the new length. Wait a millisecond and try again. |
205 int retries_remaining = 1000; // ... but not forever. | 205 int retries_remaining = 1000; // ... but not forever. |
206 do { | 206 do { |
207 OS::Sleep(1); | 207 OS::Sleep(1); |
208 const RawArray* raw_array = reinterpret_cast<const RawArray*>(this); | 208 const RawArray* raw_array = reinterpret_cast<const RawArray*>(this); |
209 intptr_t array_length = Smi::Value(raw_array->ptr()->length_); | 209 intptr_t array_length = Smi::Value(raw_array->ptr()->length_); |
210 instance_size = Array::InstanceSize(array_length); | 210 instance_size = Array::InstanceSize(array_length); |
211 } while ((instance_size > tags_size) && (--retries_remaining > 0)); | 211 } while ((instance_size > tags_size) && (--retries_remaining > 0)); |
212 } | 212 } |
213 if ((instance_size != tags_size) && (tags_size != 0)) { | 213 if ((instance_size != tags_size) && (tags_size != 0)) { |
214 FATAL3("Size mismatch: %" Pd " from class vs %" Pd " from tags %x\n", | 214 FATAL3("Size mismatch: %" Pd " from class vs %" Pd " from tags %" Px "\n", |
215 instance_size, tags_size, tags); | 215 instance_size, tags_size, tags); |
216 } | 216 } |
217 #endif // DEBUG | 217 #endif // DEBUG |
218 return instance_size; | 218 return instance_size; |
219 } | 219 } |
220 | 220 |
221 | 221 |
222 intptr_t RawObject::VisitPointersPredefined(ObjectPointerVisitor* visitor, | 222 intptr_t RawObject::VisitPointersPredefined(ObjectPointerVisitor* visitor, |
223 intptr_t class_id) { | 223 intptr_t class_id) { |
224 ASSERT(class_id < kNumPredefinedCids); | 224 ASSERT(class_id < kNumPredefinedCids); |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 | 517 |
518 | 518 |
519 intptr_t RawNamespace::VisitNamespacePointers(RawNamespace* raw_obj, | 519 intptr_t RawNamespace::VisitNamespacePointers(RawNamespace* raw_obj, |
520 ObjectPointerVisitor* visitor) { | 520 ObjectPointerVisitor* visitor) { |
521 visitor->VisitPointers(raw_obj->from(), raw_obj->to()); | 521 visitor->VisitPointers(raw_obj->from(), raw_obj->to()); |
522 return Namespace::InstanceSize(); | 522 return Namespace::InstanceSize(); |
523 } | 523 } |
524 | 524 |
525 | 525 |
526 bool RawCode::ContainsPC(RawObject* raw_obj, uword pc) { | 526 bool RawCode::ContainsPC(RawObject* raw_obj, uword pc) { |
527 uint32_t tags = raw_obj->ptr()->tags_; | 527 uword tags = raw_obj->ptr()->tags_; |
528 if (RawObject::ClassIdTag::decode(tags) == kCodeCid) { | 528 if (RawObject::ClassIdTag::decode(tags) == kCodeCid) { |
529 RawCode* raw_code = reinterpret_cast<RawCode*>(raw_obj); | 529 RawCode* raw_code = reinterpret_cast<RawCode*>(raw_obj); |
530 return RawInstructions::ContainsPC(raw_code->ptr()->instructions_, pc); | 530 return RawInstructions::ContainsPC(raw_code->ptr()->instructions_, pc); |
531 } | 531 } |
532 return false; | 532 return false; |
533 } | 533 } |
534 | 534 |
535 | 535 |
536 intptr_t RawCode::VisitCodePointers(RawCode* raw_obj, | 536 intptr_t RawCode::VisitCodePointers(RawCode* raw_obj, |
537 ObjectPointerVisitor* visitor) { | 537 ObjectPointerVisitor* visitor) { |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 ObjectPointerVisitor* visitor) { | 730 ObjectPointerVisitor* visitor) { |
731 visitor->VisitPointers(raw_obj->from(), raw_obj->to()); | 731 visitor->VisitPointers(raw_obj->from(), raw_obj->to()); |
732 return UnwindError::InstanceSize(); | 732 return UnwindError::InstanceSize(); |
733 } | 733 } |
734 | 734 |
735 | 735 |
736 intptr_t RawInstance::VisitInstancePointers(RawInstance* raw_obj, | 736 intptr_t RawInstance::VisitInstancePointers(RawInstance* raw_obj, |
737 ObjectPointerVisitor* visitor) { | 737 ObjectPointerVisitor* visitor) { |
738 // Make sure that we got here with the tagged pointer as this. | 738 // Make sure that we got here with the tagged pointer as this. |
739 ASSERT(raw_obj->IsHeapObject()); | 739 ASSERT(raw_obj->IsHeapObject()); |
740 uint32_t tags = raw_obj->ptr()->tags_; | 740 uword tags = raw_obj->ptr()->tags_; |
741 intptr_t instance_size = SizeTag::decode(tags); | 741 intptr_t instance_size = SizeTag::decode(tags); |
742 if (instance_size == 0) { | 742 if (instance_size == 0) { |
743 RawClass* cls = | 743 RawClass* cls = |
744 visitor->isolate()->GetClassForHeapWalkAt(raw_obj->GetClassId()); | 744 visitor->isolate()->GetClassForHeapWalkAt(raw_obj->GetClassId()); |
745 instance_size = cls->ptr()->instance_size_in_words_ << kWordSizeLog2; | 745 instance_size = cls->ptr()->instance_size_in_words_ << kWordSizeLog2; |
746 } | 746 } |
747 | 747 |
748 // Calculate the first and last raw object pointer fields. | 748 // Calculate the first and last raw object pointer fields. |
749 uword obj_addr = RawObject::ToAddr(raw_obj); | 749 uword obj_addr = RawObject::ToAddr(raw_obj); |
750 uword from = obj_addr + sizeof(RawObject); | 750 uword from = obj_addr + sizeof(RawObject); |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 intptr_t RawUserTag::VisitUserTagPointers(RawUserTag* raw_obj, | 1003 intptr_t RawUserTag::VisitUserTagPointers(RawUserTag* raw_obj, |
1004 ObjectPointerVisitor* visitor) { | 1004 ObjectPointerVisitor* visitor) { |
1005 // Make sure that we got here with the tagged pointer as this. | 1005 // Make sure that we got here with the tagged pointer as this. |
1006 ASSERT(raw_obj->IsHeapObject()); | 1006 ASSERT(raw_obj->IsHeapObject()); |
1007 visitor->VisitPointers(raw_obj->from(), raw_obj->to()); | 1007 visitor->VisitPointers(raw_obj->from(), raw_obj->to()); |
1008 return UserTag::InstanceSize(); | 1008 return UserTag::InstanceSize(); |
1009 } | 1009 } |
1010 | 1010 |
1011 | 1011 |
1012 } // namespace dart | 1012 } // namespace dart |
OLD | NEW |