Flutter Engine
The Flutter Engine
become.h
Go to the documentation of this 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
3// BSD-style license that can be found in the LICENSE file.
4
5#ifndef RUNTIME_VM_HEAP_BECOME_H_
6#define RUNTIME_VM_HEAP_BECOME_H_
7
8#include "platform/atomic.h"
10#include "vm/allocation.h"
11#include "vm/raw_object.h"
12
13namespace dart {
14
15class Array;
16
17// Objects that are a source in a become are transformed into forwarding
18// corpses pointing to the corresponding target. Forwarding corpses have the
19// same heap sizes as the source object to ensure the heap remains walkable.
20// If the heap sizes is small enough to be encoded in the size field of the
21// header, a forwarding corpse consists only of a header and the target pointer.
22// If the heap size is too big to be encoded in the header's size field, the
23// word after the target pointer contains the size. This is the same
24// representation as a FreeListElement.
26 public:
27 ObjectPtr target() const { return target_; }
28 void set_target(ObjectPtr target) { target_ = target; }
29
30 intptr_t HeapSize() { return HeapSize(tags_); }
31 intptr_t HeapSize(uword tags) {
33 if (size != 0) return size;
34 return *SizeAddress();
35 }
36
37 static ForwardingCorpse* AsForwarder(uword addr, intptr_t size);
38
39 static void Init();
40
41 // Used to allocate class for forwarding corpses in Object::InitOnce.
43 public:
45 static cpp_vtable vtable() { return 0; }
46 static intptr_t InstanceSize() { return 0; }
47 static intptr_t NextFieldOffset() { return -kWordSize; }
49 static bool IsInstance() { return true; }
50
51 private:
52 DISALLOW_ALLOCATION();
53 DISALLOW_COPY_AND_ASSIGN(FakeInstance);
54 };
55
56 private:
57 // This layout mirrors the layout of UntaggedObject.
60
61 // Returns the address of the embedded size.
62 intptr_t* SizeAddress() const {
63 uword addr = reinterpret_cast<uword>(&target_) + kWordSize;
64 return reinterpret_cast<intptr_t*>(addr);
65 }
66
67 // ForwardingCorpses cannot be allocated. Instead references to them are
68 // created using the AsForwarder factory method.
69 DISALLOW_ALLOCATION();
70 DISALLOW_IMPLICIT_CONSTRUCTORS(ForwardingCorpse);
71};
72
73// Forward/exchange object identity within pairs of objects.
74//
75// Forward: Redirects all pointers to each 'before' object to the corresponding
76// 'after' object. Every 'before' object is guaranteed to be unreachable after
77// the operation. The identity hash of the 'before' object is retained.
78//
79// This is useful for atomically applying behavior and schema changes, which can
80// be done by allocating fresh objects with the new schema and forwarding the
81// identity of the old objects to the new objects.
82//
83// Exchange: Redirect all pointers to each 'before' object to the corresponding
84// 'after' object and vice versa. Both objects remain reachable after the
85// operation.
86//
87// This is useful for implementing certain types of proxies. For example, an
88// infrequently accessed object may be written to disk and swapped with a
89// so-called "husk", and swapped back when it is later accessed.
90//
91// This operation is named 'become' after its original in Smalltalk:
92// x become: y "exchange identity for one pair"
93// x becomeForward: y "forward identity for one pair"
94// #(x ...) elementsExchangeIdentityWith: #(y ...)
95// #(x ...) elementsForwardIdentityTo: #(y ...)
96class Become {
97 public:
98 Become();
99 ~Become();
100
101 void Add(const Object& before, const Object& after);
102 void Forward();
104
106
107 // Convert and instance object into a dummy object,
108 // making the instance independent of its class.
109 // (used for morphic instances during reload).
110 static void MakeDummyObject(const Instance& instance);
111
112 // Update any references pointing to forwarding objects to point the
113 // forwarding objects' targets.
114 static void FollowForwardingPointers(Thread* thread);
115
116 private:
118 DISALLOW_COPY_AND_ASSIGN(Become);
119};
120
121} // namespace dart
122
123#endif // RUNTIME_VM_HEAP_BECOME_H_
static void FollowForwardingPointers(Thread *thread)
Definition: become.cc:330
static void MakeDummyObject(const Instance &instance)
Definition: become.cc:242
void VisitObjectPointers(ObjectPointerVisitor *visitor)
Definition: become.cc:236
void Add(const Object &before, const Object &after)
Definition: become.cc:231
void Exchange()
Definition: become.h:103
void Forward()
Definition: become.cc:275
static intptr_t InstanceSize()
Definition: become.h:46
static const ClassId kClassId
Definition: become.h:48
static cpp_vtable vtable()
Definition: become.h:45
static intptr_t NextFieldOffset()
Definition: become.h:47
static ForwardingCorpse * AsForwarder(uword addr, intptr_t size)
Definition: become.cc:20
void set_target(ObjectPtr target)
Definition: become.h:28
intptr_t HeapSize(uword tags)
Definition: become.h:31
intptr_t HeapSize()
Definition: become.h:30
static void Init()
Definition: become.cc:42
ObjectPtr target() const
Definition: become.h:27
static constexpr uword decode(uword tag)
Definition: raw_object.h:208
#define UNIMPLEMENTED
VkInstance instance
Definition: main.cc:48
Definition: dart_vm.cc:33
uword cpp_vtable
Definition: globals.h:163
ClassId
Definition: class_id.h:212
@ kForwardingCorpse
Definition: class_id.h:225
uintptr_t uword
Definition: globals.h:501
constexpr intptr_t kWordSize
Definition: globals.h:509
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259