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/code_generator.h" | 10 #include "vm/code_generator.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 ASSERT(!function.HasCode()); | 63 ASSERT(!function.HasCode()); |
64 const Error& error = Error::Handle(Compiler::CompileFunction(function)); | 64 const Error& error = Error::Handle(Compiler::CompileFunction(function)); |
65 if (!error.IsNull()) { | 65 if (!error.IsNull()) { |
66 Exceptions::PropagateError(error); | 66 Exceptions::PropagateError(error); |
67 } | 67 } |
68 } | 68 } |
69 | 69 |
70 | 70 |
71 RawError* Compiler::Compile(const Library& library, const Script& script) { | 71 RawError* Compiler::Compile(const Library& library, const Script& script) { |
72 Isolate* isolate = Isolate::Current(); | 72 Isolate* isolate = Isolate::Current(); |
| 73 StackZone zone(isolate); |
73 LongJump* base = isolate->long_jump_base(); | 74 LongJump* base = isolate->long_jump_base(); |
74 LongJump jump; | 75 LongJump jump; |
75 isolate->set_long_jump_base(&jump); | 76 isolate->set_long_jump_base(&jump); |
76 if (setjmp(*jump.Set()) == 0) { | 77 if (setjmp(*jump.Set()) == 0) { |
77 if (FLAG_trace_compiler) { | 78 if (FLAG_trace_compiler) { |
78 HANDLESCOPE(isolate); | |
79 const String& script_url = String::Handle(script.url()); | 79 const String& script_url = String::Handle(script.url()); |
80 // TODO(iposva): Extract script kind. | 80 // TODO(iposva): Extract script kind. |
81 OS::Print("Compiling %s '%s'\n", "", script_url.ToCString()); | 81 OS::Print("Compiling %s '%s'\n", "", script_url.ToCString()); |
82 } | 82 } |
83 const String& library_key = String::Handle(library.private_key()); | 83 const String& library_key = String::Handle(library.private_key()); |
84 script.Tokenize(library_key); | 84 script.Tokenize(library_key); |
85 Parser::ParseCompilationUnit(library, script); | 85 Parser::ParseCompilationUnit(library, script); |
86 isolate->set_long_jump_base(base); | 86 isolate->set_long_jump_base(base); |
87 return Error::null(); | 87 return Error::null(); |
88 } else { | 88 } else { |
(...skipping 22 matching lines...) Expand all Loading... |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 | 114 |
115 // Return false if bailed out. | 115 // Return false if bailed out. |
116 static bool CompileParsedFunctionHelper(const ParsedFunction& parsed_function, | 116 static bool CompileParsedFunctionHelper(const ParsedFunction& parsed_function, |
117 bool optimized) { | 117 bool optimized) { |
118 TimerScope timer(FLAG_compiler_stats, &CompilerStats::codegen_timer); | 118 TimerScope timer(FLAG_compiler_stats, &CompilerStats::codegen_timer); |
119 bool is_compiled = false; | 119 bool is_compiled = false; |
120 Isolate* isolate = Isolate::Current(); | 120 Isolate* isolate = Isolate::Current(); |
| 121 HANDLESCOPE(isolate); |
121 ASSERT(isolate->ic_data_array() == Array::null()); // Must be reset to null. | 122 ASSERT(isolate->ic_data_array() == Array::null()); // Must be reset to null. |
122 const intptr_t prev_deopt_id = isolate->deopt_id(); | 123 const intptr_t prev_deopt_id = isolate->deopt_id(); |
123 isolate->set_deopt_id(0); | 124 isolate->set_deopt_id(0); |
124 LongJump* old_base = isolate->long_jump_base(); | 125 LongJump* old_base = isolate->long_jump_base(); |
125 LongJump bailout_jump; | 126 LongJump bailout_jump; |
126 isolate->set_long_jump_base(&bailout_jump); | 127 isolate->set_long_jump_base(&bailout_jump); |
127 if (setjmp(*bailout_jump.Set()) == 0) { | 128 if (setjmp(*bailout_jump.Set()) == 0) { |
128 FlowGraph* flow_graph = NULL; | 129 FlowGraph* flow_graph = NULL; |
129 // TimerScope needs an isolate to be properly terminated in case of a | 130 // TimerScope needs an isolate to be properly terminated in case of a |
130 // LongJump. | 131 // LongJump. |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 code.raw()); | 438 code.raw()); |
438 } | 439 } |
439 OS::Print("}\n"); | 440 OS::Print("}\n"); |
440 } | 441 } |
441 } | 442 } |
442 | 443 |
443 | 444 |
444 static RawError* CompileFunctionHelper(const Function& function, | 445 static RawError* CompileFunctionHelper(const Function& function, |
445 bool optimized) { | 446 bool optimized) { |
446 Isolate* isolate = Isolate::Current(); | 447 Isolate* isolate = Isolate::Current(); |
| 448 StackZone zone(isolate); |
447 LongJump* base = isolate->long_jump_base(); | 449 LongJump* base = isolate->long_jump_base(); |
448 LongJump jump; | 450 LongJump jump; |
449 isolate->set_long_jump_base(&jump); | 451 isolate->set_long_jump_base(&jump); |
450 // Skips parsing if we need to only install unoptimized code. | 452 // Skips parsing if we need to only install unoptimized code. |
451 if (!optimized && !Code::Handle(function.unoptimized_code()).IsNull()) { | 453 if (!optimized && !Code::Handle(function.unoptimized_code()).IsNull()) { |
452 InstallUnoptimizedCode(function); | 454 InstallUnoptimizedCode(function); |
453 isolate->set_long_jump_base(base); | 455 isolate->set_long_jump_base(base); |
454 return Error::null(); | 456 return Error::null(); |
455 } | 457 } |
456 if (setjmp(*jump.Set()) == 0) { | 458 if (setjmp(*jump.Set()) == 0) { |
457 TIMERSCOPE(time_compilation); | 459 TIMERSCOPE(time_compilation); |
458 Timer per_compile_timer(FLAG_trace_compiler, "Compilation time"); | 460 Timer per_compile_timer(FLAG_trace_compiler, "Compilation time"); |
459 per_compile_timer.Start(); | 461 per_compile_timer.Start(); |
460 ParsedFunction* parsed_function = new ParsedFunction( | 462 ParsedFunction* parsed_function = new ParsedFunction( |
461 Function::ZoneHandle(function.raw())); | 463 Function::ZoneHandle(function.raw())); |
462 if (FLAG_trace_compiler) { | 464 if (FLAG_trace_compiler) { |
463 OS::Print("Compiling %sfunction: '%s' @ token %"Pd"\n", | 465 OS::Print("Compiling %sfunction: '%s' @ token %"Pd"\n", |
464 (optimized ? "optimized " : ""), | 466 (optimized ? "optimized " : ""), |
465 function.ToFullyQualifiedCString(), | 467 function.ToFullyQualifiedCString(), |
466 function.token_pos()); | 468 function.token_pos()); |
467 } | 469 } |
468 Parser::ParseFunction(parsed_function); | 470 { |
469 parsed_function->AllocateVariables(); | 471 HANDLESCOPE(isolate); |
| 472 Parser::ParseFunction(parsed_function); |
| 473 parsed_function->AllocateVariables(); |
| 474 } |
470 | 475 |
471 const bool success = | 476 const bool success = |
472 CompileParsedFunctionHelper(*parsed_function, optimized); | 477 CompileParsedFunctionHelper(*parsed_function, optimized); |
473 if (optimized && !success) { | 478 if (optimized && !success) { |
474 // Optimizer bailed out. Disable optimizations and to never try again. | 479 // Optimizer bailed out. Disable optimizations and to never try again. |
475 if (FLAG_trace_compiler) { | 480 if (FLAG_trace_compiler) { |
476 OS::Print("--> disabling optimizations for '%s'\n", | 481 OS::Print("--> disabling optimizations for '%s'\n", |
477 function.ToFullyQualifiedCString()); | 482 function.ToFullyQualifiedCString()); |
478 } | 483 } |
479 function.set_is_optimizable(false); | 484 function.set_is_optimizable(false); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 isolate->object_store()->clear_sticky_error(); | 550 isolate->object_store()->clear_sticky_error(); |
546 isolate->set_long_jump_base(base); | 551 isolate->set_long_jump_base(base); |
547 return error.raw(); | 552 return error.raw(); |
548 } | 553 } |
549 UNREACHABLE(); | 554 UNREACHABLE(); |
550 return Error::null(); | 555 return Error::null(); |
551 } | 556 } |
552 | 557 |
553 | 558 |
554 RawError* Compiler::CompileAllFunctions(const Class& cls) { | 559 RawError* Compiler::CompileAllFunctions(const Class& cls) { |
555 Isolate* isolate = Isolate::Current(); | |
556 Error& error = Error::Handle(); | 560 Error& error = Error::Handle(); |
557 Array& functions = Array::Handle(cls.functions()); | 561 Array& functions = Array::Handle(cls.functions()); |
558 Function& func = Function::Handle(); | 562 Function& func = Function::Handle(); |
559 // Class dynamic lives in the vm isolate. Its array fields cannot be set to | 563 // Class dynamic lives in the vm isolate. Its array fields cannot be set to |
560 // an empty array. | 564 // an empty array. |
561 if (functions.IsNull()) { | 565 if (functions.IsNull()) { |
562 ASSERT(cls.IsDynamicClass()); | 566 ASSERT(cls.IsDynamicClass()); |
563 return error.raw(); | 567 return error.raw(); |
564 } | 568 } |
565 for (int i = 0; i < functions.Length(); i++) { | 569 for (int i = 0; i < functions.Length(); i++) { |
566 func ^= functions.At(i); | 570 func ^= functions.At(i); |
567 ASSERT(!func.IsNull()); | 571 ASSERT(!func.IsNull()); |
568 if (!func.HasCode() && | 572 if (!func.HasCode() && |
569 !func.is_abstract() && | 573 !func.is_abstract() && |
570 !func.IsRedirectingFactory()) { | 574 !func.IsRedirectingFactory()) { |
571 StackZone zone(isolate); | |
572 HANDLESCOPE(isolate); | |
573 error = CompileFunction(func); | 575 error = CompileFunction(func); |
574 if (!error.IsNull()) { | 576 if (!error.IsNull()) { |
575 return error.raw(); | 577 return error.raw(); |
576 } | 578 } |
577 } | 579 } |
578 } | 580 } |
579 return error.raw(); | 581 return error.raw(); |
580 } | 582 } |
581 | 583 |
582 | 584 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 Object::Handle(isolate->object_store()->sticky_error()); | 636 Object::Handle(isolate->object_store()->sticky_error()); |
635 isolate->object_store()->clear_sticky_error(); | 637 isolate->object_store()->clear_sticky_error(); |
636 isolate->set_long_jump_base(base); | 638 isolate->set_long_jump_base(base); |
637 return result.raw(); | 639 return result.raw(); |
638 } | 640 } |
639 UNREACHABLE(); | 641 UNREACHABLE(); |
640 return Object::null(); | 642 return Object::null(); |
641 } | 643 } |
642 | 644 |
643 } // namespace dart | 645 } // namespace dart |
OLD | NEW |