Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/transitions.cc

Issue 228483005: Bugfix: A TransitionArray can disappear during copy. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: REBASE. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/transitions.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 origin->GetKey(origin_transition), 73 origin->GetKey(origin_transition),
74 origin->GetTarget(origin_transition)); 74 origin->GetTarget(origin_transition));
75 } 75 }
76 76
77 77
78 static bool InsertionPointFound(Name* key1, Name* key2) { 78 static bool InsertionPointFound(Name* key1, Name* key2) {
79 return key1->Hash() > key2->Hash(); 79 return key1->Hash() > key2->Hash();
80 } 80 }
81 81
82 82
83 Handle<TransitionArray> TransitionArray::NewWith(SimpleTransitionFlag flag, 83 Handle<TransitionArray> TransitionArray::NewWith(Handle<Map> map,
84 Handle<Name> key, 84 Handle<Name> name,
85 Handle<Map> target, 85 Handle<Map> target,
86 Handle<Object> back_pointer) { 86 SimpleTransitionFlag flag) {
87 Handle<TransitionArray> result; 87 Handle<TransitionArray> result;
88 Factory* factory = key->GetIsolate()->factory(); 88 Factory* factory = name->GetIsolate()->factory();
89 89
90 if (flag == SIMPLE_TRANSITION) { 90 if (flag == SIMPLE_TRANSITION) {
91 result = factory->NewSimpleTransitionArray(target); 91 result = factory->NewSimpleTransitionArray(target);
92 } else { 92 } else {
93 result = factory->NewTransitionArray(1); 93 result = factory->NewTransitionArray(1);
94 result->NoIncrementalWriteBarrierSet(0, *key, *target); 94 result->NoIncrementalWriteBarrierSet(0, *name, *target);
95 } 95 }
96 result->set_back_pointer_storage(*back_pointer); 96 result->set_back_pointer_storage(map->GetBackPointer());
97 return result; 97 return result;
98 } 98 }
99 99
100 100
101 MaybeObject* TransitionArray::ExtendToFullTransitionArray() { 101 MaybeObject* TransitionArray::ExtendToFullTransitionArray() {
102 ASSERT(!IsFullTransitionArray()); 102 ASSERT(!IsFullTransitionArray());
103 int nof = number_of_transitions(); 103 int nof = number_of_transitions();
104 TransitionArray* result; 104 TransitionArray* result;
105 MaybeObject* maybe_result = Allocate(GetIsolate(), nof); 105 MaybeObject* maybe_result = Allocate(GetIsolate(), nof);
106 if (!maybe_result->To(&result)) return maybe_result; 106 if (!maybe_result->To(&result)) return maybe_result;
107 107
108 if (nof == 1) { 108 if (nof == 1) {
109 result->NoIncrementalWriteBarrierCopyFrom(this, kSimpleTransitionIndex, 0); 109 result->NoIncrementalWriteBarrierCopyFrom(this, kSimpleTransitionIndex, 0);
110 } 110 }
111 111
112 result->set_back_pointer_storage(back_pointer_storage()); 112 result->set_back_pointer_storage(back_pointer_storage());
113 return result; 113 return result;
114 } 114 }
115 115
116 116
117 Handle<TransitionArray> TransitionArray::CopyInsert(Handle<Map> map, 117 Handle<TransitionArray> TransitionArray::CopyInsert(Handle<Map> map,
118 Handle<Name> name, 118 Handle<Name> name,
119 Handle<Map> target) { 119 Handle<Map> target,
120 ASSERT(map->HasTransitionArray()); 120 SimpleTransitionFlag flag) {
121 Handle<TransitionArray> result; 121 if (!map->HasTransitionArray()) {
122 return TransitionArray::NewWith(map, name, target, flag);
123 }
122 124
123 int number_of_transitions = map->transitions()->number_of_transitions(); 125 int number_of_transitions = map->transitions()->number_of_transitions();
124 int new_size = number_of_transitions; 126 int new_size = number_of_transitions;
125 127
126 int insertion_index = map->transitions()->Search(*name); 128 int insertion_index = map->transitions()->Search(*name);
127 if (insertion_index == kNotFound) ++new_size; 129 if (insertion_index == kNotFound) ++new_size;
128 130
129 result = map->GetIsolate()->factory()->NewTransitionArray(new_size); 131 Handle<TransitionArray> result =
132 map->GetIsolate()->factory()->NewTransitionArray(new_size);
130 133
131 // The map's transition array may have grown smaller during the allocation 134 // The map's transition array may have disappeared or grown smaller during
132 // above as it was weakly traversed. Trim the result copy if needed, and 135 // the allocation above as it was weakly traversed. Trim the result copy if
133 // recompute variables. 136 // needed, and recompute variables.
134 DisallowHeapAllocation no_gc; 137 DisallowHeapAllocation no_gc;
138 if (!map->HasTransitionArray()) {
139 if (flag == SIMPLE_TRANSITION) {
140 ASSERT(result->length() >= kSimpleTransitionSize);
141 result->Shrink(kSimpleTransitionSize);
142 result->set(kSimpleTransitionTarget, *target);
143 } else {
144 ASSERT(result->length() >= ToKeyIndex(1));
145 result->Shrink(ToKeyIndex(1));
146 result->set(kPrototypeTransitionsIndex, Smi::FromInt(0));
147 result->NoIncrementalWriteBarrierSet(0, *name, *target);
148 }
149 result->set_back_pointer_storage(map->GetBackPointer());
150
151 return result;
152 }
153
135 TransitionArray* array = map->transitions(); 154 TransitionArray* array = map->transitions();
136 if (array->number_of_transitions() != number_of_transitions) { 155 if (array->number_of_transitions() != number_of_transitions) {
137 ASSERT(array->number_of_transitions() < number_of_transitions); 156 ASSERT(array->number_of_transitions() < number_of_transitions);
138 157
139 number_of_transitions = array->number_of_transitions(); 158 number_of_transitions = array->number_of_transitions();
140 new_size = number_of_transitions; 159 new_size = number_of_transitions;
141 160
142 insertion_index = array->Search(*name); 161 insertion_index = array->Search(*name);
143 if (insertion_index == kNotFound) ++new_size; 162 if (insertion_index == kNotFound) ++new_size;
144 163
145 result->Shrink(new_size); 164 result->Shrink(ToKeyIndex(new_size));
146 } 165 }
147 166
148 if (array->HasPrototypeTransitions()) { 167 if (array->HasPrototypeTransitions()) {
149 result->SetPrototypeTransitions(array->GetPrototypeTransitions()); 168 result->SetPrototypeTransitions(array->GetPrototypeTransitions());
150 } 169 }
151 170
152 if (insertion_index != kNotFound) { 171 if (insertion_index != kNotFound) {
153 for (int i = 0; i < number_of_transitions; ++i) { 172 for (int i = 0; i < number_of_transitions; ++i) {
154 if (i != insertion_index) { 173 if (i != insertion_index) {
155 result->NoIncrementalWriteBarrierCopyFrom(array, i, i); 174 result->NoIncrementalWriteBarrierCopyFrom(array, i, i);
(...skipping 17 matching lines...) Expand all
173 result->NoIncrementalWriteBarrierCopyFrom( 192 result->NoIncrementalWriteBarrierCopyFrom(
174 array, insertion_index, insertion_index + 1); 193 array, insertion_index, insertion_index + 1);
175 } 194 }
176 195
177 result->set_back_pointer_storage(array->back_pointer_storage()); 196 result->set_back_pointer_storage(array->back_pointer_storage());
178 return result; 197 return result;
179 } 198 }
180 199
181 200
182 } } // namespace v8::internal 201 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/transitions.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698