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 #include "vm/ast_printer.h" | 8 #include "vm/ast_printer.h" |
9 #include "vm/code_generator.h" | 9 #include "vm/code_generator.h" |
| 10 #include "vm/code_index_table.h" |
10 #include "vm/code_patcher.h" | 11 #include "vm/code_patcher.h" |
11 #include "vm/dart_entry.h" | 12 #include "vm/dart_entry.h" |
12 #include "vm/debugger.h" | 13 #include "vm/debugger.h" |
13 #include "vm/disassembler.h" | 14 #include "vm/disassembler.h" |
14 #include "vm/exceptions.h" | 15 #include "vm/exceptions.h" |
15 #include "vm/flags.h" | 16 #include "vm/flags.h" |
16 #include "vm/flow_graph_builder.h" | 17 #include "vm/flow_graph_builder.h" |
17 #include "vm/flow_graph_compiler.h" | 18 #include "vm/flow_graph_compiler.h" |
18 #include "vm/longjump.h" | 19 #include "vm/longjump.h" |
19 #include "vm/object.h" | 20 #include "vm/object.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 const char* function_fullname = function.ToFullyQualifiedCString(); | 122 const char* function_fullname = function.ToFullyQualifiedCString(); |
122 if (FLAG_trace_compiler) { | 123 if (FLAG_trace_compiler) { |
123 OS::Print("Compiling %sfunction: '%s' @ token %d\n", | 124 OS::Print("Compiling %sfunction: '%s' @ token %d\n", |
124 (optimized ? "optimized " : ""), | 125 (optimized ? "optimized " : ""), |
125 function_fullname, | 126 function_fullname, |
126 function.token_index()); | 127 function.token_index()); |
127 } | 128 } |
128 Parser::ParseFunction(&parsed_function); | 129 Parser::ParseFunction(&parsed_function); |
129 parsed_function.AllocateVariables(); | 130 parsed_function.AllocateVariables(); |
130 | 131 |
| 132 CodeIndexTable* code_index_table = isolate->code_index_table(); |
| 133 ASSERT(code_index_table != NULL); |
131 bool is_compiled = false; | 134 bool is_compiled = false; |
132 if (FLAG_use_new_compiler) { | 135 if (FLAG_use_new_compiler) { |
133 ASSERT(!optimized); | 136 ASSERT(!optimized); |
134 LongJump* old_base = isolate->long_jump_base(); | 137 LongJump* old_base = isolate->long_jump_base(); |
135 LongJump bailout_jump; | 138 LongJump bailout_jump; |
136 isolate->set_long_jump_base(&bailout_jump); | 139 isolate->set_long_jump_base(&bailout_jump); |
137 if (setjmp(*bailout_jump.Set()) == 0) { | 140 if (setjmp(*bailout_jump.Set()) == 0) { |
138 FlowGraphBuilder graph_builder(parsed_function); | 141 FlowGraphBuilder graph_builder(parsed_function); |
139 graph_builder.BuildGraph(); | 142 graph_builder.BuildGraph(); |
140 | 143 |
(...skipping 11 matching lines...) Expand all Loading... |
152 graph_compiler.CompileGraph(); | 155 graph_compiler.CompileGraph(); |
153 const Code& code = | 156 const Code& code = |
154 Code::Handle(Code::FinalizeCode(function_fullname, &assembler)); | 157 Code::Handle(Code::FinalizeCode(function_fullname, &assembler)); |
155 code.set_is_optimized(false); | 158 code.set_is_optimized(false); |
156 graph_compiler.FinalizePcDescriptors(code); | 159 graph_compiler.FinalizePcDescriptors(code); |
157 graph_compiler.FinalizeVarDescriptors(code); | 160 graph_compiler.FinalizeVarDescriptors(code); |
158 graph_compiler.FinalizeExceptionHandlers(code); | 161 graph_compiler.FinalizeExceptionHandlers(code); |
159 function.set_unoptimized_code(code); | 162 function.set_unoptimized_code(code); |
160 function.SetCode(code); | 163 function.SetCode(code); |
161 ASSERT(CodePatcher::CodeIsPatchable(code)); | 164 ASSERT(CodePatcher::CodeIsPatchable(code)); |
| 165 code_index_table->AddCode(code); |
162 is_compiled = true; | 166 is_compiled = true; |
163 } else { | 167 } else { |
164 // We bailed out. | 168 // We bailed out. |
165 Error& bailout_error = Error::Handle( | 169 Error& bailout_error = Error::Handle( |
166 isolate->object_store()->sticky_error()); | 170 isolate->object_store()->sticky_error()); |
167 isolate->object_store()->clear_sticky_error(); | 171 isolate->object_store()->clear_sticky_error(); |
168 if (FLAG_trace_bailout) { | 172 if (FLAG_trace_bailout) { |
169 OS::Print("%s\n", bailout_error.ToErrorCString()); | 173 OS::Print("%s\n", bailout_error.ToErrorCString()); |
170 } | 174 } |
171 } | 175 } |
(...skipping 17 matching lines...) Expand all Loading... |
189 } | 193 } |
190 OptimizingCodeGenerator code_gen(&assembler, parsed_function); | 194 OptimizingCodeGenerator code_gen(&assembler, parsed_function); |
191 code_gen.GenerateCode(); | 195 code_gen.GenerateCode(); |
192 Code& code = Code::Handle( | 196 Code& code = Code::Handle( |
193 Code::FinalizeCode(function_fullname, &assembler)); | 197 Code::FinalizeCode(function_fullname, &assembler)); |
194 code.set_is_optimized(true); | 198 code.set_is_optimized(true); |
195 code_gen.FinalizePcDescriptors(code); | 199 code_gen.FinalizePcDescriptors(code); |
196 code_gen.FinalizeStackmaps(code); | 200 code_gen.FinalizeStackmaps(code); |
197 code_gen.FinalizeExceptionHandlers(code); | 201 code_gen.FinalizeExceptionHandlers(code); |
198 function.SetCode(code); | 202 function.SetCode(code); |
| 203 code_index_table->AddCode(code); |
199 CodePatcher::PatchEntry(Code::Handle(function.unoptimized_code())); | 204 CodePatcher::PatchEntry(Code::Handle(function.unoptimized_code())); |
200 if (FLAG_trace_compiler) { | 205 if (FLAG_trace_compiler) { |
201 OS::Print("--> patching entry 0x%x\n", | 206 OS::Print("--> patching entry 0x%x\n", |
202 Code::Handle(function.unoptimized_code()).EntryPoint()); | 207 Code::Handle(function.unoptimized_code()).EntryPoint()); |
203 } | 208 } |
204 } else { | 209 } else { |
205 // Unoptimized code. | 210 // Unoptimized code. |
206 if (Code::Handle(function.unoptimized_code()).IsNull()) { | 211 if (Code::Handle(function.unoptimized_code()).IsNull()) { |
207 ASSERT(!function.HasCode()); | 212 ASSERT(!function.HasCode()); |
208 // Compiling first time. | 213 // Compiling first time. |
209 CodeGenerator code_gen(&assembler, parsed_function); | 214 CodeGenerator code_gen(&assembler, parsed_function); |
210 code_gen.GenerateCode(); | 215 code_gen.GenerateCode(); |
211 const Code& code = | 216 const Code& code = |
212 Code::Handle(Code::FinalizeCode(function_fullname, &assembler)); | 217 Code::Handle(Code::FinalizeCode(function_fullname, &assembler)); |
213 code.set_is_optimized(false); | 218 code.set_is_optimized(false); |
214 code_gen.FinalizePcDescriptors(code); | 219 code_gen.FinalizePcDescriptors(code); |
215 code_gen.FinalizeStackmaps(code); | 220 code_gen.FinalizeStackmaps(code); |
216 code_gen.FinalizeVarDescriptors(code); | 221 code_gen.FinalizeVarDescriptors(code); |
217 code_gen.FinalizeExceptionHandlers(code); | 222 code_gen.FinalizeExceptionHandlers(code); |
218 function.set_unoptimized_code(code); | 223 function.set_unoptimized_code(code); |
219 function.SetCode(code); | 224 function.SetCode(code); |
220 ASSERT(CodePatcher::CodeIsPatchable(code)); | 225 ASSERT(CodePatcher::CodeIsPatchable(code)); |
| 226 code_index_table->AddCode(code); |
221 } else { | 227 } else { |
222 // Disable optimized code. | 228 // Disable optimized code. |
223 ASSERT(function.HasOptimizedCode()); | 229 ASSERT(function.HasOptimizedCode()); |
224 // Patch entry of optimized code. | 230 // Patch entry of optimized code. |
225 CodePatcher::PatchEntry(Code::Handle(function.CurrentCode())); | 231 CodePatcher::PatchEntry(Code::Handle(function.CurrentCode())); |
226 if (FLAG_trace_compiler) { | 232 if (FLAG_trace_compiler) { |
227 OS::Print("--> patching entry 0x%x\n", | 233 OS::Print("--> patching entry 0x%x\n", |
228 Code::Handle(function.CurrentCode()).EntryPoint()); | 234 Code::Handle(function.CurrentCode()).EntryPoint()); |
229 } | 235 } |
230 // Use previously compiled code. | 236 // Use previously compiled code. |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 ParsedFunction parsed_function(func); | 371 ParsedFunction parsed_function(func); |
366 parsed_function.set_node_sequence(fragment); | 372 parsed_function.set_node_sequence(fragment); |
367 parsed_function.set_default_parameter_values(Array::Handle()); | 373 parsed_function.set_default_parameter_values(Array::Handle()); |
368 | 374 |
369 Assembler assembler; | 375 Assembler assembler; |
370 CodeGenerator code_gen(&assembler, parsed_function); | 376 CodeGenerator code_gen(&assembler, parsed_function); |
371 code_gen.GenerateCode(); | 377 code_gen.GenerateCode(); |
372 const Code& code = Code::Handle(Code::FinalizeCode(kEvalConst, &assembler)); | 378 const Code& code = Code::Handle(Code::FinalizeCode(kEvalConst, &assembler)); |
373 | 379 |
374 func.SetCode(code); | 380 func.SetCode(code); |
| 381 CodeIndexTable* code_index_table = isolate->code_index_table(); |
| 382 ASSERT(code_index_table != NULL); |
| 383 code_index_table->AddCode(code); |
| 384 // TODO(hausner): We need a way to remove these one-time execution |
| 385 // functions from the global code description (PC mapping) tables so |
| 386 // we don't pollute the system unnecessarily with stale data. |
375 code_gen.FinalizePcDescriptors(code); | 387 code_gen.FinalizePcDescriptors(code); |
376 code_gen.FinalizeStackmaps(code); | 388 code_gen.FinalizeStackmaps(code); |
377 code_gen.FinalizeExceptionHandlers(code); | 389 code_gen.FinalizeExceptionHandlers(code); |
378 | 390 |
379 GrowableArray<const Object*> arguments; // no arguments. | 391 GrowableArray<const Object*> arguments; // no arguments. |
380 const Array& kNoArgumentNames = Array::Handle(); | 392 const Array& kNoArgumentNames = Array::Handle(); |
381 result = DartEntry::InvokeStatic(func, | 393 result = DartEntry::InvokeStatic(func, |
382 arguments, | 394 arguments, |
383 kNoArgumentNames); | 395 kNoArgumentNames); |
384 } else { | 396 } else { |
385 result = isolate->object_store()->sticky_error(); | 397 result = isolate->object_store()->sticky_error(); |
386 isolate->object_store()->clear_sticky_error(); | 398 isolate->object_store()->clear_sticky_error(); |
387 } | 399 } |
388 isolate->set_long_jump_base(base); | 400 isolate->set_long_jump_base(base); |
389 return result.raw(); | 401 return result.raw(); |
390 } | 402 } |
391 | 403 |
392 | 404 |
393 } // namespace dart | 405 } // namespace dart |
OLD | NEW |