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

Side by Side Diff: src/objects.cc

Issue 18221006: Add map transition for observed objects (Closed) Base URL: https://github.com/v8/v8.git@bleeding_edge
Patch Set: better check Created 7 years, 5 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
« no previous file with comments | « src/objects.h ('k') | src/runtime.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 4000 matching lines...) Expand 10 before | Expand all | Expand 10 after
4011 4011
4012 // From this point on everything needs to be handlified. 4012 // From this point on everything needs to be handlified.
4013 HandleScope scope(isolate); 4013 HandleScope scope(isolate);
4014 Handle<JSObject> self(this); 4014 Handle<JSObject> self(this);
4015 Handle<Name> name(name_raw); 4015 Handle<Name> name(name_raw);
4016 Handle<Object> value(value_raw, isolate); 4016 Handle<Object> value(value_raw, isolate);
4017 4017
4018 Handle<Object> old_value(isolate->heap()->the_hole_value(), isolate); 4018 Handle<Object> old_value(isolate->heap()->the_hole_value(), isolate);
4019 PropertyAttributes old_attributes = ABSENT; 4019 PropertyAttributes old_attributes = ABSENT;
4020 bool is_observed = FLAG_harmony_observation && self->map()->is_observed(); 4020 bool is_observed = FLAG_harmony_observation && self->map()->is_observed();
4021 if (is_observed) { 4021 if (is_observed && lookup.IsProperty()) {
4022 if (lookup.IsDataProperty()) old_value = Object::GetProperty(self, name); 4022 if (lookup.IsDataProperty()) old_value = Object::GetProperty(self, name);
4023 old_attributes = lookup.GetAttributes(); 4023 old_attributes = lookup.GetAttributes();
4024 } 4024 }
4025 4025
4026 // Check of IsReadOnly removed from here in clone. 4026 // Check of IsReadOnly removed from here in clone.
4027 MaybeObject* result = *value; 4027 MaybeObject* result = *value;
4028 switch (lookup.type()) { 4028 switch (lookup.type()) {
4029 case NORMAL: { 4029 case NORMAL: {
4030 PropertyDetails details = PropertyDetails(attributes, NORMAL, 0); 4030 PropertyDetails details = PropertyDetails(attributes, NORMAL, 0);
4031 result = self->SetNormalizedProperty(*name, *value, details); 4031 result = self->SetNormalizedProperty(*name, *value, details);
(...skipping 1518 matching lines...) Expand 10 before | Expand all | Expand 10 after
5550 // Make sure we never go back to the fast case 5550 // Make sure we never go back to the fast case
5551 dictionary->set_requires_slow_elements(); 5551 dictionary->set_requires_slow_elements();
5552 // Freeze all elements in the dictionary 5552 // Freeze all elements in the dictionary
5553 FreezeDictionary(dictionary); 5553 FreezeDictionary(dictionary);
5554 } 5554 }
5555 5555
5556 return this; 5556 return this;
5557 } 5557 }
5558 5558
5559 5559
5560 MUST_USE_RESULT MaybeObject* JSObject::SetObserved(Isolate* isolate) {
5561 if (map()->is_observed())
5562 return isolate->heap()->undefined_value();
5563
5564 Heap* heap = isolate->heap();
5565
5566 if (!HasExternalArrayElements()) {
5567 // Go to dictionary mode, so that we don't skip map checks.
5568 MaybeObject* maybe = NormalizeElements();
5569 if (maybe->IsFailure()) return maybe;
5570 ASSERT(!HasFastElements());
5571 }
5572
5573 LookupResult result(isolate);
5574 map()->LookupTransition(this, heap->observed_symbol(), &result);
5575
5576 Map* new_map;
5577 if (result.IsTransition()) {
5578 new_map = result.GetTransitionTarget();
5579 ASSERT(new_map->is_observed());
5580 } else if (map()->CanHaveMoreTransitions()) {
5581 MaybeObject* maybe_new_map = map()->CopyForObserved();
5582 if (!maybe_new_map->To(&new_map)) return maybe_new_map;
5583 } else {
5584 MaybeObject* maybe_copy = map()->Copy();
5585 if (!maybe_copy->To(&new_map)) return maybe_copy;
5586 new_map->set_is_observed(true);
5587 }
5588 set_map(new_map);
5589
5590 return heap->undefined_value();
5591 }
5592
5593
5560 MUST_USE_RESULT MaybeObject* JSObject::DeepCopy(Isolate* isolate) { 5594 MUST_USE_RESULT MaybeObject* JSObject::DeepCopy(Isolate* isolate) {
5561 StackLimitCheck check(isolate); 5595 StackLimitCheck check(isolate);
5562 if (check.HasOverflowed()) return isolate->StackOverflow(); 5596 if (check.HasOverflowed()) return isolate->StackOverflow();
5563 5597
5564 if (map()->is_deprecated()) { 5598 if (map()->is_deprecated()) {
5565 MaybeObject* maybe_failure = MigrateInstance(); 5599 MaybeObject* maybe_failure = MigrateInstance();
5566 if (maybe_failure->IsFailure()) return maybe_failure; 5600 if (maybe_failure->IsFailure()) return maybe_failure;
5567 } 5601 }
5568 5602
5569 Heap* heap = isolate->heap(); 5603 Heap* heap = isolate->heap();
(...skipping 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after
6673 if (insert_transition) { 6707 if (insert_transition) {
6674 MaybeObject* added_elements = set_elements_transition_map(new_map); 6708 MaybeObject* added_elements = set_elements_transition_map(new_map);
6675 if (added_elements->IsFailure()) return added_elements; 6709 if (added_elements->IsFailure()) return added_elements;
6676 new_map->SetBackPointer(this); 6710 new_map->SetBackPointer(this);
6677 } 6711 }
6678 6712
6679 return new_map; 6713 return new_map;
6680 } 6714 }
6681 6715
6682 6716
6717 MaybeObject* Map::CopyForObserved() {
6718 ASSERT(!is_observed());
6719
6720 // In case the map owned its own descriptors, share the descriptors and
6721 // transfer ownership to the new map.
6722 Map* new_map;
6723 MaybeObject* maybe_new_map;
6724 if (owns_descriptors()) {
6725 maybe_new_map = CopyDropDescriptors();
6726 } else {
6727 maybe_new_map = Copy();
6728 }
6729 if (!maybe_new_map->To(&new_map)) return maybe_new_map;
6730
6731 TransitionArray* transitions;
6732 MaybeObject* maybe_transitions = AddTransition(GetHeap()->observed_symbol(),
6733 new_map,
6734 FULL_TRANSITION);
6735 if (!maybe_transitions->To(&transitions)) return maybe_transitions;
6736 set_transitions(transitions);
6737
6738 new_map->set_is_observed(true);
6739
6740 if (owns_descriptors()) {
6741 new_map->InitializeDescriptors(instance_descriptors());
6742 set_owns_descriptors(false);
6743 }
6744
6745 new_map->SetBackPointer(this);
6746 return new_map;
6747 }
6748
6749
6683 MaybeObject* Map::CopyWithPreallocatedFieldDescriptors() { 6750 MaybeObject* Map::CopyWithPreallocatedFieldDescriptors() {
6684 if (pre_allocated_property_fields() == 0) return CopyDropDescriptors(); 6751 if (pre_allocated_property_fields() == 0) return CopyDropDescriptors();
6685 6752
6686 // If the map has pre-allocated properties always start out with a descriptor 6753 // If the map has pre-allocated properties always start out with a descriptor
6687 // array describing these properties. 6754 // array describing these properties.
6688 ASSERT(constructor()->IsJSFunction()); 6755 ASSERT(constructor()->IsJSFunction());
6689 JSFunction* ctor = JSFunction::cast(constructor()); 6756 JSFunction* ctor = JSFunction::cast(constructor());
6690 Map* map = ctor->initial_map(); 6757 Map* map = ctor->initial_map();
6691 DescriptorArray* descriptors = map->instance_descriptors(); 6758 DescriptorArray* descriptors = map->instance_descriptors();
6692 6759
(...skipping 9188 matching lines...) Expand 10 before | Expand all | Expand 10 after
15881 15948
15882 void PropertyCell::AddDependentCode(Handle<Code> code) { 15949 void PropertyCell::AddDependentCode(Handle<Code> code) {
15883 Handle<DependentCode> codes = DependentCode::Insert( 15950 Handle<DependentCode> codes = DependentCode::Insert(
15884 Handle<DependentCode>(dependent_code()), 15951 Handle<DependentCode>(dependent_code()),
15885 DependentCode::kPropertyCellChangedGroup, code); 15952 DependentCode::kPropertyCellChangedGroup, code);
15886 if (*codes != dependent_code()) set_dependent_code(*codes); 15953 if (*codes != dependent_code()) set_dependent_code(*codes);
15887 } 15954 }
15888 15955
15889 15956
15890 } } // namespace v8::internal 15957 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698