v8  3.25.30(node0.11.13)
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 // prototype transitions and multiple property transitons. The details related
45 // to property transitions are accessed in the descriptor array of the target
46 // map. In the case of a simple transition, the key is also read from the
47 // 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 fixed array of prototype transitions
56 // [2] First transition
57 // [length() - kTransitionSize] Last transition
58 class TransitionArray: public FixedArray {
59  public:
60  // Accessors for fetching instance transition at transition number.
61  inline Name* GetKey(int transition_number);
62  inline void SetKey(int transition_number, Name* value);
63  inline Object** GetKeySlot(int transition_number);
64  int GetSortedKeyIndex(int transition_number) { return transition_number; }
65 
66  Name* GetSortedKey(int transition_number) {
67  return GetKey(transition_number);
68  }
69 
70  inline Map* GetTarget(int transition_number);
71  inline void SetTarget(int transition_number, Map* target);
72 
73  inline PropertyDetails GetTargetDetails(int transition_number);
74 
75  inline bool HasElementsTransition();
76 
77  inline Object* back_pointer_storage();
78  inline void set_back_pointer_storage(
79  Object* back_pointer,
81 
83  inline void SetPrototypeTransitions(
84  FixedArray* prototype_transitions,
87  inline bool HasPrototypeTransitions();
89 
90  // Returns the number of transitions in the array.
92  if (IsSimpleTransition()) return 1;
93  int len = length();
94  return len <= kFirstIndex ? 0 : (len - kFirstIndex) / kTransitionSize;
95  }
96 
97  inline int number_of_entries() { return number_of_transitions(); }
98 
99  // Allocate a new transition array with a single entry.
100  static MUST_USE_RESULT MaybeObject* NewWith(
102  Name* key,
103  Map* target,
104  Object* back_pointer);
105 
107 
108  // Copy the transition array, inserting a new transition.
109  // TODO(verwaest): This should not cause an existing transition to be
110  // overwritten.
111  MUST_USE_RESULT MaybeObject* CopyInsert(Name* name, Map* target);
112 
113  // Copy a single transition from the origin array.
115  int origin_transition,
116  int target_transition);
117 
118  // Search a transition for a given property name.
119  inline int Search(Name* name);
120 
121  // Allocates a TransitionArray.
122  MUST_USE_RESULT static MaybeObject* Allocate(
123  Isolate* isolate, int number_of_transitions);
124 
126  return length() == kSimpleTransitionSize &&
127  get(kSimpleTransitionTarget)->IsHeapObject() &&
128  // The IntrusivePrototypeTransitionIterator may have set the map of the
129  // prototype transitions array to a smi. In that case, there are
130  // prototype transitions, hence this transition array is a full
131  // transition array.
132  HeapObject::cast(get(kSimpleTransitionTarget))->map()->IsMap() &&
133  get(kSimpleTransitionTarget)->IsMap();
134  }
135 
137  return length() > kFirstIndex ||
139  }
140 
141  // Casting.
142  static inline TransitionArray* cast(Object* obj);
143 
144  // Constant for denoting key was not found.
145  static const int kNotFound = -1;
146 
147  static const int kBackPointerStorageIndex = 0;
148 
149  // Layout for full transition arrays.
150  static const int kPrototypeTransitionsIndex = 1;
151  static const int kFirstIndex = 2;
152 
153  // Layout for simple transition arrays.
154  static const int kSimpleTransitionTarget = 1;
155  static const int kSimpleTransitionSize = 2;
156  static const int kSimpleTransitionIndex = 0;
158 
160 
161  // Layout for the full transition array header.
163  kPointerSize;
164 
165  // Layout of map transition entries in full transition arrays.
166  static const int kTransitionKey = 0;
167  static const int kTransitionTarget = 1;
168  static const int kTransitionSize = 2;
169 
170 #ifdef OBJECT_PRINT
171  // Print all the transitions.
172  inline void PrintTransitions() {
173  PrintTransitions(stdout);
174  }
175  void PrintTransitions(FILE* out);
176 #endif
177 
178 #ifdef DEBUG
179  bool IsSortedNoDuplicates(int valid_entries = -1);
180  bool IsConsistentWithBackPointers(Map* current_map);
181  bool IsEqualTo(TransitionArray* other);
182 #endif
183 
184  // The maximum number of transitions we want in a transition array (should
185  // fit in a page).
186  static const int kMaxNumberOfTransitions = 1024 + 512;
187 
188  private:
189  // Conversion from transition number to array indices.
190  static int ToKeyIndex(int transition_number) {
191  return kFirstIndex +
192  (transition_number * kTransitionSize) +
194  }
195 
196  static int ToTargetIndex(int transition_number) {
197  return kFirstIndex +
198  (transition_number * kTransitionSize) +
200  }
201 
202  inline void NoIncrementalWriteBarrierSet(int transition_number,
203  Name* key,
204  Map* target);
205 
206  DISALLOW_IMPLICIT_CONSTRUCTORS(TransitionArray);
207 };
208 
209 
210 } } // namespace v8::internal
211 
212 #endif // V8_TRANSITIONS_H_
STATIC_ASSERT(kSimpleTransitionIndex!=kNotFound)
static HeapObject * cast(Object *obj)
HeapObject * UncheckedPrototypeTransitions()
static const int kPrototypeTransitionsIndex
Definition: transitions.h:150
void NoIncrementalWriteBarrierCopyFrom(TransitionArray *origin, int origin_transition, int target_transition)
Definition: transitions.cc:58
static const int kSimpleTransitionTarget
Definition: transitions.h:154
Name * GetKey(int transition_number)
static MUST_USE_RESULT MaybeObject * NewWith(SimpleTransitionFlag flag, Name *key, Map *target, Object *back_pointer)
Definition: transitions.cc:72
kInstanceClassNameOffset flag
Definition: objects-inl.h:5115
static const int kTransitionSize
Definition: transitions.h:168
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long mode(MIPS only)") DEFINE_string(expose_natives_as
#define MUST_USE_RESULT
Definition: globals.h:381
static const int kNotFound
Definition: transitions.h:145
const int kPointerSize
Definition: globals.h:268
void SetPrototypeTransitions(FixedArray *prototype_transitions, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
static const int kTransitionKey
Definition: transitions.h:166
static const int kSimpleTransitionIndex
Definition: transitions.h:156
static MUST_USE_RESULT MaybeObject * Allocate(Isolate *isolate, int number_of_transitions)
Definition: transitions.cc:47
static TransitionArray * cast(Object *obj)
static const int kBackPointerStorageOffset
Definition: transitions.h:159
static const int kHeaderSize
Definition: objects.h:3016
SimpleTransitionFlag
Definition: objects.h:282
static const int kSimpleTransitionSize
Definition: transitions.h:155
static const int kTransitionTarget
Definition: transitions.h:167
Map * GetTarget(int transition_number)
static const int kFirstIndex
Definition: transitions.h:151
static const int kBackPointerStorageIndex
Definition: transitions.h:147
void set_back_pointer_storage(Object *back_pointer, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
MUST_USE_RESULT MaybeObject * CopyInsert(Name *name, Map *target)
Definition: transitions.cc:109
FixedArray * GetPrototypeTransitions()
HeapObject * obj
static const int kMaxNumberOfTransitions
Definition: transitions.h:186
static const int kPrototypeTransitionsOffset
Definition: transitions.h:162
Object ** GetKeySlot(int transition_number)
void SetKey(int transition_number, Name *value)
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long expose natives in global object expose freeBuffer extension expose gc extension under the specified name expose externalize string extension number of stack frames to capture disable builtin natives files print name of functions for which code is generated use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations always try to OSR functions trace optimize function deoptimization minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions trace debugging JSON request response trace out of bounds accesses to external arrays trace_js_array_abuse automatically set the debug break flag when debugger commands are in the queue abort by crashing maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print statistics of the maximum memory committed for the heap in name
Definition: flags.cc:505
void SetTarget(int transition_number, Map *target)
Name * GetSortedKey(int transition_number)
Definition: transitions.h:66
MUST_USE_RESULT MaybeObject * ExtendToFullTransitionArray()
Definition: transitions.cc:93
PropertyDetails GetTargetDetails(int transition_number)
int GetSortedKeyIndex(int transition_number)
Definition: transitions.h:64