OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 #include "runtime-profiler.h" | 44 #include "runtime-profiler.h" |
45 #include "scanner-character-streams.h" | 45 #include "scanner-character-streams.h" |
46 #include "scopeinfo.h" | 46 #include "scopeinfo.h" |
47 #include "scopes.h" | 47 #include "scopes.h" |
48 #include "vm-state-inl.h" | 48 #include "vm-state-inl.h" |
49 | 49 |
50 namespace v8 { | 50 namespace v8 { |
51 namespace internal { | 51 namespace internal { |
52 | 52 |
53 | 53 |
54 CompilationInfo::CompilationInfo(Handle<Script> script) | 54 CompilationInfo::CompilationInfo(Handle<Script> script, Zone* zone) |
55 : isolate_(script->GetIsolate()), | 55 : isolate_(script->GetIsolate()), |
56 flags_(LanguageModeField::encode(CLASSIC_MODE)), | 56 flags_(LanguageModeField::encode(CLASSIC_MODE)), |
57 function_(NULL), | 57 function_(NULL), |
58 scope_(NULL), | 58 scope_(NULL), |
59 global_scope_(NULL), | 59 global_scope_(NULL), |
60 script_(script), | 60 script_(script), |
61 extension_(NULL), | 61 extension_(NULL), |
62 pre_parse_data_(NULL), | 62 pre_parse_data_(NULL), |
63 osr_ast_id_(AstNode::kNoNumber) { | 63 osr_ast_id_(AstNode::kNoNumber), |
| 64 zone_(zone) { |
64 Initialize(BASE); | 65 Initialize(BASE); |
65 } | 66 } |
66 | 67 |
67 | 68 |
68 CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info) | 69 CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info, |
| 70 Zone* zone) |
69 : isolate_(shared_info->GetIsolate()), | 71 : isolate_(shared_info->GetIsolate()), |
70 flags_(LanguageModeField::encode(CLASSIC_MODE) | | 72 flags_(LanguageModeField::encode(CLASSIC_MODE) | |
71 IsLazy::encode(true)), | 73 IsLazy::encode(true)), |
72 function_(NULL), | 74 function_(NULL), |
73 scope_(NULL), | 75 scope_(NULL), |
74 global_scope_(NULL), | 76 global_scope_(NULL), |
75 shared_info_(shared_info), | 77 shared_info_(shared_info), |
76 script_(Handle<Script>(Script::cast(shared_info->script()))), | 78 script_(Handle<Script>(Script::cast(shared_info->script()))), |
77 extension_(NULL), | 79 extension_(NULL), |
78 pre_parse_data_(NULL), | 80 pre_parse_data_(NULL), |
79 osr_ast_id_(AstNode::kNoNumber) { | 81 osr_ast_id_(AstNode::kNoNumber), |
| 82 zone_(zone) { |
80 Initialize(BASE); | 83 Initialize(BASE); |
81 } | 84 } |
82 | 85 |
83 | 86 |
84 CompilationInfo::CompilationInfo(Handle<JSFunction> closure) | 87 CompilationInfo::CompilationInfo(Handle<JSFunction> closure, Zone* zone) |
85 : isolate_(closure->GetIsolate()), | 88 : isolate_(closure->GetIsolate()), |
86 flags_(LanguageModeField::encode(CLASSIC_MODE) | | 89 flags_(LanguageModeField::encode(CLASSIC_MODE) | |
87 IsLazy::encode(true)), | 90 IsLazy::encode(true)), |
88 function_(NULL), | 91 function_(NULL), |
89 scope_(NULL), | 92 scope_(NULL), |
90 global_scope_(NULL), | 93 global_scope_(NULL), |
91 closure_(closure), | 94 closure_(closure), |
92 shared_info_(Handle<SharedFunctionInfo>(closure->shared())), | 95 shared_info_(Handle<SharedFunctionInfo>(closure->shared())), |
93 script_(Handle<Script>(Script::cast(shared_info_->script()))), | 96 script_(Handle<Script>(Script::cast(shared_info_->script()))), |
94 extension_(NULL), | 97 extension_(NULL), |
95 pre_parse_data_(NULL), | 98 pre_parse_data_(NULL), |
96 osr_ast_id_(AstNode::kNoNumber) { | 99 osr_ast_id_(AstNode::kNoNumber), |
| 100 zone_(zone) { |
97 Initialize(BASE); | 101 Initialize(BASE); |
98 } | 102 } |
99 | 103 |
100 | 104 |
101 // Disable optimization for the rest of the compilation pipeline. | 105 // Disable optimization for the rest of the compilation pipeline. |
102 void CompilationInfo::DisableOptimization() { | 106 void CompilationInfo::DisableOptimization() { |
103 bool is_optimizable_closure = | 107 bool is_optimizable_closure = |
104 FLAG_optimize_closures && | 108 FLAG_optimize_closures && |
105 closure_.is_null() && | 109 closure_.is_null() && |
106 !scope_->HasTrivialOuterContext() && | 110 !scope_->HasTrivialOuterContext() && |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 } | 259 } |
256 | 260 |
257 // Recompile the unoptimized version of the code if the current version | 261 // Recompile the unoptimized version of the code if the current version |
258 // doesn't have deoptimization support. Alternatively, we may decide to | 262 // doesn't have deoptimization support. Alternatively, we may decide to |
259 // run the full code generator to get a baseline for the compile-time | 263 // run the full code generator to get a baseline for the compile-time |
260 // performance of the hydrogen-based compiler. | 264 // performance of the hydrogen-based compiler. |
261 int64_t start = OS::Ticks(); | 265 int64_t start = OS::Ticks(); |
262 bool should_recompile = !info->shared_info()->has_deoptimization_support(); | 266 bool should_recompile = !info->shared_info()->has_deoptimization_support(); |
263 if (should_recompile || FLAG_hydrogen_stats) { | 267 if (should_recompile || FLAG_hydrogen_stats) { |
264 HPhase phase(HPhase::kFullCodeGen); | 268 HPhase phase(HPhase::kFullCodeGen); |
265 CompilationInfo unoptimized(info->shared_info()); | 269 Zone zone(info->isolate()); |
| 270 CompilationInfo unoptimized(info->shared_info(), &zone); |
| 271 ZoneScope scope(&zone, DELETE_ON_EXIT); |
266 // Note that we use the same AST that we will use for generating the | 272 // Note that we use the same AST that we will use for generating the |
267 // optimized code. | 273 // optimized code. |
268 unoptimized.SetFunction(info->function()); | 274 unoptimized.SetFunction(info->function()); |
269 unoptimized.SetScope(info->scope()); | 275 unoptimized.SetScope(info->scope()); |
270 if (should_recompile) unoptimized.EnableDeoptimizationSupport(); | 276 if (should_recompile) unoptimized.EnableDeoptimizationSupport(); |
271 bool succeeded = FullCodeGenerator::MakeCode(&unoptimized); | 277 bool succeeded = FullCodeGenerator::MakeCode(&unoptimized); |
272 if (should_recompile) { | 278 if (should_recompile) { |
273 if (!succeeded) return false; | 279 if (!succeeded) return false; |
274 Handle<SharedFunctionInfo> shared = info->shared_info(); | 280 Handle<SharedFunctionInfo> shared = info->shared_info(); |
275 shared->EnableDeoptimizationSupport(*unoptimized.code()); | 281 shared->EnableDeoptimizationSupport(*unoptimized.code()); |
(...skipping 12 matching lines...) Expand all Loading... |
288 ASSERT(info->shared_info()->has_deoptimization_support()); | 294 ASSERT(info->shared_info()->has_deoptimization_support()); |
289 | 295 |
290 if (FLAG_trace_hydrogen) { | 296 if (FLAG_trace_hydrogen) { |
291 PrintF("-----------------------------------------------------------\n"); | 297 PrintF("-----------------------------------------------------------\n"); |
292 PrintF("Compiling method %s using hydrogen\n", *name->ToCString()); | 298 PrintF("Compiling method %s using hydrogen\n", *name->ToCString()); |
293 HTracer::Instance()->TraceCompilation(info->function()); | 299 HTracer::Instance()->TraceCompilation(info->function()); |
294 } | 300 } |
295 | 301 |
296 Handle<Context> global_context(info->closure()->context()->global_context()); | 302 Handle<Context> global_context(info->closure()->context()->global_context()); |
297 TypeFeedbackOracle oracle(code, global_context, info->isolate(), | 303 TypeFeedbackOracle oracle(code, global_context, info->isolate(), |
298 info->isolate()->zone()); | 304 info->zone()); |
299 HGraphBuilder builder(info, &oracle, info->isolate()->zone()); | 305 HGraphBuilder builder(info, &oracle); |
300 HPhase phase(HPhase::kTotal); | 306 HPhase phase(HPhase::kTotal); |
301 HGraph* graph = builder.CreateGraph(); | 307 HGraph* graph = builder.CreateGraph(); |
302 if (info->isolate()->has_pending_exception()) { | 308 if (info->isolate()->has_pending_exception()) { |
303 info->SetCode(Handle<Code>::null()); | 309 info->SetCode(Handle<Code>::null()); |
304 return false; | 310 return false; |
305 } | 311 } |
306 | 312 |
307 if (graph != NULL) { | 313 if (graph != NULL) { |
308 Handle<Code> optimized_code = graph->Compile(info, graph->zone()); | 314 Handle<Code> optimized_code = graph->Compile(); |
309 if (!optimized_code.is_null()) { | 315 if (!optimized_code.is_null()) { |
310 info->SetCode(optimized_code); | 316 info->SetCode(optimized_code); |
311 FinishOptimization(info->closure(), start); | 317 FinishOptimization(info->closure(), start); |
312 return true; | 318 return true; |
313 } | 319 } |
314 } | 320 } |
315 | 321 |
316 // Keep using the shared code. | 322 // Keep using the shared code. |
317 info->AbortOptimization(); | 323 info->AbortOptimization(); |
318 if (!builder.inline_bailout()) { | 324 if (!builder.inline_bailout()) { |
(...skipping 22 matching lines...) Expand all Loading... |
341 } | 347 } |
342 | 348 |
343 | 349 |
344 #ifdef ENABLE_DEBUGGER_SUPPORT | 350 #ifdef ENABLE_DEBUGGER_SUPPORT |
345 bool Compiler::MakeCodeForLiveEdit(CompilationInfo* info) { | 351 bool Compiler::MakeCodeForLiveEdit(CompilationInfo* info) { |
346 // Precondition: code has been parsed. Postcondition: the code field in | 352 // Precondition: code has been parsed. Postcondition: the code field in |
347 // the compilation info is set if compilation succeeded. | 353 // the compilation info is set if compilation succeeded. |
348 bool succeeded = MakeCode(info); | 354 bool succeeded = MakeCode(info); |
349 if (!info->shared_info().is_null()) { | 355 if (!info->shared_info().is_null()) { |
350 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope(), | 356 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope(), |
351 info->isolate()->zone()); | 357 info->zone()); |
352 info->shared_info()->set_scope_info(*scope_info); | 358 info->shared_info()->set_scope_info(*scope_info); |
353 } | 359 } |
354 return succeeded; | 360 return succeeded; |
355 } | 361 } |
356 #endif | 362 #endif |
357 | 363 |
358 | 364 |
359 static Handle<SharedFunctionInfo> MakeFunctionInfo(CompilationInfo* info) { | 365 static Handle<SharedFunctionInfo> MakeFunctionInfo(CompilationInfo* info) { |
360 Isolate* isolate = info->isolate(); | 366 Isolate* isolate = info->isolate(); |
361 ZoneScope zone_scope(isolate, DELETE_ON_EXIT); | 367 ZoneScope zone_scope(info->zone(), DELETE_ON_EXIT); |
362 PostponeInterruptsScope postpone(isolate); | 368 PostponeInterruptsScope postpone(isolate); |
363 | 369 |
364 ASSERT(!isolate->global_context().is_null()); | 370 ASSERT(!isolate->global_context().is_null()); |
365 Handle<Script> script = info->script(); | 371 Handle<Script> script = info->script(); |
366 script->set_context_data((*isolate->global_context())->data()); | 372 script->set_context_data((*isolate->global_context())->data()); |
367 | 373 |
368 #ifdef ENABLE_DEBUGGER_SUPPORT | 374 #ifdef ENABLE_DEBUGGER_SUPPORT |
369 if (info->is_eval()) { | 375 if (info->is_eval()) { |
370 Script::CompilationType compilation_type = Script::COMPILATION_TYPE_EVAL; | 376 Script::CompilationType compilation_type = Script::COMPILATION_TYPE_EVAL; |
371 script->set_compilation_type(Smi::FromInt(compilation_type)); | 377 script->set_compilation_type(Smi::FromInt(compilation_type)); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 return Handle<SharedFunctionInfo>::null(); | 421 return Handle<SharedFunctionInfo>::null(); |
416 } | 422 } |
417 | 423 |
418 // Allocate function. | 424 // Allocate function. |
419 ASSERT(!info->code().is_null()); | 425 ASSERT(!info->code().is_null()); |
420 Handle<SharedFunctionInfo> result = | 426 Handle<SharedFunctionInfo> result = |
421 isolate->factory()->NewSharedFunctionInfo( | 427 isolate->factory()->NewSharedFunctionInfo( |
422 lit->name(), | 428 lit->name(), |
423 lit->materialized_literal_count(), | 429 lit->materialized_literal_count(), |
424 info->code(), | 430 info->code(), |
425 ScopeInfo::Create(info->scope(), info->isolate()->zone())); | 431 ScopeInfo::Create(info->scope(), info->zone())); |
426 | 432 |
427 ASSERT_EQ(RelocInfo::kNoPosition, lit->function_token_position()); | 433 ASSERT_EQ(RelocInfo::kNoPosition, lit->function_token_position()); |
428 Compiler::SetFunctionInfo(result, lit, true, script); | 434 Compiler::SetFunctionInfo(result, lit, true, script); |
429 | 435 |
430 if (script->name()->IsString()) { | 436 if (script->name()->IsString()) { |
431 PROFILE(isolate, CodeCreateEvent( | 437 PROFILE(isolate, CodeCreateEvent( |
432 info->is_eval() | 438 info->is_eval() |
433 ? Logger::EVAL_TAG | 439 ? Logger::EVAL_TAG |
434 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script), | 440 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script), |
435 *info->code(), | 441 *info->code(), |
(...skipping 21 matching lines...) Expand all Loading... |
457 | 463 |
458 script->set_compilation_state( | 464 script->set_compilation_state( |
459 Smi::FromInt(Script::COMPILATION_STATE_COMPILED)); | 465 Smi::FromInt(Script::COMPILATION_STATE_COMPILED)); |
460 | 466 |
461 #ifdef ENABLE_DEBUGGER_SUPPORT | 467 #ifdef ENABLE_DEBUGGER_SUPPORT |
462 // Notify debugger | 468 // Notify debugger |
463 isolate->debugger()->OnAfterCompile( | 469 isolate->debugger()->OnAfterCompile( |
464 script, Debugger::NO_AFTER_COMPILE_FLAGS); | 470 script, Debugger::NO_AFTER_COMPILE_FLAGS); |
465 #endif | 471 #endif |
466 | 472 |
467 live_edit_tracker.RecordFunctionInfo(result, lit, isolate->zone()); | 473 live_edit_tracker.RecordFunctionInfo(result, lit, info->zone()); |
468 | 474 |
469 return result; | 475 return result; |
470 } | 476 } |
471 | 477 |
472 | 478 |
473 Handle<SharedFunctionInfo> Compiler::Compile(Handle<String> source, | 479 Handle<SharedFunctionInfo> Compiler::Compile(Handle<String> source, |
474 Handle<Object> script_name, | 480 Handle<Object> script_name, |
475 int line_offset, | 481 int line_offset, |
476 int column_offset, | 482 int column_offset, |
477 v8::Extension* extension, | 483 v8::Extension* extension, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 if (!script_name.is_null()) { | 521 if (!script_name.is_null()) { |
516 script->set_name(*script_name); | 522 script->set_name(*script_name); |
517 script->set_line_offset(Smi::FromInt(line_offset)); | 523 script->set_line_offset(Smi::FromInt(line_offset)); |
518 script->set_column_offset(Smi::FromInt(column_offset)); | 524 script->set_column_offset(Smi::FromInt(column_offset)); |
519 } | 525 } |
520 | 526 |
521 script->set_data(script_data.is_null() ? HEAP->undefined_value() | 527 script->set_data(script_data.is_null() ? HEAP->undefined_value() |
522 : *script_data); | 528 : *script_data); |
523 | 529 |
524 // Compile the function and add it to the cache. | 530 // Compile the function and add it to the cache. |
525 CompilationInfo info(script); | 531 Zone zone(isolate); |
| 532 CompilationInfo info(script, &zone); |
| 533 ZoneScope scope(&zone, DELETE_ON_EXIT); |
526 info.MarkAsGlobal(); | 534 info.MarkAsGlobal(); |
527 info.SetExtension(extension); | 535 info.SetExtension(extension); |
528 info.SetPreParseData(pre_data); | 536 info.SetPreParseData(pre_data); |
529 if (FLAG_use_strict) { | 537 if (FLAG_use_strict) { |
530 info.SetLanguageMode(FLAG_harmony_scoping ? EXTENDED_MODE : STRICT_MODE); | 538 info.SetLanguageMode(FLAG_harmony_scoping ? EXTENDED_MODE : STRICT_MODE); |
531 } | 539 } |
532 result = MakeFunctionInfo(&info); | 540 result = MakeFunctionInfo(&info); |
533 if (extension == NULL && !result.is_null()) { | 541 if (extension == NULL && !result.is_null()) { |
534 compilation_cache->PutScript(source, result); | 542 compilation_cache->PutScript(source, result); |
535 } | 543 } |
(...skipping 27 matching lines...) Expand all Loading... |
563 CompilationCache* compilation_cache = isolate->compilation_cache(); | 571 CompilationCache* compilation_cache = isolate->compilation_cache(); |
564 result = compilation_cache->LookupEval(source, | 572 result = compilation_cache->LookupEval(source, |
565 context, | 573 context, |
566 is_global, | 574 is_global, |
567 language_mode, | 575 language_mode, |
568 scope_position); | 576 scope_position); |
569 | 577 |
570 if (result.is_null()) { | 578 if (result.is_null()) { |
571 // Create a script object describing the script to be compiled. | 579 // Create a script object describing the script to be compiled. |
572 Handle<Script> script = isolate->factory()->NewScript(source); | 580 Handle<Script> script = isolate->factory()->NewScript(source); |
573 CompilationInfo info(script); | 581 Zone zone(isolate); |
| 582 CompilationInfo info(script, &zone); |
| 583 ZoneScope scope(&zone, DELETE_ON_EXIT); |
574 info.MarkAsEval(); | 584 info.MarkAsEval(); |
575 if (is_global) info.MarkAsGlobal(); | 585 if (is_global) info.MarkAsGlobal(); |
576 info.SetLanguageMode(language_mode); | 586 info.SetLanguageMode(language_mode); |
577 info.SetCallingContext(context); | 587 info.SetCallingContext(context); |
578 result = MakeFunctionInfo(&info); | 588 result = MakeFunctionInfo(&info); |
579 if (!result.is_null()) { | 589 if (!result.is_null()) { |
580 // Explicitly disable optimization for eval code. We're not yet prepared | 590 // Explicitly disable optimization for eval code. We're not yet prepared |
581 // to handle eval-code in the optimizing compiler. | 591 // to handle eval-code in the optimizing compiler. |
582 result->DisableOptimization(); | 592 result->DisableOptimization(); |
583 | 593 |
(...skipping 14 matching lines...) Expand all Loading... |
598 } | 608 } |
599 } | 609 } |
600 | 610 |
601 return result; | 611 return result; |
602 } | 612 } |
603 | 613 |
604 | 614 |
605 bool Compiler::CompileLazy(CompilationInfo* info) { | 615 bool Compiler::CompileLazy(CompilationInfo* info) { |
606 Isolate* isolate = info->isolate(); | 616 Isolate* isolate = info->isolate(); |
607 | 617 |
608 ZoneScope zone_scope(isolate, DELETE_ON_EXIT); | 618 ZoneScope zone_scope(info->zone(), DELETE_ON_EXIT); |
609 | 619 |
610 // The VM is in the COMPILER state until exiting this function. | 620 // The VM is in the COMPILER state until exiting this function. |
611 VMState state(isolate, COMPILER); | 621 VMState state(isolate, COMPILER); |
612 | 622 |
613 PostponeInterruptsScope postpone(isolate); | 623 PostponeInterruptsScope postpone(isolate); |
614 | 624 |
615 Handle<SharedFunctionInfo> shared = info->shared_info(); | 625 Handle<SharedFunctionInfo> shared = info->shared_info(); |
616 int compiled_size = shared->end_position() - shared->start_position(); | 626 int compiled_size = shared->end_position() - shared->start_position(); |
617 isolate->counters()->total_compile_size()->Increment(compiled_size); | 627 isolate->counters()->total_compile_size()->Increment(compiled_size); |
618 | 628 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 SharedFunctionInfo::AddToOptimizedCodeMap( | 696 SharedFunctionInfo::AddToOptimizedCodeMap( |
687 shared, global_context, code, literals); | 697 shared, global_context, code, literals); |
688 } | 698 } |
689 } else { | 699 } else { |
690 // Update the shared function info with the compiled code and the | 700 // Update the shared function info with the compiled code and the |
691 // scope info. Please note, that the order of the shared function | 701 // scope info. Please note, that the order of the shared function |
692 // info initialization is important since set_scope_info might | 702 // info initialization is important since set_scope_info might |
693 // trigger a GC, causing the ASSERT below to be invalid if the code | 703 // trigger a GC, causing the ASSERT below to be invalid if the code |
694 // was flushed. By setting the code object last we avoid this. | 704 // was flushed. By setting the code object last we avoid this. |
695 Handle<ScopeInfo> scope_info = | 705 Handle<ScopeInfo> scope_info = |
696 ScopeInfo::Create(info->scope(), info->isolate()->zone()); | 706 ScopeInfo::Create(info->scope(), info->zone()); |
697 shared->set_scope_info(*scope_info); | 707 shared->set_scope_info(*scope_info); |
698 shared->set_code(*code); | 708 shared->set_code(*code); |
699 if (!function.is_null()) { | 709 if (!function.is_null()) { |
700 function->ReplaceCode(*code); | 710 function->ReplaceCode(*code); |
701 ASSERT(!function->IsOptimized()); | 711 ASSERT(!function->IsOptimized()); |
702 } | 712 } |
703 | 713 |
704 // Set the expected number of properties for instances. | 714 // Set the expected number of properties for instances. |
705 FunctionLiteral* lit = info->function(); | 715 FunctionLiteral* lit = info->function(); |
706 int expected = lit->expected_property_count(); | 716 int expected = lit->expected_property_count(); |
(...skipping 14 matching lines...) Expand all Loading... |
721 shared->set_ast_node_count(lit->ast_node_count()); | 731 shared->set_ast_node_count(lit->ast_node_count()); |
722 | 732 |
723 if (V8::UseCrankshaft()&& | 733 if (V8::UseCrankshaft()&& |
724 !function.is_null() && | 734 !function.is_null() && |
725 !shared->optimization_disabled()) { | 735 !shared->optimization_disabled()) { |
726 // If we're asked to always optimize, we compile the optimized | 736 // If we're asked to always optimize, we compile the optimized |
727 // version of the function right away - unless the debugger is | 737 // version of the function right away - unless the debugger is |
728 // active as it makes no sense to compile optimized code then. | 738 // active as it makes no sense to compile optimized code then. |
729 if (FLAG_always_opt && | 739 if (FLAG_always_opt && |
730 !Isolate::Current()->DebuggerHasBreakPoints()) { | 740 !Isolate::Current()->DebuggerHasBreakPoints()) { |
731 CompilationInfo optimized(function); | 741 Zone zone(function->GetIsolate()); |
| 742 CompilationInfo optimized(function, &zone); |
| 743 ZoneScope scope(&zone, DELETE_ON_EXIT); |
732 optimized.SetOptimizing(AstNode::kNoNumber); | 744 optimized.SetOptimizing(AstNode::kNoNumber); |
733 return CompileLazy(&optimized); | 745 return CompileLazy(&optimized); |
734 } | 746 } |
735 } | 747 } |
736 } | 748 } |
737 | 749 |
738 return true; | 750 return true; |
739 } | 751 } |
740 } | 752 } |
741 | 753 |
742 ASSERT(info->code().is_null()); | 754 ASSERT(info->code().is_null()); |
743 return false; | 755 return false; |
744 } | 756 } |
745 | 757 |
746 | 758 |
747 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal, | 759 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal, |
748 Handle<Script> script) { | 760 Handle<Script> script) { |
749 // Precondition: code has been parsed and scopes have been analyzed. | 761 // Precondition: code has been parsed and scopes have been analyzed. |
750 CompilationInfo info(script); | 762 Zone zone(script->GetIsolate()); |
| 763 CompilationInfo info(script, &zone); |
| 764 ZoneScope scope(&zone, DELETE_ON_EXIT); |
751 info.SetFunction(literal); | 765 info.SetFunction(literal); |
752 info.SetScope(literal->scope()); | 766 info.SetScope(literal->scope()); |
753 info.SetLanguageMode(literal->scope()->language_mode()); | 767 info.SetLanguageMode(literal->scope()->language_mode()); |
754 | 768 |
755 LiveEditFunctionTracker live_edit_tracker(info.isolate(), literal); | 769 LiveEditFunctionTracker live_edit_tracker(info.isolate(), literal); |
756 // Determine if the function can be lazily compiled. This is necessary to | 770 // Determine if the function can be lazily compiled. This is necessary to |
757 // allow some of our builtin JS files to be lazily compiled. These | 771 // allow some of our builtin JS files to be lazily compiled. These |
758 // builtins cannot be handled lazily by the parser, since we have to know | 772 // builtins cannot be handled lazily by the parser, since we have to know |
759 // if a function uses the special natives syntax, which is something the | 773 // if a function uses the special natives syntax, which is something the |
760 // parser records. | 774 // parser records. |
761 bool allow_lazy = literal->AllowsLazyCompilation() && | 775 bool allow_lazy = literal->AllowsLazyCompilation() && |
762 !LiveEditFunctionTracker::IsActive(info.isolate()); | 776 !LiveEditFunctionTracker::IsActive(info.isolate()); |
763 | 777 |
764 Handle<ScopeInfo> scope_info(ScopeInfo::Empty()); | 778 Handle<ScopeInfo> scope_info(ScopeInfo::Empty()); |
765 | 779 |
766 // Generate code | 780 // Generate code |
767 if (FLAG_lazy && allow_lazy) { | 781 if (FLAG_lazy && allow_lazy) { |
768 Handle<Code> code = info.isolate()->builtins()->LazyCompile(); | 782 Handle<Code> code = info.isolate()->builtins()->LazyCompile(); |
769 info.SetCode(code); | 783 info.SetCode(code); |
770 } else if ((V8::UseCrankshaft() && MakeCrankshaftCode(&info)) || | 784 } else if ((V8::UseCrankshaft() && MakeCrankshaftCode(&info)) || |
771 (!V8::UseCrankshaft() && FullCodeGenerator::MakeCode(&info))) { | 785 (!V8::UseCrankshaft() && FullCodeGenerator::MakeCode(&info))) { |
772 ASSERT(!info.code().is_null()); | 786 ASSERT(!info.code().is_null()); |
773 scope_info = ScopeInfo::Create(info.scope(), info.isolate()->zone()); | 787 scope_info = ScopeInfo::Create(info.scope(), info.zone()); |
774 } else { | 788 } else { |
775 return Handle<SharedFunctionInfo>::null(); | 789 return Handle<SharedFunctionInfo>::null(); |
776 } | 790 } |
777 | 791 |
778 // Create a shared function info object. | 792 // Create a shared function info object. |
779 Handle<SharedFunctionInfo> result = | 793 Handle<SharedFunctionInfo> result = |
780 FACTORY->NewSharedFunctionInfo(literal->name(), | 794 FACTORY->NewSharedFunctionInfo(literal->name(), |
781 literal->materialized_literal_count(), | 795 literal->materialized_literal_count(), |
782 info.code(), | 796 info.code(), |
783 scope_info); | 797 scope_info); |
784 SetFunctionInfo(result, literal, false, script); | 798 SetFunctionInfo(result, literal, false, script); |
785 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result); | 799 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result); |
786 result->set_allows_lazy_compilation(allow_lazy); | 800 result->set_allows_lazy_compilation(allow_lazy); |
787 | 801 |
788 // Set the expected number of properties for instances and return | 802 // Set the expected number of properties for instances and return |
789 // the resulting function. | 803 // the resulting function. |
790 SetExpectedNofPropertiesFromEstimate(result, | 804 SetExpectedNofPropertiesFromEstimate(result, |
791 literal->expected_property_count()); | 805 literal->expected_property_count()); |
792 live_edit_tracker.RecordFunctionInfo(result, literal, info.isolate()->zone()); | 806 live_edit_tracker.RecordFunctionInfo(result, literal, info.zone()); |
793 return result; | 807 return result; |
794 } | 808 } |
795 | 809 |
796 | 810 |
797 // Sets the function info on a function. | 811 // Sets the function info on a function. |
798 // The start_position points to the first '(' character after the function name | 812 // The start_position points to the first '(' character after the function name |
799 // in the full script source. When counting characters in the script source the | 813 // in the full script source. When counting characters in the script source the |
800 // the first character is number 0 (not 1). | 814 // the first character is number 0 (not 1). |
801 void Compiler::SetFunctionInfo(Handle<SharedFunctionInfo> function_info, | 815 void Compiler::SetFunctionInfo(Handle<SharedFunctionInfo> function_info, |
802 FunctionLiteral* lit, | 816 FunctionLiteral* lit, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 } | 873 } |
860 } | 874 } |
861 | 875 |
862 GDBJIT(AddCode(Handle<String>(shared->DebugName()), | 876 GDBJIT(AddCode(Handle<String>(shared->DebugName()), |
863 Handle<Script>(info->script()), | 877 Handle<Script>(info->script()), |
864 Handle<Code>(info->code()), | 878 Handle<Code>(info->code()), |
865 info)); | 879 info)); |
866 } | 880 } |
867 | 881 |
868 } } // namespace v8::internal | 882 } } // namespace v8::internal |
OLD | NEW |