V8 Project
transitions.cc
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "src/v8.h"
6 
7 #include "src/objects.h"
8 #include "src/transitions-inl.h"
9 #include "src/utils.h"
10 
11 namespace v8 {
12 namespace internal {
13 
14 
16  int number_of_transitions) {
17  Handle<FixedArray> array =
18  isolate->factory()->NewFixedArray(ToKeyIndex(number_of_transitions));
20  return Handle<TransitionArray>::cast(array);
21 }
22 
23 
25  Handle<Map> target) {
26  Handle<FixedArray> array =
27  isolate->factory()->NewFixedArray(kSimpleTransitionSize);
28  array->set(kSimpleTransitionTarget, *target);
29  return Handle<TransitionArray>::cast(array);
30 }
31 
32 
34  int origin_transition,
35  int target_transition) {
36  NoIncrementalWriteBarrierSet(target_transition,
37  origin->GetKey(origin_transition),
38  origin->GetTarget(origin_transition));
39 }
40 
41 
42 static bool InsertionPointFound(Name* key1, Name* key2) {
43  return key1->Hash() > key2->Hash();
44 }
45 
46 
49  Handle<Map> target,
52  Isolate* isolate = name->GetIsolate();
53 
54  if (flag == SIMPLE_TRANSITION) {
55  result = AllocateSimple(isolate, target);
56  } else {
57  result = Allocate(isolate, 1);
58  result->NoIncrementalWriteBarrierSet(0, *name, *target);
59  }
60  result->set_back_pointer_storage(map->GetBackPointer());
61  return result;
62 }
63 
64 
66  Handle<Map> containing_map) {
67  DCHECK(!containing_map->transitions()->IsFullTransitionArray());
68  int nof = containing_map->transitions()->number_of_transitions();
69 
70  // A transition array may shrink during GC.
71  Handle<TransitionArray> result = Allocate(containing_map->GetIsolate(), nof);
73  int new_nof = containing_map->transitions()->number_of_transitions();
74  if (new_nof != nof) {
75  DCHECK(new_nof == 0);
76  result->Shrink(ToKeyIndex(0));
77  } else if (nof == 1) {
78  result->NoIncrementalWriteBarrierCopyFrom(
79  containing_map->transitions(), kSimpleTransitionIndex, 0);
80  }
81 
82  result->set_back_pointer_storage(
83  containing_map->transitions()->back_pointer_storage());
84  return result;
85 }
86 
87 
90  Handle<Map> target,
92  if (!map->HasTransitionArray()) {
93  return TransitionArray::NewWith(map, name, target, flag);
94  }
95 
96  int number_of_transitions = map->transitions()->number_of_transitions();
97  int new_size = number_of_transitions;
98 
99  int insertion_index = map->transitions()->Search(*name);
100  if (insertion_index == kNotFound) ++new_size;
101 
102  Handle<TransitionArray> result = Allocate(map->GetIsolate(), new_size);
103 
104  // The map's transition array may grown smaller during the allocation above as
105  // it was weakly traversed, though it is guaranteed not to disappear. Trim the
106  // result copy if needed, and recompute variables.
109  TransitionArray* array = map->transitions();
112 
114  new_size = number_of_transitions;
115 
116  insertion_index = array->Search(*name);
117  if (insertion_index == kNotFound) ++new_size;
118 
119  result->Shrink(ToKeyIndex(new_size));
120  }
121 
122  if (array->HasPrototypeTransitions()) {
123  result->SetPrototypeTransitions(array->GetPrototypeTransitions());
124  }
125 
126  if (insertion_index != kNotFound) {
127  for (int i = 0; i < number_of_transitions; ++i) {
128  if (i != insertion_index) {
129  result->NoIncrementalWriteBarrierCopyFrom(array, i, i);
130  }
131  }
132  result->NoIncrementalWriteBarrierSet(insertion_index, *name, *target);
133  result->set_back_pointer_storage(array->back_pointer_storage());
134  return result;
135  }
136 
137  insertion_index = 0;
138  for (; insertion_index < number_of_transitions; ++insertion_index) {
139  if (InsertionPointFound(array->GetKey(insertion_index), *name)) break;
140  result->NoIncrementalWriteBarrierCopyFrom(
141  array, insertion_index, insertion_index);
142  }
143 
144  result->NoIncrementalWriteBarrierSet(insertion_index, *name, *target);
145 
146  for (; insertion_index < number_of_transitions; ++insertion_index) {
147  result->NoIncrementalWriteBarrierCopyFrom(
148  array, insertion_index, insertion_index + 1);
149  }
150 
151  result->set_back_pointer_storage(array->back_pointer_storage());
152  return result;
153 }
154 
155 
156 } } // namespace v8::internal
static Handle< T > cast(Handle< S > that)
Definition: handles.h:116
Isolate * GetIsolate() const
Definition: objects-inl.h:1387
Factory * factory()
Definition: isolate.h:982
Object * GetBackPointer()
Definition: objects-inl.h:5134
bool HasTransitionArray() const
Definition: objects-inl.h:5150
static Smi * FromInt(int value)
Definition: objects-inl.h:1321
static int ToKeyIndex(int transition_number)
Definition: transitions.h:158
static const int kSimpleTransitionIndex
Definition: transitions.h:127
static Handle< TransitionArray > AllocateSimple(Isolate *isolate, Handle< Map > target)
Definition: transitions.cc:24
static Handle< TransitionArray > ExtendToFullTransitionArray(Handle< Map > containing_map)
Definition: transitions.cc:65
static const int kNotFound
Definition: transitions.h:116
Name * GetKey(int transition_number)
static Handle< TransitionArray > NewWith(Handle< Map > map, Handle< Name > name, Handle< Map > target, SimpleTransitionFlag flag)
Definition: transitions.cc:47
static Handle< TransitionArray > Allocate(Isolate *isolate, int number_of_transitions)
Definition: transitions.cc:15
static const int kSimpleTransitionSize
Definition: transitions.h:126
static const int kSimpleTransitionTarget
Definition: transitions.h:125
Map * GetTarget(int transition_number)
static Handle< TransitionArray > CopyInsert(Handle< Map > map, Handle< Name > name, Handle< Map > target, SimpleTransitionFlag flag)
Definition: transitions.cc:88
FixedArray * GetPrototypeTransitions()
void NoIncrementalWriteBarrierSet(int transition_number, Name *key, Map *target)
static const int kPrototypeTransitionsIndex
Definition: transitions.h:121
void NoIncrementalWriteBarrierCopyFrom(TransitionArray *origin, int origin_transition, int target_transition)
Definition: transitions.cc:33
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf map
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS 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 enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in name
#define DCHECK(condition)
Definition: logging.h:205
SimpleTransitionFlag
Definition: objects.h:277
@ SIMPLE_TRANSITION
Definition: objects.h:278
kFeedbackVectorOffset flag
Definition: objects-inl.h:5418
static bool InsertionPointFound(Name *key1, Name *key2)
Definition: transitions.cc:42
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20