| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 65 |
| 66 | 66 |
| 67 intptr_t RawObject::SizeFromClass() const { | 67 intptr_t RawObject::SizeFromClass() const { |
| 68 Isolate* isolate = Isolate::Current(); | 68 Isolate* isolate = Isolate::Current(); |
| 69 NoHandleScope no_handles(isolate); | 69 NoHandleScope no_handles(isolate); |
| 70 | 70 |
| 71 // Only reasonable to be called on heap objects. | 71 // Only reasonable to be called on heap objects. |
| 72 ASSERT(IsHeapObject()); | 72 ASSERT(IsHeapObject()); |
| 73 | 73 |
| 74 intptr_t class_id = GetClassId(); | 74 intptr_t class_id = GetClassId(); |
| 75 RawClass* raw_class = isolate->class_table()->At(class_id); | 75 ClassTable* class_table = isolate->class_table(); |
| 76 #if defined(DEBUG) |
| 77 if (!class_table->IsValidIndex(class_id) || |
| 78 !class_table->HasValidClassAt(class_id)) { |
| 79 FATAL2("Invalid class id: %" Pd " from tags %" Px "\n", |
| 80 class_id, ptr()->tags_); |
| 81 } |
| 82 #endif // DEBUG |
| 83 RawClass* raw_class = class_table->At(class_id); |
| 76 ASSERT(raw_class->ptr()->id_ == class_id); | 84 ASSERT(raw_class->ptr()->id_ == class_id); |
| 77 | 85 |
| 78 // Get the instance size out of the class. | 86 // Get the instance size out of the class. |
| 79 intptr_t instance_size = | 87 intptr_t instance_size = |
| 80 raw_class->ptr()->instance_size_in_words_ << kWordSizeLog2; | 88 raw_class->ptr()->instance_size_in_words_ << kWordSizeLog2; |
| 81 | 89 |
| 82 if (instance_size == 0) { | 90 if (instance_size == 0) { |
| 83 switch (class_id) { | 91 switch (class_id) { |
| 84 case kCodeCid: { | 92 case kCodeCid: { |
| 85 const RawCode* raw_code = reinterpret_cast<const RawCode*>(this); | 93 const RawCode* raw_code = reinterpret_cast<const RawCode*>(this); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 FreeListElement* element = reinterpret_cast<FreeListElement*>(addr); | 206 FreeListElement* element = reinterpret_cast<FreeListElement*>(addr); |
| 199 instance_size = element->Size(); | 207 instance_size = element->Size(); |
| 200 break; | 208 break; |
| 201 } | 209 } |
| 202 default: | 210 default: |
| 203 UNREACHABLE(); | 211 UNREACHABLE(); |
| 204 break; | 212 break; |
| 205 } | 213 } |
| 206 } | 214 } |
| 207 ASSERT(instance_size != 0); | 215 ASSERT(instance_size != 0); |
| 216 #if defined(DEBUG) |
| 208 uword tags = ptr()->tags_; | 217 uword tags = ptr()->tags_; |
| 209 ASSERT((instance_size == SizeTag::decode(tags)) || | 218 intptr_t tags_size = SizeTag::decode(tags); |
| 210 (SizeTag::decode(tags) == 0)); | 219 if ((instance_size != tags_size) && (tags_size != 0)) { |
| 220 FATAL3("Size mismatch: %" Pd " vs %" Pd " from tags %" Px "\n", |
| 221 instance_size, tags_size, tags); |
| 222 } |
| 223 #endif // DEBUG |
| 211 return instance_size; | 224 return instance_size; |
| 212 } | 225 } |
| 213 | 226 |
| 214 | 227 |
| 215 #if defined(DEBUG) | 228 #if defined(DEBUG) |
| 216 void RawObject::ValidateOverwrittenPointer(RawObject* raw) { | 229 void RawObject::ValidateOverwrittenPointer(RawObject* raw) { |
| 217 if (FLAG_validate_overwrite) { | 230 if (FLAG_validate_overwrite) { |
| 218 raw->Validate(Isolate::Current()); | 231 raw->Validate(Isolate::Current()); |
| 219 } | 232 } |
| 220 } | 233 } |
| (...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 911 intptr_t RawUserTag::VisitUserTagPointers( | 924 intptr_t RawUserTag::VisitUserTagPointers( |
| 912 RawUserTag* raw_obj, ObjectPointerVisitor* visitor) { | 925 RawUserTag* raw_obj, ObjectPointerVisitor* visitor) { |
| 913 // Make sure that we got here with the tagged pointer as this. | 926 // Make sure that we got here with the tagged pointer as this. |
| 914 ASSERT(raw_obj->IsHeapObject()); | 927 ASSERT(raw_obj->IsHeapObject()); |
| 915 visitor->VisitPointers(raw_obj->from(), raw_obj->to()); | 928 visitor->VisitPointers(raw_obj->from(), raw_obj->to()); |
| 916 return UserTag::InstanceSize(); | 929 return UserTag::InstanceSize(); |
| 917 } | 930 } |
| 918 | 931 |
| 919 | 932 |
| 920 } // namespace dart | 933 } // namespace dart |
| OLD | NEW |