Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Side by Side Diff: vm/raw_object_snapshot.cc

Issue 9166012: Create temporary handles in the snapshot object during initialization and use them instead of cre... (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | vm/snapshot.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/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/visitor.h" 9 #include "vm/visitor.h"
10 10
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 intptr_t object_id, 337 intptr_t object_id,
338 intptr_t tags, 338 intptr_t tags,
339 Snapshot::Kind kind) { 339 Snapshot::Kind kind) {
340 ASSERT(reader != NULL); 340 ASSERT(reader != NULL);
341 341
342 // Read the length so that we can determine instance size to allocate. 342 // Read the length so that we can determine instance size to allocate.
343 RawSmi* smi_len = GetSmi(reader->ReadIntptrValue()); 343 RawSmi* smi_len = GetSmi(reader->ReadIntptrValue());
344 intptr_t len = Smi::Value(smi_len); 344 intptr_t len = Smi::Value(smi_len);
345 345
346 TypeArguments& type_arguments = 346 TypeArguments& type_arguments =
347 TypeArguments::Handle(reader->isolate(), TypeArguments::New(len)); 347 TypeArguments::ZoneHandle(reader->isolate(), TypeArguments::New(len));
348 reader->AddBackwardReference(object_id, &type_arguments); 348 reader->AddBackwardReference(object_id, &type_arguments);
349 349
350 // Now set all the object fields. 350 // Now set all the object fields.
351 AbstractType& type = AbstractType::Handle(reader->isolate(),
352 AbstractType::null());
353 for (intptr_t i = 0; i < len; i++) { 351 for (intptr_t i = 0; i < len; i++) {
354 type ^= reader->ReadObject(); 352 *reader->TypeHandle() ^= reader->ReadObject();
355 type_arguments.SetTypeAt(i, type); 353 type_arguments.SetTypeAt(i, *reader->TypeHandle());
356 } 354 }
357 355
358 // Set the object tags (This is done after setting the object fields 356 // Set the object tags (This is done after setting the object fields
359 // because 'SetTypeAt' has an assertion to check if the object is not 357 // because 'SetTypeAt' has an assertion to check if the object is not
360 // already canonical). 358 // already canonical).
361 type_arguments.set_tags(tags); 359 type_arguments.set_tags(tags);
362 360
363 // If object needs to be a canonical object, Canonicalize it. 361 // If object needs to be a canonical object, Canonicalize it.
364 if ((kind != Snapshot::kFull) && type_arguments.IsCanonical()) { 362 if ((kind != Snapshot::kFull) && type_arguments.IsCanonical()) {
365 type_arguments ^= type_arguments.Canonicalize(); 363 type_arguments ^= type_arguments.Canonicalize();
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 571
574 // Create the token stream object. 572 // Create the token stream object.
575 TokenStream& token_stream = TokenStream::ZoneHandle(reader->isolate(), 573 TokenStream& token_stream = TokenStream::ZoneHandle(reader->isolate(),
576 TokenStream::New(len)); 574 TokenStream::New(len));
577 reader->AddBackwardReference(object_id, &token_stream); 575 reader->AddBackwardReference(object_id, &token_stream);
578 576
579 // Set the object tags. 577 // Set the object tags.
580 token_stream.set_tags(tags); 578 token_stream.set_tags(tags);
581 579
582 // Read the token stream into the TokenStream. 580 // Read the token stream into the TokenStream.
583 String& literal = String::Handle(reader->isolate(), String::null());
584 for (intptr_t i = 0; i < len; i++) { 581 for (intptr_t i = 0; i < len; i++) {
585 Token::Kind kind = static_cast<Token::Kind>( 582 Token::Kind kind = static_cast<Token::Kind>(
586 Smi::Value(GetSmi(reader->ReadIntptrValue()))); 583 Smi::Value(GetSmi(reader->ReadIntptrValue())));
587 literal ^= reader->ReadObject(); 584 *reader->StringHandle() ^= reader->ReadObject();
588 token_stream.SetTokenAt(i, kind, literal); 585 token_stream.SetTokenAt(i, kind, *reader->StringHandle());
589 } 586 }
590 return token_stream.raw(); 587 return token_stream.raw();
591 } 588 }
592 589
593 590
594 void RawTokenStream::WriteTo(SnapshotWriter* writer, 591 void RawTokenStream::WriteTo(SnapshotWriter* writer,
595 intptr_t object_id, 592 intptr_t object_id,
596 Snapshot::Kind kind) { 593 Snapshot::Kind kind) {
597 ASSERT(writer != NULL); 594 ASSERT(writer != NULL);
598 ASSERT(kind != Snapshot::kMessage && !IsCreatedFromSnapshot()); 595 ASSERT(kind != Snapshot::kMessage && !IsCreatedFromSnapshot());
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 Snapshot::Kind kind) { 662 Snapshot::Kind kind) {
666 ASSERT(reader != NULL); 663 ASSERT(reader != NULL);
667 ASSERT(kind != Snapshot::kMessage); 664 ASSERT(kind != Snapshot::kMessage);
668 665
669 Library& library = Library::ZoneHandle(reader->isolate(), Library::null()); 666 Library& library = Library::ZoneHandle(reader->isolate(), Library::null());
670 reader->AddBackwardReference(object_id, &library); 667 reader->AddBackwardReference(object_id, &library);
671 668
672 if (RawObject::IsCreatedFromSnapshot(tags)) { 669 if (RawObject::IsCreatedFromSnapshot(tags)) {
673 ASSERT(kind != Snapshot::kFull); 670 ASSERT(kind != Snapshot::kFull);
674 // Lookup the object as it should already exist in the heap. 671 // Lookup the object as it should already exist in the heap.
675 String& library_url = String::Handle(reader->isolate(), String::null()); 672 *reader->StringHandle() ^= reader->ReadObject();
676 library_url ^= reader->ReadObject(); 673 library = Library::LookupLibrary(*reader->StringHandle());
677 library = Library::LookupLibrary(library_url);
678 } else { 674 } else {
679 // Allocate library object. 675 // Allocate library object.
680 library = Library::New(); 676 library = Library::New();
681 677
682 // Set the object tags. 678 // Set the object tags.
683 library.set_tags(tags); 679 library.set_tags(tags);
684 680
685 // Set all non object fields. 681 // Set all non object fields.
686 library.raw_ptr()->num_imports_ = reader->ReadIntptrValue(); 682 library.raw_ptr()->num_imports_ = reader->ReadIntptrValue();
687 library.raw_ptr()->num_imported_into_ = reader->ReadIntptrValue(); 683 library.raw_ptr()->num_imported_into_ = reader->ReadIntptrValue();
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after
1407 template <class T> 1403 template <class T>
1408 static RawObject* ArrayReadFrom(SnapshotReader* reader, 1404 static RawObject* ArrayReadFrom(SnapshotReader* reader,
1409 intptr_t object_id, 1405 intptr_t object_id,
1410 intptr_t tags, 1406 intptr_t tags,
1411 Snapshot::Kind kind) { 1407 Snapshot::Kind kind) {
1412 ASSERT(reader != NULL); 1408 ASSERT(reader != NULL);
1413 1409
1414 // Read the length so that we can determine instance size to allocate. 1410 // Read the length so that we can determine instance size to allocate.
1415 RawSmi* smi_len = GetSmi(reader->ReadIntptrValue()); 1411 RawSmi* smi_len = GetSmi(reader->ReadIntptrValue());
1416 intptr_t len = Smi::Value(smi_len); 1412 intptr_t len = Smi::Value(smi_len);
1417 T& result = T::Handle( 1413 T& result = T::ZoneHandle(
1418 reader->isolate(), 1414 reader->isolate(),
1419 T::New(len, (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew)); 1415 T::New(len, (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew));
1420 reader->AddBackwardReference(object_id, &result); 1416 reader->AddBackwardReference(object_id, &result);
1421 1417
1422 // Set the object tags. 1418 // Set the object tags.
1423 result.set_tags(tags); 1419 result.set_tags(tags);
1424 1420
1425 // Setup the object fields. 1421 // Setup the object fields.
1426 AbstractTypeArguments& type_arguments = 1422 *reader->TypeArgumentsHandle() ^= reader->ReadObject();
1427 AbstractTypeArguments::Handle(reader->isolate(), 1423 result.SetTypeArguments(*reader->TypeArgumentsHandle());
1428 AbstractTypeArguments::null());
1429 type_arguments ^= reader->ReadObject();
1430 result.SetTypeArguments(type_arguments);
1431 1424
1432 Object& obj = Object::Handle(reader->isolate(), Object::null());
1433 for (intptr_t i = 0; i < len; i++) { 1425 for (intptr_t i = 0; i < len; i++) {
1434 obj = reader->ReadObject(); 1426 *reader->ObjectHandle() = reader->ReadObject();
1435 result.SetAt(i, obj); 1427 result.SetAt(i, *reader->ObjectHandle());
1436 } 1428 }
1437 return result.raw(); 1429 return result.raw();
1438 } 1430 }
1439 1431
1440 1432
1441 RawArray* Array::ReadFrom(SnapshotReader* reader, 1433 RawArray* Array::ReadFrom(SnapshotReader* reader,
1442 intptr_t object_id, 1434 intptr_t object_id,
1443 intptr_t tags, 1435 intptr_t tags,
1444 Snapshot::Kind kind) { 1436 Snapshot::Kind kind) {
1445 return reinterpret_cast<RawArray*>( 1437 return reinterpret_cast<RawArray*>(
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 JSRegExp& regex = JSRegExp::ZoneHandle( 1569 JSRegExp& regex = JSRegExp::ZoneHandle(
1578 reader->isolate(), 1570 reader->isolate(),
1579 JSRegExp::New(len, (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew)); 1571 JSRegExp::New(len, (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew));
1580 reader->AddBackwardReference(object_id, &regex); 1572 reader->AddBackwardReference(object_id, &regex);
1581 1573
1582 // Set the object tags. 1574 // Set the object tags.
1583 regex.set_tags(tags); 1575 regex.set_tags(tags);
1584 1576
1585 // Read and Set all the other fields. 1577 // Read and Set all the other fields.
1586 regex.raw_ptr()->num_bracket_expressions_ = GetSmi(reader->ReadIntptrValue()); 1578 regex.raw_ptr()->num_bracket_expressions_ = GetSmi(reader->ReadIntptrValue());
1587 String& pattern = String::Handle(reader->isolate(), String::null()); 1579 *reader->StringHandle() ^= reader->ReadObject();
1588 pattern ^= reader->ReadObject(); 1580 regex.raw_ptr()->pattern_ = (*reader->StringHandle()).raw();
1589 regex.raw_ptr()->pattern_ = pattern.raw();
1590 regex.raw_ptr()->type_ = reader->ReadIntptrValue(); 1581 regex.raw_ptr()->type_ = reader->ReadIntptrValue();
1591 regex.raw_ptr()->flags_ = reader->ReadIntptrValue(); 1582 regex.raw_ptr()->flags_ = reader->ReadIntptrValue();
1592 1583
1593 // TODO(5411462): Need to implement a way of recompiling the regex. 1584 // TODO(5411462): Need to implement a way of recompiling the regex.
1594 1585
1595 return regex.raw(); 1586 return regex.raw();
1596 } 1587 }
1597 1588
1598 1589
1599 void RawJSRegExp::WriteTo(SnapshotWriter* writer, 1590 void RawJSRegExp::WriteTo(SnapshotWriter* writer,
(...skipping 14 matching lines...) Expand all
1614 // Write out all the other fields. 1605 // Write out all the other fields.
1615 writer->Write<RawObject*>(ptr()->num_bracket_expressions_); 1606 writer->Write<RawObject*>(ptr()->num_bracket_expressions_);
1616 writer->WriteObject(ptr()->pattern_); 1607 writer->WriteObject(ptr()->pattern_);
1617 writer->WriteIntptrValue(ptr()->type_); 1608 writer->WriteIntptrValue(ptr()->type_);
1618 writer->WriteIntptrValue(ptr()->flags_); 1609 writer->WriteIntptrValue(ptr()->flags_);
1619 1610
1620 // Do not write out the data part which is native. 1611 // Do not write out the data part which is native.
1621 } 1612 }
1622 1613
1623 } // namespace dart 1614 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | vm/snapshot.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698