| 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 ASSERT(!function.HasCode()); | 171 ASSERT(!function.HasCode()); |
| 172 const Error& error = Error::Handle(Compiler::CompileFunction(thread, | 172 const Error& error = Error::Handle(Compiler::CompileFunction(thread, |
| 173 function)); | 173 function)); |
| 174 if (!error.IsNull()) { | 174 if (!error.IsNull()) { |
| 175 Exceptions::PropagateError(error); | 175 Exceptions::PropagateError(error); |
| 176 } | 176 } |
| 177 } | 177 } |
| 178 | 178 |
| 179 | 179 |
| 180 RawError* Compiler::Compile(const Library& library, const Script& script) { | 180 RawError* Compiler::Compile(const Library& library, const Script& script) { |
| 181 Isolate* volatile isolate = Isolate::Current(); | 181 Isolate* const isolate = Isolate::Current(); |
| 182 StackZone zone(isolate); | 182 StackZone zone(isolate); |
| 183 LongJumpScope jump; | 183 LongJumpScope jump; |
| 184 if (setjmp(*jump.Set()) == 0) { | 184 if (setjmp(*jump.Set()) == 0) { |
| 185 if (FLAG_trace_compiler) { | 185 if (FLAG_trace_compiler) { |
| 186 const String& script_url = String::Handle(script.url()); | 186 const String& script_url = String::Handle(script.url()); |
| 187 // TODO(iposva): Extract script kind. | 187 // TODO(iposva): Extract script kind. |
| 188 ISL_Print("Compiling %s '%s'\n", "", script_url.ToCString()); | 188 ISL_Print("Compiling %s '%s'\n", "", script_url.ToCString()); |
| 189 } | 189 } |
| 190 const String& library_key = String::Handle(library.private_key()); | 190 const String& library_key = String::Handle(library.private_key()); |
| 191 script.Tokenize(library_key); | 191 script.Tokenize(library_key); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 return Error::null(); | 272 return Error::null(); |
| 273 } else { | 273 } else { |
| 274 Isolate* isolate = Isolate::Current(); | 274 Isolate* isolate = Isolate::Current(); |
| 275 Error& error = Error::Handle(isolate); | 275 Error& error = Error::Handle(isolate); |
| 276 error = isolate->object_store()->sticky_error(); | 276 error = isolate->object_store()->sticky_error(); |
| 277 isolate->object_store()->clear_sticky_error(); | 277 isolate->object_store()->clear_sticky_error(); |
| 278 return error.raw(); | 278 return error.raw(); |
| 279 } | 279 } |
| 280 } | 280 } |
| 281 | 281 |
| 282 Isolate* volatile isolate = Isolate::Current(); | 282 Isolate* const isolate = Isolate::Current(); |
| 283 // We remember all the classes that are being compiled in these lists. This | 283 // We remember all the classes that are being compiled in these lists. This |
| 284 // also allows us to reset the marked_for_parsing state in case we see an | 284 // also allows us to reset the marked_for_parsing state in case we see an |
| 285 // error. | 285 // error. |
| 286 VMTagScope tagScope(isolate, VMTag::kCompileTopLevelTagId); | 286 VMTagScope tagScope(isolate, VMTag::kCompileTopLevelTagId); |
| 287 Class& parse_class = Class::Handle(isolate); | 287 Class& parse_class = Class::Handle(isolate); |
| 288 const GrowableObjectArray& parse_list = | 288 const GrowableObjectArray& parse_list = |
| 289 GrowableObjectArray::Handle(isolate, GrowableObjectArray::New(4)); | 289 GrowableObjectArray::Handle(isolate, GrowableObjectArray::New(4)); |
| 290 const GrowableObjectArray& patch_list = | 290 const GrowableObjectArray& patch_list = |
| 291 GrowableObjectArray::Handle(isolate, GrowableObjectArray::New(4)); | 291 GrowableObjectArray::Handle(isolate, GrowableObjectArray::New(4)); |
| 292 | 292 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 static bool CompileParsedFunctionHelper(CompilationPipeline* pipeline, | 367 static bool CompileParsedFunctionHelper(CompilationPipeline* pipeline, |
| 368 ParsedFunction* parsed_function, | 368 ParsedFunction* parsed_function, |
| 369 bool optimized, | 369 bool optimized, |
| 370 intptr_t osr_id) { | 370 intptr_t osr_id) { |
| 371 const Function& function = parsed_function->function(); | 371 const Function& function = parsed_function->function(); |
| 372 if (optimized && !function.IsOptimizable()) { | 372 if (optimized && !function.IsOptimizable()) { |
| 373 return false; | 373 return false; |
| 374 } | 374 } |
| 375 TimerScope timer(FLAG_compiler_stats, &CompilerStats::codegen_timer); | 375 TimerScope timer(FLAG_compiler_stats, &CompilerStats::codegen_timer); |
| 376 bool is_compiled = false; | 376 bool is_compiled = false; |
| 377 Thread* volatile thread = Thread::Current(); | 377 Thread* const thread = Thread::Current(); |
| 378 Zone* volatile zone = thread->zone(); | 378 Zone* const zone = thread->zone(); |
| 379 Isolate* volatile isolate = thread->isolate(); | 379 Isolate* const isolate = thread->isolate(); |
| 380 HANDLESCOPE(isolate); | 380 HANDLESCOPE(isolate); |
| 381 | 381 |
| 382 // We may reattempt compilation if the function needs to be assembled using | 382 // We may reattempt compilation if the function needs to be assembled using |
| 383 // far branches on ARM and MIPS. In the else branch of the setjmp call, | 383 // far branches on ARM and MIPS. In the else branch of the setjmp call, |
| 384 // done is set to false, and use_far_branches is set to true if there is a | 384 // done is set to false, and use_far_branches is set to true if there is a |
| 385 // longjmp from the ARM or MIPS assemblers. In all other paths through this | 385 // longjmp from the ARM or MIPS assemblers. In all other paths through this |
| 386 // while loop, done is set to true. use_far_branches is always false on ia32 | 386 // while loop, done is set to true. use_far_branches is always false on ia32 |
| 387 // and x64. | 387 // and x64. |
| 388 bool done = false; | 388 bool done = false; |
| 389 // volatile because the variable may be clobbered by a longjmp. | 389 // volatile because the variable may be clobbered by a longjmp. |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 if (optimized && FLAG_trace_inlining_intervals) { | 957 if (optimized && FLAG_trace_inlining_intervals) { |
| 958 code.DumpInlinedIntervals(); | 958 code.DumpInlinedIntervals(); |
| 959 } | 959 } |
| 960 } | 960 } |
| 961 | 961 |
| 962 | 962 |
| 963 static RawError* CompileFunctionHelper(CompilationPipeline* pipeline, | 963 static RawError* CompileFunctionHelper(CompilationPipeline* pipeline, |
| 964 const Function& function, | 964 const Function& function, |
| 965 bool optimized, | 965 bool optimized, |
| 966 intptr_t osr_id) { | 966 intptr_t osr_id) { |
| 967 Thread* volatile thread = Thread::Current(); | 967 Thread* const thread = Thread::Current(); |
| 968 Isolate* volatile isolate = thread->isolate(); | 968 Isolate* const isolate = thread->isolate(); |
| 969 StackZone stack_zone(isolate); | 969 StackZone stack_zone(isolate); |
| 970 Zone* volatile zone = stack_zone.GetZone(); | 970 Zone* const zone = stack_zone.GetZone(); |
| 971 LongJumpScope jump; | 971 LongJumpScope jump; |
| 972 if (setjmp(*jump.Set()) == 0) { | 972 if (setjmp(*jump.Set()) == 0) { |
| 973 TIMERSCOPE(isolate, time_compilation); | 973 TIMERSCOPE(isolate, time_compilation); |
| 974 Timer per_compile_timer(FLAG_trace_compiler, "Compilation time"); | 974 Timer per_compile_timer(FLAG_trace_compiler, "Compilation time"); |
| 975 per_compile_timer.Start(); | 975 per_compile_timer.Start(); |
| 976 ParsedFunction* parsed_function = new(zone) ParsedFunction( | 976 ParsedFunction* parsed_function = new(zone) ParsedFunction( |
| 977 thread, Function::ZoneHandle(zone, function.raw())); | 977 thread, Function::ZoneHandle(zone, function.raw())); |
| 978 if (FLAG_trace_compiler) { | 978 if (FLAG_trace_compiler) { |
| 979 ISL_Print("Compiling %s%sfunction: '%s' @ token %" Pd ", size %" Pd "\n", | 979 ISL_Print("Compiling %s%sfunction: '%s' @ token %" Pd ", size %" Pd "\n", |
| 980 (osr_id == Isolate::kNoDeoptId ? "" : "osr "), | 980 (osr_id == Isolate::kNoDeoptId ? "" : "osr "), |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1058 VMTagScope tagScope(thread->isolate(), VMTag::kCompileOptimizedTagId); | 1058 VMTagScope tagScope(thread->isolate(), VMTag::kCompileOptimizedTagId); |
| 1059 CompilationPipeline* pipeline = | 1059 CompilationPipeline* pipeline = |
| 1060 CompilationPipeline::New(thread->zone(), function); | 1060 CompilationPipeline::New(thread->zone(), function); |
| 1061 return CompileFunctionHelper(pipeline, function, true, osr_id); | 1061 return CompileFunctionHelper(pipeline, function, true, osr_id); |
| 1062 } | 1062 } |
| 1063 | 1063 |
| 1064 | 1064 |
| 1065 // This is only used from unit tests. | 1065 // This is only used from unit tests. |
| 1066 RawError* Compiler::CompileParsedFunction( | 1066 RawError* Compiler::CompileParsedFunction( |
| 1067 ParsedFunction* parsed_function) { | 1067 ParsedFunction* parsed_function) { |
| 1068 Isolate* volatile isolate = Isolate::Current(); | 1068 Isolate* const isolate = Isolate::Current(); |
| 1069 LongJumpScope jump; | 1069 LongJumpScope jump; |
| 1070 if (setjmp(*jump.Set()) == 0) { | 1070 if (setjmp(*jump.Set()) == 0) { |
| 1071 // Non-optimized code generator. | 1071 // Non-optimized code generator. |
| 1072 DartCompilationPipeline pipeline; | 1072 DartCompilationPipeline pipeline; |
| 1073 CompileParsedFunctionHelper(&pipeline, | 1073 CompileParsedFunctionHelper(&pipeline, |
| 1074 parsed_function, | 1074 parsed_function, |
| 1075 false, | 1075 false, |
| 1076 Isolate::kNoDeoptId); | 1076 Isolate::kNoDeoptId); |
| 1077 if (FLAG_disassemble) { | 1077 if (FLAG_disassemble) { |
| 1078 DisassembleCode(parsed_function->function(), false); | 1078 DisassembleCode(parsed_function->function(), false); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1135 } | 1135 } |
| 1136 return error.raw(); | 1136 return error.raw(); |
| 1137 } | 1137 } |
| 1138 | 1138 |
| 1139 | 1139 |
| 1140 RawObject* Compiler::EvaluateStaticInitializer(const Field& field) { | 1140 RawObject* Compiler::EvaluateStaticInitializer(const Field& field) { |
| 1141 ASSERT(field.is_static()); | 1141 ASSERT(field.is_static()); |
| 1142 // The VM sets the field's value to transiton_sentinel prior to | 1142 // The VM sets the field's value to transiton_sentinel prior to |
| 1143 // evaluating the initializer value. | 1143 // evaluating the initializer value. |
| 1144 ASSERT(field.value() == Object::transition_sentinel().raw()); | 1144 ASSERT(field.value() == Object::transition_sentinel().raw()); |
| 1145 Isolate* volatile isolate = Isolate::Current(); | 1145 Isolate* const isolate = Isolate::Current(); |
| 1146 StackZone zone(isolate); | 1146 StackZone zone(isolate); |
| 1147 LongJumpScope jump; | 1147 LongJumpScope jump; |
| 1148 if (setjmp(*jump.Set()) == 0) { | 1148 if (setjmp(*jump.Set()) == 0) { |
| 1149 ParsedFunction* parsed_function = | 1149 ParsedFunction* parsed_function = |
| 1150 Parser::ParseStaticFieldInitializer(field); | 1150 Parser::ParseStaticFieldInitializer(field); |
| 1151 | 1151 |
| 1152 parsed_function->AllocateVariables(); | 1152 parsed_function->AllocateVariables(); |
| 1153 // Non-optimized code generator. | 1153 // Non-optimized code generator. |
| 1154 DartCompilationPipeline pipeline; | 1154 DartCompilationPipeline pipeline; |
| 1155 CompileParsedFunctionHelper(&pipeline, | 1155 CompileParsedFunctionHelper(&pipeline, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1168 isolate->object_store()->clear_sticky_error(); | 1168 isolate->object_store()->clear_sticky_error(); |
| 1169 return error.raw(); | 1169 return error.raw(); |
| 1170 } | 1170 } |
| 1171 UNREACHABLE(); | 1171 UNREACHABLE(); |
| 1172 return Object::null(); | 1172 return Object::null(); |
| 1173 } | 1173 } |
| 1174 | 1174 |
| 1175 | 1175 |
| 1176 | 1176 |
| 1177 RawObject* Compiler::ExecuteOnce(SequenceNode* fragment) { | 1177 RawObject* Compiler::ExecuteOnce(SequenceNode* fragment) { |
| 1178 Thread* volatile thread = Thread::Current(); | 1178 Thread* const thread = Thread::Current(); |
| 1179 Isolate* volatile isolate = thread->isolate(); | 1179 Isolate* const isolate = thread->isolate(); |
| 1180 LongJumpScope jump; | 1180 LongJumpScope jump; |
| 1181 if (setjmp(*jump.Set()) == 0) { | 1181 if (setjmp(*jump.Set()) == 0) { |
| 1182 if (FLAG_trace_compiler) { | 1182 if (FLAG_trace_compiler) { |
| 1183 ISL_Print("compiling expression: "); | 1183 ISL_Print("compiling expression: "); |
| 1184 AstPrinter::PrintNode(fragment); | 1184 AstPrinter::PrintNode(fragment); |
| 1185 } | 1185 } |
| 1186 | 1186 |
| 1187 // Create a dummy function object for the code generator. | 1187 // Create a dummy function object for the code generator. |
| 1188 // The function needs to be associated with a named Class: the interface | 1188 // The function needs to be associated with a named Class: the interface |
| 1189 // Function fits the bill. | 1189 // Function fits the bill. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1231 const Object& result = | 1231 const Object& result = |
| 1232 PassiveObject::Handle(isolate->object_store()->sticky_error()); | 1232 PassiveObject::Handle(isolate->object_store()->sticky_error()); |
| 1233 isolate->object_store()->clear_sticky_error(); | 1233 isolate->object_store()->clear_sticky_error(); |
| 1234 return result.raw(); | 1234 return result.raw(); |
| 1235 } | 1235 } |
| 1236 UNREACHABLE(); | 1236 UNREACHABLE(); |
| 1237 return Object::null(); | 1237 return Object::null(); |
| 1238 } | 1238 } |
| 1239 | 1239 |
| 1240 } // namespace dart | 1240 } // namespace dart |
| OLD | NEW |