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

Side by Side Diff: src/hydrogen.cc

Issue 12880017: Build fast literals in hydrogen. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 8 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/hydrogen.h ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 6158 matching lines...) Expand 10 before | Expand all | Expand 10 after
6169 void HOptimizedGraphBuilder::VisitObjectLiteral(ObjectLiteral* expr) { 6169 void HOptimizedGraphBuilder::VisitObjectLiteral(ObjectLiteral* expr) {
6170 ASSERT(!HasStackOverflow()); 6170 ASSERT(!HasStackOverflow());
6171 ASSERT(current_block() != NULL); 6171 ASSERT(current_block() != NULL);
6172 ASSERT(current_block()->HasPredecessor()); 6172 ASSERT(current_block()->HasPredecessor());
6173 Handle<JSFunction> closure = function_state()->compilation_info()->closure(); 6173 Handle<JSFunction> closure = function_state()->compilation_info()->closure();
6174 HValue* context = environment()->LookupContext(); 6174 HValue* context = environment()->LookupContext();
6175 HInstruction* literal; 6175 HInstruction* literal;
6176 6176
6177 // Check whether to use fast or slow deep-copying for boilerplate. 6177 // Check whether to use fast or slow deep-copying for boilerplate.
6178 int total_size = 0; 6178 int total_size = 0;
6179 int max_properties = HFastLiteral::kMaxLiteralProperties; 6179 int max_properties = kMaxFastLiteralProperties;
6180 Handle<Object> boilerplate(closure->literals()->get(expr->literal_index()), 6180 Handle<Object> original_boilerplate(closure->literals()->get(
6181 isolate()); 6181 expr->literal_index()), isolate());
6182 if (boilerplate->IsJSObject() && 6182 if (original_boilerplate->IsJSObject() &&
6183 IsFastLiteral(Handle<JSObject>::cast(boilerplate), 6183 IsFastLiteral(Handle<JSObject>::cast(original_boilerplate),
6184 HFastLiteral::kMaxLiteralDepth, 6184 kMaxFastLiteralDepth,
6185 &max_properties, 6185 &max_properties,
6186 &total_size)) { 6186 &total_size)) {
6187 Handle<JSObject> boilerplate_object = Handle<JSObject>::cast(boilerplate); 6187 Handle<JSObject> original_boilerplate_object =
6188 literal = new(zone()) HFastLiteral(context, 6188 Handle<JSObject>::cast(original_boilerplate);
6189 boilerplate_object, 6189 Handle<JSObject> boilerplate_object =
6190 total_size, 6190 DeepCopy(original_boilerplate_object);
6191 expr->literal_index(), 6191
6192 expr->depth(), 6192 literal = BuildFastLiteral(context,
6193 DONT_TRACK_ALLOCATION_SITE); 6193 boilerplate_object,
6194 original_boilerplate_object,
6195 total_size,
6196 DONT_TRACK_ALLOCATION_SITE,
6197 environment()->previous_ast_id());
6194 } else { 6198 } else {
6195 literal = new(zone()) HObjectLiteral(context, 6199 literal = AddInstruction(
6196 expr->constant_properties(), 6200 new(zone()) HObjectLiteral(context,
6197 expr->fast_elements(), 6201 expr->constant_properties(),
6198 expr->literal_index(), 6202 expr->fast_elements(),
6199 expr->depth(), 6203 expr->literal_index(),
6200 expr->has_function()); 6204 expr->depth(),
6205 expr->has_function()));
6201 } 6206 }
6202 6207
6203 // The object is expected in the bailout environment during computation 6208 // The object is expected in the bailout environment during computation
6204 // of the property values and is the value of the entire expression. 6209 // of the property values and is the value of the entire expression.
6205 PushAndAdd(literal); 6210 Push(literal);
6206 6211
6207 expr->CalculateEmitStore(zone()); 6212 expr->CalculateEmitStore(zone());
6208 6213
6209 for (int i = 0; i < expr->properties()->length(); i++) { 6214 for (int i = 0; i < expr->properties()->length(); i++) {
6210 ObjectLiteral::Property* property = expr->properties()->at(i); 6215 ObjectLiteral::Property* property = expr->properties()->at(i);
6211 if (property->IsCompileTimeValue()) continue; 6216 if (property->IsCompileTimeValue()) continue;
6212 6217
6213 Literal* key = property->key(); 6218 Literal* key = property->key();
6214 Expression* value = property->value(); 6219 Expression* value = property->value();
6215 6220
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
6292 if (raw_boilerplate.is_null()) { 6297 if (raw_boilerplate.is_null()) {
6293 return Bailout("array boilerplate creation failed"); 6298 return Bailout("array boilerplate creation failed");
6294 } 6299 }
6295 literals->set(expr->literal_index(), *raw_boilerplate); 6300 literals->set(expr->literal_index(), *raw_boilerplate);
6296 if (JSObject::cast(*raw_boilerplate)->elements()->map() == 6301 if (JSObject::cast(*raw_boilerplate)->elements()->map() ==
6297 isolate()->heap()->fixed_cow_array_map()) { 6302 isolate()->heap()->fixed_cow_array_map()) {
6298 isolate()->counters()->cow_arrays_created_runtime()->Increment(); 6303 isolate()->counters()->cow_arrays_created_runtime()->Increment();
6299 } 6304 }
6300 } 6305 }
6301 6306
6302 Handle<JSObject> boilerplate = Handle<JSObject>::cast(raw_boilerplate); 6307 Handle<JSObject> original_boilerplate_object =
6308 Handle<JSObject>::cast(raw_boilerplate);
6303 ElementsKind boilerplate_elements_kind = 6309 ElementsKind boilerplate_elements_kind =
6304 Handle<JSObject>::cast(boilerplate)->GetElementsKind(); 6310 Handle<JSObject>::cast(original_boilerplate_object)->GetElementsKind();
6305 6311
6306 // TODO(mvstanton): This heuristic is only a temporary solution. In the 6312 // TODO(mvstanton): This heuristic is only a temporary solution. In the
6307 // end, we want to quit creating allocation site info after a certain number 6313 // end, we want to quit creating allocation site info after a certain number
6308 // of GCs for a call site. 6314 // of GCs for a call site.
6309 AllocationSiteMode mode = AllocationSiteInfo::GetMode( 6315 AllocationSiteMode mode = AllocationSiteInfo::GetMode(
6310 boilerplate_elements_kind); 6316 boilerplate_elements_kind);
6311 6317
6312 // Check whether to use fast or slow deep-copying for boilerplate. 6318 // Check whether to use fast or slow deep-copying for boilerplate.
6313 int total_size = 0; 6319 int total_size = 0;
6314 int max_properties = HFastLiteral::kMaxLiteralProperties; 6320 int max_properties = kMaxFastLiteralProperties;
6315 if (IsFastLiteral(boilerplate, 6321 if (IsFastLiteral(original_boilerplate_object,
6316 HFastLiteral::kMaxLiteralDepth, 6322 kMaxFastLiteralDepth,
6317 &max_properties, 6323 &max_properties,
6318 &total_size)) { 6324 &total_size)) {
6319 if (mode == TRACK_ALLOCATION_SITE) { 6325 if (mode == TRACK_ALLOCATION_SITE) {
6320 total_size += AllocationSiteInfo::kSize; 6326 total_size += AllocationSiteInfo::kSize;
6321 } 6327 }
6322 literal = new(zone()) HFastLiteral(context, 6328
6323 boilerplate, 6329 Handle<JSObject> boilerplate_object = DeepCopy(original_boilerplate_object);
6324 total_size, 6330 literal = BuildFastLiteral(context,
6325 expr->literal_index(), 6331 boilerplate_object,
6326 expr->depth(), 6332 original_boilerplate_object,
6327 mode); 6333 total_size,
6334 mode,
6335 environment()->previous_ast_id());
6328 } else { 6336 } else {
6329 literal = new(zone()) HArrayLiteral(context, 6337 literal = AddInstruction(
6330 boilerplate, 6338 new(zone()) HArrayLiteral(context,
6331 length, 6339 original_boilerplate_object,
6332 expr->literal_index(), 6340 length,
6333 expr->depth(), 6341 expr->literal_index(),
6334 mode); 6342 expr->depth(),
6343 mode));
6335 } 6344 }
6336 6345
6337 // The array is expected in the bailout environment during computation 6346 // The array is expected in the bailout environment during computation
6338 // of the property values and is the value of the entire expression. 6347 // of the property values and is the value of the entire expression.
6339 PushAndAdd(literal); 6348 Push(literal);
6340 6349
6341 HLoadElements* elements = NULL; 6350 HLoadElements* elements = NULL;
6342 6351
6343 for (int i = 0; i < length; i++) { 6352 for (int i = 0; i < length; i++) {
6344 Expression* subexpr = subexprs->at(i); 6353 Expression* subexpr = subexprs->at(i);
6345 // If the subexpression is a literal or a simple materialized literal it 6354 // If the subexpression is a literal or a simple materialized literal it
6346 // is already set in the cloned array. 6355 // is already set in the cloned array.
6347 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue; 6356 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue;
6348 6357
6349 CHECK_ALIVE(VisitForValue(subexpr)); 6358 CHECK_ALIVE(VisitForValue(subexpr));
(...skipping 3719 matching lines...) Expand 10 before | Expand all | Expand 10 after
10069 if (function_state()->outer() != NULL) { 10078 if (function_state()->outer() != NULL) {
10070 return new(zone()) HConstant( 10079 return new(zone()) HConstant(
10071 function_state()->compilation_info()->closure(), 10080 function_state()->compilation_info()->closure(),
10072 Representation::Tagged()); 10081 Representation::Tagged());
10073 } else { 10082 } else {
10074 return new(zone()) HThisFunction; 10083 return new(zone()) HThisFunction;
10075 } 10084 }
10076 } 10085 }
10077 10086
10078 10087
10088 HInstruction* HOptimizedGraphBuilder::BuildFastLiteral(
10089 HValue* context,
10090 Handle<JSObject> boilerplate_object,
10091 Handle<JSObject> original_boilerplate_object,
10092 int size,
10093 AllocationSiteMode mode,
10094 BailoutId id) {
10095 Zone* zone = this->zone();
10096
10097 HValue* size_in_bytes =
10098 AddInstruction(new(zone) HConstant(size, Representation::Integer32()));
10099 HInstruction* result =
10100 AddInstruction(new(zone) HAllocate(context,
10101 size_in_bytes,
10102 HType::JSObject(),
10103 HAllocate::CAN_ALLOCATE_IN_NEW_SPACE));
10104 int offset = 0;
10105 BuildEmitDeepCopy(boilerplate_object, original_boilerplate_object, result,
10106 &offset, mode, id);
10107 ASSERT_EQ(size, offset);
10108 return result;
10109 }
10110
10111
10112 void HOptimizedGraphBuilder::BuildEmitDeepCopy(
10113 Handle<JSObject> boilerplate_object,
10114 Handle<JSObject> original_boilerplate_object,
10115 HInstruction* target,
10116 int* offset,
10117 AllocationSiteMode mode,
10118 BailoutId id) {
10119 Zone* zone = this->zone();
10120 Factory* factory = isolate()->factory();
10121
10122 HInstruction* original_boilerplate = AddInstruction(new(zone) HConstant(
10123 original_boilerplate_object, Representation::Tagged()));
10124
10125 bool create_allocation_site_info = mode == TRACK_ALLOCATION_SITE &&
10126 boilerplate_object->map()->CanTrackAllocationSite();
10127
10128 // Only elements backing stores for non-COW arrays need to be copied.
10129 Handle<FixedArrayBase> elements(boilerplate_object->elements());
10130 Handle<FixedArrayBase> original_elements(
10131 original_boilerplate_object->elements());
10132 ElementsKind kind = boilerplate_object->map()->elements_kind();
10133
10134 // Increase the offset so that subsequent objects end up right after
10135 // this object and its backing store.
10136 int object_offset = *offset;
10137 int object_size = boilerplate_object->map()->instance_size();
10138 int elements_size = (elements->length() > 0 &&
10139 elements->map() != isolate()->heap()->fixed_cow_array_map()) ?
10140 elements->Size() : 0;
10141 int elements_offset = *offset + object_size;
10142 int inobject_properties = boilerplate_object->map()->inobject_properties();
10143 if (create_allocation_site_info) {
10144 elements_offset += AllocationSiteInfo::kSize;
10145 *offset += AllocationSiteInfo::kSize;
10146 }
10147
10148 *offset += object_size + elements_size;
10149
10150 HValue* object_elements = BuildCopyObjectHeader(boilerplate_object, target,
10151 object_offset, elements_offset, elements_size, id);
10152
10153 // Copy in-object properties.
10154 HValue* object_properties =
10155 AddInstruction(new(zone) HInnerAllocatedObject(target, object_offset));
10156 for (int i = 0; i < inobject_properties; i++) {
10157 Handle<Object> value =
10158 Handle<Object>(boilerplate_object->InObjectPropertyAt(i),
10159 isolate());
10160 if (value->IsJSObject()) {
10161 Handle<JSObject> value_object = Handle<JSObject>::cast(value);
10162 Handle<JSObject> original_value_object = Handle<JSObject>::cast(
10163 Handle<Object>(original_boilerplate_object->InObjectPropertyAt(i),
10164 isolate()));
10165 HInstruction* value_instruction =
10166 AddInstruction(new(zone) HInnerAllocatedObject(target, *offset));
10167 AddInstruction(new(zone) HStoreNamedField(
10168 object_properties, factory->empty_string(), value_instruction, true,
danno 2013/04/10 13:00:33 unknown_field_string
Hannes Payer (out of office) 2013/04/10 13:38:24 Done.
10169 boilerplate_object->GetInObjectPropertyOffset(i)));
10170 AddSimulate(id);
10171 BuildEmitDeepCopy(value_object, original_value_object, target,
10172 offset, DONT_TRACK_ALLOCATION_SITE, id);
10173 } else {
10174 HInstruction* value_instruction = AddInstruction(new(zone) HConstant(
10175 value, Representation::Tagged()));
10176 AddInstruction(new(zone) HStoreNamedField(
10177 object_properties, factory->empty_string(), value_instruction, true,
danno 2013/04/10 13:00:33 unknown_field_string
Hannes Payer (out of office) 2013/04/10 13:38:24 Done.
10178 boilerplate_object->GetInObjectPropertyOffset(i)));
10179 AddSimulate(id);
10180 }
10181 }
10182
10183 // Build Allocation Site Info if desired
10184 if (create_allocation_site_info) {
10185 HValue* alloc_site =
10186 AddInstruction(new(zone) HInnerAllocatedObject(target, JSArray::kSize));
10187 Handle<Map> alloc_site_map(isolate()->heap()->allocation_site_info_map());
10188 BuildStoreMap(alloc_site, alloc_site_map, id);
10189 int alloc_payload_offset = AllocationSiteInfo::kPayloadOffset;
10190 AddInstruction(new(zone) HStoreNamedField(alloc_site,
10191 factory->payload_string(),
10192 original_boilerplate,
10193 true, alloc_payload_offset));
10194 AddSimulate(id);
10195 }
10196
10197 if (object_elements != NULL) {
10198 HInstruction* boilerplate_elements = AddInstruction(new(zone) HConstant(
10199 elements, Representation::Tagged()));
10200
10201 int elements_length = elements->length();
10202 HValue* object_elements_length =
10203 AddInstruction(new(zone) HConstant(
10204 elements_length, Representation::Integer32()));
10205
10206 BuildInitializeElements(object_elements, kind, object_elements_length);
10207
10208 // Copy elements backing store content.
10209 if (elements->IsFixedDoubleArray()) {
10210 for (int i = 0; i < elements_length; i++) {
10211 HValue* key_constant =
10212 AddInstruction(new(zone) HConstant(i, Representation::Integer32()));
10213 HInstruction* value_instruction =
10214 AddInstruction(new(zone) HLoadKeyed(
10215 boilerplate_elements, key_constant, NULL, kind));
10216 AddInstruction(new(zone) HStoreKeyed(
10217 object_elements, key_constant, value_instruction, kind));
10218 AddSimulate(id);
10219 }
10220 } else if (elements->IsFixedArray()) {
10221 Handle<FixedArray> fast_elements = Handle<FixedArray>::cast(elements);
10222 Handle<FixedArray> original_fast_elements =
10223 Handle<FixedArray>::cast(original_elements);
10224 for (int i = 0; i < elements_length; i++) {
10225 Handle<Object> value(fast_elements->get(i), isolate());
10226 HValue* key_constant =
10227 AddInstruction(new(zone) HConstant(i, Representation::Integer32()));
10228 if (value->IsJSObject()) {
10229 Handle<JSObject> value_object = Handle<JSObject>::cast(value);
10230 Handle<JSObject> original_value_object = Handle<JSObject>::cast(
10231 Handle<Object>(original_fast_elements->get(i), isolate()));
10232 HInstruction* value_instruction =
10233 AddInstruction(new(zone) HInnerAllocatedObject(target, *offset));
10234 AddInstruction(new(zone) HStoreKeyed(
10235 object_elements, key_constant, value_instruction, kind));
10236 AddSimulate(id);
10237 BuildEmitDeepCopy(value_object, original_value_object, target,
10238 offset, DONT_TRACK_ALLOCATION_SITE, id);
10239 } else {
10240 HInstruction* value_instruction =
10241 AddInstruction(new(zone) HLoadKeyed(
10242 boilerplate_elements, key_constant, NULL, kind));
10243 AddInstruction(new(zone) HStoreKeyed(
10244 object_elements, key_constant, value_instruction, kind));
10245 AddSimulate(id);
10246 }
10247 }
10248 } else {
10249 UNREACHABLE();
10250 }
10251 }
10252 }
10253
10254
10255 HValue* HOptimizedGraphBuilder::BuildCopyObjectHeader(
10256 Handle<JSObject> boilerplate_object,
10257 HInstruction* target,
10258 int object_offset,
10259 int elements_offset,
10260 int elements_size,
10261 BailoutId id) {
10262 ASSERT(boilerplate_object->properties()->length() == 0);
10263 Zone* zone = this->zone();
10264 Factory* factory = isolate()->factory();
10265 HValue* result = NULL;
10266
10267 HValue* object_header =
10268 AddInstruction(new(zone) HInnerAllocatedObject(target, object_offset));
10269 Handle<Map> boilerplate_object_map(boilerplate_object->map());
10270 BuildStoreMap(object_header, boilerplate_object_map, id);
10271
10272 HInstruction* elements;
10273 if (elements_size == 0) {
10274 Handle<Object> elements_field =
10275 Handle<Object>(boilerplate_object->elements(), isolate());
10276 elements = AddInstruction(new(zone) HConstant(
10277 elements_field, Representation::Tagged()));
10278 } else {
10279 elements = AddInstruction(new(zone) HInnerAllocatedObject(
10280 target, elements_offset));
10281 result = elements;
10282 }
10283 HInstruction* elements_store = AddInstruction(new(zone) HStoreNamedField(
10284 object_header,
10285 factory->elements_field_string(),
10286 elements,
10287 true, JSObject::kElementsOffset));
10288 elements_store->SetGVNFlag(kChangesElementsPointer);
10289 AddSimulate(id);
10290
10291 Handle<Object> properties_field =
10292 Handle<Object>(boilerplate_object->properties(), isolate());
10293 HInstruction* properties = AddInstruction(new(zone) HConstant(
10294 properties_field, Representation::None()));
danno 2013/04/10 13:00:33 Are you guaranteed to not have out-of line propert
Hannes Payer (out of office) 2013/04/10 13:38:24 Done.
10295 AddInstruction(new(zone) HStoreNamedField(object_header,
10296 factory->empty_string(),
10297 properties,
10298 true, JSObject::kPropertiesOffset));
10299 AddSimulate(id);
10300
10301 if (boilerplate_object->IsJSArray()) {
10302 Handle<JSArray> boilerplate_array =
10303 Handle<JSArray>::cast(boilerplate_object);
10304 Handle<Object> length_field =
10305 Handle<Object>(boilerplate_array->length(), isolate());
10306 HInstruction* length = AddInstruction(new(zone) HConstant(
10307 length_field, Representation::None()));
10308 HInstruction* length_store = AddInstruction(new(zone) HStoreNamedField(
10309 object_header,
10310 factory->length_field_string(),
10311 length,
10312 true, JSArray::kLengthOffset));
10313 length_store->SetGVNFlag(kChangesArrayLengths);
10314 AddSimulate(id);
10315 }
10316
10317 return result;
10318 }
10319
10320
10079 void HOptimizedGraphBuilder::VisitThisFunction(ThisFunction* expr) { 10321 void HOptimizedGraphBuilder::VisitThisFunction(ThisFunction* expr) {
10080 ASSERT(!HasStackOverflow()); 10322 ASSERT(!HasStackOverflow());
10081 ASSERT(current_block() != NULL); 10323 ASSERT(current_block() != NULL);
10082 ASSERT(current_block()->HasPredecessor()); 10324 ASSERT(current_block()->HasPredecessor());
10083 HInstruction* instr = BuildThisFunction(); 10325 HInstruction* instr = BuildThisFunction();
10084 return ast_context()->ReturnInstruction(instr, expr->id()); 10326 return ast_context()->ReturnInstruction(instr, expr->id());
10085 } 10327 }
10086 10328
10087 10329
10088 void HOptimizedGraphBuilder::VisitDeclarations( 10330 void HOptimizedGraphBuilder::VisitDeclarations(
(...skipping 1329 matching lines...) Expand 10 before | Expand all | Expand 10 after
11418 } 11660 }
11419 } 11661 }
11420 11662
11421 #ifdef DEBUG 11663 #ifdef DEBUG
11422 if (graph_ != NULL) graph_->Verify(false); // No full verify. 11664 if (graph_ != NULL) graph_->Verify(false); // No full verify.
11423 if (allocator_ != NULL) allocator_->Verify(); 11665 if (allocator_ != NULL) allocator_->Verify();
11424 #endif 11666 #endif
11425 } 11667 }
11426 11668
11427 } } // namespace v8::internal 11669 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen.h ('k') | src/hydrogen-instructions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698