v8  3.14.5(node0.10.28)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
transitions.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #ifndef V8_TRANSITIONS_H_
29 #define V8_TRANSITIONS_H_
30 
31 #include "elements-kind.h"
32 #include "heap.h"
33 #include "isolate.h"
34 #include "objects.h"
35 #include "v8checks.h"
36 
37 namespace v8 {
38 namespace internal {
39 
40 
41 // TransitionArrays are fixed arrays used to hold map transitions for property,
42 // constant, and element changes. They can either be simple transition arrays
43 // that store a single property transition, or a full transition array that has
44 // space for elements transitions, prototype transitions and multiple property
45 // transitons. The details related to property transitions are accessed in the
46 // descriptor array of the target map. In the case of a simple transition, the
47 // key is also read from the descriptor array of the target map.
48 //
49 // The simple format of the these objects is:
50 // [0] Undefined or back pointer map
51 // [1] Single transition
52 //
53 // The full format is:
54 // [0] Undefined or back pointer map
55 // [1] Smi(0) or elements transition map
56 // [2] Smi(0) or fixed array of prototype transitions
57 // [3] First transition
58 // [length() - kTransitionSize] Last transition
59 class TransitionArray: public FixedArray {
60  public:
61  // Accessors for fetching instance transition at transition number.
62  inline String* GetKey(int transition_number);
63  inline void SetKey(int transition_number, String* value);
64  inline Object** GetKeySlot(int transition_number);
65  int GetSortedKeyIndex(int transition_number) { return transition_number; }
66 
67  String* GetSortedKey(int transition_number) {
68  return GetKey(transition_number);
69  }
70 
71  inline Map* GetTarget(int transition_number);
72  inline void SetTarget(int transition_number, Map* target);
73 
74  inline PropertyDetails GetTargetDetails(int transition_number);
75 
76  inline Map* elements_transition();
77  inline void set_elements_transition(
78  Map* target,
80  inline bool HasElementsTransition();
81  inline void ClearElementsTransition();
82 
83  inline Object* back_pointer_storage();
84  inline void set_back_pointer_storage(
85  Object* back_pointer,
87 
89  inline void SetPrototypeTransitions(
90  FixedArray* prototype_transitions,
93  inline bool HasPrototypeTransitions();
95 
96  // Returns the number of transitions in the array.
98  if (IsSimpleTransition()) return 1;
99  int len = length();
100  return len <= kFirstIndex ? 0 : (len - kFirstIndex) / kTransitionSize;
101  }
102 
103  inline int number_of_entries() { return number_of_transitions(); }
104 
105  // Allocate a new transition array with a single entry.
106  static MUST_USE_RESULT MaybeObject* NewWith(
108  String* key,
109  Map* target,
110  Object* back_pointer);
111 
113 
114  // Copy the transition array, inserting a new transition.
115  // TODO(verwaest): This should not cause an existing transition to be
116  // overwritten.
117  MUST_USE_RESULT MaybeObject* CopyInsert(String* name, Map* target);
118 
119  // Copy a single transition from the origin array.
121  int origin_transition,
122  int target_transition);
123 
124  // Search a transition for a given property name.
125  inline int Search(String* name);
126 
127  // Allocates a TransitionArray.
128  MUST_USE_RESULT static MaybeObject* Allocate(int number_of_transitions);
129 
131  bool IsFullTransitionArray() { return length() >= kFirstIndex; }
132 
133  // Casting.
134  static inline TransitionArray* cast(Object* obj);
135 
136  // Constant for denoting key was not found.
137  static const int kNotFound = -1;
138 
139  static const int kBackPointerStorageIndex = 0;
140 
141  // Layout for full transition arrays.
142  static const int kElementsTransitionIndex = 1;
143  static const int kPrototypeTransitionsIndex = 2;
144  static const int kFirstIndex = 3;
145 
146  // Layout for simple transition arrays.
147  static const int kSimpleTransitionTarget = 1;
148  static const int kSimpleTransitionSize = 2;
149  static const int kSimpleTransitionIndex = 0;
151 
153 
154  // Layout for the full transition array header.
156  kPointerSize;
158  kPointerSize;
159 
160  // Layout of map transition entries in full transition arrays.
161  static const int kTransitionKey = 0;
162  static const int kTransitionTarget = 1;
163  static const int kTransitionSize = 2;
164 
165 #ifdef OBJECT_PRINT
166  // Print all the transitions.
167  inline void PrintTransitions() {
168  PrintTransitions(stdout);
169  }
170  void PrintTransitions(FILE* out);
171 #endif
172 
173 #ifdef DEBUG
174  bool IsSortedNoDuplicates(int valid_entries = -1);
175  bool IsConsistentWithBackPointers(Map* current_map);
176  bool IsEqualTo(TransitionArray* other);
177 #endif
178 
179  // The maximum number of transitions we want in a transition array (should
180  // fit in a page).
181  static const int kMaxNumberOfTransitions = 1024 + 512;
182 
183  private:
184  // Conversion from transition number to array indices.
185  static int ToKeyIndex(int transition_number) {
186  return kFirstIndex +
187  (transition_number * kTransitionSize) +
189  }
190 
191  static int ToTargetIndex(int transition_number) {
192  return kFirstIndex +
193  (transition_number * kTransitionSize) +
195  }
196 
197  inline void NoIncrementalWriteBarrierSet(int transition_number,
198  String* key,
199  Map* target);
200 
201  DISALLOW_IMPLICIT_CONSTRUCTORS(TransitionArray);
202 };
203 
204 
205 } } // namespace v8::internal
206 
207 #endif // V8_TRANSITIONS_H_
static MUST_USE_RESULT MaybeObject * Allocate(int number_of_transitions)
Definition: transitions.cc:49
STATIC_ASSERT(kSimpleTransitionIndex!=kNotFound)
HeapObject * UncheckedPrototypeTransitions()
static const int kElementsTransitionOffset
Definition: transitions.h:155
static const int kPrototypeTransitionsIndex
Definition: transitions.h:143
void SetKey(int transition_number, String *value)
static const int kElementsTransitionIndex
Definition: transitions.h:142
void NoIncrementalWriteBarrierCopyFrom(TransitionArray *origin, int origin_transition, int target_transition)
Definition: transitions.cc:59
static const int kSimpleTransitionTarget
Definition: transitions.h:147
static const int kTransitionSize
Definition: transitions.h:163
#define MUST_USE_RESULT
Definition: globals.h:346
static const int kNotFound
Definition: transitions.h:137
const int kPointerSize
Definition: globals.h:220
void SetPrototypeTransitions(FixedArray *prototype_transitions, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
MUST_USE_RESULT MaybeObject * CopyInsert(String *name, Map *target)
Definition: transitions.cc:110
static const int kTransitionKey
Definition: transitions.h:161
static const int kSimpleTransitionIndex
Definition: transitions.h:149
String * GetKey(int transition_number)
static TransitionArray * cast(Object *obj)
static const int kBackPointerStorageOffset
Definition: transitions.h:152
static const int kHeaderSize
Definition: objects.h:2296
SimpleTransitionFlag
Definition: objects.h:184
static MUST_USE_RESULT MaybeObject * NewWith(SimpleTransitionFlag flag, String *key, Map *target, Object *back_pointer)
Definition: transitions.cc:73
static const int kSimpleTransitionSize
Definition: transitions.h:148
static const int kTransitionTarget
Definition: transitions.h:162
Map * GetTarget(int transition_number)
static const int kFirstIndex
Definition: transitions.h:144
static const int kBackPointerStorageIndex
Definition: transitions.h:139
void set_back_pointer_storage(Object *back_pointer, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
FixedArray * GetPrototypeTransitions()
static const int kMaxNumberOfTransitions
Definition: transitions.h:181
static const int kPrototypeTransitionsOffset
Definition: transitions.h:157
String * GetSortedKey(int transition_number)
Definition: transitions.h:67
void set_elements_transition(Map *target, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
Object ** GetKeySlot(int transition_number)
void SetTarget(int transition_number, Map *target)
MUST_USE_RESULT MaybeObject * ExtendToFullTransitionArray()
Definition: transitions.cc:94
PropertyDetails GetTargetDetails(int transition_number)
int GetSortedKeyIndex(int transition_number)
Definition: transitions.h:65
kPropertyAccessorsOffset kNamedPropertyHandlerOffset kInstanceTemplateOffset kAccessCheckInfoOffset kEvalFrominstructionsOffsetOffset kInstanceClassNameOffset flag
Definition: objects-inl.h:3923