| OLD | NEW |
| 1 // Copyright 2017 the V8 project authors. All rights reserved. | 1 // Copyright 2017 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/builtins/builtins-utils-gen.h" | 5 #include "src/builtins/builtins-utils-gen.h" |
| 6 #include "src/builtins/builtins.h" | 6 #include "src/builtins/builtins.h" |
| 7 #include "src/code-stub-assembler.h" | 7 #include "src/code-stub-assembler.h" |
| 8 #include "src/macro-assembler.h" | 8 #include "src/macro-assembler.h" |
| 9 #include "src/runtime/runtime.h" | 9 #include "src/runtime/runtime.h" |
| 10 | 10 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 | 162 |
| 163 TF_BUILTIN(ReturnReceiver, CodeStubAssembler) { | 163 TF_BUILTIN(ReturnReceiver, CodeStubAssembler) { |
| 164 Return(Parameter(Descriptor::kReceiver)); | 164 Return(Parameter(Descriptor::kReceiver)); |
| 165 } | 165 } |
| 166 | 166 |
| 167 class DeletePropertyBaseAssembler : public CodeStubAssembler { | 167 class DeletePropertyBaseAssembler : public CodeStubAssembler { |
| 168 public: | 168 public: |
| 169 explicit DeletePropertyBaseAssembler(compiler::CodeAssemblerState* state) | 169 explicit DeletePropertyBaseAssembler(compiler::CodeAssemblerState* state) |
| 170 : CodeStubAssembler(state) {} | 170 : CodeStubAssembler(state) {} |
| 171 | 171 |
| 172 void DeleteFastProperty(Node* receiver, Node* receiver_map, Node* properties, | |
| 173 Node* name, Label* dont_delete, Label* not_found, | |
| 174 Label* slow) { | |
| 175 // This builtin implements a special case for fast property deletion: | |
| 176 // when the last property in an object is deleted, then instead of | |
| 177 // normalizing the properties, we can undo the last map transition, | |
| 178 // with a few prerequisites: | |
| 179 // (1) The current map must not be marked stable. Otherwise there could | |
| 180 // be optimized code that depends on the assumption that no object that | |
| 181 // reached this map transitions away from it (without triggering the | |
| 182 // "deoptimize dependent code" mechanism). | |
| 183 Node* bitfield3 = LoadMapBitField3(receiver_map); | |
| 184 GotoIfNot(IsSetWord32<Map::IsUnstable>(bitfield3), slow); | |
| 185 // (2) The property to be deleted must be the last property. | |
| 186 Node* descriptors = LoadMapDescriptors(receiver_map); | |
| 187 Node* nof = DecodeWord32<Map::NumberOfOwnDescriptorsBits>(bitfield3); | |
| 188 GotoIf(Word32Equal(nof, Int32Constant(0)), not_found); | |
| 189 Node* descriptor_number = Int32Sub(nof, Int32Constant(1)); | |
| 190 Node* key_index = DescriptorArrayToKeyIndex(descriptor_number); | |
| 191 Node* actual_key = LoadFixedArrayElement(descriptors, key_index); | |
| 192 // TODO(jkummerow): We could implement full descriptor search in order | |
| 193 // to avoid the runtime call for deleting nonexistent properties, but | |
| 194 // that's probably a rare case. | |
| 195 GotoIf(WordNotEqual(actual_key, name), slow); | |
| 196 // (3) The property to be deleted must be deletable. | |
| 197 Node* details = | |
| 198 LoadDetailsByKeyIndex<DescriptorArray>(descriptors, key_index); | |
| 199 GotoIf(IsSetWord32(details, PropertyDetails::kAttributesDontDeleteMask), | |
| 200 dont_delete); | |
| 201 // (4) The map must have a back pointer. | |
| 202 Node* backpointer = | |
| 203 LoadObjectField(receiver_map, Map::kConstructorOrBackPointerOffset); | |
| 204 GotoIfNot(IsMap(backpointer), slow); | |
| 205 // (5) The last transition must have been caused by adding a property | |
| 206 // (and not any kind of special transition). | |
| 207 Node* previous_nof = DecodeWord32<Map::NumberOfOwnDescriptorsBits>( | |
| 208 LoadMapBitField3(backpointer)); | |
| 209 GotoIfNot(Word32Equal(previous_nof, descriptor_number), slow); | |
| 210 | |
| 211 // Preconditions successful, perform the map rollback! | |
| 212 // Zap the property to avoid keeping objects alive. | |
| 213 // Zapping is not necessary for properties stored in the descriptor array. | |
| 214 Label zapping_done(this); | |
| 215 GotoIf(Word32NotEqual(DecodeWord32<PropertyDetails::LocationField>(details), | |
| 216 Int32Constant(kField)), | |
| 217 &zapping_done); | |
| 218 Node* field_index = | |
| 219 DecodeWordFromWord32<PropertyDetails::FieldIndexField>(details); | |
| 220 Node* inobject_properties = LoadMapInobjectProperties(receiver_map); | |
| 221 Label inobject(this), backing_store(this); | |
| 222 // Due to inobject slack tracking, a field currently within the object | |
| 223 // could later be between objects. Use the one pointer filler map for | |
| 224 // zapping the deleted field to make this safe. | |
| 225 Node* filler = LoadRoot(Heap::kOnePointerFillerMapRootIndex); | |
| 226 DCHECK(Heap::RootIsImmortalImmovable(Heap::kOnePointerFillerMapRootIndex)); | |
| 227 Branch(UintPtrLessThan(field_index, inobject_properties), &inobject, | |
| 228 &backing_store); | |
| 229 BIND(&inobject); | |
| 230 { | |
| 231 Node* field_offset = | |
| 232 IntPtrMul(IntPtrSub(LoadMapInstanceSize(receiver_map), | |
| 233 IntPtrSub(inobject_properties, field_index)), | |
| 234 IntPtrConstant(kPointerSize)); | |
| 235 StoreObjectFieldNoWriteBarrier(receiver, field_offset, filler); | |
| 236 Goto(&zapping_done); | |
| 237 } | |
| 238 BIND(&backing_store); | |
| 239 { | |
| 240 Node* backing_store_index = IntPtrSub(field_index, inobject_properties); | |
| 241 StoreFixedArrayElement(properties, backing_store_index, filler, | |
| 242 SKIP_WRITE_BARRIER); | |
| 243 Goto(&zapping_done); | |
| 244 } | |
| 245 BIND(&zapping_done); | |
| 246 StoreMap(receiver, backpointer); | |
| 247 Return(TrueConstant()); | |
| 248 } | |
| 249 | |
| 250 void DeleteDictionaryProperty(Node* receiver, Node* properties, Node* name, | 172 void DeleteDictionaryProperty(Node* receiver, Node* properties, Node* name, |
| 251 Node* context, Label* dont_delete, | 173 Node* context, Label* dont_delete, |
| 252 Label* notfound) { | 174 Label* notfound) { |
| 253 VARIABLE(var_name_index, MachineType::PointerRepresentation()); | 175 VARIABLE(var_name_index, MachineType::PointerRepresentation()); |
| 254 Label dictionary_found(this, &var_name_index); | 176 Label dictionary_found(this, &var_name_index); |
| 255 NameDictionaryLookup<NameDictionary>(properties, name, &dictionary_found, | 177 NameDictionaryLookup<NameDictionary>(properties, name, &dictionary_found, |
| 256 &var_name_index, notfound); | 178 &var_name_index, notfound); |
| 257 | 179 |
| 258 BIND(&dictionary_found); | 180 BIND(&dictionary_found); |
| 259 Node* key_index = var_name_index.value(); | 181 Node* key_index = var_name_index.value(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 { | 243 { |
| 322 Comment("key is unique name"); | 244 Comment("key is unique name"); |
| 323 Node* unique = var_unique.value(); | 245 Node* unique = var_unique.value(); |
| 324 CheckForAssociatedProtector(unique, &slow); | 246 CheckForAssociatedProtector(unique, &slow); |
| 325 | 247 |
| 326 Label dictionary(this), dont_delete(this); | 248 Label dictionary(this), dont_delete(this); |
| 327 Node* properties = LoadProperties(receiver); | 249 Node* properties = LoadProperties(receiver); |
| 328 Node* properties_map = LoadMap(properties); | 250 Node* properties_map = LoadMap(properties); |
| 329 GotoIf(WordEqual(properties_map, LoadRoot(Heap::kHashTableMapRootIndex)), | 251 GotoIf(WordEqual(properties_map, LoadRoot(Heap::kHashTableMapRootIndex)), |
| 330 &dictionary); | 252 &dictionary); |
| 331 DeleteFastProperty(receiver, receiver_map, properties, unique, &dont_delete, | 253 // Fast properties need to clear recorded slots, which can only be done |
| 332 &if_notfound, &slow); | 254 // in C++. |
| 255 Goto(&slow); |
| 333 | 256 |
| 334 BIND(&dictionary); | 257 BIND(&dictionary); |
| 335 { | 258 { |
| 336 DeleteDictionaryProperty(receiver, properties, unique, context, | 259 DeleteDictionaryProperty(receiver, properties, unique, context, |
| 337 &dont_delete, &if_notfound); | 260 &dont_delete, &if_notfound); |
| 338 } | 261 } |
| 339 | 262 |
| 340 BIND(&dont_delete); | 263 BIND(&dont_delete); |
| 341 { | 264 { |
| 342 STATIC_ASSERT(LANGUAGE_END == 2); | 265 STATIC_ASSERT(LANGUAGE_END == 2); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 358 | 281 |
| 359 BIND(&slow); | 282 BIND(&slow); |
| 360 { | 283 { |
| 361 TailCallRuntime(Runtime::kDeleteProperty, context, receiver, key, | 284 TailCallRuntime(Runtime::kDeleteProperty, context, receiver, key, |
| 362 language_mode); | 285 language_mode); |
| 363 } | 286 } |
| 364 } | 287 } |
| 365 | 288 |
| 366 } // namespace internal | 289 } // namespace internal |
| 367 } // namespace v8 | 290 } // namespace v8 |
| OLD | NEW |