OLD | NEW |
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 1294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1305 } | 1305 } |
1306 return AddFastElementAccess(elements, checked_key, val, mapcheck, | 1306 return AddFastElementAccess(elements, checked_key, val, mapcheck, |
1307 elements_kind, is_store, load_mode, store_mode); | 1307 elements_kind, is_store, load_mode, store_mode); |
1308 } | 1308 } |
1309 | 1309 |
1310 | 1310 |
1311 HValue* HGraphBuilder::BuildAllocateElements(HValue* context, | 1311 HValue* HGraphBuilder::BuildAllocateElements(HValue* context, |
1312 ElementsKind kind, | 1312 ElementsKind kind, |
1313 HValue* capacity) { | 1313 HValue* capacity) { |
1314 Zone* zone = this->zone(); | 1314 Zone* zone = this->zone(); |
| 1315 int elements_size; |
| 1316 InstanceType instance_type; |
1315 | 1317 |
1316 int elements_size = IsFastDoubleElementsKind(kind) | 1318 if (IsFastDoubleElementsKind(kind)) { |
1317 ? kDoubleSize : kPointerSize; | 1319 elements_size = kDoubleSize; |
| 1320 instance_type = FIXED_DOUBLE_ARRAY_TYPE; |
| 1321 } else { |
| 1322 elements_size = kPointerSize; |
| 1323 instance_type = FIXED_ARRAY_TYPE; |
| 1324 } |
| 1325 |
1318 HConstant* elements_size_value = Add<HConstant>(elements_size); | 1326 HConstant* elements_size_value = Add<HConstant>(elements_size); |
1319 HValue* mul = AddInstruction( | 1327 HValue* mul = AddInstruction( |
1320 HMul::New(zone, context, capacity, elements_size_value)); | 1328 HMul::New(zone, context, capacity, elements_size_value)); |
1321 mul->ClearFlag(HValue::kCanOverflow); | 1329 mul->ClearFlag(HValue::kCanOverflow); |
1322 | 1330 |
1323 HConstant* header_size = Add<HConstant>(FixedArray::kHeaderSize); | 1331 HConstant* header_size = Add<HConstant>(FixedArray::kHeaderSize); |
1324 HValue* total_size = AddInstruction( | 1332 HValue* total_size = AddInstruction( |
1325 HAdd::New(zone, context, mul, header_size)); | 1333 HAdd::New(zone, context, mul, header_size)); |
1326 total_size->ClearFlag(HValue::kCanOverflow); | 1334 total_size->ClearFlag(HValue::kCanOverflow); |
1327 | 1335 |
1328 return Add<HAllocate>(context, total_size, HType::JSArray(), | 1336 return Add<HAllocate>(context, total_size, HType::JSArray(), |
1329 isolate()->heap()->ShouldGloballyPretenure(), kind); | 1337 isolate()->heap()->GetAllocationMode(), instance_type); |
1330 } | 1338 } |
1331 | 1339 |
1332 | 1340 |
1333 void HGraphBuilder::BuildInitializeElementsHeader(HValue* elements, | 1341 void HGraphBuilder::BuildInitializeElementsHeader(HValue* elements, |
1334 ElementsKind kind, | 1342 ElementsKind kind, |
1335 HValue* capacity) { | 1343 HValue* capacity) { |
1336 Factory* factory = isolate()->factory(); | 1344 Factory* factory = isolate()->factory(); |
1337 Handle<Map> map = IsFastDoubleElementsKind(kind) | 1345 Handle<Map> map = IsFastDoubleElementsKind(kind) |
1338 ? factory->fixed_double_array_map() | 1346 ? factory->fixed_double_array_map() |
1339 : factory->fixed_array_map(); | 1347 : factory->fixed_array_map(); |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1644 ElementsKind kind, | 1652 ElementsKind kind, |
1645 int length) { | 1653 int length) { |
1646 NoObservableSideEffectsScope no_effects(this); | 1654 NoObservableSideEffectsScope no_effects(this); |
1647 | 1655 |
1648 // All sizes here are multiples of kPointerSize. | 1656 // All sizes here are multiples of kPointerSize. |
1649 int size = JSArray::kSize; | 1657 int size = JSArray::kSize; |
1650 if (mode == TRACK_ALLOCATION_SITE) { | 1658 if (mode == TRACK_ALLOCATION_SITE) { |
1651 size += AllocationMemento::kSize; | 1659 size += AllocationMemento::kSize; |
1652 } | 1660 } |
1653 int elems_offset = size; | 1661 int elems_offset = size; |
| 1662 InstanceType instance_type = FIXED_ARRAY_TYPE; |
1654 if (length > 0) { | 1663 if (length > 0) { |
1655 size += IsFastDoubleElementsKind(kind) | 1664 if (IsFastDoubleElementsKind(kind)) { |
1656 ? FixedDoubleArray::SizeFor(length) | 1665 size += FixedDoubleArray::SizeFor(length); |
1657 : FixedArray::SizeFor(length); | 1666 instance_type = FIXED_DOUBLE_ARRAY_TYPE; |
| 1667 } else { |
| 1668 size += FixedArray::SizeFor(length); |
| 1669 } |
1658 } | 1670 } |
1659 | 1671 |
1660 // Allocate both the JS array and the elements array in one big | 1672 // Allocate both the JS array and the elements array in one big |
1661 // allocation. This avoids multiple limit checks. | 1673 // allocation. This avoids multiple limit checks. |
1662 HValue* size_in_bytes = Add<HConstant>(size); | 1674 HValue* size_in_bytes = Add<HConstant>(size); |
1663 HInstruction* object = Add<HAllocate>(context, | 1675 HInstruction* object = Add<HAllocate>(context, |
1664 size_in_bytes, | 1676 size_in_bytes, |
1665 HType::JSObject(), | 1677 HType::JSObject(), |
1666 false, | 1678 NEW_SPACE_ALLOCATION, |
1667 kind); | 1679 instance_type); |
1668 | 1680 |
1669 // Copy the JS array part. | 1681 // Copy the JS array part. |
1670 for (int i = 0; i < JSArray::kSize; i += kPointerSize) { | 1682 for (int i = 0; i < JSArray::kSize; i += kPointerSize) { |
1671 if ((i != JSArray::kElementsOffset) || (length == 0)) { | 1683 if ((i != JSArray::kElementsOffset) || (length == 0)) { |
1672 HObjectAccess access = HObjectAccess::ForJSArrayOffset(i); | 1684 HObjectAccess access = HObjectAccess::ForJSArrayOffset(i); |
1673 AddStore(object, access, AddLoad(boilerplate, access)); | 1685 AddStore(object, access, AddLoad(boilerplate, access)); |
1674 } | 1686 } |
1675 } | 1687 } |
1676 | 1688 |
1677 // Create an allocation site info if requested. | 1689 // Create an allocation site info if requested. |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1940 // These HForceRepresentations are because we store these as fields in the | 1952 // These HForceRepresentations are because we store these as fields in the |
1941 // objects we construct, and an int32-to-smi HChange could deopt. Accept | 1953 // objects we construct, and an int32-to-smi HChange could deopt. Accept |
1942 // the deopt possibility now, before allocation occurs. | 1954 // the deopt possibility now, before allocation occurs. |
1943 capacity = builder()->Add<HForceRepresentation>(capacity, | 1955 capacity = builder()->Add<HForceRepresentation>(capacity, |
1944 Representation::Smi()); | 1956 Representation::Smi()); |
1945 length_field = builder()->Add<HForceRepresentation>(length_field, | 1957 length_field = builder()->Add<HForceRepresentation>(length_field, |
1946 Representation::Smi()); | 1958 Representation::Smi()); |
1947 | 1959 |
1948 // Allocate (dealing with failure appropriately) | 1960 // Allocate (dealing with failure appropriately) |
1949 HAllocate* new_object = builder()->Add<HAllocate>(context, size_in_bytes, | 1961 HAllocate* new_object = builder()->Add<HAllocate>(context, size_in_bytes, |
1950 HType::JSArray(), false, kind_); | 1962 HType::JSArray(), NEW_SPACE_ALLOCATION, JS_ARRAY_TYPE); |
1951 | 1963 |
1952 // Fill in the fields: map, properties, length | 1964 // Fill in the fields: map, properties, length |
1953 HValue* map; | 1965 HValue* map; |
1954 if (allocation_site_payload_ == NULL) { | 1966 if (allocation_site_payload_ == NULL) { |
1955 map = EmitInternalMapCode(); | 1967 map = EmitInternalMapCode(); |
1956 } else { | 1968 } else { |
1957 map = EmitMapCode(context); | 1969 map = EmitMapCode(context); |
1958 } | 1970 } |
1959 elements_location_ = builder()->BuildJSArrayHeader(new_object, | 1971 elements_location_ = builder()->BuildJSArrayHeader(new_object, |
1960 map, | 1972 map, |
(...skipping 2583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4544 | 4556 |
4545 HStoreNamedField *instr; | 4557 HStoreNamedField *instr; |
4546 if (FLAG_track_double_fields && field_access.representation().IsDouble()) { | 4558 if (FLAG_track_double_fields && field_access.representation().IsDouble()) { |
4547 HObjectAccess heap_number_access = | 4559 HObjectAccess heap_number_access = |
4548 field_access.WithRepresentation(Representation::Tagged()); | 4560 field_access.WithRepresentation(Representation::Tagged()); |
4549 if (transition_to_field) { | 4561 if (transition_to_field) { |
4550 // The store requires a mutable HeapNumber to be allocated. | 4562 // The store requires a mutable HeapNumber to be allocated. |
4551 NoObservableSideEffectsScope no_side_effects(this); | 4563 NoObservableSideEffectsScope no_side_effects(this); |
4552 HInstruction* heap_number_size = Add<HConstant>(HeapNumber::kSize); | 4564 HInstruction* heap_number_size = Add<HConstant>(HeapNumber::kSize); |
4553 HInstruction* heap_number = Add<HAllocate>( | 4565 HInstruction* heap_number = Add<HAllocate>( |
4554 environment()->LookupContext(), heap_number_size, | 4566 environment()->LookupContext(), heap_number_size, HType::HeapNumber(), |
4555 HType::HeapNumber(), false); | 4567 NEW_SPACE_ALLOCATION, HEAP_NUMBER_TYPE); |
4556 AddStoreMapConstant(heap_number, isolate()->factory()->heap_number_map()); | 4568 AddStoreMapConstant(heap_number, isolate()->factory()->heap_number_map()); |
4557 AddStore(heap_number, HObjectAccess::ForHeapNumberValue(), value); | 4569 AddStore(heap_number, HObjectAccess::ForHeapNumberValue(), value); |
4558 instr = new(zone()) HStoreNamedField( | 4570 instr = new(zone()) HStoreNamedField( |
4559 object, heap_number_access, heap_number); | 4571 object, heap_number_access, heap_number); |
4560 } else { | 4572 } else { |
4561 // Already holds a HeapNumber; load the box and write its value field. | 4573 // Already holds a HeapNumber; load the box and write its value field. |
4562 HInstruction* heap_number = AddLoad(object, heap_number_access); | 4574 HInstruction* heap_number = AddLoad(object, heap_number_access); |
4563 heap_number->set_type(HType::HeapNumber()); | 4575 heap_number->set_type(HType::HeapNumber()); |
4564 instr = new(zone()) HStoreNamedField(heap_number, | 4576 instr = new(zone()) HStoreNamedField(heap_number, |
4565 HObjectAccess::ForHeapNumberValue(), value); | 4577 HObjectAccess::ForHeapNumberValue(), value); |
(...skipping 2560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7126 } | 7138 } |
7127 | 7139 |
7128 // Calculate instance size from initial map of constructor. | 7140 // Calculate instance size from initial map of constructor. |
7129 ASSERT(constructor->has_initial_map()); | 7141 ASSERT(constructor->has_initial_map()); |
7130 Handle<Map> initial_map(constructor->initial_map()); | 7142 Handle<Map> initial_map(constructor->initial_map()); |
7131 int instance_size = initial_map->instance_size(); | 7143 int instance_size = initial_map->instance_size(); |
7132 ASSERT(initial_map->InitialPropertiesLength() == 0); | 7144 ASSERT(initial_map->InitialPropertiesLength() == 0); |
7133 | 7145 |
7134 // Allocate an instance of the implicit receiver object. | 7146 // Allocate an instance of the implicit receiver object. |
7135 HValue* size_in_bytes = Add<HConstant>(instance_size); | 7147 HValue* size_in_bytes = Add<HConstant>(instance_size); |
7136 bool pretenure = FLAG_pretenuring_call_new && | 7148 AllocationMode allocation_mode = FLAG_pretenuring_call_new && |
7137 isolate()->heap()->ShouldGloballyPretenure(); | 7149 isolate()->heap()->GetAllocationMode() == OLD_SPACE_ALLOCATION ? |
| 7150 OLD_SPACE_ALLOCATION : NEW_SPACE_ALLOCATION; |
7138 HAllocate* receiver = | 7151 HAllocate* receiver = |
7139 Add<HAllocate>(context, size_in_bytes, HType::JSObject(), pretenure); | 7152 Add<HAllocate>(context, size_in_bytes, HType::JSObject(), |
| 7153 allocation_mode, JS_OBJECT_TYPE); |
7140 receiver->set_known_initial_map(initial_map); | 7154 receiver->set_known_initial_map(initial_map); |
7141 | 7155 |
7142 // Load the initial map from the constructor. | 7156 // Load the initial map from the constructor. |
7143 HValue* constructor_value = Add<HConstant>(constructor); | 7157 HValue* constructor_value = Add<HConstant>(constructor); |
7144 HValue* initial_map_value = | 7158 HValue* initial_map_value = |
7145 AddLoad(constructor_value, HObjectAccess::ForJSObjectOffset( | 7159 AddLoad(constructor_value, HObjectAccess::ForJSObjectOffset( |
7146 JSFunction::kPrototypeOrInitialMapOffset)); | 7160 JSFunction::kPrototypeOrInitialMapOffset)); |
7147 | 7161 |
7148 // Initialize map and fields of the newly allocated object. | 7162 // Initialize map and fields of the newly allocated object. |
7149 { NoObservableSideEffectsScope no_effects(this); | 7163 { NoObservableSideEffectsScope no_effects(this); |
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8207 Handle<JSObject> original_boilerplate_object, | 8221 Handle<JSObject> original_boilerplate_object, |
8208 Handle<Object> allocation_site, | 8222 Handle<Object> allocation_site, |
8209 int data_size, | 8223 int data_size, |
8210 int pointer_size, | 8224 int pointer_size, |
8211 AllocationSiteMode mode) { | 8225 AllocationSiteMode mode) { |
8212 NoObservableSideEffectsScope no_effects(this); | 8226 NoObservableSideEffectsScope no_effects(this); |
8213 | 8227 |
8214 HInstruction* target = NULL; | 8228 HInstruction* target = NULL; |
8215 HInstruction* data_target = NULL; | 8229 HInstruction* data_target = NULL; |
8216 | 8230 |
8217 ElementsKind kind = boilerplate_object->map()->elements_kind(); | 8231 if (isolate()->heap()->GetAllocationMode() == OLD_SPACE_ALLOCATION) { |
8218 | |
8219 if (isolate()->heap()->ShouldGloballyPretenure()) { | |
8220 if (data_size != 0) { | 8232 if (data_size != 0) { |
8221 HValue* size_in_bytes = Add<HConstant>(data_size); | 8233 HValue* size_in_bytes = Add<HConstant>(data_size); |
8222 data_target = Add<HAllocate>(context, size_in_bytes, HType::JSObject(), | 8234 data_target = Add<HAllocate>(context, size_in_bytes, HType::JSObject(), |
8223 true, FAST_DOUBLE_ELEMENTS); | 8235 OLD_SPACE_ALLOCATION, FIXED_DOUBLE_ARRAY_TYPE); |
8224 Handle<Map> free_space_map = isolate()->factory()->free_space_map(); | 8236 Handle<Map> free_space_map = isolate()->factory()->free_space_map(); |
8225 AddStoreMapConstant(data_target, free_space_map); | 8237 AddStoreMapConstant(data_target, free_space_map); |
8226 HObjectAccess access = | 8238 HObjectAccess access = |
8227 HObjectAccess::ForJSObjectOffset(FreeSpace::kSizeOffset); | 8239 HObjectAccess::ForJSObjectOffset(FreeSpace::kSizeOffset); |
8228 AddStore(data_target, access, size_in_bytes); | 8240 AddStore(data_target, access, size_in_bytes); |
8229 } | 8241 } |
8230 if (pointer_size != 0) { | 8242 if (pointer_size != 0) { |
8231 HValue* size_in_bytes = Add<HConstant>(pointer_size); | 8243 HValue* size_in_bytes = Add<HConstant>(pointer_size); |
8232 target = Add<HAllocate>(context, size_in_bytes, HType::JSObject(), | 8244 target = Add<HAllocate>(context, size_in_bytes, HType::JSObject(), |
8233 true); | 8245 OLD_SPACE_ALLOCATION, JS_OBJECT_TYPE); |
8234 } | 8246 } |
8235 } else { | 8247 } else { |
| 8248 InstanceType instance_type = boilerplate_object->map()->instance_type(); |
8236 HValue* size_in_bytes = Add<HConstant>(data_size + pointer_size); | 8249 HValue* size_in_bytes = Add<HConstant>(data_size + pointer_size); |
8237 target = Add<HAllocate>(context, size_in_bytes, HType::JSObject(), false, | 8250 target = Add<HAllocate>(context, size_in_bytes, HType::JSObject(), |
8238 kind); | 8251 NEW_SPACE_ALLOCATION, instance_type); |
8239 } | 8252 } |
8240 | 8253 |
8241 int offset = 0; | 8254 int offset = 0; |
8242 int data_offset = 0; | 8255 int data_offset = 0; |
8243 BuildEmitDeepCopy(boilerplate_object, original_boilerplate_object, | 8256 BuildEmitDeepCopy(boilerplate_object, original_boilerplate_object, |
8244 allocation_site, target, &offset, data_target, | 8257 allocation_site, target, &offset, data_target, |
8245 &data_offset, mode); | 8258 &data_offset, mode); |
8246 return target; | 8259 return target; |
8247 } | 8260 } |
8248 | 8261 |
(...skipping 1575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9824 if (ShouldProduceTraceOutput()) { | 9837 if (ShouldProduceTraceOutput()) { |
9825 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); | 9838 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); |
9826 } | 9839 } |
9827 | 9840 |
9828 #ifdef DEBUG | 9841 #ifdef DEBUG |
9829 graph_->Verify(false); // No full verify. | 9842 graph_->Verify(false); // No full verify. |
9830 #endif | 9843 #endif |
9831 } | 9844 } |
9832 | 9845 |
9833 } } // namespace v8::internal | 9846 } } // namespace v8::internal |
OLD | NEW |