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

Side by Side Diff: runtime/vm/object.cc

Issue 635393002: Fix Object::Clone. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 2 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
« runtime/vm/object.h ('K') | « runtime/vm/object.h ('k') | no next file » | 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) 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/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/cpu.h" 10 #include "vm/cpu.h"
(...skipping 1722 matching lines...) Expand 10 before | Expand all | Expand 10 after
1733 return Dart::IsReadOnlyHandle(reinterpret_cast<uword>(this)); 1733 return Dart::IsReadOnlyHandle(reinterpret_cast<uword>(this));
1734 } 1734 }
1735 1735
1736 1736
1737 bool Object::IsNotTemporaryScopedHandle() const { 1737 bool Object::IsNotTemporaryScopedHandle() const {
1738 return (IsZoneHandle() || IsReadOnlyHandle()); 1738 return (IsZoneHandle() || IsReadOnlyHandle());
1739 } 1739 }
1740 1740
1741 1741
1742 1742
1743 RawObject* Object::Clone(const Object& src, Heap::Space space) { 1743 RawObject* Object::Clone(const Object& orig, Heap::Space space) {
1744 const Class& cls = Class::Handle(src.clazz()); 1744 const Class& cls = Class::Handle(orig.clazz());
1745 intptr_t size = src.raw()->Size(); 1745 intptr_t size = orig.raw()->Size();
1746 RawObject* raw_obj = Object::Allocate(cls.id(), size, space); 1746 RawObject* raw_clone = Object::Allocate(cls.id(), size, space);
1747 NoGCScope no_gc; 1747 NoGCScope no_gc;
1748 // Newly allocated objects are white ...
1749 // TODO(koda): This will trip when we start allocating black. 1748 // TODO(koda): This will trip when we start allocating black.
1750 // Update unmarking code below at that point. 1749 // Revisit code below at that point, to account for the new write barrier.
1751 ASSERT(!raw_obj->IsMarked()); 1750 ASSERT(!raw_clone->IsMarked());
1752 memmove(raw_obj->ptr(), src.raw()->ptr(), size); 1751 // Copy the body of the original into the clone.
1753 // ... so ensure clone is too (see issue 21236). 1752 uword orig_addr = RawObject::ToAddr(orig.raw());
1754 if (raw_obj->IsMarked()) { 1753 uword clone_addr = RawObject::ToAddr(raw_clone);
1755 raw_obj->ClearMarkBit(); 1754 static const intptr_t kHeaderSizeInBytes = sizeof(RawObject);
1755 memmove(reinterpret_cast<uint8_t*>(clone_addr + kHeaderSizeInBytes),
1756 reinterpret_cast<uint8_t*>(orig_addr + kHeaderSizeInBytes),
1757 size - kHeaderSizeInBytes);
1758 // Add clone to store buffer, if needed.
1759 if (!raw_clone->IsOldObject()) {
1760 // No need to remember an object in new space.
1761 return raw_clone;
1762 } else if (orig.raw()->IsOldObject() && !orig.raw()->IsRemembered()) {
1763 // Old original doesn't need to be remembered, so neither does the clone.
1764 return raw_clone;
1756 } 1765 }
1757 if ((space == Heap::kOld) && !raw_obj->IsRemembered()) { 1766 StoreBufferUpdateVisitor visitor(Isolate::Current(), raw_clone);
1758 StoreBufferUpdateVisitor visitor(Isolate::Current(), raw_obj); 1767 raw_clone->VisitPointers(&visitor);
1759 raw_obj->VisitPointers(&visitor); 1768 return raw_clone;
1760 }
1761 return raw_obj;
1762 } 1769 }
1763 1770
1764 1771
1765 RawString* Class::Name() const { 1772 RawString* Class::Name() const {
1766 // TODO(turnidge): This assert fails for the fake kFreeListElement class. 1773 // TODO(turnidge): This assert fails for the fake kFreeListElement class.
1767 // Fix this. 1774 // Fix this.
1768 ASSERT(raw_ptr()->name_ != String::null()); 1775 ASSERT(raw_ptr()->name_ != String::null());
1769 return raw_ptr()->name_; 1776 return raw_ptr()->name_;
1770 } 1777 }
1771 1778
(...skipping 18543 matching lines...) Expand 10 before | Expand all | Expand 10 after
20315 return tag_label.ToCString(); 20322 return tag_label.ToCString();
20316 } 20323 }
20317 20324
20318 20325
20319 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { 20326 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const {
20320 Instance::PrintJSONImpl(stream, ref); 20327 Instance::PrintJSONImpl(stream, ref);
20321 } 20328 }
20322 20329
20323 20330
20324 } // namespace dart 20331 } // namespace dart
OLDNEW
« runtime/vm/object.h ('K') | « runtime/vm/object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698