OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/compiler.h" | 5 #include "vm/compiler.h" |
6 | 6 |
7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
8 | 8 |
9 #include "vm/ast_printer.h" | 9 #include "vm/ast_printer.h" |
10 #include "vm/block_scheduler.h" | 10 #include "vm/block_scheduler.h" |
(...skipping 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1074 return Error::null(); | 1074 return Error::null(); |
1075 } | 1075 } |
1076 | 1076 |
1077 | 1077 |
1078 RawError* Compiler::CompileFunction(Thread* thread, | 1078 RawError* Compiler::CompileFunction(Thread* thread, |
1079 const Function& function) { | 1079 const Function& function) { |
1080 Isolate* isolate = thread->isolate(); | 1080 Isolate* isolate = thread->isolate(); |
1081 VMTagScope tagScope(isolate, VMTag::kCompileUnoptimizedTagId); | 1081 VMTagScope tagScope(isolate, VMTag::kCompileUnoptimizedTagId); |
1082 TIMELINE_FUNCTION_COMPILATION_DURATION(isolate, "Function", function); | 1082 TIMELINE_FUNCTION_COMPILATION_DURATION(isolate, "Function", function); |
1083 | 1083 |
| 1084 if (!isolate->compilation_allowed()) { |
| 1085 FATAL2("Precompilation missed function %s (%s)\n", |
| 1086 function.ToQualifiedCString(), |
| 1087 Function::KindToCString(function.kind())); |
| 1088 } |
| 1089 |
1084 CompilationPipeline* pipeline = | 1090 CompilationPipeline* pipeline = |
1085 CompilationPipeline::New(thread->zone(), function); | 1091 CompilationPipeline::New(thread->zone(), function); |
1086 | 1092 |
1087 const bool optimized = | 1093 const bool optimized = |
1088 Compiler::always_optimize() && function.IsOptimizable(); | 1094 Compiler::always_optimize() && function.IsOptimizable(); |
1089 | 1095 |
1090 return CompileFunctionHelper(pipeline, function, optimized, | 1096 return CompileFunctionHelper(pipeline, function, optimized, |
1091 Isolate::kNoDeoptId); | 1097 Isolate::kNoDeoptId); |
1092 } | 1098 } |
1093 | 1099 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1234 | 1240 |
1235 | 1241 |
1236 static void CreateLocalVarDescriptors(const ParsedFunction& parsed_function) { | 1242 static void CreateLocalVarDescriptors(const ParsedFunction& parsed_function) { |
1237 const Function& func = parsed_function.function(); | 1243 const Function& func = parsed_function.function(); |
1238 LocalVarDescriptors& var_descs = LocalVarDescriptors::Handle(); | 1244 LocalVarDescriptors& var_descs = LocalVarDescriptors::Handle(); |
1239 var_descs = parsed_function.node_sequence()->scope()->GetVarDescriptors(func); | 1245 var_descs = parsed_function.node_sequence()->scope()->GetVarDescriptors(func); |
1240 Code::Handle(func.unoptimized_code()).set_var_descriptors(var_descs); | 1246 Code::Handle(func.unoptimized_code()).set_var_descriptors(var_descs); |
1241 } | 1247 } |
1242 | 1248 |
1243 | 1249 |
| 1250 void Compiler::CompileStaticInitializer(const Field& field) { |
| 1251 ASSERT(field.is_static()); |
| 1252 if (field.initializer() != Function::null()) { |
| 1253 // TODO(rmacnak): Investigate why this happens for _enum_names. |
| 1254 OS::Print("Warning: Ignoring repeated request for initializer for %s\n", |
| 1255 field.ToCString()); |
| 1256 return; |
| 1257 } |
| 1258 ASSERT(field.initializer() == Function::null()); |
| 1259 Isolate* isolate = Isolate::Current(); |
| 1260 StackZone zone(isolate); |
| 1261 |
| 1262 ParsedFunction* parsed_function = Parser::ParseStaticFieldInitializer(field); |
| 1263 |
| 1264 parsed_function->AllocateVariables(); |
| 1265 // Non-optimized code generator. |
| 1266 DartCompilationPipeline pipeline; |
| 1267 CompileParsedFunctionHelper(&pipeline, |
| 1268 parsed_function, |
| 1269 false, // optimized |
| 1270 Isolate::kNoDeoptId); |
| 1271 |
| 1272 const Function& initializer = parsed_function->function(); |
| 1273 field.set_initializer(initializer); |
| 1274 } |
| 1275 |
| 1276 |
1244 RawObject* Compiler::EvaluateStaticInitializer(const Field& field) { | 1277 RawObject* Compiler::EvaluateStaticInitializer(const Field& field) { |
1245 ASSERT(field.is_static()); | 1278 ASSERT(field.is_static()); |
1246 // The VM sets the field's value to transiton_sentinel prior to | 1279 // The VM sets the field's value to transiton_sentinel prior to |
1247 // evaluating the initializer value. | 1280 // evaluating the initializer value. |
1248 ASSERT(field.value() == Object::transition_sentinel().raw()); | 1281 ASSERT(field.value() == Object::transition_sentinel().raw()); |
1249 LongJumpScope jump; | 1282 LongJumpScope jump; |
1250 if (setjmp(*jump.Set()) == 0) { | 1283 if (setjmp(*jump.Set()) == 0) { |
1251 Isolate* const isolate = Isolate::Current(); | 1284 Function& initializer = Function::Handle(field.initializer()); |
1252 StackZone zone(isolate); | |
1253 ParsedFunction* parsed_function = | |
1254 Parser::ParseStaticFieldInitializer(field); | |
1255 | 1285 |
1256 parsed_function->AllocateVariables(); | 1286 // Under precompilation, the initializer may have already been compiled, in |
1257 // Non-optimized code generator. | 1287 // which case use it. Under lazy compilation or early in precompilation, the |
1258 DartCompilationPipeline pipeline; | 1288 // initializer has not yet been created, so create it now, but don't bother |
1259 CompileParsedFunctionHelper(&pipeline, | 1289 // remembering it because it won't be used again. |
1260 parsed_function, | 1290 if (initializer.IsNull()) { |
1261 false, | 1291 Isolate* const isolate = Isolate::Current(); |
1262 Isolate::kNoDeoptId); | 1292 StackZone zone(isolate); |
1263 // Eagerly create local var descriptors. | 1293 ParsedFunction* parsed_function = |
1264 CreateLocalVarDescriptors(*parsed_function); | 1294 Parser::ParseStaticFieldInitializer(field); |
1265 | 1295 |
| 1296 parsed_function->AllocateVariables(); |
| 1297 // Non-optimized code generator. |
| 1298 DartCompilationPipeline pipeline; |
| 1299 CompileParsedFunctionHelper(&pipeline, |
| 1300 parsed_function, |
| 1301 false, // optimized |
| 1302 Isolate::kNoDeoptId); |
| 1303 // Eagerly create local var descriptors. |
| 1304 CreateLocalVarDescriptors(*parsed_function); |
| 1305 |
| 1306 initializer = parsed_function->function().raw(); |
| 1307 } |
1266 // Invoke the function to evaluate the expression. | 1308 // Invoke the function to evaluate the expression. |
1267 const Function& initializer = parsed_function->function(); | |
1268 const Object& result = PassiveObject::Handle( | 1309 const Object& result = PassiveObject::Handle( |
1269 DartEntry::InvokeFunction(initializer, Object::empty_array())); | 1310 DartEntry::InvokeFunction(initializer, Object::empty_array())); |
1270 return result.raw(); | 1311 return result.raw(); |
1271 } else { | 1312 } else { |
1272 Isolate* const isolate = Isolate::Current(); | 1313 Isolate* const isolate = Isolate::Current(); |
1273 StackZone zone(isolate); | 1314 StackZone zone(isolate); |
1274 const Error& error = | 1315 const Error& error = |
1275 Error::Handle(isolate, isolate->object_store()->sticky_error()); | 1316 Error::Handle(isolate, isolate->object_store()->sticky_error()); |
1276 isolate->object_store()->clear_sticky_error(); | 1317 isolate->object_store()->clear_sticky_error(); |
1277 return error.raw(); | 1318 return error.raw(); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1342 const Object& result = | 1383 const Object& result = |
1343 PassiveObject::Handle(isolate->object_store()->sticky_error()); | 1384 PassiveObject::Handle(isolate->object_store()->sticky_error()); |
1344 isolate->object_store()->clear_sticky_error(); | 1385 isolate->object_store()->clear_sticky_error(); |
1345 return result.raw(); | 1386 return result.raw(); |
1346 } | 1387 } |
1347 UNREACHABLE(); | 1388 UNREACHABLE(); |
1348 return Object::null(); | 1389 return Object::null(); |
1349 } | 1390 } |
1350 | 1391 |
1351 } // namespace dart | 1392 } // namespace dart |
OLD | NEW |