Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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/objects.h" | 5 #include "src/objects.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <iomanip> | 8 #include <iomanip> |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 | 10 |
| (...skipping 11746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11757 // suggested by the function. | 11757 // suggested by the function. |
| 11758 InstanceType instance_type; | 11758 InstanceType instance_type; |
| 11759 int instance_size; | 11759 int instance_size; |
| 11760 int in_object_properties; | 11760 int in_object_properties; |
| 11761 if (function->shared()->is_generator()) { | 11761 if (function->shared()->is_generator()) { |
| 11762 instance_type = JS_GENERATOR_OBJECT_TYPE; | 11762 instance_type = JS_GENERATOR_OBJECT_TYPE; |
| 11763 instance_size = JSGeneratorObject::kSize; | 11763 instance_size = JSGeneratorObject::kSize; |
| 11764 in_object_properties = 0; | 11764 in_object_properties = 0; |
| 11765 } else { | 11765 } else { |
| 11766 instance_type = JS_OBJECT_TYPE; | 11766 instance_type = JS_OBJECT_TYPE; |
| 11767 instance_size = function->shared()->CalculateInstanceSize(); | 11767 instance_size = function->shared()->CalculateInstanceSize(instance_type); |
| 11768 in_object_properties = function->shared()->CalculateInObjectProperties(); | 11768 in_object_properties = |
| 11769 function->shared()->CalculateInObjectProperties(instance_type); | |
| 11769 } | 11770 } |
| 11770 Handle<Map> map = isolate->factory()->NewMap(instance_type, instance_size); | 11771 Handle<Map> map = isolate->factory()->NewMap(instance_type, instance_size); |
| 11771 if (function->map()->is_strong()) { | 11772 if (function->map()->is_strong()) { |
| 11772 map->set_is_strong(); | 11773 map->set_is_strong(); |
| 11773 } | 11774 } |
| 11774 | 11775 |
| 11775 // Fetch or allocate prototype. | 11776 // Fetch or allocate prototype. |
| 11776 Handle<Object> prototype; | 11777 Handle<Object> prototype; |
| 11777 if (function->has_instance_prototype()) { | 11778 if (function->has_instance_prototype()) { |
| 11778 prototype = handle(function->instance_prototype(), isolate); | 11779 prototype = handle(function->instance_prototype(), isolate); |
| 11779 } else { | 11780 } else { |
| 11780 prototype = isolate->factory()->NewFunctionPrototype(function); | 11781 prototype = isolate->factory()->NewFunctionPrototype(function); |
| 11781 } | 11782 } |
| 11782 map->SetInObjectProperties(in_object_properties); | 11783 map->SetInObjectProperties(in_object_properties); |
| 11783 map->set_unused_property_fields(in_object_properties); | 11784 map->set_unused_property_fields(in_object_properties); |
| 11784 DCHECK(map->has_fast_object_elements()); | 11785 DCHECK(map->has_fast_object_elements()); |
| 11785 | 11786 |
| 11786 // Finally link initial map and constructor function. | 11787 // Finally link initial map and constructor function. |
| 11787 DCHECK(prototype->IsJSReceiver()); | 11788 DCHECK(prototype->IsJSReceiver()); |
| 11788 JSFunction::SetInitialMap(function, map, prototype); | 11789 JSFunction::SetInitialMap(function, map, prototype); |
| 11789 | 11790 |
| 11790 if (!function->shared()->is_generator()) { | 11791 if (!function->shared()->is_generator()) { |
| 11791 function->StartInobjectSlackTracking(); | 11792 function->StartInobjectSlackTracking(); |
| 11792 } | 11793 } |
| 11793 } | 11794 } |
| 11794 | 11795 |
| 11795 | 11796 |
| 11797 Handle<Map> JSFunction::EnsureDerivedHasInitialMap( | |
| 11798 Handle<JSFunction> original_constructor, Handle<JSFunction> constructor) { | |
| 11799 DCHECK(constructor->has_initial_map()); | |
| 11800 Isolate* isolate = constructor->GetIsolate(); | |
| 11801 Handle<Map> constructor_initial_map(constructor->initial_map(), isolate); | |
| 11802 if (*original_constructor == *constructor) return constructor_initial_map; | |
| 11803 if (original_constructor->has_initial_map()) { | |
| 11804 // Check that |original_constructor|'s initial map still in sync with | |
| 11805 // the |constructor|, otherwise we must create a new initial map for | |
| 11806 // |original_constructor|. | |
| 11807 if (original_constructor->initial_map()->GetConstructor() == *constructor) { | |
| 11808 return handle(original_constructor->initial_map(), isolate); | |
| 11809 } | |
| 11810 } | |
| 11811 | |
| 11812 // First create a new map with the size and number of in-object properties | |
| 11813 // suggested by the function. | |
| 11814 DCHECK(!original_constructor->shared()->is_generator()); | |
| 11815 DCHECK(!constructor->shared()->is_generator()); | |
| 11816 | |
| 11817 Handle<Map> map = | |
| 11818 Map::Copy(constructor_initial_map, "EnsureDerivedHasInitialMap"); | |
| 11819 | |
| 11820 // Fetch or allocate prototype. | |
| 11821 Handle<Object> prototype; | |
| 11822 if (original_constructor->has_instance_prototype()) { | |
| 11823 prototype = handle(original_constructor->instance_prototype(), isolate); | |
| 11824 } else { | |
| 11825 prototype = isolate->factory()->NewFunctionPrototype(original_constructor); | |
| 11826 } | |
| 11827 | |
| 11828 DCHECK(prototype->IsJSReceiver()); | |
| 11829 if (map->prototype() != *prototype) { | |
| 11830 Map::SetPrototype(map, prototype, FAST_PROTOTYPE); | |
| 11831 } | |
| 11832 | |
| 11833 // Finally link initial map and constructor function if the original | |
| 11834 // constructor is actually a subclass constructor. | |
| 11835 if (IsSubclassConstructor(original_constructor->shared()->kind())) { | |
| 11836 InstanceType instance_type = map->instance_type(); | |
| 11837 int instance_size = | |
| 11838 original_constructor->shared()->CalculateInstanceSize(instance_type); | |
| 11839 map->set_instance_size(instance_size); | |
| 11840 | |
| 11841 int in_object_properties = | |
| 11842 original_constructor->shared()->CalculateInObjectProperties( | |
|
Toon Verwaest
2015/10/26 15:10:57
Shouldn't we add up the expected number of propert
Igor Sheludko
2015/10/27 12:56:12
Done.
| |
| 11843 instance_type); | |
| 11844 map->SetInObjectProperties(in_object_properties); | |
| 11845 map->set_unused_property_fields(in_object_properties); | |
| 11846 | |
| 11847 JSFunction::SetInitialMap(original_constructor, map, prototype); | |
| 11848 map->SetConstructor(*constructor); | |
| 11849 original_constructor->StartInobjectSlackTracking(); | |
| 11850 } else { | |
| 11851 map->SetConstructor(*constructor); | |
| 11852 } | |
| 11853 return map; | |
| 11854 } | |
| 11855 | |
| 11856 | |
| 11796 void JSFunction::SetInstanceClassName(String* name) { | 11857 void JSFunction::SetInstanceClassName(String* name) { |
| 11797 shared()->set_instance_class_name(name); | 11858 shared()->set_instance_class_name(name); |
| 11798 } | 11859 } |
| 11799 | 11860 |
| 11800 | 11861 |
| 11801 void JSFunction::PrintName(FILE* out) { | 11862 void JSFunction::PrintName(FILE* out) { |
| 11802 base::SmartArrayPointer<char> name = shared()->DebugName()->ToCString(); | 11863 base::SmartArrayPointer<char> name = shared()->DebugName()->ToCString(); |
| 11803 PrintF(out, "%s", name.get()); | 11864 PrintF(out, "%s", name.get()); |
| 11804 } | 11865 } |
| 11805 | 11866 |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 12101 if (!script()->IsScript()) return false; | 12162 if (!script()->IsScript()) return false; |
| 12102 return !optimization_disabled(); | 12163 return !optimization_disabled(); |
| 12103 } | 12164 } |
| 12104 | 12165 |
| 12105 | 12166 |
| 12106 int SharedFunctionInfo::SourceSize() { | 12167 int SharedFunctionInfo::SourceSize() { |
| 12107 return end_position() - start_position(); | 12168 return end_position() - start_position(); |
| 12108 } | 12169 } |
| 12109 | 12170 |
| 12110 | 12171 |
| 12111 int SharedFunctionInfo::CalculateInstanceSize() { | 12172 int SharedFunctionInfo::CalculateInstanceSize(InstanceType instance_type) { |
| 12112 int instance_size = | 12173 int header_size = JSObject::GetHeaderWithInternalFieldsSize(instance_type); |
| 12113 JSObject::kHeaderSize + | 12174 int instance_size = header_size + expected_nof_properties() * kPointerSize; |
| 12114 expected_nof_properties() * kPointerSize; | |
| 12115 if (instance_size > JSObject::kMaxInstanceSize) { | 12175 if (instance_size > JSObject::kMaxInstanceSize) { |
| 12116 instance_size = JSObject::kMaxInstanceSize; | 12176 instance_size = JSObject::kMaxInstanceSize; |
| 12117 } | 12177 } |
| 12118 return instance_size; | 12178 return instance_size; |
| 12119 } | 12179 } |
| 12120 | 12180 |
| 12121 | 12181 |
| 12122 int SharedFunctionInfo::CalculateInObjectProperties() { | 12182 int SharedFunctionInfo::CalculateInObjectProperties( |
| 12123 return (CalculateInstanceSize() - JSObject::kHeaderSize) / kPointerSize; | 12183 InstanceType instance_type) { |
| 12184 int header_size = JSObject::GetHeaderWithInternalFieldsSize(instance_type); | |
| 12185 return (CalculateInstanceSize(instance_type) - header_size) / kPointerSize; | |
| 12124 } | 12186 } |
| 12125 | 12187 |
| 12126 | 12188 |
| 12127 // Output the source code without any allocation in the heap. | 12189 // Output the source code without any allocation in the heap. |
| 12128 std::ostream& operator<<(std::ostream& os, const SourceCodeOf& v) { | 12190 std::ostream& operator<<(std::ostream& os, const SourceCodeOf& v) { |
| 12129 const SharedFunctionInfo* s = v.value; | 12191 const SharedFunctionInfo* s = v.value; |
| 12130 // For some native functions there is no source. | 12192 // For some native functions there is no source. |
| 12131 if (!s->HasSourceCode()) return os << "<No Source>"; | 12193 if (!s->HasSourceCode()) return os << "<No Source>"; |
| 12132 | 12194 |
| 12133 // Get the source for the script which this function came from. | 12195 // Get the source for the script which this function came from. |
| (...skipping 5624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 17758 if (cell->value() != *new_value) { | 17820 if (cell->value() != *new_value) { |
| 17759 cell->set_value(*new_value); | 17821 cell->set_value(*new_value); |
| 17760 Isolate* isolate = cell->GetIsolate(); | 17822 Isolate* isolate = cell->GetIsolate(); |
| 17761 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 17823 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
| 17762 isolate, DependentCode::kPropertyCellChangedGroup); | 17824 isolate, DependentCode::kPropertyCellChangedGroup); |
| 17763 } | 17825 } |
| 17764 } | 17826 } |
| 17765 | 17827 |
| 17766 } // namespace internal | 17828 } // namespace internal |
| 17767 } // namespace v8 | 17829 } // namespace v8 |
| OLD | NEW |