OLD | NEW |
---|---|
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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 MULTIPLE | 92 MULTIPLE |
93 }; | 93 }; |
94 | 94 |
95 HValue* BuildArrayConstructor(ElementsKind kind, | 95 HValue* BuildArrayConstructor(ElementsKind kind, |
96 AllocationSiteOverrideMode override_mode, | 96 AllocationSiteOverrideMode override_mode, |
97 ArgumentClass argument_class); | 97 ArgumentClass argument_class); |
98 HValue* BuildInternalArrayConstructor(ElementsKind kind, | 98 HValue* BuildInternalArrayConstructor(ElementsKind kind, |
99 ArgumentClass argument_class); | 99 ArgumentClass argument_class); |
100 | 100 |
101 void BuildInstallOptimizedCode(HValue* js_function, HValue* native_context, | 101 void BuildInstallOptimizedCode(HValue* js_function, HValue* native_context, |
102 HValue* code_object); | 102 HValue* code_object, HValue* literals); |
103 void BuildInstallCode(HValue* js_function, HValue* shared_info); | 103 void BuildInstallCode(HValue* js_function, HValue* shared_info); |
104 | |
105 HInstruction* LoadFromOptimizedCodeMap(HValue* optimized_map, | |
106 HValue* iterator, | |
107 int field_offset); | |
104 void BuildInstallFromOptimizedCodeMap(HValue* js_function, | 108 void BuildInstallFromOptimizedCodeMap(HValue* js_function, |
105 HValue* shared_info, | 109 HValue* shared_info, |
106 HValue* native_context); | 110 HValue* native_context); |
107 | 111 |
108 private: | 112 private: |
109 HValue* BuildArraySingleArgumentConstructor(JSArrayBuilder* builder); | 113 HValue* BuildArraySingleArgumentConstructor(JSArrayBuilder* builder); |
110 HValue* BuildArrayNArgumentsConstructor(JSArrayBuilder* builder, | 114 HValue* BuildArrayNArgumentsConstructor(JSArrayBuilder* builder, |
111 ElementsKind kind); | 115 ElementsKind kind); |
112 | 116 |
113 SmartArrayPointer<HParameter*> parameters_; | 117 SmartArrayPointer<HParameter*> parameters_; |
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1121 | 1125 |
1122 | 1126 |
1123 Handle<Code> ElementsTransitionAndStoreStub::GenerateCode(Isolate* isolate) { | 1127 Handle<Code> ElementsTransitionAndStoreStub::GenerateCode(Isolate* isolate) { |
1124 return DoGenerateCode(isolate, this); | 1128 return DoGenerateCode(isolate, this); |
1125 } | 1129 } |
1126 | 1130 |
1127 | 1131 |
1128 void CodeStubGraphBuilderBase::BuildInstallOptimizedCode( | 1132 void CodeStubGraphBuilderBase::BuildInstallOptimizedCode( |
1129 HValue* js_function, | 1133 HValue* js_function, |
1130 HValue* native_context, | 1134 HValue* native_context, |
1131 HValue* code_object) { | 1135 HValue* code_object, |
1136 HValue* literals) { | |
1132 Counters* counters = isolate()->counters(); | 1137 Counters* counters = isolate()->counters(); |
1133 AddIncrementCounter(counters->fast_new_closure_install_optimized()); | 1138 AddIncrementCounter(counters->fast_new_closure_install_optimized()); |
1134 | 1139 |
1135 // TODO(fschneider): Idea: store proper code pointers in the optimized code | 1140 // TODO(fschneider): Idea: store proper code pointers in the optimized code |
1136 // map and either unmangle them on marking or do nothing as the whole map is | 1141 // map and either unmangle them on marking or do nothing as the whole map is |
1137 // discarded on major GC anyway. | 1142 // discarded on major GC anyway. |
1138 Add<HStoreCodeEntry>(js_function, code_object); | 1143 Add<HStoreCodeEntry>(js_function, code_object); |
1144 Add<HStoreNamedField>(js_function, HObjectAccess::ForLiteralsPointer(), | |
1145 literals); | |
1139 | 1146 |
1140 // Now link a function into a list of optimized functions. | 1147 // Now link a function into a list of optimized functions. |
1141 HValue* optimized_functions_list = Add<HLoadNamedField>( | 1148 HValue* optimized_functions_list = Add<HLoadNamedField>( |
1142 native_context, static_cast<HValue*>(NULL), | 1149 native_context, static_cast<HValue*>(NULL), |
1143 HObjectAccess::ForContextSlot(Context::OPTIMIZED_FUNCTIONS_LIST)); | 1150 HObjectAccess::ForContextSlot(Context::OPTIMIZED_FUNCTIONS_LIST)); |
1144 Add<HStoreNamedField>(js_function, | 1151 Add<HStoreNamedField>(js_function, |
1145 HObjectAccess::ForNextFunctionLinkPointer(), | 1152 HObjectAccess::ForNextFunctionLinkPointer(), |
1146 optimized_functions_list); | 1153 optimized_functions_list); |
1147 | 1154 |
1148 // This store is the only one that should have a write barrier. | 1155 // This store is the only one that should have a write barrier. |
1149 Add<HStoreNamedField>(native_context, | 1156 Add<HStoreNamedField>(native_context, |
1150 HObjectAccess::ForContextSlot(Context::OPTIMIZED_FUNCTIONS_LIST), | 1157 HObjectAccess::ForContextSlot(Context::OPTIMIZED_FUNCTIONS_LIST), |
1151 js_function); | 1158 js_function); |
1152 } | 1159 } |
1153 | 1160 |
1154 | 1161 |
1155 void CodeStubGraphBuilderBase::BuildInstallCode(HValue* js_function, | 1162 void CodeStubGraphBuilderBase::BuildInstallCode(HValue* js_function, |
1156 HValue* shared_info) { | 1163 HValue* shared_info) { |
1157 Add<HStoreNamedField>(js_function, | 1164 Add<HStoreNamedField>(js_function, |
1158 HObjectAccess::ForNextFunctionLinkPointer(), | 1165 HObjectAccess::ForNextFunctionLinkPointer(), |
1159 graph()->GetConstantUndefined()); | 1166 graph()->GetConstantUndefined()); |
1160 HValue* code_object = Add<HLoadNamedField>( | 1167 HValue* code_object = Add<HLoadNamedField>( |
1161 shared_info, static_cast<HValue*>(NULL), HObjectAccess::ForCodeOffset()); | 1168 shared_info, static_cast<HValue*>(NULL), HObjectAccess::ForCodeOffset()); |
1162 Add<HStoreCodeEntry>(js_function, code_object); | 1169 Add<HStoreCodeEntry>(js_function, code_object); |
1163 } | 1170 } |
1164 | 1171 |
1165 | 1172 |
1173 HInstruction* CodeStubGraphBuilderBase::LoadFromOptimizedCodeMap( | |
1174 HValue* optimized_map, | |
1175 HValue* iterator, | |
1176 int field_offset) { | |
1177 // By making sure to express these loads in the form [<hvalue> + constant] | |
1178 // the keyed load can be hoisted. | |
1179 ASSERT(field_offset >= 0 && field_offset < SharedFunctionInfo::kEntryLength); | |
1180 HValue* field_slot = iterator; | |
1181 if (field_offset > 0) { | |
1182 HValue* field_offset_value = Add<HConstant>(field_offset); | |
1183 field_slot = AddUncasted<HAdd>(iterator, field_offset_value); | |
1184 } | |
1185 HInstruction* field_entry = Add<HLoadKeyed>(optimized_map, field_slot, | |
1186 static_cast<HValue*>(NULL), FAST_ELEMENTS); | |
1187 return field_entry; | |
1188 } | |
1189 | |
1190 | |
1166 void CodeStubGraphBuilderBase::BuildInstallFromOptimizedCodeMap( | 1191 void CodeStubGraphBuilderBase::BuildInstallFromOptimizedCodeMap( |
1167 HValue* js_function, | 1192 HValue* js_function, |
1168 HValue* shared_info, | 1193 HValue* shared_info, |
1169 HValue* native_context) { | 1194 HValue* native_context) { |
1170 Counters* counters = isolate()->counters(); | 1195 Counters* counters = isolate()->counters(); |
1171 IfBuilder is_optimized(this); | 1196 IfBuilder is_optimized(this); |
1172 HInstruction* optimized_map = Add<HLoadNamedField>( | 1197 HInstruction* optimized_map = Add<HLoadNamedField>( |
1173 shared_info, static_cast<HValue*>(NULL), | 1198 shared_info, static_cast<HValue*>(NULL), |
1174 HObjectAccess::ForOptimizedCodeMap()); | 1199 HObjectAccess::ForOptimizedCodeMap()); |
1175 HValue* null_constant = Add<HConstant>(0); | 1200 HValue* null_constant = Add<HConstant>(0); |
(...skipping 19 matching lines...) Expand all Loading... | |
1195 IfBuilder already_in(this); | 1220 IfBuilder already_in(this); |
1196 already_in.If<HCompareObjectEqAndBranch>(native_context, | 1221 already_in.If<HCompareObjectEqAndBranch>(native_context, |
1197 first_context_slot); | 1222 first_context_slot); |
1198 already_in.AndIf<HCompareObjectEqAndBranch>(first_osr_ast_slot, | 1223 already_in.AndIf<HCompareObjectEqAndBranch>(first_osr_ast_slot, |
1199 osr_ast_id_none); | 1224 osr_ast_id_none); |
1200 already_in.Then(); | 1225 already_in.Then(); |
1201 { | 1226 { |
1202 HValue* code_object = Add<HLoadNamedField>( | 1227 HValue* code_object = Add<HLoadNamedField>( |
1203 optimized_map, static_cast<HValue*>(NULL), | 1228 optimized_map, static_cast<HValue*>(NULL), |
1204 HObjectAccess::ForFirstCodeSlot()); | 1229 HObjectAccess::ForFirstCodeSlot()); |
1205 BuildInstallOptimizedCode(js_function, native_context, code_object); | 1230 HValue* literals = Add<HLoadNamedField>( |
1231 optimized_map, static_cast<HValue*>(NULL), | |
1232 HObjectAccess::ForFirstLiteralsSlot()); | |
1233 BuildInstallOptimizedCode(js_function, native_context, code_object, | |
1234 literals); | |
1206 } | 1235 } |
1207 already_in.Else(); | 1236 already_in.Else(); |
1208 { | 1237 { |
1209 HValue* shared_function_entry_length = | |
1210 Add<HConstant>(SharedFunctionInfo::kEntryLength); | |
1211 LoopBuilder loop_builder(this, | |
1212 context(), | |
1213 LoopBuilder::kPostDecrement, | |
1214 shared_function_entry_length); | |
1215 HValue* array_length = Add<HLoadNamedField>( | 1238 HValue* array_length = Add<HLoadNamedField>( |
1216 optimized_map, static_cast<HValue*>(NULL), | 1239 optimized_map, static_cast<HValue*>(NULL), |
1217 HObjectAccess::ForFixedArrayLength()); | 1240 HObjectAccess::ForFixedArrayLength()); |
1218 HValue* slot_iterator = loop_builder.BeginBody(array_length, | 1241 IfBuilder store_unoptimized(this); |
1219 graph()->GetConstant0(), | 1242 store_unoptimized.If<HCompareNumericAndBranch>( |
1220 Token::GT); | 1243 array_length, Add<HConstant>(SharedFunctionInfo::kInitialLength), |
1244 Token::EQ); | |
1245 store_unoptimized.Then(); | |
1246 { | |
1247 // Store the unoptimized code | |
1248 BuildInstallCode(js_function, shared_info); | |
1249 } | |
1250 store_unoptimized.Else(); | |
1221 { | 1251 { |
1222 // Iterate through the rest of map backwards. | 1252 // Iterate through the rest of map backwards. |
1223 // Do not double check first entry. | 1253 // Do not double check first entry. |
1254 // for(i = map.length() - kEntryLength; | |
1255 // i >= kSecondEntryIndex; | |
1256 // i -= kEntryLength) { .. } | |
1257 | |
1258 HValue* shared_function_entry_length = | |
1259 Add<HConstant>(SharedFunctionInfo::kEntryLength); | |
1260 LoopBuilder loop_builder(this, | |
1261 context(), | |
1262 LoopBuilder::kPostDecrement, | |
1263 shared_function_entry_length); | |
1264 HValue* start_pos = AddUncasted<HSub>(array_length, | |
1265 shared_function_entry_length); | |
1224 HValue* second_entry_index = | 1266 HValue* second_entry_index = |
1225 Add<HConstant>(SharedFunctionInfo::kSecondEntryIndex); | 1267 Add<HConstant>(SharedFunctionInfo::kSecondEntryIndex); |
1226 IfBuilder restore_check(this); | 1268 HValue* slot_iterator = loop_builder.BeginBody(start_pos, |
1227 restore_check.If<HCompareNumericAndBranch>( | 1269 second_entry_index, |
1228 slot_iterator, second_entry_index, Token::EQ); | 1270 Token::GTE); |
1229 restore_check.Then(); | |
1230 { | 1271 { |
1231 // Store the unoptimized code | 1272 // slot iterator is pointing behind the record we want to examine. |
Yang
2014/03/03 08:27:02
This comment seems not to match the code...
if the
mvstanton
2014/03/03 09:35:52
Right, the comment was old. I changed the loop ite
| |
1232 BuildInstallCode(js_function, shared_info); | 1273 HInstruction* native_context_entry = LoadFromOptimizedCodeMap( |
1233 loop_builder.Break(); | 1274 optimized_map, slot_iterator, SharedFunctionInfo::kContextOffset); |
1234 } | 1275 HInstruction* osr_ast_id_entry = LoadFromOptimizedCodeMap( |
1235 restore_check.Else(); | 1276 optimized_map, slot_iterator, |
1236 { | 1277 SharedFunctionInfo::kOsrAstIdOffset); |
1237 STATIC_ASSERT(SharedFunctionInfo::kContextOffset == 0); | |
1238 STATIC_ASSERT(SharedFunctionInfo::kEntryLength - | |
1239 SharedFunctionInfo::kOsrAstIdOffset == 1); | |
1240 HValue* native_context_slot = AddUncasted<HSub>( | |
1241 slot_iterator, shared_function_entry_length); | |
1242 HValue* osr_ast_id_slot = AddUncasted<HSub>( | |
1243 slot_iterator, graph()->GetConstant1()); | |
1244 HInstruction* native_context_entry = Add<HLoadKeyed>(optimized_map, | |
1245 native_context_slot, static_cast<HValue*>(NULL), FAST_ELEMENTS); | |
1246 HInstruction* osr_ast_id_entry = Add<HLoadKeyed>(optimized_map, | |
1247 osr_ast_id_slot, static_cast<HValue*>(NULL), FAST_ELEMENTS); | |
1248 IfBuilder done_check(this); | 1278 IfBuilder done_check(this); |
1249 done_check.If<HCompareObjectEqAndBranch>(native_context, | 1279 done_check.If<HCompareObjectEqAndBranch>(native_context, |
1250 native_context_entry); | 1280 native_context_entry); |
1251 done_check.AndIf<HCompareObjectEqAndBranch>(osr_ast_id_entry, | 1281 done_check.AndIf<HCompareObjectEqAndBranch>(osr_ast_id_entry, |
1252 osr_ast_id_none); | 1282 osr_ast_id_none); |
1253 done_check.Then(); | 1283 done_check.Then(); |
1254 { | 1284 { |
1255 // Hit: fetch the optimized code. | 1285 // Hit: fetch the optimized code. |
1256 HValue* code_slot = AddUncasted<HAdd>( | 1286 HValue* code_object = LoadFromOptimizedCodeMap(optimized_map, |
1257 native_context_slot, graph()->GetConstant1()); | 1287 slot_iterator, SharedFunctionInfo::kCachedCodeOffset); |
1258 HValue* code_object = Add<HLoadKeyed>(optimized_map, | 1288 // and the literals |
1259 code_slot, static_cast<HValue*>(NULL), FAST_ELEMENTS); | 1289 HValue* literals = LoadFromOptimizedCodeMap(optimized_map, |
1260 BuildInstallOptimizedCode(js_function, native_context, code_object); | 1290 slot_iterator, SharedFunctionInfo::kLiteralsOffset); |
1291 BuildInstallOptimizedCode(js_function, native_context, code_object, | |
1292 literals); | |
1261 | 1293 |
1262 // Fall out of the loop | 1294 // Fall out of the loop |
1263 loop_builder.Break(); | 1295 loop_builder.Break(); |
1264 } | 1296 } |
1265 done_check.Else(); | |
1266 done_check.End(); | 1297 done_check.End(); |
1267 } | 1298 } |
1268 restore_check.End(); | 1299 loop_builder.EndBody(); |
1269 } | 1300 } |
1270 loop_builder.EndBody(); | 1301 store_unoptimized.End(); |
1271 } | 1302 } |
1272 already_in.End(); | 1303 already_in.End(); |
1273 } | 1304 } |
1274 is_optimized.End(); | 1305 is_optimized.End(); |
1275 } | 1306 } |
1276 | 1307 |
1277 | 1308 |
1278 template<> | 1309 template<> |
1279 HValue* CodeStubGraphBuilder<FastNewClosureStub>::BuildCodeStub() { | 1310 HValue* CodeStubGraphBuilder<FastNewClosureStub>::BuildCodeStub() { |
1280 Counters* counters = isolate()->counters(); | 1311 Counters* counters = isolate()->counters(); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1415 return BuildRegExpConstructResult(length, index, input); | 1446 return BuildRegExpConstructResult(length, index, input); |
1416 } | 1447 } |
1417 | 1448 |
1418 | 1449 |
1419 Handle<Code> RegExpConstructResultStub::GenerateCode(Isolate* isolate) { | 1450 Handle<Code> RegExpConstructResultStub::GenerateCode(Isolate* isolate) { |
1420 return DoGenerateCode(isolate, this); | 1451 return DoGenerateCode(isolate, this); |
1421 } | 1452 } |
1422 | 1453 |
1423 | 1454 |
1424 } } // namespace v8::internal | 1455 } } // namespace v8::internal |
OLD | NEW |