| 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/bigint_operations.h" | 5 #include "vm/bigint_operations.h" |
| 6 #include "vm/object.h" | 6 #include "vm/object.h" |
| 7 #include "vm/object_store.h" | 7 #include "vm/object_store.h" |
| 8 #include "vm/snapshot.h" | 8 #include "vm/snapshot.h" |
| 9 #include "vm/symbols.h" | 9 #include "vm/symbols.h" |
| 10 #include "vm/visitor.h" | 10 #include "vm/visitor.h" |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 | 13 |
| 14 DECLARE_FLAG(bool, error_on_bad_type); | |
| 15 | |
| 16 | |
| 17 #define NEW_OBJECT(type) \ | 14 #define NEW_OBJECT(type) \ |
| 18 ((kind == Snapshot::kFull) ? reader->New##type() : type::New()) | 15 ((kind == Snapshot::kFull) ? reader->New##type() : type::New()) |
| 19 | 16 |
| 20 #define NEW_OBJECT_WITH_LEN(type, len) \ | 17 #define NEW_OBJECT_WITH_LEN(type, len) \ |
| 21 ((kind == Snapshot::kFull) ? reader->New##type(len) : type::New(len)) | 18 ((kind == Snapshot::kFull) ? reader->New##type(len) : type::New(len)) |
| 22 | 19 |
| 23 #define NEW_OBJECT_WITH_LEN_SPACE(type, len, kind) \ | 20 #define NEW_OBJECT_WITH_LEN_SPACE(type, len, kind) \ |
| 24 ((kind == Snapshot::kFull) ? \ | 21 ((kind == Snapshot::kFull) ? \ |
| 25 reader->New##type(len) : type::New(len, HEAP_SPACE(kind))) | 22 reader->New##type(len) : type::New(len, HEAP_SPACE(kind))) |
| 26 | 23 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 } | 231 } |
| 235 | 232 |
| 236 // Set the object tags (This is done after 'Canonicalize', which | 233 // Set the object tags (This is done after 'Canonicalize', which |
| 237 // does not canonicalize a type already marked as canonical). | 234 // does not canonicalize a type already marked as canonical). |
| 238 type.set_tags(tags); | 235 type.set_tags(tags); |
| 239 | 236 |
| 240 return type.raw(); | 237 return type.raw(); |
| 241 } | 238 } |
| 242 | 239 |
| 243 | 240 |
| 244 static const char* RawOneByteStringToCString(RawOneByteString* str) { | |
| 245 const char* start = reinterpret_cast<char*>(str) - kHeapObjectTag + | |
| 246 OneByteString::data_offset(); | |
| 247 const int len = Smi::Value(*reinterpret_cast<RawSmi**>( | |
| 248 reinterpret_cast<uword>(str) - kHeapObjectTag + String::length_offset())); | |
| 249 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len + 1); | |
| 250 memmove(chars, start, len); | |
| 251 chars[len] = '\0'; | |
| 252 return chars; | |
| 253 } | |
| 254 | |
| 255 | |
| 256 void RawType::WriteTo(SnapshotWriter* writer, | 241 void RawType::WriteTo(SnapshotWriter* writer, |
| 257 intptr_t object_id, | 242 intptr_t object_id, |
| 258 Snapshot::Kind kind) { | 243 Snapshot::Kind kind) { |
| 259 ASSERT(writer != NULL); | 244 ASSERT(writer != NULL); |
| 260 | 245 |
| 261 // Only resolved and finalized types should be written to a snapshot. | 246 // Only resolved and finalized types should be written to a snapshot. |
| 262 // TODO(regis): Replace the test below by an ASSERT() or remove the flag test. | 247 ASSERT((ptr()->type_state_ == RawType::kFinalizedInstantiated) || |
| 263 if (FLAG_error_on_bad_type && | 248 (ptr()->type_state_ == RawType::kFinalizedUninstantiated)); |
| 264 (ptr()->type_state_ != RawType::kFinalizedInstantiated) && | |
| 265 (ptr()->type_state_ != RawType::kFinalizedUninstantiated)) { | |
| 266 // Print the name of the class of the unfinalized type, as well as the | |
| 267 // token location from where it is referred to, making sure not | |
| 268 // to allocate any handles. Unfortunately, we cannot print the script name. | |
| 269 const intptr_t cid = ClassIdTag::decode(*reinterpret_cast<uword*>( | |
| 270 reinterpret_cast<uword>(ptr()->type_class_) - kHeapObjectTag + | |
| 271 Object::tags_offset())); | |
| 272 if (cid == kUnresolvedClassCid) { | |
| 273 OS::Print("Snapshotting unresolved type '%s' at token pos %" Pd "\n", | |
| 274 RawOneByteStringToCString( | |
| 275 reinterpret_cast<RawOneByteString*>( | |
| 276 reinterpret_cast<RawUnresolvedClass*>( | |
| 277 ptr()->type_class_)->ptr()->ident_)), | |
| 278 ptr()->token_pos_); | |
| 279 } else { | |
| 280 // Assume cid == kClassId, but it can also be kIllegalCid. | |
| 281 OS::Print("Snapshotting unfinalized type '%s' at token pos %" Pd "\n", | |
| 282 RawOneByteStringToCString( | |
| 283 reinterpret_cast<RawOneByteString*>( | |
| 284 reinterpret_cast<RawClass*>( | |
| 285 ptr()->type_class_)->ptr()->name_)), | |
| 286 ptr()->token_pos_); | |
| 287 } | |
| 288 UNREACHABLE(); | |
| 289 } | |
| 290 | 249 |
| 291 // Write out the serialization header value for this object. | 250 // Write out the serialization header value for this object. |
| 292 writer->WriteInlinedObjectHeader(object_id); | 251 writer->WriteInlinedObjectHeader(object_id); |
| 293 | 252 |
| 294 // Write out the class and tags information. | 253 // Write out the class and tags information. |
| 295 writer->WriteIndexedObject(kTypeCid); | 254 writer->WriteIndexedObject(kTypeCid); |
| 296 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 255 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 297 | 256 |
| 298 // Write out all the non object pointer fields. | 257 // Write out all the non object pointer fields. |
| 299 writer->WriteIntptrValue(ptr()->token_pos_); | 258 writer->WriteIntptrValue(ptr()->token_pos_); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 return type_parameter.raw(); | 345 return type_parameter.raw(); |
| 387 } | 346 } |
| 388 | 347 |
| 389 | 348 |
| 390 void RawTypeParameter::WriteTo(SnapshotWriter* writer, | 349 void RawTypeParameter::WriteTo(SnapshotWriter* writer, |
| 391 intptr_t object_id, | 350 intptr_t object_id, |
| 392 Snapshot::Kind kind) { | 351 Snapshot::Kind kind) { |
| 393 ASSERT(writer != NULL); | 352 ASSERT(writer != NULL); |
| 394 | 353 |
| 395 // Only finalized type parameters should be written to a snapshot. | 354 // Only finalized type parameters should be written to a snapshot. |
| 396 // TODO(regis): Replace the test below by an ASSERT() or remove the flag test. | 355 ASSERT(ptr()->type_state_ == RawTypeParameter::kFinalizedUninstantiated); |
| 397 if (FLAG_error_on_bad_type && | |
| 398 (ptr()->type_state_ != RawTypeParameter::kFinalizedUninstantiated)) { | |
| 399 // Print the name of the unfinalized type parameter, the name of the class | |
| 400 // it parameterizes, as well as the token location from where it is referred | |
| 401 // to, making sure not to allocate any handles. Unfortunately, we cannot | |
| 402 // print the script name. | |
| 403 OS::Print("Snapshotting unfinalized type parameter '%s' of class '%s' at " | |
| 404 "token pos %" Pd "\n", | |
| 405 RawOneByteStringToCString( | |
| 406 reinterpret_cast<RawOneByteString*>(ptr()->name_)), | |
| 407 RawOneByteStringToCString( | |
| 408 reinterpret_cast<RawOneByteString*>( | |
| 409 reinterpret_cast<RawClass*>( | |
| 410 ptr()->parameterized_class_)->ptr()->name_)), | |
| 411 ptr()->token_pos_); | |
| 412 UNREACHABLE(); | |
| 413 } | |
| 414 | 356 |
| 415 // Write out the serialization header value for this object. | 357 // Write out the serialization header value for this object. |
| 416 writer->WriteInlinedObjectHeader(object_id); | 358 writer->WriteInlinedObjectHeader(object_id); |
| 417 | 359 |
| 418 // Write out the class and tags information. | 360 // Write out the class and tags information. |
| 419 writer->WriteIndexedObject(kTypeParameterCid); | 361 writer->WriteIndexedObject(kTypeParameterCid); |
| 420 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 362 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 421 | 363 |
| 422 // Write out all the non object pointer fields. | 364 // Write out all the non object pointer fields. |
| 423 writer->WriteIntptrValue(ptr()->index_); | 365 writer->WriteIntptrValue(ptr()->index_); |
| (...skipping 2322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2746 // We do not allow objects with native fields in an isolate message. | 2688 // We do not allow objects with native fields in an isolate message. |
| 2747 writer->SetWriteException(Exceptions::kArgument, | 2689 writer->SetWriteException(Exceptions::kArgument, |
| 2748 "Illegal argument in isolate message" | 2690 "Illegal argument in isolate message" |
| 2749 " : (object is a MirrorReference)"); | 2691 " : (object is a MirrorReference)"); |
| 2750 } else { | 2692 } else { |
| 2751 UNREACHABLE(); | 2693 UNREACHABLE(); |
| 2752 } | 2694 } |
| 2753 } | 2695 } |
| 2754 | 2696 |
| 2755 } // namespace dart | 2697 } // namespace dart |
| OLD | NEW |