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

Side by Side Diff: src/hydrogen.cc

Issue 21089006: Allocation space decisions are precisely made in hydrogen. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « src/code-stubs-hydrogen.cc ('k') | src/hydrogen-instructions.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 1306 matching lines...) Expand 10 before | Expand all | Expand 10 after
1317 HConstant* elements_size_value = Add<HConstant>(elements_size); 1317 HConstant* elements_size_value = Add<HConstant>(elements_size);
1318 HValue* mul = AddInstruction( 1318 HValue* mul = AddInstruction(
1319 HMul::New(zone, context, capacity, elements_size_value)); 1319 HMul::New(zone, context, capacity, elements_size_value));
1320 mul->ClearFlag(HValue::kCanOverflow); 1320 mul->ClearFlag(HValue::kCanOverflow);
1321 1321
1322 HConstant* header_size = Add<HConstant>(FixedArray::kHeaderSize); 1322 HConstant* header_size = Add<HConstant>(FixedArray::kHeaderSize);
1323 HValue* total_size = AddInstruction( 1323 HValue* total_size = AddInstruction(
1324 HAdd::New(zone, context, mul, header_size)); 1324 HAdd::New(zone, context, mul, header_size));
1325 total_size->ClearFlag(HValue::kCanOverflow); 1325 total_size->ClearFlag(HValue::kCanOverflow);
1326 1326
1327 HAllocate::Flags flags = HAllocate::DefaultFlags(kind); 1327 return Add<HAllocate>(context, total_size, HType::JSArray(),
1328 if (isolate()->heap()->ShouldGloballyPretenure()) { 1328 isolate()->heap()->ShouldGloballyPretenure(), kind);
1329 // TODO(hpayer): When pretenuring can be internalized, flags can become
1330 // private to HAllocate.
1331 if (IsFastDoubleElementsKind(kind)) {
1332 flags = static_cast<HAllocate::Flags>(
1333 flags | HAllocate::CAN_ALLOCATE_IN_OLD_DATA_SPACE);
1334 } else {
1335 flags = static_cast<HAllocate::Flags>(
1336 flags | HAllocate::CAN_ALLOCATE_IN_OLD_POINTER_SPACE);
1337 }
1338 }
1339
1340 return Add<HAllocate>(context, total_size, HType::JSArray(), flags);
1341 } 1329 }
1342 1330
1343 1331
1344 void HGraphBuilder::BuildInitializeElementsHeader(HValue* elements, 1332 void HGraphBuilder::BuildInitializeElementsHeader(HValue* elements,
1345 ElementsKind kind, 1333 ElementsKind kind,
1346 HValue* capacity) { 1334 HValue* capacity) {
1347 Factory* factory = isolate()->factory(); 1335 Factory* factory = isolate()->factory();
1348 Handle<Map> map = IsFastDoubleElementsKind(kind) 1336 Handle<Map> map = IsFastDoubleElementsKind(kind)
1349 ? factory->fixed_double_array_map() 1337 ? factory->fixed_double_array_map()
1350 : factory->fixed_array_map(); 1338 : factory->fixed_array_map();
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
1661 if (mode == TRACK_ALLOCATION_SITE) { 1649 if (mode == TRACK_ALLOCATION_SITE) {
1662 size += AllocationMemento::kSize; 1650 size += AllocationMemento::kSize;
1663 } 1651 }
1664 int elems_offset = size; 1652 int elems_offset = size;
1665 if (length > 0) { 1653 if (length > 0) {
1666 size += IsFastDoubleElementsKind(kind) 1654 size += IsFastDoubleElementsKind(kind)
1667 ? FixedDoubleArray::SizeFor(length) 1655 ? FixedDoubleArray::SizeFor(length)
1668 : FixedArray::SizeFor(length); 1656 : FixedArray::SizeFor(length);
1669 } 1657 }
1670 1658
1671 HAllocate::Flags allocate_flags = HAllocate::DefaultFlags(kind);
1672 // Allocate both the JS array and the elements array in one big 1659 // Allocate both the JS array and the elements array in one big
1673 // allocation. This avoids multiple limit checks. 1660 // allocation. This avoids multiple limit checks.
1674 HValue* size_in_bytes = Add<HConstant>(size); 1661 HValue* size_in_bytes = Add<HConstant>(size);
1675 HInstruction* object = Add<HAllocate>(context, 1662 HInstruction* object = Add<HAllocate>(context,
1676 size_in_bytes, 1663 size_in_bytes,
1677 HType::JSObject(), 1664 HType::JSObject(),
1678 allocate_flags); 1665 false,
1666 kind);
1679 1667
1680 // Copy the JS array part. 1668 // Copy the JS array part.
1681 for (int i = 0; i < JSArray::kSize; i += kPointerSize) { 1669 for (int i = 0; i < JSArray::kSize; i += kPointerSize) {
1682 if ((i != JSArray::kElementsOffset) || (length == 0)) { 1670 if ((i != JSArray::kElementsOffset) || (length == 0)) {
1683 HObjectAccess access = HObjectAccess::ForJSArrayOffset(i); 1671 HObjectAccess access = HObjectAccess::ForJSArrayOffset(i);
1684 AddStore(object, access, AddLoad(boilerplate, access)); 1672 AddStore(object, access, AddLoad(boilerplate, access));
1685 } 1673 }
1686 } 1674 }
1687 1675
1688 // Create an allocation site info if requested. 1676 // Create an allocation site info if requested.
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1950 1938
1951 // These HForceRepresentations are because we store these as fields in the 1939 // These HForceRepresentations are because we store these as fields in the
1952 // objects we construct, and an int32-to-smi HChange could deopt. Accept 1940 // objects we construct, and an int32-to-smi HChange could deopt. Accept
1953 // the deopt possibility now, before allocation occurs. 1941 // the deopt possibility now, before allocation occurs.
1954 capacity = builder()->Add<HForceRepresentation>(capacity, 1942 capacity = builder()->Add<HForceRepresentation>(capacity,
1955 Representation::Smi()); 1943 Representation::Smi());
1956 length_field = builder()->Add<HForceRepresentation>(length_field, 1944 length_field = builder()->Add<HForceRepresentation>(length_field,
1957 Representation::Smi()); 1945 Representation::Smi());
1958 1946
1959 // Allocate (dealing with failure appropriately) 1947 // Allocate (dealing with failure appropriately)
1960 HAllocate::Flags flags = HAllocate::DefaultFlags(kind_);
1961 HAllocate* new_object = builder()->Add<HAllocate>(context, size_in_bytes, 1948 HAllocate* new_object = builder()->Add<HAllocate>(context, size_in_bytes,
1962 HType::JSArray(), flags); 1949 HType::JSArray(), false, kind_);
1963 1950
1964 // Fill in the fields: map, properties, length 1951 // Fill in the fields: map, properties, length
1965 HValue* map; 1952 HValue* map;
1966 if (allocation_site_payload_ == NULL) { 1953 if (allocation_site_payload_ == NULL) {
1967 map = EmitInternalMapCode(); 1954 map = EmitInternalMapCode();
1968 } else { 1955 } else {
1969 map = EmitMapCode(context); 1956 map = EmitMapCode(context);
1970 } 1957 }
1971 elements_location_ = builder()->BuildJSArrayHeader(new_object, 1958 elements_location_ = builder()->BuildJSArrayHeader(new_object,
1972 map, 1959 map,
(...skipping 2624 matching lines...) Expand 10 before | Expand all | Expand 10 after
4597 HStoreNamedField *instr; 4584 HStoreNamedField *instr;
4598 if (FLAG_track_double_fields && field_access.representation().IsDouble()) { 4585 if (FLAG_track_double_fields && field_access.representation().IsDouble()) {
4599 HObjectAccess heap_number_access = 4586 HObjectAccess heap_number_access =
4600 field_access.WithRepresentation(Representation::Tagged()); 4587 field_access.WithRepresentation(Representation::Tagged());
4601 if (transition_to_field) { 4588 if (transition_to_field) {
4602 // The store requires a mutable HeapNumber to be allocated. 4589 // The store requires a mutable HeapNumber to be allocated.
4603 NoObservableSideEffectsScope no_side_effects(this); 4590 NoObservableSideEffectsScope no_side_effects(this);
4604 HInstruction* heap_number_size = Add<HConstant>(HeapNumber::kSize); 4591 HInstruction* heap_number_size = Add<HConstant>(HeapNumber::kSize);
4605 HInstruction* heap_number = Add<HAllocate>( 4592 HInstruction* heap_number = Add<HAllocate>(
4606 environment()->LookupContext(), heap_number_size, 4593 environment()->LookupContext(), heap_number_size,
4607 HType::HeapNumber(), HAllocate::CAN_ALLOCATE_IN_NEW_SPACE); 4594 HType::HeapNumber(), false);
4608 AddStoreMapConstant(heap_number, isolate()->factory()->heap_number_map()); 4595 AddStoreMapConstant(heap_number, isolate()->factory()->heap_number_map());
4609 AddStore(heap_number, HObjectAccess::ForHeapNumberValue(), value); 4596 AddStore(heap_number, HObjectAccess::ForHeapNumberValue(), value);
4610 instr = new(zone()) HStoreNamedField( 4597 instr = new(zone()) HStoreNamedField(
4611 object, heap_number_access, heap_number); 4598 object, heap_number_access, heap_number);
4612 } else { 4599 } else {
4613 // Already holds a HeapNumber; load the box and write its value field. 4600 // Already holds a HeapNumber; load the box and write its value field.
4614 HInstruction* heap_number = AddLoad(object, heap_number_access); 4601 HInstruction* heap_number = AddLoad(object, heap_number_access);
4615 heap_number->set_type(HType::HeapNumber()); 4602 heap_number->set_type(HType::HeapNumber());
4616 instr = new(zone()) HStoreNamedField(heap_number, 4603 instr = new(zone()) HStoreNamedField(heap_number,
4617 HObjectAccess::ForHeapNumberValue(), value); 4604 HObjectAccess::ForHeapNumberValue(), value);
(...skipping 2615 matching lines...) Expand 10 before | Expand all | Expand 10 after
7233 } 7220 }
7234 7221
7235 // Calculate instance size from initial map of constructor. 7222 // Calculate instance size from initial map of constructor.
7236 ASSERT(constructor->has_initial_map()); 7223 ASSERT(constructor->has_initial_map());
7237 Handle<Map> initial_map(constructor->initial_map()); 7224 Handle<Map> initial_map(constructor->initial_map());
7238 int instance_size = initial_map->instance_size(); 7225 int instance_size = initial_map->instance_size();
7239 ASSERT(initial_map->InitialPropertiesLength() == 0); 7226 ASSERT(initial_map->InitialPropertiesLength() == 0);
7240 7227
7241 // Allocate an instance of the implicit receiver object. 7228 // Allocate an instance of the implicit receiver object.
7242 HValue* size_in_bytes = Add<HConstant>(instance_size); 7229 HValue* size_in_bytes = Add<HConstant>(instance_size);
7243 HAllocate::Flags flags = HAllocate::DefaultFlags(); 7230 bool pretenure = FLAG_pretenuring_call_new &&
7244 if (FLAG_pretenuring_call_new && 7231 isolate()->heap()->ShouldGloballyPretenure();
7245 isolate()->heap()->ShouldGloballyPretenure()) {
7246 flags = static_cast<HAllocate::Flags>(
7247 flags | HAllocate::CAN_ALLOCATE_IN_OLD_POINTER_SPACE);
7248 }
7249 HAllocate* receiver = 7232 HAllocate* receiver =
7250 Add<HAllocate>(context, size_in_bytes, HType::JSObject(), flags); 7233 Add<HAllocate>(context, size_in_bytes, HType::JSObject(), pretenure);
7251 receiver->set_known_initial_map(initial_map); 7234 receiver->set_known_initial_map(initial_map);
7252 7235
7253 // Load the initial map from the constructor. 7236 // Load the initial map from the constructor.
7254 HValue* constructor_value = Add<HConstant>(constructor); 7237 HValue* constructor_value = Add<HConstant>(constructor);
7255 HValue* initial_map_value = 7238 HValue* initial_map_value =
7256 AddLoad(constructor_value, HObjectAccess::ForJSObjectOffset( 7239 AddLoad(constructor_value, HObjectAccess::ForJSObjectOffset(
7257 JSFunction::kPrototypeOrInitialMapOffset)); 7240 JSFunction::kPrototypeOrInitialMapOffset));
7258 7241
7259 // Initialize map and fields of the newly allocated object. 7242 // Initialize map and fields of the newly allocated object.
7260 { NoObservableSideEffectsScope no_effects(this); 7243 { NoObservableSideEffectsScope no_effects(this);
(...skipping 1061 matching lines...) Expand 10 before | Expand all | Expand 10 after
8322 AllocationSiteMode mode) { 8305 AllocationSiteMode mode) {
8323 NoObservableSideEffectsScope no_effects(this); 8306 NoObservableSideEffectsScope no_effects(this);
8324 8307
8325 HInstruction* target = NULL; 8308 HInstruction* target = NULL;
8326 HInstruction* data_target = NULL; 8309 HInstruction* data_target = NULL;
8327 8310
8328 ElementsKind kind = boilerplate_object->map()->elements_kind(); 8311 ElementsKind kind = boilerplate_object->map()->elements_kind();
8329 8312
8330 if (isolate()->heap()->ShouldGloballyPretenure()) { 8313 if (isolate()->heap()->ShouldGloballyPretenure()) {
8331 if (data_size != 0) { 8314 if (data_size != 0) {
8332 HAllocate::Flags data_flags =
8333 static_cast<HAllocate::Flags>(HAllocate::DefaultFlags(kind) |
8334 HAllocate::CAN_ALLOCATE_IN_OLD_DATA_SPACE);
8335 HValue* size_in_bytes = Add<HConstant>(data_size); 8315 HValue* size_in_bytes = Add<HConstant>(data_size);
8336 data_target = Add<HAllocate>(context, size_in_bytes, HType::JSObject(), 8316 data_target = Add<HAllocate>(context, size_in_bytes, HType::JSObject(),
8337 data_flags); 8317 true, FAST_DOUBLE_ELEMENTS);
8338 Handle<Map> free_space_map = isolate()->factory()->free_space_map(); 8318 Handle<Map> free_space_map = isolate()->factory()->free_space_map();
8339 AddStoreMapConstant(data_target, free_space_map); 8319 AddStoreMapConstant(data_target, free_space_map);
8340 HObjectAccess access = 8320 HObjectAccess access =
8341 HObjectAccess::ForJSObjectOffset(FreeSpace::kSizeOffset); 8321 HObjectAccess::ForJSObjectOffset(FreeSpace::kSizeOffset);
8342 AddStore(data_target, access, size_in_bytes); 8322 AddStore(data_target, access, size_in_bytes);
8343 } 8323 }
8344 if (pointer_size != 0) { 8324 if (pointer_size != 0) {
8345 HAllocate::Flags pointer_flags =
8346 static_cast<HAllocate::Flags>(HAllocate::DefaultFlags() |
8347 HAllocate::CAN_ALLOCATE_IN_OLD_POINTER_SPACE);
8348 HValue* size_in_bytes = Add<HConstant>(pointer_size); 8325 HValue* size_in_bytes = Add<HConstant>(pointer_size);
8349 target = Add<HAllocate>(context, size_in_bytes, HType::JSObject(), 8326 target = Add<HAllocate>(context, size_in_bytes, HType::JSObject(),
8350 pointer_flags); 8327 true);
8351 } 8328 }
8352 } else { 8329 } else {
8353 HAllocate::Flags flags = HAllocate::DefaultFlags(kind);
8354 HValue* size_in_bytes = Add<HConstant>(data_size + pointer_size); 8330 HValue* size_in_bytes = Add<HConstant>(data_size + pointer_size);
8355 target = Add<HAllocate>(context, size_in_bytes, HType::JSObject(), flags); 8331 target = Add<HAllocate>(context, size_in_bytes, HType::JSObject(), false,
8332 kind);
8356 } 8333 }
8357 8334
8358 int offset = 0; 8335 int offset = 0;
8359 int data_offset = 0; 8336 int data_offset = 0;
8360 BuildEmitDeepCopy(boilerplate_object, original_boilerplate_object, 8337 BuildEmitDeepCopy(boilerplate_object, original_boilerplate_object,
8361 allocation_site, target, &offset, data_target, 8338 allocation_site, target, &offset, data_target,
8362 &data_offset, mode); 8339 &data_offset, mode);
8363 return target; 8340 return target;
8364 } 8341 }
8365 8342
(...skipping 1575 matching lines...) Expand 10 before | Expand all | Expand 10 after
9941 if (ShouldProduceTraceOutput()) { 9918 if (ShouldProduceTraceOutput()) {
9942 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); 9919 isolate()->GetHTracer()->TraceHydrogen(name(), graph_);
9943 } 9920 }
9944 9921
9945 #ifdef DEBUG 9922 #ifdef DEBUG
9946 graph_->Verify(false); // No full verify. 9923 graph_->Verify(false); // No full verify.
9947 #endif 9924 #endif
9948 } 9925 }
9949 9926
9950 } } // namespace v8::internal 9927 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/code-stubs-hydrogen.cc ('k') | src/hydrogen-instructions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698