| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 <memory> | 9 #include <memory> |
| 10 #include <sstream> | 10 #include <sstream> |
| (...skipping 11872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11883 return true; | 11883 return true; |
| 11884 } | 11884 } |
| 11885 | 11885 |
| 11886 | 11886 |
| 11887 bool Map::EquivalentToForNormalization(Map* other, | 11887 bool Map::EquivalentToForNormalization(Map* other, |
| 11888 PropertyNormalizationMode mode) { | 11888 PropertyNormalizationMode mode) { |
| 11889 int properties = | 11889 int properties = |
| 11890 mode == CLEAR_INOBJECT_PROPERTIES ? 0 : other->GetInObjectProperties(); | 11890 mode == CLEAR_INOBJECT_PROPERTIES ? 0 : other->GetInObjectProperties(); |
| 11891 return CheckEquivalent(this, other) && bit_field2() == other->bit_field2() && | 11891 return CheckEquivalent(this, other) && bit_field2() == other->bit_field2() && |
| 11892 GetInObjectProperties() == properties && | 11892 GetInObjectProperties() == properties && |
| 11893 JSObject::GetInternalFieldCount(this) == | 11893 JSObject::GetEmbedderFieldCount(this) == |
| 11894 JSObject::GetInternalFieldCount(other); | 11894 JSObject::GetEmbedderFieldCount(other); |
| 11895 } | 11895 } |
| 11896 | 11896 |
| 11897 | 11897 |
| 11898 bool JSFunction::Inlines(SharedFunctionInfo* candidate) { | 11898 bool JSFunction::Inlines(SharedFunctionInfo* candidate) { |
| 11899 DisallowHeapAllocation no_gc; | 11899 DisallowHeapAllocation no_gc; |
| 11900 if (shared() == candidate) return true; | 11900 if (shared() == candidate) return true; |
| 11901 if (code()->kind() != Code::OPTIMIZED_FUNCTION) return false; | 11901 if (code()->kind() != Code::OPTIMIZED_FUNCTION) return false; |
| 11902 DeoptimizationInputData* const data = | 11902 DeoptimizationInputData* const data = |
| 11903 DeoptimizationInputData::cast(code()->deoptimization_data()); | 11903 DeoptimizationInputData::cast(code()->deoptimization_data()); |
| 11904 if (data->length() == 0) return false; | 11904 if (data->length() == 0) return false; |
| (...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12757 | 12757 |
| 12758 // Create a new map with the size and number of in-object properties | 12758 // Create a new map with the size and number of in-object properties |
| 12759 // suggested by |function|. | 12759 // suggested by |function|. |
| 12760 | 12760 |
| 12761 // Link initial map and constructor function if the new.target is actually a | 12761 // Link initial map and constructor function if the new.target is actually a |
| 12762 // subclass constructor. | 12762 // subclass constructor. |
| 12763 if (IsDerivedConstructor(function->shared()->kind())) { | 12763 if (IsDerivedConstructor(function->shared()->kind())) { |
| 12764 Handle<Object> prototype(function->instance_prototype(), isolate); | 12764 Handle<Object> prototype(function->instance_prototype(), isolate); |
| 12765 InstanceType instance_type = constructor_initial_map->instance_type(); | 12765 InstanceType instance_type = constructor_initial_map->instance_type(); |
| 12766 DCHECK(CanSubclassHaveInobjectProperties(instance_type)); | 12766 DCHECK(CanSubclassHaveInobjectProperties(instance_type)); |
| 12767 int internal_fields = | 12767 int embedder_fields = |
| 12768 JSObject::GetInternalFieldCount(*constructor_initial_map); | 12768 JSObject::GetEmbedderFieldCount(*constructor_initial_map); |
| 12769 int pre_allocated = constructor_initial_map->GetInObjectProperties() - | 12769 int pre_allocated = constructor_initial_map->GetInObjectProperties() - |
| 12770 constructor_initial_map->unused_property_fields(); | 12770 constructor_initial_map->unused_property_fields(); |
| 12771 int instance_size; | 12771 int instance_size; |
| 12772 int in_object_properties; | 12772 int in_object_properties; |
| 12773 function->CalculateInstanceSizeForDerivedClass( | 12773 function->CalculateInstanceSizeForDerivedClass( |
| 12774 instance_type, internal_fields, &instance_size, | 12774 instance_type, embedder_fields, &instance_size, |
| 12775 &in_object_properties); | 12775 &in_object_properties); |
| 12776 | 12776 |
| 12777 int unused_property_fields = in_object_properties - pre_allocated; | 12777 int unused_property_fields = in_object_properties - pre_allocated; |
| 12778 Handle<Map> map = | 12778 Handle<Map> map = |
| 12779 Map::CopyInitialMap(constructor_initial_map, instance_size, | 12779 Map::CopyInitialMap(constructor_initial_map, instance_size, |
| 12780 in_object_properties, unused_property_fields); | 12780 in_object_properties, unused_property_fields); |
| 12781 map->set_new_target_is_base(false); | 12781 map->set_new_target_is_base(false); |
| 12782 | 12782 |
| 12783 JSFunction::SetInitialMap(function, map, prototype); | 12783 JSFunction::SetInitialMap(function, map, prototype); |
| 12784 map->SetConstructor(*constructor); | 12784 map->SetConstructor(*constructor); |
| (...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13421 if (!script()->IsScript()) return false; | 13421 if (!script()->IsScript()) return false; |
| 13422 return !optimization_disabled(); | 13422 return !optimization_disabled(); |
| 13423 } | 13423 } |
| 13424 | 13424 |
| 13425 | 13425 |
| 13426 int SharedFunctionInfo::SourceSize() { | 13426 int SharedFunctionInfo::SourceSize() { |
| 13427 return end_position() - start_position(); | 13427 return end_position() - start_position(); |
| 13428 } | 13428 } |
| 13429 | 13429 |
| 13430 void JSFunction::CalculateInstanceSizeHelper(InstanceType instance_type, | 13430 void JSFunction::CalculateInstanceSizeHelper(InstanceType instance_type, |
| 13431 int requested_internal_fields, | 13431 int requested_embedder_fields, |
| 13432 int requested_in_object_properties, | 13432 int requested_in_object_properties, |
| 13433 int* instance_size, | 13433 int* instance_size, |
| 13434 int* in_object_properties) { | 13434 int* in_object_properties) { |
| 13435 int header_size = JSObject::GetHeaderSize(instance_type); | 13435 int header_size = JSObject::GetHeaderSize(instance_type); |
| 13436 DCHECK_LE(requested_internal_fields, | 13436 DCHECK_LE(requested_embedder_fields, |
| 13437 (JSObject::kMaxInstanceSize - header_size) >> kPointerSizeLog2); | 13437 (JSObject::kMaxInstanceSize - header_size) >> kPointerSizeLog2); |
| 13438 *instance_size = | 13438 *instance_size = |
| 13439 Min(header_size + | 13439 Min(header_size + |
| 13440 ((requested_internal_fields + requested_in_object_properties) | 13440 ((requested_embedder_fields + requested_in_object_properties) |
| 13441 << kPointerSizeLog2), | 13441 << kPointerSizeLog2), |
| 13442 JSObject::kMaxInstanceSize); | 13442 JSObject::kMaxInstanceSize); |
| 13443 *in_object_properties = ((*instance_size - header_size) >> kPointerSizeLog2) - | 13443 *in_object_properties = ((*instance_size - header_size) >> kPointerSizeLog2) - |
| 13444 requested_internal_fields; | 13444 requested_embedder_fields; |
| 13445 } | 13445 } |
| 13446 | 13446 |
| 13447 | |
| 13448 void JSFunction::CalculateInstanceSize(InstanceType instance_type, | 13447 void JSFunction::CalculateInstanceSize(InstanceType instance_type, |
| 13449 int requested_internal_fields, | 13448 int requested_embedder_fields, |
| 13450 int* instance_size, | 13449 int* instance_size, |
| 13451 int* in_object_properties) { | 13450 int* in_object_properties) { |
| 13452 CalculateInstanceSizeHelper(instance_type, requested_internal_fields, | 13451 CalculateInstanceSizeHelper(instance_type, requested_embedder_fields, |
| 13453 shared()->expected_nof_properties(), | 13452 shared()->expected_nof_properties(), |
| 13454 instance_size, in_object_properties); | 13453 instance_size, in_object_properties); |
| 13455 } | 13454 } |
| 13456 | 13455 |
| 13457 | |
| 13458 void JSFunction::CalculateInstanceSizeForDerivedClass( | 13456 void JSFunction::CalculateInstanceSizeForDerivedClass( |
| 13459 InstanceType instance_type, int requested_internal_fields, | 13457 InstanceType instance_type, int requested_embedder_fields, |
| 13460 int* instance_size, int* in_object_properties) { | 13458 int* instance_size, int* in_object_properties) { |
| 13461 Isolate* isolate = GetIsolate(); | 13459 Isolate* isolate = GetIsolate(); |
| 13462 int expected_nof_properties = 0; | 13460 int expected_nof_properties = 0; |
| 13463 for (PrototypeIterator iter(isolate, this, kStartAtReceiver); !iter.IsAtEnd(); | 13461 for (PrototypeIterator iter(isolate, this, kStartAtReceiver); !iter.IsAtEnd(); |
| 13464 iter.Advance()) { | 13462 iter.Advance()) { |
| 13465 JSReceiver* current = iter.GetCurrent<JSReceiver>(); | 13463 JSReceiver* current = iter.GetCurrent<JSReceiver>(); |
| 13466 if (!current->IsJSFunction()) break; | 13464 if (!current->IsJSFunction()) break; |
| 13467 JSFunction* func = JSFunction::cast(current); | 13465 JSFunction* func = JSFunction::cast(current); |
| 13468 SharedFunctionInfo* shared = func->shared(); | 13466 SharedFunctionInfo* shared = func->shared(); |
| 13469 expected_nof_properties += shared->expected_nof_properties(); | 13467 expected_nof_properties += shared->expected_nof_properties(); |
| 13470 if (!IsDerivedConstructor(shared->kind())) { | 13468 if (!IsDerivedConstructor(shared->kind())) { |
| 13471 break; | 13469 break; |
| 13472 } | 13470 } |
| 13473 } | 13471 } |
| 13474 CalculateInstanceSizeHelper(instance_type, requested_internal_fields, | 13472 CalculateInstanceSizeHelper(instance_type, requested_embedder_fields, |
| 13475 expected_nof_properties, instance_size, | 13473 expected_nof_properties, instance_size, |
| 13476 in_object_properties); | 13474 in_object_properties); |
| 13477 } | 13475 } |
| 13478 | 13476 |
| 13479 | 13477 |
| 13480 // Output the source code without any allocation in the heap. | 13478 // Output the source code without any allocation in the heap. |
| 13481 std::ostream& operator<<(std::ostream& os, const SourceCodeOf& v) { | 13479 std::ostream& operator<<(std::ostream& os, const SourceCodeOf& v) { |
| 13482 const SharedFunctionInfo* s = v.value; | 13480 const SharedFunctionInfo* s = v.value; |
| 13483 // For some native functions there is no source. | 13481 // For some native functions there is no source. |
| 13484 if (!s->HasSourceCode()) return os << "<No Source>"; | 13482 if (!s->HasSourceCode()) return os << "<No Source>"; |
| (...skipping 5786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19271 Isolate* const isolate = GetIsolate(); | 19269 Isolate* const isolate = GetIsolate(); |
| 19272 if (isolate->IsArrayBufferNeuteringIntact()) { | 19270 if (isolate->IsArrayBufferNeuteringIntact()) { |
| 19273 isolate->InvalidateArrayBufferNeuteringProtector(); | 19271 isolate->InvalidateArrayBufferNeuteringProtector(); |
| 19274 } | 19272 } |
| 19275 } | 19273 } |
| 19276 | 19274 |
| 19277 | 19275 |
| 19278 void JSArrayBuffer::Setup(Handle<JSArrayBuffer> array_buffer, Isolate* isolate, | 19276 void JSArrayBuffer::Setup(Handle<JSArrayBuffer> array_buffer, Isolate* isolate, |
| 19279 bool is_external, void* data, size_t allocated_length, | 19277 bool is_external, void* data, size_t allocated_length, |
| 19280 SharedFlag shared) { | 19278 SharedFlag shared) { |
| 19281 DCHECK(array_buffer->GetInternalFieldCount() == | 19279 DCHECK(array_buffer->GetEmbedderFieldCount() == |
| 19282 v8::ArrayBuffer::kInternalFieldCount); | 19280 v8::ArrayBuffer::kEmbedderFieldCount); |
| 19283 for (int i = 0; i < v8::ArrayBuffer::kInternalFieldCount; i++) { | 19281 for (int i = 0; i < v8::ArrayBuffer::kEmbedderFieldCount; i++) { |
| 19284 array_buffer->SetInternalField(i, Smi::kZero); | 19282 array_buffer->SetEmbedderField(i, Smi::kZero); |
| 19285 } | 19283 } |
| 19286 array_buffer->set_bit_field(0); | 19284 array_buffer->set_bit_field(0); |
| 19287 array_buffer->set_is_external(is_external); | 19285 array_buffer->set_is_external(is_external); |
| 19288 array_buffer->set_is_neuterable(shared == SharedFlag::kNotShared); | 19286 array_buffer->set_is_neuterable(shared == SharedFlag::kNotShared); |
| 19289 array_buffer->set_is_shared(shared == SharedFlag::kShared); | 19287 array_buffer->set_is_shared(shared == SharedFlag::kShared); |
| 19290 | 19288 |
| 19291 Handle<Object> byte_length = | 19289 Handle<Object> byte_length = |
| 19292 isolate->factory()->NewNumberFromSize(allocated_length); | 19290 isolate->factory()->NewNumberFromSize(allocated_length); |
| 19293 CHECK(byte_length->IsSmi() || byte_length->IsHeapNumber()); | 19291 CHECK(byte_length->IsSmi() || byte_length->IsHeapNumber()); |
| 19294 array_buffer->set_byte_length(*byte_length); | 19292 array_buffer->set_byte_length(*byte_length); |
| (...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20234 // depend on this. | 20232 // depend on this. |
| 20235 return DICTIONARY_ELEMENTS; | 20233 return DICTIONARY_ELEMENTS; |
| 20236 } | 20234 } |
| 20237 DCHECK_LE(kind, LAST_ELEMENTS_KIND); | 20235 DCHECK_LE(kind, LAST_ELEMENTS_KIND); |
| 20238 return kind; | 20236 return kind; |
| 20239 } | 20237 } |
| 20240 } | 20238 } |
| 20241 | 20239 |
| 20242 } // namespace internal | 20240 } // namespace internal |
| 20243 } // namespace v8 | 20241 } // namespace v8 |
| OLD | NEW |