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.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(int length) {
39  Heap* heap = Isolate::Current()->heap();
40 
41  // Use FixedArray to not use TransitionArray::cast on incomplete object.
42  FixedArray* array;
43  MaybeObject* maybe_array = heap->AllocateFixedArray(length);
44  if (!maybe_array->To(&array)) return maybe_array;
45  return array;
46 }
47 
48 
49 MaybeObject* TransitionArray::Allocate(int number_of_transitions) {
50  FixedArray* array;
51  MaybeObject* maybe_array = AllocateRaw(ToKeyIndex(number_of_transitions));
52  if (!maybe_array->To(&array)) return maybe_array;
55  return array;
56 }
57 
58 
60  int origin_transition,
61  int target_transition) {
62  NoIncrementalWriteBarrierSet(target_transition,
63  origin->GetKey(origin_transition),
64  origin->GetTarget(origin_transition));
65 }
66 
67 
68 static bool InsertionPointFound(String* key1, String* key2) {
69  return key1->Hash() > key2->Hash();
70 }
71 
72 
74  String* key,
75  Map* target,
76  Object* back_pointer) {
77  TransitionArray* result;
78  MaybeObject* maybe_result;
79 
80  if (flag == SIMPLE_TRANSITION) {
81  maybe_result = AllocateRaw(kSimpleTransitionSize);
82  if (!maybe_result->To(&result)) return maybe_result;
83  result->set(kSimpleTransitionTarget, target);
84  } else {
85  maybe_result = Allocate(1);
86  if (!maybe_result->To(&result)) return maybe_result;
87  result->NoIncrementalWriteBarrierSet(0, key, target);
88  }
89  result->set_back_pointer_storage(back_pointer);
90  return result;
91 }
92 
93 
96  int nof = number_of_transitions();
97  TransitionArray* result;
98  MaybeObject* maybe_result = Allocate(nof);
99  if (!maybe_result->To(&result)) return maybe_result;
100 
101  if (nof == 1) {
103  }
104 
106  return result;
107 }
108 
109 
110 MaybeObject* TransitionArray::CopyInsert(String* name, Map* target) {
111  TransitionArray* result;
112 
114  int new_size = number_of_transitions;
115 
116  int insertion_index = this->Search(name);
117  if (insertion_index == kNotFound) ++new_size;
118 
119  MaybeObject* maybe_array;
120  maybe_array = TransitionArray::Allocate(new_size);
121  if (!maybe_array->To(&result)) return maybe_array;
122 
123  if (HasElementsTransition()) {
125  }
126 
127  if (HasPrototypeTransitions()) {
129  }
130 
131  if (insertion_index != kNotFound) {
132  for (int i = 0; i < number_of_transitions; ++i) {
133  if (i != insertion_index) {
134  result->NoIncrementalWriteBarrierCopyFrom(this, i, i);
135  }
136  }
137  result->NoIncrementalWriteBarrierSet(insertion_index, name, target);
138  return result;
139  }
140 
141  insertion_index = 0;
142  for (; insertion_index < number_of_transitions; ++insertion_index) {
143  if (InsertionPointFound(GetKey(insertion_index), name)) break;
145  this, insertion_index, insertion_index);
146  }
147 
148  result->NoIncrementalWriteBarrierSet(insertion_index, name, target);
149 
150  for (; insertion_index < number_of_transitions; ++insertion_index) {
152  this, insertion_index, insertion_index + 1);
153  }
154 
156  return result;
157 }
158 
159 
160 } } // namespace v8::internal
void set(int index, Object *value)
Definition: objects-inl.h:1757
static MUST_USE_RESULT MaybeObject * Allocate(int number_of_transitions)
Definition: transitions.cc:49
static Smi * FromInt(int value)
Definition: objects-inl.h:981
static const int kPrototypeTransitionsIndex
Definition: transitions.h:143
#define ASSERT(condition)
Definition: checks.h:270
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 kNotFound
Definition: transitions.h:137
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 kSimpleTransitionIndex
Definition: transitions.h:149
String * GetKey(int transition_number)
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
Map * GetTarget(int transition_number)
void set_back_pointer_storage(Object *back_pointer, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
FixedArray * GetPrototypeTransitions()
void set_elements_transition(Map *target, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
MUST_USE_RESULT MaybeObject * ExtendToFullTransitionArray()
Definition: transitions.cc:94
kPropertyAccessorsOffset kNamedPropertyHandlerOffset kInstanceTemplateOffset kAccessCheckInfoOffset kEvalFrominstructionsOffsetOffset kInstanceClassNameOffset flag
Definition: objects-inl.h:3923