OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 return Rewriter::Rewrite(info) && Scope::Analyze(info) && GenerateCode(info); | 319 return Rewriter::Rewrite(info) && Scope::Analyze(info) && GenerateCode(info); |
320 } | 320 } |
321 | 321 |
322 | 322 |
323 #ifdef ENABLE_DEBUGGER_SUPPORT | 323 #ifdef ENABLE_DEBUGGER_SUPPORT |
324 bool Compiler::MakeCodeForLiveEdit(CompilationInfo* info) { | 324 bool Compiler::MakeCodeForLiveEdit(CompilationInfo* info) { |
325 // Precondition: code has been parsed. Postcondition: the code field in | 325 // Precondition: code has been parsed. Postcondition: the code field in |
326 // the compilation info is set if compilation succeeded. | 326 // the compilation info is set if compilation succeeded. |
327 bool succeeded = MakeCode(info); | 327 bool succeeded = MakeCode(info); |
328 if (!info->shared_info().is_null()) { | 328 if (!info->shared_info().is_null()) { |
329 Handle<SerializedScopeInfo> scope_info = | 329 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope()); |
330 SerializedScopeInfo::Create(info->scope()); | |
331 info->shared_info()->set_scope_info(*scope_info); | 330 info->shared_info()->set_scope_info(*scope_info); |
332 } | 331 } |
333 return succeeded; | 332 return succeeded; |
334 } | 333 } |
335 #endif | 334 #endif |
336 | 335 |
337 | 336 |
338 static Handle<SharedFunctionInfo> MakeFunctionInfo(CompilationInfo* info) { | 337 static Handle<SharedFunctionInfo> MakeFunctionInfo(CompilationInfo* info) { |
339 Isolate* isolate = info->isolate(); | 338 Isolate* isolate = info->isolate(); |
340 ZoneScope zone_scope(isolate, DELETE_ON_EXIT); | 339 ZoneScope zone_scope(isolate, DELETE_ON_EXIT); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 return Handle<SharedFunctionInfo>::null(); | 387 return Handle<SharedFunctionInfo>::null(); |
389 } | 388 } |
390 | 389 |
391 // Allocate function. | 390 // Allocate function. |
392 ASSERT(!info->code().is_null()); | 391 ASSERT(!info->code().is_null()); |
393 Handle<SharedFunctionInfo> result = | 392 Handle<SharedFunctionInfo> result = |
394 isolate->factory()->NewSharedFunctionInfo( | 393 isolate->factory()->NewSharedFunctionInfo( |
395 lit->name(), | 394 lit->name(), |
396 lit->materialized_literal_count(), | 395 lit->materialized_literal_count(), |
397 info->code(), | 396 info->code(), |
398 SerializedScopeInfo::Create(info->scope())); | 397 ScopeInfo::Create(info->scope())); |
399 | 398 |
400 ASSERT_EQ(RelocInfo::kNoPosition, lit->function_token_position()); | 399 ASSERT_EQ(RelocInfo::kNoPosition, lit->function_token_position()); |
401 Compiler::SetFunctionInfo(result, lit, true, script); | 400 Compiler::SetFunctionInfo(result, lit, true, script); |
402 | 401 |
403 if (script->name()->IsString()) { | 402 if (script->name()->IsString()) { |
404 PROFILE(isolate, CodeCreateEvent( | 403 PROFILE(isolate, CodeCreateEvent( |
405 info->is_eval() | 404 info->is_eval() |
406 ? Logger::EVAL_TAG | 405 ? Logger::EVAL_TAG |
407 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script), | 406 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script), |
408 *info->code(), | 407 *info->code(), |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 Handle<Code> code = info->code(); | 615 Handle<Code> code = info->code(); |
617 // Set optimizable to false if this is disallowed by the shared | 616 // Set optimizable to false if this is disallowed by the shared |
618 // function info, e.g., we might have flushed the code and must | 617 // function info, e.g., we might have flushed the code and must |
619 // reset this bit when lazy compiling the code again. | 618 // reset this bit when lazy compiling the code again. |
620 if (shared->optimization_disabled()) code->set_optimizable(false); | 619 if (shared->optimization_disabled()) code->set_optimizable(false); |
621 | 620 |
622 Handle<JSFunction> function = info->closure(); | 621 Handle<JSFunction> function = info->closure(); |
623 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); | 622 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); |
624 | 623 |
625 if (info->IsOptimizing()) { | 624 if (info->IsOptimizing()) { |
626 ASSERT(shared->scope_info() != SerializedScopeInfo::Empty()); | 625 ASSERT(shared->scope_info() != ScopeInfo::Empty()); |
627 function->ReplaceCode(*code); | 626 function->ReplaceCode(*code); |
628 } else { | 627 } else { |
629 // Update the shared function info with the compiled code and the | 628 // Update the shared function info with the compiled code and the |
630 // scope info. Please note, that the order of the shared function | 629 // scope info. Please note, that the order of the shared function |
631 // info initialization is important since set_scope_info might | 630 // info initialization is important since set_scope_info might |
632 // trigger a GC, causing the ASSERT below to be invalid if the code | 631 // trigger a GC, causing the ASSERT below to be invalid if the code |
633 // was flushed. By settting the code object last we avoid this. | 632 // was flushed. By settting the code object last we avoid this. |
634 Handle<SerializedScopeInfo> scope_info = | 633 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope()); |
635 SerializedScopeInfo::Create(info->scope()); | |
636 shared->set_scope_info(*scope_info); | 634 shared->set_scope_info(*scope_info); |
637 shared->set_code(*code); | 635 shared->set_code(*code); |
638 if (!function.is_null()) { | 636 if (!function.is_null()) { |
639 function->ReplaceCode(*code); | 637 function->ReplaceCode(*code); |
640 ASSERT(!function->IsOptimized()); | 638 ASSERT(!function->IsOptimized()); |
641 } | 639 } |
642 | 640 |
643 // Set the expected number of properties for instances. | 641 // Set the expected number of properties for instances. |
644 FunctionLiteral* lit = info->function(); | 642 FunctionLiteral* lit = info->function(); |
645 int expected = lit->expected_property_count(); | 643 int expected = lit->expected_property_count(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 | 686 |
689 LiveEditFunctionTracker live_edit_tracker(info.isolate(), literal); | 687 LiveEditFunctionTracker live_edit_tracker(info.isolate(), literal); |
690 // Determine if the function can be lazily compiled. This is necessary to | 688 // Determine if the function can be lazily compiled. This is necessary to |
691 // allow some of our builtin JS files to be lazily compiled. These | 689 // allow some of our builtin JS files to be lazily compiled. These |
692 // builtins cannot be handled lazily by the parser, since we have to know | 690 // builtins cannot be handled lazily by the parser, since we have to know |
693 // if a function uses the special natives syntax, which is something the | 691 // if a function uses the special natives syntax, which is something the |
694 // parser records. | 692 // parser records. |
695 bool allow_lazy = literal->AllowsLazyCompilation() && | 693 bool allow_lazy = literal->AllowsLazyCompilation() && |
696 !LiveEditFunctionTracker::IsActive(info.isolate()); | 694 !LiveEditFunctionTracker::IsActive(info.isolate()); |
697 | 695 |
698 Handle<SerializedScopeInfo> scope_info(SerializedScopeInfo::Empty()); | 696 Handle<ScopeInfo> scope_info(ScopeInfo::Empty()); |
699 | 697 |
700 // Generate code | 698 // Generate code |
701 if (FLAG_lazy && allow_lazy) { | 699 if (FLAG_lazy && allow_lazy) { |
702 Handle<Code> code = info.isolate()->builtins()->LazyCompile(); | 700 Handle<Code> code = info.isolate()->builtins()->LazyCompile(); |
703 info.SetCode(code); | 701 info.SetCode(code); |
704 } else if ((V8::UseCrankshaft() && MakeCrankshaftCode(&info)) || | 702 } else if ((V8::UseCrankshaft() && MakeCrankshaftCode(&info)) || |
705 (!V8::UseCrankshaft() && FullCodeGenerator::MakeCode(&info))) { | 703 (!V8::UseCrankshaft() && FullCodeGenerator::MakeCode(&info))) { |
706 ASSERT(!info.code().is_null()); | 704 ASSERT(!info.code().is_null()); |
707 scope_info = SerializedScopeInfo::Create(info.scope()); | 705 scope_info = ScopeInfo::Create(info.scope()); |
708 } else { | 706 } else { |
709 return Handle<SharedFunctionInfo>::null(); | 707 return Handle<SharedFunctionInfo>::null(); |
710 } | 708 } |
711 | 709 |
712 // Create a shared function info object. | 710 // Create a shared function info object. |
713 Handle<SharedFunctionInfo> result = | 711 Handle<SharedFunctionInfo> result = |
714 FACTORY->NewSharedFunctionInfo(literal->name(), | 712 FACTORY->NewSharedFunctionInfo(literal->name(), |
715 literal->materialized_literal_count(), | 713 literal->materialized_literal_count(), |
716 info.code(), | 714 info.code(), |
717 scope_info); | 715 scope_info); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 } | 787 } |
790 } | 788 } |
791 | 789 |
792 GDBJIT(AddCode(Handle<String>(shared->DebugName()), | 790 GDBJIT(AddCode(Handle<String>(shared->DebugName()), |
793 Handle<Script>(info->script()), | 791 Handle<Script>(info->script()), |
794 Handle<Code>(info->code()), | 792 Handle<Code>(info->code()), |
795 info)); | 793 info)); |
796 } | 794 } |
797 | 795 |
798 } } // namespace v8::internal | 796 } } // namespace v8::internal |
OLD | NEW |