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

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