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 11896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11907 return true; | 11907 return true; |
11908 } | 11908 } |
11909 | 11909 |
11910 | 11910 |
11911 bool Map::EquivalentToForNormalization(Map* other, | 11911 bool Map::EquivalentToForNormalization(Map* other, |
11912 PropertyNormalizationMode mode) { | 11912 PropertyNormalizationMode mode) { |
11913 int properties = | 11913 int properties = |
11914 mode == CLEAR_INOBJECT_PROPERTIES ? 0 : other->GetInObjectProperties(); | 11914 mode == CLEAR_INOBJECT_PROPERTIES ? 0 : other->GetInObjectProperties(); |
11915 return CheckEquivalent(this, other) && bit_field2() == other->bit_field2() && | 11915 return CheckEquivalent(this, other) && bit_field2() == other->bit_field2() && |
11916 GetInObjectProperties() == properties && | 11916 GetInObjectProperties() == properties && |
11917 JSObject::GetInternalFieldCount(this) == | 11917 JSObject::GetEmbedderFieldCount(this) == |
11918 JSObject::GetInternalFieldCount(other); | 11918 JSObject::GetEmbedderFieldCount(other); |
11919 } | 11919 } |
11920 | 11920 |
11921 | 11921 |
11922 bool JSFunction::Inlines(SharedFunctionInfo* candidate) { | 11922 bool JSFunction::Inlines(SharedFunctionInfo* candidate) { |
11923 DisallowHeapAllocation no_gc; | 11923 DisallowHeapAllocation no_gc; |
11924 if (shared() == candidate) return true; | 11924 if (shared() == candidate) return true; |
11925 if (code()->kind() != Code::OPTIMIZED_FUNCTION) return false; | 11925 if (code()->kind() != Code::OPTIMIZED_FUNCTION) return false; |
11926 DeoptimizationInputData* const data = | 11926 DeoptimizationInputData* const data = |
11927 DeoptimizationInputData::cast(code()->deoptimization_data()); | 11927 DeoptimizationInputData::cast(code()->deoptimization_data()); |
11928 if (data->length() == 0) return false; | 11928 if (data->length() == 0) return false; |
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12785 | 12785 |
12786 // Create a new map with the size and number of in-object properties | 12786 // Create a new map with the size and number of in-object properties |
12787 // suggested by |function|. | 12787 // suggested by |function|. |
12788 | 12788 |
12789 // Link initial map and constructor function if the new.target is actually a | 12789 // Link initial map and constructor function if the new.target is actually a |
12790 // subclass constructor. | 12790 // subclass constructor. |
12791 if (IsDerivedConstructor(function->shared()->kind())) { | 12791 if (IsDerivedConstructor(function->shared()->kind())) { |
12792 Handle<Object> prototype(function->instance_prototype(), isolate); | 12792 Handle<Object> prototype(function->instance_prototype(), isolate); |
12793 InstanceType instance_type = constructor_initial_map->instance_type(); | 12793 InstanceType instance_type = constructor_initial_map->instance_type(); |
12794 DCHECK(CanSubclassHaveInobjectProperties(instance_type)); | 12794 DCHECK(CanSubclassHaveInobjectProperties(instance_type)); |
12795 int internal_fields = | 12795 int embedder_fields = |
12796 JSObject::GetInternalFieldCount(*constructor_initial_map); | 12796 JSObject::GetEmbedderFieldCount(*constructor_initial_map); |
12797 int pre_allocated = constructor_initial_map->GetInObjectProperties() - | 12797 int pre_allocated = constructor_initial_map->GetInObjectProperties() - |
12798 constructor_initial_map->unused_property_fields(); | 12798 constructor_initial_map->unused_property_fields(); |
12799 int instance_size; | 12799 int instance_size; |
12800 int in_object_properties; | 12800 int in_object_properties; |
12801 function->CalculateInstanceSizeForDerivedClass( | 12801 function->CalculateInstanceSizeForDerivedClass( |
12802 instance_type, internal_fields, &instance_size, | 12802 instance_type, embedder_fields, &instance_size, |
12803 &in_object_properties); | 12803 &in_object_properties); |
12804 | 12804 |
12805 int unused_property_fields = in_object_properties - pre_allocated; | 12805 int unused_property_fields = in_object_properties - pre_allocated; |
12806 Handle<Map> map = | 12806 Handle<Map> map = |
12807 Map::CopyInitialMap(constructor_initial_map, instance_size, | 12807 Map::CopyInitialMap(constructor_initial_map, instance_size, |
12808 in_object_properties, unused_property_fields); | 12808 in_object_properties, unused_property_fields); |
12809 map->set_new_target_is_base(false); | 12809 map->set_new_target_is_base(false); |
12810 | 12810 |
12811 JSFunction::SetInitialMap(function, map, prototype); | 12811 JSFunction::SetInitialMap(function, map, prototype); |
12812 map->SetConstructor(*constructor); | 12812 map->SetConstructor(*constructor); |
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13451 if (!script()->IsScript()) return false; | 13451 if (!script()->IsScript()) return false; |
13452 return !optimization_disabled(); | 13452 return !optimization_disabled(); |
13453 } | 13453 } |
13454 | 13454 |
13455 | 13455 |
13456 int SharedFunctionInfo::SourceSize() { | 13456 int SharedFunctionInfo::SourceSize() { |
13457 return end_position() - start_position(); | 13457 return end_position() - start_position(); |
13458 } | 13458 } |
13459 | 13459 |
13460 void JSFunction::CalculateInstanceSizeHelper(InstanceType instance_type, | 13460 void JSFunction::CalculateInstanceSizeHelper(InstanceType instance_type, |
13461 int requested_internal_fields, | 13461 int requested_embedder_fields, |
13462 int requested_in_object_properties, | 13462 int requested_in_object_properties, |
13463 int* instance_size, | 13463 int* instance_size, |
13464 int* in_object_properties) { | 13464 int* in_object_properties) { |
13465 int header_size = JSObject::GetHeaderSize(instance_type); | 13465 int header_size = JSObject::GetHeaderSize(instance_type); |
13466 DCHECK_LE(requested_internal_fields, | 13466 DCHECK_LE(requested_embedder_fields, |
13467 (JSObject::kMaxInstanceSize - header_size) >> kPointerSizeLog2); | 13467 (JSObject::kMaxInstanceSize - header_size) >> kPointerSizeLog2); |
13468 *instance_size = | 13468 *instance_size = |
13469 Min(header_size + | 13469 Min(header_size + |
13470 ((requested_internal_fields + requested_in_object_properties) | 13470 ((requested_embedder_fields + requested_in_object_properties) |
13471 << kPointerSizeLog2), | 13471 << kPointerSizeLog2), |
13472 JSObject::kMaxInstanceSize); | 13472 JSObject::kMaxInstanceSize); |
13473 *in_object_properties = ((*instance_size - header_size) >> kPointerSizeLog2) - | 13473 *in_object_properties = ((*instance_size - header_size) >> kPointerSizeLog2) - |
13474 requested_internal_fields; | 13474 requested_embedder_fields; |
13475 } | 13475 } |
13476 | 13476 |
13477 | |
13478 void JSFunction::CalculateInstanceSize(InstanceType instance_type, | 13477 void JSFunction::CalculateInstanceSize(InstanceType instance_type, |
13479 int requested_internal_fields, | 13478 int requested_embedder_fields, |
13480 int* instance_size, | 13479 int* instance_size, |
13481 int* in_object_properties) { | 13480 int* in_object_properties) { |
13482 CalculateInstanceSizeHelper(instance_type, requested_internal_fields, | 13481 CalculateInstanceSizeHelper(instance_type, requested_embedder_fields, |
13483 shared()->expected_nof_properties(), | 13482 shared()->expected_nof_properties(), |
13484 instance_size, in_object_properties); | 13483 instance_size, in_object_properties); |
13485 } | 13484 } |
13486 | 13485 |
13487 | |
13488 void JSFunction::CalculateInstanceSizeForDerivedClass( | 13486 void JSFunction::CalculateInstanceSizeForDerivedClass( |
13489 InstanceType instance_type, int requested_internal_fields, | 13487 InstanceType instance_type, int requested_embedder_fields, |
13490 int* instance_size, int* in_object_properties) { | 13488 int* instance_size, int* in_object_properties) { |
13491 Isolate* isolate = GetIsolate(); | 13489 Isolate* isolate = GetIsolate(); |
13492 int expected_nof_properties = 0; | 13490 int expected_nof_properties = 0; |
13493 for (PrototypeIterator iter(isolate, this, kStartAtReceiver); !iter.IsAtEnd(); | 13491 for (PrototypeIterator iter(isolate, this, kStartAtReceiver); !iter.IsAtEnd(); |
13494 iter.Advance()) { | 13492 iter.Advance()) { |
13495 JSReceiver* current = iter.GetCurrent<JSReceiver>(); | 13493 JSReceiver* current = iter.GetCurrent<JSReceiver>(); |
13496 if (!current->IsJSFunction()) break; | 13494 if (!current->IsJSFunction()) break; |
13497 JSFunction* func = JSFunction::cast(current); | 13495 JSFunction* func = JSFunction::cast(current); |
13498 SharedFunctionInfo* shared = func->shared(); | 13496 SharedFunctionInfo* shared = func->shared(); |
13499 expected_nof_properties += shared->expected_nof_properties(); | 13497 expected_nof_properties += shared->expected_nof_properties(); |
13500 if (!IsDerivedConstructor(shared->kind())) { | 13498 if (!IsDerivedConstructor(shared->kind())) { |
13501 break; | 13499 break; |
13502 } | 13500 } |
13503 } | 13501 } |
13504 CalculateInstanceSizeHelper(instance_type, requested_internal_fields, | 13502 CalculateInstanceSizeHelper(instance_type, requested_embedder_fields, |
13505 expected_nof_properties, instance_size, | 13503 expected_nof_properties, instance_size, |
13506 in_object_properties); | 13504 in_object_properties); |
13507 } | 13505 } |
13508 | 13506 |
13509 | 13507 |
13510 // Output the source code without any allocation in the heap. | 13508 // Output the source code without any allocation in the heap. |
13511 std::ostream& operator<<(std::ostream& os, const SourceCodeOf& v) { | 13509 std::ostream& operator<<(std::ostream& os, const SourceCodeOf& v) { |
13512 const SharedFunctionInfo* s = v.value; | 13510 const SharedFunctionInfo* s = v.value; |
13513 // For some native functions there is no source. | 13511 // For some native functions there is no source. |
13514 if (!s->HasSourceCode()) return os << "<No Source>"; | 13512 if (!s->HasSourceCode()) return os << "<No Source>"; |
(...skipping 5803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19318 Isolate* const isolate = GetIsolate(); | 19316 Isolate* const isolate = GetIsolate(); |
19319 if (isolate->IsArrayBufferNeuteringIntact()) { | 19317 if (isolate->IsArrayBufferNeuteringIntact()) { |
19320 isolate->InvalidateArrayBufferNeuteringProtector(); | 19318 isolate->InvalidateArrayBufferNeuteringProtector(); |
19321 } | 19319 } |
19322 } | 19320 } |
19323 | 19321 |
19324 | 19322 |
19325 void JSArrayBuffer::Setup(Handle<JSArrayBuffer> array_buffer, Isolate* isolate, | 19323 void JSArrayBuffer::Setup(Handle<JSArrayBuffer> array_buffer, Isolate* isolate, |
19326 bool is_external, void* data, size_t allocated_length, | 19324 bool is_external, void* data, size_t allocated_length, |
19327 SharedFlag shared) { | 19325 SharedFlag shared) { |
19328 DCHECK(array_buffer->GetInternalFieldCount() == | 19326 DCHECK(array_buffer->GetEmbedderFieldCount() == |
19329 v8::ArrayBuffer::kInternalFieldCount); | 19327 v8::ArrayBuffer::kEmbedderFieldCount); |
19330 for (int i = 0; i < v8::ArrayBuffer::kInternalFieldCount; i++) { | 19328 for (int i = 0; i < v8::ArrayBuffer::kEmbedderFieldCount; i++) { |
19331 array_buffer->SetInternalField(i, Smi::kZero); | 19329 array_buffer->SetEmbedderField(i, Smi::kZero); |
19332 } | 19330 } |
19333 array_buffer->set_bit_field(0); | 19331 array_buffer->set_bit_field(0); |
19334 array_buffer->set_is_external(is_external); | 19332 array_buffer->set_is_external(is_external); |
19335 array_buffer->set_is_neuterable(shared == SharedFlag::kNotShared); | 19333 array_buffer->set_is_neuterable(shared == SharedFlag::kNotShared); |
19336 array_buffer->set_is_shared(shared == SharedFlag::kShared); | 19334 array_buffer->set_is_shared(shared == SharedFlag::kShared); |
19337 | 19335 |
19338 Handle<Object> byte_length = | 19336 Handle<Object> byte_length = |
19339 isolate->factory()->NewNumberFromSize(allocated_length); | 19337 isolate->factory()->NewNumberFromSize(allocated_length); |
19340 CHECK(byte_length->IsSmi() || byte_length->IsHeapNumber()); | 19338 CHECK(byte_length->IsSmi() || byte_length->IsHeapNumber()); |
19341 array_buffer->set_byte_length(*byte_length); | 19339 array_buffer->set_byte_length(*byte_length); |
(...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20287 // depend on this. | 20285 // depend on this. |
20288 return DICTIONARY_ELEMENTS; | 20286 return DICTIONARY_ELEMENTS; |
20289 } | 20287 } |
20290 DCHECK_LE(kind, LAST_ELEMENTS_KIND); | 20288 DCHECK_LE(kind, LAST_ELEMENTS_KIND); |
20291 return kind; | 20289 return kind; |
20292 } | 20290 } |
20293 } | 20291 } |
20294 | 20292 |
20295 } // namespace internal | 20293 } // namespace internal |
20296 } // namespace v8 | 20294 } // namespace v8 |
OLD | NEW |