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.cc
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 #include "v8.h"
29 
30 #include "objects.h"
31 #include "transitions-inl.h"
32 #include "utils.h"
33 
34 namespace v8 {
35 namespace internal {
36 
37 
38 static MaybeObject* AllocateRaw(Isolate* isolate, int length) {
39  // Use FixedArray to not use TransitionArray::cast on incomplete object.
40  FixedArray* array;
41  MaybeObject* maybe_array = isolate->heap()->AllocateFixedArray(length);
42  if (!maybe_array->To(&array)) return maybe_array;
43  return array;
44 }
45 
46 
47 MaybeObject* TransitionArray::Allocate(Isolate* isolate,
48  int number_of_transitions) {
49  FixedArray* array;
50  MaybeObject* maybe_array =
51  AllocateRaw(isolate, ToKeyIndex(number_of_transitions));
52  if (!maybe_array->To(&array)) return maybe_array;
54  return array;
55 }
56 
57 
59  int origin_transition,
60  int target_transition) {
61  NoIncrementalWriteBarrierSet(target_transition,
62  origin->GetKey(origin_transition),
63  origin->GetTarget(origin_transition));
64 }
65 
66 
67 static bool InsertionPointFound(Name* key1, Name* key2) {
68  return key1->Hash() > key2->Hash();
69 }
70 
71 
73  Name* key,
74  Map* target,
75  Object* back_pointer) {
76  TransitionArray* result;
77  MaybeObject* maybe_result;
78 
79  if (flag == SIMPLE_TRANSITION) {
80  maybe_result = AllocateRaw(target->GetIsolate(), kSimpleTransitionSize);
81  if (!maybe_result->To(&result)) return maybe_result;
82  result->set(kSimpleTransitionTarget, target);
83  } else {
84  maybe_result = Allocate(target->GetIsolate(), 1);
85  if (!maybe_result->To(&result)) return maybe_result;
86  result->NoIncrementalWriteBarrierSet(0, key, target);
87  }
88  result->set_back_pointer_storage(back_pointer);
89  return result;
90 }
91 
92 
95  int nof = number_of_transitions();
96  TransitionArray* result;
97  MaybeObject* maybe_result = Allocate(GetIsolate(), nof);
98  if (!maybe_result->To(&result)) return maybe_result;
99 
100  if (nof == 1) {
102  }
103 
105  return result;
106 }
107 
108 
109 MaybeObject* TransitionArray::CopyInsert(Name* name, Map* target) {
110  TransitionArray* result;
111 
113  int new_size = number_of_transitions;
114 
115  int insertion_index = this->Search(name);
116  if (insertion_index == kNotFound) ++new_size;
117 
118  MaybeObject* maybe_array;
119  maybe_array = TransitionArray::Allocate(GetIsolate(), new_size);
120  if (!maybe_array->To(&result)) return maybe_array;
121 
122  if (HasPrototypeTransitions()) {
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(this, i, i);
130  }
131  }
132  result->NoIncrementalWriteBarrierSet(insertion_index, name, target);
134  return result;
135  }
136 
137  insertion_index = 0;
138  for (; insertion_index < number_of_transitions; ++insertion_index) {
139  if (InsertionPointFound(GetKey(insertion_index), name)) break;
141  this, insertion_index, insertion_index);
142  }
143 
144  result->NoIncrementalWriteBarrierSet(insertion_index, name, target);
145 
146  for (; insertion_index < number_of_transitions; ++insertion_index) {
148  this, insertion_index, insertion_index + 1);
149  }
150 
152  return result;
153 }
154 
155 
156 } } // namespace v8::internal
void set(int index, Object *value)
Definition: objects-inl.h:2147
static Smi * FromInt(int value)
Definition: objects-inl.h:1209
static const int kPrototypeTransitionsIndex
Definition: transitions.h:150
#define ASSERT(condition)
Definition: checks.h:329
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 kNotFound
Definition: transitions.h:145
void SetPrototypeTransitions(FixedArray *prototype_transitions, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
static const int kSimpleTransitionIndex
Definition: transitions.h:156
static MUST_USE_RESULT MaybeObject * Allocate(Isolate *isolate, int number_of_transitions)
Definition: transitions.cc:47
SimpleTransitionFlag
Definition: objects.h:282
static const int kSimpleTransitionSize
Definition: transitions.h:155
Map * GetTarget(int transition_number)
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()
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
MUST_USE_RESULT MaybeObject * ExtendToFullTransitionArray()
Definition: transitions.cc:93