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

Side by Side Diff: runtime/vm/become.h

Issue 2026643004: Don't overload FreeListElement for become. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « no previous file | runtime/vm/become.cc » ('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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 #ifndef VM_BECOME_H_ 5 #ifndef VM_BECOME_H_
6 #define VM_BECOME_H_ 6 #define VM_BECOME_H_
7 7
8 #include "vm/allocation.h" 8 #include "vm/allocation.h"
9 #include "vm/raw_object.h"
9 10
10 namespace dart { 11 namespace dart {
11 12
12 class Array; 13 class Array;
13 14
15 // Objects that are a source in a become are tranformed into forwarding
16 // corpses pointing to the corresponding target. Forwarding corpses have the
17 // same heap sizes as the source object to ensure the heap remains walkable.
18 // If the heap sizes is small enough to be encoded in the size field of the
19 // header, a forwarding corpse consists only of a header and the target pointer.
20 // If the heap size is too big to be encoded in the header's size field, the
21 // word after the target pointer contains the size. This is the same
22 // representation as a FreeListElement.
23 class ForwardingCorpse {
24 public:
25 RawObject* target() const {
26 return target_;
27 }
28 void set_target(RawObject* target) {
29 target_ = target;
30 }
31
32 intptr_t Size() {
33 intptr_t size = RawObject::SizeTag::decode(tags_);
34 if (size != 0) return size;
35 return *SizeAddress();
36 }
37
38 static ForwardingCorpse* AsForwarder(uword addr, intptr_t size);
39
40 static void InitOnce();
41
42 // Used to allocate class for forwarding corpses in Object::InitOnce.
43 class FakeInstance {
44 public:
45 FakeInstance() { }
46 static cpp_vtable vtable() { return 0; }
47 static intptr_t InstanceSize() { return 0; }
48 static intptr_t NextFieldOffset() { return -kWordSize; }
49 static const ClassId kClassId = kForwardingCorpse;
50 static bool IsInstance() { return true; }
51
52 private:
53 DISALLOW_ALLOCATION();
54 DISALLOW_COPY_AND_ASSIGN(FakeInstance);
55 };
56
57 private:
58 // This layout mirrors the layout of RawObject.
59 uword tags_;
60 RawObject* target_;
61
62 // Returns the address of the embedded size.
63 intptr_t* SizeAddress() const {
64 uword addr = reinterpret_cast<uword>(&target_) + kWordSize;
65 return reinterpret_cast<intptr_t*>(addr);
66 }
67
68 // ForwardingCorpses cannot be allocated. Instead references to them are
69 // created using the AsForwarder factory method.
70 DISALLOW_ALLOCATION();
71 DISALLOW_IMPLICIT_CONSTRUCTORS(ForwardingCorpse);
72 };
73
14 // TODO(johnmccutchan): Refactor this class so that it is not all static and 74 // TODO(johnmccutchan): Refactor this class so that it is not all static and
15 // provides utility methods for building the mapping of before and after. 75 // provides utility methods for building the mapping of before and after.
16 class Become : public AllStatic { 76 class Become : public AllStatic {
17 public: 77 public:
18 // Smalltalk's one-way bulk become (Array>>#elementsForwardIdentityTo:). 78 // Smalltalk's one-way bulk become (Array>>#elementsForwardIdentityTo:).
19 // Redirects all pointers to elements of 'before' to the corresponding element 79 // Redirects all pointers to elements of 'before' to the corresponding element
20 // in 'after'. Every element in 'before' is guaranteed to be not reachable. 80 // in 'after'. Every element in 'before' is guaranteed to be not reachable.
21 // Useful for atomically applying behavior and schema changes. 81 // Useful for atomically applying behavior and schema changes.
22 static void ElementsForwardIdentity(const Array& before, const Array& after); 82 static void ElementsForwardIdentity(const Array& before, const Array& after);
23 }; 83 };
24 84
25 } // namespace dart 85 } // namespace dart
26 86
27 #endif // VM_BECOME_H_ 87 #endif // VM_BECOME_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/become.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698